def __init__(self, exceptIps=["0.0.0.0"]): """ Constructor """ self.__serverReader = [] self.__exceptIps = exceptIps self.__networkService = NetworkService() self.__app = qi.Application( url="tcp://" + Settings.naoHostName + ":" + str(Settings.naoPort) ) logging.info( "Connecting to %s", self.__app.url ) self.__app.start() self.__session = self.__app.session NAOCommand.startDefaultModules(self.__session)
def __handleData(self, data, addr): """ Handles received data :param data: Received data string :param addr: Remote address of received data :return: None """ # check for connect if data: if 'command' in data and 'commandArguments' in data: disconnect = False # handle build in commands if data['command'] == dataCommands.SYS_DISCONNECT: self.__sendSystemInfoData(data) disconnect = True elif data['command'] == dataCommands.SYS_GET_INFO: disconnect = not self.__server.send(data) elif data['command'] == dataCommands.SYS_SET_REQUIRED_DATA: self.__server.setRequiredData( data['commandArguments'] ) disconnect = not self.__sendSystemInfoData(data) # handle user command else: ret = NAOCommand.resolveCmd( data, self.__server, self.__session ) data = self.__server.createDataResponsePackage(data, ret) if self.__server.send(data): # also send system information disconnect = not self.__sendSystemInfoData(data) else: disconnect = True # handle protocol error else: logging.error( "Protocol error receiving %s", str(data) ) disconnect = not self.__sendSystemInfoData(data) # check if command was executed succesfuly if disconnect: logging.warning( "restarting server due to communication errors." ) self.__server.close(True)
def __handleData(self, data, addr): ''' Handles recieved data ''' # check for connect if data: if 'command' in data and 'commandArguments' in data: disconnect = False # handle build in commands if data['command'] == dataCommands.SYS_DISCONNECT: data = self.__server.createDataResponsePackage(data, True) self.__server.send(data); disconnect = True elif data['command'] == dataCommands.SYS_GET_INFO: data = self.__server.createDataResponsePackage(data, True) disconnect = not self.__server.send(data) elif data['command'] == dataCommands.SYS_SET_REQUIRED_DATA: self.__server.setRequiredData( data['commandArguments'] ) data = self.__server.createDataResponsePackage(data, True) disconnect = not self.__server.send(data) # handle user else: ret = NAOCommand.resolveCmd( data, self.__server ) data = self.__server.createDataResponsePackage(data, ret) disconnect = not self.__server.send(data) # handle protocol error else: data = self.__server.createDataResponsePackage(data, False) disconnect = not self.__server.send(data) # check if command was successfully executed if disconnect: self.__server.close(True)
def __handleData(self, data, addr): """ Handles recieved data """ # check for connect if data: if "command" in data and "commandArguments" in data: disconnect = False # handle build in commands if data["command"] == dataCommands.SYS_DISCONNECT: data = self.__server.createDataResponsePackage(data, True) self.__server.send(data) disconnect = True elif data["command"] == dataCommands.SYS_GET_INFO: data = self.__server.createDataResponsePackage(data, True) disconnect = not self.__server.send(data) elif data["command"] == dataCommands.SYS_SET_REQUIRED_DATA: self.__server.setRequiredData(data["commandArguments"]) data = self.__server.createDataResponsePackage(data, True) disconnect = not self.__server.send(data) # handle user else: ret = NAOCommand.resolveCmd(data, self.__server) data = self.__server.createDataResponsePackage(data, ret) disconnect = not self.__server.send(data) # handle protocol error else: data = self.__server.createDataResponsePackage(data, False) disconnect = not self.__server.send(data) # check if command was successfully executed if disconnect: self.__server.close(True)
i += 2 return True if __name__ == '__main__': # set current working padth path = os.path.dirname(sys.argv[0]) if not path: path = str(os.getcwd()) sys.argv[0] = path + "/" + str(sys.argv[0]) os.chdir(path) print "set working path from " + str(os.getcwd()) + " to " + str(path) # parse settings parseSettings(sys.argv[1:]) # create commands list NAOCommand.addCmds() servermanager = ServerManager() # Endlosschleife while (True): servermanager.manage() sleep(2) print "ERROR: Program terminated"
return True if __name__ == '__main__': # parse settings parseSettings(); logging.debug("Parsed command line options") # set current working path path = os.path.dirname(sys.argv[0]) if not path: path = str(os.getcwd()) sys.argv[0] = path + "/" + str(sys.argv[0]) logging.debug("set working path from %s to %s", str(os.getcwd()), str(path)) os.chdir(path) # create commands list NAOCommand.addCmds() servermanager = ServerManager() # Endlosschleife while(True): if not servermanager.manage(): break; sleep(5) logging.error( "Terminated" )