mip_result.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdbool.h>
4 #include <stdint.h>
5 
6 #ifdef __cplusplus
7 namespace mip {
8 namespace C {
9 extern "C" {
10 #endif // __cplusplus
11 
12 
16 
25 typedef enum mip_cmd_result
26 {
28 
29  // Status codes < 0
36 
37  // Device replies >= 0
38  MIP_ACK_OK = 0x00,
45 
46 const char* mip_cmd_result_to_string(enum mip_cmd_result result);
47 
49 
50 bool mip_cmd_result_is_reply(enum mip_cmd_result result);
52 bool mip_cmd_result_is_user(enum mip_cmd_result result);
53 
54 bool mip_cmd_result_is_ack(enum mip_cmd_result result);
55 
58 
59 #ifdef __cplusplus
60 } // extern "C"
61 } // namespace C
62 
66 
71 // member functions and some operator overloads.
79 struct CmdResult
80 {
81  static constexpr C::mip_cmd_result STATUS_USER = C::MIP_STATUS_USER_START;
82  static constexpr C::mip_cmd_result STATUS_ERROR = C::MIP_STATUS_ERROR;
83  static constexpr C::mip_cmd_result STATUS_CANCELLED = C::MIP_STATUS_CANCELLED;
84  static constexpr C::mip_cmd_result STATUS_TIMEDOUT = C::MIP_STATUS_TIMEDOUT;
85  static constexpr C::mip_cmd_result STATUS_WAITING = C::MIP_STATUS_WAITING;
86  static constexpr C::mip_cmd_result STATUS_QUEUED = C::MIP_STATUS_PENDING;
87  static constexpr C::mip_cmd_result STATUS_NONE = C::MIP_STATUS_NONE;
88 
89  static constexpr C::mip_cmd_result ACK_OK = C::MIP_ACK_OK;
90  static constexpr C::mip_cmd_result NACK_COMMAND_UNKNOWN = C::MIP_NACK_COMMAND_UNKNOWN;
91  static constexpr C::mip_cmd_result NACK_INVALID_CHECKSUM = C::MIP_NACK_INVALID_CHECKSUM;
92  static constexpr C::mip_cmd_result NACK_INVALID_PARAM = C::MIP_NACK_INVALID_PARAM;
93  static constexpr C::mip_cmd_result NACK_COMMAND_FAILED = C::MIP_NACK_COMMAND_FAILED;
94  static constexpr C::mip_cmd_result NACK_COMMAND_TIMEOUT = C::MIP_NACK_COMMAND_TIMEOUT;
95 
96 #ifndef _WIN32 // Avoid name conflict with windows.h
97  static constexpr C::mip_cmd_result STATUS_PENDING = STATUS_QUEUED;
98 #endif
99 
101 
102  constexpr CmdResult() : value(C::MIP_ACK_OK) {}
103  constexpr CmdResult(C::mip_cmd_result result) : value(result) {}
104  ~CmdResult() = default;
105 
106  CmdResult& operator=(const CmdResult& other) = default;
107  CmdResult& operator=(C::mip_cmd_result other) { value = other; return *this; }
108 
109  static constexpr CmdResult userResult(uint8_t n) { return CmdResult(static_cast<C::mip_cmd_result>(STATUS_USER - int8_t(n))); }
110  static constexpr CmdResult fromAckNack(uint8_t code) { return CmdResult(static_cast<C::mip_cmd_result>(code)); }
111 
112  operator const void*() const { return isAck() ? this : nullptr; }
113  bool operator!() const { return !isAck(); }
114 
115  constexpr bool operator==(CmdResult other) const { return value == other.value; }
116  constexpr bool operator!=(CmdResult other) const { return value != other.value; }
117 
118  constexpr bool operator==(C::mip_cmd_result other) const { return value == other; }
119  constexpr bool operator!=(C::mip_cmd_result other) const { return value != other; }
120 
121  const char* name() const { return C::mip_cmd_result_to_string(value); }
122 
123  bool isReplyCode() const { return C::mip_cmd_result_is_reply(value); }
124  bool isStatusCode() const { return C::mip_cmd_result_is_status(value); }
125  bool isFinished() const { return C::mip_cmd_result_is_finished(value); }
126  bool isAck() const { return C::mip_cmd_result_is_ack(value); }
127 };
128 
129 // using Ack = C::mip_ack;
130 
133 
134 } // namespace mip
135 #endif // __cplusplus
MIP_STATUS_PENDING
@ MIP_STATUS_PENDING
Command has been queued but the I/O update hasn't run yet.
Definition: mip_result.h:34
mip
Definition: ping.cpp:12
mip_cmd_result_to_string
const char * mip_cmd_result_to_string(enum mip_cmd_result result)
Converts the command result to a string for debugging.
Definition: mip_result.c:16
mip_cmd_result_is_reply
bool mip_cmd_result_is_reply(enum mip_cmd_result result)
Determines if the result is a reply from the device (i.e.
Definition: mip_result.c:53
MIP_NACK_COMMAND_FAILED
@ MIP_NACK_COMMAND_FAILED
The device could not complete the command.
Definition: mip_result.h:42
mip_cmd_result_is_ack
bool mip_cmd_result_is_ack(enum mip_cmd_result result)
Determines if the result is an ack (successful response from the device)
Definition: mip_result.c:77
MIP_STATUS_ERROR
@ MIP_STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.h:30
mip_cmd_result
mip_cmd_result
Represents the status of a MIP command.
Definition: mip_result.h:25
MIP_NACK_COMMAND_UNKNOWN
@ MIP_NACK_COMMAND_UNKNOWN
Command not supported.
Definition: mip_result.h:39
MIP_NACK_COMMAND_TIMEOUT
@ MIP_NACK_COMMAND_TIMEOUT
Internal device timeout. Use MIP_STATUS_TIMEDOUT for command timeouts.
Definition: mip_result.h:43
MIP_ACK_OK
@ MIP_ACK_OK
Command completed successfully.
Definition: mip_result.h:38
mip_cmd_result_is_finished
bool mip_cmd_result_is_finished(enum mip_cmd_result result)
Determines if the command has completed, timed out, been cancelled, or otherwise is no longer waiting...
Definition: mip_result.c:45
MIP_NACK_INVALID_CHECKSUM
@ MIP_NACK_INVALID_CHECKSUM
Reserved.
Definition: mip_result.h:40
MIP_STATUS_WAITING
@ MIP_STATUS_WAITING
Waiting for command reply (timeout timer has started).
Definition: mip_result.h:33
mip_cmd_result_is_status
bool mip_cmd_result_is_status(enum mip_cmd_result result)
Determines if the result code was generated by this lib (i.e.
Definition: mip_result.c:61
operator==
bool operator==(const GTEST_10_TUPLE_(T)&t, const GTEST_10_TUPLE_(U)&u)
MIP_STATUS_NONE
@ MIP_STATUS_NONE
Command has been initialized but not queued yet.
Definition: mip_result.h:35
operator!=
bool operator!=(const GTEST_10_TUPLE_(T)&t, const GTEST_10_TUPLE_(U)&u)
MIP_STATUS_USER_START
@ MIP_STATUS_USER_START
Values defined by user code must be less than or equal to this value.
Definition: mip_result.h:27
MIP_STATUS_CANCELLED
@ MIP_STATUS_CANCELLED
Command was canceled in software.
Definition: mip_result.h:31
MIP_NACK_INVALID_PARAM
@ MIP_NACK_INVALID_PARAM
A parameter was not a supported value.
Definition: mip_result.h:41
mip_cmd_result_is_user
bool mip_cmd_result_is_user(enum mip_cmd_result result)
Determines if the result code was generated by user software.
Definition: mip_result.c:69
MIP_STATUS_TIMEDOUT
@ MIP_STATUS_TIMEDOUT
Reply was not received before timeout expired.
Definition: mip_result.h:32


microstrain_inertial_driver
Author(s): Brian Bingham, Parker Hannifin Corp
autogenerated on Mon Jun 24 2024 02:51:40