MIP SDK
0.0.1
MicroStrain Communications Library for embedded systems
|
#include "mip_interface.h"
#include "mip_field.h"
#include "definitions/descriptors.h"
#include <assert.h>
#include <stdio.h>
Functions | |
bool | mip_interface_parse_callback (void *device, const mip_packet *packet, timestamp_type timestamp) |
Wrapper around mip_interface_receive_packet for use with mip_parser. More... | |
void | mip_interface_init (mip_interface *device, uint8_t *parse_buffer, size_t parse_buffer_size, timeout_type parse_timeout, timeout_type base_reply_timeout) |
Initialize the mip_interface components. More... | |
void | mip_interface_set_update_function (struct mip_interface *device, mip_update_callback function) |
Sets the update function. More... | |
mip_update_callback | mip_interface_update_function (struct mip_interface *device) |
Gets the update function pointer. More... | |
void | mip_interface_set_user_pointer (mip_interface *device, void *pointer) |
Sets an optional user data pointer which can be retrieved later. More... | |
void * | mip_interface_user_pointer (const mip_interface *device) |
Retrieves the pointer set by mip_interface_set_user_pointer(). More... | |
unsigned int | mip_interface_max_packets_per_update (const mip_interface *device) |
Returns the maximum number of packets to parser per update call. More... | |
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_bytes() function. More... | |
bool | mip_interface_update (struct mip_interface *device, bool blocking) |
Call to process data from the device. More... | |
bool | mip_interface_default_update (struct mip_interface *device, bool blocking) |
Polls the port for new data or command replies. More... | |
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). More... | |
remaining_count | mip_interface_receive_bytes (mip_interface *device, const uint8_t *data, size_t length, timestamp_type timestamp) |
Receive data from the port (i.e. the physical device) into the parser. More... | |
void | mip_interface_process_unparsed_packets (mip_interface *device) |
Process more packets from the internal buffer. More... | |
void | mip_interface_receive_packet (mip_interface *device, const mip_packet *packet, timestamp_type timestamp) |
Processes a pre-parsed packet for command replies and data. More... | |
mip_parser * | mip_interface_parser (mip_interface *device) |
Returns the MIP parser for the device. More... | |
mip_cmd_queue * | mip_interface_cmd_queue (mip_interface *device) |
Returns the commmand queue for the device. More... | |
enum mip_cmd_result | mip_interface_wait_for_reply (mip_interface *device, const mip_pending_cmd *cmd) |
Blocks until the pending command completes or times out. More... | |
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. More... | |
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. More... | |
enum mip_cmd_result | mip_interface_run_command_packet (mip_interface *device, const mip_packet *packet, mip_pending_cmd *cmd) |
Similar to mip_interface_start_command_packet but waits for the command to complete. More... | |
bool | mip_interface_start_command_packet (mip_interface *device, const mip_packet *packet, mip_pending_cmd *cmd) |
Queues the command and sends the packet. Does not wait for completion. More... | |
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. More... | |
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. More... | |
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. More... | |
mip_cmd_queue* mip_interface_cmd_queue | ( | mip_interface * | device | ) |
Returns the commmand queue for the device.
bool mip_interface_default_update | ( | struct mip_interface * | device, |
bool | blocking | ||
) |
Polls the port for new data or command replies.
This is the default choice for the user update function. It ignores the blocking flag and always reads data from the device.
device | The mip_interface object. |
blocking | Ignored. |
void mip_interface_init | ( | mip_interface * | device, |
uint8_t * | parse_buffer, | ||
size_t | parse_buffer_size, | ||
timeout_type | parse_timeout, | ||
timeout_type | base_reply_timeout | ||
) |
Initialize the mip_interface components.
device | |
parse_buffer | A working buffer for the MIP parser. See mip_parser_init(). |
parse_buffer_size | Size of the parsing buffer. Must be at least MIP_PACKET_LENGTH_MAX. |
parse_timeout | Maximum length of time to wait for the end of a MIP packet. See mip_parser_init(). |
base_reply_timeout | Minimum time for all commands. See mip_cmd_queue_init(). |
unsigned int mip_interface_max_packets_per_update | ( | const mip_interface * | device | ) |
Returns the maximum number of packets to parser per update call.
bool mip_interface_parse_callback | ( | void * | device, |
const mip_packet * | packet, | ||
timestamp_type | timestamp | ||
) |
Wrapper around mip_interface_receive_packet for use with mip_parser.
device | Void pointer to the device. Must be a mip_interface pointer. |
packet | MIP Packet from the parser. |
timestamp | timestamp_type of the packet. |
mip_parser* mip_interface_parser | ( | mip_interface * | device | ) |
Returns the MIP parser for the device.
void mip_interface_process_unparsed_packets | ( | mip_interface * | device | ) |
Process more packets from the internal buffer.
This is an alternative to mip_interface_receive_bytes() for the case when no new input data is available and max_packets is nonzero. The timestamp is reused from the last call to receive_bytes.
This function obeys the max_packets_per_update setting.
remaining_count mip_interface_receive_bytes | ( | mip_interface * | device, |
const uint8_t * | data, | ||
size_t | length, | ||
timestamp_type | timestamp | ||
) |
Receive data from the port (i.e. the physical device) into the parser.
device | |
data | Input data buffer. May be NULL if length == 0. |
length | Length of the input buffer. Must be 0 if data is NULL. |
timestamp | Time of the received data. |
void mip_interface_receive_packet | ( | mip_interface * | device, |
const mip_packet * | packet, | ||
timestamp_type | timestamp | ||
) |
Processes a pre-parsed packet for command replies and data.
device | |
packet | The received MIP packet. |
timestamp | timestamp_type of the received MIP packet. |
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.
device | |
handler | An uninitialized mip_dispatch_handler object. This call will initialize it. |
descriptor_set | |
field_descriptor | |
extractor | |
field_ptr |
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.
device | |
handler | An uninitialized mip_dispatch_handler object. This call will initialize it. |
descriptor_set | |
field_descriptor | |
callback | |
user_data |
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.
device | |
handler | An uninitialized mip_dispatch_handler object. This call will initialize it. |
descriptor_set | |
after_fields | |
callback | |
user_data |
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.
device | |
descriptor_set | Command descriptor set. |
cmd_descriptor | Command field descriptor. |
cmd_data | Optional payload data. May be NULL if cmd_length == 0. |
cmd_length | Length of the command payload (parameters). |
enum mip_cmd_result mip_interface_run_command_packet | ( | mip_interface * | device, |
const mip_packet * | packet, | ||
mip_pending_cmd * | cmd | ||
) |
Similar to mip_interface_start_command_packet but waits for the command to complete.
device | |
packet | A MIP packet containing the command. |
cmd | The command status tracker. No lifetime requirement. |
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.
device | |
descriptor_set | Command descriptor set. |
cmd_descriptor | Command field descriptor. |
cmd_data | Optional payload data. May be NULL if cmd_length == 0. |
cmd_length | Length of the command payload (parameters). |
response_descriptor | Descriptor of the response data. May be MIP_INVALID_FIELD_DESCRIPTOR if no response is expected. |
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).
device | The mip_interface object. |
data | Data to be sent. |
length | Length of data. |
This is called whenever bytes must be sent to the physical device.
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_bytes() function.
Use this when receiving data in bursts to smooth out the processing load over time.
device | |
max_packets | Maximum number of packets to parse at once. |
void mip_interface_set_update_function | ( | struct mip_interface * | device, |
mip_update_callback | function | ||
) |
Sets the update function.
By default, the update function is mip_interface_default_update.
device | |
function | Update function to call when polling the device for data. If this is NULL, then update calls will fail and no data or or command replies will be received. |
void mip_interface_set_user_pointer | ( | mip_interface * | device, |
void * | pointer | ||
) |
Sets an optional user data pointer which can be retrieved later.
device | |
pointer |
bool mip_interface_start_command_packet | ( | mip_interface * | device, |
const mip_packet * | packet, | ||
mip_pending_cmd * | cmd | ||
) |
Queues the command and sends the packet. Does not wait for completion.
device | |
packet | A MIP packet containing the command. |
cmd | The command status tracker. Must be valid while the command executes. |
bool mip_interface_update | ( | struct mip_interface * | device, |
bool | blocking | ||
) |
Call to process data from the device.
This function is also called while waiting for command replies.
Call this periodically to process packets received from the device. It should be called at a suitably-high rate to prevent the connection buffers from overflowing. The update rate affects the reception timestamp resolution.
device | |
blocking | This is true when called from within a blocking command function. Applications should generally set this to false, e.g. when calling this to process incoming data packets. |
mip_update_callback mip_interface_update_function | ( | struct mip_interface * | device | ) |
Gets the update function pointer.
void* mip_interface_user_pointer | ( | const mip_interface * | device | ) |
Retrieves the pointer set by mip_interface_set_user_pointer().
device |
enum mip_cmd_result mip_interface_wait_for_reply | ( | mip_interface * | device, |
const mip_pending_cmd * | cmd | ||
) |
Blocks until the pending command completes or times out.
device | |
cmd |