lpcmanager

66ee29c1b7ba
FW updater: fix update operation timeout to accomodate new 1GB images.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
#
# --------- Libraries Extension ------------
#
import features
from POULibrary import SimplePOULibraryFactory
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),
('Common', SimplePOULibraryFactory(_poulibpath("Common")), True),
('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True),
('MQTT', 'mqtt.MQTTLibrary', True)]
if product in WX_GOT_modules + SVG_GOT_modules:
features.libraries += [('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)]
enable_SVGHMI_lib_by_default = product in SOM6_modules
features.libraries += [('SVGHMI', 'LPCSVGHMI.SVGHMILibrary', enable_SVGHMI_lib_by_default)]
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(zip(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'),
('mqtt', _('MQTT client'), _('Map MQTT topics as located variables'), 'LPCMQTT.MQTTClient'),
('LPCBus', _('LPC bus'), _('Support for Smarteh modules'), 'LPCBus.LPCBus'),
('CanOpen', _('CANOpen'), _('Support for CANopen'), 'LPCCanFestival.LPCCanOpen')]
features.catalog += [ catalog_index['svghmi'][:3]+('LPCSVGHMI.SVGHMI',) ]
#
# --------- Connectors Extension ------------
#
from functools import partial
from connectors import WAMP
SMARTECLOUD_DEFAULT_HOST = "cloud.smarteh.com"
SMARTECLOUD_DEFAULT_PORT = "5678"
SMARTECLOUD_DEFAULT_PATH = "/ws"
SMARTECLOUD_DEFAULT_REALM = "Automation"
def CustomWAMPFactory(uri, *args, **kwargs):
scheme, location = uri.split("://")
if scheme.upper() == "WAMPS-SMT":
if "#" in location:
url, anchor = location.split('#',1)
if "#" in anchor:
realm, plcID = anchor.split("#")
else:
realm = SMARTECLOUD_DEFAULT_REALM
plcID = anchor
idx = url.find("/")
if idx != -1:
urlhost = url[:idx]
urlpath = url[idx:]
else:
urlhost = url
urlpath = SMARTECLOUD_DEFAULT_PATH
if ":" in urlhost:
hostname, port = urlhost.split(":")
else:
hostname = urlhost
port = SMARTECLOUD_DEFAULT_PORT
else:
hostname = SMARTECLOUD_DEFAULT_HOST
port = SMARTECLOUD_DEFAULT_PORT
urlpath = SMARTECLOUD_DEFAULT_PATH
realm = SMARTECLOUD_DEFAULT_REALM
plcID = location
uri = "WAMPS-CRT://%s:%s%s#%s#%s"%(hostname, port, urlpath, realm, plcID)
return WAMP._WAMP_connector_factory(WAMP.WampSession, uri, *args, **kwargs)
WAMP.WAMP_connector_factory = CustomWAMPFactory
#
# --------- 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, *args):
if name in ["BACnet", "Modbus", "CanFestival-3"]:
res = old_ThirdPartyPath(name)
res = os.path.join(res, arch)
elif name == "paho.mqtt.c":
res = old_ThirdPartyPath("MQTT")
res = os.path.join(res, arch)
else :
res = old_ThirdPartyPath(name)
return res
paths.ThirdPartyPath = ThirdPartyPath