-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathhelpers.py
52 lines (42 loc) · 1.61 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def twoCharHex(b):
strHex = "%0.2X" % b
return strHex
def showAsHex(mybytearray, description=""):
packetlength = len(mybytearray)
strHex = ""
for i in range(0, packetlength):
strHex = strHex + twoCharHex(mybytearray[i]) + " "
print(description + "(" + str(packetlength) + "bytes) = " + strHex)
def prettyHexMessage(mybytearray, description=""):
packetlength = len(mybytearray)
strHex = ""
for i in range(0, packetlength):
strHex = strHex + twoCharHex(mybytearray[i]) + " "
return description + "(" + str(packetlength) + "bytes) = " + strHex
def compactHexMessage(mybytearray):
packetlength = len(mybytearray)
strHex = ""
for i in range(0, packetlength):
strHex = strHex + twoCharHex(mybytearray[i])
return strHex
def prettyMac(macByteArray):
s=""
length = len(macByteArray)
if (length!=6):
s="invalid MAC length " + str(length) + "!"
for i in range(0, length-1):
s = s + twoCharHex(macByteArray[i]) + ":"
s = s + twoCharHex(macByteArray[length-1])
return s
def combineValueAndMultiplier(value, mult):
# input: value and multipliers as strings
# output: The numerical value x* 10^mult
x = float(value)
m = int(mult)
return x * 10**m
if __name__ == "__main__":
print("Testing the helpers")
print(str(combineValueAndMultiplier("123", "0")) + " should be 123")
print(str(combineValueAndMultiplier("5678", "-1")) + " should be 567.8")
print(str(combineValueAndMultiplier("-17", "1")) + " should be -170")
print(str(combineValueAndMultiplier("4", "4")) + " should be 40000")