added comments. improved logging on PEV side.

This commit is contained in:
uhi22 2022-11-24 07:46:45 +01:00
parent 52538e759e
commit 9a555df269
2 changed files with 23 additions and 9 deletions

View file

@ -46,6 +46,7 @@ class fsmPev():
def stateFunctionInitialized(self): def stateFunctionInitialized(self):
if (self.Tcp.isConnected): if (self.Tcp.isConnected):
# we just use the initial request message from the Ioniq. It contains one entry: DIN. # we just use the initial request message from the Ioniq. It contains one entry: DIN.
self.addToTrace("Sending the initial SupportedApplicationProtocolReq")
self.Tcp.transmit(addV2GTPHeader(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequestIoniq))) self.Tcp.transmit(addV2GTPHeader(exiHexToByteArray(exiHexDemoSupportedApplicationProtocolRequestIoniq)))
self.enterState(stateWaitForSupportedApplicationProtocolResponse) self.enterState(stateWaitForSupportedApplicationProtocolResponse)
@ -58,6 +59,7 @@ class fsmPev():
self.addToTrace(strConverterResult) self.addToTrace(strConverterResult)
if (strConverterResult.find("supportedAppProtocolRes")>0): if (strConverterResult.find("supportedAppProtocolRes")>0):
# todo: check the request content, and fill response parameters # todo: check the request content, and fill response parameters
self.addToTrace("Will send SessionSetupReq")
msg = addV2GTPHeader(exiEncode("EDA")) # EDA for Encode, Din, SessionSetupReq msg = addV2GTPHeader(exiEncode("EDA")) # EDA for Encode, Din, SessionSetupReq
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
@ -77,10 +79,11 @@ class fsmPev():
try: try:
y = json.loads(strConverterResult) y = json.loads(strConverterResult)
strSessionId = y["header.SessionID"] strSessionId = y["header.SessionID"]
self.addToTrace("[PEV] The Evse decided for SessionId " + strSessionId) self.addToTrace("The Evse decided for SessionId " + strSessionId)
self.sessionId = strSessionId self.sessionId = strSessionId
except: except:
self.addToTrace("ERROR: Could not decode the sessionID") self.addToTrace("ERROR: Could not decode the sessionID")
self.addToTrace("Will send ServiceDiscoveryReq")
msg = addV2GTPHeader(exiEncode("EDB_"+self.sessionId)) # EDB for Encode, Din, ServiceDiscoveryRequest msg = addV2GTPHeader(exiEncode("EDB_"+self.sessionId)) # EDB for Encode, Din, ServiceDiscoveryRequest
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
@ -97,6 +100,7 @@ class fsmPev():
self.addToTrace(strConverterResult) self.addToTrace(strConverterResult)
if (strConverterResult.find("ServiceDiscoveryRes")>0): if (strConverterResult.find("ServiceDiscoveryRes")>0):
# todo: check the request content, and fill response parameters # todo: check the request content, and fill response parameters
self.addToTrace("Will send ServicePaymentSelectionReq")
msg = addV2GTPHeader(exiEncode("EDC_"+self.sessionId)) # EDC for Encode, Din, ServicePaymentSelection msg = addV2GTPHeader(exiEncode("EDC_"+self.sessionId)) # EDC for Encode, Din, ServicePaymentSelection
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
@ -113,6 +117,7 @@ class fsmPev():
self.addToTrace(strConverterResult) self.addToTrace(strConverterResult)
if (strConverterResult.find("ServicePaymentSelectionRes")>0): if (strConverterResult.find("ServicePaymentSelectionRes")>0):
# todo: check the request content, and fill response parameters # todo: check the request content, and fill response parameters
self.addToTrace("Will send ChargeParameterDiscoveryReq")
msg = addV2GTPHeader(exiEncode("EDE_"+self.sessionId)) # EDE for Encode, Din, ChargeParameterDiscovery. We ignore Authorization, not specified in DIN. msg = addV2GTPHeader(exiEncode("EDE_"+self.sessionId)) # EDE for Encode, Din, ChargeParameterDiscovery. We ignore Authorization, not specified in DIN.
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
@ -129,6 +134,7 @@ class fsmPev():
self.addToTrace(strConverterResult) self.addToTrace(strConverterResult)
if (strConverterResult.find("ChargeParameterDiscoveryRes")>0): if (strConverterResult.find("ChargeParameterDiscoveryRes")>0):
# todo: check the request content, and fill response parameters # todo: check the request content, and fill response parameters
self.addToTrace("Will send CableCheckReq")
msg = addV2GTPHeader(exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck msg = addV2GTPHeader(exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
@ -156,12 +162,15 @@ class fsmPev():
# 1) The charger says "cable check is finished and cable ok", by setting ResponseCode=OK and EVSEProcessing=Finished. # 1) The charger says "cable check is finished and cable ok", by setting ResponseCode=OK and EVSEProcessing=Finished.
# 2) Else: The charger says "need more time or cable not ok". In this case, we just run into timeout and start from the beginning. # 2) Else: The charger says "need more time or cable not ok". In this case, we just run into timeout and start from the beginning.
if ((strEVSEProcessing==dinEVSEProcessingType_Finished) and (strResponseCode=="OK")): if ((strEVSEProcessing==dinEVSEProcessingType_Finished) and (strResponseCode=="OK")):
self.addToTrace("The EVSE says that the CableCheck is finished and ok.")
self.addToTrace("Will send PreChargeReq")
msg = addV2GTPHeader(exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge msg = addV2GTPHeader(exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
self.enterState(stateWaitForPreChargeResponse) self.enterState(stateWaitForPreChargeResponse)
else: else:
# cable check not yet finished or finished with bad result -> try again # cable check not yet finished or finished with bad result -> try again
self.addToTrace("Will again send CableCheckReq")
msg = addV2GTPHeader(exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck msg = addV2GTPHeader(exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)

View file

@ -10,12 +10,17 @@ class udplog():
def log(self, s): def log(self, s):
# The frame format follows the Syslog protocol, https://en.wikipedia.org/wiki/Syslog
# Level consists of
# Facility = 1 = "user"
# Severity = 7 = "debug"
strLevel="<15>" strLevel="<15>"
# The String to be logged. Terminated by 00.
strMessage=s+"\0" strMessage=s+"\0"
lenPayLoad = 4 + len(strMessage) lenPayLoad = 4 + len(strMessage) # length of level is 4
buffer=bytearray(lenPayLoad+28) buffer=bytearray(lenPayLoad+28) # prepare the IPv4 buffer. Including 28 bytes IP header.
# syslog level (4 characters) # syslog level (4 characters)
for i in range(0, len(strLevel)): for i in range(0, len(strLevel)):
buffer[28+i] = ord(strLevel[i]) buffer[28+i] = ord(strLevel[i])
@ -41,8 +46,8 @@ class udplog():
# source ip 4 bytes # source ip 4 bytes
buffer[12] = 192 # does this really matter? buffer[12] = 192 # does this really matter?
buffer[13] = 168 buffer[13] = 168
buffer[14] = 2 buffer[14] = self.ownMac[4] # quick&dirty: we just fill the last two bytes of the MAC here.
buffer[15] = 222 buffer[15] = self.ownMac[5] #
# destination ip 4 bytes: broadcast # destination ip 4 bytes: broadcast
buffer[16] = 0xff buffer[16] = 0xff
buffer[17] = 0xff buffer[17] = 0xff
@ -51,13 +56,13 @@ class udplog():
# source port # source port
buffer[20] = 0xff buffer[20] = 0xff
buffer[21] = 0x95 buffer[21] = 0x95
# destination port # destination port. 0x0202 = 514 = the official Syslog UDP port
buffer[22] = 0x02 buffer[22] = 0x02
buffer[23] = 0x02 buffer[23] = 0x02
udplen = lenPayLoad + 8 # payload plus 8 byte udp header udplen = lenPayLoad + 8 # payload plus 8 byte udp header
buffer[24] = udplen >> 8 buffer[24] = udplen >> 8
buffer[25] = (udplen & 0xff) buffer[25] = (udplen & 0xff)
udpchecksum = 0 udpchecksum = 0 # checksum 0 has the special meaning: no checksum. Receiver ignores it.
buffer[26] = udpchecksum >> 8 buffer[26] = udpchecksum >> 8
buffer[27] = (udpchecksum & 0xff) buffer[27] = (udpchecksum & 0xff)
@ -78,9 +83,9 @@ class udplog():
self.fillMac(self.ownMac) # bytes 6 to 11 are the source MAC self.fillMac(self.ownMac) # bytes 6 to 11 are the source MAC
self.EthTxFrame[12] = 0x08 # 0800 is IPv4 self.EthTxFrame[12] = 0x08 # 0800 is IPv4
self.EthTxFrame[13] = 0x00 self.EthTxFrame[13] = 0x00
for i in range(0, len(buffer)): for i in range(0, len(buffer)): # copy the IPv4 buffer content into the Ethernet buffer
self.EthTxFrame[14+i] = buffer[i] self.EthTxFrame[14+i] = buffer[i]
self.transmit(self.EthTxFrame) self.transmit(self.EthTxFrame) # and finally transmit the Ethernet frame
def __init__(self, transmitCallback, addressManager): def __init__(self, transmitCallback, addressManager):