mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/
Dependencies: EthernetNetIf SDHCFileSystem I2CLEDDisp Agentbed NTPClient_NetServices mbed BMP085 HTTPClient ConfigFile I2CLCD
Diff: conf.cpp
- Revision:
- 18:9286e5010c14
- Parent:
- 16:df39da7bef98
diff -r 7c9d111a5d45 -r 9286e5010c14 conf.cpp --- a/conf.cpp Fri Apr 08 15:59:29 2011 +0000 +++ b/conf.cpp Tue May 31 15:40:14 2011 +0000 @@ -2,14 +2,9 @@ * @brief mbed Weather Platform */ #include "mbed.h" -#include "conf.h" +#include "weather.h" #include "ConfigFile.h" -extern Serial xbee; -extern Config conf; -extern Sensor sensor, offset, sensor_old; - -void int_counter(); char* chop (char *s) { int i; @@ -24,237 +19,6 @@ return s; } -int check_action (char type) { - int i, j, count; - float value, vold; - time_t sec = time(NULL) + (60 * 60 * 9); - struct tm *tim = localtime(&sec); - - for(i = 0; i < conf.actionscount; i ++) { - if (conf.actions[i].action != type) continue; - - count = 0; - for (j = 0; j < conf.actions[i].count; j ++) { - switch (conf.actions[i].exps[j].key) { - case 'P': - value = sensor.pres; - vold = sensor_old.pres; - break; - case 'T': - value = sensor.temp; - vold = sensor_old.temp; - break; - case 'H': - value = sensor.humi; - vold = sensor_old.humi; - break; - case 'A': - value = sensor.anemo; - vold = sensor_old.anemo; - break; - case 'V': - value = sensor.vane; - vold = sensor_old.vane; - break; - case 'R': - value = sensor.rain; - vold = sensor_old.rain; - break; - case 'L': - value = sensor.light; - vold = sensor_old.light; - break; - case 'U': - value = sensor.uv; - vold = sensor_old.uv; - break; - case 'M': - value = sensor.moist; - vold = sensor_old.moist; - break; - - case 'y': - value = tim->tm_year + 1900; - break; - case 'm': - value = tim->tm_mon; - break; - case 'd': - value = tim->tm_mday; - break; - case 'h': - value = tim->tm_hour; - break; - case 'i': - value = tim->tm_min; - break; - case 's': - value = tim->tm_sec; - break; - - default: - value = 0; - break; - } - - switch (conf.actions[i].exps[j].expression) { - case EXP_EQ: - if (value == conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_NE: - if (value != conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_LE: - if (value <= conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_LT: - if (value < conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_GE: - if (value >= conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_GT: - if (value > conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_MOD: - if ((int)value % (int)conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_NMOD: - if (! (int)value % (int)conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_FALL: - if (value < conf.actions[i].exps[j].value && vold >= conf.actions[i].exps[j].value) { - count ++; - } - break; - case EXP_RISE: - if (value > conf.actions[i].exps[j].value && vold <= conf.actions[i].exps[j].value) { - count ++; - } - break; - - default: - count ++; - break; - } - } - if (count == conf.actions[i].count) { - return conf.actions[i].sub ? conf.actions[i].sub : ' '; - } - } - return 0; -} - -void add_actionsub (struct tExpression *exp, char *buf) { - - exp->key = buf[0]; - - switch (buf[1]) { - case '=': - if (buf[2] == '=') { - exp->expression = EXP_EQ; - exp->value = atof(&buf[3]); - } - break; - - case '!': - if (buf[2] == '=') { - exp->expression = EXP_NE; - exp->value = atof(&buf[3]); - } else - if (buf[2] == '%') { - exp->expression = EXP_NMOD; - exp->value = atof(&buf[3]); - } - break; - - case '<': - if (buf[2] == '=') { - exp->expression = EXP_LE; - exp->value = atof(&buf[3]); - } else { - exp->expression = EXP_LT; - exp->value = atof(&buf[2]); - } - break; - - case '>': - if (buf[2] == '=') { - exp->expression = EXP_GE; - exp->value = atof(&buf[3]); - } else { - exp->expression = EXP_GT; - exp->value = atof(&buf[2]); - } - break; - - case '%': - exp->expression = EXP_MOD; - exp->value = atof(&buf[2]); - break; - - case '_': - exp->expression = EXP_FALL; - exp->value = atof(&buf[2]); - break; - case '^': - exp->expression = EXP_RISE; - exp->value = atof(&buf[2]); - break; - - default: - exp->expression = EXP_NULL; - break; - } -} - -void add_action (char *buf) { - int i, len, count; - char c; - char *tmp = NULL; - - if (conf.actionscount >= CF_ACTION_NUM) return; - -// conf.actions[conf.actionscount].action = atoi(&buf[0]); - conf.actions[conf.actionscount].action = buf[0]; - conf.actions[conf.actionscount].sub = buf[1]; - - count = 0; - strcat(buf, "\n"); - len = strlen(buf); - for (i = 1; i < len; i ++) { - c = buf[i]; - if (c == ' ' || c == '\t' || c == '\n' || c == '\r') { - buf[i] = 0; - if (count) { - add_actionsub(&conf.actions[conf.actionscount].exps[count - 1], tmp); - } - if (count >= CF_ACTION_EXPS || c == '\n') break; - tmp = &buf[i + 1]; - count ++; - } - } - - conf.actions[conf.actionscount].count = count; - conf.actionscount ++; -} - int config (char *file) { int i; ConfigFile cfg; @@ -371,13 +135,6 @@ conf.inputtype = (enum eINPUTTYPE)atoi(chop(buf)); } - for (i = 0; i < CF_ACTION_NUM; i ++) { - sprintf(key, "ACTION[%d]", i); - if (cfg.getValue(key, buf, sizeof(buf))) { - add_action(chop(buf)); - } - } - if (cfg.getValue("OFFSET[P]", buf, sizeof(buf))) { offset.pres = atof(chop(buf)); }