MIP SDK  0.0.1
MicroStrain Communications Library for embedded systems
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 
23 typedef enum mip_cmd_result
24 {
31 
32  MIP_ACK_OK = 0x00,
39 
40 const char* mip_cmd_result_to_string(enum mip_cmd_result result);
41 
43 
46 
48 
51 
52 #ifdef __cplusplus
53 } // extern "C"
54 } // namespace C
55 
66 struct CmdResult
67 {
74 
75  static constexpr C::mip_cmd_result ACK_OK = C::MIP_ACK_OK;
81 
82 #ifndef _WIN32 // Avoid name conflict with windows.h
84 #endif
85 
87 
89  CmdResult(C::mip_cmd_result result) : value(result) {}
90 
91  CmdResult& operator=(const CmdResult& other) = default;
92  CmdResult& operator=(C::mip_cmd_result other) { value = other; return *this; }
93 
94  static CmdResult fromAckNack(uint8_t code) { return CmdResult(static_cast<C::mip_cmd_result>(code)); }
95 
96  operator const void*() const { return isAck() ? this : nullptr; }
97  bool operator!() const { return !isAck(); }
98 
99  bool operator==(CmdResult other) const { return value == other.value; }
100  bool operator!=(CmdResult other) const { return value != other.value; }
101 
102  bool operator==(C::mip_cmd_result other) const { return value == other; }
103  bool operator!=(C::mip_cmd_result other) const { return value != other; }
104 
105  const char* name() const { return C::mip_cmd_result_to_string(value); }
106 
107  bool isReplyCode() const { return C::mip_cmd_result_is_reply(value); }
110  bool isAck() const { return C::mip_cmd_result_is_ack(value); }
111 };
112 
113 // using Ack = C::mip_ack;
114 
117 
118 } // namespace mip
119 #endif // __cplusplus
const char * mip_cmd_result_to_string(enum mip_cmd_result result)
bool mip_cmd_result_is_reply(enum mip_cmd_result result)
bool mip_cmd_result_is_ack(enum mip_cmd_result result)
mip_cmd_result
Represents the status of a MIP command.
Definition: mip_result.h:24
bool mip_cmd_result_is_status(enum mip_cmd_result result)
bool mip_cmd_result_is_finished(enum mip_cmd_result result)
@ MIP_STATUS_WAITING
Waiting for command reply (timeout timer has started).
Definition: mip_result.h:28
@ MIP_NACK_INVALID_CHECKSUM
Reserved.
Definition: mip_result.h:34
@ MIP_STATUS_PENDING
Command has been queued but the I/O update hasn't run yet.
Definition: mip_result.h:29
@ MIP_STATUS_TIMEDOUT
Reply was not received before timeout expired.
Definition: mip_result.h:27
@ MIP_ACK_OK
Command completed successfully.
Definition: mip_result.h:32
@ MIP_STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.h:25
@ MIP_NACK_COMMAND_FAILED
The device could not complete the command.
Definition: mip_result.h:36
@ MIP_NACK_COMMAND_UNKNOWN
Command not supported.
Definition: mip_result.h:33
@ MIP_STATUS_NONE
Command has been initialized but not queued yet.
Definition: mip_result.h:30
@ MIP_STATUS_CANCELLED
Command was canceled in software.
Definition: mip_result.h:26
@ MIP_NACK_INVALID_PARAM
A parameter was not a supported value.
Definition: mip_result.h:35
@ MIP_NACK_COMMAND_TIMEOUT
Internal device timeout. Use MIP_STATUS_TIMEDOUT for command timeouts.
Definition: mip_result.h:37
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
Represents the status of a MIP command.
Definition: mip_result.h:67
bool operator==(CmdResult other) const
Definition: mip_result.h:99
static constexpr C::mip_cmd_result STATUS_PENDING
Definition: mip_result.h:83
C::mip_cmd_result value
Definition: mip_result.h:86
CmdResult()
Definition: mip_result.h:88
CmdResult & operator=(const CmdResult &other)=default
const char * name() const
Definition: mip_result.h:105
bool operator!=(C::mip_cmd_result other) const
Definition: mip_result.h:103
static constexpr C::mip_cmd_result NACK_COMMAND_FAILED
The device could not complete the command.
Definition: mip_result.h:79
static constexpr C::mip_cmd_result NACK_COMMAND_TIMEOUT
Internal device timeout. Use MIP_STATUS_TIMEDOUT for command timeouts.
Definition: mip_result.h:80
static constexpr C::mip_cmd_result STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.h:68
static constexpr C::mip_cmd_result ACK_OK
Command completed successfully.
Definition: mip_result.h:75
static constexpr C::mip_cmd_result STATUS_WAITING
Waiting for command reply (timeout timer has started).
Definition: mip_result.h:71
static constexpr C::mip_cmd_result NACK_INVALID_CHECKSUM
Reserved.
Definition: mip_result.h:77
static constexpr C::mip_cmd_result STATUS_CANCELLED
Command was canceled in software.
Definition: mip_result.h:69
CmdResult & operator=(C::mip_cmd_result other)
Definition: mip_result.h:92
static constexpr C::mip_cmd_result STATUS_TIMEDOUT
Reply was not received before timeout expired.
Definition: mip_result.h:70
bool operator==(C::mip_cmd_result other) const
Definition: mip_result.h:102
bool isFinished() const
Definition: mip_result.h:109
bool operator!=(CmdResult other) const
Definition: mip_result.h:100
bool isReplyCode() const
Definition: mip_result.h:107
CmdResult(C::mip_cmd_result result)
Definition: mip_result.h:89
bool isAck() const
Definition: mip_result.h:110
static CmdResult fromAckNack(uint8_t code)
Definition: mip_result.h:94
bool operator!() const
Definition: mip_result.h:97
static constexpr C::mip_cmd_result NACK_COMMAND_UNKNOWN
Command not supported.
Definition: mip_result.h:76
static constexpr C::mip_cmd_result STATUS_NONE
Command has been initialized but not queued yet.
Definition: mip_result.h:73
bool isStatusCode() const
Definition: mip_result.h:108
static constexpr C::mip_cmd_result NACK_INVALID_PARAM
A parameter was not a supported value.
Definition: mip_result.h:78
static constexpr C::mip_cmd_result STATUS_QUEUED
Command has been queued but the I/O update hasn't run yet.
Definition: mip_result.h:72