mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +00:00
pcap reading by dispatch instead of iterator, this works also on Raspberry
This commit is contained in:
parent
2db41aad69
commit
88b60197fb
1 changed files with 16 additions and 12 deletions
|
@ -887,19 +887,23 @@ class pyPlcHomeplug():
|
||||||
|
|
||||||
def showStatus(self, s, selection=""):
|
def showStatus(self, s, selection=""):
|
||||||
self.callbackShowStatus(s, selection)
|
self.callbackShowStatus(s, selection)
|
||||||
|
|
||||||
|
def receiveCallback(self, timestamp, pkt, *args):
|
||||||
|
self.nPacketsReceived+=1
|
||||||
|
# print('%d' % (ts)) # the time stamp
|
||||||
|
# We received an ethernet package. Determine its type, and dispatch it to the related handler.
|
||||||
|
etherType = self.getEtherType(pkt)
|
||||||
|
if (etherType == 0x88E1): # it is a HomePlug message
|
||||||
|
self.myreceivebuffer = pkt
|
||||||
|
self.evaluateReceivedHomeplugPacket()
|
||||||
|
if (etherType == 0x86dd): # it is an IPv6 frame
|
||||||
|
self.ipv6.evaluateReceivedPacket(pkt)
|
||||||
|
|
||||||
def mainfunction(self):
|
def mainfunction(self):
|
||||||
# print("will evaluate self.sniffer")
|
# https://stackoverflow.com/questions/31305712/how-do-i-make-libpcap-pcap-loop-non-blocking
|
||||||
for ts, pkt in self.sniffer: # attention: for using this in non-blocking manner, we need the patch described above.
|
# Tell the sniffer to give max 100 received packets to the callback function:
|
||||||
self.nPacketsReceived+=1
|
self.sniffer.dispatch(100, self.receiveCallback, None)
|
||||||
# print('%d' % (ts)) # the time stamp
|
|
||||||
# We received an ethernet package. Determine its type, and dispatch it to the related handler.
|
|
||||||
etherType = self.getEtherType(pkt)
|
|
||||||
if (etherType == 0x88E1): # it is a HomePlug message
|
|
||||||
self.myreceivebuffer = pkt
|
|
||||||
self.evaluateReceivedHomeplugPacket()
|
|
||||||
if (etherType == 0x86dd): # it is an IPv6 frame
|
|
||||||
self.ipv6.evaluateReceivedPacket(pkt)
|
|
||||||
|
|
||||||
self.showStatus("nPacketsReceived=" + str(self.nPacketsReceived))
|
self.showStatus("nPacketsReceived=" + str(self.nPacketsReceived))
|
||||||
self.runPevSequencer() # run the message sequencer for the PEV side
|
self.runPevSequencer() # run the message sequencer for the PEV side
|
||||||
|
|
Loading…
Reference in a new issue