From 1c3bd15807146de97370f9a4f0a7bee15c26d4b3 Mon Sep 17 00:00:00 2001 From: uhi22 Date: Fri, 26 May 2023 21:51:33 +0200 Subject: [PATCH] tools: 5 channels in pcapconverter and scope --- pcapConverter.py | 9 +- scope.py | 286 +++++++++++++++++++---------------------------- 2 files changed, 126 insertions(+), 169 deletions(-) diff --git a/pcapConverter.py b/pcapConverter.py index b935a31..1a5f7e0 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 = 1000 +nLimitNumberOfPackets = 2000 def getManufacturerFromMAC(strMAC): @@ -134,6 +134,13 @@ def convertPcapToTxt(inputFileName): print("[" + str(packet.sniff_time) + "] EVSEPresentCurrent=" + str(i), file=fileOutValues) except: pass + try: + u = combineValueAndMultiplier(y["EVTargetVoltage.Value"], y["EVTargetVoltage.Multiplier"]) + print("[" + str(packet.sniff_time) + "] EVTargetVoltage=" + str(u), file=fileOutValues) + i = combineValueAndMultiplier(y["EVTargetCurrent.Value"], y["EVTargetCurrent.Multiplier"]) + print("[" + str(packet.sniff_time) + "] EVTargetCurrent=" + str(i), file=fileOutValues) + except: + pass try: soc = y["DC_EVStatus.EVRESSSOC"] print("[" + str(packet.sniff_time) + "] EVRESSSOC=" + str(soc), file=fileOutValues) diff --git a/scope.py b/scope.py index 1d96bf2..78f70b4 100644 --- a/scope.py +++ b/scope.py @@ -16,14 +16,43 @@ import time import sys # for argv +def addChannelNameToChannel(s): + global channelNames + blAlreadyPresent=0 + for i in range(len(channelNames)): + if (channelNames[i]==s): + blAlreadyPresent=1 + if (blAlreadyPresent==1): + #print("The name " + s + " is already present in the channel names. Nothing to do.") + return + # The new name is not known yet. Search an empty channel and store it there. + for i in range(len(channelNames)): + if (channelNames[i]==""): + channelNames[i]=s + print("Stored " + s + " as channel name for channel " + str(i)) + return + # if we come here, there was no free channel, and we discard the new name. + print("Discarding name " + s) + + +def addChannelData(name, time, value): + # adds a data point to the channel with the given name + global channelNames + global channelData + for i in range(len(channelNames)): + if (channelNames[i]==name): + channelData[i].append([time, float(value)]) + return + + root = Tk() -root.geometry("600x500") +root.geometry("750x500") lastKey = '' lblHelp = Label(root, justify= "left") lblHelp['text']="press ctrl C to exit" lblHelp.pack() -canvas_width = 590 +canvas_width = 750 canvas_height = 400 divisionsPerScreen = 10 @@ -32,7 +61,6 @@ c = Canvas(root, height=canvas_height) c.pack() - x0Scope = 10 y0Scope = 45 xSizeScope = canvas_width-30 @@ -51,197 +79,119 @@ 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_170340_tcpdump.pcap.values.txt" +inputFileName = "local/pcaps_converted/2023-05-12_174912_tcpdump.pcap.values.txt" fileIn = open(inputFileName, 'r') Lines = fileIn.readlines() -strCh1Color="#FFFF00" # yellow -strCh2Color="#10FF10" # green -strCh3Color="#4040FF" # blue +# yellow green blue red orange +channelColors = ["#FFFF00", "#10FF10", "#4040FF", "#FF4040", "#FFC000" ] +numberOfChannels = len(channelColors) +print(str(numberOfChannels) + " channels") + +channelNames = [] +channelData = [] + +for i in range(numberOfChannels): + channelNames.append("") # empty string for each channel + channelData.append([]) # empty list for each channel +channelOffsets = [] # will be appended dynamically below +channelPerDivs = [] # will be appended dynamically below -strChannelName1="" -strChannelName2="" -strChannelName3="" -ch1values = [] -ch2values = [] -ch3values = [] count = 0 for line in Lines: count += 1 - p1 = line.find("] ") - p2 = line.find("=") - if (p1>0) and (p2>p1+3): - s = line[p1+2:p2] - if (strChannelName1==""): - strChannelName1=s - else: - if ((strChannelName2=="") and (s!=strChannelName1)): - strChannelName2=s - else: - if ((strChannelName3=="") and (s!=strChannelName1) and (s!=strChannelName2)): - strChannelName3=s - if (s==strChannelName1): - sVal=line[p2+1:].strip() - ch1values.append(float(sVal)) - if (s==strChannelName2): - sVal=line[p2+1:].strip() - ch2values.append(float(sVal)) - if (s==strChannelName3): - sVal=line[p2+1:].strip() - ch3values.append(float(sVal)) + p1 = line.find("[") + p2 = line.find("] ") + p3 = line.find("=") + if (p1>=0) and (p2>p1) and (p3>p2+3): + strName = line[p2+2:p3] + addChannelNameToChannel(strName) # assign the found variable name to a channel, if not yet assigned + strVal=line[p3+1:].strip() + strTime=line[p1+1:p2].strip() + #print("Time >"+strTime+"<") + addChannelData(strName, strTime, strVal) #print("Line{}: {}".format(count, line.strip())) fileIn.close() +print("The channel names") +for i in range(numberOfChannels): + print(str(i) + " " + channelNames[i]) + +#print("The channel data") +#for i in range(numberOfChannels): +# print(str(i) + " " + channelNames[i]) +# for k in range(len(channelData[i])): +# t = channelData[i][k][0] +# y = channelData[i][k][1] +# print("t= " + t + " y= " + str(y) ) + # Hack: look which channel has the most samples. # Todo: This is not correct, because we have to use the time stamp instead of the sample number. maxSamples = 1 -if maxSamplesvMax): - vMax = v +# Auto-scaling of the y axis +for i in range(numberOfChannels): + vMin=channelData[i][0][1] + vMax=vMin + for v in channelData[i]: + #print(v) + if (v[1]vMax): + vMax = v[1] + print("For channel " + str(i) + " we have min " + str(vMin) + " and max " + str(vMax)) + vDelta = vMax - vMin + perDiv = 1 + if (vDelta/perDiv>10): + perDiv=2 + if (vDelta/perDiv>10): + perDiv=5 + if (vDelta/perDiv>10): + perDiv=10 + if (vDelta/perDiv>10): + perDiv=20 + if (vDelta/perDiv>10): + perDiv=50 + if (vDelta/perDiv>10): + perDiv=100 + print("Scale: " + str(perDiv) + "/div") -print("min=" + str(vMin) + ", max=" + str(vMax)) -vDelta = vMax - vMin -perDiv1 = 1 -if (vDelta/perDiv1>10): - perDiv1=2 -if (vDelta/perDiv1>10): - perDiv1=5 -if (vDelta/perDiv1>10): - perDiv1=10 -if (vDelta/perDiv1>10): - perDiv1=20 -if (vDelta/perDiv1>10): - perDiv1=50 -if (vDelta/perDiv1>10): - perDiv1=100 -print("Scale: " + str(perDiv1) + "/div") - -offs1 = 0 -while ((offs1+perDiv1)vMax): - vMax = v - -print("min=" + str(vMin) + ", max=" + str(vMax)) -vDelta = vMax - vMin -perDiv2 = 1 -if (vDelta/perDiv2>10): - perDiv2=2 -if (vDelta/perDiv2>10): - perDiv2=5 -if (vDelta/perDiv2>10): - perDiv2=10 -if (vDelta/perDiv2>10): - perDiv2=20 -if (vDelta/perDiv2>10): - perDiv2=50 -if (vDelta/perDiv2>10): - perDiv2=100 -print("Scale: " + str(perDiv2) + "/div") - -offs2 = 0 -while ((offs2+perDiv2)vMax): - vMax = v - -print("min=" + str(vMin) + ", max=" + str(vMax)) -vDelta = vMax - vMin -perDiv3 = 1 -if (vDelta/perDiv3>10): - perDiv3=2 -if (vDelta/perDiv3>10): - perDiv3=5 -if (vDelta/perDiv3>10): - perDiv3=10 -if (vDelta/perDiv3>10): - perDiv3=20 -if (vDelta/perDiv3>10): - perDiv3=50 -if (vDelta/perDiv3>10): - perDiv3=100 -print("Scale: " + str(perDiv3) + "/div") - -offs3 = 0 -while ((offs3+perDiv3)