MIP_SDK
v3.0.0
MicroStrain Communications Library for embedded systems
|
Go to the documentation of this file.
99 template<
bool (*Send)(Interface&, const u
int8_t*,
size_t)>
102 template<
bool (*Recv)(Interface&, u
int8_t*,
size_t, Timeout,
size_t*, Timestamp*)>
105 template<
bool (*Update)(Interface&, Timeout)>
110 template<
class Derived,
bool (Derived::*Send)(const u
int8_t*,
size_t)>
113 template<
class Derived,
bool (Derived::*Recv)(u
int8_t*,
size_t, Timeout,
size_t*, Timestamp*)>
116 template<
class Derived,
bool (Derived::*Update)(Timeout)>
123 bool (T::*Send)(
const uint8_t*, size_t),
125 bool (T::*Update)(
Timeout) =
nullptr
170 template<
void (*Callback)(
void*, const PacketView&, Timestamp)>
173 template<
class Object,
void (Object::*Callback)(const PacketView&, Timestamp)>
177 template<
void (*Callback)(
void*, const FieldView&, Timestamp)>
180 template<
class Object,
void (Object::*Callback)(const FieldView& field, Timestamp)>
184 template<
class DataField,
void (*Callback)(
void*, const DataField&, Timestamp)>
187 template<
class DataField,
void (*Callback)(
void*, const DataField&, u
int8_t, Timestamp)>
190 template<
class DataField,
class Object,
void (Object::*Callback)(const DataField&, Timestamp)>
193 template<
class DataField,
class Object,
void (Object::*Callback)(const DataField&, u
int8_t, Timestamp)>
197 template<
class DataField>
207 template<
class Cmd,
class... Args>
228 template<
bool (*Send)(Interface&, const u
int8_t*,
size_t)>
232 return (*Send)(*
static_cast<Interface*
>(device), data, length);
241 template<
bool (*Recv)(Interface&, u
int8_t*,
size_t, Timeout,
size_t*, Timestamp*)>
245 return (*Recv)(*
static_cast<Interface*
>(device), buffer, max_length, wait_time, length_out, timestamp_out);
254 template<
bool (*Update)(Interface&, Timeout)>
258 return (*Update)(*
static_cast<Interface*
>(device), wait_time);
284 template<
class Derived,
bool (Derived::*Send)(const u
int8_t*,
size_t)>
287 static_assert(std::is_base_of<C::mip_interface, Derived>::value,
"Derived must be derived from C::mip_interface.");
292 return (
static_cast<Derived*
>(device)->*Send)(data, length);
305 template<
class Derived,
bool (Derived::*Recv)(u
int8_t*,
size_t, Timeout,
size_t*, Timestamp*)>
308 static_assert(std::is_base_of<C::mip_interface, Derived>::value,
"Derived must be derived from C::mip_interface.");
313 return (
static_cast<Derived*
>(device)->*Recv)(buffer, max_length, wait_time, length_out, timestamp_out);
326 template<
class Derived,
bool (Derived::*Update)(Timeout)>
329 static_assert(std::is_base_of<C::mip_interface, Derived>::value,
"Derived must be derived from C::mip_interface.");
334 return (
static_cast<Derived*
>(device)->*Update)(wait_time);
379 bool (T::*Send)(
const uint8_t*, size_t),
391 return (
static_cast<T*
>(
mip_interface_user_pointer(device))->*Recv)(buffer, max_length, wait_time, length_out, timestamp_out);
402 if( Update !=
nullptr )
404 else if( Recv !=
nullptr )
441 template<
void (*Callback)(
void*, const PacketView&, Timestamp)>
447 Callback(context, packetView, timestamp);
484 template<
class Object,
void (Object::*Callback)(const PacketView&, Timestamp)>
490 Object* obj =
static_cast<Object*
>(pointer);
491 (obj->*Callback)(packetView, timestamp);
528 template<
void (*Callback)(
void*, const FieldView&, Timestamp)>
534 Callback(context, fieldView, timestamp);
571 template<
class Object,
void (Object::*Callback)(const FieldView&, Timestamp)>
577 Object* obj =
static_cast<Object*
>(pointer);
578 (obj->*Callback)(fieldView, timestamp);
619 template<
class DataField,
void (*Callback)(
void*, const DataField&, Timestamp)>
622 assert(descriptorSet != 0x00);
623 if(descriptorSet == 0x00)
626 assert(descriptorSet != 0xFF);
627 if(descriptorSet == 0xFF)
635 assert(ok); (void)ok;
637 Callback(context, data, timestamp);
678 template<
class DataField,
void (*Callback)(
void*, const DataField&, u
int8_t, Timestamp)>
681 assert(descriptorSet != 0x00);
682 if(descriptorSet == 0x00)
685 assert(descriptorSet != 0xFF);
686 if(descriptorSet == 0xFF)
694 assert(ok); (void)ok;
738 template<
class DataField,
class Object,
void (Object::*Callback)(const DataField&, Timestamp)>
741 assert(descriptorSet != 0x00);
742 if(descriptorSet == 0x00)
745 assert(descriptorSet != 0xFF);
746 if(descriptorSet == 0xFF)
754 assert(ok); (void)ok;
756 Object* obj =
static_cast<Object*
>(pointer);
757 (obj->*Callback)(data, timestamp);
799 template<
class DataField,
class Object,
void (Object::*Callback)(const DataField&, u
int8_t, Timestamp)>
802 assert(descriptorSet != 0x00);
803 if(descriptorSet == 0x00)
806 assert(descriptorSet != 0xFF);
807 if(descriptorSet == 0xFF)
815 assert(ok); (void)ok;
817 Object* obj =
static_cast<Object*
>(pointer);
825 template<
class DataField>
848 template<
class Cmd,
class... Args>
851 Cmd cmd{std::forward<Args>(args)...};
852 return runCommand(device, cmd, additionalTime);
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
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
size_t receiveBytes(const uint8_t *data, size_t length, Timestamp timestamp)
Definition: mip_interface.hpp:156
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_DISPATCH_ANY_DATA_SET
Definition: mip_dispatch.h:70
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
Interface(uint8_t *parseBuffer, size_t parseBufferSize, Timeout parseTimeout, Timeout baseReplyTimeout)
Initialize the mip_interface components.
Definition: mip_interface.hpp:64
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
bool mip_interface_update(struct mip_interface *device, mip_timeout wait_time)
Call to process data from the device.
Definition: mip_interface.c:398
void setRecvFunction(C::mip_recv_callback callback)
Definition: mip_interface.hpp:94
void * mip_interface_user_pointer(const mip_interface *device)
Retrieves the pointer set by mip_interface_set_user_pointer().
Definition: mip_interface.c:282
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
bool startCommand(PendingCmd &pending, const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:215
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_DISPATCH_ANY_DESCRIPTOR
Definition: mip_dispatch.h:74
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
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
void mip_interface_process_unparsed_packets(mip_interface *device)
Process more packets from the internal buffer.
Definition: mip_interface.c:477
void mip_interface_set_update_function(mip_interface *device, mip_update_callback callback)
Sets the update function.
Definition: mip_interface.c:246
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
void setSendFunction(C::mip_send_callback callback)
Definition: mip_interface.hpp:93
mip_send_callback mip_interface_send_function(const mip_interface *device)
Gets the send function pointer.
Definition: mip_interface.c:198
void setUpdateFunction(C::mip_update_callback function)
Definition: mip_interface.hpp:95
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
bool update(Timeout wait_time=0)
Definition: mip_interface.hpp:153
CmdResult waitForReply(C::mip_pending_cmd &cmd)
Definition: mip_interface.hpp:160
bool extract(FieldType &field, bool exact_size=true) const
Deserializes the field data to specific field struct.
Definition: mip_field.hpp:87
CmdResult runCommand(const Cmd &cmd, typename Cmd::Response &response, Timeout additionalTime=0)
Definition: mip_interface.hpp:211
CmdResult runCommand(const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:205
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
bool(* mip_update_callback)(struct mip_interface *device, mip_timeout timeout)
Callback function typedef for custom update behavior.
Definition: mip_interface.h:38
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
void registerExtractor(C::mip_dispatch_handler &handler, DataField *field, uint8_t descriptorSet=DataField::DESCRIPTOR_SET)
Definition: mip_interface.hpp:826
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
struct mip::C::mip_interface mip_interface
State of the interface for communicating with a MIP device.
Interface & operator=(const Interface &)=delete
static constexpr C::mip_cmd_result STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.hpp:27
const CmdQueue & cmdQueue() const
Definition: mip_interface.hpp:144
void removeAllHandlers()
Definition: mip_interface.hpp:42
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_update_callback mip_interface_update_function(const mip_interface *device)
Gets the update function pointer.
Definition: mip_interface.c:258
void addHandler(DispatchHandler &handler)
Definition: mip_interface.hpp:39
C::mip_recv_callback recvFunction() const
Definition: mip_interface.hpp:90
Structure representing a MIP Packet.
Definition: mip_packet.h:50
Holds the state of the MIP dispatch system.
Definition: mip_dispatch.h:130
void setUpdateFunction()
Sets the update callback function (free function version).
Definition: mip_interface.hpp:255
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
microstrain::C::microstrain_embedded_timestamp mip_timeout
Definition: mip_types.h:16
void setCallbacks(T *object)
Sets the callback functions to a common class object.
Definition: mip_interface.hpp:383
struct mip::C::mip_dispatch_handler mip_dispatch_handler
Handler information for MIP Packet or Field callbacks.
C::mip_send_callback sendFunction() const
Definition: mip_interface.hpp:89
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
void mip_dispatcher_add_handler(mip_dispatcher *self, mip_dispatch_handler *handler)
Registers a handler in the dispatch system.
Definition: mip_dispatch.c:189
struct mip::C::mip_pending_cmd mip_pending_cmd
Represents a command awaiting a reply from the device.
A mip packet with a self-contained buffer (useful with std::vector).
Definition: mip_packet.hpp:290
C++ class representing the state of a MIP command.
Definition: mip_cmdqueue.hpp:46
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
A structure representing a MIP field.
Definition: mip_field.h:52
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
Represents the status of a MIP command.
Definition: mip_result.hpp:24
uint8_t mip_pending_cmd_response_length(const mip_pending_cmd *cmd)
Returns the length of the response data.
Definition: mip_cmdqueue.c:142
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
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
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
const Parser & parser() const
Definition: mip_interface.hpp:143
CmdResult runCommand(C::mip_interface &device, const Cmd &cmd, Timeout additionalTime=0)
Definition: mip_interface.hpp:838
C++ class representing a MIP field.
Definition: mip_field.hpp:25
void processUnparsedPackets()
Definition: mip_interface.hpp:158
Definition: mip_interface.hpp:32
unsigned int maxPacketsPerPoll() const
Definition: mip_interface.hpp:134
State of the interface for communicating with a MIP device.
Definition: mip_interface.h:44
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
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
Parser & parser()
Definition: mip_interface.hpp:140
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
void mip_interface_set_send_function(mip_interface *device, mip_send_callback callback)
Sets the send callback function.
Definition: mip_interface.c:186
microstrain::EmbeddedTimestamp Timestamp
Definition: mip_types.h:50
mip_parser * mip_interface_parser(mip_interface *device)
Returns the MIP parser for the device.
Definition: mip_interface.c:320
Represents a command awaiting a reply from the device.
Definition: mip_cmdqueue.h:37
C::mip_update_callback updateFunction() const
Definition: mip_interface.hpp:91
CmdResult runCommand(Args &&... args, Timeout additionalTime=0)
Definition: mip_interface.hpp:208
Timeout baseReplyTimeout() const
Definition: mip_interface.hpp:136
mip_cmd_queue * mip_interface_cmd_queue(mip_interface *device)
Returns the commmand queue for the device.
Definition: mip_interface.c:328
CmdQueue & cmdQueue()
Definition: mip_interface.hpp:141
bool sendToDevice(const C::mip_packet_view &packet)
Definition: mip_interface.hpp:151
@ ANY_DATA_SET
Definition: mip_interface.hpp:35
void setRecvFunction()
Sets the receive callback function (free function version).
Definition: mip_interface.hpp:242
void mip_interface_set_recv_function(mip_interface *device, mip_recv_callback callback)
Sets the receive callback function.
Definition: mip_interface.c:213
static constexpr C::mip_cmd_result ACK_OK
Command completed successfully.
Definition: mip_result.hpp:34
void setSendFunction()
Sets the send callback function (free function version).
Definition: mip_interface.hpp:229
microstrain::EmbeddedTimeout Timeout
Definition: mip_types.h:51
@ MIP_ACK_OK
Command completed successfully.
Definition: mip_result.h:40
void receivePacket(const C::mip_packet_view &packet, Timestamp timestamp)
Definition: mip_interface.hpp:157
void setBaseReplyTimeout(Timeout timeout)
Definition: mip_interface.hpp:137
@ ANY_DESCRIPTOR
Definition: mip_interface.hpp:36
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_recv_callback mip_interface_recv_function(const mip_interface *device)
Gets the receive function pointer.
Definition: mip_interface.c:225
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
Handler information for MIP Packet or Field callbacks.
Definition: mip_dispatch.h:94
Represents a type of connection.
Definition: connection.hpp:25
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
Interface(microstrain::Connection *connection, uint8_t *parseBuffer, size_t parseBufferSize, Timeout parseTimeout, Timeout baseReplyTimeout)
Initialize the mip_interface components.
Definition: mip_interface.hpp:71
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
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
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
bool startCommand(C::mip_interface &device, C::mip_pending_cmd &pending, const Cmd &cmd, Timeout additionalTime)
Definition: mip_interface.hpp:874
bool recvFromDevice(uint8_t *buffer, size_t max_length, Timeout wait_time, size_t *length_out, Timestamp *timestamp)
Definition: mip_interface.hpp:152
Represents a connected MIP device.
Definition: mip_interface.hpp:55
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:35
void removeHandler(DispatchHandler &handler)
Definition: mip_interface.hpp:40
bool sendToDevice(const uint8_t *data, size_t length)
Definition: mip_interface.hpp:150
C++ class representing a MIP parser.
Definition: mip_parser.hpp:19
void setMaxPacketsPerPoll(unsigned int maxPackets)
Definition: mip_interface.hpp:133
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
Definition: embedded_time.h:8
void mip_dispatcher_remove_all_handlers(mip_dispatcher *self)
Removes all handlers from the dispatcher.
Definition: mip_dispatch.c:239
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
size_t extract(Serializer &serializer, Vector< T, N > &v)
Definition: common.hpp:133
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
C++ wrapper around a command queue.
Definition: mip_cmdqueue.hpp:20
bool defaultUpdate(Timeout wait_time=0)
Definition: mip_interface.hpp:154