lpcmanager

Parents bb465ef96b61
Children 1f602009a26f
Added our wxglade_hmi to LPCManager and our connectors. (PYRO, WAMP)
--- a/LPCManager.py Fri Jan 13 15:22:25 2017 +0100
+++ b/LPCManager.py Wed Jan 25 10:45:37 2017 +0100
@@ -98,11 +98,19 @@
features.libraries += [('LPC', lambda: PLCLibraryLPC)]
features.catalog.pop([i for i, x in enumerate(features.catalog) if x[0].startswith('svg')][0])
+wxglade_hmi_index = [i for i, x in enumerate(features.catalog) if x[0].startswith('wxglade_hmi')][0]
+old_wxglade_hmi = features.catalog[wxglade_hmi_index]
+mwwxglade_hmi = ('wxglade_hmi', _('WxGlade GUI'), _('Add a simple WxGlade based GUI.'), 'MWWxglade_hmi.mwwxglade_hmi.WxGladeHMI')
+features.catalog[wxglade_hmi_index] = mwwxglade_hmi
import connectors
from LPCconnector import LPC_connector_factory
+from LPCconnector.PYRO import MW_PYRO_connector_factory
+from LPCconnector.WAMP import MWWAMP_connector_factory
connectors.connectors["LPC"] = lambda: LPC_connector_factory
+connectors.connectors["PYRO"] = lambda: MW_PYRO_connector_factory
+connectors.connectors["WAMP"] = lambda: MWWAMP_connector_factory
import targets
from LPCtarget import LPC_target
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCconnector/PYRO/__init__.py Wed Jan 25 10:45:37 2017 +0100
@@ -0,0 +1,36 @@
+# 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 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)
+ pyro_connector.RemoteMWControllerProxy = RemoteMWControllerProxy
+ pyro_connector.CustomFunctionCall = CustomFunctionCall
+
+ return pyro_connector
+
+PYRO_connector_factory = MW_PYRO_connector_factory
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCconnector/WAMP/__init__.py Wed Jan 25 10:45:37 2017 +0100
@@ -0,0 +1,88 @@
+# 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
+
+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.WAMP as WAMP
+from connectors.WAMP import WAMP_connector_factory, WampSession
+from threading import _sleep
+
+PASSWORDS = {
+ u'smarteh': u'smarteh'
+}
+
+USER = u'smarteh'
+
+class MWWampSession(WampSession):
+ def onConnect(self):
+ self.join(u"Automation", [u"wampcra"], USER)
+ print "CRA checking init ..."
+
+ 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):
+ ## start logging to console
+ # log.startLogging(sys.stdout)
+
+ # 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
\ No newline at end of file