added encoding details (SOC etc)

This commit is contained in:
uhi22 2022-12-09 14:23:32 +01:00
parent ed3a8922aa
commit 3732c4eb2f
3 changed files with 55 additions and 27 deletions

View file

@ -2,7 +2,7 @@
- [ ] PevMode: PreChargeReq: Fill EVRESSSOC, EVTargetVoltage, EVTargetCurrent - [ ] PevMode: PreChargeReq: Fill EVRESSSOC, EVTargetVoltage, EVTargetCurrent
- [ ] PevMode: PowerDeliveryReq: Fill EVRESSSOC, Stop/Start - [ ] PevMode: PowerDeliveryReq: Fill EVRESSSOC, Stop/Start
- [ ] PevMode: CurrentDemandReq: Fill EVTargetCurrent, EVMaximumVoltageLimit - [ ] PevMode: CurrentDemandReq: Fill EVRESSSOC, EVTargetCurrent, EVTargetVoltage
- [ ] EvseMode: CurrentDemandRes: Fill EVSEPresentVoltage, EVSEPresentCurrent, EVSEMaximumVoltageLimit, ...LimitAchieved - [ ] EvseMode: CurrentDemandRes: Fill EVSEPresentVoltage, EVSEPresentCurrent, EVSEMaximumVoltageLimit, ...LimitAchieved
- [ ] EvseMode: Fill V2G messages as far as needed, to convince the car to accept it. - [ ] EvseMode: Fill V2G messages as far as needed, to convince the car to accept it.
- [ ] PevMode: Fill V2G messages as far as needed, to convince the charger to accept it. - [ ] PevMode: Fill V2G messages as far as needed, to convince the charger to accept it.

View file

@ -50,6 +50,33 @@ class fsmPev():
self.exiLogFile.write(schema + " " + s +"\n") # write the EXI data to the exiLogFile self.exiLogFile.write(schema + " " + s +"\n") # write the EXI data to the exiLogFile
return exidata return exidata
def sendChargeParameterDiscoveryReq(self):
soc = str(self.hardwareInterface.getSoc())
msg = addV2GTPHeader(self.exiEncode("EDE_"+self.sessionId + "_" + soc)) # EDE for Encode, Din, ChargeParameterDiscovery.
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
def sendCableCheckReq(self):
soc = str(self.hardwareInterface.getSoc())
msg = addV2GTPHeader(self.exiEncode("EDF_"+self.sessionId + "_" + soc)) # EDF for Encode, Din, CableCheckReq
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
def sendCurrentDemandReq(self):
soc = str(self.hardwareInterface.getSoc())
EVTargetCurrent = str(self.hardwareInterface.getAccuMaxCurrent)
EVTargetVoltage = str(self.hardwareInterface.getAccuMaxVoltage)
msg = addV2GTPHeader(self.exiEncode("EDI_"+self.sessionId + "_" + soc + "_" + EVTargetCurrent + "_" + EVTargetVoltage )) # EDI for Encode, Din, CurrentDemandReq
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
def sendWeldingDetectionReq(self):
soc = str(self.hardwareInterface.getSoc())
msg = addV2GTPHeader(self.exiEncode("EDJ_"+self.sessionId + "_" + soc)) # EDI for Encode, Din, WeldingDetectionReq
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
def enterState(self, n): def enterState(self, n):
print("from " + str(self.state) + " entering " + str(n)) print("from " + str(self.state) + " entering " + str(n))
self.state = n self.state = n
@ -184,9 +211,7 @@ class fsmPev():
# 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.addToTrace("It is Finished. Will send ChargeParameterDiscoveryReq") self.addToTrace("It is Finished. Will send ChargeParameterDiscoveryReq")
msg = addV2GTPHeader(self.exiEncode("EDE_"+self.sessionId)) # EDE for Encode, Din, ChargeParameterDiscovery. self.sendChargeParameterDiscoveryReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
self.numberOfChargeParameterDiscoveryReq = 1 # first message self.numberOfChargeParameterDiscoveryReq = 1 # first message
self.enterState(stateWaitForChargeParameterDiscoveryResponse) self.enterState(stateWaitForChargeParameterDiscoveryResponse)
else: else:
@ -224,9 +249,7 @@ class fsmPev():
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()
msg = addV2GTPHeader(self.exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck self.sendCableCheckReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
self.numberOfCableCheckReq = 1 # This is the first request. self.numberOfCableCheckReq = 1 # This is the first request.
self.enterState(stateWaitForCableCheckResponse) self.enterState(stateWaitForCableCheckResponse)
else: else:
@ -238,9 +261,7 @@ class fsmPev():
# Try again. # Try again.
self.numberOfChargeParameterDiscoveryReq += 1 # count the number of tries. self.numberOfChargeParameterDiscoveryReq += 1 # count the number of tries.
self.addToTrace("Not (yet) finished. Will again send ChargeParameterDiscoveryReq #" + str(self.numberOfChargeParameterDiscoveryReq)) self.addToTrace("Not (yet) finished. Will again send ChargeParameterDiscoveryReq #" + str(self.numberOfChargeParameterDiscoveryReq))
msg = addV2GTPHeader(self.exiEncode("EDE_"+self.sessionId)) # EDE for Encode, Din, ChargeParameterDiscovery. self.sendChargeParameterDiscoveryReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
# we stay in the same state # we stay in the same state
self.enterState(stateWaitForChargeParameterDiscoveryResponse) self.enterState(stateWaitForChargeParameterDiscoveryResponse)
if (self.isTooLong()): if (self.isTooLong()):
@ -270,7 +291,9 @@ class fsmPev():
if ((strEVSEProcessing=="Finished") and (strResponseCode=="OK")): if ((strEVSEProcessing=="Finished") and (strResponseCode=="OK")):
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")
msg = addV2GTPHeader(self.exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge soc = self.hardwareInterface.getSoc()
EVTargetVoltage = self.hardwareInterface.getAccuVoltage()
msg = addV2GTPHeader(self.exiEncode("EDG_"+self.sessionId+"_"+str(soc)+"_"+str(EVTargetVoltage))) # EDG for Encode, Din, PreChargeReq
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
self.enterState(stateWaitForPreChargeResponse) self.enterState(stateWaitForPreChargeResponse)
@ -282,9 +305,7 @@ class fsmPev():
# 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.addToTrace("Will again send CableCheckReq") self.addToTrace("Will again send CableCheckReq")
msg = addV2GTPHeader(self.exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck self.sendCableCheckReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
# stay in the same state # stay in the same state
self.enterState(stateWaitForCableCheckResponse) self.enterState(stateWaitForCableCheckResponse)
@ -307,15 +328,17 @@ class fsmPev():
if (abs(self.hardwareInterface.getInletVoltage()-self.hardwareInterface.getAccuVoltage()) < PARAM_U_DELTA_MAX_FOR_END_OF_PRECHARGE): if (abs(self.hardwareInterface.getInletVoltage()-self.hardwareInterface.getAccuVoltage()) < PARAM_U_DELTA_MAX_FOR_END_OF_PRECHARGE):
self.addToTrace("Difference between accu voltage and inlet voltage is small. Sending PowerDeliveryReq.") self.addToTrace("Difference between accu voltage and inlet voltage is small. Sending PowerDeliveryReq.")
self.hardwareInterface.setPowerRelayOn() self.hardwareInterface.setPowerRelayOn()
msg = addV2GTPHeader(self.exiEncode("EDH_"+self.sessionId+"_"+"1")) # EDH for Encode, Din, PowerDeliveryReq, ON soc = self.hardwareInterface.getSoc()
msg = addV2GTPHeader(self.exiEncode("EDH_"+self.sessionId+"_"+ str(soc) + "_" + "1")) # EDH for Encode, Din, PowerDeliveryReq, ON
self.wasPowerDeliveryRequestedOn=True self.wasPowerDeliveryRequestedOn=True
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
self.enterState(stateWaitForPowerDeliveryResponse) self.enterState(stateWaitForPowerDeliveryResponse)
else: else:
self.addToTrace("Difference too big. Continuing PreCharge.") self.addToTrace("Difference too big. Continuing PreCharge.")
#self.addToTrace("As Demo, we stay in PreCharge forever.") soc = self.hardwareInterface.getSoc()
msg = addV2GTPHeader(self.exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge EVTargetVoltage = self.hardwareInterface.getAccuVoltage()
msg = addV2GTPHeader(self.exiEncode("EDG_"+self.sessionId+"_"+str(soc)+"_"+str(EVTargetVoltage))) # EDG for Encode, Din, PreChargeReq
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
self.DelayCycles=15 # wait with the next evaluation approx half a second self.DelayCycles=15 # wait with the next evaluation approx half a second
@ -332,17 +355,13 @@ class fsmPev():
if (strConverterResult.find("PowerDeliveryRes")>0): if (strConverterResult.find("PowerDeliveryRes")>0):
if (self.wasPowerDeliveryRequestedOn): if (self.wasPowerDeliveryRequestedOn):
self.addToTrace("Starting the charging loop with CurrentDemandReq") self.addToTrace("Starting the charging loop with CurrentDemandReq")
msg = addV2GTPHeader(self.exiEncode("EDI_"+self.sessionId)) # EDI for Encode, Din, CurrentDemandReq self.sendCurrentDemandReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
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.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()
msg = addV2GTPHeader(self.exiEncode("EDJ_"+self.sessionId)) # EDI for Encode, Din, WeldingDetectionReq self.sendWeldingDetectionReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
self.enterState(stateWaitForWeldingDetectionResponse) self.enterState(stateWaitForWeldingDetectionResponse)
if (self.isTooLong()): if (self.isTooLong()):
self.enterState(stateSequenceTimeout) self.enterState(stateSequenceTimeout)
@ -358,16 +377,15 @@ class fsmPev():
# as long as the accu is not full and no stop-demand from the user, we continue charging # as long as the accu is not full and no stop-demand from the user, we continue charging
if (self.hardwareInterface.getIsAccuFull()): if (self.hardwareInterface.getIsAccuFull()):
self.addToTrace("Accu is full. Sending PowerDeliveryReq Stop.") self.addToTrace("Accu is full. Sending PowerDeliveryReq Stop.")
msg = addV2GTPHeader(self.exiEncode("EDH_"+self.sessionId+"_"+"0")) # EDH for Encode, Din, PowerDeliveryReq, OFF soc = self.hardwareInterface.getSoc()
msg = addV2GTPHeader(self.exiEncode("EDH_"+self.sessionId+"_"+ str(soc) + "_" + "0")) # EDH for Encode, Din, PowerDeliveryReq, OFF
self.wasPowerDeliveryRequestedOn=False self.wasPowerDeliveryRequestedOn=False
self.addToTrace("responding " + prettyHexMessage(msg)) self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg) self.Tcp.transmit(msg)
self.enterState(stateWaitForPowerDeliveryResponse) self.enterState(stateWaitForPowerDeliveryResponse)
else: else:
# continue charging loop # continue charging loop
msg = addV2GTPHeader(self.exiEncode("EDI_"+self.sessionId)) # EDI for Encode, Din, CurrentDemandReq self.sendCurrentDemandReq()
self.addToTrace("responding " + prettyHexMessage(msg))
self.Tcp.transmit(msg)
self.enterState(stateWaitForCurrentDemandResponse) self.enterState(stateWaitForCurrentDemandResponse)
if (self.isTooLong()): if (self.isTooLong()):
@ -381,6 +399,7 @@ class fsmPev():
strConverterResult = self.exiDecode(exidata, "DD") # Decode DIN strConverterResult = self.exiDecode(exidata, "DD") # Decode DIN
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.
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))

View file

@ -65,10 +65,19 @@ class hardwareInterface():
self.accuMaxCurrent = 10 self.accuMaxCurrent = 10
return self.accuMaxCurrent return self.accuMaxCurrent
def getAccuMaxVoltage(self):
#todo: get max charging voltage from the BMS
self.accuMaxVoltage = 230
return self.accuMaxVoltage
def getIsAccuFull(self): def getIsAccuFull(self):
#todo: get "full" indication from the BMS #todo: get "full" indication from the BMS
self.IsAccuFull = (self.simulatedSoc >= 98) self.IsAccuFull = (self.simulatedSoc >= 98)
return self.IsAccuFull return self.IsAccuFull
def getSoc(self):
#todo: get SOC from the BMS
return self.simulatedSoc
def __init__(self, callbackAddToTrace=None): def __init__(self, callbackAddToTrace=None):