mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
tools: 5 channels in pcapconverter and scope
This commit is contained in:
parent
719ed51d20
commit
1c3bd15807
2 changed files with 126 additions and 169 deletions
|
@ -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)
|
||||
|
|
274
scope.py
274
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,177 +79,105 @@ 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 maxSamples<len(ch1values):
|
||||
maxSamples=len(ch1values)
|
||||
if maxSamples<len(ch2values):
|
||||
maxSamples=len(ch2values)
|
||||
if maxSamples<len(ch3values):
|
||||
maxSamples=len(ch3values)
|
||||
for i in range(numberOfChannels):
|
||||
if maxSamples<len(channelData[i]):
|
||||
maxSamples=len(channelData[i])
|
||||
print("maxSamples " + str(maxSamples))
|
||||
|
||||
dxPerSample = xSizeScope / maxSamples
|
||||
|
||||
vMin=ch1values[0]
|
||||
vMax=ch1values[0]
|
||||
for v in ch1values:
|
||||
# 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<vMin):
|
||||
vMin = v
|
||||
if (v>vMax):
|
||||
vMax = v
|
||||
|
||||
print("min=" + str(vMin) + ", max=" + str(vMax))
|
||||
if (v[1]<vMin):
|
||||
vMin = v[1]
|
||||
if (v[1]>vMax):
|
||||
vMax = v[1]
|
||||
print("For channel " + str(i) + " we have min " + str(vMin) + " and 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")
|
||||
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")
|
||||
|
||||
offs1 = 0
|
||||
while ((offs1+perDiv1)<vMin):
|
||||
offs1+=perDiv1
|
||||
print("Offset: " + str(offs1))
|
||||
offs = 0
|
||||
while ((offs+perDiv)<vMin):
|
||||
offs+=perDiv
|
||||
print("Offset: " + str(offs))
|
||||
channelOffsets.append(offs)
|
||||
channelPerDivs.append(perDiv)
|
||||
|
||||
|
||||
for i in range(numberOfChannels):
|
||||
x = x0Scope
|
||||
for v in ch1values:
|
||||
yPix = y0Scope+ySizeScope - (v - offs1)/perDiv1 * ySizeScope / divisionsPerScreen
|
||||
for v in channelData[i]:
|
||||
yPix = y0Scope+ySizeScope - (v[1] - channelOffsets[i])/channelPerDivs[i] * ySizeScope / divisionsPerScreen
|
||||
x1, y1 = ( x - 1 ), ( yPix - 1 )
|
||||
x2, y2 = ( x + 1 ), ( yPix + 1 )
|
||||
c.create_line(x1, y1, x2, y2, fill=strCh1Color)
|
||||
c.create_line(x1, y2, x2, y1, fill=strCh1Color)
|
||||
x+=dxPerSample
|
||||
|
||||
vMin=ch2values[0]
|
||||
vMax=ch2values[0]
|
||||
for v in ch2values:
|
||||
#print(v)
|
||||
if (v<vMin):
|
||||
vMin = v
|
||||
if (v>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)<vMin):
|
||||
offs2+=perDiv2
|
||||
print("Offset: " + str(offs2))
|
||||
|
||||
x = x0Scope
|
||||
for v in ch2values:
|
||||
yPix = y0Scope+ySizeScope - (v - offs2)/perDiv2 * ySizeScope / divisionsPerScreen
|
||||
x1, y1 = ( x - 1 ), ( yPix - 1 )
|
||||
x2, y2 = ( x + 1 ), ( yPix + 1 )
|
||||
c.create_line(x1, y1, x2, y2, fill=strCh2Color)
|
||||
c.create_line(x1, y2, x2, y1, fill=strCh2Color)
|
||||
x+=dxPerSample
|
||||
|
||||
|
||||
vMin=ch3values[0]
|
||||
vMax=ch3values[0]
|
||||
for v in ch3values:
|
||||
print(v)
|
||||
if (v<vMin):
|
||||
vMin = v
|
||||
if (v>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)<vMin):
|
||||
offs3+=perDiv3
|
||||
print("Offset: " + str(offs3))
|
||||
|
||||
x = x0Scope
|
||||
for v in ch3values:
|
||||
yPix = y0Scope+ySizeScope - (v - offs3)/perDiv3 * ySizeScope / divisionsPerScreen
|
||||
x1, y1 = ( x - 3 ), ( yPix - 3 )
|
||||
x2, y2 = ( x + 3 ), ( yPix + 3 )
|
||||
c.create_line(x1, y1, x2, y2, fill=strCh3Color)
|
||||
c.create_line(x1, y2, x2, y1, fill=strCh3Color)
|
||||
c.create_line(x1, y1, x2, y2, fill=channelColors[i])
|
||||
c.create_line(x1, y2, x2, y1, fill=channelColors[i])
|
||||
x+=dxPerSample
|
||||
|
||||
|
||||
|
@ -231,17 +187,11 @@ ySizeLegend = 40
|
|||
# legend background
|
||||
c.create_rectangle(x0Scope, y0Legend, x0Scope+xSizeScope, y0Legend+ySizeLegend, fill="black")
|
||||
|
||||
c.create_text(x0Scope,y0Legend+0, text=strChannelName1, anchor="nw", fill=strCh1Color)
|
||||
c.create_text(x0Scope,y0Legend+10, text=str(perDiv1) + "/div", anchor="nw", fill=strCh1Color)
|
||||
c.create_text(x0Scope,y0Legend+20, text="Offs " + str(offs1), anchor="nw", fill=strCh1Color)
|
||||
for i in range(numberOfChannels):
|
||||
c.create_text(x0Scope+150*i,y0Legend+0, text=channelNames[i], anchor="nw", fill=channelColors[i])
|
||||
c.create_text(x0Scope+150*i,y0Legend+10, text=str(channelPerDivs[i]) + "/div", anchor="nw", fill=channelColors[i])
|
||||
c.create_text(x0Scope+150*i,y0Legend+20, text="Offs " + str(channelOffsets[i]), anchor="nw", fill=channelColors[i])
|
||||
|
||||
c.create_text(x0Scope+150,y0Legend+0, text=strChannelName2, anchor="nw", fill=strCh2Color)
|
||||
c.create_text(x0Scope+150,y0Legend+10, text=str(perDiv2) + "/div", anchor="nw", fill=strCh2Color)
|
||||
c.create_text(x0Scope+150,y0Legend+20, text="Offs " + str(offs2), anchor="nw", fill=strCh2Color)
|
||||
|
||||
c.create_text(x0Scope+300,y0Legend+0, text=strChannelName3, anchor="nw", fill=strCh3Color)
|
||||
c.create_text(x0Scope+300,y0Legend+10, text=str(perDiv3) + "/div", anchor="nw", fill=strCh3Color)
|
||||
c.create_text(x0Scope+300,y0Legend+20, text="Offs " + str(offs3), anchor="nw", fill=strCh3Color)
|
||||
|
||||
lastKey = ''
|
||||
|
||||
|
|
Loading…
Reference in a new issue