475 name = xstrcat(name, (char *)"/.thermferm/log/"); |
475 name = xstrcat(name, (char *)"/.thermferm/log/"); |
476 name = xstrcat(name, param); |
476 name = xstrcat(name, param); |
477 |
477 |
478 if ((fp = fopen(name, "r"))) { |
478 if ((fp = fopen(name, "r"))) { |
479 char buffer[256], outbuf[256], q[5], hr[3]; |
479 char buffer[256], outbuf[256], q[5], hr[3]; |
480 char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n, *room_n; |
480 char *date_n, *mode_n, *air_n, *beer_n, *target_lo_n, *target_hi_n, *heater_n, *cooler_n, *room_n; |
481 char *heater_u, *cooler_u; |
481 char *heater_u, *cooler_u; |
482 int lines = 0, heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, graphstep = 0; |
482 int lines = 0, heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, graphstep = 0; |
483 float room_t = 0.0; |
483 float room_t = 0.0; |
484 |
484 |
485 srv_send((char *)"212 Logfile list follows:"); |
485 srv_send((char *)"212 Logfile list follows:"); |
502 graphstep = MAX_INTERVALS; |
502 graphstep = MAX_INTERVALS; |
503 syslog(LOG_NOTICE, "ARCHIVE LOG %s: lines=%d, interval=%d, graphstep=%d", param, lines, GRAPH_INTERVAL[graphstep], graphstep); |
503 syslog(LOG_NOTICE, "ARCHIVE LOG %s: lines=%d, interval=%d, graphstep=%d", param, lines, GRAPH_INTERVAL[graphstep], graphstep); |
504 |
504 |
505 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
505 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
506 /* |
506 /* |
507 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA,18.000 |
507 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA,18.000,20.1 |
508 * | | | | | | | | | | | | | |
508 * | | | | | | | | | | | | | | |
509 * date_n | | | | | | | | | | | | |
509 * date_n | | | | | | | | | | | | | |
510 * mode_n ----------+ | | | | | | | | | | | |
510 * mode_n ----------+ | | | | | | | | | | | | |
511 * air_n -----------------+ | | | | | | | | | | |
511 * air_n -----------------+ | | | | | | | | | | | |
512 * beer_n -----------------------+ | | | | | | | | | |
512 * beer_n -----------------------+ | | | | | | | | | | |
513 * target_n ---------------------------+ | | | | | | | | |
513 * target_lo_n ------------------------+ | | | | | | | | | |
514 * heater_n -------------------------------+ | | | | | | | |
514 * heater_n -------------------------------+ | | | | | | | | |
515 * cooler_n ---------------------------------+ | | | | | | |
515 * cooler_n ---------------------------------+ | | | | | | | |
516 * not used ------------------------------------+ | | | | | |
516 * not used ------------------------------------+ | | | | | | |
517 * not used ---------------------------------------+ | | | | |
517 * not used ---------------------------------------+ | | | | | |
518 * heater_u --------------------------------------------+ | | | |
518 * heater_u --------------------------------------------+ | | | | |
519 * cooler_u ------------------------------------------------+ | | |
519 * cooler_u ------------------------------------------------+ | | | |
520 * not used ---------------------------------------------------+ | |
520 * not used ---------------------------------------------------+ | | |
521 * room_n ----------------------------------------------------------+ |
521 * room_n ----------------------------------------------------------+ | |
|
522 * target_hi_n -----------------------------------------------------------+ |
522 */ |
523 */ |
523 hr[0] = q[0] = buffer[11]; |
524 hr[0] = q[0] = buffer[11]; |
524 hr[1] = q[1] = buffer[12]; |
525 hr[1] = q[1] = buffer[12]; |
525 q[2] = buffer[14]; |
526 q[2] = buffer[14]; |
526 q[3] = buffer[15]; |
527 q[3] = buffer[15]; |
527 hr[2] = '\0'; |
528 hr[2] = '\0'; |
528 buffer[strlen(buffer) -1] = '\0'; |
529 buffer[strlen(buffer) -1] = '\0'; |
529 date_n = strtok(buffer, ",\0"); /* timestamp */ |
530 date_n = strtok(buffer, ",\0"); /* timestamp */ |
530 mode_n = strtok(NULL, ",\0"); /* unit mode */ |
531 mode_n = strtok(NULL, ",\0"); /* unit mode */ |
531 air_n = strtok(NULL, ",\0"); /* air temp */ |
532 air_n = strtok(NULL, ",\0"); /* air temp */ |
532 beer_n = strtok(NULL, ",\0"); /* beer temp */ |
533 beer_n = strtok(NULL, ",\0"); /* beer temp */ |
533 target_n = strtok(NULL, ",\0"); /* target temp */ |
534 target_lo_n = strtok(NULL, ",\0"); /* target low temp */ |
534 heater_n = strtok(NULL, ",\0"); /* current heater state */ |
535 heater_n = strtok(NULL, ",\0"); /* current heater state */ |
535 cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
536 cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
536 heater_u = strtok(NULL, ",\0"); /* current fan state */ |
537 heater_u = strtok(NULL, ",\0"); /* current fan state */ |
537 heater_u = strtok(NULL, ",\0"); /* current door state */ |
538 heater_u = strtok(NULL, ",\0"); /* current door state */ |
538 heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
539 heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
539 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
540 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
540 room_n = strtok(NULL, ",\0"); /* fan use counter */ |
541 room_n = strtok(NULL, ",\0"); /* fan use counter */ |
541 room_n = strtok(NULL, ",\0"); /* room temperature */ |
542 room_n = strtok(NULL, ",\0"); /* room temperature */ |
|
543 target_hi_n = strtok(NULL, ",\0"); /* target high temp */ |
542 |
544 |
543 if (strncmp(mode_n, (char *)"Mode", 4)) { |
545 if (strncmp(mode_n, (char *)"Mode", 4)) { |
544 /* |
546 /* |
545 * Output a line at the right intervals |
547 * Output a line at the right intervals |
546 */ |
548 */ |
564 cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
566 cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
565 } |
567 } |
566 } |
568 } |
567 if (room_n) |
569 if (room_n) |
568 sscanf(room_n, "%f", &room_t); |
570 sscanf(room_n, "%f", &room_t); |
569 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f", |
571 if (target_hi_n == NULL) |
570 date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used, room_t); |
572 target_hi_n = target_lo_n; |
|
573 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f,%s", |
|
574 date_n, mode_n, air_n, beer_n, target_lo_n, heater_n, cooler_n, heat_used, cool_used, room_t,target_hi_n); |
571 srv_send(outbuf); |
575 srv_send(outbuf); |
572 if (heater_u && h && strcmp(heater_u, "NA")) |
576 if (heater_u && h && strcmp(heater_u, "NA")) |
573 heater_l = h; |
577 heater_l = h; |
574 if (cooler_u && c & strcmp(cooler_u, "NA")) |
578 if (cooler_u && c & strcmp(cooler_u, "NA")) |
575 cooler_l = c; |
579 cooler_l = c; |
1102 * LIST LOG |
1106 * LIST LOG |
1103 */ |
1107 */ |
1104 int cmd_list(char *buf) |
1108 int cmd_list(char *buf) |
1105 { |
1109 { |
1106 char *opt, *param, *filename, q[5], hr[3], buffer[256], outbuf[256]; |
1110 char *opt, *param, *filename, q[5], hr[3], buffer[256], outbuf[256]; |
1107 char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n, *room_n; |
1111 char *date_n, *mode_n, *air_n, *beer_n, *target_lo_n, *target_hi_n, *heater_n, *cooler_n, *room_n; |
1108 char *heater_u, *cooler_u; |
1112 char *heater_u, *cooler_u; |
1109 int heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, lines = 0, graphstep = 0; |
1113 int heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, lines = 0, graphstep = 0; |
1110 units_list *unit; |
1114 units_list *unit; |
1111 FILE *fp; |
1115 FILE *fp; |
1112 float room_t; |
1116 float room_t; |
1189 hr[1] = q[1] = buffer[12]; |
1193 hr[1] = q[1] = buffer[12]; |
1190 q[2] = buffer[14]; |
1194 q[2] = buffer[14]; |
1191 q[3] = buffer[15]; |
1195 q[3] = buffer[15]; |
1192 hr[2] = '\0'; |
1196 hr[2] = '\0'; |
1193 buffer[strlen(buffer) -1] = '\0'; |
1197 buffer[strlen(buffer) -1] = '\0'; |
1194 date_n = strtok(buffer, ",\0"); /* timestamp */ |
1198 date_n = strtok(buffer, ",\0"); /* timestamp */ |
1195 mode_n = strtok(NULL, ",\0"); /* unit mode */ |
1199 mode_n = strtok(NULL, ",\0"); /* unit mode */ |
1196 air_n = strtok(NULL, ",\0"); /* air temp */ |
1200 air_n = strtok(NULL, ",\0"); /* air temp */ |
1197 beer_n = strtok(NULL, ",\0"); /* beer temp */ |
1201 beer_n = strtok(NULL, ",\0"); /* beer temp */ |
1198 target_n = strtok(NULL, ",\0"); /* target temp */ |
1202 target_lo_n = strtok(NULL, ",\0"); /* target low temp */ |
1199 heater_n = strtok(NULL, ",\0"); /* current heater state */ |
1203 heater_n = strtok(NULL, ",\0"); /* current heater state */ |
1200 cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
1204 cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
1201 heater_u = strtok(NULL, ",\0"); /* current fan state */ |
1205 heater_u = strtok(NULL, ",\0"); /* current fan state */ |
1202 heater_u = strtok(NULL, ",\0"); /* current door state */ |
1206 heater_u = strtok(NULL, ",\0"); /* current door state */ |
1203 heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
1207 heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
1204 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
1208 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
1205 room_n = strtok(NULL, ",\0"); /* fan use counter */ |
1209 room_n = strtok(NULL, ",\0"); /* fan use counter */ |
1206 room_n = strtok(NULL, ",\0"); /* room temperature */ |
1210 room_n = strtok(NULL, ",\0"); /* room temperature */ |
|
1211 target_hi_n = strtok(NULL, ",\0"); /* target high temp */ |
1207 |
1212 |
1208 if (strncmp(mode_n, (char *)"Mode", 4)) { |
1213 if (strncmp(mode_n, (char *)"Mode", 4)) { |
1209 /* |
1214 /* |
1210 * Output a line at the right intervals |
1215 * Output a line at the right intervals |
1211 */ |
1216 */ |
1231 } |
1236 } |
1232 if (room_n) |
1237 if (room_n) |
1233 sscanf(room_n, "%f", &room_t); |
1238 sscanf(room_n, "%f", &room_t); |
1234 else |
1239 else |
1235 room_t = 0.0; |
1240 room_t = 0.0; |
1236 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f", |
1241 if (target_hi_n == NULL) |
1237 date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used, room_t); |
1242 target_hi_n = target_lo_n; |
|
1243 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f,%s", |
|
1244 date_n, mode_n, air_n, beer_n, target_lo_n, heater_n, cooler_n, heat_used, cool_used, room_t, target_hi_n); |
1238 srv_send(outbuf); |
1245 srv_send(outbuf); |
1239 if (h && strcmp(heater_u, "NA")) |
1246 if (h && strcmp(heater_u, "NA")) |
1240 heater_l = h; |
1247 heater_l = h; |
1241 if (c & strcmp(cooler_u, "NA")) |
1248 if (c & strcmp(cooler_u, "NA")) |
1242 cooler_l = c; |
1249 cooler_l = c; |
1265 * PROFILE GETS uuid Get profile steps list |
1272 * PROFILE GETS uuid Get profile steps list |
1266 * PROFILE PUTS uuid Put profile steps list |
1273 * PROFILE PUTS uuid Put profile steps list |
1267 */ |
1274 */ |
1268 int cmd_profile(char *buf) |
1275 int cmd_profile(char *buf) |
1269 { |
1276 { |
1270 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param, *kwd, *val; |
1277 char ibuf[SS_BUFSIZE], *sstep, *rest, *tlarg, *tharg, *frarg, *param, *kwd, *val; |
1271 int j, rlen, istep, irest; |
1278 int j, ival, rlen, istep, irest, ifrarg; |
1272 float ftarg, fval; |
1279 float ftlarg, ftharg, fval; |
1273 char *opt; |
1280 char *opt; |
1274 profiles_list *profile, *tmpp; |
1281 profiles_list *profile, *tmpp; |
1275 prof_step *step, *olds; |
1282 prof_step *step, *olds; |
1276 uuid_t uu; |
1283 uuid_t uu; |
1277 |
1284 |
1360 for (profile = Config.profiles; profile; profile = profile->next) { |
1368 for (profile = Config.profiles; profile; profile = profile->next) { |
1361 if (strcmp(profile->uuid, param) == 0) { |
1369 if (strcmp(profile->uuid, param) == 0) { |
1362 srv_send((char *)"213 Profile record follows:"); |
1370 srv_send((char *)"213 Profile record follows:"); |
1363 srv_send((char *)"UUID,%s", profile->uuid); |
1371 srv_send((char *)"UUID,%s", profile->uuid); |
1364 srv_send((char *)"NAME,%s", profile->name); |
1372 srv_send((char *)"NAME,%s", profile->name); |
1365 srv_send((char *)"INITTEMP,%.1f", profile->inittemp); |
1373 srv_send((char *)"INITTEMP_LO,%.1f", profile->inittemp_lo); |
|
1374 srv_send((char *)"INITTEMP_HI,%.1f", profile->inittemp_hi); |
|
1375 srv_send((char *)"FRIDGE_MODE,%d", profile->fridge_mode); |
1366 srv_send((char *)"."); |
1376 srv_send((char *)"."); |
1367 return 0; |
1377 return 0; |
1368 } |
1378 } |
1369 } |
1379 } |
1370 srv_send((char *)"440 No such profile"); |
1380 srv_send((char *)"440 No such profile"); |
1391 if (strcmp(profile->name, val)) |
1401 if (strcmp(profile->name, val)) |
1392 syslog(LOG_NOTICE, "Profile %s name `%s' to `%s'", profile->uuid, profile->name, val); |
1402 syslog(LOG_NOTICE, "Profile %s name `%s' to `%s'", profile->uuid, profile->name, val); |
1393 free(profile->name); |
1403 free(profile->name); |
1394 } |
1404 } |
1395 profile->name = xstrcpy(val); |
1405 profile->name = xstrcpy(val); |
1396 } else if (strcmp(kwd, (char *)"INITTEMP") == 0) { |
1406 } else if (strcmp(kwd, (char *)"INITTEMP_LO") == 0) { |
1397 if (sscanf(val, "%f", &fval) == 1) { |
1407 if (sscanf(val, "%f", &fval) == 1) { |
1398 if (profile->inittemp != fval) |
1408 if (profile->inittemp_lo != fval) |
1399 syslog(LOG_NOTICE, "Profile %s initial temperature %.1f to %.1f", profile->uuid, profile->inittemp, fval); |
1409 syslog(LOG_NOTICE, "Profile %s initial temperature low %.1f to %.1f", profile->uuid, profile->inittemp_lo, fval); |
1400 profile->inittemp = fval; |
1410 profile->inittemp_lo = fval; |
|
1411 } |
|
1412 } else if (strcmp(kwd, (char *)"INITTEMP_HI") == 0) { |
|
1413 if (sscanf(val, "%f", &fval) == 1) { |
|
1414 if (profile->inittemp_hi != fval) |
|
1415 syslog(LOG_NOTICE, "Profile %s initial temperature high %.1f to %.1f", profile->uuid, profile->inittemp_hi, fval); |
|
1416 profile->inittemp_hi = fval; |
|
1417 } |
|
1418 } else if (strcmp(kwd, (char *)"FRIDGE_MODE") == 0) { |
|
1419 if (sscanf(val, "%d", &ival) == 1) { |
|
1420 if (profile->fridge_mode != ival) |
|
1421 syslog(LOG_NOTICE, "Profile %s fridge mode %d to %d", profile->uuid, profile->fridge_mode, ival); |
|
1422 profile->fridge_mode = ival; |
1401 } |
1423 } |
1402 } |
1424 } |
1403 } |
1425 } |
1404 } |
1426 } |
1405 } |
1427 } |
1450 srv_send((char *)"219 Accepted Profile steps"); |
1472 srv_send((char *)"219 Accepted Profile steps"); |
1451 return 1; |
1473 return 1; |
1452 } |
1474 } |
1453 sstep = strtok(ibuf, ",\0"); |
1475 sstep = strtok(ibuf, ",\0"); |
1454 rest = strtok(NULL, ",\0"); |
1476 rest = strtok(NULL, ",\0"); |
1455 targ = strtok(NULL, "\0"); |
1477 tlarg = strtok(NULL, ",\0"); |
|
1478 tharg = strtok(NULL, ",\0"); |
|
1479 frarg = strtok(NULL, "\0"); |
1456 |
1480 |
1457 if ((sscanf(sstep, "%d", &istep) == 1) && |
1481 if ((sscanf(sstep, "%d", &istep) == 1) && |
1458 (sscanf(rest, "%d", &irest) == 1) && |
1482 (sscanf(rest, "%d", &irest) == 1) && |
1459 (sscanf(targ, "%f", &ftarg) == 1)) { |
1483 (sscanf(tlarg, "%f", &ftlarg) == 1) && |
|
1484 (sscanf(tharg, "%f", &ftharg) == 1) && |
|
1485 (sscanf(frarg, "%d", &ifrarg) == 1)) { |
1460 |
1486 |
1461 j++; |
1487 j++; |
1462 syslog(LOG_NOTICE, "PROFILE PUTS %s add step %d: steptime=%d resttime=%d target=%.1f", |
1488 syslog(LOG_NOTICE, "PROFILE PUTS %s add step %d: steptime=%d resttime=%d target=%.1f..%.1f fridge_mode=%d", |
1463 profile->uuid, j, istep, irest, ftarg); |
1489 profile->uuid, j, istep, irest, ftlarg, ftharg, ifrarg); |
1464 step = (prof_step *)malloc(sizeof(prof_step)); |
1490 step = (prof_step *)malloc(sizeof(prof_step)); |
1465 step->next = NULL; |
1491 step->next = NULL; |
1466 step->version = 1; |
1492 step->version = 1; |
1467 step->steptime = istep; |
1493 step->steptime = istep; |
1468 step->resttime = irest; |
1494 step->resttime = irest; |
1469 step->target = ftarg; |
1495 step->target_lo = ftlarg; |
|
1496 step->target_hi = ftharg; |
|
1497 step->fridge_mode = ifrarg; |
1470 |
1498 |
1471 if (profile->steps == NULL) { |
1499 if (profile->steps == NULL) { |
1472 profile->steps = step; |
1500 profile->steps = step; |
1473 } else { |
1501 } else { |
1474 for (olds = profile->steps; olds; olds = olds->next) { |
1502 for (olds = profile->steps; olds; olds = olds->next) { |
2100 if (unit->prof_state == PROFILE_RUN) { |
2128 if (unit->prof_state == PROFILE_RUN) { |
2101 srv_send((char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent); |
2129 srv_send((char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent); |
2102 } else { |
2130 } else { |
2103 srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]); |
2131 srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]); |
2104 } |
2132 } |
2105 srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target); |
2133 srv_send((char *)"PROF_TARGET_LO,%.3f", unit->prof_target_lo); |
|
2134 srv_send((char *)"PROF_TARGET_HI,%.3f", unit->prof_target_hi); |
|
2135 srv_send((char *)"PROF_FRIDGE_MODE,%.3f", unit->prof_fridge_mode); |
2106 srv_send((char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs); |
2136 srv_send((char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs); |
2107 srv_send((char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel); |
2137 srv_send((char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel); |
2108 srv_send((char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done); |
2138 srv_send((char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done); |
2109 srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
2139 srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
2110 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); |
2140 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); |