mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +00:00
added comments. improved logging on PEV side.
This commit is contained in:
parent
52538e759e
commit
9a555df269
2 changed files with 23 additions and 9 deletions
11
fsmPev.py
11
fsmPev.py
|
@ -46,6 +46,7 @@ class fsmPev():
|
|||
def stateFunctionInitialized(self):
|
||||
if (self.Tcp.isConnected):
|
||||
# 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.enterState(stateWaitForSupportedApplicationProtocolResponse)
|
||||
|
||||
|
@ -58,6 +59,7 @@ class fsmPev():
|
|||
self.addToTrace(strConverterResult)
|
||||
if (strConverterResult.find("supportedAppProtocolRes")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
self.addToTrace("Will send SessionSetupReq")
|
||||
msg = addV2GTPHeader(exiEncode("EDA")) # EDA for Encode, Din, SessionSetupReq
|
||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
|
@ -77,10 +79,11 @@ class fsmPev():
|
|||
try:
|
||||
y = json.loads(strConverterResult)
|
||||
strSessionId = y["header.SessionID"]
|
||||
self.addToTrace("[PEV] The Evse decided for SessionId " + strSessionId)
|
||||
self.addToTrace("The Evse decided for SessionId " + strSessionId)
|
||||
self.sessionId = strSessionId
|
||||
except:
|
||||
self.addToTrace("ERROR: Could not decode the sessionID")
|
||||
self.addToTrace("Will send ServiceDiscoveryReq")
|
||||
msg = addV2GTPHeader(exiEncode("EDB_"+self.sessionId)) # EDB for Encode, Din, ServiceDiscoveryRequest
|
||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
|
@ -97,6 +100,7 @@ class fsmPev():
|
|||
self.addToTrace(strConverterResult)
|
||||
if (strConverterResult.find("ServiceDiscoveryRes")>0):
|
||||
# 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
|
||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
|
@ -113,6 +117,7 @@ class fsmPev():
|
|||
self.addToTrace(strConverterResult)
|
||||
if (strConverterResult.find("ServicePaymentSelectionRes")>0):
|
||||
# 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.
|
||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
|
@ -129,6 +134,7 @@ class fsmPev():
|
|||
self.addToTrace(strConverterResult)
|
||||
if (strConverterResult.find("ChargeParameterDiscoveryRes")>0):
|
||||
# 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
|
||||
self.addToTrace("responding " + prettyHexMessage(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.
|
||||
# 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")):
|
||||
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
|
||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForPreChargeResponse)
|
||||
else:
|
||||
# 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
|
||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
|
|
21
udplog.py
21
udplog.py
|
@ -10,12 +10,17 @@ class udplog():
|
|||
|
||||
|
||||
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>"
|
||||
# The String to be logged. Terminated by 00.
|
||||
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)
|
||||
for i in range(0, len(strLevel)):
|
||||
buffer[28+i] = ord(strLevel[i])
|
||||
|
@ -41,8 +46,8 @@ class udplog():
|
|||
# source ip 4 bytes
|
||||
buffer[12] = 192 # does this really matter?
|
||||
buffer[13] = 168
|
||||
buffer[14] = 2
|
||||
buffer[15] = 222
|
||||
buffer[14] = self.ownMac[4] # quick&dirty: we just fill the last two bytes of the MAC here.
|
||||
buffer[15] = self.ownMac[5] #
|
||||
# destination ip 4 bytes: broadcast
|
||||
buffer[16] = 0xff
|
||||
buffer[17] = 0xff
|
||||
|
@ -51,13 +56,13 @@ class udplog():
|
|||
# source port
|
||||
buffer[20] = 0xff
|
||||
buffer[21] = 0x95
|
||||
# destination port
|
||||
# destination port. 0x0202 = 514 = the official Syslog UDP port
|
||||
buffer[22] = 0x02
|
||||
buffer[23] = 0x02
|
||||
udplen = lenPayLoad + 8 # payload plus 8 byte udp header
|
||||
buffer[24] = udplen >> 8
|
||||
buffer[25] = (udplen & 0xff)
|
||||
udpchecksum = 0
|
||||
udpchecksum = 0 # checksum 0 has the special meaning: no checksum. Receiver ignores it.
|
||||
buffer[26] = udpchecksum >> 8
|
||||
buffer[27] = (udpchecksum & 0xff)
|
||||
|
||||
|
@ -78,9 +83,9 @@ class udplog():
|
|||
self.fillMac(self.ownMac) # bytes 6 to 11 are the source MAC
|
||||
self.EthTxFrame[12] = 0x08 # 0800 is IPv4
|
||||
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.transmit(self.EthTxFrame)
|
||||
self.transmit(self.EthTxFrame) # and finally transmit the Ethernet frame
|
||||
|
||||
|
||||
def __init__(self, transmitCallback, addressManager):
|
||||
|
|
Loading…
Reference in a new issue