mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +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'
|
directory = 'local/pcaps_to_convert'
|
||||||
|
|
||||||
# stop the evaluation after this number of packets. Set to zero to have no limit.
|
# stop the evaluation after this number of packets. Set to zero to have no limit.
|
||||||
nLimitNumberOfPackets = 1000
|
nLimitNumberOfPackets = 2000
|
||||||
|
|
||||||
|
|
||||||
def getManufacturerFromMAC(strMAC):
|
def getManufacturerFromMAC(strMAC):
|
||||||
|
@ -134,6 +134,13 @@ def convertPcapToTxt(inputFileName):
|
||||||
print("[" + str(packet.sniff_time) + "] EVSEPresentCurrent=" + str(i), file=fileOutValues)
|
print("[" + str(packet.sniff_time) + "] EVSEPresentCurrent=" + str(i), file=fileOutValues)
|
||||||
except:
|
except:
|
||||||
pass
|
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:
|
try:
|
||||||
soc = y["DC_EVStatus.EVRESSSOC"]
|
soc = y["DC_EVStatus.EVRESSSOC"]
|
||||||
print("[" + str(packet.sniff_time) + "] EVRESSSOC=" + str(soc), file=fileOutValues)
|
print("[" + str(packet.sniff_time) + "] EVRESSSOC=" + str(soc), file=fileOutValues)
|
||||||
|
|
286
scope.py
286
scope.py
|
@ -16,14 +16,43 @@ import time
|
||||||
import sys # for argv
|
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 = Tk()
|
||||||
root.geometry("600x500")
|
root.geometry("750x500")
|
||||||
lastKey = ''
|
lastKey = ''
|
||||||
lblHelp = Label(root, justify= "left")
|
lblHelp = Label(root, justify= "left")
|
||||||
lblHelp['text']="press ctrl C to exit"
|
lblHelp['text']="press ctrl C to exit"
|
||||||
lblHelp.pack()
|
lblHelp.pack()
|
||||||
|
|
||||||
canvas_width = 590
|
canvas_width = 750
|
||||||
canvas_height = 400
|
canvas_height = 400
|
||||||
divisionsPerScreen = 10
|
divisionsPerScreen = 10
|
||||||
|
|
||||||
|
@ -32,7 +61,6 @@ c = Canvas(root,
|
||||||
height=canvas_height)
|
height=canvas_height)
|
||||||
c.pack()
|
c.pack()
|
||||||
|
|
||||||
|
|
||||||
x0Scope = 10
|
x0Scope = 10
|
||||||
y0Scope = 45
|
y0Scope = 45
|
||||||
xSizeScope = canvas_width-30
|
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+xSizeScope, y0Scope, fill="#FFFFFF")
|
||||||
c.create_line(x0Scope+xSizeScope, y0Scope+ySizeScope, x0Scope, y0Scope+ySizeScope, 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')
|
fileIn = open(inputFileName, 'r')
|
||||||
Lines = fileIn.readlines()
|
Lines = fileIn.readlines()
|
||||||
|
|
||||||
strCh1Color="#FFFF00" # yellow
|
# yellow green blue red orange
|
||||||
strCh2Color="#10FF10" # green
|
channelColors = ["#FFFF00", "#10FF10", "#4040FF", "#FF4040", "#FFC000" ]
|
||||||
strCh3Color="#4040FF" # blue
|
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
|
count = 0
|
||||||
for line in Lines:
|
for line in Lines:
|
||||||
count += 1
|
count += 1
|
||||||
p1 = line.find("] ")
|
p1 = line.find("[")
|
||||||
p2 = line.find("=")
|
p2 = line.find("] ")
|
||||||
if (p1>0) and (p2>p1+3):
|
p3 = line.find("=")
|
||||||
s = line[p1+2:p2]
|
if (p1>=0) and (p2>p1) and (p3>p2+3):
|
||||||
if (strChannelName1==""):
|
strName = line[p2+2:p3]
|
||||||
strChannelName1=s
|
addChannelNameToChannel(strName) # assign the found variable name to a channel, if not yet assigned
|
||||||
else:
|
strVal=line[p3+1:].strip()
|
||||||
if ((strChannelName2=="") and (s!=strChannelName1)):
|
strTime=line[p1+1:p2].strip()
|
||||||
strChannelName2=s
|
#print("Time >"+strTime+"<")
|
||||||
else:
|
addChannelData(strName, strTime, strVal)
|
||||||
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))
|
|
||||||
#print("Line{}: {}".format(count, line.strip()))
|
#print("Line{}: {}".format(count, line.strip()))
|
||||||
fileIn.close()
|
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.
|
# 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.
|
# Todo: This is not correct, because we have to use the time stamp instead of the sample number.
|
||||||
maxSamples = 1
|
maxSamples = 1
|
||||||
if maxSamples<len(ch1values):
|
for i in range(numberOfChannels):
|
||||||
maxSamples=len(ch1values)
|
if maxSamples<len(channelData[i]):
|
||||||
if maxSamples<len(ch2values):
|
maxSamples=len(channelData[i])
|
||||||
maxSamples=len(ch2values)
|
print("maxSamples " + str(maxSamples))
|
||||||
if maxSamples<len(ch3values):
|
|
||||||
maxSamples=len(ch3values)
|
|
||||||
dxPerSample = xSizeScope / maxSamples
|
dxPerSample = xSizeScope / maxSamples
|
||||||
|
|
||||||
vMin=ch1values[0]
|
# Auto-scaling of the y axis
|
||||||
vMax=ch1values[0]
|
for i in range(numberOfChannels):
|
||||||
for v in ch1values:
|
vMin=channelData[i][0][1]
|
||||||
#print(v)
|
vMax=vMin
|
||||||
if (v<vMin):
|
for v in channelData[i]:
|
||||||
vMin = v
|
#print(v)
|
||||||
if (v>vMax):
|
if (v[1]<vMin):
|
||||||
vMax = v
|
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
|
||||||
|
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))
|
offs = 0
|
||||||
vDelta = vMax - vMin
|
while ((offs+perDiv)<vMin):
|
||||||
perDiv1 = 1
|
offs+=perDiv
|
||||||
if (vDelta/perDiv1>10):
|
print("Offset: " + str(offs))
|
||||||
perDiv1=2
|
channelOffsets.append(offs)
|
||||||
if (vDelta/perDiv1>10):
|
channelPerDivs.append(perDiv)
|
||||||
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)<vMin):
|
|
||||||
offs1+=perDiv1
|
|
||||||
print("Offset: " + str(offs1))
|
|
||||||
|
|
||||||
x = x0Scope
|
|
||||||
for v in ch1values:
|
|
||||||
yPix = y0Scope+ySizeScope - (v - offs1)/perDiv1 * 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]
|
for i in range(numberOfChannels):
|
||||||
vMax=ch3values[0]
|
x = x0Scope
|
||||||
for v in ch3values:
|
for v in channelData[i]:
|
||||||
print(v)
|
yPix = y0Scope+ySizeScope - (v[1] - channelOffsets[i])/channelPerDivs[i] * ySizeScope / divisionsPerScreen
|
||||||
if (v<vMin):
|
x1, y1 = ( x - 1 ), ( yPix - 1 )
|
||||||
vMin = v
|
x2, y2 = ( x + 1 ), ( yPix + 1 )
|
||||||
if (v>vMax):
|
c.create_line(x1, y1, x2, y2, fill=channelColors[i])
|
||||||
vMax = v
|
c.create_line(x1, y2, x2, y1, fill=channelColors[i])
|
||||||
|
x+=dxPerSample
|
||||||
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)
|
|
||||||
x+=dxPerSample
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
y0Legend = 0
|
y0Legend = 0
|
||||||
ySizeLegend = 40
|
ySizeLegend = 40
|
||||||
# legend background
|
# legend background
|
||||||
c.create_rectangle(x0Scope, y0Legend, x0Scope+xSizeScope, y0Legend+ySizeLegend, fill="black")
|
c.create_rectangle(x0Scope, y0Legend, x0Scope+xSizeScope, y0Legend+ySizeLegend, fill="black")
|
||||||
|
|
||||||
c.create_text(x0Scope,y0Legend+0, text=strChannelName1, anchor="nw", fill=strCh1Color)
|
for i in range(numberOfChannels):
|
||||||
c.create_text(x0Scope,y0Legend+10, text=str(perDiv1) + "/div", anchor="nw", fill=strCh1Color)
|
c.create_text(x0Scope+150*i,y0Legend+0, text=channelNames[i], anchor="nw", fill=channelColors[i])
|
||||||
c.create_text(x0Scope,y0Legend+20, text="Offs " + str(offs1), anchor="nw", fill=strCh1Color)
|
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 = ''
|
lastKey = ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue