From 7f233f1baad91e84d13c5e79d90b764fabd32251 Mon Sep 17 00:00:00 2001 From: uhi22 Date: Mon, 19 Jun 2023 07:52:08 +0200 Subject: [PATCH] exiConnector: improved demo mode, to fix issue #6 --- DemoExiLog.txt | 24 ++++++++++++++++++++ exiConnector.py | 58 ++++++++++++++++++++++++++---------------------- pcapConverter.py | 2 +- scope.py | 2 +- 4 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 DemoExiLog.txt diff --git a/DemoExiLog.txt b/DemoExiLog.txt new file mode 100644 index 0000000..c35c83a --- /dev/null +++ b/DemoExiLog.txt @@ -0,0 +1,24 @@ +init +Dh 80400040 +ED 809a02000000000000000011d00000 +DD 809A022189CBF75B9625A951E020040080 +ED 809a022189cbf75b9625a95198 +DD 809A022189CBF75B9625A951A00120024100C4 +ED 809a022189cbf75b9625a951b2001280 +DD 809A022189CBF75B9625A951C000 +ED 809a022189cbf75b9625a950b8 +DD 809A022189CBF75B9625A950C00200 +ED 809a022189cbf75b9625a950b8 +DD 809A022189CBF75B9625A950C00000 +ED 809a022189cbf75b9625a9507191400500c8c82324701900 +DD 809A022189CBF75B9625A9508002002802800007FFFFF8383FFFC045500000000101857040101C29C8408143C894080C03C08143403C4406010200 +ED 809a022189cbf75b9625a9507191400500c8c82324701900 +DD 809A022189CBF75B9625A9508000002802800007FFFFF8383FFFC045500000000101871048101C2209C08143C894080C03C08143403C4406010200 +ED 809a022189cbf75b9625a95011400500 +DD 809A022189CBF75B9625A95020000200000400 +ED 809a022189cbf75b9625a95011400500 +DD 809A022189CBF75B9625A95020004080000000 +ED 809a022189cbf75b9625a95151400500c9cc0206401000 +DD 809A022189CBF75B9625A9516000408000010284904800 +ED 809a022189cbf75b9625a9513022800a0800 +closing diff --git a/exiConnector.py b/exiConnector.py index 5d57443..6f5cd52 100644 --- a/exiConnector.py +++ b/exiConnector.py @@ -261,31 +261,36 @@ def testReadExiFromSnifferFile(): #print(s) testDecoder(s, "DD", "") -def testReadExiFromExiLogFile(): - file1 = open('PevExiLog.txt', 'r') - fileOut = open('PevExiLog.decoded.txt', 'w') - # example: "ED 809a02004080c1014181c210b8" - # example with timestamp: "2022-12-20T08:17:15.055755=ED 809a02004080c1014181c21198" - Lines = file1.readlines() - for myLine in Lines: - posOfEqual=myLine.find("=") - if (posOfEqual>0): - # we have an equal-sign. Take the string behind it. - strToDecode=myLine[posOfEqual+1:] - else: - # no equal-sign. Take the complete line. - strToDecode=myLine - if (strToDecode[1:3]=="D "): # it is DIN - posOfSpace=2 - s = strToDecode[posOfSpace+1:] # The part after the " " contains the EXI hex data. - s = s.replace(" ", "") # Remove blanks - s = s.replace("\n", "") # Remove line feeds - #print(s) - decoded=exiDecode(s, "DD") - print(decoded) - print(myLine.replace("\n", "") + " means:", file=fileOut) - print(decoded, file=fileOut) - fileOut.close() +def testReadExiFromExiLogFile(strLogFileName): + try: + file1 = open(strLogFileName, 'r') + fileOut = open('PevExiLog.decoded.txt', 'w') + # example: "ED 809a02004080c1014181c210b8" + # example with timestamp: "2022-12-20T08:17:15.055755=ED 809a02004080c1014181c21198" + Lines = file1.readlines() + for myLine in Lines: + posOfEqual=myLine.find("=") + if (posOfEqual>0): + # we have an equal-sign. Take the string behind it. + strToDecode=myLine[posOfEqual+1:] + else: + # no equal-sign. Take the complete line. + strToDecode=myLine + if (strToDecode[1:3]=="D "): # it is DIN + posOfSpace=2 + s = strToDecode[posOfSpace+1:] # The part after the " " contains the EXI hex data. + s = s.replace(" ", "") # Remove blanks + s = s.replace("\n", "") # Remove line feeds + #print(s) + decoded=exiDecode(s, "DD") + print(decoded) + print(myLine.replace("\n", "") + " means:", file=fileOut) + print(decoded, file=fileOut) + fileOut.close() + except: + print("Could not open " + strLogFileName) + if (strLogFileName == "PevExiLog.txt"): + print("This is no problem. The PevExiLog.txt will be created when the pyPLC runs in PevMode, and can be decoded afterwards.") def testTimeConsumption(): strHex = "809a001150400000c80006400000" @@ -314,7 +319,8 @@ if __name__ == "__main__": testTimeConsumption() exit() if (True): - testReadExiFromExiLogFile() + testReadExiFromExiLogFile('DemoExiLog.txt') + testReadExiFromExiLogFile('PevExiLog.txt') exit() if (False): diff --git a/pcapConverter.py b/pcapConverter.py index 1a5f7e0..6319117 100644 --- a/pcapConverter.py +++ b/pcapConverter.py @@ -33,7 +33,7 @@ import json directory = 'local/pcaps_to_convert' # stop the evaluation after this number of packets. Set to zero to have no limit. -nLimitNumberOfPackets = 2000 +nLimitNumberOfPackets = -1 def getManufacturerFromMAC(strMAC): diff --git a/scope.py b/scope.py index 78f70b4..c41afcc 100644 --- a/scope.py +++ b/scope.py @@ -79,7 +79,7 @@ c.create_line(x0Scope, y0Scope, x0Scope, y0Scope+ySizeScope, fill="#FFFFFF") c.create_line(x0Scope+xSizeScope, y0Scope+ySizeScope, x0Scope+xSizeScope, y0Scope, fill="#FFFFFF") c.create_line(x0Scope+xSizeScope, y0Scope+ySizeScope, x0Scope, y0Scope+ySizeScope, fill="#FFFFFF") -inputFileName = "local/pcaps_converted/2023-05-12_174912_tcpdump.pcap.values.txt" +inputFileName = "local/pcaps_to_convert/ccm_spi_ioniq_compleo_full_charge_sequence_ended_on_charger.txt.pcap.values.txt" fileIn = open(inputFileName, 'r') Lines = fileIn.readlines()