From: Ebersold Date: Mon, 13 Nov 2023 13:48:03 +0000 (+0100) Subject: Improved ErrorHandler X-Git-Url: https://git.ebersold.fr/?a=commitdiff_plain;h=4207e3c9bb316443d2d5e5cb07f986cbaf2d4dbb;p=atmel%2Favr.git Improved ErrorHandler --- diff --git a/Metadata/Errors.h b/Metadata/Errors.h new file mode 100644 index 0000000..c457426 --- /dev/null +++ b/Metadata/Errors.h @@ -0,0 +1,12 @@ +#ifndef __ERRORS_H__ +#define __ERRORS_H__ + +enum ErrorIds_t { + ERROR_Application_Starting = 0 + ,ERROR_Eeprom_Read_Invalid_Length = 1 + ,ERROR_Eeprom_Read_Invalid_Address = 2 + ,ERROR_Eeprom_Write_Invalid_Length = 3 + ,ERROR_Eeprom_Write_Invalid_Address = 4 + ,ERROR_MAX = 5 +}; +#endif 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.h b/Platform/ErrorHandler.h deleted file mode 100644 index ff03c17..0000000 --- a/Platform/ErrorHandler.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __ERROR_HANDLER_H__ -#define __ERROR_HANDLER_H__ - -/** - * \brief good, lets implement basic error handler - * that reports the error through the serial communication - * May be I have to got through the communication handler - * - * - */ -class ErrorHandler : public IErrorHandler , public ITask -{ - public: - ErrorHandler(); - /// 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(); -}; - -#endif 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/ErrorHandler.h b/Platform/ErrorHandler/ErrorHandler.h new file mode 100644 index 0000000..5c81877 --- /dev/null +++ b/Platform/ErrorHandler/ErrorHandler.h @@ -0,0 +1,28 @@ +#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 + * May be I have to got through the communication handler + * + * + */ + +class ErrorHandler : public IErrorHandler , public ITask +{ + public: + 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/ErrorHandler/IErrorHandler.h b/Platform/ErrorHandler/IErrorHandler.h new file mode 100644 index 0000000..6f7c9b0 --- /dev/null +++ b/Platform/ErrorHandler/IErrorHandler.h @@ -0,0 +1,16 @@ +#ifndef __IERROR_HANDLER_H__ +#define __IERROR_HANDLER_H__ + +/** + * \brief well, except setting an error, there is not mutch to be + * done there. The handler might eventually trigger the communication + * handler to report the error or what ever. + */ +class IErrorHandler +{ + public: + IErrorHandler() {}; + /// + virtual setError(Uint16_t error_id) = 0 ; +}; +#endif diff --git a/Platform/Errors.h b/Platform/Errors.h deleted file mode 100644 index c457426..0000000 --- a/Platform/Errors.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __ERRORS_H__ -#define __ERRORS_H__ - -enum ErrorIds_t { - ERROR_Application_Starting = 0 - ,ERROR_Eeprom_Read_Invalid_Length = 1 - ,ERROR_Eeprom_Read_Invalid_Address = 2 - ,ERROR_Eeprom_Write_Invalid_Length = 3 - ,ERROR_Eeprom_Write_Invalid_Address = 4 - ,ERROR_MAX = 5 -}; -#endif diff --git a/Platform/IErrorHandler.h b/Platform/IErrorHandler.h deleted file mode 100644 index 6f7c9b0..0000000 --- a/Platform/IErrorHandler.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __IERROR_HANDLER_H__ -#define __IERROR_HANDLER_H__ - -/** - * \brief well, except setting an error, there is not mutch to be - * done there. The handler might eventually trigger the communication - * handler to report the error or what ever. - */ -class IErrorHandler -{ - public: - IErrorHandler() {}; - /// - virtual setError(Uint16_t error_id) = 0 ; -}; -#endif