mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-20 01:13:58 +00:00
introduced sessionId
This commit is contained in:
parent
19219e49a5
commit
d153af9002
5 changed files with 32 additions and 12 deletions
|
@ -121,7 +121,8 @@ class fsmEvse():
|
|||
self.enterState(stateWaitForFlexibleRequest) # todo: not clear, what is specified in DIN
|
||||
if (strConverterResult.find("PreChargeReq")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
msg = addV2GTPHeader(exiEncode("EDg")) # EDg for Encode, Din, PreChargeResponse
|
||||
strPresentVoltage = "345"
|
||||
msg = addV2GTPHeader(exiEncode("EDg_"+strPresentVoltage)) # EDg for Encode, Din, PreChargeResponse
|
||||
print("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForFlexibleRequest) # todo: not clear, what is specified in DIN
|
||||
|
|
19
fsmPev.py
19
fsmPev.py
|
@ -8,6 +8,7 @@ import pyPlcTcpSocket
|
|||
import time # for time.sleep()
|
||||
from helpers import prettyHexMessage
|
||||
from exiConnector import * # for EXI data handling/converting
|
||||
import json
|
||||
|
||||
stateInitialized = 0
|
||||
stateWaitForSupportedApplicationProtocolResponse = 1
|
||||
|
@ -62,7 +63,14 @@ class fsmPev():
|
|||
print(strConverterResult)
|
||||
if (strConverterResult.find("SessionSetupRes")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
msg = addV2GTPHeader(exiEncode("EDB")) # EDB for Encode, Din, ServiceDiscoveryRequest
|
||||
try:
|
||||
y = json.loads(strConverterResult)
|
||||
strSessionId = y["header.SessionID"]
|
||||
print("[PEV] The Evse decided for SessionId " + strSessionId)
|
||||
self.sessionId = strSessionId
|
||||
except:
|
||||
print("ERROR: Could not decode the sessionID")
|
||||
msg = addV2GTPHeader(exiEncode("EDB_"+self.sessionId)) # EDB for Encode, Din, ServiceDiscoveryRequest
|
||||
print("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForServiceDiscoveryResponse)
|
||||
|
@ -78,7 +86,7 @@ class fsmPev():
|
|||
print(strConverterResult)
|
||||
if (strConverterResult.find("ServiceDiscoveryRes")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
msg = addV2GTPHeader(exiEncode("EDC")) # EDC for Encode, Din, ServicePaymentSelection
|
||||
msg = addV2GTPHeader(exiEncode("EDC_"+self.sessionId)) # EDC for Encode, Din, ServicePaymentSelection
|
||||
print("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForServicePaymentSelectionResponse)
|
||||
|
@ -94,7 +102,7 @@ class fsmPev():
|
|||
print(strConverterResult)
|
||||
if (strConverterResult.find("ServicePaymentSelectionRes")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
msg = addV2GTPHeader(exiEncode("EDE")) # 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.
|
||||
print("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForChargeParameterDiscoveryResponse)
|
||||
|
@ -110,7 +118,7 @@ class fsmPev():
|
|||
print(strConverterResult)
|
||||
if (strConverterResult.find("ChargeParameterDiscoveryRes")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
msg = addV2GTPHeader(exiEncode("EDF")) # EDF for Encode, Din, CableCheck
|
||||
msg = addV2GTPHeader(exiEncode("EDF_"+self.sessionId)) # EDF for Encode, Din, CableCheck
|
||||
print("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForCableCheckResponse)
|
||||
|
@ -126,7 +134,7 @@ class fsmPev():
|
|||
print(strConverterResult)
|
||||
if (strConverterResult.find("CableCheckRes")>0):
|
||||
# todo: check the request content, and fill response parameters
|
||||
msg = addV2GTPHeader(exiEncode("EDG")) # EDG for Encode, Din, PreCharge
|
||||
msg = addV2GTPHeader(exiEncode("EDG_"+self.sessionId)) # EDG for Encode, Din, PreCharge
|
||||
print("responding " + prettyHexMessage(msg))
|
||||
self.Tcp.transmit(msg)
|
||||
self.enterState(stateWaitForPreChargeResponse)
|
||||
|
@ -181,6 +189,7 @@ class fsmPev():
|
|||
self.Tcp = pyPlcTcpSocket.pyPlcTcpClientSocket()
|
||||
self.addressManager = addressManager
|
||||
self.state = stateNotYetInitialized
|
||||
self.sessionId = "DEAD55AADEAD55AA"
|
||||
self.cyclesInState = 0
|
||||
self.rxData = []
|
||||
# we do NOT call the reInit, because we want to wait with the connection until external trigger comes
|
||||
|
|
7
pyPlc.py
7
pyPlc.py
|
@ -48,6 +48,11 @@ if (len(sys.argv) > 1):
|
|||
if (sys.argv[1] == "E"):
|
||||
myMode = C_EVSE_MODE
|
||||
|
||||
isSimulationMode=0
|
||||
if (len(sys.argv) > 2):
|
||||
if (sys.argv[2] == "S"):
|
||||
isSimulationMode=1
|
||||
|
||||
if (myMode == C_LISTEN_MODE):
|
||||
print("starting in LISTEN_MODE")
|
||||
if (myMode == C_PEV_MODE):
|
||||
|
@ -71,7 +76,7 @@ lblMode.pack()
|
|||
root.bind('<Key>', storekeyname)
|
||||
cbShowStatus("initialized")
|
||||
root.update()
|
||||
worker=pyPlcWorker.pyPlcWorker(cbAddToTrace, cbShowStatus, myMode)
|
||||
worker=pyPlcWorker.pyPlcWorker(cbAddToTrace, cbShowStatus, myMode, isSimulationMode)
|
||||
|
||||
nMainloops=0
|
||||
nKeystrokes=0
|
||||
|
|
|
@ -733,7 +733,10 @@ class pyPlcHomeplug():
|
|||
if (self.pevSequenceState==10): # SLAC is finished, SET_KEY.REQ is transmitted. Wait some time, until
|
||||
# the homeplug modem made the reset and is ready with the new key.
|
||||
self.addToTrace("[PEVSLAC] waiting until homeplug modem starts up with new key...")
|
||||
self.pevSequenceDelayCycles = 200
|
||||
if (self.isSimulationMode==0):
|
||||
self.pevSequenceDelayCycles = 200 # long waiting time if we have real homeplug modems
|
||||
else:
|
||||
self.pevSequenceDelayCycles = 10 # short waiting in simulation
|
||||
self.enterState(11)
|
||||
return
|
||||
if (self.pevSequenceState==11):
|
||||
|
@ -755,7 +758,7 @@ class pyPlcHomeplug():
|
|||
return
|
||||
# we should have received a software version response from at least two modems.
|
||||
print("[PEVSLAC] Number of modems in the AVLN: " + str(self.numberOfSoftwareVersionResponses))
|
||||
if (self.numberOfSoftwareVersionResponses<2):
|
||||
if ((self.numberOfSoftwareVersionResponses<2) and (self.isSimulationMode==0)):
|
||||
print("[PEVSLAC] ERROR: There should be at least two modems, one from car and one from charger.")
|
||||
self.callbackAvlnEstablished(0) # report that we lost the connection
|
||||
self.addressManager.setSeccIp("") # forget the IPv6 of the charger
|
||||
|
@ -809,7 +812,7 @@ class pyPlcHomeplug():
|
|||
self.ipv6.enterListenMode()
|
||||
self.showStatus("LISTEN mode", "mode")
|
||||
|
||||
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None, mode=C_LISTEN_MODE, addrMan=None, callbackAvlnEstablished=None):
|
||||
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None, mode=C_LISTEN_MODE, addrMan=None, callbackAvlnEstablished=None, isSimulationMode=0):
|
||||
self.mytransmitbuffer = bytearray("Hallo das ist ein Test", 'UTF-8')
|
||||
self.nPacketsReceived = 0
|
||||
self.callbackAddToTrace = callbackAddToTrace
|
||||
|
@ -819,6 +822,7 @@ class pyPlcHomeplug():
|
|||
self.pevSequenceState = 0
|
||||
self.pevSequenceCyclesInState = 0
|
||||
self.numberOfSoftwareVersionResponses = 0
|
||||
self.isSimulationMode = isSimulationMode # simulation without homeplug modem
|
||||
#self.sniffer = pcap.pcap(name=None, promisc=True, immediate=True, timeout_ms=50)
|
||||
# eth3 means: Third entry from back, in the list of interfaces, which is provided by pcap.findalldevs.
|
||||
# Improvement necessary: select the interface based on the name.
|
||||
|
|
|
@ -12,7 +12,7 @@ import addressManager
|
|||
|
||||
|
||||
class pyPlcWorker():
|
||||
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None, mode=C_EVSE_MODE):
|
||||
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None, mode=C_EVSE_MODE, isSimulationMode=0):
|
||||
print("initializing pyPlcWorker")
|
||||
self.nMainFunctionCalls=0
|
||||
self.mode = mode
|
||||
|
@ -22,7 +22,8 @@ class pyPlcWorker():
|
|||
self.callbackAddToTrace = callbackAddToTrace
|
||||
self.callbackShowStatus = callbackShowStatus
|
||||
self.oldAvlnStatus = 0
|
||||
self.hp = pyPlcHomeplug.pyPlcHomeplug(self.callbackAddToTrace, self.callbackShowStatus, self.mode, self.addressManager, self.callbackAvlnEstablished)
|
||||
self.isSimulationMode = isSimulationMode
|
||||
self.hp = pyPlcHomeplug.pyPlcHomeplug(self.callbackAddToTrace, self.callbackShowStatus, self.mode, self.addressManager, self.callbackAvlnEstablished, self.isSimulationMode)
|
||||
if (self.mode == C_EVSE_MODE):
|
||||
self.evse = fsmEvse.fsmEvse()
|
||||
if (self.mode == C_PEV_MODE):
|
||||
|
|
Loading…
Reference in a new issue