Ejemplo n.º 1
0
    def __scanning_run(self):
        try:
            while self.is_alive():
                subscribers = self.__get_subscribers()

                if len(subscribers) == 0 and self.__enable_scanning is False:
                    break

                angles, distances, timestamp = self.__get_scan_now()

                response_header = drivermsg_pb2.DriverHdr()
                response_message = drivermsg_pb2.DriverMsg()

                response_message.type = drivermsg_pb2.DriverMsg.DATA
                response_message.ackNum = 0

                response_header.clientIDs.extend(subscribers)
                response_message = self.__fill_scan(response_message, angles,
                                                    distances, timestamp)

                self.get_pipes().write_header_and_message_to_pipe(
                    response_header, response_message)

            self.__logger.warning('hokuyo: stop')

        finally:
            self.__remove_scanning_thread()
Ejemplo n.º 2
0
    def send_subscribers_message(self):
        subscribers = self.__get_subscribers()
        if len(subscribers) > 0:
            response_header = drivermsg_pb2.DriverHdr()
            response_message = drivermsg_pb2.DriverMsg()

            response_message.type = drivermsg_pb2.DriverMsg.DATA
            response_message.ackNum = 0

            response_header.clientIDs.extend(subscribers)
            response_message = self.fill_subscription_response(response_message)

            self.get_pipes().write_header_and_message_to_pipe(response_header, response_message)
Ejemplo n.º 3
0
    def __read_header_and_message_from_pipe(self):
        """
        Read and parse header and message from pipe.

        :return: header and message
        """
        header = drivermsg_pb2.DriverHdr()
        message = drivermsg_pb2.DriverMsg()

        header = self.__read_data_from_pipe(header)
        message = self.__read_data_from_pipe(message)

        return header, message
Ejemplo n.º 4
0
        def wrapped(inst, received_header, received_message):
            response_header = drivermsg_pb2.DriverHdr()
            response_message = drivermsg_pb2.DriverMsg()

            response_message.type = drivermsg_pb2.DriverMsg.DATA
            response_message.ackNum = received_message.synNum

            response_header.clientIDs.extend(received_header.clientIDs)

            response_header, response_message = func(inst, received_header, received_message,
                                                     response_header, response_message)

            inst.get_pipes().write_header_and_message_to_pipe(response_header, response_message)
Ejemplo n.º 5
0
    def __handle_ping_message(self, ping_header, ping_message):
        """
        Handle PING message which came from mediator.

        :param ping_header: object of DriverHdr
        :param ping_message: object of DriverMsg
        :return: nothing
        """
        if not ping_message.HasField('synNum'):
            self.__logger.warning('PING\'s synNum is not set, ignoring.')

        else:
            pong_message = drivermsg_pb2.DriverMsg()
            pong_message.type = drivermsg_pb2.DriverMsg.PONG
            pong_message.ackNum = ping_message.synNum

            pong_header = drivermsg_pb2.DriverHdr()
            pong_header.clientIDs.extend(ping_header.clientIDs)

            self.__logger.debug('Send PONG message')

            self.write_header_and_message_to_pipe(pong_header, pong_message)