#include <AVR/AvrPwm.h>
#include <Platform/IParameterHandler.h>
#include <Metadata/DCMotorParamIds.h>
-#include <Platform/DCMotorParameterHandler.h>
+#include <Platform/ParameterHandler.h>
#include <Platform/PersistentStorage.h>
#include <Communication/CommunicationHandler.h>
int main(void)
{
Timer1 lCounter;
- DCMotorParameterHandler gParam;
+ ParameterHandler gParam;
#if defined (__AVR_ATmega32U4__)
Led0 led(&PORTC, &DDRC, PINB7,&gParam);
AvrPwm pwmA;
#include <AVR/AvrEeprom.h>
#include <Platform/IParameterHandler.h>
#include <Metadata/PowerswitchParamIds.h>
-#include <Platform/PowerswitchParameterHandler.h>
+#include <Platform/ParameterHandler.h>
#include <Platform/PersistentStorage.h>
#include <Communication/CommunicationHandler.h>
*/
int main(void)
{
- PowerswitchParameterHandler gParam;
+ ParameterHandler gParam;
#if defined (__AVR_ATmega32U4__)
Led0 led(&PORTC, &DDRC, PINB7,&gParam);
#else
//#include <AVR/AvrPwm.h>
#include <Platform/IParameterHandler.h>
#include <Metadata/ShutterCtrlParamIds.h>
-#include <Platform/ShutterCtrlParameterHandler.h>
+#include <Platform/ParameterHandler.h>
#include <Platform/PersistentStorage.h>
#include <Communication/CommunicationHandler.h>
int main(void)
{
Timer1 lCounter;
- ShutterCtrlParameterHandler gParam;
+ ParameterHandler gParam;
Led0 led(&PORTB, &DDRB, PINB5,&gParam);
AvrUart uart(IUart::BAUD_9600,IUart::PARITY_NONE,IUart::STB_ONE);
AvrEeprom gEeprom;
main.cpp
Led0.cpp
WorkMeterHandler.cpp
+ Scheduler.cpp
)
target_link_libraries(
--- /dev/null
+#include <Utils/StdTypes.h>
+#include <util/delay.h>
+
+#include <Abstract/IInterruptActivity.h>
+#include <Abstract/IProtocolLayer2.h>
+#include <Abstract/IUart.h>
+#include <Abstract/II2C.h>
+#include <Abstract/IRtc.h>
+#include <Abstract/ILCD.h>
+#include "Abstract/RFID/IPN532Interface.h"
+#include <Abstract/IEeprom.h>
+#include <Application/ITask.h>
+#include <Platform/IParameterHandler.h>
+#include <Platform/ErrorHandler/IErrorHandler.h>
+#include <Metadata/WorkmeterParamIds.h>
+#include <Platform/ParameterHandler.h>
+
+#include "Led0.h"
+
+#include "Scheduler.h"
+
+
+
+Scheduler::Scheduler( Led0 *_led,IProtocolLayer2 *_net
+ , ITask *_com
+ , ITask *_argRtc
+ , ITask *_Storage
+ , ITask *_RFIDReader
+ )
+ :
+ m_Led(_led)
+ , m_Netstring(_net)
+ , m_Com(_com)
+ , m_WorkMeter(_argRtc)
+ , m_Storage(_Storage)
+ , m_RFIDReader(_RFIDReader)
+ , m_CurrentTimeslot(FIRST_TIME_SLOT)
+ , m_CurrentTask(TASK1)
+ {
+ }
+// main entry point
+void Scheduler::schedule()
+{
+
+static const Scheduler::pFunction_t task[3] = {
+ &Scheduler::doTask1
+ , &Scheduler::doTask2
+ , &Scheduler::doTask3
+};
+
+
+ waitForTimeslot();
+ m_Com->run();
+#if 1
+ (this->*(task[m_CurrentTask]))();
+#else
+ switch (m_CurrentTask)
+ {
+ case TASK1:
+ //m_Adc->run();
+ m_WorkMeter->run();
+ //m_Led->tick();
+ break;
+ case TASK2:
+ m_Led->tick();
+ m_RFIDReader->run();
+ break;
+ case TASK3:
+ m_Led->tick();
+ m_Storage->run();
+ break;
+ default:
+ ;
+
+ }
+#endif
+ m_CurrentTask = gTasks[m_CurrentTask].m_NextTask;
+}
+
+void Scheduler::doTask1()
+{
+ m_WorkMeter->run();
+}
+void Scheduler::doTask2()
+{
+ m_Led->tick();
+ m_RFIDReader->run();
+}
+void Scheduler::doTask3()
+{
+ m_Led->tick();
+ m_Storage->run();
+}
+
+// called by the interrupt timer handler
+void Scheduler::tick()
+{
+ m_CurrentTimeslot = (m_CurrentTimeslot < LAST_TIME_SLOT)
+ ? (TIME_SLOTS)(m_CurrentTimeslot+1)
+ : (FIRST_TIME_SLOT);
+ m_Netstring->tick();
+}
+
+void Scheduler::waitForTimeslot( void )
+{
+ /// prevent instant scheduling
+ while (m_CurrentTimeslot == gTasks[m_CurrentTask].m_FirstTimeslot )
+ {
+ ;
+ }
+ // beginning of the timeslot
+ while (m_CurrentTimeslot != gTasks[m_CurrentTask].m_FirstTimeslot )
+ {
+ ;
+ }
+}
+
+
+Scheduler::Task_type Scheduler::gTasks[TASK_COUNT] = {
+ { FIRST_TIME_SLOT , TASK2 }
+ , { BLOCK2_FIRST_TIME_SLOT, TASK3 }
+ , { BLOCK3_FIRST_TIME_SLOT, TASK1 }
+};
+
--- /dev/null
+#ifndef __SCHEDULER_H__
+#define __SCHEDULER_H__
+
+/**
+ * @brief the scheduler will still slice the execution
+ * flow. The whole cycle is now 40 ticks !
+ * 40 *
+ * 250ns * 4 = 1us * 10 = 10 us. On fast devices.
+ *
+ * 16MHz / 8 / 256 = 100us each tick
+ *
+ */
+class Scheduler : public IInterruptActivity
+{
+ typedef void (Scheduler::*pFunction_t)();
+ private:
+ enum TIME_SLOTS {
+ FIRST_TIME_SLOT = 0,
+ BLOCK2_FIRST_TIME_SLOT = 30,
+ BLOCK3_FIRST_TIME_SLOT = 60,
+ LAST_TIME_SLOT = 99,
+ TIME_SLOT_COUNT = 99 // :( not used
+ };
+ enum ETASK_ID {
+ TASK1 = 0,
+ TASK2 = 1,
+ TASK3 = 2,
+ TASK_COUNT = 3
+ };
+ typedef struct Task_t {
+ TIME_SLOTS m_FirstTimeslot;
+ ETASK_ID m_NextTask;
+ } Task_type ;
+
+ static Task_type gTasks[TASK_COUNT];
+ private:
+ Led0 *m_Led;
+ IProtocolLayer2 *m_Netstring;
+ ITask *m_Com;
+ ITask *m_WorkMeter;
+ ITask *m_Storage;
+ ITask *m_RFIDReader;
+ volatile TIME_SLOTS m_CurrentTimeslot;
+ ETASK_ID m_CurrentTask;
+ RtcTime_t m_Time;
+ private:
+ void doTask1();
+
+ void doTask2();
+ void doTask3();
+ public:
+ Scheduler( Led0 *_led,IProtocolLayer2 *_net
+ , ITask *_com
+ , ITask *_argRtc
+ , ITask *_Storage
+ , ITask *_RFIDReader
+ );
+
+ // main entry point
+ void schedule();
+
+ // called by the interrupt timer handler
+ virtual void tick();
+
+ private:
+ void waitForTimeslot( void ) ;
+};
+
+#endif
#include <Platform/RFIDReader/RFIDReaderHandler.h>
#include "Led0.h"
#include "WorkMeterHandler.h"
-#if 0
-#include "Switch.h"
-#include "PowerswitchHandler.h"
-#endif
+#include "Scheduler.h"
+
/**
* @brief the scheduler will still slice the execution
* flow. The whole cycle is now 40 ticks !
* 16MHz / 8 / 256 = 100us each tick
*
*/
-class Scheduler : public IInterruptActivity
-{
- typedef void (Scheduler::*pFunction_t)();
- private:
- enum TIME_SLOTS {
- FIRST_TIME_SLOT = 0,
- BLOCK2_FIRST_TIME_SLOT = 30,
- BLOCK3_FIRST_TIME_SLOT = 60,
- LAST_TIME_SLOT = 99,
- TIME_SLOT_COUNT = 99 // :( not used
- };
- enum ETASK_ID {
- TASK1 = 0,
- TASK2 = 1,
- TASK3 = 2,
- TASK_COUNT = 3
- };
- typedef struct Task_t {
- TIME_SLOTS m_FirstTimeslot;
- ETASK_ID m_NextTask;
- } Task_type ;
-
- static Task_type gTasks[TASK_COUNT];
- private:
- Led0 *m_Led;
- IProtocolLayer2 *m_Netstring;
- CommunicationHandler *m_Com;
- ITask *m_WorkMeter;
- ITask *m_Storage;
- ITask *m_RFIDReader;
- volatile TIME_SLOTS m_CurrentTimeslot;
- ETASK_ID m_CurrentTask;
- RtcTime_t m_Time;
- private:
- void doTask1()
- {
- m_WorkMeter->run();
- }
- void doTask2()
- {
- m_Led->tick();
- m_RFIDReader->run();
- }
- void doTask3()
- {
- m_Led->tick();
- m_Storage->run();
- }
- public:
- Scheduler( Led0 *_led,IProtocolLayer2 *_net
- , CommunicationHandler *_com
- , ITask *_argRtc
- , ITask *_Storage
- , ITask *_RFIDReader
- )
- :
- m_Led(_led)
- , m_Netstring(_net)
- , m_Com(_com)
- , m_WorkMeter(_argRtc)
- , m_Storage(_Storage)
- , m_RFIDReader(_RFIDReader)
- , m_CurrentTimeslot(FIRST_TIME_SLOT)
- , m_CurrentTask(TASK1)
- {
- }
- // main entry point
- void schedule()
- {
-
- static const Scheduler::pFunction_t task[3] = {
- &Scheduler::doTask1
- , &Scheduler::doTask2
- , &Scheduler::doTask3
- };
-
-
- waitForTimeslot();
- m_Com->run();
-#if 1
- (this->*(task[m_CurrentTask]))();
-#else
- switch (m_CurrentTask)
- {
- case TASK1:
- //m_Adc->run();
- m_WorkMeter->run();
- //m_Led->tick();
- break;
- case TASK2:
- m_Led->tick();
- m_RFIDReader->run();
- break;
- case TASK3:
- m_Led->tick();
- m_Storage->run();
- break;
- default:
- ;
-
- }
-#endif
- m_CurrentTask = gTasks[m_CurrentTask].m_NextTask;
- }
-
- // called by the interrupt timer handler
- virtual void tick()
- {
- m_CurrentTimeslot = (m_CurrentTimeslot < LAST_TIME_SLOT)
- ? (TIME_SLOTS)(m_CurrentTimeslot+1)
- : (FIRST_TIME_SLOT);
- m_Netstring->tick();
- }
-
- private:
- void waitForTimeslot( void )
- {
- /// prevent instant scheduling
- while (m_CurrentTimeslot == gTasks[m_CurrentTask].m_FirstTimeslot )
- {
- ;
- }
- // beginning of the timeslot
- while (m_CurrentTimeslot != gTasks[m_CurrentTask].m_FirstTimeslot )
- {
- ;
- }
- }
-
-
-};
-
-Scheduler::Task_type Scheduler::gTasks[TASK_COUNT] = {
- { FIRST_TIME_SLOT , TASK2 }
- , { BLOCK2_FIRST_TIME_SLOT, TASK3 }
- , { BLOCK3_FIRST_TIME_SLOT, TASK1 }
-};
-
/**
* \brief Init database ....
*/
#else
Led0 led(&PORTB, &DDRB, PINB5,&gParam);
#endif
- AvrUart uart(IUart::BAUD_9600,IUart::PARITY_NONE,IUart::STB_ONE);
+ AvrUart uart(IUart::BAUD_19200,IUart::PARITY_NONE,IUart::STB_ONE);
AvrI2C gI2c;
DS3231 gRtc(&gI2c);
LiquidCrystal lcd(&gI2c
msg[0]= static_cast<Uint8_t >( (ver >>16 & 0xFF) + 48 );
msg[1]= static_cast<Uint8_t >( (ver >>8 & 0xFF ) + 48 );
lcd.print(msg);
- nfc.setPassiveActivationRetries(0x01);
+ nfc.setPassiveActivationRetries(0x03);
nfc.SAMConfig();
lTimer.init();
init(&gParam);
#include <Metadata/DCMotorParamIds.h> // To be removed
#endif
#include <Platform/IParameterHandler.h>
+#include <Application/ITask.h>
+#include <Metadata/Metadata.h>
#include <Communication/CommunicationHandler.h>
CommunicationHandler::CommunicationHandler(IProtocolLayer2 *_l2,IParameterHandler *_p)
#endif
case 'M':
{
- parse_msg(msg,len ,IParameterHandler::TYPE_U16);
+ parse_msg(msg,len ,TYPE_U16);
}
break;
case 'L':
{
- parse_msg(msg,len ,IParameterHandler::TYPE_U32);
+ parse_msg(msg,len ,TYPE_U32);
}
break;
case 'F':
{
- parse_msg(msg,len ,IParameterHandler::TYPE_FLOAT);
+ parse_msg(msg,len ,TYPE_FLOAT);
}
break;
default:
#define OUTPUT_BUFFER_SIZE 32
void
-CommunicationHandler::parse_msg(const Uint8_t *_msg,const Uint8_t len,IParameterHandler::eParameterType _eType)
+CommunicationHandler::parse_msg(const Uint8_t *_msg,const Uint8_t len,eParameterType _eType)
{
uint32_t nv = 0;
uint32_t val = 0;
}
if ( _msg[pos] == '=' )
{
- if (_eType == IParameterHandler::TYPE_FLOAT)
+ if (_eType == TYPE_FLOAT)
{
Float32_t result;
result = atof((const char *)(_msg+1+pos));
{
char l_OutBuffer[OUTPUT_BUFFER_SIZE];
for (Uint8_t i = 0 ; i < OUTPUT_BUFFER_SIZE; i++) l_OutBuffer[i] = '\0';
- if (_eType == IParameterHandler::TYPE_FLOAT)
+ if (_eType == TYPE_FLOAT)
{
Float32_t fval;
m_Params->readValue(nv,fval);
//dtostre(fval,(char *)l_OutBuffer,4,0);
dtostrf(fval,8,4,(char *)l_OutBuffer);
- } else if (_eType == IParameterHandler::TYPE_U32)
+ } else if (_eType == TYPE_U32)
{
m_Params->readValue(nv,val);
ltoa(val,(char *)l_OutBuffer,10);
#define __COMMUNICATIONHANDLER_H__
class CommunicationHandler
-/* : public ITask */
+ : public ITask
{
public:
CommunicationHandler(IProtocolLayer2 *_l2,IParameterHandler *_p);
virtual void run();
private:
- void parse_msg(const Uint8_t *_msg,const Uint8_t len,IParameterHandler::eParameterType _eT);
+ void parse_msg(const Uint8_t *_msg,const Uint8_t len,eParameterType _eT);
///
void parse_num(const Uint8_t *_msg,const Uint8_t len, Uint32_t &_out);
private:
enum Baudrate_t { BAUD_2400 = 0
,BAUD_9600 = 1
,BAUD_19200 = 2
+ ,BAUD_33600 = 3
,BAUD_57600 = 4
- ,BAUD_115200 = 6
+ ,BAUD_115200 = 5
};
#endif
PowerswitchParameterTable.cpp
)
+set_target_properties(
+ avrPowerswitchParameters${MCU_TYPE_FOR_FILENAME} PROPERTIES
+ COMPILE_DEFINITIONS POWERSWITCH_PARAMETERS
+ )
add_avr_library(
avrDCMotorParameters
DCMotorParameterTable.cpp
)
+set_target_properties(
+ avrDCMotorParameters${MCU_TYPE_FOR_FILENAME} PROPERTIES
+ COMPILE_DEFINITIONS DCMOTOR_PARAMETERS
+ )
+
add_avr_library(
avrShutterCtrlParameters
ShutterCtrlParameterTable.cpp
)
+set_target_properties(
+ avrShutterCtrlParameters${MCU_TYPE_FOR_FILENAME} PROPERTIES
+ COMPILE_DEFINITIONS SHUTTERCTRL_PARAMETERS
+ )
+
add_avr_library(
avrWorkMeterParameters
WorkMeterParameterTable.cpp
)
+set_target_properties(
+ avrWorkMeterParameters${MCU_TYPE_FOR_FILENAME} PROPERTIES
+ COMPILE_DEFINITIONS WORKMETER_PARAMETERS
+ )
#ifndef __METADATA_H__
#define __METADATA_H__
+enum eParameterType {
+ TYPE_U8 = 0
+ , TYPE_U16 = 1
+ , TYPE_U32 = 2
+ , TYPE_I8 = 4
+ , TYPE_I16 = 4
+ , TYPE_I32 = 5
+ , TYPE_FLOAT = 6
+};
+
+enum eParameterLevel {
+ ALL
+ ,EUP = 1
+ ,SUP = 2
+ ,FUP = 3
+};
+enum eParameterAcess {
+ NONE = 0
+ ,RO = 1
+ ,WO = 2
+ ,RW = 3
+};
/* Forward declaration */
class IParameterListener;
Float32_t m_Float;
} u;
IParameterListener *m_Listener;
+#if defined(WORKMETER_PARAMETERS)
+ union ParameterAttributes
+ {
+ uint8_t m_AllAttributes;
+ uint8_t m_Type:4;
+ uint8_t m_AccessLevel:2;
+ uint8_t m_AccessRight:2;
+ } a;
+#endif
} ParameterValue;
#endif
-#ifndef __DCMOTORPARAMIDS_H__
-#define __DCMOTORPARAMIDS_H__
+#ifndef __SHUTTERCTRLPARAMIDS_H__
+#define __SHUTTERCTRLPARAMIDS_H__
/**
#include "WorkMeterParamIds.h"
#include "ParameterTable.h"
-
+#if 0
+ uint8_t m_Type:4;
+ uint8_t m_AccessLevel:2;
+ uint8_t m_AccessRight:2;
+#endif
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}
+ {0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_I32<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
};
#####################################################################
add_avr_library(
avrPtf
- DCMotorParameterHandler.cpp
+ ParameterHandler.cpp
PersistentStorage.cpp
)
#
add_avr_library(
avrPS-Ptf
- PowerswitchParameterHandler.cpp
+ ParameterHandler.cpp
PersistentStorage.cpp
)
set_target_properties(
- avrPtf${MCU_TYPE_FOR_FILENAME} PROPERTIES
+ avrPS-Ptf${MCU_TYPE_FOR_FILENAME} PROPERTIES
COMPILE_DEFINITIONS POWERSWITCH_PARAMETERS
)
#
#
add_avr_library(
avrSC-Ptf
- ShutterCtrlParameterHandler.cpp
+ ParameterHandler.cpp
PersistentStorage.cpp
)
set_target_properties(
- avrPtf${MCU_TYPE_FOR_FILENAME} PROPERTIES
+ avrSC-Ptf${MCU_TYPE_FOR_FILENAME} PROPERTIES
COMPILE_DEFINITIONS SHUTTERCTRL_PARAMETERS
)
#ifndef __IPARAMETER_HANDLER_H__
#define __IPARAMETER_HANDLER_H__
+#include "Metadata/Metadata.h"
+
/**
* \brief interface to be implemented by
* objects that need to be informed that a parameter
class IParameterHandler
{
public:
+#if 0
enum eParameterType {
TYPE_U8 = 0
, TYPE_U16 = 1
, TYPE_U32 = 2
- , TYPE_FLOAT = 3
+ , TYPE_I8 = 4
+ , TYPE_I16 = 4
+ , TYPE_I32 = 5
+ , TYPE_FLOAT = 6
};
+#endif
public:
IParameterHandler() {};
virtual void writeValue(const uint8_t paramID,const Float32_t _val) = 0;
///
virtual void registerListener(const uint8_t paramID,IParameterListener *_val) = 0;
+
+ // get Parameter ID value as string
+ virtual Bool_t toString(const uint8_t paramID, eParameterType _eType,Uint8_t *buffer) = 0 ;
+ // set Parameter ID value from string
+ // In case of type mismatch, return fail and don't assign the value
+ virtual Bool_t fromString(const uint8_t paramID, eParameterType _eType,Uint8_t *buffer) = 0 ;
};
#endif
#ifdef POWERSWITCH_PARAMETERS
#include <Metadata/PowerswitchParamIds.h>
#include <Metadata/PowerswitchParameterTable.h>
+#elif defined(DCMOTOR_PARAMETERS)
+#include <Metadata/DCMotorParamIds.h>
+#include <Metadata/DCMotorParameterTable.h>
+#elif defined(SHUTTERCTRL_PARAMETERS)
+#include <Metadata/ShutterCtrlParamIds.h>
+#include <Metadata/ShutterCtrlParameterTable.h>
#elif defined(WORKMETER_PARAMETERS)
#include <Metadata/WorkMeterParamIds.h>
#include <Metadata/ParameterTable.h>
}
}
+
+
+// get Parameter ID value as string
+Bool_t ParameterHandler::toString(const uint8_t paramID
+ , eParameterType _eType
+ , Uint8_t *buffer)
+{
+ return true;
+}
+// set Parameter ID value from string
+// In case of type mismatch, return fail and don't assign the value
+Bool_t ParameterHandler::fromString(const uint8_t paramID
+ , eParameterType _eType
+ , Uint8_t *buffer)
+{
+ return true;
+}
+
+
///
virtual void registerListener(const uint8_t paramID,IParameterListener *_val);
+ // get Parameter ID value as string
+ Bool_t toString(const uint8_t paramID
+ , eParameterType _eType
+ , Uint8_t *buffer) ;
+ // set Parameter ID value from string
+ // In case of type mismatch, return fail and don't assign the value
+ Bool_t fromString(const uint8_t paramID
+ , eParameterType _eType
+ , Uint8_t *buffer) ;
private:
};