-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorService.h
118 lines (107 loc) · 4.26 KB
/
ErrorService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* @file ErrorService.h
* @author Felix Schuelke (flxscode@gmail.com)
* @brief
* @version 0.1
* @date 2024-08-18
*
* @copyright * Copyright (C) 2024 Felix Schuelke
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef ERROR_SERVICE_H
#define ERROR_SERVICE_H
#ifdef ARDUINO
#include <Arduino.h> // include Arduino-Library for platformIO-build
#else
#include <mockArduino.h>
#include <cstring>
using namespace arduinoMocking;
#endif
#include "Service.h"
#include "Error.h"
/// @brief Number of elements the services stacks can store
#define STACKSIZE 2
/// @brief Service-id ASCII: "e"
#define SERVICEID 0x65
/**
* @class ErrorService
* @brief Service class for handling Errors.
*
* The `ErrorService` class manages content from type 'Error', processes incoming errors from the receive stack, and handles sending errors.
* It inherits from a Service for content_type 'Error' (`Service<Error, STACKSIZE>`).
* Errors occurred internally are raised by calling the raiseError-function of the service. Those Errors are added with the local instanceId
* to the recStack. During the processing, errors with the local instanceId are putted back to the sendStack to publish them to the network.
* All Errors are printed to the Serial-interface.
*
* @section Constructors
* - `ErrorService(uint8_t instance_id)`: Constructs a `ErrorService` with a default service ID of "e".
* - `ErrorService(uint8_t instance_id, uint8_t service_id)`: Constructs a `ErrorService` with a custom service ID.
*
* @section Methods
* - `void stackProcessing() override`: Processes all errors from the receive stack until it is empty. Adds error-responds to the send stack and prints received errors.
* - `void raiseError(errorCodes code)`: add an Error occurred internally to the receive-stack
*
* @private
* - `void printError(Error* error)`: Prints the content of an error
*
* @note
* - The class handles both the processing of incoming errors and the sending of internally occurred errors.
* - The `stackProcessing` method is responsible for managing the receive and send stacks.
*/
class ErrorService: public Service<Error, STACKSIZE>
{
public:
/**
* @brief Constructor for `ErrorService` with default Service ID "m".
*
* Initializes the service with the given instance ID and a default service ID.
*
* @param instance_id The instance ID for the service.
*/
ErrorService(uint8_t instance_id);
/**
* @brief Constructor for `ErrorService` with a custom Service ID.
*
* Initializes the service with the given instance ID and a custom service ID.
*
* @param instance_id The instance ID for the service.
* @param service_id The custom service ID.
*/
ErrorService(uint8_t instance_id, uint8_t service_id);
/**
* @brief Adds an Error-object for the local Instance-Id to the Error-services rec-stack
*
* @param code The error code of the error to be raised.
*/
void raiseError(errorCodes code);
/**
* @brief Processes all errors from the receive stack.
*
* Processes each error in the receive stack until it is empty.
* Each received error is printed to the serial output,
* generates and adds an acknowledgment PDU to the send stack, and removes the processed message from the receive stack.
*/
void stackProcessing() override;
private:
/**
* @brief Prints the content of an error
*
* Outputs the string representation of the error-object to the serial monitor.
*
* @param message The error to be printed.
*/
void printError(Error* error);
};
#endif // ERROR_SERVICE_H