exiconnector made compatible for Raspberry

This commit is contained in:
uhi22 2022-11-20 14:23:37 +01:00
parent e4a7cd3373
commit f61f68a0ab
2 changed files with 63 additions and 48 deletions

View file

@ -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 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.
cd $home
mkdir myprogs
cd myprogs
git clone http://github.com/uhi22/pyPlc
git clone http://github.com/uhi22/OpenV2Gx
cd OpenV2Gx/Release
make
Clone the two github repositories, and compile the OpenV2Gx EXI decoder/encoder:
```
cd $home
mkdir myprogs
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
./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
python --version
`python --version`
reports e.g. 3.9.2.
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)
sudo python -m pip install --upgrade pcap-ct
Install the python library for accessing the network interface.
Also for the superuser (otherwise the import pcap fails).
```
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:
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.
sudo python test_pcap.py
This should run through loops 0 to 9. If it stucks at Loop 0, the
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
```
sudo python test_pcap.py
```
This should run through loops 0 to 9.
Problem: Each loop needs around 2 seconds. This is not intended. The 10ms timeout
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
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.
Try-out the cooperation of Python with the EXI encoder/decoder:
```
python exiConnector.py
```
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.

View file

@ -43,6 +43,7 @@ import subprocess
import sys
import time
import json
import os
# Example data:
# (1) From the Ioniq:
@ -83,7 +84,13 @@ exiHexDemoSupportedApplicationProtocolRequest2="8000ebab9371d34b9b79d189a98989c1
# 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
def exiHexToByteArray(hexString):
@ -235,8 +242,8 @@ def testReadExiFromFile():
if __name__ == "__main__":
nFail=0
print("Testing exiConnector...")
testReadExiFromFile()
exit()
#testReadExiFromFile()
#exit()
#testByteArrayConversion("123456")
#testByteArrayConversion("1234567")
#testByteArrayConversion("ABCDEF")
@ -300,4 +307,4 @@ if __name__ == "__main__":
#strConverterResult = exiDecode(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequest2))
#print(strConverterResult)