Beispiel #1
0
  def run(self):
    self.sock.settimeout(1.0)
    errors = 0

    # Aggregate message for republishing the sensor config as a single blob.
    all_msgs = applanix_msgs.msg.AllMsgs()
    all_msgs_pub = rospy.Publisher("config", all_msgs.__class__, queue_size=5, latch=True) 

    # Listener object which tracks what topics have been subscribed to.
    listener = SubscribeListenerManager()
  
    # Set up handlers for translating different Applanix messages as they arrive.
    handlers = {}
    for group_num in groups.keys():
      include = True
      for prefix in self.opts['exclude_prefixes']:
        if groups[group_num][0].startswith(prefix): include = False
      if include:
        handlers[(applanix_msgs.msg.CommonHeader.START_GROUP, group_num)] = \
            GroupHandler(*groups[group_num], listener=listener.listener_for(group_num))
    for msg_num in msgs.keys():
      print msgs[msg_num]
      handlers[(applanix_msgs.msg.CommonHeader.START_MESSAGE, msg_num)] = \
          MessageHandler(*msgs[msg_num], all_msgs=all_msgs)

    pkt_counters = {}
    bad_pkts = set()

    while not self.finish.is_set():
      try:
        pkt_id, pkt_str = self.recv()
        if pkt_id != None:
          handlers[pkt_id].handle(StringIO(pkt_str))

      except ValueError as e:
        # Some problem in the recv() routine.
        rospy.logwarn(str(e))
        continue

      except KeyError:
        # No handler for this pkt_id. Only warn on the first sighting.
        if pkt_id not in pkt_counters:
          rospy.logwarn("Unhandled packet: %s.%d" % pkt_id)

      except translator.TranslatorError:
        if pkt_id not in bad_pkts:
          rospy.logwarn("Error parsing %s.%d" % pkt_id)
          bad_pkts.add(pkt)

      if pkt_id not in pkt_counters:
        pkt_counters[pkt_id] = 0
      pkt_counters[pkt_id] += 1


      # Since the config messages come all at once in a burst, we can time out in between those
      # bursts and send this aggregate message out with all of them at once.
      if all_msgs.last_changed > all_msgs.last_sent and \
          rospy.get_rostime() > all_msgs.last_changed + self.ALLMSGS_SEND_TIMEOUT:
        all_msgs_pub.publish(all_msgs)
        all_msgs.last_sent = rospy.get_rostime() 
Beispiel #2
0
	def _parse(self):
		"""
		Parse and do whatever work necessary for the message.
		
		If the message necessitates a reply, save it to self.reply_msg.
		"""
		
		self.reply_msg = MessageHandler.fire_handlers(self)
Beispiel #3
0
async def serve(websocket, path):
    bot = FedeBot()
    handler = MessageHandler(bot, websocket)
    async for message in websocket:
        message = json.loads(message)
        print('<<<')
        print(json.dumps(message, indent=4))
        print('-'*30)
        await getattr(handler, message["mensaje"])(message)
Beispiel #4
0
    def on_pvtmsg(self, user, msg):  # P
        """
        Received when a user sends the client a private message.

        :param user: The user sending a private message as User object.
        :type user: Users.User
        :param msg: The text message as TextMessage object.
        :type msg: TextMessage
        """
        if user.handle != self.users.client.handle:
            mh = MessageHandler(self, user, CONF, msg)
            # write message to console
            mh.console()

            if self.users.client.is_mod:
                # check private message for ban string
                self.pool.add_task(mh.handle)

                # initialize the command handler
                ch = CommandHandler(self, user, msg, CONF, self.pool)
                # handle command
                ch.handle()
Beispiel #5
0
    def run(self):
        # Set up handlers for translating different novatel messages as they arrive.
        handlers = {}
        pkt_counters = {}
        pkt_times = {}

        for msg_id in msgs.keys():
            handlers[msg_id] = MessageHandler(*msgs[msg_id])
            pkt_counters[msg_id] = 0
            pkt_times[msg_id] = 0

        bad_pkts = set()
        pkt_id = None

        while not self.finish.is_set():
            try:
                header, pkt_str = self.recv()
                #                 continue
                if header is not None:
                    if header.id not in handlers:
                        continue
#                     rospy.loginfo("processing message {}".format(header.id))
                    if header.id not in pkt_counters:
                        pkt_counters[header.id] = 0
                    else:
                        pkt_counters[header.id] += 1
                    header.sequence = pkt_counters[header.id]
                    handlers[header.id].handle(StringIO(pkt_str), header)

            except ValueError as e:
                # Some problem in the recv() routine.
                rospy.logwarn(str(e))
                continue

            except KeyError as e:
                if header.id not in handlers:
                    #                     pass
                    rospy.logwarn("No handler for message id %d" % header.id)

            except translator.TranslatorError as e:
                rospy.logwarn("Error parsing %s.%d" % header.id)
                bad_pkts.add(pkt)
            except Exception as e:
                rospy.logwarn(str(e))
Beispiel #6
0
    def run(self):
        # Set up handlers for translating different novatel messages as they arrive.
        handlers = {}
        pkt_counters = {}
        pkt_times = {}

        for msg_id in msgs.keys():
            handlers[msg_id] = MessageHandler(*msgs[msg_id])
            pkt_counters[msg_id] = 0
            pkt_times[msg_id] = 0

        bad_pkts = set()
        pkt_id = None

        while not self.finish.is_set():
            try:
                header, pkt_str = self.recv()
                if header is not None:
                    handlers[header.id].handle(StringIO(pkt_str), header)

            except ValueError as e:
                # Some problem in the recv() routine.
                rospy.logwarn(str(e))
                continue

            except KeyError as e:
                if header is not None and header.id not in handlers and header.id not in pkt_counters:
                    rospy.logwarn("No handler for message id %d" % header.id)

            except translator.TranslatorError:
                if header is not None and header.id not in bad_pkts:
                    rospy.logwarn("Error parsing %s.%d" % header.id)
                    bad_pkts.add(pkt)

            if header is not None and header.id not in pkt_counters:
                pkt_counters[header.id] = 0
            elif header is not None:
                pkt_counters[header.id] += 1
                pkt_times[
                    header.
                    id] = header.gps_week_seconds  # only track times of msgs that are part of novatel msgs
Beispiel #7
0
    def run(self):
        all_msgs = novatel_msgs.msg.AllMsgs()
        all_msgs_pub = rospy.Publisher("config",
                                       all_msgs.__class__,
                                       latch=True,
                                       queue_size=1)

        # Set up handlers for translating different novatel messages as they arrive.
        handlers = {}
        pkt_counters = {}
        pkt_times = {}

        for msg_num in msgs.keys():
            handlers[(novatel_msgs.msg.CommonHeader.START_MESSAGE, msg_num)] = \
                MessageHandler(*msgs[msg_num], all_msgs=all_msgs)
            pkt_counters[(novatel_msgs.msg.CommonHeader.START_MESSAGE,
                          msg_num)] = 0
            pkt_times[(novatel_msgs.msg.CommonHeader.START_MESSAGE,
                       msg_num)] = 0

        bad_pkts = set()
        pkt_id = None

        while not self.finish.is_set():
            try:
                pkt_id, pkt_str, pkt_time = self.recv()
                if pkt_id != None:
                    handlers[pkt_id].handle(StringIO(pkt_str))

            except ValueError as e:
                # Some problem in the recv() routine.
                rospy.logwarn(str(e))
                continue

            except KeyError as e:
                # No handler for this pkt_id. Only warn on the first sighting.
                rospy.logwarn(str(e))

                if pkt_id not in handlers:
                    rospy.logwarn("Uninitialised Handler")
                    handlers[pkt_id] = MessageHandler(*msgs[msg_num],
                                                      all_msgs=all_msgs)

                if pkt_id not in pkt_counters:
                    rospy.logwarn("Unhandled packet")

            except translator.TranslatorError:
                if pkt_id not in bad_pkts:
                    rospy.logwarn("Error parsing %s.%d" % pkt_id)
                    bad_pkts.add(pkt)

            if pkt_id not in pkt_counters:
                pkt_counters[pkt_id] = 0
            else:
                pkt_counters[pkt_id] += 1
                pkt_times[
                    pkt_id] = pkt_time  # only track times of msgs that are part of novatel msgs

            # wait until all the msgs have the same GNSS time before sending
            if all_same(pkt_times):
                all_msgs_pub.publish(all_msgs)
                all_msgs.last_sent = rospy.get_rostime()
Beispiel #8
0
 def test_uncertain_handler_yields_to_succeeding_certain_handler_conditionally(
         self):
     MessageHandler(msg_quack)
     MessageHandler(msg_swap_case)
     self.assertEqual(quack, self.fire(self.quack_msg))
     self.assertEqual(self.swap_msg.swapcase(), self.fire(self.swap_msg))
Beispiel #9
0
 def test_empty_handler_yields_to_certain_handler(self):
     MessageHandler(nothing)
     MessageHandler(msg_swap_case)
     self.assertEqual(self.swap_msg.swapcase(), self.fire(self.swap_msg))
Beispiel #10
0
 def test_handlers_give_expected_resp(self):
     MessageHandler(msg_swap_case)
     self.assertEqual(self.swap_msg.swapcase(), self.fire(self.swap_msg))
     MessageHandler.handlers.clear()
     MessageHandler(msg_quack)
     self.assertEqual(quack, self.fire(self.quack_msg))
Beispiel #11
0
 def test_uncertain_handler_conditionally_gives_resp(self):
     MessageHandler(msg_quack)
     self.assertIsNone(self.fire(self.noquack_msg))
     self.assertIsNotNone(self.fire(self.quack_msg))
Beispiel #12
0
 def test_certain_handler_gives_resp(self):
     MessageHandler(msg_swap_case)
     self.assertIsNotNone(self.fire(self.swap_msg))
     self.assertIsNotNone(self.fire(""))
Beispiel #13
0
 def test_empty_handler_gives_no_resp(self):
     MessageHandler(nothing)
     self.assertIsNone(self.fire(None))
Beispiel #14
0
 def test_msg_handler_does_not_change_object(self):
     self.assertIs(nothing, MessageHandler(nothing))
     self.assertIs(msg_swap_case, MessageHandler(msg_swap_case))
     self.assertIs(msg_quack, MessageHandler(msg_quack))