Skip to content

Commit

Permalink
Merge pull request #23 from Trail-Tech/master
Browse files Browse the repository at this point in the history
Fix 16 and 18 bit masking
  • Loading branch information
milhead2 authored Apr 28, 2023
2 parents d76df50 + ba859a2 commit b83b41e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions j1939/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def value(self):

@value.setter
def value(self, value):
self.reserved_flag = (value & 0x080000) >> 17
self.data_page_flag = (value & 0x040000) >> 16
self.pdu_format = (value & 0x03FF00) >> 8
self.reserved_flag = (value & 0x020000) >> 17
self.data_page_flag = (value & 0x010000) >> 16
self.pdu_format = (value & 0x00FF00) >> 8
self.pdu_specific = value & 0x0000FF
#MIL logger.debug("PGN.@valueSetter, value=0x%08x, pdu_format=0x%08x" % (value, self.pdu_format))

@staticmethod
def from_value(pgn_value):
logger.debug("PGN.@from_value, pgn_value=0x%08x" % (pgn_value))
pgn = PGN()
pgn.reserved_flag = (pgn_value & 0x080000) >> 17
pgn.data_page_flag = (pgn_value & 0x040000) >> 16
pgn.pdu_format = (pgn_value & 0x03FF00) >> 8
pgn.reserved_flag = (pgn_value & 0x020000) >> 17
pgn.data_page_flag = (pgn_value & 0x010000) >> 16
pgn.pdu_format = (pgn_value & 0x00FF00) >> 8
pgn.pdu_specific = pgn_value & 0x0000FF
return pgn

Expand All @@ -64,9 +64,9 @@ def from_can_id(canid):
canid = canid>>8
pgn = PGN()

pgn.reserved_flag = (canid & 0x080000) >> 17
pgn.data_page_flag = (canid & 0x040000) >> 16
pgn.pdu_format = (canid & 0x03FF00) >> 8
pgn.reserved_flag = (canid & 0x020000) >> 17
pgn.data_page_flag = (canid & 0x010000) >> 16
pgn.pdu_format = (canid & 0x00FF00) >> 8
pgn.pdu_specific = canid & 0x0000FF
logger.info("{} staticmethod: PGN Creation, res={}, dp={}, pdu_format=0x{:02x}, pdu_specific=0x{:02x}".format(inspect.stack()[0][3],
pgn.reserved_flag,
Expand Down

0 comments on commit b83b41e

Please sign in to comment.