def __init__(self, config=types.ComponentConfig(u"anonymous")): PARSER_FILE = "../config/definitions.xml" uRC_MODULE_NAME = "TestEmitter" Autobahn_Client.__init__(self, uRC_MODULE_NAME, PARSER_FILE, config=config) self.worker = None
def onDisconnect(self): self.worker.interrupt() Autobahn_Client.onDisconnect(self)
def _startupComponents(self): Autobahn_Client._startupComponents(self) self.worker = EmitterThread(self) self.worker.start()
def _initRpcs(self): Autobahn_Client._initRpcs(self)
def _initSubscriptions(self): Autobahn_Client._initSubscriptions(self)
def run(self): Thread.run(self) for i in range(10): if self.interrupted: break time.sleep(2) print "==run # " + str(i) + "==" print "publishing..." data = {"message":"This is " + self.emitter.uRC_MODULE_NAME + " testing subscription 'uRC.testing.receiver.data'", "index":i} self.emitter.publishTestData(data) print "done" time.sleep(2) print "calling rpc..." result = self.emitter.testPing(i) print "done, result:", result self.emitter.leave() if __name__ == "__main__": logging.basicConfig(level=logging.INFO) # Autobahn_Client.startup_client(TestEmitter) ######################################################################## from autobahn.twisted.choosereactor import install_reactor reactor = install_reactor() Autobahn_Client.startup_client_2(TestEmitter) # Autobahn_Client.startup_client_2(TestEmitter_cp) reactor.run()
def _initRpcs(self): Autobahn_Client._initRpcs(self) self._rpcs["uRC.testing.receiver.rpc."+self.uRC_MODULE_NAME] = self.handleRPC
def _startupComponents(self): Autobahn_Client._startupComponents(self)
def _initSubscriptions(self): Autobahn_Client._initSubscriptions(self) self._subscriptions["uRC.testing.receiver.data"] = self.handleTopic
def handleTopic(self, data): if self._parser.parse("uRC.testing.receiver.data", data): print "received: ", data else: print "received message contains error", data def handleRPC(self, data): def function(data): result = "" if self._parser.parse("uRC.testing.receiver.rpc", data): print "RPC: Data:" + str(data) time.sleep(3) result = "pong:" + str(data["index"]) else: print "RPC: Data contains error: " + str(data) result = "received rpc contains error" return {"ping":result} return self._handle_RPC(function, data) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) # Autobahn_Client.startup_client(TestReceiver) ######################################################################## from autobahn.twisted.choosereactor import install_reactor reactor = install_reactor() Autobahn_Client.startup_client_2(TestReceiver) # Autobahn_Client.startup_client_2(TestReceiver_cp) reactor.run()
def _initRpcs(self): Autobahn_Client._initRpcs(self) self.__initRPCs_sensor()
def __init__(self, config=types.ComponentConfig(u"anonymous")): PARSER_FILE = "../config/definitions.xml" uRC_MODULE_NAME = "AscTec_Falcon" Autobahn_Client.__init__(self, uRC_MODULE_NAME, PARSER_FILE, config=config) self._serial = None
def _initRpcs(self): Autobahn_Client._initRpcs(self) self.__initRPCs_sensor() def __initRPCs_sensor(self): self._rpcs["uRC.sensor.TRIGGER."+self.uRC_MODULE_NAME] = self.on_trigger self._rpcs["uRC.sensor.STATUS.GET."+self.uRC_MODULE_NAME] = self.on_status_get self._rpcs["uRC.sensor.PROPS.GET."+self.uRC_MODULE_NAME] = self.on_props_get self._rpcs["uRC.sensor.PROPS.SET."+self.uRC_MODULE_NAME] = self.on_props_set def _startupComponents(self): Autobahn_Client._startupComponents(self) def on_trigger(self, data): pass def on_status_get(self, data): pass def on_props_get(self, data): pass def on_props_set(self, data): pass if __name__ == "__main__": reactor = install_reactor() logging.basicConfig(level=logging.INFO) Autobahn_Client.startup_client_2(Sensor_WebSocket) reactor.run()