I2C is working. I'm able to read seconds, minutes, and hours
authorandre Ebersold <andre.ebersold@free.fr>
Thu, 26 Oct 2023 20:30:28 +0000 (22:30 +0200)
committerandre Ebersold <andre.ebersold@free.fr>
Thu, 26 Oct 2023 20:30:28 +0000 (22:30 +0200)
15 files changed:
Application/WorkhourMeter/CMakeLists.txt
Application/WorkhourMeter/WorkMeterHandler.cpp [new file with mode: 0644]
Application/WorkhourMeter/WorkMeterHandler.h [new file with mode: 0644]
Application/WorkhourMeter/main.cpp
HAL/AVR/AvrI2C.cpp
HAL/AVR/AvrI2C.h
HAL/Abstract/II2C.h
HAL/Drivers/DS3231.cpp
Metadata/CMakeLists.txt
Metadata/ParameterTable.h [new file with mode: 0644]
Metadata/WorkMeterParamIds.h [new file with mode: 0644]
Metadata/WorkMeterParameterTable.cpp [new file with mode: 0644]
Platform/CMakeLists.txt
Platform/ParameterHandler.cpp [new file with mode: 0644]
Platform/ParameterHandler.h [new file with mode: 0644]

index 51e750693342a827e4be003f6ac95da9919463da..113c8a2208b284d14fd90b964a4a25ad12c6925b 100644 (file)
@@ -5,6 +5,7 @@ add_avr_executable(
    workmeter
    main.cpp
    Led0.cpp
+   WorkMeterHandler.cpp
    )
 
 target_link_libraries(
diff --git a/Application/WorkhourMeter/WorkMeterHandler.cpp b/Application/WorkhourMeter/WorkMeterHandler.cpp
new file mode 100644 (file)
index 0000000..03dd259
--- /dev/null
@@ -0,0 +1,38 @@
+#include "Utils/StdTypes.h"
+#include "Application/ITask.h"
+#include "Abstract/IRtc.h"
+#include "Platform/IParameterHandler.h"
+
+#include "Metadata/PowerswitchParamIds.h"
+#include "WorkMeterHandler.h"
+
+
+WorkMeterHandler::WorkMeterHandler(IRtc *argRtc,IParameterHandler *argPH)
+  : m_Rtc(argRtc), m_Params(argPH),m_Ticks(0)
+{
+    Uint8_t i = 0;     
+    m_Params->writeValue(PID_Switch1,i);
+    m_Params->writeValue(PID_Switch2,i);
+    m_Params->writeValue(PID_Switch3,i);
+    m_Time.seconds = 10;
+}
+
+void WorkMeterHandler::onWriteValue(const Uint8_t paramID,const Uint8_t _val) 
+{
+}
+
+void WorkMeterHandler::onWriteValue(const Uint8_t paramID,const Float32_t _val) 
+{
+}
+
+void WorkMeterHandler::run()
+{
+    if (m_Ticks++ > 50)
+    {
+        m_Rtc->getTime(m_Time);
+        m_Params->writeValue(PID_Switch1,m_Time.seconds);
+        m_Params->writeValue(PID_Switch2,m_Time.min);
+        m_Params->writeValue(PID_Switch3,m_Time.hour);
+        m_Ticks = 0;
+    }
+}
diff --git a/Application/WorkhourMeter/WorkMeterHandler.h b/Application/WorkhourMeter/WorkMeterHandler.h
new file mode 100644 (file)
index 0000000..f531120
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __WORKMETERHANDLER_H__
+#define __WORKMETERHANDLER_H__
+
+class WorkMeterHandler : public ITask, public  IParameterListener
+{
+    public:
+        WorkMeterHandler(IRtc *argRTC,IParameterHandler *argPH);
+
+        void run();
+
+        void onWriteValue(const Uint8_t paramID,const Uint8_t _val) ;
+        
+        void onWriteValue(const Uint8_t paramID,const Float32_t _val) ;
+    private:
+        IRtc *m_Rtc;
+        IParameterHandler *m_Params;
+        RtcTime_t          m_Time;
+        Uint32_t           m_Ticks;
+};
+
+#endif
index dfde31d0cecce255dd900b71b1dc3c539b228131..126bdfdd38b08575bafe509336a50ada523f6279 100644 (file)
@@ -31,6 +31,7 @@
 #include <Drivers/NetString.h>
 #include <Drivers/DS3231.h>
 #include "Led0.h"
+#include "WorkMeterHandler.h"
 #if 0
 #include "Switch.h"
 #include "PowerswitchHandler.h"
@@ -67,14 +68,14 @@ class Scheduler : public IInterruptActivity
 
       static Task_type gTasks[TASK_COUNT];
   public:
-    Scheduler(Led0 *_led,IProtocolLayer2 *_net,CommunicationHandler *_com,IRtc *_argRtc
+    Scheduler(Led0 *_led,IProtocolLayer2 *_net,CommunicationHandler *_com,ITask *_argRtc
                    ,ITask *_Storage
                    )
       : 
               m_Led(_led)
               , m_Netstring(_net)
               , m_Com(_com)
-              , m_Rtc(_argRtc)
+              , m_WorkMeter(_argRtc)
              , m_Storage(_Storage)
               , m_CurrentTimeslot(FIRST_TIME_SLOT)
               , m_CurrentTask(TASK1)
@@ -89,7 +90,7 @@ class Scheduler : public IInterruptActivity
         {
             case TASK1:
                //m_Adc->run();
-               m_Rtc->getTime(m_Time);
+               m_WorkMeter->run();
                 //m_Led->tick();
             break;
             case TASK2:
@@ -132,7 +133,7 @@ class Scheduler : public IInterruptActivity
     Led0                   *m_Led;
     IProtocolLayer2        *m_Netstring;
     CommunicationHandler   *m_Com;
-    IRtc                   *m_Rtc;
+    ITask                  *m_WorkMeter;
     ITask                  *m_Storage;
     volatile TIME_SLOTS     m_CurrentTimeslot;
     ETASK_ID                m_CurrentTask;
@@ -173,7 +174,8 @@ int main(void)
    NetString            netstring(&uart);
    CommunicationHandler gCom(&netstring,&gParam);
    PersistentStorage    gStorage(&gEeprom,&gParam);
-   Scheduler            sched(&led,&netstring,&gCom,&gRtc,&gStorage);
+   WorkMeterHandler     gWorkMeter(&gRtc,&gParam);
+   Scheduler            sched(&led,&netstring,&gCom,&gWorkMeter,&gStorage);
 
    uart.init();
    gI2c.init();
index e76bc7b248da33141574e8606ee225d286ba0ce0..167d6d264a684f0b63c145ee8bda26b4876de9ae 100644 (file)
 #endif
 #define SCL_CLOCK 400000
 
+#define START
+#define MT_SLA_ACK
+#define TW_SDA_PIN PORTC4
+#define TW_SCL_PIN PORTC5
+
+#define I2C_ERROR   0
+#define I2C_SUCCESS 1
+
 AvrI2C::AvrI2C()
+  : m_Received(0)
 {
 }
 
 void AvrI2C::init()
 {
     TWSR = 0;                         // no prescaler
-    TWBR = ((F_CPU/SCL_CLOCK)-16)/2; 
-    TWCR = (1<<(TWINT))|(1<<TWSTA )|(1<<TWEN);
+    //TWBR = ((F_CPU/SCL_CLOCK)-16)/2; 
+    // 16Mhz / (16 + 2*12*1) = 400Khz
+    TWBR = 12; 
+    PRR   &= ~(1<<PRTWI);
+    DDRC  |= (1<<TW_SDA_PIN) | (1 <<TW_SCL_PIN);
+    // Enable Pull UP
+    PORTC |= (1<<TW_SDA_PIN) | (1 <<TW_SCL_PIN);
+    // Disable Pull Up
+    //PORTC &= ~((1<<TW_SDA_PIN) | (1 <<TW_SCL_PIN));
+    DDRC  &= ~((1<<TW_SDA_PIN) | (1 <<TW_SCL_PIN));
+
+    //TWCR = (1<<(TWINT))|(1<<TWSTA )|(1<<TWEN);
+
 #if 0
     printf("TWCR 0x%x \n",TWCR);
 #endif
-    while( !( TWCR & (1<< TWINT) ) ) ;
+    //while( !( TWCR & (1<< TWINT) ) ) ;
 #if 0
     printf(" Start condition has been transmitted \n");
     if( (TWSR&0xF8) != TW_START)
@@ -31,27 +51,165 @@ void AvrI2C::init()
      printf(" Error \n");
     }
 #endif
+#if 0    
     // Setting Address 
     TWDR = 0x1C; 
     // cleating TWCR 
     TWCR = (1<<TWINT) |(1<<TWEN);
 
-    while ( !(TWCR & (1<<TWINT))) ; 
+    while ( !(TWCR & (1<<TWINT))) ;
+#endif    
+#if 0
     if ((TWSR & 0xF8) != TW_MT_SLA_ACK)
     {
-#if 0
        printf(" Error at TWSR   0x%x\n", TWSR);  // here is the problem !!!!!!!!!  TWSR value should be 0x18
-#endif
        return; 
     }        
+#endif
 }
 
-void AvrI2C::write(Uint8_t argAddress,Uint8_t *argData,Uint8_t argLen)
+II2C::Error_t AvrI2C::write(const Uint8_t argAddress,Uint8_t *argData,Uint8_t argLen)
 {
-    return;
+    if ( ! start() )
+        return I2C_ERROR;
+    if ( ! sendSla(argAddress) )
+        return I2C_ERROR;
+
+    for (Uint8_t i = 0; i < argLen ; i++)
+    {
+        if (  ! sendByte(argData[i]) )
+          return I2C_ERROR;
+    }
+    stop() ;
+
+    return I2C_SUCCESS;
 }
 
-void AvrI2C::read(Uint8_t argAddress,Uint8_t *argData,Uint8_t argLen)
+II2C::Error_t AvrI2C::read(const Uint8_t argAddress,Uint8_t *argData,Uint8_t argLen)
 {
-    return;
+    if ( ! start() )
+        return I2C_ERROR;
+
+    if (  ! sendSla( (argAddress | 1 ) ) )
+        return I2C_ERROR;
+    for (Uint8_t i = 0; i < argLen -1  ; ++i)
+    {
+        if (  ! receiveByte(&argData[i],true) )
+            return I2C_ERROR;
+    }
+    if (  ! receiveByte(&argData[argLen-1],false) )
+        return I2C_ERROR;
+    stop();
+    
+    return I2C_SUCCESS;
+
 }
+/**
+ *
+ */
+II2C::Error_t AvrI2C::read( const Uint8_t argSlaAddress
+     , const Uint8_t regAddress
+     , Uint8_t *argData
+     , Uint8_t argLen)
+{
+    Uint8_t cmd[2];
+    cmd[0] = regAddress;
+    cmd[1] = 0x00;
+
+    argData[0] = 129;
+
+    write(argSlaAddress,cmd,1);
+    if (  ! start() )
+    {
+        return I2C_ERROR;
+    }
+    if (  ! sendSla(argSlaAddress | 0x01 ) )
+    {
+        return I2C_ERROR;
+    } 
+    
+    for (Uint8_t i = 0; i < argLen -1; i++)
+    {
+        if (  ! receiveByte(&argData[i],true) )
+        {
+          return I2C_ERROR;
+        } 
+    }
+    if (  ! receiveByte(&argData[argLen - 1],false) )
+    {
+          return I2C_ERROR;
+    } 
+    stop(); 
+    return I2C_SUCCESS;
+}
+/* Send Start condition
+ * \return true on success false on fail send
+ */
+Bool_t AvrI2C::start()
+{
+    TWCR = ( 1<<TWINT ) | ( 1<<TWSTA ) |( 1<<TWEN ) ;
+    while (! (TWCR & ( 1<<TWINT) ) ) ;
+
+    return ( (TW_STATUS == TW_START) || (TW_STATUS == TW_REP_START) ) ;
+}
+
+/* Send Slave Address
+ * \return true on success false on fail send
+ */
+Bool_t AvrI2C::sendSla(Uint8_t argAddress)
+{
+    TWDR = argAddress ;
+    TWCR = ( 1<<TWINT ) | ( 1<<TWEN ) ;
+    while (! (TWCR & ( 1<<TWINT) ) ) ;
+
+    return ( (TW_STATUS == TW_MT_SLA_ACK) || (TW_STATUS == TW_MR_SLA_ACK) ) ;
+}
+/* Write Byte Data
+ * \return true on success false on fail send
+ */
+Bool_t AvrI2C::sendByte(Uint8_t argData)
+{
+    TWDR = argData;
+    TWCR = ( 1<<TWINT ) | ( 1<<TWEN ) ;
+    while (! (TWCR & ( 1<<TWINT) ) ) ;
+
+    return ( TW_STATUS == TW_MT_DATA_ACK ) ;
+}
+/* Write Byte Data
+ * \return true on success false on fail send
+ */
+Bool_t AvrI2C::receiveByte(Uint8_t *argData,Bool_t receive_ack )
+{
+    Bool_t status = true;
+    if ( receive_ack)
+    {
+        TWCR = ( 1<<TWINT ) | ( 1<<TWEN ) | ( 1<<TWEA) ;
+        
+        while (! (TWCR & ( 1<<TWINT) ) ) ;
+
+        status = !( ( TWSR & 0xF8 ) != TW_MR_DATA_ACK ) ;
+    } 
+    else
+    {
+        TWCR = ( 1<<TWINT ) | ( 1<<TWEN )  ;
+        
+        while (! (TWCR & ( 1<<TWINT) ) ) ;
+
+        status = !( ( TWSR & 0xF8 ) != TW_MR_DATA_NACK ) ;
+    }
+    argData[0] = TWDR;
+    return status;
+}
+/* Send Stop
+ * \return true on success false on fail send
+ */
+Bool_t AvrI2C::stop()
+{
+    TWCR = ( 1<<TWINT ) | ( 1<<TWSTO ) | ( 1<<TWEN ) ;
+    //while (! (TWCR & ( 1<<TWINT) ) ) ;
+    return true;
+    //return !( ( TWSR & 0xF8 ) != TW_STOP ) ;
+}
+
+
+/* vim: set et sw=4 ts=4 list: */
index 47d9abf37e45931c342007f60a8fbec9a2323403..877d9db560c601d8667b1b77eeea94c3be3eb4a1 100644 (file)
@@ -8,10 +8,54 @@ class AvrI2C : public II2C
 
         void init();
 
-        void write(Uint8_t argAddress,Uint8_t *argData,Uint8_t argLen);
-        
-        void read(Uint8_t argAddress,Uint8_t *argData,Uint8_t argLen);
+        /**
+         *
+         * \return 0 on Success
+         */
+        Error_t write( const Uint8_t argSlaAddress
+                  , Uint8_t *argData
+                  , Uint8_t argLen);
         
+        /**
+         *
+         * \return 0 on Success
+         */
+        Error_t read( const Uint8_t argSlaAddress
+                 , Uint8_t *argData
+                 , Uint8_t argLen);
+        /**
+         *
+         * \return 0 on Success
+         */
+        Error_t read( const Uint8_t argSlaAddress
+                 , const Uint8_t regAddress
+                 , Uint8_t *argData
+                 , Uint8_t argLen);
+    private:
+      
+        /* Send Start condition
+         * \return true on success false on fail send
+         */
+        Bool_t start();
+
+        /* Send Slave Address
+         * \return true on success false on fail send
+         */
+        Bool_t sendSla(Uint8_t argAddre);
+        /* Write Byte Data
+         * \return true on success false on fail send
+         */
+        Bool_t sendByte(Uint8_t argData);
+        /* Write Byte Data
+         * \return true on success false on fail send
+         */
+        Bool_t receiveByte(Uint8_t *argData,Bool_t receive_ack = false);
+        /* Send Stop
+         * \return true on success false on fail send
+         */
+        Bool_t stop();
+    private:
+        Uint8_t m_Received;
 };
 
 /* vim: set et sw=4 ts=4 list: */
index a8fc34f87e5c7fb66607113272c72da33ec0515f..82d7268a1e38c01b4b6f22b2618012ef7a5dfc5f 100644 (file)
@@ -4,11 +4,17 @@
 class II2C
 {
     public:
+        typedef Uint8_t Error_t;
     II2C() {};
 
-    virtual void write(Uint8_t argAddress,Uint8_t *argData, Uint8_t argLen);
+    virtual Error_t write(const Uint8_t argAddress,Uint8_t *argData, Uint8_t argLen) = 0;
 
-    virtual void read(Uint8_t argAddress,Uint8_t *argData ,Uint8_t argLen);
+    virtual Error_t read(const Uint8_t argAddress,Uint8_t *argData ,Uint8_t argLen) = 0;
+    
+    virtual Error_t read( const Uint8_t argAddress
+                    , const Uint8_t regAddr
+                    , Uint8_t *argData
+                    , Uint8_t argLen) = 0;
 };
 
 #endif
index 755d03fdd8532d621434e6153f85fa49f8bffa90..fb617a1e911e712af19d9a3a43cbcf96edce7b15 100644 (file)
@@ -4,6 +4,7 @@
 #include "Drivers/DS3231.h"
 
 #define DS3231_ADDRESS 0xD0
+//#define DS3231_ADDRESS 0xDE
 
 DS3231::DS3231(II2C *argI2c)
  : itsII2C(argI2c)
@@ -14,11 +15,24 @@ DS3231::DS3231(II2C *argI2c)
 
 void DS3231::getTime(RtcTime_t &argTime)
 {
-    Uint8_t cmd[2] ; 
-    cmd[0] = 0x00;
-    itsII2C->read(DS3231_ADDRESS,cmd,2);
-
-    argTime.seconds = cmd[1];
+    Uint8_t cmd[9] ; 
+    cmd[0] = 0x00; cmd[1] = 128;
+#if 1    
+    Bool_t success = itsII2C->read(DS3231_ADDRESS,cmd[0],&cmd[1],8);
+   
+    if (!success)
+    {
+        argTime.seconds = 255;
+    } else
+    {
+        argTime.seconds = (cmd[1] & 0x0F) + ( ( (cmd[1]>>4) & 0x07) * 10);
+        argTime.min     = (cmd[2] & 0x0F) + ( ( (cmd[2]>>4) & 0x07) * 10);
+        argTime.hour    = (cmd[3] & 0x0F) + ( ( (cmd[3]>>4) & 0x03) * 10);
+    }
+#else
+    itsII2C->write(DS3231_ADDRESS,cmd,1);
+    itsII2C->read(DS3231_ADDRESS,&argTime.seconds,1);
+#endif
 }
 
 void DS3231::setTime(const RtcTime_t &argTime)
index 37acbe5d5f913988ed03f3d4c8792d1df3bb8af4..f6cb12bc3815d3b2d844cce160b0b9891e6d8a24 100644 (file)
@@ -2,17 +2,22 @@
 # simple AVR library
 #####################################################################
 add_avr_library(
-       avrPowerswitchParameters
-       PowerswitchParameterTable.cpp
+    avrPowerswitchParameters
+    PowerswitchParameterTable.cpp
    )
 
 add_avr_library(
-       avrDCMotorParameters
-       DCMotorParameterTable.cpp
+    avrDCMotorParameters
+    DCMotorParameterTable.cpp
    )
 
 add_avr_library(
-       avrShutterCtrlParameters
-       ShutterCtrlParameterTable.cpp
+    avrShutterCtrlParameters
+    ShutterCtrlParameterTable.cpp
+   )
+
+add_avr_library(
+    avrWorkMeterParameters
+    WorkMeterParameterTable.cpp
    )
 
diff --git a/Metadata/ParameterTable.h b/Metadata/ParameterTable.h
new file mode 100644 (file)
index 0000000..45a52d0
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef POWERSWITCHPARAMETERTABLE_H__
+#define POWERSWITCHPARAMETERTABLE_H__
+
+#include "Metadata/Metadata.h"
+extern
+ParameterValue m_Values[PID_MAX]; 
+#endif
diff --git a/Metadata/WorkMeterParamIds.h b/Metadata/WorkMeterParamIds.h
new file mode 100644 (file)
index 0000000..78a641f
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __DCMOTORPARAMIDS_H__
+#define __DCMOTORPARAMIDS_H__
+
+
+/**
+ * Maybe put this in an include file
+ * DCMotorParamIds.h
+ */
+enum ParameterIds {
+      PID_SwitchAll  =  0 /* State on or off */
+    , PID_Switch1    =  1 /* On / Off Socket 1 */
+    , PID_Switch2    =  2 /* On / Off Socket 2 */
+    , PID_Switch3    =  3 /* On / Off Socket 3 */
+    , PID_Switch4    =  4 /* On / Off Socket 4 */
+    , PID_LedCycle   =  5 /* Ye Blinking led cycle. 0 is off */
+    , PID_LedState   =  6 /* Set let state ... */
+    , PID_DelayP1    =  7
+    , PID_DelayP2    =  8
+    , PID_DelayP3    =  9 /* Cycle Per rotation used in closed loop  */
+    , PID_DelayP4    = 10 /* Set PID constant factor   */
+    , PID_Ki         = 11 /* Set PID integral factor   */
+    , PID_Kd         = 12 /* Set PID derivation factor */
+    , PID_MAConsPwm  = 13 /* Pwm modulation instruction, Applied in open loop, ignore in closed loop */
+    , PID_MAConsRpm  = 14 /* Rpm instruction used as reference in closed loop */
+    , PID_LowLevelError1  = 15 /* Low Level Error1  up to 32 errors */
+    , PID_LowLevelError2  = 16 /* Low Level Error2  up to 32 errors */
+    , PID_MAX        = 17
+};
+#endif
diff --git a/Metadata/WorkMeterParameterTable.cpp b/Metadata/WorkMeterParameterTable.cpp
new file mode 100644 (file)
index 0000000..a2cdf6b
--- /dev/null
@@ -0,0 +1,29 @@
+#include <Utils/StdTypes.h>
+#include <stdlib.h> // for itoa
+#include "Metadata/Metadata.h"
+#include "Platform/IParameterHandler.h"
+#include "WorkMeterParamIds.h"
+#include "ParameterTable.h"
+
+
+ParameterValue m_Values[PID_MAX] =
+{
+  {0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+  ,{0,NULL}
+
+};
index 244b2d2244065acb9e4d9252f471fa24fc866047..283bf362cf1017cde0ff665cff4c926364f9ceba 100644 (file)
@@ -7,15 +7,49 @@ add_avr_library(
     PersistentStorage.cpp
    )
 
+set_target_properties(
+    avrPtf${MCU_TYPE_FOR_FILENAME} PROPERTIES
+    COMPILE_DEFINITIONS DCMOTOR_PARAMETERS
+)
+
+#
+#
+#
 add_avr_library(
     avrPS-Ptf
     PowerswitchParameterHandler.cpp
     PersistentStorage.cpp
    )
 
+set_target_properties(
+    avrPtf${MCU_TYPE_FOR_FILENAME} PROPERTIES
+    COMPILE_DEFINITIONS POWERSWITCH_PARAMETERS
+)
+#
+#
+#
 add_avr_library(
     avrSC-Ptf
     ShutterCtrlParameterHandler.cpp
     PersistentStorage.cpp
    )
 
+set_target_properties(
+    avrPtf${MCU_TYPE_FOR_FILENAME} PROPERTIES
+    COMPILE_DEFINITIONS SHUTTERCTRL_PARAMETERS
+)
+
+#
+#
+#
+add_avr_library(
+    avrWM-Ptf
+    ParameterHandler.cpp
+    PersistentStorage.cpp
+   )
+
+set_target_properties(
+    avrWM-Ptf${MCU_TYPE_FOR_FILENAME} PROPERTIES
+    COMPILE_DEFINITIONS WORKMETER_PARAMETERS
+)
+
diff --git a/Platform/ParameterHandler.cpp b/Platform/ParameterHandler.cpp
new file mode 100644 (file)
index 0000000..345c4ce
--- /dev/null
@@ -0,0 +1,97 @@
+#include <Utils/StdTypes.h>
+
+#include <Platform/IParameterHandler.h>
+#ifdef POWERSWITCH_PARAMETERS
+#include <Metadata/PowerswitchParamIds.h>
+#include <Metadata/PowerswitchParameterTable.h>
+#elif defined(WORKMETER_PARAMETERS)
+#include <Metadata/WorkMeterParamIds.h>
+#include <Metadata/ParameterTable.h>
+#endif
+#include <Platform/ParameterHandler.h>
+
+ParameterHandler::ParameterHandler()
+{
+  
+}
+///
+void
+ParameterHandler::readValue(const uint8_t paramID,uint8_t &_val)
+{
+    if (paramID < PID_MAX)
+    {
+        _val = m_Values[paramID].u.m_U8;
+    } 
+}
+
+///
+void
+ParameterHandler::writeValue(const uint8_t paramID,const uint8_t _val)
+{
+    if (paramID < PID_MAX)
+    {
+        m_Values[paramID].u.m_U8 = _val;
+        if (m_Values[paramID].m_Listener != 0 )
+        {
+            m_Values[paramID].m_Listener->onWriteValue(paramID,_val);
+        }
+    } 
+}
+
+/// Handle UInt16_t
+void
+ParameterHandler::readValue(const uint8_t paramID,uint16_t &_val)
+{
+    if (paramID < PID_MAX)
+    {
+        _val = m_Values[paramID].u.m_U16;
+    } 
+}
+
+///
+void
+ParameterHandler::writeValue(const uint8_t paramID,const uint16_t _val)
+{
+    if (paramID < PID_MAX)
+    {
+        m_Values[paramID].u.m_U16 = _val;
+        if (m_Values[paramID].m_Listener != 0 )
+        {
+            m_Values[paramID].m_Listener->onWriteValue(paramID,m_Values[paramID].u.m_U8);
+        }
+    } 
+}
+
+/// Handle Float32_t
+void
+ParameterHandler::readValue(const uint8_t paramID,Float32_t &_val)
+{
+    if (paramID < PID_MAX)
+    {
+        _val = m_Values[paramID].u.m_Float;
+    } 
+}
+
+///
+void
+ParameterHandler::writeValue(const uint8_t paramID,const Float32_t _val)
+{
+    if (paramID < PID_MAX)
+    {
+        m_Values[paramID].u.m_Float = _val;
+        if (m_Values[paramID].m_Listener != 0 )
+        {
+            m_Values[paramID].m_Listener->onWriteValue(paramID,m_Values[paramID].u.m_Float);
+        }
+    } 
+}
+
+void 
+ParameterHandler::registerListener(const uint8_t paramID,IParameterListener *_val)
+{
+    if (paramID < PID_MAX)
+    {
+        m_Values[paramID].m_Listener = _val;
+    } 
+
+}
diff --git a/Platform/ParameterHandler.h b/Platform/ParameterHandler.h
new file mode 100644 (file)
index 0000000..5b75a53
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef __PARAMETERHANDLER_H__
+#define __PARAMETERHANDLER_H__
+
+
+/**
+ * @brief storage class 
+ *
+ */
+class ParameterHandler : public IParameterHandler
+{
+    public:
+        ParameterHandler();
+        ///
+        virtual void readValue(const uint8_t paramID,uint8_t &_val);
+        ///
+        virtual void writeValue(const uint8_t paramID,const uint8_t _val);
+        ///
+        virtual void readValue(const uint8_t paramID,uint16_t &_val);
+        ///
+        virtual void writeValue(const uint8_t paramID,const uint16_t _val);
+        
+       ///
+        virtual void readValue(const uint8_t paramID,Float32_t &_val) ;
+        ///
+        virtual void writeValue(const uint8_t paramID,const Float32_t _val) ;
+        ///
+        ///
+        virtual void registerListener(const uint8_t paramID,IParameterListener *_val);
+
+
+    private:
+};
+
+#endif