From 4207e3c9bb316443d2d5e5cb07f986cbaf2d4dbb Mon Sep 17 00:00:00 2001 From: Ebersold Date: Mon, 13 Nov 2023 14:48:03 +0100 Subject: [PATCH] Improved ErrorHandler --- {Platform => Metadata}/Errors.h | 0 Metadata/ParameterTable.h | 14 +++++- Platform/CMakeLists.txt | 1 + Platform/ErrorHandler/ErrorHandler.cpp | 49 +++++++++++++++++++++ Platform/{ => ErrorHandler}/ErrorHandler.h | 9 +++- Platform/{ => ErrorHandler}/IErrorHandler.h | 0 6 files changed, 70 insertions(+), 3 deletions(-) rename {Platform => Metadata}/Errors.h (100%) create mode 100644 Platform/ErrorHandler/ErrorHandler.cpp rename Platform/{ => ErrorHandler}/ErrorHandler.h (70%) rename Platform/{ => ErrorHandler}/IErrorHandler.h (100%) diff --git a/Platform/Errors.h b/Metadata/Errors.h similarity index 100% rename from Platform/Errors.h rename to Metadata/Errors.h diff --git a/Metadata/ParameterTable.h b/Metadata/ParameterTable.h index 45a52d0..927d4f3 100644 --- a/Metadata/ParameterTable.h +++ b/Metadata/ParameterTable.h @@ -1,7 +1,17 @@ -#ifndef POWERSWITCHPARAMETERTABLE_H__ -#define POWERSWITCHPARAMETERTABLE_H__ +#ifndef __PARAMETERTABLE_H__ +#define __PARAMETERTABLE_H__ #include "Metadata/Metadata.h" +#ifdef POWERSWITCH_PARAMETERS +#include +#elif defined(WORKMETER_PARAMETERS) +#include +#elif defined(DCMOTOR_PARAMETERS) +#include +#elif defined(SHUTTERCTRL_PARAMETERS) +#include +#endif + extern ParameterValue m_Values[PID_MAX]; #endif diff --git a/Platform/CMakeLists.txt b/Platform/CMakeLists.txt index 3b9d0e2..c225ef8 100644 --- a/Platform/CMakeLists.txt +++ b/Platform/CMakeLists.txt @@ -47,6 +47,7 @@ add_avr_library( ParameterHandler.cpp PersistentStorage.cpp RFIDReader/RFIDReaderHandler.cpp + ErrorHandler/ErrorHandler.cpp ) set_target_properties( diff --git a/Platform/ErrorHandler/ErrorHandler.cpp b/Platform/ErrorHandler/ErrorHandler.cpp new file mode 100644 index 0000000..02bc74d --- /dev/null +++ b/Platform/ErrorHandler/ErrorHandler.cpp @@ -0,0 +1,49 @@ +#include + +#include + +#include + +#include "IErrorHandler.h" +#include "ErrorHandler.h" + +static Uint8_t m_PID_Errors[ERROR_VECTORS] = {PID_LowLevelError1,PID_LowLevelError2}; +static Uint32_t m_LowLevelErrors[ERROR_VECTORS] {0,0}; + + +void ErrorHandler::ErrorHandler() +{ +} + +void ErrorHandler::run() +{ + updateErrors(); +} + +void ErrorHandler::setError(Error_t _err) +{ + Uint16_t _offset = 0; + Uint8_t _vect = 0; + Bool_t _found = false; + while (!_found && (_vect < ERROR_VECTOR) ) + { + if (_err < (offset + 32)) + { + Uint32_t _errorBit = static_cast(1)<<(_err - ofsset); + m_LowLevelErrors[_vect] |= + _found = true; + } + offset+=32; + _vect++; + }; +} + +void ErrorHandler::updateErrors() +{ + for (Uint8_t i = 0; i < ERROR_VECTOR ; ++i) + { + m_Params->writeValue(m_PID_Errors[i],m_LowLevelErrors[i]); + m_LowLevelErrors[i] = 0L; + } +} + diff --git a/Platform/ErrorHandler.h b/Platform/ErrorHandler/ErrorHandler.h similarity index 70% rename from Platform/ErrorHandler.h rename to Platform/ErrorHandler/ErrorHandler.h index ff03c17..5c81877 100644 --- a/Platform/ErrorHandler.h +++ b/Platform/ErrorHandler/ErrorHandler.h @@ -1,6 +1,7 @@ #ifndef __ERROR_HANDLER_H__ #define __ERROR_HANDLER_H__ +#define ERROR_VECTORS 2 /** * \brief good, lets implement basic error handler * that reports the error through the serial communication @@ -8,14 +9,20 @@ * * */ + class ErrorHandler : public IErrorHandler , public ITask { public: - ErrorHandler(); + ErrorHandler(IParameterHandler *argParams); /// Method available to modules so that errors can be reported virtual void setError(Uint16_t _error); /// Alright process some stuff in case an errors has been raised virtual void run(); + private: + void updateErrors(); + private: + static Uint8_t m_PID_Errors[ERROR_VECTORS]; + static Uint32_t m_LowLevelErrors[ERROR_VECTORS]; }; #endif diff --git a/Platform/IErrorHandler.h b/Platform/ErrorHandler/IErrorHandler.h similarity index 100% rename from Platform/IErrorHandler.h rename to Platform/ErrorHandler/IErrorHandler.h -- 2.30.2