Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- # ascii version of a test message
- message = 'DA0400010201000100000000000000004B02AA2B00'
- # VVCCCLLLVIVMSSSSIIIIIIIIIIIIIIIITTTTTTTTPPAAAAAAAA
- # 01234567890123456789012345678901234567890123456789
- # * * * * *
- # grab each part of the header
- version = message[0:2]
- control_bits = message[2:5]
- payload_length = message[5:8]
- vendor_id = message[8:10]
- vendor_model = message[10:12]
- sequence = message[12:16]
- identifier = message[16:32]
- timestamp = message[32:40]
- # convert FROM ascii hex (base 16).
- version = int(version, 16)
- # need to deal with this a little diffrently due to 3bit integers.
- control_bits = int(control_bits, 16)
- identifier_schema = (control_bits >> 5) & 0x7
- authorisation_schema = (control_bits >> 2) & 0x7
- acknowledge_required = (control_bits >> 1) & 0x1
- response = control_bits & 0x1
- payload_length = int(payload_length, 16)
- vendor_id = int(vendor_id, 16)
- vendor_model = int(vendor_model, 16)
- sequence = int(sequence, 16)
- identifier = int(identifier, 16)
- timestamp = int(timestamp, 16)
- print "---"
- print "ascii hex message: %s" % message
- print "---"
- print " version: 0x%X" % version
- print " control_bits..."
- print " identifier_schema: 0x%X" % identifier_schema
- print " authorisation_schema: 0x%X" % authorisation_schema
- print " acknowledge_required: 0x%X" % acknowledge_required
- print " response: 0x%X" % response
- print "payload_length: 0x%X" % payload_length
- print " vendor_id: 0x%X" % vendor_id
- print " vendor_model: 0x%X" % vendor_model
- print " sequence: 0x%X" % sequence
- print " identifier: %s" % identifier
- print " timestamp: %s" % time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))
Add Comment
Please, Sign In to add comment