MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
mip_result.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mip/mip_result.h>
4 
5 
6 namespace mip
7 {
11 
24 struct CmdResult
25 {
33 
34  static constexpr C::mip_cmd_result ACK_OK = C::MIP_ACK_OK;
40 
41 #ifndef MICROSTRAIN_PLATFORM_WINDOWS // Avoid name conflict with windows.h
43 #endif
44 
46 
47  constexpr CmdResult() : value(C::MIP_ACK_OK) {}
48  constexpr CmdResult(C::mip_cmd_result result) : value(result) {}
49  ~CmdResult() = default;
50 
51  CmdResult& operator=(const CmdResult& other) = default;
52  CmdResult& operator=(C::mip_cmd_result other) { value = other; return *this; }
53 
54  static constexpr CmdResult userResult(uint8_t n) { return CmdResult(static_cast<C::mip_cmd_result>(STATUS_USER - int8_t(n))); }
55  static constexpr CmdResult fromAckNack(uint8_t code) { return CmdResult(static_cast<C::mip_cmd_result>(code)); }
56 
57  operator const void*() const { return isAck() ? this : nullptr; }
58  bool operator!() const { return !isAck(); }
59 
60  constexpr bool operator==(CmdResult other) const { return value == other.value; }
61  constexpr bool operator!=(CmdResult other) const { return value != other.value; }
62 
63  constexpr bool operator==(C::mip_cmd_result other) const { return value == other; }
64  constexpr bool operator!=(C::mip_cmd_result other) const { return value != other; }
65 
66  const char* name() const { return C::mip_cmd_result_to_string(value); }
67 
68  bool isReplyCode() const { return C::mip_cmd_result_is_reply(value); }
71  bool isAck() const { return C::mip_cmd_result_is_ack(value); }
72 };
73 
76 } // namespace mip
mip::C::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. mip_ack).
Definition: mip_result.c:55
mip::C::MIP_STATUS_WAITING
@ MIP_STATUS_WAITING
Waiting for command reply (timeout timer has started).
Definition: mip_result.h:35
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::C::mip_cmd_result_is_finished
bool mip_cmd_result_is_finished(enum mip_cmd_result status)
Determines if the command has completed, timed out, been cancelled, or otherwise is no longer waiting...
Definition: mip_result.c:47
mip::CmdResult::NACK_INVALID_CHECKSUM
static constexpr C::mip_cmd_result NACK_INVALID_CHECKSUM
Reserved.
Definition: mip_result.hpp:36
mip::CmdResult::~CmdResult
~CmdResult()=default
mip::C::mip_cmd_result
mip_cmd_result
Represents the status of a MIP command.
Definition: mip_result.h:27
mip::CmdResult::NACK_INVALID_PARAM
static constexpr C::mip_cmd_result NACK_INVALID_PARAM
A parameter was not a supported value.
Definition: mip_result.hpp:37
mip::CmdResult::isAck
bool isAck() const
Definition: mip_result.hpp:71
mip::C::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:17
mip::CmdResult::STATUS_PENDING
static constexpr C::mip_cmd_result STATUS_PENDING
Definition: mip_result.hpp:42
mip::C::MIP_NACK_COMMAND_UNKNOWN
@ MIP_NACK_COMMAND_UNKNOWN
Command not supported.
Definition: mip_result.h:41
mip::CmdResult::isReplyCode
bool isReplyCode() const
Definition: mip_result.hpp:68
mip::CmdResult::STATUS_ERROR
static constexpr C::mip_cmd_result STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.hpp:27
mip_result.h
mip::CmdResult::operator!
bool operator!() const
Definition: mip_result.hpp:58
mip::C::MIP_STATUS_PENDING
@ MIP_STATUS_PENDING
Command has been queued but the I/O update hasn't run yet.
Definition: mip_result.h:36
mip::CmdResult::STATUS_WAITING
static constexpr C::mip_cmd_result STATUS_WAITING
Waiting for command reply (timeout timer has started).
Definition: mip_result.hpp:30
mip::CmdResult::userResult
static constexpr CmdResult userResult(uint8_t n)
Definition: mip_result.hpp:54
mip::C::MIP_NACK_COMMAND_TIMEOUT
@ MIP_NACK_COMMAND_TIMEOUT
Internal device timeout. Use MIP_STATUS_TIMEDOUT for command timeouts.
Definition: mip_result.h:45
mip::CmdResult::fromAckNack
static constexpr CmdResult fromAckNack(uint8_t code)
Definition: mip_result.hpp:55
mip::C::MIP_NACK_COMMAND_FAILED
@ MIP_NACK_COMMAND_FAILED
The device could not complete the command.
Definition: mip_result.h:44
mip::CmdResult::isFinished
bool isFinished() const
Definition: mip_result.hpp:70
mip::CmdResult::operator!=
constexpr bool operator!=(CmdResult other) const
Definition: mip_result.hpp:61
mip::CmdResult::STATUS_TIMEDOUT
static constexpr C::mip_cmd_result STATUS_TIMEDOUT
Reply was not received before timeout expired.
Definition: mip_result.hpp:29
mip::CmdResult::STATUS_QUEUED
static constexpr C::mip_cmd_result STATUS_QUEUED
Command has been queued but the I/O update hasn't run yet.
Definition: mip_result.hpp:31
mip::CmdResult::operator==
constexpr bool operator==(CmdResult other) const
Definition: mip_result.hpp:60
mip::C::MIP_STATUS_TIMEDOUT
@ MIP_STATUS_TIMEDOUT
Reply was not received before timeout expired.
Definition: mip_result.h:34
mip::C::MIP_STATUS_CANCELLED
@ MIP_STATUS_CANCELLED
Command was canceled in software.
Definition: mip_result.h:33
mip::CmdResult
Represents the status of a MIP command.
Definition: mip_result.hpp:24
mip::CmdResult::operator=
CmdResult & operator=(const CmdResult &other)=default
mip::CmdResult::STATUS_CANCELLED
static constexpr C::mip_cmd_result STATUS_CANCELLED
Command was canceled in software.
Definition: mip_result.hpp:28
mip::CmdResult::CmdResult
constexpr CmdResult(C::mip_cmd_result result)
Definition: mip_result.hpp:48
mip::CmdResult::operator!=
constexpr bool operator!=(C::mip_cmd_result other) const
Definition: mip_result.hpp:64
mip::CmdResult::name
const char * name() const
Definition: mip_result.hpp:66
mip::CmdResult::NACK_COMMAND_UNKNOWN
static constexpr C::mip_cmd_result NACK_COMMAND_UNKNOWN
Command not supported.
Definition: mip_result.hpp:35
mip::C::MIP_STATUS_ERROR
@ MIP_STATUS_ERROR
Command could not be executed (error sending/receiving)
Definition: mip_result.h:32
mip::C::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:79
mip::CmdResult::isStatusCode
bool isStatusCode() const
Definition: mip_result.hpp:69
mip::C::MIP_NACK_INVALID_PARAM
@ MIP_NACK_INVALID_PARAM
A parameter was not a supported value.
Definition: mip_result.h:43
mip::C::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. mip_cmd_status).
Definition: mip_result.c:63
mip::CmdResult::ACK_OK
static constexpr C::mip_cmd_result ACK_OK
Command completed successfully.
Definition: mip_result.hpp:34
mip::CmdResult::operator==
constexpr bool operator==(C::mip_cmd_result other) const
Definition: mip_result.hpp:63
mip::C::MIP_ACK_OK
@ MIP_ACK_OK
Command completed successfully.
Definition: mip_result.h:40
mip::CmdResult::STATUS_USER
static constexpr C::mip_cmd_result STATUS_USER
Values defined by user code must be less than or equal to this value.
Definition: mip_result.hpp:26
mip::C::MIP_NACK_INVALID_CHECKSUM
@ MIP_NACK_INVALID_CHECKSUM
Reserved.
Definition: mip_result.h:42
mip::CmdResult::operator=
CmdResult & operator=(C::mip_cmd_result other)
Definition: mip_result.hpp:52
mip::C::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:29
mip::CmdResult::STATUS_NONE
static constexpr C::mip_cmd_result STATUS_NONE
Command has been initialized but not queued yet.
Definition: mip_result.hpp:32
mip::CmdResult::value
C::mip_cmd_result value
Definition: mip_result.hpp:45
mip::C::MIP_STATUS_NONE
@ MIP_STATUS_NONE
Command has been initialized but not queued yet.
Definition: mip_result.h:37
mip::CmdResult::NACK_COMMAND_TIMEOUT
static constexpr C::mip_cmd_result NACK_COMMAND_TIMEOUT
Internal device timeout. Use MIP_STATUS_TIMEDOUT for command timeouts.
Definition: mip_result.hpp:39
mip::CmdResult::CmdResult
constexpr CmdResult()
Definition: mip_result.hpp:47
mip::CmdResult::NACK_COMMAND_FAILED
static constexpr C::mip_cmd_result NACK_COMMAND_FAILED
The device could not complete the command.
Definition: mip_result.hpp:38