MIP SDK
0.0.1
MicroStrain Communications Library for embedded systems
|
#include "mip_cmdqueue.h"
#include "mip_field.h"
#include "mip_packet.h"
#include <string.h>
#include <assert.h>
Macros | |
#define | MIP_REPLY_DESC_GLOBAL_ACK_NACK 0xF1 |
#define | MIP_INDEX_REPLY_DESCRIPTOR 0 |
#define | MIP_INDEX_REPLY_ACK_CODE 1 |
Functions | |
void | mip_pending_cmd_init (mip_pending_cmd *cmd, uint8_t descriptor_set, uint8_t field_descriptor) |
Initialize a pending command with no reponse data or additional time. More... | |
void | mip_pending_cmd_init_with_timeout (mip_pending_cmd *cmd, uint8_t descriptor_set, uint8_t field_descriptor, timeout_type additional_time) |
Initialize a pending mip commmand with extra timeout time. More... | |
void | mip_pending_cmd_init_with_response (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) |
Initialize a pending mip commmand with expected response data. More... | |
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, timeout_type additional_time) |
Initialize a pending mip commmand with all parameters. More... | |
enum mip_cmd_result | mip_pending_cmd_status (const mip_pending_cmd *cmd) |
Returns the status of the pending command. More... | |
const uint8_t * | mip_pending_cmd_response (const mip_pending_cmd *cmd) |
Returns the response payload pointer. More... | |
uint8_t | mip_pending_cmd_response_length (const mip_pending_cmd *cmd) |
Returns the length of the response data. More... | |
bool | mip_pending_cmd_check_timeout (const mip_pending_cmd *cmd, timestamp_type now) |
Checks if the command should time out. More... | |
void | mip_cmd_queue_init (mip_cmd_queue *queue, timeout_type base_reply_timeout) |
Initializes a command queue. More... | |
void | mip_cmd_queue_enqueue (mip_cmd_queue *queue, mip_pending_cmd *cmd) |
Queue a command to wait for replies. More... | |
void | mip_cmd_queue_dequeue (mip_cmd_queue *queue, mip_pending_cmd *cmd) |
Removes a pending command from the queue. More... | |
void | mip_cmd_queue_process_packet (mip_cmd_queue *queue, const mip_packet *packet, timestamp_type timestamp) |
Process an incoming packet and check for replies to pending commands. More... | |
void | mip_cmd_queue_clear (mip_cmd_queue *queue) |
Clears the command queue. More... | |
void | mip_cmd_queue_update (mip_cmd_queue *queue, timestamp_type now) |
Call periodically to make sure commands time out if no packets are received. More... | |
void | mip_cmd_queue_set_base_reply_timeout (mip_cmd_queue *queue, timeout_type timeout) |
Sets the base reply timeout for all commands. More... | |
timeout_type | mip_cmd_queue_base_reply_timeout (const mip_cmd_queue *queue) |
Gets the base reply timeout for all commands. More... | |
#define MIP_INDEX_REPLY_ACK_CODE 1 |
#define MIP_INDEX_REPLY_DESCRIPTOR 0 |
#define MIP_REPLY_DESC_GLOBAL_ACK_NACK 0xF1 |
timeout_type mip_cmd_queue_base_reply_timeout | ( | const mip_cmd_queue * | queue | ) |
Gets the base reply timeout for all commands.
void mip_cmd_queue_clear | ( | mip_cmd_queue * | queue | ) |
Clears the command queue.
This must be called from the same thread context as the update function.
queue |
void mip_cmd_queue_dequeue | ( | mip_cmd_queue * | queue, |
mip_pending_cmd * | cmd | ||
) |
Removes a pending command from the queue.
void mip_cmd_queue_enqueue | ( | mip_cmd_queue * | queue, |
mip_pending_cmd * | cmd | ||
) |
Queue a command to wait for replies.
queue | |
cmd | Listens for replies to this command. |
void mip_cmd_queue_init | ( | mip_cmd_queue * | queue, |
timeout_type | base_reply_timeout | ||
) |
Initializes a command queue.
queue | |
base_reply_timeout | The minimum timeout given to all MIP commands. Additional time may be given to specific commands which take longer. This is intended to be used to accommodate long communication latencies, such as when using a TCP connection. |
void mip_cmd_queue_process_packet | ( | mip_cmd_queue * | queue, |
const mip_packet * | packet, | ||
timestamp_type | timestamp | ||
) |
Process an incoming packet and check for replies to pending commands.
Call this from the Mip_parser callback, passing the arguments directly.
queue | |
packet | The received MIP packet. Assumed to be valid. |
timestamp | The time the packet was received |
void mip_cmd_queue_set_base_reply_timeout | ( | mip_cmd_queue * | queue, |
timeout_type | timeout | ||
) |
Sets the base reply timeout for all commands.
THe base reply timeout is the minimum time to wait for a reply.
queue | |
timeout |
void mip_cmd_queue_update | ( | mip_cmd_queue * | queue, |
timestamp_type | now | ||
) |
Call periodically to make sure commands time out if no packets are received.
Call this during the device update if no calls to mip_cmd_queue_process_packet are made (e.g. because no packets were received). It is safe to call this in either case.
queue | |
now |
bool mip_pending_cmd_check_timeout | ( | const mip_pending_cmd * | cmd, |
timestamp_type | now | ||
) |
Checks if the command should time out.
cmd | |
now | Current time |
void mip_pending_cmd_init | ( | mip_pending_cmd * | cmd, |
uint8_t | descriptor_set, | ||
uint8_t | field_descriptor | ||
) |
Initialize a pending command with no reponse data or additional time.
cmd | |
descriptor_set | Command descriptor set. |
field_descriptor | Command field descriptor. |
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, | ||
timeout_type | additional_time | ||
) |
Initialize a pending mip commmand with all parameters.
cmd | |
descriptor_set | Command descriptor set. |
field_descriptor | Command field descriptor. |
response_descriptor | Optional response data descriptor. Use 0x00 if no data is expected. |
response_buffer | Optional buffer to hold response data, if any. If NULL, response_buffer_size must be 0. |
response_buffer_size | Size of the response buffer. The response will be limited to this size. |
additional_time | Additional time on top of the base reply timeout for this specific command. |
void mip_pending_cmd_init_with_response | ( | 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 | ||
) |
Initialize a pending mip commmand with expected response data.
cmd | |
descriptor_set | Command descriptor set. |
field_descriptor | Command field descriptor. |
response_descriptor | Optional response data descriptor. Use 0x00 if no data is expected. |
response_buffer | Optional buffer to hold response data, if any. If NULL, response_buffer_size must be 0. |
response_buffer_size | Optional buffer to hold response data, if any. If NULL, response_buffer_size must be 0. |
response_buffer_size | Size of the response buffer. The response will be limited to this size. |
void mip_pending_cmd_init_with_timeout | ( | mip_pending_cmd * | cmd, |
uint8_t | descriptor_set, | ||
uint8_t | field_descriptor, | ||
timeout_type | additional_time | ||
) |
Initialize a pending mip commmand with extra timeout time.
cmd | |
descriptor_set | Command descriptor set. |
field_descriptor | Command field descriptor. |
additional_time | Additional time on top of the base reply timeout for this specific command. |
const uint8_t* mip_pending_cmd_response | ( | const mip_pending_cmd * | cmd | ) |
Returns the response payload pointer.
This function may only be called after the command finishes with an ACK.
uint8_t mip_pending_cmd_response_length | ( | const mip_pending_cmd * | cmd | ) |
Returns the length of the response data.
This function may only be called after the command finishes. If the command completed with a NACK, or if it timed out, the response length will be zero.
enum mip_cmd_result mip_pending_cmd_status | ( | const mip_pending_cmd * | cmd | ) |
Returns the status of the pending command.