Skip to content

Commit

Permalink
more acurate j1939 handling ... #156
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker committed Jun 18, 2018
1 parent a14e8a1 commit 8715304
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,14 @@ def contains_fd(self):
return True
return False

@property
def contains_j1939(self):
for frame in self.frames:
if frame.is_j1939:
return True
return False


def attribute(self, attributeName):
if attributeName in self.attributes:
return self.attributes[attributeName]
Expand Down
14 changes: 10 additions & 4 deletions canmatrix/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,22 @@ def dump(mydb, f, **options):
else:
compatibility = True

if db.contains_fd:
db.addGlobalDefines("BusType","STRING")
db.addAttribute("BusType", "CAN FD")
db.addFrameDefines("VFrameFormat",'ENUM "StandardCAN","ExtendedCAN","StandardCAN_FD","ExtendedCAN_FD"')
if db.contains_fd or db.contains_j1939:
if db.contains_fd:
db.addGlobalDefines("BusType", "STRING")
db.addAttribute("BusType", "CAN FD")
elif db.contains_j1939:
db.addGlobalDefines("ProtocolType", "STRING")
db.addAttribute("ProtocolType", "J1939")
db.addFrameDefines("VFrameFormat",'ENUM "StandardCAN","ExtendedCAN","StandardCAN_FD","ExtendedCAN_FD","J1939PG"')
for frame in db.frames:
if frame.is_fd:
if frame.extended:
frame.addAttribute("VFrameFormat", "ExtendedCAN_FD")
else:
frame.addAttribute("VFrameFormat", "StandardCAN_FD")
elif frame.is_j1939:
frame.addAttribute("VFrameFormat","J1939PG")
else:
if frame.extended:
frame.addAttribute("VFrameFormat", "ExtendedCAN")
Expand Down
6 changes: 0 additions & 6 deletions examples/createJ1939Dbc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python3

import canmatrix.formats
cm = canmatrix.CanMatrix()

cm.addFrameDefines("VFrameFormat", 'ENUM "StandardCAN","ExtendedCAN","J1939PG"')

#
# create frame Node604
#
Expand All @@ -14,7 +11,6 @@
for i in range(1,9):
sig = canmatrix.Signal("ch%d" % i, signalSize = 32, is_float = True, is_little_endian = False, startBit = (i-1)*32)
frame1.addSignal(sig)
frame1.addAttribute("VFrameFormat", "J1939PG")
cm.frames.addFrame(frame1)

#
Expand All @@ -28,7 +24,6 @@
sig2 = canmatrix.Signal("ch2", signalSize=32, is_float=True, is_little_endian=False, startBit=32)
frame2.addSignal(sig)
frame2.addSignal(sig2)
frame2.addAttribute("VFrameFormat", "J1939PG")
cm.frames.addFrame(frame2)


Expand All @@ -40,7 +35,6 @@
comment="J1939 packet containing <8 byte payload")
sig = canmatrix.Signal("ch1", signalSize=32, is_float=True, is_little_endian=False, startBit=0)
frame3.addSignal(sig)
frame3.addAttribute("VFrameFormat", "J1939PG")
cm.frames.addFrame(frame3)


Expand Down

0 comments on commit 8715304

Please sign in to comment.