Libraries/IOControl/include/IO/Error.h
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include "WString.h"
23 #include <ArduinoJson.h>
24 
25 namespace IO
26 {
27 using ErrorCode = int16_t;
28 
29 namespace Error
30 {
31 #define IOERROR_MAX_MAP(XX) \
32  XX(common, -100) \
33  XX(modbus, -200) \
34  XX(rfswitch, -300)
35 
37 #define XX(name, value) max_##name = value,
39 #undef XX
40 };
41 
42 #define IOERROR_STD_MAP(XX) \
43  XX(access_denied, "Access Denied") \
44  XX(timeout, "Timeout") \
45  XX(cancelled, "Cancelled") \
46  XX(not_impl, "Not Implemented") \
47  XX(no_mem, "Out of memory") \
48  XX(busy, "Device or controller is busy") \
49  XX(bad_config, "Configuration data invalid") \
50  XX(file, "File Error") \
51  XX(bad_controller_class, "Wrong controller class specified for device") \
52  XX(bad_controller, "Controller not registered") \
53  XX(bad_device_class, "Device class not registered") \
54  XX(bad_device, "Device not registered") \
55  XX(bad_node, "Node ID not valid") \
56  XX(bad_command, "Invalid Command") \
57  XX(bad_function, "Invalid Function") \
58  XX(bad_param, "Invalid Parameter") \
59  XX(bad_checksum, "Checksum failed") \
60  XX(bad_size, "Data size invalid") \
61  XX(queue_full, "Request queue is full") \
62  XX(no_config, "No configuration found") \
63  XX(no_control_id, "Control ID not specified") \
64  XX(no_device_id, "Device ID not specified") \
65  XX(no_command, "Command not specified") \
66  XX(no_address, "Device address not specified") \
67  XX(no_baudrate, "Device baud rate not specified") \
68  XX(no_code, "RF code not specified")
69 
70 enum Common : ErrorCode {
71  success = 0,
72  pending = 1,
73  max_common_ = max_common,
74 #define XX(tag, comment) tag,
75  IOERROR_STD_MAP(XX)
76 #undef XX
77 };
78 
80 } // namespace Error
81 
82 #define debug_err(err, arg) debug_w("%s: %s", IO::Error::toString(err).c_str(), (arg).c_str())
83 
85 
87 
88 /*
89  * @param json
90  * @param err Numeric error code
91  * @param text Text for error
92  * @param arg Argument or additional description
93  *
94  */
95 ErrorCode setError(JsonObject json, ErrorCode err, const String& text = nullptr, const String& arg = nullptr);
96 
97 } // namespace IO
#define XX(name, comment)
Definition: DirectoryTemplate.h:47
#define IOERROR_STD_MAP(XX)
Definition: Libraries/IOControl/include/IO/Error.h:42
#define IOERROR_MAX_MAP(XX)
Definition: Libraries/IOControl/include/IO/Error.h:31
The String class.
Definition: WString.h:137
Json json
String toString(ErrorCode err)
ErrorMax
Definition: Libraries/IOControl/include/IO/Error.h:36
Common
Definition: Libraries/IOControl/include/IO/Error.h:70
@ success
Definition: Libraries/IOControl/include/IO/Error.h:71
@ pending
Definition: Libraries/IOControl/include/IO/Error.h:72
@ max_common_
Definition: Libraries/IOControl/include/IO/Error.h:73
Definition: IOControl/include/IO/Controller.h:26
ErrorCode setError(JsonObject json, ErrorCode err, const String &text=nullptr, const String &arg=nullptr)
ErrorCode setPending(JsonObject json)
int16_t ErrorCode
Definition: Libraries/IOControl/include/IO/Error.h:27
ErrorCode setSuccess(JsonObject json)
Error
Definition: Libraries/DiskStorage/src/include/Storage/Disk/Error.h:37