2022-10-20 19:29:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-11-08 11:01:54 +00:00
|
|
|
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
|
|
|
|
|
2022-12-09 11:06:10 +00:00
|
|
|
def compactHexMessage(mybytearray):
|
|
|
|
packetlength = len(mybytearray)
|
|
|
|
strHex = ""
|
|
|
|
for i in range(0, packetlength):
|
|
|
|
strHex = strHex + twoCharHex(mybytearray[i])
|
|
|
|
return strHex
|
|
|
|
|
2022-10-20 19:29:02 +00:00
|
|
|
def prettyMac(macByteArray):
|
|
|
|
s=""
|
2022-11-11 10:21:28 +00:00
|
|
|
length = len(macByteArray)
|
|
|
|
if (length!=6):
|
|
|
|
s="invalid MAC length " + str(length) + "!"
|
|
|
|
for i in range(0, length-1):
|
2022-10-20 19:29:02 +00:00
|
|
|
s = s + twoCharHex(macByteArray[i]) + ":"
|
2022-11-11 10:21:28 +00:00
|
|
|
s = s + twoCharHex(macByteArray[length-1])
|
2022-10-20 19:29:02 +00:00
|
|
|
return s
|