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 
48  int KvhPacketStorage::Init(KvhPacketRequest& _packRequest)
49  {
50 
51  std::set<packet_id_e> packetIdList;
52  for (int i = 0; i < _packRequest.size(); i++)
53  {
54  packet_id_e packEnum = _packRequest.at(i).first;
55 
56  // Check for duplicates
57  if (packetIdList.count(packEnum) > 0)
58  {
59  return -1;
60  }
61  else
62  {
63  packetIdList.insert(packEnum);
64  }
65 
66 
67  /*
68  * General form for below:
69  * case (packetId):
70  * packetMap_[packetId] = pair(false, shared_ptr(packet_struct_t))
71  */
72  switch (packEnum)
73  {
75  packetMap_[packet_id_system_state] = std::make_pair(false, std::make_shared<system_state_packet_t>());
76  break;
78  packetMap_[packet_id_unix_time] = std::make_pair(false, std::make_shared<unix_time_packet_t>());
79  break;
81  packetMap_[packet_id_raw_sensors] = std::make_pair(false, std::make_shared<raw_sensors_packet_t>());
82  break;
84  packetMap_[packet_id_satellites] = std::make_pair(false, std::make_shared<satellites_packet_t>());
85  break;
87  packetMap_[packet_id_satellites_detailed] = std::make_pair(false, std::make_shared<detailed_satellites_packet_t>());
88  break;
90  packetMap_[packet_id_local_magnetics] = std::make_pair(false, std::make_shared<local_magnetics_packet_t>());
91  break;
93  packetMap_[packet_id_utm_position] = std::make_pair(false, std::make_shared<utm_fix>());
94  break;
96  packetMap_[packet_id_ecef_position] = std::make_pair(false, std::make_shared<ecef_position_packet_t>());
97  break;
99  packetMap_[packet_id_north_seeking_status] = std::make_pair(false, std::make_shared<north_seeking_status_packet_t>());
100  break;
102  packetMap_[packet_id_euler_orientation_standard_deviation] = std::make_pair(false, std::make_shared<euler_orientation_standard_deviation_packet_t>());
103  break;
105  packetMap_[packet_id_odometer_state] = std::make_pair(false, std::make_shared<odometer_state_packet_t>());
106  break;
107  case packet_id_raw_gnss:
108  packetMap_[packet_id_raw_gnss] = std::make_pair(false, std::make_shared<raw_gnss_packet_t>());
109  break;
110  default:
111  return -2;
112  }
113  }
114 
115  // Will return 0 if we support all, or the number of entered id's we don't support if >0
116  return 0;
117  } // END CreatePacketMap()
118 
127  int KvhPacketStorage::SetPacketUpdated(packet_id_e _packetId, bool _updateStatus)
128  {
129  if(this->Contains(_packetId))
130  {
131  packetMap_[_packetId].first = _updateStatus;
132  return 0;
133  }
134 
135  return -1;
136  }
137 
144  {
145  if (this->Contains(_packetId))
146  {
147  return packetMap_[_packetId].first;
148  }
149 
150  return false;
151  }
152 
159  {
160  return packetMap_.count(_packetId) > 0;
161  }
162 
168  {
169  return packetMap_.size();
170  }
171 
178  {
179  for(auto it = packetTypeStr_.cbegin(); it != packetTypeStr_.cend(); it++)
180  {
181  printf("Packet Id: %d, Packet Type: %s\n", it->first, packetTypeStr_[it->first].c_str());
182  }
183  }
184 
191  {
192  for (auto it = packetSize_.cbegin(); it != packetSize_.cend(); it++)
193  {
194  printf("Packet id: %d, Size: %d\n", it->first, packetSize_[it->first]);
195  }
196  }
197 }
KVH Geo Fog 3D driver class header.
std::map< packet_id_e, std::string > packetTypeStr_
Holds the string value for the different types of structs.
packet_id_e
KVH Packet storing class header.
std::map< packet_id_e, int > packetSize_
Map relating packet id&#39;s to the associated struct size. Used for baudrate calculation.
std::vector< std::pair< packet_id_e, uint16_t > > KvhPacketRequest
int Init(KvhPacketRequest &)
Correctly sets up a KvhPacketMap for the requested packets.
int SetPacketUpdated(packet_id_e, bool)
bool PacketIsUpdated(packet_id_e)
static void PrintPacketTypes()
static void PrintPacketSizes()
bool Contains(packet_id_e)


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