intermediate: running sensor tasks inits after all user init tasks
This commit is contained in:
parent
f75f8033d1
commit
1ab70aca8b
|
@ -240,7 +240,10 @@ static void checkDef(T... args){};
|
||||||
#define DECLARE_USERTASK_PARAM(task,...)
|
#define DECLARE_USERTASK_PARAM(task,...)
|
||||||
#endif
|
#endif
|
||||||
#ifndef DECLARE_INITFUNCTION
|
#ifndef DECLARE_INITFUNCTION
|
||||||
#define DECLARE_INITFUNCTION(task)
|
#define DECLARE_INITFUNCTION(task,...)
|
||||||
|
#endif
|
||||||
|
#ifndef DECLARE_INITFUNCTION_ORDER
|
||||||
|
#define DECLARE_INITFUNCTION_ORDER(task,...)
|
||||||
#endif
|
#endif
|
||||||
#ifndef DECLARE_CAPABILITY
|
#ifndef DECLARE_CAPABILITY
|
||||||
#define DECLARE_CAPABILITY(name,value)
|
#define DECLARE_CAPABILITY(name,value)
|
||||||
|
@ -322,5 +325,8 @@ class ConfiguredSensors : public GwApi::TaskInterfaces::Base{
|
||||||
};
|
};
|
||||||
DECLARE_TASKIF(ConfiguredSensors);
|
DECLARE_TASKIF(ConfiguredSensors);
|
||||||
|
|
||||||
|
//order for late init functions
|
||||||
|
//all user tasks should have lower orders (default: 0)
|
||||||
|
#define GWLATEORDER 9999
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
#include "GwApi.h"
|
#include "GwApi.h"
|
||||||
#include "GwSensor.h"
|
#include "GwSensor.h"
|
||||||
void initIicTask(GwApi *api);
|
void initIicTask(GwApi *api);
|
||||||
DECLARE_INITFUNCTION(initIicTask);
|
DECLARE_INITFUNCTION_ORDER(initIicTask,GWLATEORDER);
|
||||||
#endif
|
#endif
|
|
@ -16,5 +16,5 @@
|
||||||
#define _GWSPITASK_H
|
#define _GWSPITASK_H
|
||||||
#include "GwApi.h"
|
#include "GwApi.h"
|
||||||
void initSpiTask(GwApi *api);
|
void initSpiTask(GwApi *api);
|
||||||
DECLARE_INITFUNCTION(initSpiTask);
|
DECLARE_INITFUNCTION_ORDER(initSpiTask,GWLATEORDER);
|
||||||
#endif
|
#endif
|
|
@ -1,6 +1,7 @@
|
||||||
#define DECLARE_USERTASK(task) GwUserTaskDef __##task##__(task,#task);
|
#define DECLARE_USERTASK(task) GwUserTaskDef __##task##__(task,#task);
|
||||||
#define DECLARE_USERTASK_PARAM(task,...) GwUserTaskDef __##task##__(task,#task,__VA_ARGS__);
|
#define DECLARE_USERTASK_PARAM(task,...) GwUserTaskDef __##task##__(task,#task,__VA_ARGS__);
|
||||||
#define DECLARE_INITFUNCTION(task) GwInitTask __Init##task##__(task,#task);
|
#define DECLARE_INITFUNCTION(task) GwInitTask __Init##task##__(task,#task);
|
||||||
|
#define DECLARE_INITFUNCTION_ORDER(task,order) GwInitTask __Init##task##__(task,#task,order);
|
||||||
#define DECLARE_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,#value);
|
#define DECLARE_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,#value);
|
||||||
#define DECLARE_STRING_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,value);
|
#define DECLARE_STRING_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,value);
|
||||||
#define DECLARE_TASKIF(type) \
|
#define DECLARE_TASKIF(type) \
|
||||||
|
@ -43,8 +44,8 @@ class GwInitTask{
|
||||||
GwInitTask(TaskFunction_t task, String name){
|
GwInitTask(TaskFunction_t task, String name){
|
||||||
initTasks.push_back(GwUserTask(name,task));
|
initTasks.push_back(GwUserTask(name,task));
|
||||||
}
|
}
|
||||||
GwInitTask(GwUserTaskFunction task, String name){
|
GwInitTask(GwUserTaskFunction task, String name,int order=0){
|
||||||
initTasks.push_back(GwUserTask(name,task));
|
initTasks.push_back(GwUserTask(name,task,GwUserTask::DEFAULT_STACKSIZE,order));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class GwUserCapability{
|
class GwUserCapability{
|
||||||
|
@ -341,7 +342,6 @@ public:
|
||||||
sensors->sensors.add(sensor);
|
sensors->sensors.add(sensor);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
api->getLogger()->logDebug(GwLog::LOG,"adding sensor %s returns %d",sensor->prefix.c_str(),(int)rt);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -378,6 +378,9 @@ void GwUserCode::startUserTasks(int baseId){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GwUserCode::startInitTasks(int baseId){
|
void GwUserCode::startInitTasks(int baseId){
|
||||||
|
std::sort(initTasks.begin(),initTasks.end(),[](const GwUserTask &a, const GwUserTask &b){
|
||||||
|
return a.order < b.order;
|
||||||
|
});
|
||||||
LOG_DEBUG(GwLog::DEBUG,"starting %d user init tasks",initTasks.size());
|
LOG_DEBUG(GwLog::DEBUG,"starting %d user init tasks",initTasks.size());
|
||||||
for (auto it=initTasks.begin();it != initTasks.end();it++){
|
for (auto it=initTasks.begin();it != initTasks.end();it++){
|
||||||
LOG_DEBUG(GwLog::LOG,"starting user init task %s with id %d",it->name.c_str(),baseId);
|
LOG_DEBUG(GwLog::LOG,"starting user init task %s with id %d",it->name.c_str(),baseId);
|
||||||
|
|
|
@ -15,22 +15,25 @@ class GwApiInternal : public GwApi{
|
||||||
};
|
};
|
||||||
class GwUserTask{
|
class GwUserTask{
|
||||||
public:
|
public:
|
||||||
|
static const int DEFAULT_STACKSIZE=2000;
|
||||||
String name;
|
String name;
|
||||||
TaskFunction_t task=NULL;
|
TaskFunction_t task=NULL;
|
||||||
GwUserTaskFunction usertask=NULL;
|
GwUserTaskFunction usertask=NULL;
|
||||||
bool isUserTask=false;
|
bool isUserTask=false;
|
||||||
GwApiInternal *api=NULL;
|
GwApiInternal *api=NULL;
|
||||||
int stackSize=2000;
|
int stackSize=2000;
|
||||||
GwUserTask(String name,TaskFunction_t task,int stackSize=2000){
|
int order=0;
|
||||||
|
GwUserTask(String name,TaskFunction_t task,int stackSize=DEFAULT_STACKSIZE){
|
||||||
this->name=name;
|
this->name=name;
|
||||||
this->task=task;
|
this->task=task;
|
||||||
this->stackSize=stackSize;
|
this->stackSize=stackSize;
|
||||||
}
|
}
|
||||||
GwUserTask(String name, GwUserTaskFunction task,int stackSize=2000){
|
GwUserTask(String name, GwUserTaskFunction task,int stackSize=DEFAULT_STACKSIZE, int order=0){
|
||||||
this->name=name;
|
this->name=name;
|
||||||
this->usertask=task;
|
this->usertask=task;
|
||||||
this->isUserTask=true;
|
this->isUserTask=true;
|
||||||
this->stackSize=stackSize;
|
this->stackSize=stackSize;
|
||||||
|
this->order=order;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue