parent
7571be1f54
commit
ecc5062e0f
8 changed files with 165 additions and 10 deletions
@ -0,0 +1,50 @@ |
||||
#include <cassert> |
||||
#include <string> |
||||
#include "Error.h" |
||||
|
||||
using namespace logid::backend::hidpp10; |
||||
|
||||
Error::Error(uint8_t code): _code(code) |
||||
{ |
||||
assert(code != Success); |
||||
} |
||||
|
||||
const char* Error::what() const noexcept |
||||
{ |
||||
switch(_code) |
||||
{ |
||||
case Success: |
||||
return "Success"; |
||||
case InvalidSubID: |
||||
return "Invalid sub ID"; |
||||
case InvalidAddress: |
||||
return "Invalid address"; |
||||
case InvalidValue: |
||||
return "Invalid value"; |
||||
case ConnectFail: |
||||
return "Connection failure"; |
||||
case TooManyDevices: |
||||
return "Too many devices"; |
||||
case AlreadyExists: |
||||
return "Already exists"; |
||||
case Busy: |
||||
return "Busy"; |
||||
case UnknownDevice: |
||||
return "Unknown device"; |
||||
case ResourceError: |
||||
return "Resource error"; |
||||
case RequestUnavailable: |
||||
return "Request unavailable"; |
||||
case InvalidParameterValue: |
||||
return "Invalid parameter value"; |
||||
case WrongPINCode: |
||||
return "Wrong PIN code"; |
||||
default: |
||||
return std::string("Unknown error code " + std::to_string(_code)).c_str(); |
||||
} |
||||
} |
||||
|
||||
uint8_t Error::code() const noexcept |
||||
{ |
||||
return _code; |
||||
} |
@ -0,0 +1,41 @@ |
||||
#ifndef LOGID_BACKEND_HIDPP10_ERROR_H |
||||
#define LOGID_BACKEND_HIDPP10_ERROR_H |
||||
|
||||
#include <cstdint> |
||||
|
||||
namespace logid { |
||||
namespace backend { |
||||
namespace hidpp10 { |
||||
static constexpr uint8_t ErrorID = 0x8f; |
||||
|
||||
class Error: public std::exception |
||||
{ |
||||
public: |
||||
enum ErrorCode: uint8_t |
||||
{ |
||||
Success = 0x00, |
||||
InvalidSubID = 0x01, |
||||
InvalidAddress = 0x02, |
||||
InvalidValue = 0x03, |
||||
ConnectFail = 0x04, |
||||
TooManyDevices = 0x05, |
||||
AlreadyExists = 0x06, |
||||
Busy = 0x07, |
||||
UnknownDevice = 0x08, |
||||
ResourceError = 0x09, |
||||
RequestUnavailable = 0x0A, |
||||
InvalidParameterValue = 0x0B, |
||||
WrongPINCode = 0x0C |
||||
}; |
||||
|
||||
Error(uint8_t code); |
||||
|
||||
virtual const char* what() const noexcept; |
||||
uint8_t code() const noexcept; |
||||
|
||||
private: |
||||
uint8_t _code; |
||||
}; |
||||
}}} |
||||
|
||||
#endif //LOGID_BACKEND_HIDPP10_ERROR_H
|
Loading…
Reference in new issue