예제 #1
0
파일: container.py 프로젝트: LCROBOT/rce
def main(reactor, commID, masterIP, masterPort, masterID):
    f = open('/home/rce-user/container.log', 'w')
    log.startLogging(f)
    #log.startLogging(sys.stdout)
    
    manager = ContainerManager(reactor)
    commManager = CommManager(reactor, commID)
    cmdSerializer = CommandSerializer()
    cmdSerializer.registerCommand([ContainerCommand])
    commManager.registerContentSerializers([CommInfoSerializer(),
                                            cmdSerializer,
                                            TagSerializer()])
    
    distributor = ControlDistributor()
    distributor.addHandler(types.CONTAINER, manager.createContainer)
    distributor.addHandler(types.RM_CONTAINER, manager.destroyContainer)
    commManager.registerMessageProcessors([CommInfoProcessor(manager),
                                           CommandProcessor(distributor),
                                           TagProcessor(distributor)])
    
    factory = RCEClientFactory(commManager, masterID)
    factory.addApprovedMessageTypes([msgTypes.COMM_INFO, msgTypes.COMMAND,
                                     msgTypes.TAG])
    reactor.connectTCP(masterIP, masterPort, factory)
    
    reactor.addSystemEventTrigger('before', 'shutdown', manager.shutdown)
    reactor.addSystemEventTrigger('before', 'shutdown', commManager.shutdown)
    
    reactor.run()
    
    f.close()
예제 #2
0
파일: environment.py 프로젝트: LCROBOT/rce
def main(reactor, commID, relayIP, relayPort, relayID, nodeIP, nodePort,
         nodeID):
    f = open('/opt/rce/data/env.log', 'w')
    log.startLogging(f)
    
    rospy.init_node('RCE_Master')
    
    manager = Manager(reactor)
    commManager = CommManager(reactor, commID)
    manager.registerCommManager(commManager)
    messenger = Messenger(manager, commManager)
    manager.registerMessenger(messenger)
    
    cmdSerializer = CommandSerializer()
    cmdSerializer.registerCommand([NodeForwarderCommand, ConnectionCommand])
    cmdSerializer.registerCommand(map(lambda x: x[1], _PARAMETER))
    cmdSerializer.registerCommand(map(lambda x: x[1], _INTERFACE))
    
    commManager.registerContentSerializers([cmdSerializer,
                                            TagSerializer(),
                                            ROSMsgSerializer()])
    
    distributor = ControlDistributor()
    distributor.addHandler(types.NODE, manager.addNode)
    distributor.addHandler(types.RM_NODE, manager.removeNode)
    distributor.addHandler(types.RM_PARAMETER, manager.removeParameter)
    distributor.addHandler(types.RM_INTERFACE, manager.removeInterface)
    distributor.addHandler(types.CONNECTION, manager.modifyConnection)
    
    for conv in _PARAMETER:
        distributor.addHandler(conv[0], manager.addParameter)
    
    for conv in _INTERFACE:
        distributor.addHandler(conv[0], manager.addInterface)
    
    commManager.registerMessageProcessors([CommandProcessor(distributor),
                                           TagProcessor(distributor),
                                           messenger])
    
    factory = RCEClientFactory(commManager, relayID)
    factory.addApprovedMessageTypes([msgTypes.COMMAND, msgTypes.TAG,
                                     msgTypes.ROS_MSG])
    reactor.connectTCP(relayIP, relayPort, factory)
    
    factory = RCEClientFactory(commManager, nodeID)
    reactor.connectTCP(nodeIP, nodePort, factory)
    
    def terminate():
        reactor.callFromThread(manager.shutdown)
        reactor.callFromThread(commManager.shutdown)
        reactor.callFromThread(reactor.stop)

    rospy.on_shutdown(terminate)
    
    reactor.run(installSignalHandlers=False)
    
    f.close()
예제 #3
0
파일: manager.py 프로젝트: LCROBOT/rce
 def connectToRelays(self, relays):
     """ Callback for remote.message.ConnectDirectiveProcessor to connect
         to the specified relays.
         
         @param relays:  List of (commID, IP address) tuples describing the
                         relays to which connections should be established.
         @type  relay:  [ (str, str) ]
     """
     for relay in relays:
         commID, ip = relay
         
         if commID in self._relays:
             continue  # We are already connected to this relay.
         
         # TODO: Small hack to circumvent problem with localhost IP
         if ip == '127.0.0.1':
             ip = self._masterIP
         
         cb = RelayCallbackFromRelay(self, self._commManager)
         factory = RCEClientFactory(self._commManager, commID, [cb], [cb])
         factory.addApprovedMessageTypes([msgTypes.ROS_MSG])
         self._reactor.connectTCP(ip, self._RELAY_PORT, factory)