ParsingTools.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class ParsingTools():
  2. def macToString(self, mac_bytes):
  3. ''' Convert uint8 byte string to "XX:XX:XX:XX:XX"
  4. '''
  5. mac_str = ""
  6. for byte in mac_bytes:
  7. mac_str = mac_str + format(byte, '02x') + ':'
  8. return mac_str[:-1].format('utf-8')
  9. def calculateVCell(self, raw_Vcell):
  10. return raw_Vcell*1.25e-3
  11. def calculateSOC(self, raw_SOC):
  12. return raw_SOC.to_bytes(2, 'big')[0]
  13. def getModuleIDfromTopic(self, topic):
  14. return topic.split('/')[2]
  15. class FieldGenerator():
  16. def generateMACID(self):
  17. import numpy as np
  18. macID = np.random.randint(255, size=5)
  19. macStr = ""
  20. for val in macID:
  21. macStr = macStr + format(val, 'x') + ":"
  22. return macStr[:-1]
  23. def generateRSSI(self):
  24. import numpy as np
  25. rssi = np.random.randint(80)
  26. rssiStr = "RSSI: -" + str(rssi) + "dBm"
  27. return rssiStr
  28. def generateSOC(self):
  29. import numpy as np
  30. soc = np.random.randint(100)
  31. socStr = "Battery: " + str(soc) + "%"
  32. return socStr
  33. def generateStatus(self):
  34. import numpy as np
  35. hr = np.random.randint(12) + 1
  36. min = np.random.randint(60)
  37. ampm = np.random.randint(1)
  38. statusStr = "Last Update: " + str(hr) + ":" + str(min)
  39. return statusStr
  40. if __name__ == '__main__':
  41. print("I never developed self-test, but if I did they would go here.")
  42. pt = ParsingTools()
  43. print("Testing macToString")
  44. print(pt.macToString(b'023430'))