fix scheduler decoder

This commit is contained in:
Mats van Reenen 2020-12-25 20:42:47 +01:00
parent 705fc119a4
commit 47db19d567

View File

@ -120,7 +120,6 @@ time_t getNextTrigger(Script_t *script, time_t startTime){
} }
//TODO: add devide option //TODO: add devide option
//TOOD: add full file name instad of only extention
void getSchedule(Script_t *script, char *str){ void getSchedule(Script_t *script, char *str){
uint8_t is = 0; uint8_t is = 0;
script->scheduler[0] = script->scheduler[0] =
@ -128,8 +127,9 @@ void getSchedule(Script_t *script, char *str){
script->scheduler[2] = script->scheduler[2] =
script->scheduler[3] = script->scheduler[3] =
script->scheduler[4] = 0; script->scheduler[4] = 0;
int8_t cmd[3]; uint8_t cmd[3];
cmd[0] = cmd[1] = cmd[2] = 0; cmd[0] = 0xff;
cmd[1] = cmd[2] = 0;
logTrace("get the scheduler for '%s'", str); logTrace("get the scheduler for '%s'", str);
@ -137,9 +137,6 @@ void getSchedule(Script_t *script, char *str){
uint8_t ic; uint8_t ic;
for(ic=0; ic<strlen(str); ic++){ for(ic=0; ic<strlen(str); ic++){
switch ((char)*(str+ic)){ switch ((char)*(str+ic)){
case '*': // set all bits
script->scheduler[is] = ~0;
break;
case '0' ... '9': // read a number case '0' ... '9': // read a number
if(cmd[0] == '-'){ // the second numer of a range should not be overritten if(cmd[0] == '-'){ // the second numer of a range should not be overritten
cmd[2] *= 10; cmd[2] *= 10;
@ -148,6 +145,11 @@ void getSchedule(Script_t *script, char *str){
cmd[1] *= 10; cmd[1] *= 10;
cmd[1] += (char)*(str+ic) - '0'; cmd[1] += (char)*(str+ic) - '0';
} }
if(cmd[0] == 0xff)
cmd[0] = ',';
break;
case '*': // set all bits
script->scheduler[is] = ~0;
break; break;
case ',': // list of times case ',': // list of times
cmd[0] = ','; cmd[0] = ',';
@ -164,19 +166,20 @@ void getSchedule(Script_t *script, char *str){
{ {
case '-': case '-':
// set all bits in the range // set all bits in the range
for(uint8_t i=cmd[2]; i>cmd[1]; i--){ for(int8_t i=cmd[2]; i>=cmd[1]; i--){
script->scheduler[is] |= 1<<i; script->scheduler[is] |= 1<<i;
} }
break; break;
case ',':
default:
// set the bit from last number from the list // set the bit from last number from the list
script->scheduler[is] |= (is == 0) ? 1<<(cmd[1]/2) : 1<<cmd[1]; script->scheduler[is] |= (is == 0) ? 1<<(cmd[1]/2) : 1<<cmd[1];
break; break;
case 0xff:
break;
} }
is++; is++;
cmd[0] = 0; cmd[0] = 0xff;
cmd[1] = 0; cmd[1] = cmd[2] = 0;
break; break;
} }
if((char)*(str+ic) == '.'){ if((char)*(str+ic) == '.'){
@ -189,7 +192,7 @@ void getSchedule(Script_t *script, char *str){
// copy filename // copy filename
memcpy(&script->filename, str, strlen(str)+1); memcpy(&script->filename, str, strlen(str)+1);
logInfo("scheduler: [0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x]", logTrace("scheduler: [0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x]",
script->scheduler[0], script->scheduler[0],
script->scheduler[1], script->scheduler[1],
script->scheduler[2], script->scheduler[2],