packet_storage.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 
33 
34 namespace kvh
35 {
36 
38 
50 {
51 
52  int returnValue = 0;
53  int tempReturn = 0;
54  for (int i = 0; i < _packRequest.size(); i++)
55  {
56  tempReturn = AddPacket(_packRequest.at(i).first);
57 
58  // Returns immediately on error, or with warning if duplicate found
59  if (tempReturn > 0)
60  {
61  returnValue = tempReturn;
62  }
63  else if (tempReturn < 0)
64  {
65  return tempReturn;
66  }
67  }
68 
69  return returnValue;
70 } // END CreatePacketMap()
71 
73 {
74 
75  if (Contains(_packetId))
76  {
77  return 1;
78  }
79 
80  /*
81  * General form for below:
82  * case (packetId):
83  * packetMap_[packetId] = pair(false, shared_ptr(packet_struct_t))
84  */
85  switch (_packetId)
86  {
88  packetMap_[packet_id_system_state] = std::make_pair(false, std::make_shared<system_state_packet_t>());
89  break;
91  packetMap_[packet_id_unix_time] = std::make_pair(false, std::make_shared<unix_time_packet_t>());
92  break;
94  packetMap_[packet_id_raw_sensors] = std::make_pair(false, std::make_shared<raw_sensors_packet_t>());
95  break;
97  packetMap_[packet_id_satellites] = std::make_pair(false, std::make_shared<satellites_packet_t>());
98  break;
100  packetMap_[packet_id_satellites_detailed] = std::make_pair(false, std::make_shared<detailed_satellites_packet_t>());
101  break;
103  packetMap_[packet_id_local_magnetics] = std::make_pair(false, std::make_shared<local_magnetics_packet_t>());
104  break;
106  packetMap_[packet_id_utm_position] = std::make_pair(false, std::make_shared<utm_fix>());
107  break;
109  packetMap_[packet_id_ecef_position] = std::make_pair(false, std::make_shared<ecef_position_packet_t>());
110  break;
112  packetMap_[packet_id_north_seeking_status] = std::make_pair(false, std::make_shared<north_seeking_status_packet_t>());
113  break;
115  packetMap_[packet_id_euler_orientation_standard_deviation] = std::make_pair(false, std::make_shared<euler_orientation_standard_deviation_packet_t>());
116  break;
118  packetMap_[packet_id_odometer_state] = std::make_pair(false, std::make_shared<odometer_state_packet_t>());
119  break;
120  case packet_id_raw_gnss:
121  packetMap_[packet_id_raw_gnss] = std::make_pair(false, std::make_shared<raw_gnss_packet_t>());
122  break;
124  packetMap_[packet_id_odometer_configuration] = std::make_pair(false, std::make_shared<odometer_configuration_packet_t>());
125  break;
127  packetMap_[packet_id_body_velocity] = std::make_pair(false, std::make_shared<body_velocity_packet_t>());
128  break;
130  packetMap_[packet_id_velocity_standard_deviation] = std::make_pair(false, std::make_shared<velocity_standard_deviation_packet_t>());
131  break;
132  default:
133  return -1;
134  }
135 
136  return 0;
137 
138 } // namespace kvh
139 
148 int KvhPacketStorage::SetPacketUpdated(packet_id_e _packetId, bool _updateStatus)
149 {
150  if (this->Contains(_packetId))
151  {
152  packetMap_[_packetId].first = _updateStatus;
153  return 0;
154  }
155 
156  return -1;
157 }
158 
165 {
166  if (this->Contains(_packetId))
167  {
168  return packetMap_[_packetId].first;
169  }
170 
171  return false;
172 }
173 
180 {
181  return packetMap_.count(_packetId) > 0;
182 }
183 
189 {
190  return packetMap_.size();
191 }
192 
199 {
200  for (auto it = packetTypeStr_.cbegin(); it != packetTypeStr_.cend(); it++)
201  {
202  printf("Packet Id: %d, Packet Type: %s\n", it->first, packetTypeStr_[it->first].c_str());
203  }
204 }
205 
212 {
213  for (auto it = packetSize_.cbegin(); it != packetSize_.cend(); it++)
214  {
215  printf("Packet id: %d, Size: %d\n", it->first, packetSize_[it->first]);
216  }
217 }
218 } // namespace kvh
packet_id_satellites_detailed
@ packet_id_satellites_detailed
Definition: spatial_packets.h:71
kvh::KvhPacketRequest
std::vector< std::pair< packet_id_e, uint16_t > > KvhPacketRequest
Definition: kvh_geo_fog_3d_packet_storage.hpp:65
kvh::KvhPacketStorage::Contains
bool Contains(packet_id_e)
Definition: packet_storage.cpp:179
kvh::KvhPacketStorage::PacketIsUpdated
bool PacketIsUpdated(packet_id_e)
Definition: packet_storage.cpp:164
kvh
Definition: kvh_geo_fog_3d_device_configuration.hpp:44
kvh::KvhPacketStorage::Size
int Size()
Definition: packet_storage.cpp:188
packet_id_north_seeking_status
@ packet_id_north_seeking_status
Definition: spatial_packets.h:111
kvh::KvhPacketStorage::Init
int Init(KvhPacketRequest &)
Correctly sets up a KvhPacketMap for the requested packets.
Definition: packet_storage.cpp:37
packet_id_utm_position
@ packet_id_utm_position
Definition: spatial_packets.h:74
kvh::KvhPacketStorage::packetMap_
KvhPacketMap packetMap_
Definition: kvh_geo_fog_3d_packet_storage.hpp:71
packet_id_euler_orientation_standard_deviation
@ packet_id_euler_orientation_standard_deviation
Definition: spatial_packets.h:66
packet_id_satellites
@ packet_id_satellites
Definition: spatial_packets.h:70
packet_id_odometer_state
@ packet_id_odometer_state
Definition: spatial_packets.h:91
kvh::KvhPacketStorage::PrintPacketSizes
static void PrintPacketSizes()
Definition: packet_storage.cpp:211
packet_id_raw_gnss
@ packet_id_raw_gnss
Definition: spatial_packets.h:69
packet_id_ecef_position
@ packet_id_ecef_position
Definition: spatial_packets.h:73
packet_id_system_state
@ packet_id_system_state
Definition: spatial_packets.h:60
kvh::KvhPacketStorage::AddPacket
int AddPacket(packet_id_e)
Definition: packet_storage.cpp:72
kvh::packetTypeStr_
std::map< packet_id_e, std::string > packetTypeStr_
Holds the string value for the different types of structs.
Definition: kvh_global_vars.cpp:74
kvh::KvhPacketStorage::PrintPacketTypes
static void PrintPacketTypes()
Definition: packet_storage.cpp:198
kvh_geo_fog_3d_packet_storage.hpp
KVH Packet storing class header.
packet_id_local_magnetics
@ packet_id_local_magnetics
Definition: spatial_packets.h:90
packet_id_odometer_configuration
@ packet_id_odometer_configuration
Definition: spatial_packets.h:126
packet_id_unix_time
@ packet_id_unix_time
Definition: spatial_packets.h:61
packet_id_e
packet_id_e
Definition: spatial_packets.h:45
packet_id_body_velocity
@ packet_id_body_velocity
Definition: spatial_packets.h:76
kvh::packetSize_
std::map< packet_id_e, int > packetSize_
Map relating packet id's to the associated struct size. Used for baudrate calculation.
Definition: kvh_global_vars.cpp:56
kvh_geo_fog_3d_driver.hpp
KVH Geo Fog 3D driver class header.
kvh::KvhPacketStorage::SetPacketUpdated
int SetPacketUpdated(packet_id_e, bool)
Definition: packet_storage.cpp:148
packet_id_velocity_standard_deviation
@ packet_id_velocity_standard_deviation
Definition: spatial_packets.h:65
kvh::KvhPacketStorage::KvhPacketStorage
KvhPacketStorage()
Definition: packet_storage.cpp:37
packet_id_raw_sensors
@ packet_id_raw_sensors
Definition: spatial_packets.h:68


kvh_geo_fog_3d_driver
Author(s): Trevor Bostic , Zach LaCelle
autogenerated on Wed Mar 2 2022 00:28:57