preparations for PevMode

This commit is contained in:
uhi22 2022-11-15 08:30:51 +01:00
parent e9fd6c3068
commit a055846a3f
6 changed files with 1317 additions and 351 deletions

View file

@ -231,8 +231,8 @@ def testReadExiFromFile():
if __name__ == "__main__":
nFail=0
print("Testing exiConnector...")
#testReadExiFromFile()
#exit()
testReadExiFromFile()
exit()
#testByteArrayConversion("123456")
#testByteArrayConversion("1234567")
#testByteArrayConversion("ABCDEF")

View file

@ -292,6 +292,16 @@ class pyPlcHomeplug():
self.mytransmitbuffer[42]=0x0 #
self.mytransmitbuffer[43]=0x0 #
# rest is 00
def composeStartAttenCharInd(self):
# todo
print("todo: implement composeStartAttenCharInd")
pass
def composeNmbcSoundInd(self):
# todo
print("todo: implement composeNmbcSoundInd")
pass
def composeAttenCharInd(self):
self.mytransmitbuffer = bytearray(129)
@ -356,6 +366,75 @@ class pyPlcHomeplug():
self.setNmkAt(93) # 93 to 108 NMK. We can freely choose this. Normally we should use a random number.
def runPevSequencer(self):
# in PEV mode, initiate the SLAC sequence
# Todo: Timing between the states, and timeout handling to be implemented
if (self.iAmPev==1):
if (self.pevSequenceState==0): # waiting for start condition
# In real life we would check whether we see 5% PWM on the pilot line.
# Then we would maybe wait a little bit until the homeplug modems are awake.
# Now sending the first packet for the SLAC sequence:
self.composeSlacParamReq()
self.addToTrace("transmitting SLAC_PARAM.REQ...")
self.transmit(self.mytransmitbuffer)
self.pevSequenceState = 1
return
if (self.pevSequenceState==1): # waiting for SLAC_PARAM.CNF
return
if (self.pevSequenceState==2): # received SLAC_PARAM.CNF
# todo: transmit the START_ATTEN_CHAR.IND 3 times
self.composeStartAttenCharInd()
self.addToTrace("transmitting START_ATTEN_CHAR.IND...")
self.transmit(self.mytransmitbuffer)
self.pevSequenceState = 3
return
if (self.pevSequenceState==3):
# todo: transmit the START_ATTEN_CHAR.IND 3 times
self.composeStartAttenCharInd()
self.addToTrace("transmitting START_ATTEN_CHAR.IND...")
self.transmit(self.mytransmitbuffer)
self.pevSequenceState = 4
return
if (self.pevSequenceState==4):
# todo: transmit the START_ATTEN_CHAR.IND 3 times
self.composeStartAttenCharInd()
self.addToTrace("transmitting START_ATTEN_CHAR.IND...")
self.transmit(self.mytransmitbuffer)
self.pevSequenceState = 5
self.SoundCountDown=10
return
if (self.pevSequenceState==5): # START_ATTEN_CHAR.IND are finished. Now we send 10 MNBC_SOUND.IND
self.composeNmbcSoundInd()
self.addToTrace("transmitting MNBC_SOUND.IND...")
self.transmit(self.mytransmitbuffer)
if (self.SoundCountDown>0):
self.SoundCountDown-=1
else:
self.pevSequenceState = 6
return
if (self.pevSequenceState==6): # waiting for ATTEN_CHAR.IND
# todo: it is possible that we receive this message from multiple chargers. We need
# to select the charger with the loudest reported signals.
return
if (self.pevSequenceState==7): # ATTEN_CHAR.IND was received and the nearest charger decided
self.composeAttenCharRsp()
self.addToTrace("transmitting ATTEN_CHAR.RSP...")
self.transmit(self.mytransmitbuffer)
self.pevSequenceState = 8
return
if (self.pevSequenceState==8): # ATTEN_CHAR.RSP was transmitted. Next is SLAC_MATCH.REQ
self.composeSlacMatchReq()
self.addToTrace("transmitting SLAC_MATCH.REQ...")
self.transmit(self.mytransmitbuffer)
self.pevSequenceState = 9
return
if (self.pevSequenceState==9): # waiting for SLAC_MATCH.CNF
return
if (self.pevSequenceState==10): # SLAC is finished, KEY is set, AVLN is established.
# todo: inform the higher-level state machine, that now it can start the SDP
return
def sendTestFrame(self, selection):
if (selection=="1"):
@ -418,6 +497,12 @@ class pyPlcHomeplug():
self.composeSlacParamCnf()
self.addToTrace("transmitting CM_SLAC_PARAM.CNF")
self.sniffer.sendpacket(bytes(self.mytransmitbuffer))
def evaluateSlacParamCnf(self):
# As PEV, we receive the first response from the charger.
if (self.iAmPev==1):
if (self.pevSequenceState==1): # we were waiting for the SlacParamCnf
self.pevSequenceState=2 # enter next state. Will be handled in the cyclic runPevSequencer
def evaluateMnbcSoundInd(self):
# We received MNBC_SOUND.IND from the PEV. Normally this happens 10times, with a countdown (remaining number of sounds)
@ -475,6 +560,8 @@ class pyPlcHomeplug():
self.evaluateSlacMatchCnf()
if (mmt == CM_SLAC_PARAM + MMTYPE_REQ):
self.evaluateSlacParamReq()
if (mmt == CM_SLAC_PARAM + MMTYPE_CNF):
self.evaluateSlacParamCnf()
if (mmt == CM_MNBC_SOUND + MMTYPE_IND):
self.evaluateMnbcSoundInd()
if (mmt == CM_SET_KEY + MMTYPE_CNF):
@ -483,11 +570,11 @@ class pyPlcHomeplug():
def findEthernetAdaptor(self):
self.strInterfaceName="eth0" # default, if the real is not found
print("Interfaces:\n" + '\n'.join(pcap.findalldevs()))
#print("Interfaces:\n" + '\n'.join(pcap.findalldevs()))
for i in range(0, 10):
strInterfaceName = pcap.ex_name("eth"+str(i))
if (strInterfaceName == '\\Device\\NPF_{E4B8176C-8516-4D48-88BC-85225ABCF259}'):
print("This is the wanted Ethernet adaptor.")
#print("This is the wanted Ethernet adaptor.")
self.strInterfaceName="eth"+str(i)
#print("eth"+ str(i) + " is " + strInterfaceName)
@ -513,6 +600,7 @@ class pyPlcHomeplug():
self.callbackAddToTrace = callbackAddToTrace
self.callbackShowStatus = callbackShowStatus
self.addressManager = addrMan
self.pevSequenceState = 0
#self.sniffer = pcap.pcap(name=None, promisc=True, immediate=True, timeout_ms=50)
# eth3 means: Third entry from back, in the list of interfaces, which is provided by pcap.findalldevs.
# Improvement necessary: select the interface based on the name.
@ -567,6 +655,7 @@ class pyPlcHomeplug():
self.ipv6.evaluateReceivedPacket(pkt)
self.showStatus("nPacketsReceived=" + str(self.nPacketsReceived))
self.runPevSequencer() # run the message sequencer for the PEV side
def close(self):
self.sniffer.close()

View file

@ -1,170 +0,0 @@
C:\UwesTechnik\pyPLC>python pyPlc.py E
starting in EVSE_MODE
initializing pyPlcWorker
sniffer created at eth3
initializing fsmEvse
pyPlcTcpSocket listening on port 15118
0x6064
transmitting CM_SLAC_PARAM.CNF
0x6065
0x606a
0x606a
0x606a
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
transmitting ATTEN_CHAR.IND
0xa14e
0x6086
0x606e
0x606f
0x607c
transmitting SLAC_MATCH.CNF
0x607d
V2GTP (10bytes) = 01 FE 90 00 00 00 00 02 10 00
ok, this was a valid SDP request
We are the SECC. Sending SDP response.
SDP payload (20bytes) = FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
V2Gframe (28bytes) = 01 FE 90 01 00 00 00 14 FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
UDP response (36bytes) = 3B 0E C3 73 00 24 00 00 01 FE 90 01 00 00 00 14 FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
IP response (76bytes) = 60 00 00 00 00 24 11 0A FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 FE 80 00 00 00 00 00 00 06 65 65 FF FE 00 64 C3 3B 0E C3 73 00 24 B3 24 01 FE 90 01 00 00 00 14 FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
Connection from ('fe80::665:65ff:fe00:64c3', 50109, 0, 16)
In state WaitForSupportedApplicationProtocolRequest, received (42bytes) = 01 FE 80 01 00 00 00 22 80 00 DB AB 93 71 D3 23 4B 71 D1 B9 81 89 91 89 D1 91 81 89 91 D2 6B 9B 3A 23 2B 30 02 00 00 04 00 40
{
"info": "34 bytes to convert",
"error": "",
"result": "Vehicle supports 1 protocols. ProtocolEntry#1 ProtocolNamespace=urn:din:70121:2012:MsgDef Version=2.0 SchemaID=1 Priority=1 ",
"schema": "appHandshake",
"msgName": "supportedAppProtocolReq"
}
Detected DIN
responding (12bytes) = 01 FE 80 01 00 00 00 04 80 40 00 40
from 0 entering 1
EXI from 50109 to 15118
(34bytes) = 80 00 DB AB 93 71 D3 23 4B 71 D1 B9 81 89 91 89 D1 91 81 89 91 D2 6B 9B 3A 23 2B 30 02 00 00 04 00 40
EXI from 15118 to 50109
(4bytes) = 80 40 00 40
EXI from 50109 to 15118
(21bytes) = 80 9A 02 00 00 00 00 00 00 00 00 11 D0 18 11 95 94 01 93 0C 00
In state stateFunctionWaitForSessionSetupRequest, received (29bytes) = 01 FE 80 01 00 00 00 15 80 9A 02 00 00 00 00 00 00 00 00 11 D0 18 11 95 94 01 93 0C 00
{
"info": "21 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "SessionSetupReq"
}
responding (24bytes) = 01 FE 80 01 00 00 00 10 80 9A 02 00 40 80 C1 01 41 81 C2 11 E0 00 00 80
from 1 entering 2
EXI from 15118 to 50109
(16bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 E0 00 00 80
EXI from 50109 to 15118
(14bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 94 00
In state WaitForServiceDiscoveryRequest, received (22bytes) = 01 FE 80 01 00 00 00 0E 80 9A 02 00 40 80 C1 01 41 81 C2 11 94 00
{
"info": "14 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "ServiceDiscoveryReq"
}
responding (19bytes) = 01 FE 80 01 00 00 00 0B 80 9A 00 11 A0 01 20 02 41 21 04
from 2 entering 3
EXI from 15118 to 50109
(11bytes) = 80 9A 00 11 A0 01 20 02 41 21 04
EXI from 50109 to 15118
(8bytes) = 80 9A 00 11 B2 00 12 80
In state WaitForServicePaymentSelectionRequest, received (16bytes) = 01 FE 80 01 00 00 00 08 80 9A 00 11 B2 00 12 80
{
"info": "8 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "ServicePaymentSelectionReq"
}
responding (14bytes) = 01 FE 80 01 00 00 00 06 80 9A 00 11 C0 00
from 3 entering 5
EXI from 15118 to 50109
(6bytes) = 80 9A 00 11 C0 00
In state WaitForChargeParameterDiscoveryRequest, received (20bytes) = 01 FE 80 01 00 00 00 0C 80 9A 00 11 30 20 00 0A 00 00 00 00
{
"info": "12 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0"
}
EXI from 50109 to 15118
(12bytes) = 80 9A 00 11 30 20 00 0A 00 00 00 00
from 5 entering 0
In state WaitForSupportedApplicationProtocolRequest, received (13bytes) = 01 FE 80 01 00 00 00 05 80 9A 00 11 F0
{
"info": "5 bytes to convert",
"error": "runTheDecoder error-111",
"result": "",
"schema": "appHandshake"
}
EXI from 50109 to 15118
(5bytes) = 80 9A 00 11 F0
connection closed

View file

@ -1,177 +0,0 @@
C:\UwesTechnik\pyPLC>python pyPlc.py E
starting in EVSE_MODE
initializing pyPlcWorker
Interfaces:
\Device\NPF_{CF245078-25B1-4487-AE2A-1763158ACD5F}
\Device\NPF_{7105741E-F8FC-46AD-9BCD-95F7CDCC76B0}
\Device\NPF_{F2DFA311-B486-461A-A3F4-0DBA998BF9F9}
\Device\NPF_{0DFD428E-B132-4188-8EBC-38C13B0C89CF}
\Device\NPF_{E4B8176C-8516-4D48-88BC-85225ABCF259}
\Device\NPF_{68936D7B-F0E7-46E7-A047-3C07A24E03B9}
\Device\NPF_{A541C45F-EDAC-4242-ABF6-B4337228BBFF}
\Device\NPF_Loopback
index match at 0 dev name=b'\\Device\\NPF_Loopback' dev.description=b'Adapter for loopback traffic capture'
index match at 1 dev name=b'\\Device\\NPF_{A541C45F-EDAC-4242-ABF6-B4337228BBFF}' dev.description=b'Microsoft Wi-Fi Direct Virtual Adapter'
index match at 2 dev name=b'\\Device\\NPF_{68936D7B-F0E7-46E7-A047-3C07A24E03B9}' dev.description=b'Microsoft Wi-Fi Direct Virtual Adapter #2'
index match at 3 dev name=b'\\Device\\NPF_{E4B8176C-8516-4D48-88BC-85225ABCF259}' dev.description=b'Broadcom NetLink (TM) Gigabit Ethernet'
This is the wanted Ethernet adaptor.
index match at 4 dev name=b'\\Device\\NPF_{0DFD428E-B132-4188-8EBC-38C13B0C89CF}' dev.description=b'Broadcom 802.11n-Netzwerkadapter'
index match at 5 dev name=b'\\Device\\NPF_{F2DFA311-B486-461A-A3F4-0DBA998BF9F9}' dev.description=b'WAN Miniport (IP)'
index match at 6 dev name=b'\\Device\\NPF_{7105741E-F8FC-46AD-9BCD-95F7CDCC76B0}' dev.description=b'WAN Miniport (IPv6)'
index match at 7 dev name=b'\\Device\\NPF_{CF245078-25B1-4487-AE2A-1763158ACD5F}' dev.description=b'WAN Miniport (Network Monitor)'
index match at 3 dev name=b'\\Device\\NPF_{E4B8176C-8516-4D48-88BC-85225ABCF259}' dev.description=b'Broadcom NetLink (TM) Gigabit Ethernet'
sniffer created at eth3
initializing fsmEvse
pyPlcTcpSocket listening on port 15118
0x6064
transmitting CM_SLAC_PARAM.CNF
0x6065
0x606a
0x606a
0x606a
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
0xa14e
0x6086
0x6076
transmitting ATTEN_CHAR.IND
0xa14e
0x6086
0x606e
0x606f
0x607c
transmitting SLAC_MATCH.CNF
0x607d
V2GTP (10bytes) = 01 FE 90 00 00 00 00 02 10 00
ok, this was a valid SDP request
We are the SECC. Sending SDP response.
SDP payload (20bytes) = FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
V2Gframe (28bytes) = 01 FE 90 01 00 00 00 14 FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
UDP response (36bytes) = 3B 0E C3 71 00 24 00 00 01 FE 90 01 00 00 00 14 FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
IP response (76bytes) = 60 00 00 00 00 24 11 0A FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 FE 80 00 00 00 00 00 00 06 65 65 FF FE 00 64 C3 3B 0E C3 71 00 24 B3 26 01 FE 90 01 00 00 00 14 FE 80 00 00 00 00 00 00 E0 AD 99 AC 52 EB 85 D3 3B 0E 10 00
Connection from ('fe80::665:65ff:fe00:64c3', 50095, 0, 16)
In state WaitForSupportedApplicationProtocolRequest, received (42bytes) = 01 FE 80 01 00 00 00 22 80 00 DB AB 93 71 D3 23 4B 71 D1 B9 81 89 91 89 D1 91 81 89 91 D2 6B 9B 3A 23 2B 30 02 00 00 04 00 40
{
"info": "34 bytes to convert",
"error": "",
"result": "Vehicle supports 1 protocols. ProtocolEntry#1 ProtocolNamespace=urn:din:70121:2012:MsgDef Version=2.0 SchemaID=1 Priority=1 ",
"schema": "appHandshake",
"msgName": "supportedAppProtocolReq",
"debug": ""
}
Detected DIN
responding (12bytes) = 01 FE 80 01 00 00 00 04 80 40 00 40
from 0 entering 1
[SNIFFER] EXI from 50095 to 15118 (34bytes) = 80 00 DB AB 93 71 D3 23 4B 71 D1 B9 81 89 91 89 D1 91 81 89 91 D2 6B 9B 3A 23 2B 30 02 00 00 04 00 40
[SNIFFER] EXI from 15118 to 50095 (4bytes) = 80 40 00 40
[SNIFFER] EXI from 50095 to 15118 (21bytes) = 80 9A 02 00 00 00 00 00 00 00 00 11 D0 18 11 95 94 01 93 0C 00
In state stateFunctionWaitForSessionSetupRequest, received (29bytes) = 01 FE 80 01 00 00 00 15 80 9A 02 00 00 00 00 00 00 00 00 11 D0 18 11 95 94 01 93 0C 00
{
"info": "21 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "SessionSetupReq",
"EVCCID.bytesLen": "6",
"EVCCID": "0465650064c3",
"debug": "Line532"
}
responding (24bytes) = 01 FE 80 01 00 00 00 10 80 9A 02 00 40 80 C1 01 41 81 C2 11 E0 00 00 80
from 1 entering 2
[SNIFFER] EXI from 15118 to 50095 (16bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 E0 00 00 80
[SNIFFER] EXI from 50095 to 15118 (14bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 94 00
In state WaitForServiceDiscoveryRequest, received (22bytes) = 01 FE 80 01 00 00 00 0E 80 9A 02 00 40 80 C1 01 41 81 C2 11 94 00
{
"info": "14 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "ServiceDiscoveryReq",
"ServiceCategory_isUsed": "True",
"debug": "Line508"
}
responding (27bytes) = 01 FE 80 01 00 00 00 13 80 9A 02 00 40 80 C1 01 41 81 C2 11 A0 01 20 02 41 00 84
from 2 entering 3
[SNIFFER] EXI from 15118 to 50095 (19bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 A0 01 20 02 41 00 84
[SNIFFER] EXI from 50095 to 15118 (16bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 B2 00 12 80
In state WaitForServicePaymentSelectionRequest, received (24bytes) = 01 FE 80 01 00 00 00 10 80 9A 02 00 40 80 C1 01 41 81 C2 11 B2 00 12 80
{
"info": "16 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "ServicePaymentSelectionReq",
"SelectedPaymentOption": "ExternalPayment",
"SelectedService.arrayLen": "1",
"SelectedService.array": "0:1",
"debug": "Line520"
}
responding (22bytes) = 01 FE 80 01 00 00 00 0E 80 9A 02 00 40 80 C1 01 41 81 C2 11 C0 00
from 3 entering 4
[SNIFFER] EXI from 15118 to 50095 (14bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 C0 00
In state WaitForFlexibleRequest, received (28bytes) = 01 FE 80 01 00 00 00 14 80 9A 02 00 40 80 C1 01 41 81 C2 11 30 20 00 0A 00 00 00 00
{
"info": "20 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "PowerDeliveryReq",
"ReadyToChargeState": "0",
"ChargingProfile_isUsed": "0",
"EVPowerDeliveryParameter_isUsed": "0",
"DC_EVPowerDeliveryParameter_isUsed": "1",
"EVReady": "0",
"EVErrorCode": "10",
"EVErrorCodeText": "FAILED_ChargingSystemIncompatibility",
"EVRESSSOC": "0",
"BulkChargingComplete": "0",
"ChargingComplete": "0",
"debug": "Line472"
}
responding (26bytes) = 01 FE 80 01 00 00 00 12 80 9A 02 00 40 80 C1 01 41 81 C2 11 40 04 20 40 00 00
from 4 entering 4
[SNIFFER] EXI from 50095 to 15118 (20bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 30 20 00 0A 00 00 00 00
[SNIFFER] EXI from 15118 to 50095 (18bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 40 04 20 40 00 00
[SNIFFER] EXI from 50095 to 15118 (13bytes) = 80 9A 02 00 40 80 C1 01 41 81 C2 11 F0
In state WaitForFlexibleRequest, received (21bytes) = 01 FE 80 01 00 00 00 0D 80 9A 02 00 40 80 C1 01 41 81 C2 11 F0
{
"info": "13 bytes to convert",
"error": "",
"result": "",
"schema": "DIN",
"g_errn": "0",
"msgName": "SessionStopReq",
"debug": "Line544"
}
connection closed
from 4 entering 0
C:\UwesTechnik\pyPLC>

1224
results/tmp.txt Normal file

File diff suppressed because it is too large Load diff