Guest User

Untitled

a guest
Apr 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import time
  2.  
  3. # ascii version of a test message
  4. message = 'DA0400010201000100000000000000004B02AA2B00'
  5. # VVCCCLLLVIVMSSSSIIIIIIIIIIIIIIIITTTTTTTTPPAAAAAAAA
  6. # 01234567890123456789012345678901234567890123456789
  7. # * * * * *
  8.  
  9. # grab each part of the header
  10. version = message[0:2]
  11. control_bits = message[2:5]
  12. payload_length = message[5:8]
  13. vendor_id = message[8:10]
  14. vendor_model = message[10:12]
  15. sequence = message[12:16]
  16. identifier = message[16:32]
  17. timestamp = message[32:40]
  18.  
  19.  
  20. # convert FROM ascii hex (base 16).
  21. version = int(version, 16)
  22.  
  23. # need to deal with this a little diffrently due to 3bit integers.
  24. control_bits = int(control_bits, 16)
  25. identifier_schema = (control_bits >> 5) & 0x7
  26. authorisation_schema = (control_bits >> 2) & 0x7
  27. acknowledge_required = (control_bits >> 1) & 0x1
  28. response = control_bits & 0x1
  29.  
  30. payload_length = int(payload_length, 16)
  31. vendor_id = int(vendor_id, 16)
  32. vendor_model = int(vendor_model, 16)
  33. sequence = int(sequence, 16)
  34. identifier = int(identifier, 16)
  35. timestamp = int(timestamp, 16)
  36.  
  37. print "---"
  38. print "ascii hex message: %s" % message
  39. print "---"
  40. print " version: 0x%X" % version
  41. print " control_bits..."
  42. print " identifier_schema: 0x%X" % identifier_schema
  43. print " authorisation_schema: 0x%X" % authorisation_schema
  44. print " acknowledge_required: 0x%X" % acknowledge_required
  45. print " response: 0x%X" % response
  46. print "payload_length: 0x%X" % payload_length
  47. print " vendor_id: 0x%X" % vendor_id
  48. print " vendor_model: 0x%X" % vendor_model
  49. print " sequence: 0x%X" % sequence
  50. print " identifier: %s" % identifier
  51. print " timestamp: %s" % time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))
Add Comment
Please, Sign In to add comment