BusBricks: /Users/felixschulke/Developement/Arduino/Modbus_RTU/Modbus_RTU/Modbus-RTU/lib/ErrorService/Error.h Source File
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
Error.h
Go to the documentation of this file.
1
24#ifndef ERROR_H
25#define ERROR_H
26
27#ifdef ARDUINO
28 #include <Arduino.h> // include Arduino-Library for platformIO-build
29#else
30 #include <iostream> // include iostream for local testing
31 #include <cstring>
32 #include <cstdio>
33 #include <mockArduino.h>
34 using namespace arduinoMocking;
35#endif
36
37#include "Content.h" // include Content-template
38
39
51 noError = '0',
52
57
61 crcError = '2',
62
67
73
79
84 overflow = '6',
85
90 unknownError = 'X'
91};
92
93
103
109
113 const char* message;
114
120 code(errCode), instanceId(instanceId) {
121 message = getErrorMessage(errCode);
122 }
123
124private:
130 const char* getErrorMessage(errorCodes code) {
131 switch (code) {
132 case noError:
133 return "No Error";
134 case framingError:
135 return "Framing-Error: Structure of the frame is not as expected";
136 case crcError:
137 return "CRC-Error: CRC checksum incorrect";
138 case arbitrationError:
139 return "Arbitration-Error: Silence-time between frames violated";
140 case serviceNotFound:
141 return "Service-not-found: Service-Id was not found in the service-cluster";
142 case frameLengthError:
143 return "Frame-Length-Error: Maximum length of Frame was violated";
144 case overflow:
145 return "Service-Stack-Overflow: Send- or Receivestack of Service has reached max. size of items";
146 default:
147 return "Unknown Error";
148 }
149 }
150};
151
175class Error: public Content<ErrorContent_t, String>
176{
177 public:
183 Error();
184
189 ~Error();
190
199
207 Error(ErrorContent_t* errorContent);
208
216 Error(char instanceId, errorCodes code);
217
224
225 private:
231 virtual void rep_to_content() override;
232
238 virtual void content_to_rep() override;
239
240
241
242};
243
244
245#endif // ERROR_H
errorCodes
Enumeration for various error codes.
Definition Error.h:47
@ unknownError
Unknown Error.
Definition Error.h:90
@ framingError
Structure of the frame is not as expected by the services content-representation-definition.
Definition Error.h:56
@ arbitrationError
Violated silence-time between frames.
Definition Error.h:66
@ crcError
CRC checksum incorrect.
Definition Error.h:61
@ overflow
Send- or Receivestack reached max. size of items.
Definition Error.h:84
@ serviceNotFound
The Service-Id addressed by the frame was not found in the service-cluster.
Definition Error.h:72
@ noError
no Error
Definition Error.h:51
@ frameLengthError
Maximum framelength violated.
Definition Error.h:78
The cascading of processing information and the rules applied to it lead to the concept of content- a...
Definition Content.h:45
String representation
Definition Content.h:94
Represents an error with it's error-content (error-code and an error-message), and provides methods f...
Definition Error.h:176
~Error()
Destroy the Error object.
Definition Error.cpp:32
Error()
Default constructor for Error.
Definition Error.cpp:27
String to_string()
Converts the Error to a well formatted, printable string.
Definition Error.cpp:50
Provides mock implementations of Arduino framework functions and classes for native builds.
Definition mockArduino.cpp:28
std::string String
Alias for std::string to simulate Arduino's String type.
Definition mockArduino.h:51
Structure to hold an error code and its associated message.
Definition Error.h:98
ErrorContent_t(char instanceId=0x0, errorCodes errCode=noError)
Constructor that initializes the error content based on the provided error code.
Definition Error.h:119
errorCodes code
The error code representing the specific error.
Definition Error.h:102
char instanceId
Instance-ID if Error-Service, that raised the error.
Definition Error.h:108
const char * message
A human-readable message describing the error.
Definition Error.h:113