SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
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>
28
29namespace satnogs::comms
30{
31
53{
54public:
60 static error_handler &
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
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
131protected:
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
142private:
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
static error_handler & get_instance()
Singleton access to the error_handler subsystem.
error_handler(error_handler const &)=delete
uint32_t hwinfo_reset_cause() const
Retrieves the hardware reset cause from the MCU.
error_handler()
Constructs an error_handler instance.
void system_reboot() const
Instructs a system reboot.
void assert_error(const char *file, int line)
Asserts an error with file and line number information.
void assert_error(bool condition, const char *file, int line)
Asserts an error based on a condition, with file and line information.
void handle(const lib::exception &e)
Handles a lib::exception based on its severity.
void log(const T &e) const
void operator=(error_handler const &)=delete
void assert_error(const lib::exception &e)
Logs error details and throws an exception with ETL_ASSERT().
Exception base class.
Definition exception.hpp:63
static logger & get_instance()
Singleton access to the logger subsystem.
Definition logger.hpp:102