Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 16 and 18 bit masking #23

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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