oem7_message_util.cpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2020 NovAtel Inc.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
24 
26 
28 
29 
30 namespace
31 {
32  bool is_initialized = false;
33 
34  std::map<std::string, int> oem7_msg_id_map;
35  std::map<int, std::string> oem7_msg_name_map;
36 
37 }
38 
39 namespace novatel_oem7_driver
40 {
41 
43  {
44  GPS_REFTIME_STATUS_UNKNOWN = 20 // Refer to Oem7 manual.
45  };
46 
48  {
49  if(is_initialized)
50  return;
51 
52  const std::string ns(ros::this_node::getNamespace());
53  nh.getParam(ns + "/oem7_msgs", oem7_msg_id_map);
54  for(const auto& msg_itr : oem7_msg_id_map)
55  {
56  ROS_DEBUG_STREAM("Oem7 Message: " << msg_itr.first << ":" << msg_itr.second);
57  oem7_msg_name_map[msg_itr.second] = msg_itr.first;
58  }
59 
60  is_initialized = true;
61  }
62 
63  int getOem7MessageId(const std::string& msg_name)
64  {
65  return oem7_msg_id_map[msg_name];
66  }
67 
68  const std::string& getOem7MessageName(int msg_id)
69  {
70  return oem7_msg_name_map[msg_id];
71  }
72 
73 
79  const Oem7RawMessageIf::ConstPtr& raw_msg,
80  novatel_oem7_msgs::Oem7Header::Type& hdr
81  )
82  {
83  const Oem7MessageHeaderMem* hdr_mem = reinterpret_cast<const Oem7MessageHeaderMem*>(raw_msg->getMessageData(0));
84 
85  hdr.message_id = hdr_mem->message_id;
86  hdr.message_type = hdr_mem->message_type;
87  hdr.sequence_number = hdr_mem->sequence;
88  hdr.time_status = hdr_mem->time_status;
89  hdr.gps_week_number = hdr_mem->gps_week;
90  hdr.gps_week_milliseconds = hdr_mem->gps_milliseconds;
91  }
92 
94  const Oem7RawMessageIf::ConstPtr& raw_msg,
95  novatel_oem7_msgs::Oem7Header::Type& hdr
96  )
97  {
98  const Oem7MessgeShortHeaderMem* hdr_mem = reinterpret_cast<const Oem7MessgeShortHeaderMem*>(raw_msg->getMessageData(0));
99 
100  hdr.message_id = hdr_mem->message_id;
101  hdr.message_type = novatel_oem7_msgs::Oem7Header::OEM7MSGTYPE_LOG; // Always log
102  hdr.sequence_number = 0; // Not available; assume it's a single log.
103  hdr.time_status = GPS_REFTIME_STATUS_UNKNOWN;
104  hdr.gps_week_number = hdr_mem->gps_week;
105  hdr.gps_week_milliseconds = hdr_mem->gps_milliseconds;
106  }
107 
108 
112  bool isNMEAMessage(const Oem7RawMessageIf::ConstPtr& raw_msg)
113  {
114  return std::find(OEM7_NMEA_MSGIDS.begin(),
115  OEM7_NMEA_MSGIDS.end(),
116  raw_msg->getMessageId()) != OEM7_NMEA_MSGIDS.end();
117  }
118 
119  size_t Get_INSCONFIG_NumTranslations(const INSCONFIG_FixedMem* insconfig)
120  {
121  const uint8_t* mem = reinterpret_cast<const uint8_t*>(insconfig) + sizeof(INSCONFIG_FixedMem);
122  return *reinterpret_cast<const uint32_t*>(mem); // Safe because all fields are guaranteed to be aligned.
123  }
124 
125  const INSCONFIG_TranslationMem* Get_INSCONFIG_Translation(const INSCONFIG_FixedMem* insconfig, size_t idx)
126  {
127  const uint8_t* mem = reinterpret_cast<const uint8_t*>(insconfig) +
128  sizeof(INSCONFIG_FixedMem) +
129  sizeof(uint32_t) +
130  sizeof(INSCONFIG_TranslationMem) * idx;
131 
132  return reinterpret_cast<const INSCONFIG_TranslationMem*>(mem);
133  }
134 
135  size_t Get_INSCONFIG_NumRotations(const INSCONFIG_FixedMem* insconfig)
136  {
137  const uint8_t* mem = reinterpret_cast<const uint8_t*>(insconfig) +
138  sizeof(INSCONFIG_FixedMem) +
139  sizeof(uint32_t) +
140  sizeof(INSCONFIG_TranslationMem) * Get_INSCONFIG_NumTranslations(insconfig);
141 
142  return *reinterpret_cast<const uint32_t*>(mem);
143  }
144 
145 
146  const INSCONFIG_RotationMem* Get_INSCONFIG_Rotation(const INSCONFIG_FixedMem* insconfig, size_t idx)
147  {
148  const uint8_t* mem = reinterpret_cast<const uint8_t*>(insconfig) +
149  sizeof(INSCONFIG_FixedMem) +
150  sizeof(uint32_t) +
151  sizeof(INSCONFIG_TranslationMem) * Get_INSCONFIG_NumTranslations(insconfig) +
152  sizeof(uint32_t) +
153  sizeof(INSCONFIG_RotationMem) * idx;
154 
155  return reinterpret_cast<const INSCONFIG_RotationMem*>(mem);
156  }
157 
158 
159  size_t Get_PSRDOP2_NumSystems(const PSRDOP2_FixedMem* psrdop2)
160  {
161  const uint8_t* mem = reinterpret_cast<const uint8_t*>(psrdop2) + sizeof(PSRDOP2_FixedMem);
162  return *reinterpret_cast<const uint32_t*>(mem); // Safe because all fields are guaranteed to be aligned.
163  }
164 
165  const PSRDOP2_SystemMem* Get_PSRDOP2_System(const PSRDOP2_FixedMem* psrdop2, size_t idx)
166  {
167  const uint8_t* mem = reinterpret_cast<const uint8_t*>(psrdop2) +
168  sizeof(PSRDOP2_FixedMem) +
169  sizeof(uint32_t) +
170  sizeof(PSRDOP2_SystemMem) * idx;
171 
172  return reinterpret_cast<const PSRDOP2_SystemMem*>(mem);
173  }
174 
175 
176 }
177 
178 
179 
180 
181 
static const std::vector< int > OEM7_NMEA_MSGIDS({GLMLA_OEM7_MSGID, GPALM_OEM7_MSGID, GPGGA_OEM7_MSGID, GPGGALONG_OEM7_MSGID, GPGLL_OEM7_MSGID, GPGRS_OEM7_MSGID, GPGSA_OEM7_MSGID, GPGST_OEM7_MSGID, GPGSV_OEM7_MSGID, GPHDT_OEM7_MSGID, GPHDTDUALANTENNA_MSGID, GPRMB_OEM7_MSGID, GPRMC_OEM7_MSGID, GPVTG_OEM7_MSGID, GPZDA_OEM7_MSGID})
const PSRDOP2_SystemMem * Get_PSRDOP2_System(const PSRDOP2_FixedMem *psrdop2, size_t idx)
bool isNMEAMessage(const Oem7RawMessageIf::ConstPtr &raw_msg)
size_t Get_INSCONFIG_NumTranslations(const INSCONFIG_FixedMem *insconfig)
const INSCONFIG_TranslationMem * Get_INSCONFIG_Translation(const INSCONFIG_FixedMem *insconfig, size_t idx)
int getOem7MessageId(const std::string &msg_name)
ROSCPP_DECL const std::string & getNamespace()
size_t Get_PSRDOP2_NumSystems(const PSRDOP2_FixedMem *psrdop2)
#define ROS_DEBUG_STREAM(args)
void getOem7ShortHeader(const Oem7RawMessageIf::ConstPtr &raw_msg, novatel_oem7_msgs::Oem7Header::Type &hdr)
size_t Get_INSCONFIG_NumRotations(const INSCONFIG_FixedMem *insconfig)
void getOem7Header(const Oem7RawMessageIf::ConstPtr &raw_msg, novatel_oem7_msgs::Oem7Header::Type &hdr)
void initializeOem7MessageUtil(ros::NodeHandle &nh)
bool getParam(const std::string &key, std::string &s) const
const std::string & getOem7MessageName(int msg_id)
const INSCONFIG_RotationMem * Get_INSCONFIG_Rotation(const INSCONFIG_FixedMem *insconfig, size_t idx)


novatel_oem7_driver
Author(s):
autogenerated on Tue Mar 9 2021 03:48:00