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

18 bit PGN changes break 16 bit masking #22

Open
brearl opened this issue Feb 1, 2023 · 2 comments
Open

18 bit PGN changes break 16 bit masking #22

brearl opened this issue Feb 1, 2023 · 2 comments

Comments

@brearl
Copy link
Contributor

brearl commented Feb 1, 2023

The 18 bit PGN mask changes break the 16 bit masking and don't appear to work correctly for 18 bit PGNs. The patch below appears to correct this:

diff --git a/j1939/pgn.py b/j1939/pgn.py
index 24611c1..4305ffc 100644
--- a/j1939/pgn.py
+++ b/j1939/pgn.py
@@ -42,9 +42,9 @@ class PGN(object):

 @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))
    

@@ -52,9 +52,9 @@ class PGN(object):
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
    

@@ -64,9 +64,9 @@ class PGN(object):
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, 
    
@milhead2
Copy link
Owner

milhead2 commented Feb 1, 2023 via email

@brearl
Copy link
Contributor Author

brearl commented Feb 6, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants