data.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD)
5 #
6 # file @data.py
7 # authors Mike Purvis <mpurvis@clearpathrobotics.com>
8 # NovAtel <novatel.com/support>
9 # copyright Copyright (c) 2012, Clearpath Robotics, Inc., All rights reserved.
10 # Copyright (c) 2014, NovAtel Inc., All rights reserved.
11 #
12 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that
13 # the following conditions are met:
14 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15 # following disclaimer.
16 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
17 # following disclaimer in the documentation and/or other materials provided with the distribution.
18 # * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or promote
19 # products derived from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WAR-
22 # RANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN-
24 # DIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
25 # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 import rospy
30 import novatel_msgs.msg
31 
32 from port import Port
33 from novatel_span_driver.mapping import msgs
34 from handlers import MessageHandler
35 import translator
36 
37 from cStringIO import StringIO
38 from threading import Lock
39 
40 
41 class DataPort(Port):
42  def run(self):
43  # Set up handlers for translating different novatel messages as they arrive.
44  handlers = {}
45  pkt_counters = {}
46  pkt_times = {}
47 
48  for msg_id in msgs.keys():
49  handlers[msg_id] = MessageHandler(*msgs[msg_id])
50  pkt_counters[msg_id] = 0
51  pkt_times[msg_id] = 0
52 
53  bad_pkts = set()
54  pkt_id = None
55 
56  while not self.finish.is_set():
57  try:
58  header, pkt_str = self.recv()
59  if header is not None:
60  handlers[header.id].handle(StringIO(pkt_str), header)
61 
62  except ValueError as e:
63  # Some problem in the recv() routine.
64  rospy.logwarn(str(e))
65  continue
66 
67  except KeyError as e:
68  if header.id not in handlers and header.id not in pkt_counters:
69  rospy.logwarn("No handler for message id %d" % header.id)
70 
72  if header.id not in bad_pkts:
73  rospy.logwarn("Error parsing %s.%d" % header.id)
74  bad_pkts.add(pkt)
75 
76  if header.id not in pkt_counters:
77  pkt_counters[header.id] = 0
78  else:
79  pkt_counters[header.id] += 1
80  pkt_times[header.id] = header.gps_week_seconds # only track times of msgs that are part of novatel msgs


novatel_span_driver
Author(s): NovAtel Support
autogenerated on Wed Apr 3 2019 02:52:53