Compare commits
5 Commits
bfaea9ef9a
...
634faad650
Author | SHA1 | Date | |
---|---|---|---|
|
634faad650 | ||
|
8d2df8530d | ||
|
c97db9f6a9 | ||
|
ae31aac4ee | ||
|
c2c95bf339 |
@ -221,7 +221,7 @@ boolean CFGFileParser::save(void *data)
|
|||||||
//Let's write the settings
|
//Let's write the settings
|
||||||
for(int i = 0; i < ref->count(); i++)
|
for(int i = 0; i < ref->count(); i++)
|
||||||
{
|
{
|
||||||
CFGParameterValue *cfgPV = ref->get(i);
|
CFGParameterValue *cfgPV = ref->getAt(i);
|
||||||
|
|
||||||
if(cfgPV->isQuotedParameter())
|
if(cfgPV->isQuotedParameter())
|
||||||
{
|
{
|
||||||
|
@ -132,16 +132,16 @@ public:
|
|||||||
return remove(indiceToStr);
|
return remove(indiceToStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean removeAt(unsigned int index)
|
boolean removeAt(unsigned int position)
|
||||||
{
|
{
|
||||||
unsigned int position(0);
|
unsigned int pos(0);
|
||||||
if(_head->_next == NULL) return false;
|
if(_head->_next == NULL) return false;
|
||||||
|
|
||||||
Dictionary *cursor = _head, *toDelete(NULL);
|
Dictionary *cursor = _head, *toDelete(NULL);
|
||||||
|
|
||||||
while(!isListEmpty(cursor->_next))
|
while(!isListEmpty(cursor->_next))
|
||||||
{
|
{
|
||||||
if(position++ == index)
|
if(pos++ == position)
|
||||||
{
|
{
|
||||||
toDelete = cursor->_next;
|
toDelete = cursor->_next;
|
||||||
cursor->_next = cursor->_next->_next;
|
cursor->_next = cursor->_next->_next;
|
||||||
@ -176,16 +176,32 @@ public:
|
|||||||
return get(parameter);
|
return get(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
T* get(const unsigned int index)
|
T* get(const unsigned int id)
|
||||||
{
|
{
|
||||||
unsigned int position(0);
|
char indiceToStr[10];
|
||||||
|
sprintf(indiceToStr,"%d", id);
|
||||||
|
|
||||||
|
return get(indiceToStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
T* operator()(const unsigned int id)
|
||||||
|
{
|
||||||
|
char indiceToStr[10];
|
||||||
|
sprintf(indiceToStr,"%d", id);
|
||||||
|
|
||||||
|
return get(indiceToStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
T* getAt(const unsigned int position)
|
||||||
|
{
|
||||||
|
unsigned int pos(0);
|
||||||
if(isListEmpty(_head->_next))return NULL;
|
if(isListEmpty(_head->_next))return NULL;
|
||||||
|
|
||||||
Dictionary *cursor = _head->_next;
|
Dictionary *cursor = _head->_next;
|
||||||
|
|
||||||
while(!isListEmpty(cursor))
|
while(!isListEmpty(cursor))
|
||||||
{
|
{
|
||||||
if(position++ == index)
|
if(pos++ == position)
|
||||||
return cursor->_value;
|
return cursor->_value;
|
||||||
cursor = cursor->_next;
|
cursor = cursor->_next;
|
||||||
}
|
}
|
||||||
@ -193,11 +209,6 @@ public:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* operator()(const unsigned int index)
|
|
||||||
{
|
|
||||||
return get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int count()
|
unsigned int count()
|
||||||
{
|
{
|
||||||
unsigned int counter(0);
|
unsigned int counter(0);
|
||||||
|
@ -116,7 +116,7 @@ boolean TaskSchedulerManager::addTask(const char *name, TaskSchedulerManagerHelp
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean TaskSchedulerManager::addTask(uint8_t id, TaskSchedulerManagerHelper::Schedule *schedule, boolean (*taskRoutine)(void*), void *pData)
|
boolean TaskSchedulerManager::addTask(uint16_t id, TaskSchedulerManagerHelper::Schedule *schedule, boolean (*taskRoutine)(void*), void *pData)
|
||||||
{
|
{
|
||||||
boolean result = _taskDataDictio.add(id, new TaskData({*schedule, taskRoutine, pData}));
|
boolean result = _taskDataDictio.add(id, new TaskData({*schedule, taskRoutine, pData}));
|
||||||
delete schedule;
|
delete schedule;
|
||||||
@ -128,7 +128,7 @@ boolean TaskSchedulerManager::removeTask(const char *name)
|
|||||||
return _taskDataDictio.remove(name);
|
return _taskDataDictio.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean TaskSchedulerManager::removeTask(uint8_t id)
|
boolean TaskSchedulerManager::removeTask(uint16_t id)
|
||||||
{
|
{
|
||||||
return _taskDataDictio.remove(id);
|
return _taskDataDictio.remove(id);
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ boolean TaskSchedulerManager::enableTask(const char *name)
|
|||||||
_taskDataDictio(name)->schedule.setEnabled(true);
|
_taskDataDictio(name)->schedule.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean TaskSchedulerManager::enableTask(uint8_t id)
|
boolean TaskSchedulerManager::enableTask(uint16_t id)
|
||||||
{
|
{
|
||||||
char indiceToStr[10];
|
char indiceToStr[10];
|
||||||
sprintf(indiceToStr,"%d", id);
|
sprintf(indiceToStr,"%d", id);
|
||||||
@ -150,7 +150,7 @@ boolean TaskSchedulerManager::disableTask(const char *name)
|
|||||||
_taskDataDictio(name)->schedule.setEnabled(false);
|
_taskDataDictio(name)->schedule.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean TaskSchedulerManager::disableTask(uint8_t id)
|
boolean TaskSchedulerManager::disableTask(uint16_t id)
|
||||||
{
|
{
|
||||||
char indiceToStr[10];
|
char indiceToStr[10];
|
||||||
sprintf(indiceToStr,"%d", id);
|
sprintf(indiceToStr,"%d", id);
|
||||||
@ -168,7 +168,7 @@ void TaskSchedulerManager::runTaskScheduler()
|
|||||||
|
|
||||||
if(_nextTaskIndexToBeRun >= _taskDataDictio.count())_nextTaskIndexToBeRun = 0;
|
if(_nextTaskIndexToBeRun >= _taskDataDictio.count())_nextTaskIndexToBeRun = 0;
|
||||||
|
|
||||||
TaskData *p = _taskDataDictio(_nextTaskIndexToBeRun);
|
TaskData *p = _taskDataDictio.getAt(_nextTaskIndexToBeRun);
|
||||||
|
|
||||||
if(p == NULL)//Shouldn't happen
|
if(p == NULL)//Shouldn't happen
|
||||||
return;
|
return;
|
||||||
@ -206,14 +206,24 @@ void TaskSchedulerManager::runTaskScheduler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(p->schedule._triggerType != TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE)_nextTaskIndexToBeRun++;
|
if(p->schedule._triggerType != TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE)_nextTaskIndexToBeRun++;
|
||||||
|
else if(p->schedule._triggerType == TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE && !(p->schedule._triggered))_nextTaskIndexToBeRun++;
|
||||||
else if(p->schedule._triggerType == TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE && p->schedule._triggered) //If the task has to be deleted after executing and if it has been executed, we delete it
|
else if(p->schedule._triggerType == TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE && p->schedule._triggered) //If the task has to be deleted after executing and if it has been executed, we delete it
|
||||||
{
|
{
|
||||||
_taskDataDictio.removeAt(_nextTaskIndexToBeRun);
|
_taskDataDictio.removeAt(_nextTaskIndexToBeRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned int TaskSchedulerManager::taskCount()
|
const unsigned int TaskSchedulerManager::taskCount()
|
||||||
{
|
{
|
||||||
return _taskDataDictio.count();
|
return _taskDataDictio.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t TaskSchedulerManager::findFreeTaskId()
|
||||||
|
{
|
||||||
|
uint16_t idToTry(1);
|
||||||
|
while(_taskDataDictio(idToTry) != NULL)
|
||||||
|
{
|
||||||
|
idToTry++;
|
||||||
|
}
|
||||||
|
return idToTry;
|
||||||
|
}
|
||||||
|
@ -61,16 +61,17 @@ class TaskSchedulerManager
|
|||||||
_taskDataDictio.dispose();
|
_taskDataDictio.dispose();
|
||||||
}
|
}
|
||||||
boolean addTask(const char *name, TaskSchedulerManagerHelper::Schedule *schedule, boolean (*taskRoutine)(void*), void *pData = NULL);
|
boolean addTask(const char *name, TaskSchedulerManagerHelper::Schedule *schedule, boolean (*taskRoutine)(void*), void *pData = NULL);
|
||||||
boolean addTask(uint8_t id, TaskSchedulerManagerHelper::Schedule *schedule, boolean (*taskRoutine)(void*), void *pData = NULL);
|
boolean addTask(uint16_t id, TaskSchedulerManagerHelper::Schedule *schedule, boolean (*taskRoutine)(void*), void *pData = NULL);
|
||||||
boolean removeTask(const char *name);
|
boolean removeTask(const char *name);
|
||||||
boolean removeTask(uint8_t id);
|
boolean removeTask(uint16_t id);
|
||||||
boolean enableTask(const char *name);
|
boolean enableTask(const char *name);
|
||||||
boolean enableTask(uint8_t id);
|
boolean enableTask(uint16_t id);
|
||||||
boolean disableTask(const char *name);
|
boolean disableTask(const char *name);
|
||||||
boolean disableTask(uint8_t id);
|
boolean disableTask(uint16_t id);
|
||||||
boolean clearTask();
|
boolean clearTask();
|
||||||
void runTaskScheduler();
|
void runTaskScheduler();
|
||||||
const unsigned int taskCount();
|
const unsigned int taskCount();
|
||||||
|
uint16_t findFreeTaskId();
|
||||||
protected:
|
protected:
|
||||||
TaskSchedulerManager();
|
TaskSchedulerManager();
|
||||||
TaskSchedulerManager(RtcManager &rtcManager);
|
TaskSchedulerManager(RtcManager &rtcManager);
|
||||||
@ -82,7 +83,7 @@ class TaskSchedulerManager
|
|||||||
void *pData;
|
void *pData;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t _nextTaskIndexToBeRun;
|
uint16_t _nextTaskIndexToBeRun;
|
||||||
RtcManager *_rtcManager;
|
RtcManager *_rtcManager;
|
||||||
Dictionary<TaskData> _taskDataDictio;
|
Dictionary<TaskData> _taskDataDictio;
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,7 @@ boolean task_batt_sensing(void *pData)
|
|||||||
View1Packet *p = (View1Packet *) pData;
|
View1Packet *p = (View1Packet *) pData;
|
||||||
Serial.println(F("BATT SENSING..."));
|
Serial.println(F("BATT SENSING..."));
|
||||||
p->powerInfo = p->sab->getPowerInfo();
|
p->powerInfo = p->sab->getPowerInfo();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,12 +80,12 @@ boolean rtcSetTimeApi(WEBServerManager::HttpRequestData &HRD, WiFiClient *wc, vo
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
p->getRtcManager().setDateTime(DateTime(
|
p->getRtcManager().setDateTime(DateTime(
|
||||||
atoi(dictio->get(2)->getString()),
|
atoi(dictio->getAt(2)->getString()),
|
||||||
atoi(dictio->get(1)->getString()),
|
atoi(dictio->getAt(1)->getString()),
|
||||||
atoi(dictio->get((unsigned int)0)->getString()),
|
atoi(dictio->getAt((unsigned int)0)->getString()),
|
||||||
atoi(dictio->get(3)->getString()),
|
atoi(dictio->getAt(3)->getString()),
|
||||||
atoi(dictio->get(4)->getString()),
|
atoi(dictio->getAt(4)->getString()),
|
||||||
atoi(dictio->get(5)->getString())
|
atoi(dictio->getAt(5)->getString())
|
||||||
));
|
));
|
||||||
DateTime d = p->getRtcManager().getDateTime();
|
DateTime d = p->getRtcManager().getDateTime();
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"date\" : \"%d/%d/%d\", \"time\" : \"%d:%d:%d\" }", d.day(), d.month(), d.year(), d.hour(), d.minute(), d.second());
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"date\" : \"%d/%d/%d\", \"time\" : \"%d:%d:%d\" }", d.day(), d.month(), d.year(), d.hour(), d.minute(), d.second());
|
||||||
@ -138,18 +138,13 @@ boolean espRestartApi(WEBServerManager::HttpRequestData &HRD, WiFiClient *wc, vo
|
|||||||
SAB *sab = (SAB*)pData;
|
SAB *sab = (SAB*)pData;
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"message\" : \"module restarting in 10 seconds\" }");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"message\" : \"module %s in 10 seconds\" }",strstr(HRD.httpResource,"reset") == NULL ? "restarting" : "resetting");
|
||||||
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
|
|
||||||
unsigned int id = sab->getTaskSchedulerManager().taskCount()+1;
|
sab->getTaskSchedulerManager().addTask(sab->getTaskSchedulerManager().findFreeTaskId(), TaskSchedulerManagerHelper::Schedule::scheduleBuilder()
|
||||||
|
|
||||||
sab->getTaskSchedulerManager().addTask(id, TaskSchedulerManagerHelper::Schedule::scheduleBuilder()
|
|
||||||
->setSeconds(10)
|
->setSeconds(10)
|
||||||
->setTriggerType(TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE)
|
->setTriggerType(TaskSchedulerManagerHelper::Schedule::TRIGGER_ONCE_AND_DELETE)
|
||||||
->setTriggerRightAway(false), &(task_esp_reset_restart), NULL);
|
->setTriggerRightAway(false), &(task_esp_reset_restart), NULL);
|
||||||
|
|
||||||
Serial.print(F("Task id : "));Serial.println(id);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user