Exemplo n.º 1
0
    def handle_delivery(self, channel, method, header, body):
        """
        The incoming message is either a hardware status update, a command sent
        by another Pi or a social media status update.
            # On HW message: update the robot
            # On Pi message: add to message queue
            # On SM message: TBD
        """
        # For testing purposes
        message = Message.decode(body)
        if message.getChannel() == "Message":
            # If it's a "do this" type message ...
            logger.debug('Adding message from %s with content \'%s\'' %
                         (message.getSource(), message.getContent()))
            self.msgQueue.append(message)
        elif message.getChannel() == "Subs":
            logger.debug('Message for Subs channel: \'%s\'' %
                         message.getContent())
            usercode.run(self, self.channel)
        else:
            # If it's a robot status update ...
            hwDict = message.getContent()
            logger.debug('Updating the robot status: %s' % str(hwDict))
            # Apply the value changes
            for key, valueList in hwDict.iteritems():
                for index, value in enumerate(valueList):
                    if value is not None:
                        self.robot[key][index] = value

            #tells user script that there is unread data on all ports
            for sensor in self.sensorStatus:
                self.sensorStatus[sensor] = True
Exemplo n.º 2
0
 def handle_delivery(self, channel, method, header, body):
     """
     The incoming message is either a hardware status update, a command sent
     by another Pi or a social media status update.
         # On HW message: update the robot
         # On Pi message: add to message queue
         # On SM message: TBD
     """
     # For testing purposes
     message = Message.decode(body)
     if message.getChannel() == "Message":
         # If it's a "do this" type message ...
         logger.debug('Adding message from %s with content \'%s\'' % (message.getSource(), message.getContent()))
         self.msgQueue.append(message)
     elif message.getChannel() == "Subs":
         logger.debug('Message for Subs channel: \'%s\'' % message.getContent())
         usercode.run(self, self.channel)
     else:
         # If it's a robot status update ...
         hwDict = message.getContent()
         logger.debug('Updating the robot status: %s' % str(hwDict))
         # Apply the value changes
         for key, valueList in hwDict.iteritems():
             for index, value in enumerate(valueList):
                 if value is not None:
                     self.robot[key][index] = value
     
         #tells user script that there is unread data on all ports
         for sensor in self.sensorStatus:
             self.sensorStatus[sensor]= True
Exemplo n.º 3
0
    def executeScript(self):
        """
        Resets the robot to its default state and runs the script downloaded
        from Google Blockly via usercode.run().
        """
        global channel2

        # Initialize local image to the default state.
        self.robot = Message.initStatus()
        # Runs the user code generated by Blockly.
        logger.info('Running usercode.py ...')
        connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
        channel = connection.channel()
        channel.queue_declare(queue="HwCmd")
        connection2 = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
        channel2 = connection2.channel()
        channel2.queue_declare(queue="Message")
        usercode.run(self, channel, channel2)
Exemplo n.º 4
0
    def executeScript(self):
        """
        Resets the robot to its default state and runs the script downloaded
        from Google Blockly via usercode.run().
        """
        global channel2

        # Initialize local image to the default state.
        self.robot = Message.initStatus()
        # Runs the user code generated by Blockly.
        logger.info('Running usercode.py ...')
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(host='localhost'))
        channel = connection.channel()
        channel.queue_declare(queue="HwCmd")
        connection2 = pika.BlockingConnection(
            pika.ConnectionParameters(host='localhost'))
        channel2 = connection2.channel()
        channel2.queue_declare(queue="Message")
        usercode.run(self, channel, channel2)