mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +00:00
feature: show voltage and SOC on display. Shorter status to fit on display. Faster close relay at charging start.
This commit is contained in:
parent
8493daeb56
commit
ecd5aca99e
3 changed files with 25 additions and 25 deletions
38
fsmPev.py
38
fsmPev.py
|
@ -39,8 +39,8 @@ class fsmPev():
|
||||||
def addToTrace(self, s):
|
def addToTrace(self, s):
|
||||||
self.callbackAddToTrace("[PEV] " + s)
|
self.callbackAddToTrace("[PEV] " + s)
|
||||||
|
|
||||||
def publishStatus(self, s):
|
def publishStatus(self, s, strAuxInfo1="", strAuxInfo2=""):
|
||||||
self.callbackShowStatus(s, "pevState")
|
self.callbackShowStatus(s, "pevState", strAuxInfo1, strAuxInfo2)
|
||||||
|
|
||||||
def exiDecode(self, exidata, schema):
|
def exiDecode(self, exidata, schema):
|
||||||
s = compactHexMessage(exidata)
|
s = compactHexMessage(exidata)
|
||||||
|
@ -181,7 +181,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.publishStatus("ServiceDiscovery finished")
|
self.publishStatus("ServDisc done")
|
||||||
self.addToTrace("Will send ServicePaymentSelectionReq")
|
self.addToTrace("Will send ServicePaymentSelectionReq")
|
||||||
msg = addV2GTPHeader(self.exiEncode("EDC_"+self.sessionId)) # EDC for Encode, Din, ServicePaymentSelection
|
msg = addV2GTPHeader(self.exiEncode("EDC_"+self.sessionId)) # EDC for Encode, Din, ServicePaymentSelection
|
||||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||||
|
@ -199,7 +199,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.publishStatus("ServicePaymentSelection finished")
|
self.publishStatus("ServPaySel done")
|
||||||
self.addToTrace("Will send ContractAuthenticationReq")
|
self.addToTrace("Will send ContractAuthenticationReq")
|
||||||
msg = addV2GTPHeader(self.exiEncode("EDL_"+self.sessionId)) # EDL for Encode, Din, ContractAuthenticationReq.
|
msg = addV2GTPHeader(self.exiEncode("EDL_"+self.sessionId)) # EDL for Encode, Din, ContractAuthenticationReq.
|
||||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||||
|
@ -223,7 +223,7 @@ class fsmPev():
|
||||||
# needs to authorize by RFID card or app, or something like this.
|
# needs to authorize by RFID card or app, or something like this.
|
||||||
# Or, the authorization is finished. This is shown by EVSEProcessing=Finished.
|
# Or, the authorization is finished. This is shown by EVSEProcessing=Finished.
|
||||||
if (strConverterResult.find('"EVSEProcessing": "Finished"')>0):
|
if (strConverterResult.find('"EVSEProcessing": "Finished"')>0):
|
||||||
self.publishStatus("Authorization finished")
|
self.publishStatus("Auth finished")
|
||||||
self.addToTrace("It is Finished. Will send ChargeParameterDiscoveryReq")
|
self.addToTrace("It is Finished. Will send ChargeParameterDiscoveryReq")
|
||||||
self.sendChargeParameterDiscoveryReq()
|
self.sendChargeParameterDiscoveryReq()
|
||||||
self.numberOfChargeParameterDiscoveryReq = 1 # first message
|
self.numberOfChargeParameterDiscoveryReq = 1 # first message
|
||||||
|
@ -236,7 +236,7 @@ class fsmPev():
|
||||||
else:
|
else:
|
||||||
# Try again.
|
# Try again.
|
||||||
self.numberOfContractAuthenticationReq += 1 # count the number of tries.
|
self.numberOfContractAuthenticationReq += 1 # count the number of tries.
|
||||||
self.publishStatus("Waiting for Authorization")
|
self.publishStatus("Waiting f Auth")
|
||||||
self.addToTrace("Not (yet) finished. Will again send ContractAuthenticationReq #" + str(self.numberOfContractAuthenticationReq))
|
self.addToTrace("Not (yet) finished. Will again send ContractAuthenticationReq #" + str(self.numberOfContractAuthenticationReq))
|
||||||
msg = addV2GTPHeader(self.exiEncode("EDL_"+self.sessionId)) # EDL for Encode, Din, ContractAuthenticationReq.
|
msg = addV2GTPHeader(self.exiEncode("EDL_"+self.sessionId)) # EDL for Encode, Din, ContractAuthenticationReq.
|
||||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||||
|
@ -261,7 +261,7 @@ class fsmPev():
|
||||||
# (A) The charger needs more time to show the charge parameters.
|
# (A) The charger needs more time to show the charge parameters.
|
||||||
# (B) The charger finished to tell the charge parameters.
|
# (B) The charger finished to tell the charge parameters.
|
||||||
if (strConverterResult.find('"EVSEProcessing": "Finished"')>0):
|
if (strConverterResult.find('"EVSEProcessing": "Finished"')>0):
|
||||||
self.publishStatus("ChargeParameters discovered")
|
self.publishStatus("ChargeParams discovered")
|
||||||
self.addToTrace("It is Finished. Will change to state C and send CableCheckReq.")
|
self.addToTrace("It is Finished. Will change to state C and send CableCheckReq.")
|
||||||
# pull the CP line to state C here:
|
# pull the CP line to state C here:
|
||||||
self.hardwareInterface.setStateC()
|
self.hardwareInterface.setStateC()
|
||||||
|
@ -276,7 +276,7 @@ class fsmPev():
|
||||||
else:
|
else:
|
||||||
# Try again.
|
# Try again.
|
||||||
self.numberOfChargeParameterDiscoveryReq += 1 # count the number of tries.
|
self.numberOfChargeParameterDiscoveryReq += 1 # count the number of tries.
|
||||||
self.publishStatus("discovering ChargeParameters")
|
self.publishStatus("disc ChargeParams")
|
||||||
self.addToTrace("Not (yet) finished. Will again send ChargeParameterDiscoveryReq #" + str(self.numberOfChargeParameterDiscoveryReq))
|
self.addToTrace("Not (yet) finished. Will again send ChargeParameterDiscoveryReq #" + str(self.numberOfChargeParameterDiscoveryReq))
|
||||||
self.sendChargeParameterDiscoveryReq()
|
self.sendChargeParameterDiscoveryReq()
|
||||||
# we stay in the same state
|
# we stay in the same state
|
||||||
|
@ -306,7 +306,7 @@ 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=="Finished") and (strResponseCode=="OK")):
|
if ((strEVSEProcessing=="Finished") and (strResponseCode=="OK")):
|
||||||
self.publishStatus("CableCheck done")
|
self.publishStatus("CbleChck done")
|
||||||
self.addToTrace("The EVSE says that the CableCheck is finished and ok.")
|
self.addToTrace("The EVSE says that the CableCheck is finished and ok.")
|
||||||
self.addToTrace("Will send PreChargeReq")
|
self.addToTrace("Will send PreChargeReq")
|
||||||
soc = self.hardwareInterface.getSoc()
|
soc = self.hardwareInterface.getSoc()
|
||||||
|
@ -322,7 +322,7 @@ class fsmPev():
|
||||||
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.numberOfCableCheckReq += 1
|
self.numberOfCableCheckReq += 1
|
||||||
self.publishStatus("CableCheck ongoing")
|
self.publishStatus("CbleChck ongoing", format(self.hardwareInterface.getInletVoltage(),".0f") + "V")
|
||||||
self.addToTrace("Will again send CableCheckReq")
|
self.addToTrace("Will again send CableCheckReq")
|
||||||
self.sendCableCheckReq()
|
self.sendCableCheckReq()
|
||||||
# stay in the same state
|
# stay in the same state
|
||||||
|
@ -364,7 +364,7 @@ class fsmPev():
|
||||||
self.Tcp.transmit(msg)
|
self.Tcp.transmit(msg)
|
||||||
self.enterState(stateWaitForPowerDeliveryResponse)
|
self.enterState(stateWaitForPowerDeliveryResponse)
|
||||||
else:
|
else:
|
||||||
self.publishStatus("PreCharge ongoing")
|
self.publishStatus("PreChrge ongoing", format(self.hardwareInterface.getInletVoltage(), ".0f") + "V")
|
||||||
self.addToTrace("Difference too big. Continuing PreCharge.")
|
self.addToTrace("Difference too big. Continuing PreCharge.")
|
||||||
soc = self.hardwareInterface.getSoc()
|
soc = self.hardwareInterface.getSoc()
|
||||||
EVTargetVoltage = self.hardwareInterface.getAccuVoltage()
|
EVTargetVoltage = self.hardwareInterface.getAccuVoltage()
|
||||||
|
@ -384,13 +384,13 @@ class fsmPev():
|
||||||
self.addToTrace(strConverterResult)
|
self.addToTrace(strConverterResult)
|
||||||
if (strConverterResult.find("PowerDeliveryRes")>0):
|
if (strConverterResult.find("PowerDeliveryRes")>0):
|
||||||
if (self.wasPowerDeliveryRequestedOn):
|
if (self.wasPowerDeliveryRequestedOn):
|
||||||
self.publishStatus("PowerDelivery ON success")
|
self.publishStatus("PwrDelvy ON success")
|
||||||
self.addToTrace("Starting the charging loop with CurrentDemandReq")
|
self.addToTrace("Starting the charging loop with CurrentDemandReq")
|
||||||
self.sendCurrentDemandReq()
|
self.sendCurrentDemandReq()
|
||||||
self.enterState(stateWaitForCurrentDemandResponse)
|
self.enterState(stateWaitForCurrentDemandResponse)
|
||||||
else:
|
else:
|
||||||
# We requested "OFF". So we turn-off the Relay and continue with the Welding detection.
|
# We requested "OFF". So we turn-off the Relay and continue with the Welding detection.
|
||||||
self.publishStatus("PowerDelivery OFF success")
|
self.publishStatus("PwrDelvry OFF success")
|
||||||
self.addToTrace("Turning off the relay and starting the WeldingDetection")
|
self.addToTrace("Turning off the relay and starting the WeldingDetection")
|
||||||
self.hardwareInterface.setPowerRelayOff()
|
self.hardwareInterface.setPowerRelayOff()
|
||||||
self.hardwareInterface.setRelay2Off()
|
self.hardwareInterface.setRelay2Off()
|
||||||
|
@ -414,7 +414,7 @@ class fsmPev():
|
||||||
self.publishStatus("Accu full")
|
self.publishStatus("Accu full")
|
||||||
self.addToTrace("Accu is full. Sending PowerDeliveryReq Stop.")
|
self.addToTrace("Accu is full. Sending PowerDeliveryReq Stop.")
|
||||||
else:
|
else:
|
||||||
self.publishStatus("User requested stop")
|
self.publishStatus("User req stop")
|
||||||
self.addToTrace("User requested stop. Sending PowerDeliveryReq Stop.")
|
self.addToTrace("User requested stop. Sending PowerDeliveryReq Stop.")
|
||||||
soc = self.hardwareInterface.getSoc()
|
soc = self.hardwareInterface.getSoc()
|
||||||
msg = addV2GTPHeader(self.exiEncode("EDH_"+self.sessionId+"_"+ str(soc) + "_" + "0")) # EDH for Encode, Din, PowerDeliveryReq, OFF
|
msg = addV2GTPHeader(self.exiEncode("EDH_"+self.sessionId+"_"+ str(soc) + "_" + "0")) # EDH for Encode, Din, PowerDeliveryReq, OFF
|
||||||
|
@ -424,15 +424,15 @@ class fsmPev():
|
||||||
self.enterState(stateWaitForPowerDeliveryResponse)
|
self.enterState(stateWaitForPowerDeliveryResponse)
|
||||||
else:
|
else:
|
||||||
# continue charging loop
|
# continue charging loop
|
||||||
self.publishStatus("Charging")
|
self.publishStatus("Charging", format(self.hardwareInterface.getInletVoltage(), ".0f") + "V", format(self.hardwareInterface.getSoc(), ".1f") + "%")
|
||||||
self.sendCurrentDemandReq()
|
self.sendCurrentDemandReq()
|
||||||
self.enterState(stateWaitForCurrentDemandResponse)
|
self.enterState(stateWaitForCurrentDemandResponse)
|
||||||
if (self.isLightBulbDemo):
|
if (self.isLightBulbDemo):
|
||||||
if (self.cyclesLightBulbDelay<=33*5):
|
if (self.cyclesLightBulbDelay<=33*2):
|
||||||
self.cyclesLightBulbDelay+=1
|
self.cyclesLightBulbDelay+=1
|
||||||
else:
|
else:
|
||||||
if (not self.isBulbOn):
|
if (not self.isBulbOn):
|
||||||
self.addToTrace("This is a light bulb demo. Turning-on the bulb when 5s in the main charging loop.")
|
self.addToTrace("This is a light bulb demo. Turning-on the bulb when 2s in the main charging loop.")
|
||||||
self.hardwareInterface.setPowerRelayOn()
|
self.hardwareInterface.setPowerRelayOn()
|
||||||
self.hardwareInterface.setRelay2On()
|
self.hardwareInterface.setRelay2On()
|
||||||
self.isBulbOn = True
|
self.isBulbOn = True
|
||||||
|
@ -448,7 +448,7 @@ class fsmPev():
|
||||||
self.addToTrace(strConverterResult)
|
self.addToTrace(strConverterResult)
|
||||||
if (strConverterResult.find("WeldingDetectionRes")>0):
|
if (strConverterResult.find("WeldingDetectionRes")>0):
|
||||||
# todo: add real welding detection here, run in welding detection loop until finished.
|
# todo: add real welding detection here, run in welding detection loop until finished.
|
||||||
self.publishStatus("WeldingDetection done")
|
self.publishStatus("WldingDet done")
|
||||||
self.addToTrace("Sending SessionStopReq")
|
self.addToTrace("Sending SessionStopReq")
|
||||||
msg = addV2GTPHeader(self.exiEncode("EDK_"+self.sessionId)) # EDI for Encode, Din, SessionStopReq
|
msg = addV2GTPHeader(self.exiEncode("EDK_"+self.sessionId)) # EDI for Encode, Din, SessionStopReq
|
||||||
self.addToTrace("responding " + prettyHexMessage(msg))
|
self.addToTrace("responding " + prettyHexMessage(msg))
|
||||||
|
@ -468,7 +468,7 @@ class fsmPev():
|
||||||
# req -508
|
# req -508
|
||||||
# Todo: close the TCP connection here.
|
# Todo: close the TCP connection here.
|
||||||
# Todo: Unlock the connector lock.
|
# Todo: Unlock the connector lock.
|
||||||
self.publishStatus("Session stopped normally")
|
self.publishStatus("Stopped normally")
|
||||||
self.hardwareInterface.setStateB()
|
self.hardwareInterface.setStateB()
|
||||||
self.addToTrace("Charging is finished")
|
self.addToTrace("Charging is finished")
|
||||||
self.enterState(stateChargingFinished)
|
self.enterState(stateChargingFinished)
|
||||||
|
|
|
@ -62,8 +62,8 @@ class hardwareInterface():
|
||||||
self.outvalue &= ~4
|
self.outvalue &= ~4
|
||||||
|
|
||||||
def getInletVoltage(self):
|
def getInletVoltage(self):
|
||||||
#todo: get real measured voltage from the inlet
|
# uncomment this line, to take the simulated inlet voltage instead of the really measured
|
||||||
self.inletVoltage = self.simulatedInletVoltage
|
# self.inletVoltage = self.simulatedInletVoltage
|
||||||
return self.inletVoltage
|
return self.inletVoltage
|
||||||
|
|
||||||
def getAccuVoltage(self):
|
def getAccuVoltage(self):
|
||||||
|
@ -121,9 +121,9 @@ class hardwareInterface():
|
||||||
s = self.rxbuffer[x+3:x+7]
|
s = self.rxbuffer[x+3:x+7]
|
||||||
if (len(s)==4):
|
if (len(s)==4):
|
||||||
try:
|
try:
|
||||||
self.uInlet_V = int(s) / 1024.0 * 1.08 * (6250) / (4.7+4.7)
|
self.inletVoltage = int(s) / 1024.0 * 1.08 * (6250) / (4.7+4.7)
|
||||||
|
|
||||||
self.callbackShowStatus(format(self.uInlet_V,".1f"), "uInlet")
|
self.callbackShowStatus(format(self.inletVoltage,".1f"), "uInlet")
|
||||||
except:
|
except:
|
||||||
# keep last known value, if nothing new valid was received.
|
# keep last known value, if nothing new valid was received.
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -54,10 +54,10 @@ class pyPlcWorker():
|
||||||
self.callbackAddToTrace(s) # give the message to the upper level, eg for console log.
|
self.callbackAddToTrace(s) # give the message to the upper level, eg for console log.
|
||||||
self.hp.printToUdp(s) # give the message to the udp for remote logging.
|
self.hp.printToUdp(s) # give the message to the udp for remote logging.
|
||||||
|
|
||||||
def showStatus(self, s, selection = ""):
|
def showStatus(self, s, selection = "", strAuxInfo1="", strAuxInfo2=""):
|
||||||
self.callbackShowStatus(s, selection)
|
self.callbackShowStatus(s, selection)
|
||||||
if (selection == "pevState"):
|
if (selection == "pevState"):
|
||||||
self.hardwareInterface.showOnDisplay(s, "", "")
|
self.hardwareInterface.showOnDisplay(s, strAuxInfo1, strAuxInfo2)
|
||||||
|
|
||||||
def callbackReadyForTcp(self, status):
|
def callbackReadyForTcp(self, status):
|
||||||
if (status==1):
|
if (status==1):
|
||||||
|
|
Loading…
Reference in a new issue