MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
mip_interface.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_cmdqueue.hpp"
4 #include "mip_parser.hpp"
5 
6 #include <mip/mip_descriptors.h>
7 #include <mip/mip_interface.h>
8 
9 #include <assert.h>
10 #include <string>
11 
12 namespace microstrain
13 {
14  class Connection;
15 } // namespace microstrain
16 
17 namespace mip
18 {
22 
23  class Interface;
24 
25  void connect_interface(Interface& dev, microstrain::Connection& conn);
26 
28 
29  struct Dispatcher : public C::mip_dispatcher
30  {
31  enum : uint8_t {
34  };
35 
36  void addHandler(DispatchHandler& handler) { C::mip_dispatcher_add_handler(this, &handler); }
38 
40  };
41 
42  template<class Cmd> CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime=0);
43  template<class Cmd> CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0);
44  template<class Cmd, class... Args> CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime);
45  template<class Cmd> bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, Timeout additionalTime);
46 
50  class Interface : public C::mip_interface
51  {
52  public:
53  //
54  // Constructors
55  //
56 
63  {
64  C::mip_interface_init(this, parseTimeout, baseReplyTimeout, nullptr, nullptr, &C::mip_interface_default_update, nullptr);
65  }
66 
74  Interface(parseTimeout, baseReplyTimeout)
75  {
76  if (connection)
77  connect_interface(*this, *connection);
78  }
79 
80  Interface(const Interface&) = delete;
81  Interface& operator=(const Interface&) = delete;
82 
83  ~Interface() = default;
84 
85  //
86  // Callback functions
87  //
88 
89  // C function callbacks
90 
94 
98 
99  // free/nonmember function callbacks
100 
101  template<bool (*Send)(Interface&, const uint8_t*, size_t)>
102  void setSendFunction();
103 
104  template<bool (*Recv)(Interface&, uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
105  void setRecvFunction();
106 
107  template<bool (*Update)(Interface&, Timeout, bool)>
108  void setUpdateFunction();
109 
110  // derived member function callbacks
111 
112  template<class Derived, bool (Derived::*Send)(const uint8_t*, size_t)>
113  void setSendFunction();
114 
115  template<class Derived, bool (Derived::*Recv)(uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
116  void setRecvFunction();
117 
118  template<class Derived, bool (Derived::*Update)(Timeout, bool)>
119  void setUpdateFunction();
120 
121  // Separate class object callbacks
122 
123  template<
124  class T,
125  bool (T::*Send)(const uint8_t*, size_t),
126  bool (T::*Recv)(Timeout, bool, Timestamp*),
127  bool (T::*Update)(Timeout, bool) = nullptr
128  >
129  void setCallbacks(T* object);
130 
131  //
132  // General accessors
133  //
134 
135  //void setMaxPacketsPerPoll(unsigned int maxPackets) { C::mip_interface_set_max_packets_per_update(this, maxPackets); }
136  //unsigned int maxPacketsPerPoll() const { return C::mip_interface_max_packets_per_update(this); }
137 
140 
141  Parser& parser() { return *static_cast<Parser*>(C::mip_interface_parser(this)); }
142  CmdQueue& cmdQueue() { return *static_cast<CmdQueue*>(C::mip_interface_cmd_queue(this)); }
143 
144  const Parser& parser() const { return const_cast<Interface*>(this)->parser(); }
145  const CmdQueue& cmdQueue() const { return const_cast<Interface*>(this)->cmdQueue(); }
146 
147  //
148  // Communications
149  //
150 
151  bool sendToDevice(const uint8_t* data, size_t length) { return C::mip_interface_send_to_device(this, data, length); }
153  bool recvFromDevice(Timeout wait_time, size_t* length_out, Timestamp* timestamp_out) { return C::mip_interface_recv_from_device(this, wait_time, length_out, timestamp_out); }
154  bool update(Timeout wait_time = 0, bool from_cmd = false) { return C::mip_interface_update(this, wait_time, from_cmd); }
155 
156  bool defaultUpdate(Timeout wait_time = 0, bool from_cmd = false) { return C::mip_interface_default_update(this, wait_time, from_cmd); }
157  void inputBytes(const uint8_t* data, size_t length, Timestamp timestamp) { C::mip_interface_input_bytes(this, data, length, timestamp); }
158  void inputPacket(const C::mip_packet_view& packet, Timestamp timestamp) { C::mip_interface_input_packet(this, &packet, timestamp); }
159 
160 
162 
163  //
164  // Data Callbacks
165  //
166 
167  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); }
168  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); }
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  template<void (*Callback)(void*, const FieldView&, Timestamp)>
177  void registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, void* userData=nullptr);
178 
179  template<class Object, void (Object::*Callback)(const FieldView& field, Timestamp)>
180  void registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, Object* object);
181 
182  template<class DataField, void (*Callback)(void*, const DataField&, Timestamp)>
183  void registerDataCallback(C::mip_dispatch_handler& handler, void* userData=nullptr, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
184 
185  template<class DataField, void (*Callback)(void*, const DataField&, uint8_t, Timestamp)>
186  void registerDataCallback(C::mip_dispatch_handler& handler, void* userData=nullptr, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
187 
188  template<class DataField, class Object, void (Object::*Callback)(const DataField&, Timestamp)>
189  void registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
190 
191  template<class DataField, class Object, void (Object::*Callback)(const DataField&, uint8_t, Timestamp)>
192  void registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
193 
194  template<class DataField>
195  void registerExtractor(C::mip_dispatch_handler& handler, DataField* field, uint8_t descriptorSet=DataField::DESCRIPTOR_SET);
196 
197  //
198  // Run function templates
199  //
200 
201  template<class Cmd>
202  CmdResult runCommand(const Cmd& cmd, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, additionalTime); }
203 
204  template<class Cmd, class... Args>
205  CmdResult runCommand(Args&&... args, Timeout additionalTime=0) { return mip::runCommand(*this, std::forward<Args>(args)..., additionalTime); }
206 
207  template<class Cmd>
208  CmdResult runCommand(const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, response, additionalTime); }
209 
210  template<class Cmd>
211  bool startCommand(PendingCmd& pending, const Cmd& cmd, Timeout additionalTime=0) { return mip::startCommand(*this, pending, cmd, additionalTime); }
212 
213  // template<class Cmd>
214  // bool startCommand(PendingCmd& pending, const Cmd& cmd, uint8_t* responseBuffer, uint8_t responseBufferSize, Timeout additionalTime=0) { return startCommand(pending, cmd, responseBuffer, responseBufferSize, additionalTime); }
215  };
216 
222  template<bool (*Send)(Interface&, const uint8_t*, size_t)>
224  {
225  setSendFunction([](C::mip_interface* device, const uint8_t* data, size_t length)->bool
226  {
227  return (*Send)(*static_cast<Interface*>(device), data, length);
228  });
229  }
230 
236  template<bool (*Recv)(Interface&, uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
238  {
239  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)->bool
240  {
241  return (*Recv)(*static_cast<Interface*>(device), buffer, max_length, wait_time, length_out, timestamp_out);
242  });
243  }
244 
250  template<bool (*Update)(Interface&, Timeout, bool)>
252  {
253  setUpdateFunction([](C::mip_interface* device, C::mip_timeout wait_time, bool from_cmd)->bool
254  {
255  return (*Update)(*static_cast<Interface*>(device), wait_time, from_cmd);
256  });
257  }
258 
280  template<class Derived, bool (Derived::*Send)(const uint8_t*, size_t)>
282  {
283  static_assert(std::is_base_of<C::mip_interface, Derived>::value, "Derived must be derived from C::mip_interface.");
284 
285  setSendFunction([](C::mip_interface* device, const uint8_t* data, size_t length)
286  {
287  return (static_cast<Derived*>(device)->*Send)(data, length);
288  });
289  }
290 
300  template<class Derived, bool (Derived::*Recv)(uint8_t*, size_t, Timeout, size_t*, Timestamp*)>
302  {
303  static_assert(std::is_base_of<C::mip_interface, Derived>::value, "Derived must be derived from C::mip_interface.");
304 
305  setRecvFunction([](C::mip_interface* device, uint8_t* buffer, size_t max_length, Timeout wait_time, size_t* length_out, Timestamp* timestamp_out)
306  {
307  return (static_cast<Derived*>(device)->*Recv)(buffer, max_length, wait_time, length_out, timestamp_out);
308  });
309  }
310 
320  template<class Derived, bool (Derived::*Update)(Timeout, bool)>
322  {
323  static_assert(std::is_base_of<C::mip_interface, Derived>::value, "Derived must be derived from C::mip_interface.");
324 
325  setUpdateFunction([](C::mip_interface* device, C::mip_timeout wait_time, bool from_cmd)->bool
326  {
327  return (static_cast<Derived*>(device)->*Update)(wait_time, from_cmd);
328  });
329  }
330 
368  template<
369  class T,
370  bool (T::*Send)(const uint8_t*, size_t),
371  bool (T::*Recv)(Timeout, bool, Timestamp*),
372  bool (T::*Update)(Timeout, bool)
373  >
374  void Interface::setCallbacks(T* object)
375  {
376  C::mip_send_callback send = [](C::mip_interface* device, const uint8_t* data, size_t size)
377  {
378  return (static_cast<T*>(mip_interface_user_pointer(device))->*Send)(data, size);
379  };
380 
381  C::mip_recv_callback recv = [](C::mip_interface* device, C::mip_timeout wait_time, bool from_cmd, C::mip_timestamp* timestamp_out)
382  {
383  return (static_cast<T*>(mip_interface_user_pointer(device))->*Recv)(wait_time, from_cmd, timestamp_out);
384  };
385 
386  C::mip_update_callback update = [](C::mip_interface* device, C::mip_timeout wait_time, bool from_cmd)
387  {
388  return (static_cast<T*>(mip_interface_user_pointer(device))->*Update)(wait_time, from_cmd);
389  };
390 
391  C::mip_interface_set_user_pointer(this, object);
392  C::mip_interface_set_send_function(this, Send != nullptr ? send : nullptr);
393  C::mip_interface_set_recv_function(this, Recv != nullptr ? recv : nullptr);
394 
395  if (Update != nullptr)
397  else if (Recv != nullptr)
399  else
401  }
402 
436  template<void (*Callback)(void*, const PacketView&, Timestamp)>
437  void Interface::registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, void* userData)
438  {
439  C::mip_dispatch_packet_callback callback = [](void* context, const C::mip_packet_view* packet, Timestamp timestamp)
440  {
441  PacketView packetView(*packet);
442  Callback(context, packetView, timestamp);
443  };
444 
445  registerPacketCallback(handler, descriptorSet, afterFields, callback, userData);
446  }
447 
481  template<class Object, void (Object::*Callback)(const PacketView&, Timestamp)>
482  void Interface::registerPacketCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, bool afterFields, Object* object)
483  {
484  C::mip_dispatch_packet_callback callback = [](void* pointer, const C::mip_packet_view* packet, Timestamp timestamp)->void
485  {
486  PacketView packetView(*packet);
487  Object* obj = static_cast<Object*>(pointer);
488  (obj->*Callback)(packetView, timestamp);
489  };
490 
491  registerPacketCallback(handler, descriptorSet, afterFields, callback, object);
492  }
493 
527  template<void (*Callback)(void*, const FieldView&, Timestamp)>
528  void Interface::registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, void* userData)
529  {
530  C::mip_dispatch_field_callback callback = [](void* context, const C::mip_field_view* field, Timestamp timestamp)
531  {
532  FieldView fieldView(*field);
533  Callback(context, fieldView, timestamp);
534  };
535 
536  registerFieldCallback(handler, descriptorSet, fieldDescriptor, callback, userData);
537  }
538 
572  template<class Object, void (Object::*Callback)(const FieldView&, Timestamp)>
573  void Interface::registerFieldCallback(C::mip_dispatch_handler& handler, uint8_t descriptorSet, uint8_t fieldDescriptor, Object* object)
574  {
575  C::mip_dispatch_field_callback callback = [](void* pointer, const C::mip_field_view* field, Timestamp timestamp)
576  {
577  FieldView fieldView(*field);
578  Object* obj = static_cast<Object*>(pointer);
579  (obj->*Callback)(fieldView, timestamp);
580  };
581 
582  registerFieldCallback(handler, descriptorSet, fieldDescriptor, callback, object);
583  }
584 
620  template<class DataField, void (*Callback)(void*, const DataField&, Timestamp)>
621  void Interface::registerDataCallback(C::mip_dispatch_handler& handler, void* userData, uint8_t descriptorSet)
622  {
623  assert(descriptorSet != 0x00);
624  if (descriptorSet == 0x00)
625  return;
626 
627  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
628  if (descriptorSet == 0xFF)
629  return;
630 
631  C::mip_dispatch_field_callback callback = [](void* context, const C::mip_field_view* field, Timestamp timestamp)
632  {
633  DataField data;
634 
635  bool ok = FieldView(*field).extract(data);
636  assert(ok); (void)ok;
637 
638  Callback(context, data, timestamp);
639  };
640 
641  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, userData);
642  }
643 
679  template<class DataField, void (*Callback)(void*, const DataField&, uint8_t, Timestamp)>
680  void Interface::registerDataCallback(C::mip_dispatch_handler& handler, void* userData, uint8_t descriptorSet)
681  {
682  assert(descriptorSet != 0x00);
683  if (descriptorSet == 0x00)
684  return;
685 
686  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
687  if (descriptorSet == 0xFF)
688  return;
689 
690  C::mip_dispatch_field_callback callback = [](void* context, const C::mip_field_view* field, Timestamp timestamp)
691  {
692  DataField data;
693 
694  bool ok = FieldView(*field).extract(data);
695  assert(ok); (void)ok;
696 
697  Callback(context, data, mip_field_descriptor_set(field), timestamp);
698  };
699 
700  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, userData);
701  }
702 
739  template<class DataField, class Object, void (Object::*Callback)(const DataField&, Timestamp)>
740  void Interface::registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet)
741  {
742  assert(descriptorSet != 0x00);
743  if (descriptorSet == 0x00)
744  return;
745 
746  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
747  if (descriptorSet == 0xFF)
748  return;
749 
750  C::mip_dispatch_field_callback callback = [](void* pointer, const C::mip_field_view* field, Timestamp timestamp)
751  {
752  DataField data;
753 
754  bool ok = FieldView(*field).extract(data);
755  assert(ok); (void)ok;
756 
757  Object* obj = static_cast<Object*>(pointer);
758  (obj->*Callback)(data, timestamp);
759  };
760 
761  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, object);
762  }
763 
800  template<class DataField, class Object, void (Object::*Callback)(const DataField&, uint8_t, Timestamp)>
801  void Interface::registerDataCallback(C::mip_dispatch_handler& handler, Object* object, uint8_t descriptorSet)
802  {
803  assert(descriptorSet != 0x00);
804  if (descriptorSet == 0x00)
805  return;
806 
807  assert(descriptorSet != 0xFF); // Descriptor set must be specified for shared data.
808  if (descriptorSet == 0xFF)
809  return;
810 
811  C::mip_dispatch_field_callback callback = [](void* pointer, const C::mip_field_view* field, Timestamp timestamp)
812  {
813  DataField data;
814 
815  bool ok = FieldView(*field).extract(data);
816  assert(ok); (void)ok;
817 
818  Object* obj = static_cast<Object*>(pointer);
819  (obj->*Callback)(data, mip_field_descriptor_set(field), timestamp);
820  };
821 
822  registerFieldCallback(handler, descriptorSet, DataField::FIELD_DESCRIPTOR, callback, object);
823  }
824 
825  template<class DataField>
826  void Interface::registerExtractor(C::mip_dispatch_handler& handler, DataField* field, uint8_t descriptorSet)
827  {
828  C::mip_dispatch_field_callback 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  template<class Cmd>
837  CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime)
838  {
839  PacketBuf packet(cmd);
840 
841  C::mip_pending_cmd pending;
842  C::mip_pending_cmd_init_with_timeout(&pending, Cmd::DESCRIPTOR_SET, Cmd::FIELD_DESCRIPTOR, additionalTime);
843 
844  return C::mip_interface_run_command_packet(&device, &packet, &pending);
845  }
846 
847  template<class Cmd, class... Args>
848  CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime)
849  {
850  Cmd cmd{std::forward<Args>(args)...};
851  return runCommand(device, cmd, additionalTime);
852  }
853 
854  template<class Cmd>
855  CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime)
856  {
857  PacketBuf packet(cmd);
858 
859  C::mip_pending_cmd pending;
860  C::mip_pending_cmd_init_full(&pending, Cmd::DESCRIPTOR_SET, Cmd::FIELD_DESCRIPTOR, Cmd::Response::FIELD_DESCRIPTOR, packet.buffer(), FIELD_PAYLOAD_LENGTH_MAX, additionalTime);
861 
862  CmdResult result = C::mip_interface_run_command_packet(&device, &packet, &pending);
863  if (result != C::MIP_ACK_OK)
864  return result;
865 
866  size_t responseLength = C::mip_pending_cmd_response_length(&pending);
867 
868  return extract(response, packet.buffer(), responseLength, 0) ? CmdResult::ACK_OK : CmdResult::STATUS_ERROR;
869  }
870 
871  template<class Cmd>
872  bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, Timeout additionalTime)
873  {
874  PacketBuf packet(cmd);
875 
876  C::mip_pending_cmd_init_with_timeout(&pending, Cmd::DESCRIPTOR_SET, Cmd::FIELD_DESCRIPTOR, additionalTime);
877 
878  return C::mip_interface_start_command_packet(&device, &packet, &pending);
879  }
880 
881  //template<class Cmd>
882  //bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, uint8_t* responseBuffer, uint8_t responseBufferSize, Timeout additionalTime)
883  //{
884  // PacketBuf packet(cmd);
885  //
886  // C::mip_pending_cmd_init_full(&pending, Cmd::descriptorSet, Cmd::fieldDescriptor, Cmd::Response::fieldDescriptor, responseBuffer, responseBufferSize, additionalTime);
887  //
888  // return C::mip_interface_start_command_packet(&device, &packet, &pending);
889  //}
890 
893 } // namespace mip
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:621
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
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::Interface::setRecvFunction
void setRecvFunction(C::mip_recv_callback callback)
Definition: mip_interface.hpp:96
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:281
mip::Interface::startCommand
bool startCommand(PendingCmd &pending, const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:211
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:361
mip::C::mip_interface_default_update
bool mip_interface_default_update(struct mip_interface *device, mip_timeout wait_time, bool from_cmd)
Polls the port for new data or command replies.
Definition: mip_interface.c:398
mip::Interface::recvFromDevice
bool recvFromDevice(Timeout wait_time, size_t *length_out, Timestamp *timestamp_out)
Definition: mip_interface.hpp:153
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:245
mip::Interface::Interface
Interface(microstrain::Connection *connection, Timeout parseTimeout, Timeout baseReplyTimeout)
Initialize the mip_interface components.
Definition: mip_interface.hpp:73
mip::Interface::inputBytes
void inputBytes(const uint8_t *data, size_t length, Timestamp timestamp)
Definition: mip_interface.hpp:157
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::Interface::update
bool update(Timeout wait_time=0, bool from_cmd=false)
Definition: mip_interface.hpp:154
mip_parser.hpp
mip::Interface::setSendFunction
void setSendFunction(C::mip_send_callback callback)
Definition: mip_interface.hpp:95
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:197
mip::Interface::setUpdateFunction
void setUpdateFunction(C::mip_update_callback function)
Definition: mip_interface.hpp:97
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:603
mip::Interface::waitForReply
CmdResult waitForReply(C::mip_pending_cmd &cmd)
Definition: mip_interface.hpp:161
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:208
mip::Interface::runCommand
CmdResult runCommand(const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:202
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_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::Interface::defaultUpdate
bool defaultUpdate(Timeout wait_time=0, bool from_cmd=false)
Definition: mip_interface.hpp:156
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:145
mip::C::mip_interface_recv_from_device
bool mip_interface_recv_from_device(mip_interface *device, mip_timeout wait_time, bool from_cmd, mip_timestamp *timestamp_out)
Checks for data at the port and reads it into buffer.
Definition: mip_interface.c:342
mip::C::mip_interface_update
bool mip_interface_update(struct mip_interface *device, mip_timeout wait_time, bool from_cmd)
Call to process data from the device.
Definition: mip_interface.c:372
mip::Dispatcher::removeAllHandlers
void removeAllHandlers()
Definition: mip_interface.hpp:39
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:42
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:257
mip::Dispatcher::addHandler
void addHandler(DispatchHandler &handler)
Definition: mip_interface.hpp:36
mip::Interface::recvFunction
C::mip_recv_callback recvFunction() const
Definition: mip_interface.hpp:92
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:251
mip::C::mip_recv_callback
bool(* mip_recv_callback)(struct mip_interface *device, mip_timeout wait_time, bool from_cmd, mip_timestamp *timestamp_out)
Called from mip_interface_recv_from_device() to receive data from the device port.
Definition: mip_interface.h:37
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:374
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:91
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:303
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::CmdResult
Represents the status of a MIP command.
Definition: mip_result.hpp:24
mip::C::mip_interface_input_bytes
void mip_interface_input_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:425
mip::C::mip_interface_init
void mip_interface_init(mip_interface *device, 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_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:167
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:582
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:168
mip::Interface::parser
const Parser & parser() const
Definition: mip_interface.hpp:144
mip::runCommand
CmdResult runCommand(C::mip_interface &device, const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:837
mip::FieldView
C++ class representing a MIP field.
Definition: mip_field.hpp:25
mip::Dispatcher
Definition: mip_interface.hpp:29
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:323
mip::Interface::parser
Parser & parser()
Definition: mip_interface.hpp:141
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:185
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:289
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:93
mip::Interface::runCommand
CmdResult runCommand(Args &&... args, Timeout additionalTime=0)
Definition: mip_interface.hpp:205
mip::Interface::baseReplyTimeout
Timeout baseReplyTimeout() const
Definition: mip_interface.hpp:138
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:297
mip::Interface::cmdQueue
CmdQueue & cmdQueue()
Definition: mip_interface.hpp:142
mip::Interface::sendToDevice
bool sendToDevice(const C::mip_packet_view &packet)
Definition: mip_interface.hpp:152
mip::Dispatcher::ANY_DATA_SET
@ ANY_DATA_SET
Definition: mip_interface.hpp:32
mip::Interface::setRecvFunction
void setRecvFunction()
Sets the receive callback function (free function version).
Definition: mip_interface.hpp:237
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:212
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:223
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::setBaseReplyTimeout
void setBaseReplyTimeout(Timeout timeout)
Definition: mip_interface.hpp:139
mip::Dispatcher::ANY_DESCRIPTOR
@ ANY_DESCRIPTOR
Definition: mip_interface.hpp:33
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:474
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:224
mip::Interface::inputPacket
void inputPacket(const C::mip_packet_view &packet, Timestamp timestamp)
Definition: mip_interface.hpp:158
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:24
mip::C::mip_timestamp
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
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_update_callback
bool(* mip_update_callback)(struct mip_interface *device, mip_timeout wait_time, bool from_cmd)
Callback function typedef for custom update behavior.
Definition: mip_interface.h:38
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::startCommand
bool startCommand(C::mip_interface &device, C::mip_pending_cmd &pending, const Cmd &cmd, Timeout additionalTime)
Definition: mip_interface.hpp:872
mip::Interface
Represents a connected MIP device.
Definition: mip_interface.hpp:50
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:37
mip::Interface::sendToDevice
bool sendToDevice(const uint8_t *data, size_t length)
Definition: mip_interface.hpp:151
mip::Parser
C++ class representing a MIP parser.
Definition: mip_parser.hpp:19
mip::Interface::Interface
Interface(Timeout parseTimeout, Timeout baseReplyTimeout)
Initialize the mip_interface components.
Definition: mip_interface.hpp:62
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:653
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:630
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:269
mip::CmdQueue
C++ wrapper around a command queue.
Definition: mip_cmdqueue.hpp:20
mip::C::mip_interface_input_packet
void mip_interface_input_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:440