2022-10-14 16:11:01 +00:00
|
|
|
# Worker for the pyPLC
|
|
|
|
#
|
|
|
|
# Tested on Windows10 with python 3.9
|
|
|
|
#
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
import pyPlcHomeplug
|
2022-11-07 08:21:25 +00:00
|
|
|
import fsmEvse
|
|
|
|
import fsmPev
|
|
|
|
from pyPlcModes import *
|
2022-11-11 10:21:28 +00:00
|
|
|
import addressManager
|
|
|
|
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
class pyPlcWorker():
|
2022-11-07 08:21:25 +00:00
|
|
|
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None, mode=C_EVSE_MODE):
|
2022-10-14 16:11:01 +00:00
|
|
|
print("initializing pyPlcWorker")
|
|
|
|
self.nMainFunctionCalls=0
|
2022-11-07 08:21:25 +00:00
|
|
|
self.mode = mode
|
2022-10-14 16:11:01 +00:00
|
|
|
self.strUserAction = ""
|
2022-11-11 10:21:28 +00:00
|
|
|
self.addressManager = addressManager.addressManager()
|
|
|
|
self.addressManager.findLinkLocalIpv6Address()
|
2022-10-14 16:11:01 +00:00
|
|
|
self.callbackAddToTrace = callbackAddToTrace
|
|
|
|
self.callbackShowStatus = callbackShowStatus
|
2022-11-11 10:21:28 +00:00
|
|
|
self.hp = pyPlcHomeplug.pyPlcHomeplug(self.callbackAddToTrace, self.callbackShowStatus, self.mode, self.addressManager)
|
2022-11-07 08:21:25 +00:00
|
|
|
if (self.mode == C_EVSE_MODE):
|
|
|
|
self.evse = fsmEvse.fsmEvse()
|
|
|
|
if (self.mode == C_PEV_MODE):
|
|
|
|
self.pev = fsmPev.fsmPev()
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
def addToTrace(self, s):
|
|
|
|
self.callbackAddToTrace(s)
|
|
|
|
|
2022-10-19 16:52:43 +00:00
|
|
|
def showStatus(self, s, selection = ""):
|
|
|
|
self.callbackShowStatus(s, selection)
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
def mainfunction(self):
|
|
|
|
self.nMainFunctionCalls+=1
|
2022-10-14 21:36:03 +00:00
|
|
|
#self.showStatus("pyPlcWorker loop " + str(self.nMainFunctionCalls))
|
|
|
|
self.hp.mainfunction() # call the lower-level worker
|
2022-11-07 08:21:25 +00:00
|
|
|
if (self.mode == C_EVSE_MODE):
|
|
|
|
self.evse.mainfunction() # call the evse state machine
|
|
|
|
if (self.mode == C_PEV_MODE):
|
|
|
|
self.pev.mainfunction() # call the pev state machine
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
def handleUserAction(self, strAction):
|
|
|
|
self.strUserAction = strAction
|
2022-10-19 16:52:43 +00:00
|
|
|
if (strAction == "P"):
|
2022-11-07 08:21:25 +00:00
|
|
|
print("switching to PEV mode")
|
|
|
|
self.mode = C_PEV_MODE
|
|
|
|
if (hasattr(self, 'evse')):
|
|
|
|
print("deleting evse")
|
|
|
|
del self.evse
|
2022-10-19 16:52:43 +00:00
|
|
|
self.hp.enterPevMode()
|
2022-11-07 08:21:25 +00:00
|
|
|
if (not hasattr(self, 'pev')):
|
|
|
|
print("creating pev")
|
|
|
|
self.pev = fsmPev.fsmPev()
|
|
|
|
self.pev.reInit()
|
2022-10-19 16:52:43 +00:00
|
|
|
if (strAction == "E"):
|
2022-11-07 08:21:25 +00:00
|
|
|
print("switching to EVSE mode")
|
|
|
|
self.mode = C_EVSE_MODE
|
|
|
|
if (hasattr(self, 'pev')):
|
|
|
|
print("deleting pev")
|
|
|
|
del self.pev
|
2022-10-19 16:52:43 +00:00
|
|
|
self.hp.enterEvseMode()
|
2022-11-07 08:21:25 +00:00
|
|
|
if (not hasattr(self, 'evse')):
|
|
|
|
print("creating fsmEvse")
|
|
|
|
self.evse = fsmEvse.fsmEvse()
|
|
|
|
self.evse.reInit()
|
2022-10-19 16:52:43 +00:00
|
|
|
if (strAction == "L"):
|
2022-11-07 08:21:25 +00:00
|
|
|
print("switching to LISTEN mode")
|
|
|
|
self.mode = C_LISTEN_MODE
|
2022-10-24 21:19:45 +00:00
|
|
|
self.hp.enterListenMode()
|
2022-11-07 08:21:25 +00:00
|
|
|
if (hasattr(self, 'evse')):
|
|
|
|
print("deleting evse")
|
|
|
|
del self.evse
|
|
|
|
if (hasattr(self, 'pev')):
|
|
|
|
print("deleting pev")
|
|
|
|
del self.pev
|
2022-10-24 21:19:45 +00:00
|
|
|
# self.addToTrace("UserAction " + strAction)
|
2022-10-16 00:57:57 +00:00
|
|
|
self.hp.sendTestFrame(strAction)
|
2022-10-14 16:11:01 +00:00
|
|
|
|