July 2021
25
def processPacket(self):
ret_ = True
if self.gui is None:
print("SOP")
header = bytearray(self.ser.readbytes(self.headerLength - 2))
if self.processHeader(header):
if self.rawFilename == None:
self.rawFilename = format( "RAW_S%X_%X_R%X_%X.txt" % (self.senderAddr, self.senderID, self.recipientAddr, self.recipientID) )
self.rawFile = ResFile("",self.test_directory_path, self.rawFilename)
packetBody = self.ser.readbytes(self.lenPacket - self.headerLength)
packet = bytes("#@".encode() + packetBody)
#print(packet)
self.rawFile.appendTestFileString(packet.decode('utf-8'))
header[self.chksumOffset] = 0
header[self.chksum 1] = 0
header[self.chksum 2] = 0
header[self.chksum 3] = 0
packet = bytes("#@".encode() + packetBody)
#print(packet)
f = Fletcher32_16()
f.update(packet)
self.calculatedChecksum = f.digest()
if self.parsedChecksum != self.calculatedChecksum:
print("self.calculatedChecksum=",hex(self.calculatedChecksum))
print("c,p=", hex(self.calculatedChecksum), hex(self.parsedChecksum))
print("CHECKSUMS DO NOT MATCH!")
ret_ = False
elif False == self.processPacketBody(packetBody):
ret_ = False
if self.gui is None:
print("-------------")
return ret_;
if __name__ == "__main__":
global ser
portName='CultivoUSB'
if (len(sys.argv) > 1):
if re.match('-i',sys.argv[1]): # if an argument present, and it is -i run GUI version
app = BPPReader(sys.argv[3],BPPReader_GUI(None))
print("Goodbye")
if re.match('-p',sys.argv[1]):
portName = sys.argv[2]
rdr = BPPReader(portName,None)
rdr.start()
try:
while rdr.stop is False:
sys.stdin.read(1)
except KeyboardInterrupt:
rdr.stop = True;
rdr.join()
print("Goodbye")
else:
rdr = BPPReader(portName,None)
rdr.start()
try:
while rdr.stop is False:
sys.stdin.read(1)
except KeyboardInterrupt: