lpcmanager

FW update : change default 256K transfer chunksize to 56K, compatible with maximum eRPC payload size of 64K.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# --------- Libraries Extension ------------
#
import features
from POULibrary import SimplePOULibraryFactory, UserAddressedException
from LPCArch import GetLPCProduct, GetLPCSOM, WX_GOT_modules, SOM28_modules, SOM6_modules, SVG_GOT_modules, GetLPCArch, PREEMPTSOM6_modules
# _lpcmanager_path, arch, etc are defined here because
# globals() of LPCManager.py are passed to extentions
wanted_features_names = ["c_ext", "py_ext"]
features.libraries=[('Native', 'NativeLib.NativeLibrary', True)]
def _poulibpath(name):
return os.path.join(_lpcmanager_path, 'Pous', "pous"+name+".xml")
product = GetLPCProduct()
if product in SOM28_modules + SOM6_modules:
features.libraries += [('Python', 'py_ext.PythonLibrary', True),
('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True)]
if product in WX_GOT_modules + SVG_GOT_modules:
features.libraries += [('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)]
if product in SOM6_modules:
features.libraries += [('SVGHMI', 'LPCSVGHMI.SVGHMILibrary', True)]
else: # MC8 ?
features.libraries += [('LPC', SimplePOULibraryFactory(_poulibpath("LPC")), True)]
if product in WX_GOT_modules:
wanted_features_names.extend(["wxglade_hmi"])
#
# --------- Configuration Tree Nodes (CTN) catalog extension ------------
#
_oldcatalog = features.catalog
catalog_index = dict(list(zip(list(zip(*_oldcatalog))[0],_oldcatalog)))
wanted_beremiz_features = [catalog_index[feature]
for feature in wanted_features_names]
features.catalog = wanted_beremiz_features + [
('lpchmi', _('Smarteh HMI'), _('Create customized HMI'), 'lpchmi.LPCHMI'),
('bacnet', _('Bacnet support'), _('Map located variables over Bacnet'), 'LPCBACnet.RootClass'),
('modbus', _('Modbus'), _('Map located variables over Modbus'), 'LPCModbus.RootClass'),
('LPCBus', _('LPC bus'), _('Support for Smarteh modules'), 'LPCBus.LPCBus'),
('CanOpen', _('CANOpen'), _('Support for CANopen'), 'LPCCanFestival.LPCCanOpen')]
if product in SOM6_modules:
features.catalog += [ catalog_index['svghmi'][:3]+('LPCSVGHMI.SVGHMI',) ]
#
# --------- Connectors Extension ------------
#
import connectors
from functools import partial
# On demand monkey patching
def CustomWAMPFactory(*args, **kwargs):
from connectors import WAMP
from WampAuthentication import WampSession
return WAMP._WAMP_connector_factory(WampSession, *args, **kwargs)
connectors.connectors["WAMP"] = lambda:CustomWAMPFactory
from erpc_interface.erpc_PLCObject.client import BeremizPLCObjectServiceClient
import json
def JsonMethodProxyFactory(ExtendedCallName):
def JsonMethodProxy(self, *args, **kwargs):
outputbin = self.ExtendedCall(ExtendedCallName, json.dumps([args, kwargs]).encode())
jsonoutput = json.loads(outputbin)
if type(jsonoutput) == list and len(jsonoutput) == 2:
result, error = jsonoutput
if type(error) == str:
raise UserAddressedException(error)
else:
return result
raise Exception("Invalid input for " + ExtendedCallName)
return JsonMethodProxy
def JsonOutputMethodProxyFactory(ExtendedCallName):
def JsonMethodProxy(self, inputbin):
outputbin = self.ExtendedCall(ExtendedCallName, inputbin)
jsonoutput = json.loads(outputbin)
if type(jsonoutput) == list and len(jsonoutput) == 2:
result, error = jsonoutput
if type(error) == str:
raise UserAddressedException(error)
else:
return result
raise Exception("Invalid input for " + ExtendedCallName)
return JsonMethodProxy
LPCManagerExtendedCalls = [
"CheckProductID",
"GetFWVersions",
"RunUpdateScript",
"CreateFirmwareImageFileSizeFile",
"CreateFirmwareImageFileSizeMD5File",
"CreateFirmwareImageFileMD5File",
"RebootTarget"
]
for ExtendedCallName in LPCManagerExtendedCalls:
setattr(BeremizPLCObjectServiceClient, ExtendedCallName, JsonMethodProxyFactory(ExtendedCallName))
# RunFeedPipe uses no JSON encoding for performance
setattr(BeremizPLCObjectServiceClient, "RunFeedPipe", JsonOutputMethodProxyFactory("RunFeedPipe"))
# TODO
# from LPCconnector import LPC_connector_factory
# connectors.connectors["LPC"] = lambda: LPC_connector_factory
#
# --------- Targets/Toolchains Extension ------------
#
import targets
# from LPCtarget import LPC_target
som = GetLPCSOM()
if som is not None:
# added for MM1 dev, TODO merge with SOM6
if product in PREEMPTSOM6_modules:
rtosname = "Linux"
XSDname = "XSD_PREEMPT"
else:
rtosname = "Xenomai"
XSDname = "XSD"
targets.targets = {product : {
"xsd": os.path.join(_lpcmanager_path, som+"target", XSDname),
"class": targets.targets[rtosname]["class"],
"code": {"plc_"+som+"_main.c": targets.targets[rtosname]["code"]["plc_"+rtosname+"_main.c"],
"plc_"+som+"_main_retain.c": os.path.join(_lpcmanager_path,
som+"target",
"plc_"+som+"_main_retain.c")}}}
else:
raise NotImplemented
# targets.targets["LPC"] = {"xsd": os.path.join(_lpcmanager_path, "LPCtarget", "XSD"),
# "class": lambda: LPC_target,
# "code": {os.path.join(_lpcmanager_path, "LPCtarget", "plc_LPC_main.c")}}
# targets.toolchains["makefile"] = os.path.join(_lpcmanager_path, "LPCtarget", "XSD_toolchain_makefile")
#
# --------- Custom columns function Extension ------------
#
from WampOptionsEditor import WampOptionsCellEditor
from py_ext.PythonEditor import PythonEditor
from wxglade_hmi import WxGladeHMI
from WxGladeEditor import WxGladeEditor
WxGladeHMI.EditorType = WxGladeEditor
PythonEditor.COLUMNS_TYPE = {'Options': WampOptionsCellEditor}
#
# --------- special OnChange behavior ------------
# ----- on load options and OnChange colums fix --------
#
from py_ext.PythonFileCTNMixin import PythonFileCTNMixin
from OnChangeFromOptions import GetVarOnChangeContent, FixOptions
PythonFileCTNMixin.GetVarOnChangeContent = GetVarOnChangeContent
old_PythonFileCTNMixin__init__ = PythonFileCTNMixin.__init__
def PythonFileCTNMixin__init__with_FixOptions(self):
old_PythonFileCTNMixin__init__(self)
FixOptions(self)
PythonFileCTNMixin.__init__ = PythonFileCTNMixin__init__with_FixOptions
#
# ------- select pre-built stack according to SOM -------
#
import util.paths as paths
arch = GetLPCArch()
old_ThirdPartyPath = paths.ThirdPartyPath
def ThirdPartyPath(name):
res = old_ThirdPartyPath(name)
if name in ["BACnet", "Modbus", "CanFestival-3"]:
res = os.path.join(res, arch)
return res
paths.ThirdPartyPath = ThirdPartyPath