MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
mip_interface.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_parser.hpp"
4 #include "mip_cmdqueue.hpp"
5 
6 #include <mip/mip_interface.h>
7 #include <mip/mip_descriptors.h>
8 
9 #include <assert.h>
10 #include <string>
11 
12 
13 namespace microstrain
14 {
15  class Connection;
16 }
17 
18 namespace mip
19 {
23 
24 class Interface;
25 
27 
28 
29 
31 
33 {
34  enum : uint8_t {
37  };
38 
39  void addHandler(DispatchHandler& handler) { C::mip_dispatcher_add_handler(this, &handler); }
41 
43 };
44 
45 
46 template<class Cmd> CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime=0);
47 template<class Cmd> CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0);
48 template<class Cmd, class... Args> CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime);
49 template<class Cmd> bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, Timeout additionalTime);
50 
51 
56 {
57 public:
58  //
59  // Constructors
60  //
61 
64  Interface(uint8_t* parseBuffer, size_t parseBufferSize, Timeout parseTimeout, Timeout baseReplyTimeout)
65  {
66  C::mip_interface_init(this, parseBuffer, parseBufferSize, parseTimeout, baseReplyTimeout, nullptr, nullptr, &C::mip_interface_default_update, nullptr);
67  }
68 
71  Interface(microstrain::Connection* connection, uint8_t* parseBuffer, size_t parseBufferSize, Timeout parseTimeout, Timeout baseReplyTimeout) :
72  Interface(parseBuffer, parseBufferSize, parseTimeout, baseReplyTimeout)
73  {
74  if(connection)
75  connect_interface(*this, *connection);
76  }
77 
78  Interface(const Interface&) = delete;
79  Interface& operator=(const Interface&) = delete;
80 
81  ~Interface() = default;
82 
83  //
84  // Callback functions
85  //
86 
87  // C function callbacks
88 
92 
96 
97  // free/nonmember function callbacks
98 
99  template<bool (*Send)(Interface&, const uint8_t*, size_t)>
100  void setSendFunction();
101 
102  template<bool (*Recv)(Interface&, uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
103  void setRecvFunction();
104 
105  template<bool (*Update)(Interface&, Timeout)>
106  void setUpdateFunction();
107 
108  // derived member function callbacks
109 
110  template<class Derived, bool (Derived::*Send)(const uint8_t*, size_t)>
111  void setSendFunction();
112 
113  template<class Derived, bool (Derived::*Recv)(uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
114  void setRecvFunction();
115 
116  template<class Derived, bool (Derived::*Update)(Timeout)>
117  void setUpdateFunction();
118 
119  // Separate class object callbacks
120 
121  template<
122  class T,
123  bool (T::*Send)(const uint8_t*, size_t),
124  bool (T::*Recv)(uint8_t*, size_t, Timeout, size_t*, Timestamp*),
125  bool (T::*Update)(Timeout) = nullptr
126  >
127  void setCallbacks(T* object);
128 
129  //
130  // General accessors
131  //
132 
133  void setMaxPacketsPerPoll(unsigned int maxPackets) { C::mip_interface_set_max_packets_per_update(this, maxPackets); }
134  unsigned int maxPacketsPerPoll() const { return C::mip_interface_max_packets_per_update(this); }
135 
138 
139 
140  Parser& parser() { return *static_cast<Parser*>(C::mip_interface_parser(this)); }
141  CmdQueue& cmdQueue() { return *static_cast<CmdQueue*>(C::mip_interface_cmd_queue(this)); }
142 
143  const Parser& parser() const { return const_cast<Interface*>(this)->parser(); }
144  const CmdQueue& cmdQueue() const { return const_cast<Interface*>(this)->cmdQueue(); }
145 
146  //
147  // Communications
148  //
149 
150  bool sendToDevice(const uint8_t* data, size_t length) { return C::mip_interface_send_to_device(this, data, length); }
152  bool recvFromDevice(uint8_t* buffer, size_t max_length, Timeout wait_time, size_t* length_out, Timestamp* timestamp) { return C::mip_interface_recv_from_device(this, buffer, max_length, wait_time, length_out, timestamp); }
153  bool update(Timeout wait_time=0) { return C::mip_interface_update(this, wait_time); }
154  bool defaultUpdate(Timeout wait_time=0) { return C::mip_interface_default_update(this, wait_time); }
155 
156  size_t receiveBytes(const uint8_t* data, size_t length, Timestamp timestamp) { return C::mip_interface_receive_bytes(this, data, length, timestamp); }
157  void receivePacket(const C::mip_packet_view& packet, Timestamp timestamp) { C::mip_interface_receive_packet(this, &packet, timestamp); }
159 
161 
162  //
163  // Data Callbacks
164  //
165 
166  void registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, C::mip_dispatch_packet_callback callback, void* userData) { C::mip_interface_register_packet_callback(this, &handler, descriptorSet, afterFields, callback, userData); }
167  void registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, C::mip_dispatch_field_callback callback, void* userData) { C::mip_interface_register_field_callback(this, &handler, descriptorSet, fieldDescriptor, callback, userData); }
168 
169 
170  template<void (*Callback)(void*, const PacketView&, Timestamp)>
171  void registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, void* userData=nullptr);
172 
173  template<class Object, void (Object::*Callback)(const PacketView&, Timestamp)>
174  void registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, Object* object);
175 
176 
177  template<void (*Callback)(void*, const FieldView&, Timestamp)>
178  void registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, void* userData=nullptr);
179 
180  template<class Object, void (Object::*Callback)(const FieldView& field, Timestamp)>
181  void registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, Object* object);
182 
183 
184  template<class DataField, void (*Callback)(void*, const DataField&, Timestamp)>
185  void registerDataCallback(C::mip_dispatch_handler& handler, void* userData=nullptr, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
186 
187  template<class DataField, void (*Callback)(void*, const DataField&, uint8_t, Timestamp)>
188  void registerDataCallback(C::mip_dispatch_handler& handler, void* userData=nullptr, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
189 
190  template<class DataField, class Object, void (Object::*Callback)(const DataField&, Timestamp)>
191  void registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
192 
193  template<class DataField, class Object, void (Object::*Callback)(const DataField&, uint8_t, Timestamp)>
194  void registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
195 
196 
197  template<class DataField>
198  void registerExtractor(C::mip_dispatch_handler& handler, DataField* field, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
199 
200  //
201  // Run function templates
202  //
203 
204  template<class Cmd>
205  CmdResult runCommand(const Cmd& cmd, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, additionalTime); }
206 
207  template<class Cmd, class... Args>
208  CmdResult runCommand(Args&&... args, Timeout additionalTime=0) { return mip::runCommand(*this, std::forward<Args>(args)..., additionalTime); }
209 
210  template<class Cmd>
211  CmdResult runCommand(const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, response, additionalTime); }
212 
213 
214  template<class Cmd>
215  bool startCommand(PendingCmd& pending, const Cmd& cmd, Timeout additionalTime=0) { return mip::startCommand(*this, pending, cmd, additionalTime); }
216 
217 // template<class Cmd>
218 // bool startCommand(PendingCmd& pending, const Cmd& cmd, uint8_t* responseBuffer, uint8_t responseBufferSize, Timeout additionalTime=0) { return mip::startCommand(pending, cmd, responseBuffer, responseBufferSize, additionalTime); }
219 };
220 
221 
222 
228 template<bool (*Send)(Interface&, const uint8_t*, size_t)>
230 {
231  setSendFunction([](C::mip_interface* device, const uint8_t* data, size_t length){
232  return (*Send)(*static_cast<Interface*>(device), data, length);
233  });
234 }
235 
241 template<bool (*Recv)(Interface&, uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
243 {
244  setRecvFunction([](C::mip_interface* device, uint8_t* buffer, size_t max_length, C::mip_timeout wait_time, size_t* length_out, C::mip_timestamp* timestamp_out){
245  return (*Recv)(*static_cast<Interface*>(device), buffer, max_length, wait_time, length_out, timestamp_out);
246  });
247 }
248 
254 template<bool (*Update)(Interface&, Timeout)>
256 {
257  setUpdateFunction([](C::mip_interface* device, C::mip_timeout wait_time){
258  return (*Update)(*static_cast<Interface*>(device), wait_time);
259  });
260 }
261 
262 
283 
284 template<class Derived, bool (Derived::*Send)(const uint8_t*, size_t)>
286 {
287  static_assert(std::is_base_of<C::mip_interface, Derived>::value, "Derived must be derived from C::mip_interface.");
288 
290  [](C::mip_interface* device, const uint8_t* data, size_t length)
291  {
292  return (static_cast<Derived*>(device)->*Send)(data, length);
293  }
294  );
295 }
296 
305 template<class Derived, bool (Derived::*Recv)(uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
307 {
308  static_assert(std::is_base_of<C::mip_interface, Derived>::value, "Derived must be derived from C::mip_interface.");
309 
311  [](C::mip_interface* device, uint8_t* buffer, size_t max_length, Timeout wait_time, size_t* length_out, Timestamp* timestamp_out)
312  {
313  return (static_cast<Derived*>(device)->*Recv)(buffer, max_length, wait_time, length_out, timestamp_out);
314  }
315  );
316 }
317 
326 template<class Derived, bool (Derived::*Update)(Timeout)>
328 {
329  static_assert(std::is_base_of<C::mip_interface, Derived>::value, "Derived must be derived from C::mip_interface.");
330 
332  [](C::mip_interface* device, C::mip_timeout wait_time)->bool
333  {
334  return (static_cast<Derived*>(device)->*Update)(wait_time);
335  }
336  );
337 }
338 
339 
377 template<
378  class T,
379  bool (T::*Send)(const uint8_t*, size_t),
380  bool (T::*Recv)(uint8_t*, size_t, Timeout, size_t*, Timestamp*),
381  bool (T::*Update)(Timeout)
382 >
383 void Interface::setCallbacks(T* object)
384 {
385  auto send = [](C::mip_interface* device, const uint8_t* data, size_t size)
386  {
387  return (static_cast<T*>(mip_interface_user_pointer(device))->*Send)(data, size);
388  };
389  auto recv = [](C::mip_interface* device, uint8_t* buffer, size_t max_length, C::mip_timeout wait_time, size_t* length_out, C::mip_timestamp* timestamp_out)
390  {
391  return (static_cast<T*>(mip_interface_user_pointer(device))->*Recv)(buffer, max_length, wait_time, length_out, timestamp_out);
392  };
393  auto update = [](C::mip_interface* device, C::mip_timeout wait_time)
394  {
395  return (static_cast<T*>(mip_interface_user_pointer(device))->*Update)(wait_time);
396  };
397 
398  C::mip_interface_set_user_pointer(this, object);
399  C::mip_interface_set_send_function(this, Send != nullptr ? send : nullptr);
400  C::mip_interface_set_recv_function(this, Recv != nullptr ? recv : nullptr);
401 
402  if( Update != nullptr )
404  else if( Recv != nullptr )
406  else
408 }
409 
410 
441 template<void (*Callback)(void*, const PacketView&, Timestamp)>
442 void Interface::registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, void* userData)
443 {
444  auto callback = [](void* context, const C::mip_packet_view* packet, Timestamp timestamp)
445  {
446  PacketView packetView(*packet);
447  Callback(context, packetView, timestamp);
448  };
449 
450  registerPacketCallback(handler, descriptorSet, afterFields, callback, userData);
451 }
452 
453 
484 template<class Object, void (Object::*Callback)(const PacketView&, Timestamp)>
485 void Interface::registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, Object* object)
486 {
487  auto callback = [](void* pointer, const mip::C::mip_packet_view* packet, Timestamp timestamp)
488  {
489  PacketView packetView(*packet);
490  Object* obj = static_cast<Object*>(pointer);
491  (obj->*Callback)(packetView, timestamp);
492  };
493 
494  registerPacketCallback(handler, descriptorSet, afterFields, callback, object);
495 }
496 
497 
528 template<void (*Callback)(void*, const FieldView&, Timestamp)>
529 void Interface::registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, void* userData)
530 {
531  auto callback = [](void* context, const C::mip_field_view* field, Timestamp timestamp)
532  {
533  FieldView fieldView(*field);
534  Callback(context, fieldView, timestamp);
535  };
536 
537  registerFieldCallback(handler, descriptorSet, fieldDescriptor, callback, userData);
538 }
539 
540 
571 template<class Object, void (Object::*Callback)(const FieldView&, Timestamp)>
572 void Interface::registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, Object* object)
573 {
574  auto callback = [](void* pointer, const C::mip_field_view* field, Timestamp timestamp)
575  {
576  FieldView fieldView(*field);
577  Object* obj = static_cast<Object*>(pointer);
578  (obj->*Callback)(fieldView, timestamp);
579  };
580 
581  registerFieldCallback(handler, descriptorSet, fieldDescriptor, callback, object);
582 }
583 
619 template<class DataField, void (*Callback)(void*, const DataField&, Timestamp)>
620 void Interface::registerDataCallback(C::mip_dispatch_handler& handler, void* userData, uint8_t descriptorSet)
621 {
622  assert(descriptorSet != 0x00);
623  if(descriptorSet == 0x00)
624  return;
625 
626  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
627  if(descriptorSet == 0xFF)
628  return;
629 
630  auto callback = [](void* context, const C::mip_field_view* field, Timestamp timestamp)
631  {
632  DataField data;
633 
634  bool ok = FieldView(*field).extract(data);
635  assert(ok); (void)ok;
636 
637  Callback(context, data, timestamp);
638  };
639 
640  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, userData);
641 }
642 
678 template<class DataField, void (*Callback)(void*, const DataField&, uint8_t, Timestamp)>
679 void Interface::registerDataCallback(C::mip_dispatch_handler& handler, void* userData, uint8_t descriptorSet)
680 {
681  assert(descriptorSet != 0x00);
682  if(descriptorSet == 0x00)
683  return;
684 
685  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
686  if(descriptorSet == 0xFF)
687  return;
688 
689  auto callback = [](void* context, const C::mip_field_view* field, Timestamp timestamp)
690  {
691  DataField data;
692 
693  bool ok = FieldView(*field).extract(data);
694  assert(ok); (void)ok;
695 
696  Callback(context, data, mip_field_descriptor_set(field), timestamp);
697  };
698 
699  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, userData);
700 }
701 
738 template<class DataField, class Object, void (Object::*Callback)(const DataField&, Timestamp)>
739 void Interface::registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet)
740 {
741  assert(descriptorSet != 0x00);
742  if(descriptorSet == 0x00)
743  return;
744 
745  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
746  if(descriptorSet == 0xFF)
747  return;
748 
749  auto callback = [](void* pointer, const C::mip_field_view* field, Timestamp timestamp)
750  {
751  DataField data;
752 
753  bool ok = FieldView(*field).extract(data);
754  assert(ok); (void)ok;
755 
756  Object* obj = static_cast<Object*>(pointer);
757  (obj->*Callback)(data, timestamp);
758  };
759 
760  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, object);
761 }
762 
799 template<class DataField, class Object, void (Object::*Callback)(const DataField&, uint8_t, Timestamp)>
800 void Interface::registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet)
801 {
802  assert(descriptorSet != 0x00);
803  if(descriptorSet == 0x00)
804  return;
805 
806  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
807  if(descriptorSet == 0xFF)
808  return;
809 
810  auto callback = [](void* pointer, const C::mip_field_view* field, Timestamp timestamp)
811  {
812  DataField data;
813 
814  bool ok = FieldView(*field).extract(data);
815  assert(ok); (void)ok;
816 
817  Object* obj = static_cast<Object*>(pointer);
818  (obj->*Callback)(data, mip_field_descriptor_set(field), timestamp);
819  };
820 
821  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, object);
822 }
823 
824 
825 template<class DataField>
826 void Interface::registerExtractor(C::mip_dispatch_handler& handler, DataField* field, uint8_t descriptorSet)
827 {
828  auto callback = [](void* pointer, const C::mip_field_view* field, Timestamp /*timestamp*/)
829  {
830  FieldView(*field).extract( *static_cast<DataField*>(pointer) );
831  };
832 
833  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, field);
834 }
835 
836 
837 template<class Cmd>
838 CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime)
839 {
840  PacketBuf packet(cmd);
841 
842  C::mip_pending_cmd pending;
843  C::mip_pending_cmd_init_with_timeout(&pending, Cmd::DESCRIPTOR_SET, Cmd::FIELD_DESCRIPTOR, additionalTime);
844 
845  return C::mip_interface_run_command_packet(&device, &packet, &pending);
846 }
847 
848 template<class Cmd, class... Args>
849 CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime)
850 {
851  Cmd cmd{std::forward<Args>(args)...};
852  return runCommand(device, cmd, additionalTime);
853 }
854 
855 template<class Cmd>
856 CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime)
857 {
858  PacketBuf packet(cmd);
859 
860  C::mip_pending_cmd pending;
861  C::mip_pending_cmd_init_full(&pending, Cmd::DESCRIPTOR_SET, Cmd::FIELD_DESCRIPTOR, Cmd::Response::FIELD_DESCRIPTOR, packet.buffer(), FIELD_PAYLOAD_LENGTH_MAX, additionalTime);
862 
863  CmdResult result = C::mip_interface_run_command_packet(&device, &packet, &pending);
864  if( result != C::MIP_ACK_OK )
865  return result;
866 
867  size_t responseLength = C::mip_pending_cmd_response_length(&pending);
868 
869  return extract(response, packet.buffer(), responseLength, 0) ? CmdResult::ACK_OK : CmdResult::STATUS_ERROR;
870 }
871 
872 
873 template<class Cmd>
874 bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, Timeout additionalTime)
875 {
876  PacketBuf packet(cmd);
877 
878  C::mip_pending_cmd_init_with_timeout(&pending, Cmd::DESCRIPTOR_SET, Cmd::FIELD_DESCRIPTOR, additionalTime);
879 
880  return C::mip_interface_start_command_packet(&device, &packet, &pending);
881 }
882 
883 //template<class Cmd>
884 //bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, uint8_t* responseBuffer, uint8_t responseBufferSize, Timeout additionalTime)
885 //{
886 // PacketBuf packet(cmd);
887 //
888 // C::mip_pending_cmd_init_full(&pending, Cmd::descriptorSet, Cmd::fieldDescriptor, Cmd::Response::fieldDescriptor, responseBuffer, responseBufferSize, additionalTime);
889 //
890 // return C::mip_interface_start_command_packet(&device, &packet, &pending);
891 //}
892 
893 
896 } // namespace mip
mip::C::mip_interface_receive_bytes
size_t mip_interface_receive_bytes(mip_interface *device, const uint8_t *data, size_t length, mip_timestamp timestamp)
Passes data from the device into the parser.
Definition: mip_interface.c:460
mip::C::mip_interface_receive_packet
void mip_interface_receive_packet(mip_interface *device, const mip_packet_view *packet, mip_timestamp timestamp)
Processes a pre-parsed packet for command replies and data.
Definition: mip_interface.c:492
mip::Interface::receiveBytes
size_t receiveBytes(const uint8_t *data, size_t length, Timestamp timestamp)
Definition: mip_interface.hpp:156
mip::Interface::registerDataCallback
void registerDataCallback(C::mip_dispatch_handler &handler, void *userData=nullptr, uint8_t descriptorSet=DataField::DESCRIPTOR_SET)
Registers a data callback (free function version).
Definition: mip_interface.hpp:620
mip::C::MIP_DISPATCH_ANY_DATA_SET
@ MIP_DISPATCH_ANY_DATA_SET
Definition: mip_dispatch.h:70
mip::C::mip_dispatch_field_callback
void(* mip_dispatch_field_callback)(void *context, const mip_field_view *field, mip_timestamp timestamp)
Signature for field-level callbacks.
Definition: mip_dispatch.h:54
mip::Interface::Interface
Interface(uint8_t *parseBuffer, size_t parseBufferSize, Timeout parseTimeout, Timeout baseReplyTimeout)
Initialize the mip_interface components.
Definition: mip_interface.hpp:64
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::C::mip_interface_update
bool mip_interface_update(struct mip_interface *device, mip_timeout wait_time)
Call to process data from the device.
Definition: mip_interface.c:398
mip::Interface::setRecvFunction
void setRecvFunction(C::mip_recv_callback callback)
Definition: mip_interface.hpp:94
mip::C::mip_interface_user_pointer
void * mip_interface_user_pointer(const mip_interface *device)
Retrieves the pointer set by mip_interface_set_user_pointer().
Definition: mip_interface.c:282
mip::C::mip_interface_max_packets_per_update
unsigned int mip_interface_max_packets_per_update(const mip_interface *device)
Returns the maximum number of packets to parser per update call.
Definition: mip_interface.c:291
mip::Interface::startCommand
bool startCommand(PendingCmd &pending, const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:215
mip::C::mip_dispatcher_remove_handler
void mip_dispatcher_remove_handler(mip_dispatcher *self, mip_dispatch_handler *handler)
Removes a handler from the dispatch system.
Definition: mip_dispatch.c:210
mip::C::MIP_DISPATCH_ANY_DESCRIPTOR
@ MIP_DISPATCH_ANY_DESCRIPTOR
Definition: mip_dispatch.h:74
mip::SizedPacketBuf::buffer
uint8_t * buffer()
Returns a pointer to the underlying buffer. This is technically the same as PacketRef::pointer but is...
Definition: mip_packet.hpp:348
mip::C::mip_interface_init
void mip_interface_init(mip_interface *device, uint8_t *parse_buffer, size_t parse_buffer_size, mip_timeout parse_timeout, mip_timeout base_reply_timeout, mip_send_callback send, mip_recv_callback recv, mip_update_callback update, void *user_pointer)
Initialize the mip_interface components.
Definition: mip_interface.c:150
mip::C::mip_interface_process_unparsed_packets
void mip_interface_process_unparsed_packets(mip_interface *device)
Process more packets from the internal buffer.
Definition: mip_interface.c:477
mip::C::mip_interface_set_update_function
void mip_interface_set_update_function(mip_interface *device, mip_update_callback callback)
Sets the update function.
Definition: mip_interface.c:246
mip::C::mip_field_descriptor_set
uint8_t mip_field_descriptor_set(const mip_field_view *field)
Returns the descriptor set of the packet containing this field._.
Definition: mip_field.c:50
mip_parser.hpp
mip::Interface::setSendFunction
void setSendFunction(C::mip_send_callback callback)
Definition: mip_interface.hpp:93
mip::C::mip_interface_send_function
mip_send_callback mip_interface_send_function(const mip_interface *device)
Gets the send function pointer.
Definition: mip_interface.c:198
mip::Interface::setUpdateFunction
void setUpdateFunction(C::mip_update_callback function)
Definition: mip_interface.hpp:95
mip::C::mip_interface_start_command_packet
bool mip_interface_start_command_packet(mip_interface *device, const mip_packet_view *packet, mip_pending_cmd *cmd)
Queues the command and sends the packet. Does not wait for completion.
Definition: mip_interface.c:659
mip::Interface::update
bool update(Timeout wait_time=0)
Definition: mip_interface.hpp:153
mip::Interface::waitForReply
CmdResult waitForReply(C::mip_pending_cmd &cmd)
Definition: mip_interface.hpp:160
mip::FieldView::extract
bool extract(FieldType &field, bool exact_size=true) const
Deserializes the field data to specific field struct.
Definition: mip_field.hpp:87
mip::Interface::runCommand
CmdResult runCommand(const Cmd &cmd, typename Cmd::Response &response, Timeout additionalTime=0)
Definition: mip_interface.hpp:211
mip::Interface::runCommand
CmdResult runCommand(const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:205
mip::C::mip_packet_pointer
const uint8_t * mip_packet_pointer(const mip_packet_view *packet)
Returns a pointer to the data buffer containing the packet.
Definition: mip_packet.c:129
mip::C::mip_update_callback
bool(* mip_update_callback)(struct mip_interface *device, mip_timeout timeout)
Callback function typedef for custom update behavior.
Definition: mip_interface.h:38
mip::C::mip_packet_total_length
uint_least16_t mip_packet_total_length(const mip_packet_view *packet)
Returns the total length of the packet, in bytes.
Definition: mip_packet.c:113
mip::Interface::registerExtractor
void registerExtractor(C::mip_dispatch_handler &handler, DataField *field, uint8_t descriptorSet=DataField::DESCRIPTOR_SET)
Definition: mip_interface.hpp:826
mip::C::mip_cmd_queue_base_reply_timeout
mip_timeout mip_cmd_queue_base_reply_timeout(const mip_cmd_queue *queue)
Gets the base reply timeout for all commands.
Definition: mip_cmdqueue.c:493
mip::C::mip_interface
struct mip::C::mip_interface mip_interface
State of the interface for communicating with a MIP device.
mip::Interface::operator=
Interface & operator=(const Interface &)=delete
mip::CmdResult::STATUS_ERROR
static constexpr C::mip_cmd_result STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.hpp:27
mip::Interface::cmdQueue
const CmdQueue & cmdQueue() const
Definition: mip_interface.hpp:144
mip::Dispatcher::removeAllHandlers
void removeAllHandlers()
Definition: mip_interface.hpp:42
mip::connect_interface
void connect_interface(mip::Interface &device, microstrain::Connection &conn)
Sets up the mip interface callbacks to point at this object.
Definition: mip_interface.cpp:38
mip::C::mip_interface_update_function
mip_update_callback mip_interface_update_function(const mip_interface *device)
Gets the update function pointer.
Definition: mip_interface.c:258
mip::Dispatcher::addHandler
void addHandler(DispatchHandler &handler)
Definition: mip_interface.hpp:39
mip::Interface::recvFunction
C::mip_recv_callback recvFunction() const
Definition: mip_interface.hpp:90
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
mip::C::mip_dispatcher
Holds the state of the MIP dispatch system.
Definition: mip_dispatch.h:130
mip_cmdqueue.hpp
mip::Interface::setUpdateFunction
void setUpdateFunction()
Sets the update callback function (free function version).
Definition: mip_interface.hpp:255
mip::C::mip_interface_set_max_packets_per_update
void mip_interface_set_max_packets_per_update(mip_interface *device, unsigned int max_packets)
Sets a limit on the number of packets which can be processed in one call to the mip_interface_receive...
Definition: mip_interface.c:311
mip::C::mip_timeout
microstrain::C::microstrain_embedded_timestamp mip_timeout
Definition: mip_types.h:16
mip::Interface::setCallbacks
void setCallbacks(T *object)
Sets the callback functions to a common class object.
Definition: mip_interface.hpp:383
mip::C::mip_dispatch_handler
struct mip::C::mip_dispatch_handler mip_dispatch_handler
Handler information for MIP Packet or Field callbacks.
mip::Interface::sendFunction
C::mip_send_callback sendFunction() const
Definition: mip_interface.hpp:89
mip::C::mip_dispatch_packet_callback
void(* mip_dispatch_packet_callback)(void *context, const mip_packet_view *packet, mip_timestamp timestamp)
Signature for packet-level callbacks.
Definition: mip_dispatch.h:45
mip::C::mip_dispatcher_add_handler
void mip_dispatcher_add_handler(mip_dispatcher *self, mip_dispatch_handler *handler)
Registers a handler in the dispatch system.
Definition: mip_dispatch.c:189
mip::C::mip_pending_cmd
struct mip::C::mip_pending_cmd mip_pending_cmd
Represents a command awaiting a reply from the device.
mip::SizedPacketBuf
A mip packet with a self-contained buffer (useful with std::vector).
Definition: mip_packet.hpp:290
mip::PendingCmd
C++ class representing the state of a MIP command.
Definition: mip_cmdqueue.hpp:46
mip::commands_3dm::DESCRIPTOR_SET
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
mip::Interface::~Interface
~Interface()=default
mip::C::mip_field_view
A structure representing a MIP field.
Definition: mip_field.h:52
mip::C::mip_recv_callback
bool(* mip_recv_callback)(struct mip_interface *device, uint8_t *buffer, size_t max_length, mip_timeout wait_time, size_t *length_out, mip_timestamp *timestamp_out)
Called from mip_interface_recv_from_device() to receive data from the device port.
Definition: mip_interface.h:37
mip::CmdResult
Represents the status of a MIP command.
Definition: mip_result.hpp:24
mip::C::mip_pending_cmd_response_length
uint8_t mip_pending_cmd_response_length(const mip_pending_cmd *cmd)
Returns the length of the response data.
Definition: mip_cmdqueue.c:142
mip::Interface::registerPacketCallback
void registerPacketCallback(C::mip_dispatch_handler &handler, uint8_t descriptorSet, bool afterFields, C::mip_dispatch_packet_callback callback, void *userData)
Definition: mip_interface.hpp:166
mip::C::mip_interface_run_command_packet
enum mip_cmd_result mip_interface_run_command_packet(mip_interface *device, const mip_packet_view *packet, mip_pending_cmd *cmd)
Similar to mip_interface_start_command_packet but waits for the command to complete.
Definition: mip_interface.c:638
mip::Interface::registerFieldCallback
void registerFieldCallback(C::mip_dispatch_handler &handler, uint8_t descriptorSet, uint8_t fieldDescriptor, C::mip_dispatch_field_callback callback, void *userData)
Definition: mip_interface.hpp:167
mip::Interface::parser
const Parser & parser() const
Definition: mip_interface.hpp:143
mip::runCommand
CmdResult runCommand(C::mip_interface &device, const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:838
mip::FieldView
C++ class representing a MIP field.
Definition: mip_field.hpp:25
mip::Interface::processUnparsedPackets
void processUnparsedPackets()
Definition: mip_interface.hpp:158
mip::Dispatcher
Definition: mip_interface.hpp:32
mip::Interface::maxPacketsPerPoll
unsigned int maxPacketsPerPoll() const
Definition: mip_interface.hpp:134
mip::C::mip_interface
State of the interface for communicating with a MIP device.
Definition: mip_interface.h:44
mip::C::mip_pending_cmd_init_full
void mip_pending_cmd_init_full(mip_pending_cmd *cmd, uint8_t descriptor_set, uint8_t field_descriptor, uint8_t response_descriptor, uint8_t *response_buffer, uint8_t response_buffer_size, mip_timeout additional_time)
Initialize a pending mip commmand with all parameters.
Definition: mip_cmdqueue.c:90
mip::C::mip_interface_send_to_device
bool mip_interface_send_to_device(mip_interface *device, const uint8_t *data, size_t length)
Sends data to the port (i.e. from this library to the physical device).
Definition: mip_interface.c:354
mip::Interface::parser
Parser & parser()
Definition: mip_interface.hpp:140
mip::C::mip_cmd_queue_set_base_reply_timeout
void mip_cmd_queue_set_base_reply_timeout(mip_cmd_queue *queue, mip_timeout timeout)
Sets the base reply timeout for all commands.
Definition: mip_cmdqueue.c:483
mip::C::mip_interface_set_send_function
void mip_interface_set_send_function(mip_interface *device, mip_send_callback callback)
Sets the send callback function.
Definition: mip_interface.c:186
mip::Timestamp
microstrain::EmbeddedTimestamp Timestamp
Definition: mip_types.h:50
mip::C::mip_interface_parser
mip_parser * mip_interface_parser(mip_interface *device)
Returns the MIP parser for the device.
Definition: mip_interface.c:320
mip::C::mip_pending_cmd
Represents a command awaiting a reply from the device.
Definition: mip_cmdqueue.h:37
mip_interface.h
mip::Interface::updateFunction
C::mip_update_callback updateFunction() const
Definition: mip_interface.hpp:91
mip::Interface::runCommand
CmdResult runCommand(Args &&... args, Timeout additionalTime=0)
Definition: mip_interface.hpp:208
mip::Interface::baseReplyTimeout
Timeout baseReplyTimeout() const
Definition: mip_interface.hpp:136
mip::C::mip_interface_cmd_queue
mip_cmd_queue * mip_interface_cmd_queue(mip_interface *device)
Returns the commmand queue for the device.
Definition: mip_interface.c:328
mip::Interface::cmdQueue
CmdQueue & cmdQueue()
Definition: mip_interface.hpp:141
mip::Interface::sendToDevice
bool sendToDevice(const C::mip_packet_view &packet)
Definition: mip_interface.hpp:151
mip::Dispatcher::ANY_DATA_SET
@ ANY_DATA_SET
Definition: mip_interface.hpp:35
mip::Interface::setRecvFunction
void setRecvFunction()
Sets the receive callback function (free function version).
Definition: mip_interface.hpp:242
mip::C::mip_interface_set_recv_function
void mip_interface_set_recv_function(mip_interface *device, mip_recv_callback callback)
Sets the receive callback function.
Definition: mip_interface.c:213
mip::CmdResult::ACK_OK
static constexpr C::mip_cmd_result ACK_OK
Command completed successfully.
Definition: mip_result.hpp:34
mip::Interface::setSendFunction
void setSendFunction()
Sets the send callback function (free function version).
Definition: mip_interface.hpp:229
mip::Timeout
microstrain::EmbeddedTimeout Timeout
Definition: mip_types.h:51
mip_descriptors.h
mip::C::MIP_ACK_OK
@ MIP_ACK_OK
Command completed successfully.
Definition: mip_result.h:40
mip::Interface::receivePacket
void receivePacket(const C::mip_packet_view &packet, Timestamp timestamp)
Definition: mip_interface.hpp:157
mip::Interface::setBaseReplyTimeout
void setBaseReplyTimeout(Timeout timeout)
Definition: mip_interface.hpp:137
mip::Dispatcher::ANY_DESCRIPTOR
@ ANY_DESCRIPTOR
Definition: mip_interface.hpp:36
mip::C::mip_interface_wait_for_reply
enum mip_cmd_result mip_interface_wait_for_reply(mip_interface *device, mip_pending_cmd *cmd)
Blocks until the pending command completes or times out.
Definition: mip_interface.c:530
mip::C::mip_interface_recv_function
mip_recv_callback mip_interface_recv_function(const mip_interface *device)
Gets the receive function pointer.
Definition: mip_interface.c:225
mip::C::mip_interface_default_update
bool mip_interface_default_update(struct mip_interface *device, mip_timeout wait_time)
Polls the port for new data or command replies.
Definition: mip_interface.c:421
mip::C::mip_dispatch_handler
Handler information for MIP Packet or Field callbacks.
Definition: mip_dispatch.h:94
microstrain::Connection
Represents a type of connection.
Definition: connection.hpp:25
mip::C::mip_timestamp
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
mip::Interface::Interface
Interface(microstrain::Connection *connection, uint8_t *parseBuffer, size_t parseBufferSize, Timeout parseTimeout, Timeout baseReplyTimeout)
Initialize the mip_interface components.
Definition: mip_interface.hpp:71
mip::C::mip_send_callback
bool(* mip_send_callback)(struct mip_interface *device, const uint8_t *data, size_t length)
Called from mip_interface_send_to_device() to send data to the device port. The application should fo...
Definition: mip_interface.h:36
mip::C::mip_pending_cmd_init_with_timeout
void mip_pending_cmd_init_with_timeout(mip_pending_cmd *cmd, uint8_t descriptor_set, uint8_t field_descriptor, mip_timeout additional_time)
Initialize a pending mip commmand with extra timeout time.
Definition: mip_cmdqueue.c:48
mip::C::mip_interface_recv_from_device
bool mip_interface_recv_from_device(mip_interface *device, uint8_t *buffer, size_t max_length, mip_timeout wait_time, size_t *length_out, mip_timestamp *timestamp_out)
Checks for data at the port and reads it into buffer.
Definition: mip_interface.c:373
mip::startCommand
bool startCommand(C::mip_interface &device, C::mip_pending_cmd &pending, const Cmd &cmd, Timeout additionalTime)
Definition: mip_interface.hpp:874
mip::Interface::recvFromDevice
bool recvFromDevice(uint8_t *buffer, size_t max_length, Timeout wait_time, size_t *length_out, Timestamp *timestamp)
Definition: mip_interface.hpp:152
mip::Interface
Represents a connected MIP device.
Definition: mip_interface.hpp:55
mip::PacketView
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:35
mip::Dispatcher::removeHandler
void removeHandler(DispatchHandler &handler)
Definition: mip_interface.hpp:40
mip::Interface::sendToDevice
bool sendToDevice(const uint8_t *data, size_t length)
Definition: mip_interface.hpp:150
mip::Parser
C++ class representing a MIP parser.
Definition: mip_parser.hpp:19
mip::Interface::setMaxPacketsPerPoll
void setMaxPacketsPerPoll(unsigned int maxPackets)
Definition: mip_interface.hpp:133
mip::C::mip_interface_register_field_callback
void mip_interface_register_field_callback(mip_interface *device, mip_dispatch_handler *handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_field_callback callback, void *user_data)
Registers a callback for packets of the specified descriptor set.
Definition: mip_interface.c:709
microstrain
Definition: embedded_time.h:8
mip::C::mip_dispatcher_remove_all_handlers
void mip_dispatcher_remove_all_handlers(mip_dispatcher *self)
Removes all handlers from the dispatcher.
Definition: mip_dispatch.c:239
mip::C::mip_interface_register_packet_callback
void mip_interface_register_packet_callback(mip_interface *device, mip_dispatch_handler *handler, uint8_t descriptor_set, bool after_fields, mip_dispatch_packet_callback callback, void *user_data)
Registers a callback for packets of the specified descriptor set.
Definition: mip_interface.c:686
mip::extract
size_t extract(Serializer &serializer, Vector< T, N > &v)
Definition: common.hpp:133
mip::C::mip_interface_set_user_pointer
void mip_interface_set_user_pointer(mip_interface *device, void *pointer)
Sets an optional user data pointer which can be retrieved later.
Definition: mip_interface.c:270
mip::CmdQueue
C++ wrapper around a command queue.
Definition: mip_cmdqueue.hpp:20
mip::Interface::defaultUpdate
bool defaultUpdate(Timeout wait_time=0)
Definition: mip_interface.hpp:154