MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
mip_cmdqueue.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <stdint.h>
5 
6 #include "mip_types.h"
7 #include "mip_result.h"
8 #include "mip_packet.h"
9 
10 #ifdef __cplusplus
11 namespace mip {
12 namespace C {
13 extern "C" {
14 #endif
15 
23 
24 
29 
37 typedef struct mip_pending_cmd
38 {
39  struct mip_pending_cmd* _next;
40  uint8_t* _response_buffer;
41  union {
42  mip_timeout _extra_timeout;
43  mip_timestamp _timeout_time;
44  mip_timestamp _reply_time;
45  };
46  uint8_t _descriptor_set;
47  uint8_t _field_descriptor;
48  uint8_t _response_descriptor;
49  union {
50  uint8_t _response_buffer_size;
51  uint8_t _response_length;
52  };
53  volatile enum mip_cmd_result _status;
55 
56 void mip_pending_cmd_init(mip_pending_cmd* cmd, uint8_t descriptor_set, uint8_t field_descriptor);
57 void mip_pending_cmd_init_with_timeout(mip_pending_cmd* cmd, uint8_t descriptor_set, uint8_t field_descriptor, mip_timeout additional_time);
58 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);
59 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_size, mip_timeout additional_time);
60 
63 const uint8_t* mip_pending_cmd_response(const mip_pending_cmd* cmd);
65 
68 
78 
88 typedef struct mip_cmd_queue
89 {
90  mip_pending_cmd* _first_pending_cmd;
91  mip_timeout _base_timeout;
92 
93 #ifdef MIP_ENABLE_DIAGNOSTICS
94  uint16_t _diag_cmds_queued;
95  uint16_t _diag_cmds_acked;
96  uint8_t _diag_cmds_nacked;
97  uint8_t _diag_cmds_timedout;
98  uint8_t _diag_cmds_failed;
99 #endif // MIP_ENABLE_DIAGNOSTICS
100 
101 } mip_cmd_queue;
102 
103 void mip_cmd_queue_init(mip_cmd_queue* queue, mip_timeout base_reply_timeout);
106 
108 
109 void mip_cmd_queue_update(mip_cmd_queue* queue, mip_timestamp timestamp);
110 
113 
114 void mip_cmd_queue_process_packet(mip_cmd_queue* queue, const mip_packet_view* packet, mip_timestamp timestamp);
115 
116 
117 #ifdef MIP_ENABLE_DIAGNOSTICS
118 uint16_t mip_cmd_queue_diagnostic_cmds_queued(const mip_cmd_queue* queue);
119 uint16_t mip_cmd_queue_diagnostic_cmds_failed(const mip_cmd_queue* queue);
120 uint16_t mip_cmd_queue_diagnostic_cmds_successful(const mip_cmd_queue* queue);
121 
122 uint16_t mip_cmd_queue_diagnostic_cmd_acks(const mip_cmd_queue* queue);
123 uint16_t mip_cmd_queue_diagnostic_cmd_nacks(const mip_cmd_queue* queue);
124 uint16_t mip_cmd_queue_diagnostic_cmd_timeouts(const mip_cmd_queue* queue);
125 uint16_t mip_cmd_queue_diagnostic_cmd_errors(const mip_cmd_queue* queue);
126 #endif // MIP_ENABLE_DIAGNOSTICS
127 
131 
132 #ifdef __cplusplus
133 } // extern "C"
134 } // namespace C
135 } // namespace mip
136 #endif
mip_packet.h
mip::C::mip_pending_cmd_response
const uint8_t * mip_pending_cmd_response(const mip_pending_cmd *cmd)
Returns the response payload pointer.
Definition: mip_cmdqueue.c:128
mip::C::mip_cmd_queue
struct mip::C::mip_cmd_queue mip_cmd_queue
Holds a list of pending commands.
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip_types.h
mip::C::mip_cmd_queue_process_packet
void mip_cmd_queue_process_packet(mip_cmd_queue *queue, const mip_packet_view *packet, mip_timestamp timestamp)
Process an incoming packet and check for replies to pending commands.
Definition: mip_cmdqueue.c:381
mip::C::mip_cmd_result
mip_cmd_result
Represents the status of a MIP command.
Definition: mip_result.h:27
mip::C::mip_cmd_queue_clear
void mip_cmd_queue_clear(mip_cmd_queue *queue)
Clears the command queue.
Definition: mip_cmdqueue.c:423
mip::C::mip_pending_cmd_check_timeout
bool mip_pending_cmd_check_timeout(const mip_pending_cmd *cmd, mip_timestamp now)
Checks if the command should time out.
Definition: mip_cmdqueue.c:182
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_result.h
mip::C::mip_cmd_queue
Holds a list of pending commands.
Definition: mip_cmdqueue.h:88
mip::C::mip_pending_cmd_remaining_time
int mip_pending_cmd_remaining_time(const mip_pending_cmd *cmd, mip_timestamp now)
Determines how much time is remaining before the command times out.
Definition: mip_cmdqueue.c:164
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
mip::C::mip_cmd_queue_enqueue
void mip_cmd_queue_enqueue(mip_cmd_queue *queue, mip_pending_cmd *cmd)
Queue a command to wait for replies.
Definition: mip_cmdqueue.c:227
mip::C::mip_timeout
microstrain::C::microstrain_embedded_timestamp mip_timeout
Definition: mip_types.h:16
mip::C::mip_pending_cmd
struct mip::C::mip_pending_cmd mip_pending_cmd
Represents a command awaiting a reply from the device.
mip::C::mip_cmd_queue_dequeue
void mip_cmd_queue_dequeue(mip_cmd_queue *queue, mip_pending_cmd *cmd)
Removes a pending command from the queue.
Definition: mip_cmdqueue.c:250
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::C::mip_pending_cmd_status
enum mip_cmd_result mip_pending_cmd_status(const mip_pending_cmd *cmd)
Returns the status of the pending command.
Definition: mip_cmdqueue.c:110
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_pending_cmd_init
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.
Definition: mip_cmdqueue.c:32
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_pending_cmd
Represents a command awaiting a reply from the device.
Definition: mip_cmdqueue.h:37
mip::C::mip_cmd_queue_update
void mip_cmd_queue_update(mip_cmd_queue *queue, mip_timestamp now)
Call periodically to make sure commands time out if no packets are received.
Definition: mip_cmdqueue.c:446
mip::C::mip_pending_cmd_response_descriptor
uint8_t mip_pending_cmd_response_descriptor(const mip_pending_cmd *cmd)
Returns the response descriptor.
Definition: mip_cmdqueue.c:118
mip::C::mip_cmd_queue_init
void mip_cmd_queue_init(mip_cmd_queue *queue, mip_timeout base_reply_timeout)
Initializes a command queue.
Definition: mip_cmdqueue.c:206
mip::C::mip_pending_cmd_init_with_response
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.
Definition: mip_cmdqueue.c:68
mip::C::mip_timestamp
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
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