SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
Loading...
Searching...
No Matches
error_handler.hpp
Go to the documentation of this file.
1
/*
2
* SatNOGS-COMMS control library
3
*
4
* Copyright (C) 2024, Libre Space Foundation <http://libre.space>
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*
19
* SPDX-License-Identifier: GNU General Public License v3.0 or later
20
*/
21
22
#pragma once
23
24
#include "
logger.hpp
"
25
#include <etl/error_handler.h>
26
#include <exception>
27
#include <
satnogs-comms-lib/exception.hpp
>
28
29
namespace
satnogs::comms
30
{
31
52
class
error_handler
53
{
54
public
:
60
static
error_handler
&
61
get_instance
()
62
{
63
static
error_handler
instance;
64
return
instance;
65
}
66
/* Singleton */
67
error_handler
(
error_handler
const
&) =
delete
;
68
void
69
operator=
(
error_handler
const
&) =
delete
;
70
71
void
72
assert_error
(
const
lib::exception
&e);
73
74
void
75
assert_error
(
bool
condition,
const
lib::exception
&e);
76
77
uint32_t
78
hwinfo_reset_cause
()
const
;
79
80
void
81
handle
(
const
lib::exception
&e);
82
83
void
84
handle
(
const
std::exception &e);
85
86
void
87
handle
(
const
etl::exception &e);
88
99
template
<
typename
T>
100
void
101
assert_error
(
const
char
*file,
int
line)
102
{
103
T error(file, line);
104
assert_error
(error);
105
}
106
120
template
<
typename
T>
121
void
122
assert_error
(
bool
condition,
const
char
*file,
int
line)
123
{
124
T error(file, line);
125
assert_error
(condition, error);
126
}
127
128
void
129
system_reboot
()
const
;
130
131
protected
:
132
error_handler
();
133
134
template
<
typename
T>
135
void
136
log
(
const
T &e)
const
137
{
138
auto
&
log
=
logger::get_instance
();
139
log
.log(e);
140
}
141
142
private
:
143
uint32_t m_hw_reset_cause;
144
int32_t m_last_errno;
145
uint32_t m_errno_cnt;
146
147
void
148
get_reset_cause();
149
};
150
151
}
// namespace satnogs::comms
satnogs::comms::error_handler::get_instance
static error_handler & get_instance()
Singleton access to the error_handler subsystem.
Definition
error_handler.hpp:61
satnogs::comms::error_handler::error_handler
error_handler(error_handler const &)=delete
satnogs::comms::error_handler::hwinfo_reset_cause
uint32_t hwinfo_reset_cause() const
Retrieves the hardware reset cause from the MCU.
Definition
error_handler.cpp:41
satnogs::comms::error_handler::error_handler
error_handler()
Constructs an error_handler instance.
Definition
error_handler.cpp:173
satnogs::comms::error_handler::system_reboot
void system_reboot() const
Instructs a system reboot.
Definition
error_handler.cpp:79
satnogs::comms::error_handler::assert_error
void assert_error(const char *file, int line)
Asserts an error with file and line number information.
Definition
error_handler.hpp:101
satnogs::comms::error_handler::assert_error
void assert_error(bool condition, const char *file, int line)
Asserts an error based on a condition, with file and line information.
Definition
error_handler.hpp:122
satnogs::comms::error_handler::handle
void handle(const lib::exception &e)
Handles a lib::exception based on its severity.
Definition
error_handler.cpp:108
satnogs::comms::error_handler::log
void log(const T &e) const
Definition
error_handler.hpp:136
satnogs::comms::error_handler::operator=
void operator=(error_handler const &)=delete
satnogs::comms::error_handler::assert_error
void assert_error(const lib::exception &e)
Logs error details and throws an exception with ETL_ASSERT().
Definition
error_handler.cpp:15
satnogs::comms::lib::exception
Exception base class.
Definition
exception.hpp:63
satnogs::comms::logger::get_instance
static logger & get_instance()
Singleton access to the logger subsystem.
Definition
logger.hpp:102
exception.hpp
logger.hpp
satnogs::comms
Definition
bsp.cpp:28
src
error_handler.hpp
Generated by
1.17.0