Esempio n. 1
0
 def logevent(self, module, message, priority=0):
     if priority >= self.min_log_priority:
         print(str(module).upper() + str(" - ") + str(message))
         if self.server is not None:
             for c in self.server.clients:
                 if c.type == ServerClient.ANDROID_DASHBOARD:
                     c.send_message(COMMAND.encode_message(COMMAND.LOG_ENTRY, [str(module).upper() + str(" - ") + str(message)]))
Esempio n. 2
0
 def run(self):
     while self.alive:
         time.sleep(0.2)
         f = self.client_socket.makefile()
         l = f.readline()
         l = l.replace("\n", "")
         command_recieved = COMMAND.decode_message(l)
         self.mutex.acquire()
         self.messages.append([self] + command_recieved)
         self.mutex.release()
         self.send_message(COMMAND.encode_message(COMMAND.RECIEVED, [command_recieved[0]]))
Esempio n. 3
0
    def run(self):
        try:
            while self.running:
                time.sleep(0.2)
                message_list = self.server.get_messages()#berichten ophalen van serverclients
                for message in message_list:
                    client = message[0]#client is eerste in lijst
                    message.remove(client)#verwijderen uit lijst
                    if message[0] == COMMAND.IDENTIFY:#if en elsif om te achterhalen welk commando is gegeven
                        #kijken welk apparaat connect
                        if message[1] == "dashboard":
                            client.type = ServerClient.ANDROID_DASHBOARD
                            self.logger.logevent("SPINOS", "Connected - ANDROID_DASHBOARD", Logger.MESSAGE)
                        elif message[1] == "controller":
                            client.type = ServerClient.ANDROID_CONTROLLER
                            self.logger.logevent("SPINOS", "Connected - ANDROID_CONTROLLER", Logger.MESSAGE)
                        elif message[1] == "gamepad":
                            client.type = ServerClient.GAMEPAD_CONTROLLER
                            self.logger.logevent("SPINOS", "Connected - GAMEPAD_CONTROLLER", Logger.MESSAGE)
                        else:
                            client.type = ServerClient.UNKNOWN
                            self.logger.logevent("SPINOS", "Connected - UNKNOWN", Logger.WARNING)
                    elif message[0] == COMMAND.KILL:
                        #spider wordt uitegezet alle threads worden gestopt
                        self.logger.logevent("SPINOS", "KILLING SPIDER, OH NO!!!!!")
                        self.running = False
                        self.shutdown()
                    elif message[0] == COMMAND.TO_MANUAL:
                        #huidige mode alive false zodat threads stoppen
                        self.current_mode.set_alive(False)
                        self.mode = "manual"
                        #set mode naar manual besturing
                        SpinOS.logger.logevent("SPINOS", "Mode set to " + self.mode, Logger.MESSAGE)
                        self.current_mode = ManualMode(self.movementHandler, self.logger)
                        self.current_mode.alive = True
                    elif message[0] == COMMAND.TO_BALLOON_MODE:
                        #huidige mode alive false zodat threads stoppen
                        self.current_mode.set_alive(False)
                        self.mode = "balloon mode"
                        #set mode naar balloon mode
                        SpinOS.logger.logevent("SPINOS", "Mode set to " + self.mode, Logger.MESSAGE)
                        self.current_mode = BalloonMode(self.movementHandler, self.logger, self)
                        self.current_mode.alive = True
                    elif message[0] == COMMAND.TO_TEERBAL_MODE:
                        #huidige mode alive false zodat threads stoppen
                        self.current_mode.set_alive(False)
                        self.mode = "teerbal mode"
                        #mode naar teerbal zetten
                        SpinOS.logger.logevent("SPINOS", "Mode set to " + self.mode, Logger.MESSAGE)
                        self.current_mode = TeerbalMode(self.movementHandler,self.logger,self)
                        self.current_mode.alive = True
                    elif message[0] == COMMAND.TO_DANCE_MODE:
                        #huidige mode alive false zodat threads stoppen
                        self.current_mode.set_alive(False)
                        self.mode = "dance mode"
                        #dance mode aanzetten
                        SpinOS.logger.logevent("SPINOS", "Mode set to " + self.mode, Logger.MESSAGE)
                        self.current_mode = DanceMode(self.movementHandler, self.logger)
                        self.current_mode.set_alive(True)

                    elif message[0] == COMMAND.SEND_SENSOR_DATA:
                        data = self.MPU.sensorlogger.get_log()
                        encoded = COMMAND.encode_message(COMMAND.SEND_SENSOR_DATA, data)
                        client.send_message(encoded)

                    elif message[0] == COMMAND.SEND_ACCU_DATA:
                        data = self.serial.voltagelogger.get_log()
                        encoded = COMMAND.encode_message(COMMAND.SEND_ACCU_DATA, data)
                        client.send_message(encoded)

                    else:
                        command = message[0]
                        message.remove(command)
                        self.current_mode.process_command(command, message)

        except Exception, e :
            print e
            self.shutdown()#als er een exception optreedt wordt de spin gedood