Improved ErrorHandler
authorEbersold <aebersol@n3150.home>
Mon, 13 Nov 2023 13:48:03 +0000 (14:48 +0100)
committerEbersold <aebersol@n3150.home>
Mon, 13 Nov 2023 13:48:03 +0000 (14:48 +0100)
Metadata/Errors.h [new file with mode: 0644]
Metadata/ParameterTable.h
Platform/CMakeLists.txt
Platform/ErrorHandler.h [deleted file]
Platform/ErrorHandler/ErrorHandler.cpp [new file with mode: 0644]
Platform/ErrorHandler/ErrorHandler.h [new file with mode: 0644]
Platform/ErrorHandler/IErrorHandler.h [new file with mode: 0644]
Platform/Errors.h [deleted file]
Platform/IErrorHandler.h [deleted file]

diff --git a/Metadata/Errors.h b/Metadata/Errors.h
new file mode 100644 (file)
index 0000000..c457426
--- /dev/null
@@ -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
index 45a52d08a3d1f1fa319257b2e2976154a24b2c6c..927d4f386dd6361bb1e3887a09b9769081e00c2e 100644 (file)
@@ -1,7 +1,17 @@
-#ifndef POWERSWITCHPARAMETERTABLE_H__
-#define POWERSWITCHPARAMETERTABLE_H__
+#ifndef __PARAMETERTABLE_H__
+#define __PARAMETERTABLE_H__
 
 #include "Metadata/Metadata.h"
+#ifdef POWERSWITCH_PARAMETERS
+#include <Metadata/PowerswitchParamIds.h>
+#elif defined(WORKMETER_PARAMETERS)
+#include <Metadata/WorkMeterParamIds.h>
+#elif defined(DCMOTOR_PARAMETERS)
+#include <Metadata/DCMotorParamIds.h>
+#elif defined(SHUTTERCTRL_PARAMETERS)
+#include <Metadata/ShutterCtrlParamIds.h>
+#endif
+
 extern
 ParameterValue m_Values[PID_MAX]; 
 #endif
index 3b9d0e22f8f4125e3e04089c04122193fbea9d7b..c225ef8d9fd4351bda51c822ad4a6e68caf4d87f 100644 (file)
@@ -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 (file)
index ff03c17..0000000
+++ /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 (file)
index 0000000..02bc74d
--- /dev/null
@@ -0,0 +1,49 @@
+#include <Utils/StdTypes.h>
+
+#include <Platform/IParameterHandler.h>
+
+#include <Metadata/ParameterTable.h>
+
+#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<Uin32_t>(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 (file)
index 0000000..5c81877
--- /dev/null
@@ -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 (file)
index 0000000..6f7c9b0
--- /dev/null
@@ -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 (file)
index c457426..0000000
+++ /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 (file)
index 6f7c9b0..0000000
+++ /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