MIP_SDK  v3.0.0-187-g93c7302
MicroStrain Communications Library for embedded systems
mip_interface.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_parser.h"
4 #include "mip_cmdqueue.h"
5 #include "mip_dispatch.h"
6 
7 #include <stdint.h>
8 #include <stddef.h>
9 
10 #ifdef __cplusplus
11 namespace mip {
12 namespace C {
13 extern "C" {
14 #endif
15 
32 
33 struct mip_interface;
34 
35 // Documentation is in source file.
36 typedef bool (*mip_send_callback)(struct mip_interface* device, const uint8_t* data, size_t length);
37 typedef bool (*mip_recv_callback)(struct mip_interface* device, uint8_t* buffer, size_t max_length, mip_timeout wait_time, bool from_cmd, size_t* length_out, mip_timestamp* timestamp_out);
38 typedef bool (*mip_update_callback)(struct mip_interface* device, mip_timeout wait_time, bool from_cmd);
39 
40 
44 typedef struct mip_interface
45 {
46  mip_parser _parser;
47  mip_cmd_queue _queue;
48  mip_dispatcher _dispatcher;
49  mip_send_callback _send_callback;
50  mip_recv_callback _recv_callback;
51  mip_update_callback _update_callback;
52  void* _user_pointer;
54 
55 
57  mip_interface* device,
58  mip_timeout parse_timeout, mip_timeout base_reply_timeout,
60  mip_update_callback update, void* user_pointer
61 );
62 
63 //
64 // Communications
65 //
66 
67 bool mip_interface_send_to_device(mip_interface* device, const uint8_t* data, size_t length);
68 bool mip_interface_recv_from_device(mip_interface* device, uint8_t* buffer, size_t max_length, mip_timeout wait_time, bool from_cmd, size_t* length_out, mip_timestamp* timestamp_out);
69 bool mip_interface_update(mip_interface* device, mip_timeout wait_time, bool from_cmd);
70 
71 bool mip_interface_default_update(mip_interface* device, mip_timeout wait_time, bool from_cmd);
72 bool mip_interface_default_update_ext_buffer(mip_interface* device, mip_timeout wait_time, bool from_cmd, uint8_t* buffer, size_t buffer_size);
73 void mip_interface_input_bytes_andor_time(mip_interface* device, const uint8_t* received_data, size_t data_length, mip_timestamp now);
74 
75 void mip_interface_input_bytes_from_device(mip_interface* device, const uint8_t* data, size_t length, mip_timestamp timestamp);
78 
79 void mip_interface_parse_callback(void* device, const mip_packet_view* packet, mip_timestamp timestamp);
80 
81 //
82 // Commands
83 //
84 
86 enum mip_cmd_result mip_interface_run_command(mip_interface* device, uint8_t descriptor_set, uint8_t field_descriptor, const uint8_t* payload, uint8_t payload_length);
87 enum mip_cmd_result mip_interface_run_command_with_response(mip_interface* device, uint8_t descriptor_set, uint8_t field_descriptor, const uint8_t* payload, uint8_t payload_length, uint8_t response_descriptor, uint8_t* response_data, uint8_t* response_length_inout);
89 
91 
92 //
93 // Data Callbacks
94 //
95 
96 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);
97 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);
98 void mip_interface_register_extractor(mip_interface* device, mip_dispatch_handler* handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_extractor callback, void* field_ptr);
99 
100 //
101 // Accessors
102 //
103 
107 void mip_interface_set_user_pointer(mip_interface* device, void* pointer);
108 
112 void* mip_interface_user_pointer(const mip_interface* device);
113 
116 
119 
120 #ifdef __cplusplus
121 } // extern "C"
122 } // namespace C
123 } // namespace mip
124 #endif
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_parser.h
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::C::mip_interface_default_update
bool mip_interface_default_update(mip_interface *device, mip_timeout wait_time, bool from_cmd)
Polls the port for new data or command replies.
Definition: mip_interface.c:404
mip_dispatch.h
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::C::mip_interface_update
bool mip_interface_update(mip_interface *device, mip_timeout wait_time, bool from_cmd)
Call to process data from the device.
Definition: mip_interface.c:372
mip::C::mip_cmd_result
mip_cmd_result
Represents the status of a MIP command.
Definition: mip_result.h:27
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::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, bool from_cmd, size_t *length_out, mip_timestamp *timestamp_out)
Checks for data at the port and reads it into buffer.
Definition: mip_interface.c:342
mip_cmdqueue.h
mip::C::mip_interface_input_bytes_from_device
void mip_interface_input_bytes_from_device(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:495
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:690
mip::C::mip_interface_run_command_with_response
enum mip_cmd_result mip_interface_run_command_with_response(mip_interface *device, uint8_t descriptor_set, uint8_t cmd_descriptor, const uint8_t *cmd_data, uint8_t cmd_length, uint8_t response_descriptor, uint8_t *response_buffer, uint8_t *response_length_inout)
Runs a command using a pre-serialized payload.
Definition: mip_interface.c:634
mip::C::mip_interface_update_time
void mip_interface_update_time(mip_interface *device, mip_timestamp timestamp)
Call this to ensure that pending commands time out properly.
Definition: mip_interface.c:528
mip::C::mip_interface
struct mip::C::mip_interface mip_interface
State of the interface for communicating with a MIP device.
mip::C::mip_interface_parse_callback
void mip_interface_parse_callback(void *device, const mip_packet_view *packet, mip_timestamp timestamp)
Wrapper around mip_interface_input_packet_from_device for use with mip_parser.
Definition: mip_interface.c:540
mip::C::mip_cmd_queue
Holds a list of pending commands.
Definition: mip_cmdqueue.h:88
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::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::C::mip_interface_input_bytes_andor_time
void mip_interface_input_bytes_andor_time(mip_interface *device, const uint8_t *received_data, size_t data_length, mip_timestamp now)
This function takes care of processing received data and updating the current time.
Definition: mip_interface.c:473
mip::C::mip_timeout
microstrain::C::microstrain_embedded_timestamp mip_timeout
Definition: mip_types.h:16
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_interface_default_update_ext_buffer
bool mip_interface_default_update_ext_buffer(mip_interface *device, mip_timeout wait_time, bool from_cmd, uint8_t *buffer, size_t buffer_size)
Polls the port for new data or command replies using a supplied buffer.
Definition: mip_interface.c:446
mip::C::mip_parser
MIP Parser state.
Definition: mip_parser.h:53
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_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:669
mip::C::mip_recv_callback
bool(* mip_recv_callback)(struct mip_interface *device, uint8_t *buffer, size_t max_length, mip_timeout wait_time, bool from_cmd, 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::C::mip_interface
State of the interface for communicating with a MIP device.
Definition: mip_interface.h:44
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::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::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::C::mip_interface_run_command
enum mip_cmd_result mip_interface_run_command(mip_interface *device, uint8_t descriptor_set, uint8_t cmd_descriptor, const uint8_t *cmd_data, uint8_t cmd_length)
Runs a command using a pre-serialized payload.
Definition: mip_interface.c:605
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::C::mip_interface_input_packet_from_device
void mip_interface_input_packet_from_device(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:510
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::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:561
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::C::mip_dispatch_handler
Handler information for MIP Packet or Field callbacks.
Definition: mip_dispatch.h:94
mip::C::mip_timestamp
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
mip::C::mip_dispatch_extractor
bool(* mip_dispatch_extractor)(const mip_field_view *field, void *ptr)
Signature for extraction callbacks.
Definition: mip_dispatch.h:62
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_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:740
mip::C::mip_interface_register_extractor
void mip_interface_register_extractor(mip_interface *device, mip_dispatch_handler *handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_extractor extractor, void *field_ptr)
Registers a callback for packets of the specified descriptor set.
Definition: mip_interface.c:762
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:717
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