Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. #!/usr/bin/python
  2.  
  3. import string
  4.  
  5. CAN_NMT             = 0x00
  6.  
  7. CAN_NMT_RESET       = 0x04
  8. CAN_NMT_BIOS_START  = 0x08
  9. CAN_NMT_PGM_START   = 0x0C
  10. CAN_NMT_PGM_DATA    = 0x10
  11. CAN_NMT_PGM_END     = 0x14
  12. CAN_NMT_PGM_COPY    = 0x18
  13. CAN_NMT_PGM_ACK     = 0x1C
  14. CAN_NMT_PGM_NACK    = 0x20
  15. CAN_NMT_START_APP   = 0x24
  16. CAN_NMT_APP_START   = 0x28
  17. CAN_NMT_HEARTBEAT   = 0x2C
  18.  
  19. def nmt_id( type, nodeid, snodeid=0 ):
  20.     return (CAN_NMT<<24) | (type<<16) | (snodeid<<8) | (nodeid)
  21.  
  22. class CanPacket:
  23.     """Can packet stortage
  24.  
  25.    """
  26.     def __init__( self, id, data, extended = True, remote = False ):
  27.         if extended:
  28.             self.id = id & 0x1FFFFFFF
  29.         else:
  30.             self.id = id & 0x1FF
  31.         self.data = [val & 0xFF for val in data[:8]]
  32.         self.extended = extended
  33.         self.remote = remote
  34.  
  35.     def __repr__( self ):
  36.         return "CanPacket( " + hex(self.id) + \
  37.                         ", [" + string.join( [hex(val) for val in self.data], ", " ) + "]" + \
  38.                         ", " + str(self.extended) + \
  39.                         ", " + str(self.remote) + \
  40.                         ")"
  41.