MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
commands_system.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #include <mip/mip_result.hpp>
6 #include <mip/mip_interface.hpp>
7 
8 #include <stdint.h>
9 #include <stddef.h>
10 
11 namespace mip {
12 namespace C {
13 struct mip_interface;
14 } // namespace C
15 
16 namespace commands_system {
17 
24 
26 // Descriptors
28 
29 enum
30 {
32 
33  CMD_ENUMERATE = 0x01,
35  CMD_COM_MODE = 0x10,
38 
43 };
44 
46 // Shared Type Definitions
48 
49 static constexpr const uint8_t MIP_SYSTEM_COMMAND_COMM_MODE_PASSTHRU = 0x00;
50 static constexpr const uint8_t MIP_SYSTEM_COMMAND_COMM_MODE_NORMAL = 0x01;
51 static constexpr const uint8_t MIP_SYSTEM_COMMAND_COMM_MODE_IMU = 0x02;
52 static constexpr const uint8_t MIP_SYSTEM_COMMAND_COMM_MODE_GPS = 0x03;
53 enum class CommsInterface : uint8_t
54 {
55  ALL = 0,
56  MAIN = 1,
57  UART_1 = 17,
58  UART_2 = 18,
59  UART_3 = 19,
60  USB_1 = 33,
61  USB_2 = 34,
62 };
63 
64 struct CommsProtocol : Bitfield<CommsProtocol>
65 {
66  typedef uint32_t Type;
67  enum _enumType : uint32_t
68  {
69  NONE = 0x00000000,
70  MIP_COMMANDS = 0x00000001,
71  MIP_DATA = 0x00000002,
72  NMEA = 0x00000004,
73  RTCM = 0x00000008,
74  SPARTN = 0x00000010,
75  ALL = 0x0000001F,
76  };
77  uint32_t value = NONE;
78 
80  CommsProtocol(int val) : value((uint32_t)val) {}
81  operator uint32_t() const { return value; }
82  CommsProtocol& operator=(uint32_t val) { value = val; return *this; }
83  CommsProtocol& operator=(int val) { value = uint32_t(val); return *this; }
84  CommsProtocol& operator|=(uint32_t val) { return *this = value | val; }
85  CommsProtocol& operator&=(uint32_t val) { return *this = value & val; }
86 
87  bool mipCommands() const { return (value & MIP_COMMANDS) > 0; }
88  void mipCommands(bool val) { value &= ~MIP_COMMANDS; if(val) value |= MIP_COMMANDS; }
89  bool mipData() const { return (value & MIP_DATA) > 0; }
90  void mipData(bool val) { value &= ~MIP_DATA; if(val) value |= MIP_DATA; }
91  bool nmea() const { return (value & NMEA) > 0; }
92  void nmea(bool val) { value &= ~NMEA; if(val) value |= NMEA; }
93  bool rtcm() const { return (value & RTCM) > 0; }
94  void rtcm(bool val) { value &= ~RTCM; if(val) value |= RTCM; }
95  bool spartn() const { return (value & SPARTN) > 0; }
96  void spartn(bool val) { value &= ~SPARTN; if(val) value |= SPARTN; }
97  bool allSet() const { return value == ALL; }
98  void setAll() { value |= ALL; }
99 };
100 
102 // Mip Fields
104 
118 
119 struct CommMode
120 {
122  FunctionSelector function = static_cast<FunctionSelector>(0);
123  uint8_t mode = 0;
124 
126  static constexpr const uint8_t DESCRIPTOR_SET = ::mip::commands_system::DESCRIPTOR_SET;
127  static constexpr const uint8_t FIELD_DESCRIPTOR = ::mip::commands_system::CMD_COM_MODE;
129  static constexpr const char* NAME = "CommMode";
130  static constexpr const char* DOC_NAME = "CommMode";
131  static constexpr const bool HAS_FUNCTION_SELECTOR = true;
132 
133  auto asTuple() const
134  {
135  return std::make_tuple(mode);
136  }
137 
138  auto asTuple()
139  {
140  return std::make_tuple(std::ref(mode));
141  }
142 
144  {
145  CommMode cmd;
146  cmd.function = function;
147  return cmd;
148  }
149 
151  void insert(Serializer& serializer) const;
152  void extract(Serializer& serializer);
153 
154  struct Response
155  {
157  uint8_t mode = 0;
158 
160  static constexpr const uint8_t DESCRIPTOR_SET = ::mip::commands_system::DESCRIPTOR_SET;
163  static constexpr const char* NAME = "CommMode::Response";
164  static constexpr const char* DOC_NAME = "CommMode Response";
165  static constexpr const bool HAS_FUNCTION_SELECTOR = false;
166 
167  auto asTuple() const
168  {
169  return std::make_tuple(mode);
170  }
171 
172  auto asTuple()
173  {
174  return std::make_tuple(std::ref(mode));
175  }
176 
178  void insert(Serializer& serializer) const;
179  void extract(Serializer& serializer);
180 
181  };
182 };
184 TypedResult<CommMode> readCommMode(C::mip_interface& device, uint8_t* modeOut);
186 
207 
209 {
211  FunctionSelector function = static_cast<FunctionSelector>(0);
212  CommsInterface port = static_cast<CommsInterface>(0);
215 
217  static constexpr const uint8_t DESCRIPTOR_SET = ::mip::commands_system::DESCRIPTOR_SET;
220  static constexpr const char* NAME = "InterfaceControl";
221  static constexpr const char* DOC_NAME = "Interface Control";
222  static constexpr const bool HAS_FUNCTION_SELECTOR = true;
223 
224  auto asTuple() const
225  {
226  return std::make_tuple(port,protocols_incoming,protocols_outgoing);
227  }
228 
229  auto asTuple()
230  {
231  return std::make_tuple(std::ref(port),std::ref(protocols_incoming),std::ref(protocols_outgoing));
232  }
233 
235  {
236  InterfaceControl cmd;
237  cmd.function = function;
239  return cmd;
240  }
241 
243  void insert(Serializer& serializer) const;
244  void extract(Serializer& serializer);
245 
246  struct Response
247  {
249  CommsInterface port = static_cast<CommsInterface>(0);
252 
254  static constexpr const uint8_t DESCRIPTOR_SET = ::mip::commands_system::DESCRIPTOR_SET;
257  static constexpr const char* NAME = "InterfaceControl::Response";
258  static constexpr const char* DOC_NAME = "Interface Control Response";
259  static constexpr const bool HAS_FUNCTION_SELECTOR = false;
260 
261  auto asTuple() const
262  {
263  return std::make_tuple(port,protocols_incoming,protocols_outgoing);
264  }
265 
266  auto asTuple()
267  {
268  return std::make_tuple(std::ref(port),std::ref(protocols_incoming),std::ref(protocols_outgoing));
269  }
270 
272  void insert(Serializer& serializer) const;
273  void extract(Serializer& serializer);
274 
275  };
276 };
277 TypedResult<InterfaceControl> writeInterfaceControl(C::mip_interface& device, CommsInterface port, CommsProtocol protocolsIncoming, CommsProtocol protocolsOutgoing);
278 TypedResult<InterfaceControl> readInterfaceControl(C::mip_interface& device, CommsInterface port, CommsProtocol* protocolsIncomingOut, CommsProtocol* protocolsOutgoingOut);
282 
285 
290 } // namespace commands_system
291 } // namespace mip
292 
mip::commands_system::CommsInterface::MAIN
@ MAIN
An alias that directs to Main USB if it's connected, or Main UART otherwise.
mip::commands_system::CommsProtocol::operator=
CommsProtocol & operator=(int val)
Definition: commands_system.hpp:83
mip::commands_system::InterfaceControl::Response::asTuple
auto asTuple()
Definition: commands_system.hpp:266
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::commands_system::CommsProtocol::value
uint32_t value
Definition: commands_system.hpp:77
mip::commands_system::CMD_HARDWARE_CONTROL_2
@ CMD_HARDWARE_CONTROL_2
Definition: commands_system.hpp:37
mip::commands_system::CommsInterface::UART_1
@ UART_1
Depending on your device, this may mean either the first UART currently configured,...
mip::commands_system::CMD_HARDWARE_CONTROL
@ CMD_HARDWARE_CONTROL
Definition: commands_system.hpp:36
mip::commands_system::CommsProtocol::ALL
@ ALL
Definition: commands_system.hpp:75
mip_descriptors.hpp
mip::commands_system::InterfaceControl
Definition: commands_system.hpp:208
mip::commands_system::InterfaceControl::asTuple
auto asTuple() const
Definition: commands_system.hpp:224
mip::commands_system::defaultCommMode
TypedResult< CommMode > defaultCommMode(C::mip_interface &device)
Definition: commands_system.cpp:90
mip::commands_system::InterfaceControl::NAME
static constexpr const char * NAME
Definition: commands_system.hpp:220
mip::commands_system::CommMode::insert
void insert(Serializer &serializer) const
Serialization.
Definition: commands_system.cpp:23
mip::commands_system::CommsProtocol::nmea
void nmea(bool val)
Definition: commands_system.hpp:92
mip::commands_system::CommsProtocol::mipData
bool mipData() const
Definition: commands_system.hpp:89
microstrain::Serializer
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:125
mip::commands_system::InterfaceControl::Response::NAME
static constexpr const char * NAME
Definition: commands_system.hpp:257
mip::commands_system::CommMode::extract
void extract(Serializer &serializer)
Definition: commands_system.cpp:33
mip::commands_system::CommsInterface
CommsInterface
Definition: commands_system.hpp:53
mip::commands_system::CommMode::asTuple
auto asTuple()
Definition: commands_system.hpp:138
mip::commands_system::CommsInterface::UART_3
@ UART_3
mip::commands_system::InterfaceControl::insert
void insert(Serializer &serializer) const
Serialization.
Definition: commands_system.cpp:100
mip::commands_system::InterfaceControl::create_sld_all
static InterfaceControl create_sld_all(::mip::FunctionSelector function)
Definition: commands_system.hpp:234
mip::commands_system::CMD_ENUMERATE
@ CMD_ENUMERATE
Definition: commands_system.hpp:33
mip::commands_system::InterfaceControl::function
FunctionSelector function
Parameters.
Definition: commands_system.hpp:211
mip::commands_system::InterfaceControl::Response::DESCRIPTOR
static constexpr const CompositeDescriptor DESCRIPTOR
Definition: commands_system.hpp:256
mip::commands_system::CommMode::Response::asTuple
auto asTuple() const
Definition: commands_system.hpp:167
mip::commands_system::defaultInterfaceControl
TypedResult< InterfaceControl > defaultInterfaceControl(C::mip_interface &device, CommsInterface port)
Definition: commands_system.cpp:218
mip::commands_system::CommsProtocol::CommsProtocol
CommsProtocol(int val)
Definition: commands_system.hpp:80
mip::C::mip_interface
struct mip::C::mip_interface mip_interface
State of the interface for communicating with a MIP device.
mip::commands_system::CommMode::Response::DOC_NAME
static constexpr const char * DOC_NAME
Definition: commands_system.hpp:164
mip::commands_system::InterfaceControl::Response::extract
void extract(Serializer &serializer)
Definition: commands_system.cpp:138
mip::commands_system::CommsInterface::USB_1
@ USB_1
The first virtual serial port over USB (ie. COM5)
mip::commands_system::CommMode::Response::FIELD_DESCRIPTOR
static constexpr const uint8_t FIELD_DESCRIPTOR
Definition: commands_system.hpp:161
mip::commands_system::CommMode::create_sld_all
static CommMode create_sld_all(::mip::FunctionSelector function)
Definition: commands_system.hpp:143
mip::commands_system::InterfaceControl::Response
Definition: commands_system.hpp:246
mip::commands_system::InterfaceControl::port
CommsInterface port
Which physical interface is being selected (USB, serial, etc)
Definition: commands_system.hpp:212
mip::commands_system::CommsProtocol::mipData
void mipData(bool val)
Definition: commands_system.hpp:90
mip::commands_system::CommMode::Response::insert
void insert(Serializer &serializer) const
Serialization.
Definition: commands_system.cpp:44
mip::commands_system::CommsInterface::USB_2
@ USB_2
The second virtual serial port over USB (ie. COM6), only available on GNSS/INS devices....
mip::commands_system::InterfaceControl::Response::protocols_incoming
CommsProtocol protocols_incoming
Input protocol(s) the port will accept. If the protocol supports ACK/NACK or detailed responses,...
Definition: commands_system.hpp:250
mip::commands_system::CommsInterface::ALL
@ ALL
mip::commands_system::CommMode::asTuple
auto asTuple() const
Definition: commands_system.hpp:133
mip::commands_system::CommsInterface::UART_2
@ UART_2
mip::commands_system::CommsProtocol::SPARTN
@ SPARTN
Definition: commands_system.hpp:74
mip::commands_system::REPLY_COM_MODE
@ REPLY_COM_MODE
Definition: commands_system.hpp:39
mip::commands_system::CommsProtocol::NONE
@ NONE
Definition: commands_system.hpp:69
mip::commands_system::writeCommMode
TypedResult< CommMode > writeCommMode(C::mip_interface &device, uint8_t mode)
Definition: commands_system.cpp:55
mip::commands_system::InterfaceControl::Response::port
CommsInterface port
Parameters.
Definition: commands_system.hpp:249
mip::commands_system::CommsProtocol::mipCommands
bool mipCommands() const
Definition: commands_system.hpp:87
mip::FunctionSelector
FunctionSelector
Definition: mip_descriptors.hpp:66
mip::commands_system::InterfaceControl::Response::protocols_outgoing
CommsProtocol protocols_outgoing
Data protocol(s) the port will output.
Definition: commands_system.hpp:251
mip::commands_system::CommsProtocol
Definition: commands_system.hpp:64
mip::commands_system::CommMode::Response
Definition: commands_system.hpp:154
mip::commands_system::InterfaceControl::DOC_NAME
static constexpr const char * DOC_NAME
Definition: commands_system.hpp:221
mip::commands_system::CommMode::Response::asTuple
auto asTuple()
Definition: commands_system.hpp:172
mip::commands_system::CommMode::Response::HAS_FUNCTION_SELECTOR
static constexpr const bool HAS_FUNCTION_SELECTOR
Definition: commands_system.hpp:165
mip::commands_system::CommMode::Response::NAME
static constexpr const char * NAME
Definition: commands_system.hpp:163
mip::commands_system::CommMode::NAME
static constexpr const char * NAME
Definition: commands_system.hpp:129
mip::commands_system::CommMode::HAS_FUNCTION_SELECTOR
static constexpr const bool HAS_FUNCTION_SELECTOR
Definition: commands_system.hpp:131
mip::commands_system::InterfaceControl::HAS_FUNCTION_SELECTOR
static constexpr const bool HAS_FUNCTION_SELECTOR
Definition: commands_system.hpp:222
mip::commands_system::InterfaceControl::Response::DESCRIPTOR_SET
static constexpr const uint8_t DESCRIPTOR_SET
Descriptors.
Definition: commands_system.hpp:254
mip::commands_system::CommMode::FIELD_DESCRIPTOR
static constexpr const uint8_t FIELD_DESCRIPTOR
Definition: commands_system.hpp:127
mip::commands_system::InterfaceControl::Response::FIELD_DESCRIPTOR
static constexpr const uint8_t FIELD_DESCRIPTOR
Definition: commands_system.hpp:255
mip::commands_system::CMD_INTERFACE_CONTROL
@ CMD_INTERFACE_CONTROL
Definition: commands_system.hpp:34
mip::commands_system::CommsProtocol::operator=
CommsProtocol & operator=(uint32_t val)
Definition: commands_system.hpp:82
mip::commands_system::REPLY_HARDWARE_CONTROL_2
@ REPLY_HARDWARE_CONTROL_2
Definition: commands_system.hpp:41
mip::commands_system::CMD_COM_MODE
@ CMD_COM_MODE
Definition: commands_system.hpp:35
mip::commands_system::InterfaceControl::Response::asTuple
auto asTuple() const
Definition: commands_system.hpp:261
mip::C::mip_interface
State of the interface for communicating with a MIP device.
Definition: mip_interface.h:44
mip::commands_system::readInterfaceControl
TypedResult< InterfaceControl > readInterfaceControl(C::mip_interface &device, CommsInterface port, CommsProtocol *protocolsIncomingOut, CommsProtocol *protocolsOutgoingOut)
Definition: commands_system.cpp:164
mip::commands_system::REPLY_HARDWARE_CONTROL
@ REPLY_HARDWARE_CONTROL
Definition: commands_system.hpp:40
mip::commands_system::CommMode::DOC_NAME
static constexpr const char * DOC_NAME
Definition: commands_system.hpp:130
mip::commands_system::CommsProtocol::NMEA
@ NMEA
Definition: commands_system.hpp:72
mip::commands_system::saveInterfaceControl
TypedResult< InterfaceControl > saveInterfaceControl(C::mip_interface &device, CommsInterface port)
Definition: commands_system.cpp:194
mip::commands_system::CommMode::function
FunctionSelector function
Parameters.
Definition: commands_system.hpp:122
mip::commands_system::CommMode::DESCRIPTOR
static constexpr const CompositeDescriptor DESCRIPTOR
Definition: commands_system.hpp:128
mip::commands_system::CommsProtocol::nmea
bool nmea() const
Definition: commands_system.hpp:91
mip::commands_system::CommsProtocol::rtcm
bool rtcm() const
Definition: commands_system.hpp:93
mip::commands_system::InterfaceControl::asTuple
auto asTuple()
Definition: commands_system.hpp:229
mip::commands_system::CommsProtocol::operator&=
CommsProtocol & operator&=(uint32_t val)
Definition: commands_system.hpp:85
mip_interface.hpp
mip::commands_system::CommsProtocol::operator|=
CommsProtocol & operator|=(uint32_t val)
Definition: commands_system.hpp:84
mip::commands_system::InterfaceControl::FIELD_DESCRIPTOR
static constexpr const uint8_t FIELD_DESCRIPTOR
Definition: commands_system.hpp:218
mip::commands_system::CommsProtocol::RTCM
@ RTCM
Definition: commands_system.hpp:73
mip::commands_system::CommsProtocol::MIP_DATA
@ MIP_DATA
Definition: commands_system.hpp:71
mip::commands_system::InterfaceControl::extract
void extract(Serializer &serializer)
Definition: commands_system.cpp:114
mip::commands_system::CommMode::Response::mode
uint8_t mode
Parameters.
Definition: commands_system.hpp:157
mip::commands_system::CommsProtocol::_enumType
_enumType
Definition: commands_system.hpp:67
mip::commands_system::InterfaceControl::Response::HAS_FUNCTION_SELECTOR
static constexpr const bool HAS_FUNCTION_SELECTOR
Definition: commands_system.hpp:259
mip::commands_system::CommsProtocol::Type
uint32_t Type
Definition: commands_system.hpp:66
mip::commands_system::InterfaceControl::protocols_incoming
CommsProtocol protocols_incoming
Input protocol(s) the port will accept. If the protocol supports ACK/NACK or detailed responses,...
Definition: commands_system.hpp:213
mip::commands_system::REPLY_INTERFACE_CONTROL
@ REPLY_INTERFACE_CONTROL
Definition: commands_system.hpp:42
mip::commands_system::InterfaceControl::protocols_outgoing
CommsProtocol protocols_outgoing
Data protocol(s) the port will output.
Definition: commands_system.hpp:214
mip::commands_system::CommsProtocol::spartn
void spartn(bool val)
Definition: commands_system.hpp:96
mip::commands_system::readCommMode
TypedResult< CommMode > readCommMode(C::mip_interface &device, uint8_t *modeOut)
Definition: commands_system.cpp:67
mip::commands_system::CommMode::Response::extract
void extract(Serializer &serializer)
Definition: commands_system.cpp:49
mip::commands_system::CommMode::Response::DESCRIPTOR
static constexpr const CompositeDescriptor DESCRIPTOR
Definition: commands_system.hpp:162
mip::commands_system::InterfaceControl::Response::insert
void insert(Serializer &serializer) const
Serialization.
Definition: commands_system.cpp:129
mip::commands_system::CommMode::DESCRIPTOR_SET
static constexpr const uint8_t DESCRIPTOR_SET
Descriptors.
Definition: commands_system.hpp:126
mip::commands_system::CommMode::Response::DESCRIPTOR_SET
static constexpr const uint8_t DESCRIPTOR_SET
Descriptors.
Definition: commands_system.hpp:160
mip::commands_system::InterfaceControl::DESCRIPTOR
static constexpr const CompositeDescriptor DESCRIPTOR
Definition: commands_system.hpp:219
mip::CompositeDescriptor
Convenience struct holding both descriptor set and field descriptor.
Definition: mip_descriptors.hpp:21
mip::commands_system::loadInterfaceControl
TypedResult< InterfaceControl > loadInterfaceControl(C::mip_interface &device, CommsInterface port)
Definition: commands_system.cpp:206
mip::commands_system::CommsProtocol::rtcm
void rtcm(bool val)
Definition: commands_system.hpp:94
mip::commands_system::DESCRIPTOR_SET
@ DESCRIPTOR_SET
Definition: commands_system.hpp:31
mip::commands_system::CommsProtocol::setAll
void setAll()
Definition: commands_system.hpp:98
mip::commands_system::CommsProtocol::MIP_COMMANDS
@ MIP_COMMANDS
Definition: commands_system.hpp:70
mip::Bitfield
A dummy struct which is used to mark bitfield objects.
Definition: mip_descriptors.hpp:61
mip::commands_system::CommMode
Definition: commands_system.hpp:119
mip::commands_system::InterfaceControl::DESCRIPTOR_SET
static constexpr const uint8_t DESCRIPTOR_SET
Descriptors.
Definition: commands_system.hpp:217
mip::commands_system::InterfaceControl::Response::DOC_NAME
static constexpr const char * DOC_NAME
Definition: commands_system.hpp:258
mip::commands_system::CommsProtocol::spartn
bool spartn() const
Definition: commands_system.hpp:95
mip::TypedResult
A CmdResult that knows the corresponding command type.
Definition: mip_descriptors.hpp:97
common.hpp
mip::commands_system::CommsProtocol::CommsProtocol
CommsProtocol()
Definition: commands_system.hpp:79
mip_result.hpp
mip::commands_system::CommMode::mode
uint8_t mode
Definition: commands_system.hpp:123
mip::commands_system::writeInterfaceControl
TypedResult< InterfaceControl > writeInterfaceControl(C::mip_interface &device, CommsInterface port, CommsProtocol protocolsIncoming, CommsProtocol protocolsOutgoing)
Definition: commands_system.cpp:148
mip::commands_system::CommsProtocol::allSet
bool allSet() const
Definition: commands_system.hpp:97
mip::commands_system::CommsProtocol::mipCommands
void mipCommands(bool val)
Definition: commands_system.hpp:88