mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
PevMode CableCheck draft
This commit is contained in:
parent
a10877cada
commit
0da4acd0b5
1 changed files with 30 additions and 5 deletions
35
fsmPev.py
35
fsmPev.py
|
@ -22,6 +22,9 @@ stateWaitForPreChargeResponse = 8
|
||||||
stateWaitForPowerDeliveryResponse = 9
|
stateWaitForPowerDeliveryResponse = 9
|
||||||
stateNotYetInitialized = 10
|
stateNotYetInitialized = 10
|
||||||
|
|
||||||
|
dinEVSEProcessingType_Finished = "0"
|
||||||
|
dinEVSEProcessingType_Ongoing = "1"
|
||||||
|
|
||||||
class fsmPev():
|
class fsmPev():
|
||||||
def enterState(self, n):
|
def enterState(self, n):
|
||||||
print("from " + str(self.state) + " entering " + str(n))
|
print("from " + str(self.state) + " entering " + str(n))
|
||||||
|
@ -30,7 +33,12 @@ class fsmPev():
|
||||||
|
|
||||||
def isTooLong(self):
|
def isTooLong(self):
|
||||||
# The timeout handling function.
|
# The timeout handling function.
|
||||||
return (self.cyclesInState > 20)
|
limit = 30 # number of call cycles until timeout
|
||||||
|
if (self.state==stateWaitForCableCheckResponse):
|
||||||
|
limit = 30*30 # CableCheck may need some time. Wait at least 30s.
|
||||||
|
if (self.state==stateWaitForPreChargeResponse):
|
||||||
|
limit = 30*30 # PreCharge may need some time. Wait at least 30s.
|
||||||
|
return (self.cyclesInState > limit)
|
||||||
|
|
||||||
def stateFunctionInitialized(self):
|
def stateFunctionInitialized(self):
|
||||||
if (self.Tcp.isConnected):
|
if (self.Tcp.isConnected):
|
||||||
|
@ -133,11 +141,28 @@ class fsmPev():
|
||||||
strConverterResult = exiDecode(exidata, "DD") # Decode DIN
|
strConverterResult = exiDecode(exidata, "DD") # Decode DIN
|
||||||
print(strConverterResult)
|
print(strConverterResult)
|
||||||
if (strConverterResult.find("CableCheckRes")>0):
|
if (strConverterResult.find("CableCheckRes")>0):
|
||||||
|
try:
|
||||||
|
y = json.loads(strConverterResult)
|
||||||
|
strResponseCode = y["ResponseCode"]
|
||||||
|
strEVSEProcessing = y["EVSEProcessing"]
|
||||||
|
print("[PEV] The CableCheck result is " + strResponseCode + " " + strEVSEProcessing)
|
||||||
|
except:
|
||||||
|
print("ERROR: Could not decode the CableCheckRes")
|
||||||
# todo: check the request content, and fill response parameters
|
# todo: check the request content, and fill response parameters
|
||||||
msg = addV2GTPHeader(exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge
|
# We have two cases here:
|
||||||
print("responding " + prettyHexMessage(msg))
|
# 1) The charger says "cable check is finished and cable ok", by setting ResponseCode=OK and EVSEProcessing=Finished.
|
||||||
self.Tcp.transmit(msg)
|
# 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.
|
||||||
self.enterState(stateWaitForPreChargeResponse)
|
if ((strEVSEProcessing==dinEVSEProcessingType_Finished) and (strResponseCode=="OK")):
|
||||||
|
msg = addV2GTPHeader(exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge
|
||||||
|
print("responding " + prettyHexMessage(msg))
|
||||||
|
self.Tcp.transmit(msg)
|
||||||
|
self.enterState(stateWaitForPreChargeResponse)
|
||||||
|
else:
|
||||||
|
# cable check not yet finished or finished with bad result -> try again
|
||||||
|
msg = addV2GTPHeader(exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck
|
||||||
|
print("responding " + prettyHexMessage(msg))
|
||||||
|
self.Tcp.transmit(msg)
|
||||||
|
|
||||||
if (self.isTooLong()):
|
if (self.isTooLong()):
|
||||||
self.enterState(0)
|
self.enterState(0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue