mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
exiconnector made compatible for Raspberry
This commit is contained in:
parent
e4a7cd3373
commit
f61f68a0ab
2 changed files with 63 additions and 48 deletions
|
@ -14,64 +14,72 @@ Start putty and connect to the raspberry.
|
||||||
Install samba server on the raspberry, to be able to access the files from remote. https://www.elektronik-kompendium.de/sites/raspberry-pi/2007071.htm
|
Install samba server on the raspberry, to be able to access the files from remote. https://www.elektronik-kompendium.de/sites/raspberry-pi/2007071.htm
|
||||||
|
|
||||||
Install wireshark
|
Install wireshark
|
||||||
sudo apt-get install wireshark
|
```
|
||||||
|
sudo apt-get install wireshark
|
||||||
|
```
|
||||||
Choose "yes" for the question whether other users shall be able to trace network traffic.
|
Choose "yes" for the question whether other users shall be able to trace network traffic.
|
||||||
|
|
||||||
cd $home
|
|
||||||
mkdir myprogs
|
|
||||||
cd myprogs
|
|
||||||
|
|
||||||
git clone http://github.com/uhi22/pyPlc
|
Clone the two github repositories, and compile the OpenV2Gx EXI decoder/encoder:
|
||||||
|
```
|
||||||
git clone http://github.com/uhi22/OpenV2Gx
|
cd $home
|
||||||
cd OpenV2Gx/Release
|
mkdir myprogs
|
||||||
make
|
cd myprogs
|
||||||
|
git clone http://github.com/uhi22/pyPlc
|
||||||
|
git clone http://github.com/uhi22/OpenV2Gx
|
||||||
|
cd OpenV2Gx/Release
|
||||||
|
make
|
||||||
|
```
|
||||||
|
(this may take some minutes)
|
||||||
|
(In case you later change something in the code, use `make all` to build again.)
|
||||||
|
|
||||||
Test the EXI decoder/encoder
|
Test the EXI decoder/encoder
|
||||||
./OpenV2G DD809a0010d0400000c800410c8000
|
```
|
||||||
./OpenV2G EDa
|
cd $home/myprogs/OpenV2Gx/Release
|
||||||
|
./OpenV2G.exe DD809a0010d0400000c800410c8000
|
||||||
|
./OpenV2G.exe EDB_5555aaaa5555aaaa
|
||||||
|
```
|
||||||
|
This should run without error and show the decoded/encoded data in the command window.
|
||||||
|
|
||||||
cd $home/myprogs/pyPlc
|
Now we go to the python part.
|
||||||
|
```
|
||||||
|
cd $home/myprogs/pyPlc
|
||||||
|
```
|
||||||
|
|
||||||
Check python version
|
Check python version
|
||||||
python --version
|
|
||||||
|
`python --version`
|
||||||
reports e.g. 3.9.2.
|
reports e.g. 3.9.2.
|
||||||
|
|
||||||
Install the python library for accessing the network interface:
|
Install the python library for accessing the network interface.
|
||||||
python -m pip install --upgrade pcap-ct
|
Also for the superuser (otherwise the import pcap fails).
|
||||||
also for the superuser (otherwise the import pcap fails)
|
|
||||||
sudo python -m pip install --upgrade pcap-ct
|
```
|
||||||
|
python -m pip install --upgrade pcap-ct
|
||||||
|
sudo python -m pip install --upgrade pcap-ct
|
||||||
|
```
|
||||||
|
|
||||||
Try-out whether the python is able to sniff ethernet packets:
|
Try-out whether the python is able to sniff ethernet packets:
|
||||||
cd $home/myprogs/pyPlc/tests
|
```
|
||||||
python test_pcap.py
|
cd $home/myprogs/pyPlc/tests
|
||||||
|
python test_pcap.py
|
||||||
|
```
|
||||||
Result: Fails due to missing permission. This is normal, we need to run with superuser permissions.
|
Result: Fails due to missing permission. This is normal, we need to run with superuser permissions.
|
||||||
sudo python test_pcap.py
|
```
|
||||||
This should run through loops 0 to 9. If it stucks at Loop 0, the
|
sudo python test_pcap.py
|
||||||
patch for non-blocking is missing.
|
```
|
||||||
|
|
||||||
Patch is not needed if we use self.sniffer.dispatch.
|
|
||||||
|
|
||||||
Patch the pcap-ct for non-blocking usage:
|
|
||||||
Navigate to /usr/local/lib/python3.9/dist-packages/pcap
|
|
||||||
cd /usr/local/lib/python3.9/dist-packages/pcap
|
|
||||||
Open the file _pcap.py with superuser permissions:
|
|
||||||
sudo nano _pcap.py
|
|
||||||
Scroll to "def __next__".
|
|
||||||
Under the condition "if n == 0: # timeout" replace the line
|
|
||||||
continue
|
|
||||||
by
|
|
||||||
raise StopIteration
|
|
||||||
This issue is discussed in https://github.com/karpierz/pcap-ct/issues/9.
|
|
||||||
|
|
||||||
Try again
|
|
||||||
sudo python test_pcap.py
|
|
||||||
This should run through loops 0 to 9.
|
This should run through loops 0 to 9.
|
||||||
|
|
||||||
Problem: Each loop needs around 2 seconds. This is not intended. The 10ms timeout
|
Try-out the cooperation of Python with the EXI encoder/decoder:
|
||||||
seems not to work (timeout_ms=10). On win10, this works perfect.
|
```
|
||||||
On Raspberry, the combination of iterator and non-blocking does not work, see
|
python exiConnector.py
|
||||||
https://stackoverflow.com/questions/31305712/how-do-i-make-libpcap-pcap-loop-non-blocking.
|
```
|
||||||
Solution: Change to self.sniffer.dispatch instead of for ts, pkt in self.sniffer.
|
This should run some decoder/encoder tests and report in the end "Number of fails: 0".
|
||||||
|
|
||||||
|
|
||||||
|
Start the EVSE `sudo python pyPlc.py E`.
|
||||||
|
Open a second console window, and start here the pev in simulation mode
|
||||||
|
`sudo python pyPlc.py P S`.
|
||||||
|
We should see how the EVSE and PEV are talking to each other.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
# Example data:
|
# Example data:
|
||||||
# (1) From the Ioniq:
|
# (1) From the Ioniq:
|
||||||
|
@ -83,7 +84,13 @@ exiHexDemoSupportedApplicationProtocolRequest2="8000ebab9371d34b9b79d189a98989c1
|
||||||
|
|
||||||
|
|
||||||
# Configuration of the exi converter tool
|
# Configuration of the exi converter tool
|
||||||
pathToOpenV2GExe = "..\\OpenV2Gx\\Release\\OpenV2G.exe";
|
if os.name == "nt":
|
||||||
|
# Windows: Path to the EXI decoder/encoder
|
||||||
|
pathToOpenV2GExe = "..\\OpenV2Gx\\Release\\OpenV2G.exe"
|
||||||
|
else:
|
||||||
|
# Linux: Path to the EXI decoder/encoder
|
||||||
|
pathToOpenV2GExe = "../OpenV2Gx/Release/OpenV2G.exe";
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
def exiHexToByteArray(hexString):
|
def exiHexToByteArray(hexString):
|
||||||
|
@ -235,8 +242,8 @@ def testReadExiFromFile():
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
nFail=0
|
nFail=0
|
||||||
print("Testing exiConnector...")
|
print("Testing exiConnector...")
|
||||||
testReadExiFromFile()
|
#testReadExiFromFile()
|
||||||
exit()
|
#exit()
|
||||||
#testByteArrayConversion("123456")
|
#testByteArrayConversion("123456")
|
||||||
#testByteArrayConversion("1234567")
|
#testByteArrayConversion("1234567")
|
||||||
#testByteArrayConversion("ABCDEF")
|
#testByteArrayConversion("ABCDEF")
|
||||||
|
@ -300,4 +307,4 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
#strConverterResult = exiDecode(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequest2))
|
#strConverterResult = exiDecode(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequest2))
|
||||||
#print(strConverterResult)
|
#print(strConverterResult)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue