tooling: claralogConverter changed path and ignore already decoded files

This commit is contained in:
uhi22 2024-01-20 21:36:38 +01:00
parent c0bc567f01
commit 80aec67c4d

View file

@ -27,7 +27,7 @@ from helpers import combineValueAndMultiplier
import json
# The path where the script will search for pcap files:
directory = 'local/pcaps_to_convert'
directory = '../clara-logs'
# stop the evaluation after this number of packets. Set to zero to have no limit.
nLimitNumberOfPackets = -1
@ -42,8 +42,13 @@ nLimitNumberOfPackets = -1
def convertClaralogToTxt(inputFileName):
global nLimitNumberOfPackets
global directory
outputFileName = inputFileName + '.decoded.txt'
# todo: if output file exists
if (os.path.isfile(os.path.join(directory, outputFileName))):
print("output file " + outputFileName + " already exists. Nothing to do.")
return
fileIn = open(inputFileName, 'r')
fileOut = open(inputFileName + '.decoded.txt', 'w')
fileOut = open(outputFileName, 'w')
print("# generated by claralogConverter.py", file=fileOut)
print("# https://github.com/uhi22/pyPLC", file=fileOut)
fileOutValues = open(inputFileName + '.values.txt', 'w')
@ -60,12 +65,13 @@ def convertClaralogToTxt(inputFileName):
numberOfPackets+=1
#print(packet)
print(line.strip(), file=fileOut)
posTcpPayload = line.find(": 01 fe 80 01 00")
lineWithoutBlanks = line.replace(" ", "")
posTcpPayload = lineWithoutBlanks.find(":01fe800100")
if posTcpPayload>0:
# we found the V2GTP header.
tcppayload = line[posTcpPayload + 2:] # everything until the end of the line is the data
# this gives a string of hex values, separated by " ", e.g. "01 fe 80 01"
s = tcppayload.replace(" ", "") # remove spaces
tcppayload = lineWithoutBlanks[posTcpPayload + 1:] # everything until the end of the line is the data
# this gives a string of hex values, separated by " ", e.g. "01fe8001"
s = tcppayload
if (s[0:8]=="01fe8001"):
# it is a V2GTP header with EXI content
strExi = s[16:] # remove V2GTP header (8 bytes, means 16 hex characters)