decode_packets.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (Apache 2.0)
3  *
4  * Copyright (c) 2019, The MITRE Corporation.
5  * All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * https://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Sections of this project contains content developed by The MITRE Corporation.
20  * If this code is used in a deployment or embedded within another project,
21  * it is requested that you send an email to opensource@mitre.org in order to
22  * let us know where this software is being used.
23  *********************************************************************/
24 
34 #include <cmath>
35 
36 #define RADIANS_TO_DEGREES (180.0 / M_PI)
37 
38 namespace kvh
39 {
40 
54  int Driver::DecodeUtmFix(utm_fix *_utmPacket, an_packet_t *_anPacket)
55  {
56  if (_anPacket->id == packet_id_utm_position && _anPacket->length == 26)
57  {
58  memcpy(&_utmPacket->position, &_anPacket->data[0], 3 * sizeof(double));
59  _utmPacket->zone_num = _anPacket->data[24];
60  _utmPacket->zone = _anPacket->data[25];
61  return 0;
62  }
63  else
64  return -1;
65  }
66 
80  {
81 
82  // See if packet id is in our map
83  if (!(packetStorage_.Contains(static_cast<packet_id_e>(_anPacket->id))))
84  {
85  // If packet is not in our map, print out the id and length and return as unsupported
86  if (debug_)
87  printf("Decoding error: packet ID %u of Length %u\n", _anPacket->id, _anPacket->length);
88  return -1;
89  }
90 
91  /*********************************
92  * PATTERN CODE NOTE - All code here follows the same pattern.
93  * We shouldn't have to check for error in update or setupdated functions since
94  * we confirm the packet is already available above.
95  * Switch (packet_id) to determine packet type
96  * case packet_id:
97  * if (decode(packet))
98  * update packet
99  * set packet update to true
100  * else
101  * return error unable to decode
102  */
103 
104  switch (_anPacket->id)
105  {
107  // copy all the binary data into the typedef struct for the packet
108  // this allows easy access to all the different values
109  system_state_packet_t sysPacket;
110  if (decode_system_state_packet(&sysPacket, _anPacket) == 0)
111  {
112  // Notify that we have updated packet
115 
116  if (debug_)
117  {
118  printf("Recieved system state packet.\n");
119  }
120  }
121  else
122  {
123  if (debug_)
124  printf("Failed to decode system state packet properly.\n");
125 
126  return -2;
127  }
128  break;
129  case packet_id_unix_time:
130  unix_time_packet_t unixPacket;
131  if (decode_unix_time_packet(&unixPacket, _anPacket) == 0)
132  {
135 
136  if (debug_)
137  {
138  printf("Recieved unix time packet.\n");
139  }
140  }
141  else
142  {
143  if (debug_)
144  printf("Failed to decode unix time packet properly.\n");
145 
146  return -2;
147  }
148  break;
150  raw_sensors_packet_t rawSensors;
151  if (decode_raw_sensors_packet(&rawSensors, _anPacket) == 0)
152  {
155 
156  if (debug_)
157  {
158  printf("Recieved raw sensors packet.\n");
159  }
160  }
161  else
162  {
163  if (debug_)
164  printf("Failed to decode raw sensors packet properly.\n");
165 
166  return -2;
167  }
168  break;
170  satellites_packet_t satellitesPacket;
171  if (decode_satellites_packet(&satellitesPacket, _anPacket) == 0)
172  {
175 
176  if (debug_)
177  printf("Collected satellites packet.\n");
178  }
179  else
180  {
181  if (debug_)
182  printf("Failed to decode satellites packet properly.\n");
183 
184  return -2;
185  }
186  break;
188  detailed_satellites_packet_t detailedPacket;
189  if (decode_detailed_satellites_packet(&detailedPacket, _anPacket) == 0)
190  {
193 
194  if (debug_)
195  printf("Collected detailed satellites packet.\n");
196  }
197  else
198  {
199  if (debug_)
200  printf("Failed to decode detailed satellites packet properly.\n");
201 
202  return -2;
203  }
204  break;
206  local_magnetics_packet_t magPacket;
207  if (decode_local_magnetics_packet(&magPacket, _anPacket) == 0)
208  {
211 
212  if (debug_)
213  printf("Collected local magnetics packet.\n");
214  }
215  else
216  {
217  if (debug_)
218  printf("Failed to decode local magnetics packet properly.\n");
219 
220  return -2;
221  }
222  break;
224  // Below we had to create a modified decode function since
225 
226  utm_fix utmPacket;
227  if (DecodeUtmFix(&utmPacket, _anPacket) == 0)
228  {
229  if (debug_) printf("UTM: %f, %f, %f\n", utmPacket.position[0], utmPacket.position[1], utmPacket.position[2]);
232 
233  if (debug_)
234  printf("Collected utm position packet.\n");
235  }
236  else
237  {
238  if (debug_)
239  printf("Failed to decode utm position packet properly.\n");
240 
241  return -2;
242  }
243  break;
245  ecef_position_packet_t ecefPacket;
246  if (decode_ecef_position_packet(&ecefPacket, _anPacket) == 0)
247  {
250 
251  if (debug_)
252  printf("Collected ecef position packet.\n");
253  }
254  else
255  {
256  if (debug_)
257  printf("Failed to decode ecef position packet properly.\n");
258 
259  return -2;
260  }
261  break;
263  north_seeking_status_packet_t northPacket;
264  if (decode_north_seeking_status_packet(&northPacket, _anPacket) == 0)
265  {
268 
269  if (debug_)
270  printf("Collected north seeking status packet.\n");
271  }
272  else
273  {
274  if (debug_)
275  printf("Failed to decode north seeking status packet properly.\n");
276 
277  return -2;
278  }
279  break;
282  if (decode_euler_orientation_standard_deviation_packet(&eulerPacket, _anPacket) == 0)
283  {
286 
287  if (debug_)
288  printf("Collected euler orientation standard deviation packet.\n");
289  }
290  else
291  {
292  if (debug_)
293  printf("Failed to decode euler orientation standard devation packet.\n");
294  return -2;
295  }
296  break;
298  odometer_state_packet_t odometerStatePacket;
299  if (decode_odometer_state_packet(&odometerStatePacket, _anPacket) == 0)
300  {
303 
304  if (debug_)
305  printf("Collected odometer state packet.\n");
306  }
307  else
308  {
309  if (debug_)
310  printf("Failed to decode odometer state packet.\n");
311  return -2;
312  }
313  break;
314  case packet_id_raw_gnss:
315  raw_gnss_packet_t rawGnssPacket;
316  if (decode_raw_gnss_packet(&rawGnssPacket, _anPacket) == 0)
317  {
320 
321  if (debug_)
322  printf("Collected raw gnss packet\n");
323  }
324  else
325  {
326  if (debug_)
327  printf("Failed to decode raw gnss packet\n");
328  return -2;
329  }
330  break;
331  default:
332  break;
333  }
334 
335  return 0;
336  } // END DecodePacket()
337 } // namespace kvh
KVH Geo Fog 3D driver class header.
int decode_north_seeking_status_packet(north_seeking_status_packet_t *north_seeking_status_packet, an_packet_t *an_packet)
uint8_t data[1]
int decode_detailed_satellites_packet(detailed_satellites_packet_t *detailed_satellites_packet, an_packet_t *an_packet)
int decode_raw_sensors_packet(raw_sensors_packet_t *raw_sensors_packet, an_packet_t *an_packet)
int decode_euler_orientation_standard_deviation_packet(euler_orientation_standard_deviation_packet_t *euler_orientation_standard_deviation, an_packet_t *an_packet)
int decode_raw_gnss_packet(raw_gnss_packet_t *raw_gnss_packet, an_packet_t *an_packet)
int SetPacketUpdated(packet_id_e, bool)
int DecodeUtmFix(utm_fix *, an_packet_t *)
The current api given by kvh incorrectly deals with this packet so we needed to write our own decoder...
int decode_local_magnetics_packet(local_magnetics_packet_t *local_magnetics_packet, an_packet_t *an_packet)
int decode_odometer_state_packet(odometer_state_packet_t *odometer_state_packet, an_packet_t *an_packet)
bool debug_
Set true to print debug statements.
KvhPacketStorage packetStorage_
Class responsible for handling packets and ensuring consistency.
int decode_ecef_position_packet(ecef_position_packet_t *ecef_position_packet, an_packet_t *an_packet)
int decode_satellites_packet(satellites_packet_t *satellites_packet, an_packet_t *an_packet)
int DecodePacket(an_packet_t *)
int decode_unix_time_packet(unix_time_packet_t *unix_time_packet, an_packet_t *an_packet)
bool Contains(packet_id_e)
int UpdatePacket(packet_id_e _packetId, T &_packetData)
int decode_system_state_packet(system_state_packet_t *system_state_packet, an_packet_t *an_packet)


kvh_geo_fog_3d_driver
Author(s): Trevor Bostic , Zach LaCelle
autogenerated on Fri Jan 24 2020 03:18:17