lpcmanager

1d0ab360af8a
Parents ce13540e7e69
Children 3731d5792801
Moved connectors, targets and toolchain customizations to LPCExtension.py
--- a/LPCExtension.py Mon Feb 05 13:59:50 2018 +0100
+++ b/LPCExtension.py Mon Feb 05 14:01:42 2018 +0100
@@ -26,4 +26,28 @@
else:
features.libraries += [('LPC', SimplePOULibraryFactory(_poulibpath("LPC")))]
+#
+# --------- Connectors Extension ------------
+#
+import connectors
+from LPCconnector import LPC_connector_factory
+
+connectors.connectors["LPC"] = lambda: LPC_connector_factory
+
+#
+# --------- Targets/Toolchains Extension ------------
+#
+
+import targets
+from LPCtarget import LPC_target
+
+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")
+targets.targets["MC9"] = {"xsd": os.path.join(_lpcmanager_path, "MC9target", "XSD"),
+ "class": targets.targets["Xenomai"]["class"],
+ "code": {"plc_MC9_main.c": targets.targets["Xenomai"]["code"]["plc_Xenomai_main.c"],
+ "plc_MC9_main_retain.c": os.path.join(_lpcmanager_path,
+ "MC9target", "plc_MC9_main_retain.c")}}
--- a/LPCManager.py Mon Feb 05 13:59:50 2018 +0100
+++ b/LPCManager.py Mon Feb 05 14:01:42 2018 +0100
@@ -118,24 +118,6 @@
AddBitmapFolder(os.path.join(_lpcmanager_path, "images"))
-import connectors
-from LPCconnector import LPC_connector_factory
-from LPCconnector.PYRO import MW_PYRO_connector_factory
-from LPCconnector.WAMP import MWWAMP_connector_factory
-
-import targets
-from LPCtarget import LPC_target
-
-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")
-targets.targets["MC9"] = {"xsd": os.path.join(_lpcmanager_path, "MC9target", "XSD"),
- "class": targets.targets["Xenomai"]["class"],
- "code": {"plc_MC9_main.c": targets.targets["Xenomai"]["code"]["plc_Xenomai_main.c"],
- "plc_MC9_main_retain.c": os.path.join(_lpcmanager_path,
- "MC9target", "plc_MC9_main_retain.c")}}
-from BeremizIDE import *
from ProjectController import ProjectController
from ConfigTreeNode import ConfigTreeNode
from editors.ProjectNodeEditor import ProjectNodeEditor
--- a/LPCconnector/PYRO/__init__.py Mon Feb 05 13:59:50 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-# Project name: SmartehIDE
-# __init__.py.py: spacer widget module initialization
-# 19. 01. 2017 12:24 Uporabnik
-#
-# Copyright (c) 2017 Smarteh d.o.o. <info@smarteh.si>
-# THIS PROGRAM COMES WITH NO WARRANTY
-
-import connectors
-import Pyro.core
-from connectors.PYRO import PYRO_connector_factory
-
-oldPYRO_connector_factory = PYRO_connector_factory
-def MW_PYRO_connector_factory(uri, confnodesroot):
- servicetype, location = uri.split("://")
- if servicetype == "PYROS":
- schemename = "PYROLOCSSL"
- else:
- schemename = "PYROLOC"
-
- def CustomFunctionCall(self, funcname, args=None):
- member = self.__dict__.get(funcname, None)
- if member is None:
- def my_local_func(*args, **kwargs):
- funcnameCall = funcname.split('.')[-1]
- return RemoteMWControllerProxy.__getattr__(funcnameCall)(*args, **kwargs)
- member = PyroCatcher(my_local_func, None)
- self.__dict__[funcname] = member
- return member
-
- RemoteMWControllerProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/MWController")
- pyro_connector = oldPYRO_connector_factory(uri, confnodesroot)
- if pyro_connector:
- pyro_connector.RemoteMWControllerProxy = RemoteMWControllerProxy
- pyro_connector.CustomFunctionCall = CustomFunctionCall
-
- return pyro_connector
-
-PYRO_connector_factory = MW_PYRO_connector_factory
-
-connectors.connectors["PYRO"] = lambda: MW_PYRO_connector_factory
\ No newline at end of file
--- a/LPCconnector/WAMP/__init__.py Mon Feb 05 13:59:50 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,177 +0,0 @@
-# Project name: SmartehIDE
-# __init__.py.py: spacer widget module initialization
-# 19. 01. 2017 12:24 Uporabnik
-#
-# Copyright (c) 2017 Smarteh d.o.o. <info@smarteh.si>
-# THIS PROGRAM COMES WITH NO WARRANTY
-import traceback
-from autobahn.twisted import wamp
-from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
-from autobahn.wamp import types
-from autobahn.wamp import auth
-from autobahn.wamp.serializer import MsgPackSerializer
-import connectors
-from twisted.internet import reactor, threads
-from autobahn.wamp.exception import TransportLost
-from threading import Thread, Event
-
-# import connectors.WAMP as WAMP
-# from connectors.WAMP import WAMP_connector_factory, WampSession
-# from threading import _sleep
-
-PLCObjDefaults = { "StartPLC": False,
- "GetTraceVariables" : ("Broken",None),
- "GetPLCstatus" : ("Broken",None),
- "RemoteExec" : (-1, "RemoteExec script failed!")}
-
-PASSWORDS = {
- u'smarteh': u'smarteh'
-}
-
-USER = u'smarteh'
-
-_WampSession = None
-_WampConnection = None
-_WampSessionEvent = Event()
-
-class MWWampSession(wamp.ApplicationSession):
- def onConnect(self):
- self.join(u"Automation", [u"wampcra"], USER)
- print "CRA checking init ..."
-
- def onJoin(self, details):
- global _WampSession, _WampSessionEvent
- _WampSession = self
- _WampSessionEvent.set()
- print 'WAMP session joined for :', self.config.extra["ID"]
-
- def onChallenge(self, challenge):
- if challenge.method == u"wampcra":
- key = PASSWORDS[USER].encode('utf8')
- key = auth.derive_key(key, "salt123", 100, 16)
- signature = auth.compute_wcs(key, challenge.extra['challenge'].encode('utf8'))
- return signature.decode('ascii')
- else:
- raise Exception("don't know how to handle authmethod {}".format(challenge.method))
-
- def onLeave(self, details):
- global _WampSession, _WampSessionEvent
- print details
- self.disconnect()
- _WampSessionEvent.clear()
- _WampSession = None
- print 'WAMP session left'
-
-# DefalutWAMP_connector_factory = WAMP_connector_factory
-
-def MWRegisterWampClient(realm, ID, url, confnodesroot):
- # create a WAMP application session factory
- component_config = types.ComponentConfig(
- realm = unicode(realm),
- extra = {"ID":ID})
- session_factory = wamp.ApplicationSessionFactory(
- config = component_config)
- session_factory.session = MWWampSession
-
- # create a WAMP-over-WebSocket transport client factory
- transport_factory = WampWebSocketClientFactory(
- session_factory,
- url = url+"/beremiz",
- serializers = [MsgPackSerializer()])
- # settings autoPing in seconds
- #transport_factory.autoPingInterval = 60
- #transport_factory.autoPingTimeout = 20
-
- # start the client from a Twisted endpoint
- conn = connectWS(transport_factory)
- confnodesroot.logger.write(_("WAMP connecting to URL : %s\n")%url)
- return conn
-
-def MWWAMP_connector_factory(uri, confnodesroot):
-
- # def CustomFunctionCall(self, funcname, args=None):
- # member = self.__dict__.get(funcname, None)
- # if member is None:
- # member = WampSessionProcMapper(funcname)
- # self.__dict__[funcname] = member
- # return member
- #
- # WAMP.RegisterWampClient = MWRegisterWampClient
- # WAMP.WampSession = MWWampSession
- #
- # wamp_connector = DefalutWAMP_connector_factory(uri, confnodesroot)
- # wamp_connector.CustomFunctionCall = CustomFunctionCall
- # _sleep(1)
- # return wamp_connector
-
- servicetype, location = uri.split("://")
- urlpath, realm, ID = location.split('#')
- urlprefix = {"WAMP": "ws",
- "WAMPS": "wss"}[servicetype]
- url = urlprefix + "://" + urlpath
-
- AddToDoBeforeQuit = confnodesroot.AppFrame.AddToDoBeforeQuit
-
- def ThreadProc():
- global _WampConnection
- _WampConnection = MWRegisterWampClient(realm, ID, url, confnodesroot)
- AddToDoBeforeQuit(reactor.stop)
- reactor.run(installSignalHandlers=False)
-
- def WampSessionProcMapper(funcname):
- wampfuncname = unicode('.'.join((ID, funcname)))
-
- def catcher_func(*args, **kwargs):
- global _WampSession
- if _WampSession is not None:
- try:
- return threads.blockingCallFromThread(
- reactor, _WampSession.call, wampfuncname,
- *args, **kwargs)
- except TransportLost, e:
- confnodesroot.logger.write_error(_("Connection lost!\n"))
- confnodesroot._SetConnector(None)
- except Exception, e:
- errmess = traceback.format_exc()
- confnodesroot.logger.write_error(errmess + "\n")
- print errmess
- # confnodesroot._SetConnector(None)
- return PLCObjDefaults.get(funcname)
-
- return catcher_func
-
- class WampPLCObjectProxy(object):
- def __init__(self):
- global _WampSessionEvent, _WampConnection
- if not reactor.running:
- Thread(target=ThreadProc).start()
- else:
- _WampConnection = threads.blockingCallFromThread(
- reactor, MWRegisterWampClient, realm, ID, url, confnodesroot)
- if not _WampSessionEvent.wait(5):
- _WampConnection = stopConnecting()
- raise Exception, _("WAMP connection timeout")
-
- def __del__(self):
- global _WampConnection
- _WampConnection.disconnect()
- #
- # reactor.stop()
-
- def __getattr__(self, attrName):
- member = self.__dict__.get(attrName, None)
- if member is None:
- member = WampSessionProcMapper(attrName)
- self.__dict__[attrName] = member
- return member
-
- # Try to get the proxy object
- try:
- return WampPLCObjectProxy()
- except Exception, msg:
- confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location)
- confnodesroot.logger.write_error(traceback.format_exc())
- return None
-
-
-connectors.connectors["WAMP"] = lambda: MWWAMP_connector_factory
\ No newline at end of file
--- a/LPCconnector/__init__.py Mon Feb 05 13:59:50 2018 +0100
+++ b/LPCconnector/__init__.py Mon Feb 05 14:01:42 2018 +0100
@@ -33,6 +33,5 @@
from LPCBootObject import LPCBootObject
return LPCBootObject(confnodesroot,comportstr)
-connectors.connectors["LPC"] = lambda: LPC_connector_factory