data.cpp
Go to the documentation of this file.
1 #include "create/data.h"
2 
3 #define ADD_PACKET(id,nbytes,info,enabledVersion) if ((enabledVersion) & version) packets[id]=boost::make_shared<Packet>(nbytes,info)
4 
5 namespace create {
6 
8  // Populate data map
9  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10  * WARNING: Adding too many packets will flood the serial *
11  * buffer and corrupt the stream. *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13  ADD_PACKET(ID_BUMP_WHEELDROP, 1, "bumps_wheeldrops", V_ALL);
14  ADD_PACKET(ID_WALL, 1, "wall", V_ALL);
15  ADD_PACKET(ID_CLIFF_LEFT, 1, "cliff_left", V_ALL);
16  ADD_PACKET(ID_CLIFF_FRONT_LEFT, 1, "cliff_front_left", V_ALL);
17  ADD_PACKET(ID_CLIFF_FRONT_RIGHT, 1, "cliff_front_right", V_ALL);
18  ADD_PACKET(ID_CLIFF_RIGHT, 1, "cliff_right", V_ALL);
19  ADD_PACKET(ID_VIRTUAL_WALL, 1, "virtual_wall", V_ALL);
20  ADD_PACKET(ID_OVERCURRENTS, 1, "overcurrents", V_1);
21  ADD_PACKET(ID_DIRT_DETECT_LEFT, 1, "dirt_detect_left", V_ALL);
22  ADD_PACKET(ID_DIRT_DETECT_RIGHT, 1, "dirt_detect_right", V_1);
23  ADD_PACKET(ID_IR_OMNI, 1, "ir_opcode", V_ALL);
24  ADD_PACKET(ID_BUTTONS, 1, "buttons", V_ALL);
25  ADD_PACKET(ID_DISTANCE, 2, "distance", V_1 | V_2);
26  ADD_PACKET(ID_ANGLE, 2, "angle", V_1 | V_2);
27  ADD_PACKET(ID_CHARGE_STATE, 1, "charging_state", V_ALL);
28  ADD_PACKET(ID_VOLTAGE, 2, "voltage", V_ALL);
29  ADD_PACKET(ID_CURRENT, 2, "current", V_ALL);
30  ADD_PACKET(ID_TEMP, 1, "temperature", V_ALL);
31  ADD_PACKET(ID_CHARGE , 2, "battery_charge", V_ALL);
32  ADD_PACKET(ID_CAPACITY, 2, "battery_capacity", V_ALL);
33  ADD_PACKET(ID_OI_MODE, 1, "oi_mode", V_2 | V_3);
34  ADD_PACKET(ID_LEFT_ENC, 2, "enc_counts_left", V_3);
35  ADD_PACKET(ID_RIGHT_ENC, 2, "enc_counts_right", V_3);
36  ADD_PACKET(ID_LIGHT, 1, "light_bumper", V_3);
37  ADD_PACKET(ID_LIGHT_LEFT, 2, "light_bumper_left", V_3);
38  ADD_PACKET(ID_LIGHT_FRONT_LEFT, 2, "light_bumper_front_left", V_3);
39  ADD_PACKET(ID_LIGHT_CENTER_LEFT, 2, "light_bumper_center_left", V_3);
40  ADD_PACKET(ID_LIGHT_CENTER_RIGHT, 2, "light_bumper_center_right", V_3);
41  ADD_PACKET(ID_LIGHT_FRONT_RIGHT, 2, "light_bumper_front_right", V_3);
42  ADD_PACKET(ID_LIGHT_RIGHT, 2, "light_bumper_right", V_3);
43  ADD_PACKET(ID_IR_LEFT, 1, "ir_opcode_left", V_3);
44  ADD_PACKET(ID_IR_RIGHT, 1, "ir_opcode_right", V_3);
45  ADD_PACKET(ID_STASIS, 1, "stasis", V_3);
46 
47  totalDataBytes = 0;
48  for (std::map<uint8_t, boost::shared_ptr<Packet> >::iterator it = packets.begin();
49  it != packets.end();
50  ++it) {
51  ids.push_back(it->first);
52  totalDataBytes += it->second->nbytes;
53  }
54  }
55 
57 
58  bool Data::isValidPacketID(uint8_t id) const {
59  if (packets.count(id)) {
60  return true;
61  }
62  return false;
63  }
64 
65  boost::shared_ptr<Packet> Data::getPacket(uint8_t id) {
66  if (isValidPacketID(id)) {
67  return packets[id];
68  }
69  return boost::shared_ptr<Packet>();
70  }
71 
73  for (std::map<uint8_t, boost::shared_ptr<Packet> >::iterator it = packets.begin();
74  it != packets.end();
75  ++it) {
76  it->second->validate();
77  }
78  }
79 
80  unsigned int Data::getTotalDataBytes() const {
81  return totalDataBytes;
82  }
83 
84  uint8_t Data::getNumPackets() const {
85  return packets.size();
86  }
87 
88  std::vector<uint8_t> Data::getPacketIDs() {
89  return ids;
90  }
91 
92 } // namespace create
uint8_t getNumPackets() const
Definition: data.cpp:84
bool isValidPacketID(const uint8_t id) const
Definition: data.cpp:58
std::vector< uint8_t > getPacketIDs()
Definition: data.cpp:88
uint32_t getTotalDataBytes() const
Definition: data.cpp:80
Data(ProtocolVersion version=V_3)
Definition: data.cpp:7
Definition: create.h:46
boost::shared_ptr< Packet > getPacket(const uint8_t id)
Definition: data.cpp:65
ProtocolVersion
Definition: types.h:41
std::vector< uint8_t > ids
Definition: data.h:48
#define ADD_PACKET(id, nbytes, info, enabledVersion)
Definition: data.cpp:3
std::map< uint8_t, boost::shared_ptr< Packet > > packets
Definition: data.h:46
uint32_t totalDataBytes
Definition: data.h:47
void validateAll()
Definition: data.cpp:72


libcreate
Author(s): Jacob Perron
autogenerated on Sat Jun 8 2019 17:58:17