From 2b5806bf4307a1c194727d4d73b158abb220d1b5 Mon Sep 17 00:00:00 2001 From: uhi22 Date: Tue, 27 Jun 2023 21:22:21 +0200 Subject: [PATCH] fix: EvseMode: Find the DIN schema and use the related SchemaID. Should fix issue #9 --- exiConnector.py | 4 ++++ fsmEvse.py | 37 ++++++++++++++++++++++++++----------- fsmPev.py | 3 +++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/exiConnector.py b/exiConnector.py index 073fcf6..7fae5d6 100644 --- a/exiConnector.py +++ b/exiConnector.py @@ -55,6 +55,10 @@ exiHexDemoSupportedApplicationProtocolRequestIoniq="8000dbab9371d3234b71d1b98189 # Command line: # ./OpenV2G.exe DH8000dbab9371d3234b71d1b981899189d191818991d26b9b3a232b30020000040040 +# (1b) From the tesla. Source https://github.com/SmartEVSE/SmartEVSE-3/issues/25#issuecomment-1606259381) +exiHexDemoSupportedApplicationProtocolRequestTesla="8000DBAB9371D3234B71D1B981899189D191818991D26B9B3A232B30020000040401B75726E3A7465736C613A64696E3A323031383A4D736744656600001C0100080" +# The BMW iX3 handshake request (one schema, schemaID 0, from https://github.com/SmartEVSE/SmartEVSE-3/issues/25#issuecomment-1606271999) +exiHexDemoSupportedApplicationProtocolRequestBMWiX3="8000DBAB9371D3234B71D1B981899189D191818991D26B9B3A232B30020000000040" # (2) From OpenV2G main_example.appHandshake() # 8000ebab9371d34b9b79d189a98989c1d191d191818981d26b9b3a232b30010000040001b75726e3a64696e3a37303132313a323031323a4d73674465660020000100880 diff --git a/fsmEvse.py b/fsmEvse.py index 38ace4a..f86dcde 100644 --- a/fsmEvse.py +++ b/fsmEvse.py @@ -51,17 +51,32 @@ class fsmEvse(): self.rxData = [] strConverterResult = exiDecode(exidata, "DH") # Decode Handshake-request self.addToTrace(strConverterResult) - if (strConverterResult.find("ProtocolNamespace=urn:din")>0): - # todo: of course we should care for schemaID and prio also here - self.addToTrace("Detected DIN") - # TESTSUITE: When the EVSE received the Handshake, it selects a new test case. - testsuite_choose_testcase() - # Eh for encode handshake, SupportedApplicationProtocolResponse - msg = addV2GTPHeader(exiEncode("Eh")) - self.addToTrace("responding " + prettyHexMessage(msg)) - self.Tcp.transmit(msg) - self.publishStatus("Schema negotiated") - self.enterState(stateWaitForSessionSetupRequest) + if (strConverterResult.find("supportedAppProtocolReq")>0): + nDinSchemaID = 255 # invalid default value + try: + y = json.loads(strConverterResult) + nAppProtocol_ArrayLen = int(y["AppProtocol_arrayLen"]) + self.addToTrace("The car supports " + str(nAppProtocol_ArrayLen) + " schemas.") + for i in range(nAppProtocol_ArrayLen): + strNameSpace = y["NameSpace_"+str(i)] + nSchemaId = int(y["SchemaID_"+str(i)]) + self.addToTrace("The NameSpace " + strNameSpace + " has SchemaID " + str(nSchemaId)) + if (strNameSpace.find(":din:70121:")>0): + nDinSchemaID = nSchemaId + except: + self.addToTrace("ERROR: Could not decode the supportedAppProtocolReq") + if (nDinSchemaID<255): + self.addToTrace("Detected DIN") + # TESTSUITE: When the EVSE received the Handshake, it selects a new test case. + testsuite_choose_testcase() + # Eh for encode handshake, SupportedApplicationProtocolResponse, with SchemaID as parameter + msg = addV2GTPHeader(exiEncode("Eh__"+str(nDinSchemaID))) + self.addToTrace("responding " + prettyHexMessage(msg)) + self.Tcp.transmit(msg) + self.publishStatus("Schema negotiated") + self.enterState(stateWaitForSessionSetupRequest) + else: + self.addToTrace("Error: The connected car does not support DIN. At the moment, the pyPLC only supports DIN.") def stateFunctionWaitForSessionSetupRequest(self): if (len(self.rxData)>0): diff --git a/fsmPev.py b/fsmPev.py index 61acb26..b2c2ef0 100644 --- a/fsmPev.py +++ b/fsmPev.py @@ -232,6 +232,9 @@ class fsmPev(): # We just use the initial request message from the Ioniq. It contains one entry: DIN. self.addToTrace("Checkpoint400: Sending the initial SupportedApplicationProtocolReq") self.Tcp.transmit(addV2GTPHeader(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequestIoniq))) + # For testing purposes, we can also use the requests from other cars: + #self.Tcp.transmit(addV2GTPHeader(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequestTesla))) + #self.Tcp.transmit(addV2GTPHeader(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequestBMWiX3))) self.hardwareInterface.resetSimulation() self.enterState(stateWaitForSupportedApplicationProtocolResponse)