503 graphstep = MAX_INTERVALS; |
503 graphstep = MAX_INTERVALS; |
504 syslog(LOG_NOTICE, "ARCHIVE LOG %s: lines=%d, interval=%d, graphstep=%d", param, lines, GRAPH_INTERVAL[graphstep], graphstep); |
504 syslog(LOG_NOTICE, "ARCHIVE LOG %s: lines=%d, interval=%d, graphstep=%d", param, lines, GRAPH_INTERVAL[graphstep], graphstep); |
505 |
505 |
506 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
506 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
507 /* |
507 /* |
508 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA,18.000,20.1 |
508 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA,18.000,20.1,5.312 |
509 * | | | | | | | | | | | | | | |
509 * | | | | | | | | | | | | | | | |
510 * date_n | | | | | | | | | | | | | |
510 * date_n | | | | | | | | | | | | | | |
511 * mode_n ----------+ | | | | | | | | | | | | |
511 * mode_n ----------+ | | | | | | | | | | | | | |
512 * air_n -----------------+ | | | | | | | | | | | |
512 * air_n -----------------+ | | | | | | | | | | | | |
513 * beer_n -----------------------+ | | | | | | | | | | |
513 * beer_n -----------------------+ | | | | | | | | | | | |
514 * target_lo_n ------------------------+ | | | | | | | | | |
514 * target_lo_n ------------------------+ | | | | | | | | | | |
515 * heater_n -------------------------------+ | | | | | | | | |
515 * heater_n -------------------------------+ | | | | | | | | | |
516 * cooler_n ---------------------------------+ | | | | | | | |
516 * cooler_n ---------------------------------+ | | | | | | | | |
517 * not used ------------------------------------+ | | | | | | |
517 * not used ------------------------------------+ | | | | | | | |
518 * not used ---------------------------------------+ | | | | | |
518 * not used ---------------------------------------+ | | | | | | |
519 * heater_u --------------------------------------------+ | | | | |
519 * heater_u --------------------------------------------+ | | | | | |
520 * cooler_u ------------------------------------------------+ | | | |
520 * cooler_u ------------------------------------------------+ | | | | |
521 * not used ---------------------------------------------------+ | | |
521 * not used ---------------------------------------------------+ | | | |
522 * room_n ----------------------------------------------------------+ | |
522 * room_n ----------------------------------------------------------+ | | |
523 * target_hi_n -----------------------------------------------------------+ |
523 * target_hi_n -----------------------------------------------------------+ | |
|
524 * chiller_n ------------------------------------------------------------------+ |
524 */ |
525 */ |
525 hr[0] = q[0] = buffer[11]; |
526 hr[0] = q[0] = buffer[11]; |
526 hr[1] = q[1] = buffer[12]; |
527 hr[1] = q[1] = buffer[12]; |
527 q[2] = buffer[14]; |
528 q[2] = buffer[14]; |
528 q[3] = buffer[15]; |
529 q[3] = buffer[15]; |
1219 } |
1222 } |
1220 filename = xstrcat(filename, (char *)"/.thermferm/log/"); |
1223 filename = xstrcat(filename, (char *)"/.thermferm/log/"); |
1221 filename = xstrcat(filename, unit->name); |
1224 filename = xstrcat(filename, unit->name); |
1222 filename = xstrcat(filename, (char *)".log"); |
1225 filename = xstrcat(filename, (char *)".log"); |
1223 if ((fp = fopen(filename, "r"))) { |
1226 if ((fp = fopen(filename, "r"))) { |
1224 |
1227 */ |
1225 /* |
1228 /* |
1226 * Count the lines in the logfile |
1229 * Count the lines in the logfile |
1227 */ |
1230 */ |
1228 lines = 0; |
1231 /* lines = 0; |
1229 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
1232 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
1230 lines++; |
1233 lines++; |
1231 } |
1234 } |
1232 fseek(fp, 0L, SEEK_SET); |
1235 fseek(fp, 0L, SEEK_SET); |
1233 /* |
1236 */ /* |
1234 * We have counted the lines in the logfile including the header lines. |
1237 * We have counted the lines in the logfile including the header lines. |
1235 * The header lines should be ignored but there are so few of them, we |
1238 * The header lines should be ignored but there are so few of them, we |
1236 * just include them in the total. |
1239 * just include them in the total. |
1237 * Now find a reasonable interval of lines to sent to the client. |
1240 * Now find a reasonable interval of lines to sent to the client. |
1238 */ |
1241 */ |
1239 for (graphstep = 1; graphstep <= MAX_INTERVALS; graphstep++) { |
1242 /* for (graphstep = 1; graphstep <= MAX_INTERVALS; graphstep++) { |
1240 if (lines < GRAPH_DATALINES[graphstep]) { |
1243 if (lines < GRAPH_DATALINES[graphstep]) { |
1241 break; |
1244 break; |
1242 } |
1245 } |
1243 } |
1246 } |
1244 if (graphstep > MAX_INTERVALS) |
1247 if (graphstep > MAX_INTERVALS) |
1245 graphstep = MAX_INTERVALS; |
1248 graphstep = MAX_INTERVALS; |
1246 syslog(LOG_NOTICE, "LIST LOG %s: lines=%d, interval=%d, graphstep=%d", unit->name, lines, GRAPH_INTERVAL[graphstep], graphstep); |
1249 syslog(LOG_NOTICE, "LIST LOG %s: lines=%d, interval=%d, graphstep=%d", unit->name, lines, GRAPH_INTERVAL[graphstep], graphstep); |
1247 |
1250 |
1248 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
1251 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
1249 /* |
1252 */ /* |
1250 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA |
1253 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA |
1251 */ |
1254 */ |
1252 hr[0] = q[0] = buffer[11]; |
1255 // hr[0] = q[0] = buffer[11]; |
1253 hr[1] = q[1] = buffer[12]; |
1256 // hr[1] = q[1] = buffer[12]; |
1254 q[2] = buffer[14]; |
1257 // q[2] = buffer[14]; |
1255 q[3] = buffer[15]; |
1258 // q[3] = buffer[15]; |
1256 hr[2] = '\0'; |
1259 // hr[2] = '\0'; |
1257 buffer[strlen(buffer) -1] = '\0'; |
1260 // buffer[strlen(buffer) -1] = '\0'; |
1258 date_n = strtok(buffer, ",\0"); /* timestamp */ |
1261 // date_n = strtok(buffer, ",\0"); /* timestamp */ |
1259 mode_n = strtok(NULL, ",\0"); /* unit mode */ |
1262 // mode_n = strtok(NULL, ",\0"); /* unit mode */ |
1260 air_n = strtok(NULL, ",\0"); /* air temp */ |
1263 // air_n = strtok(NULL, ",\0"); /* air temp */ |
1261 beer_n = strtok(NULL, ",\0"); /* beer temp */ |
1264 // beer_n = strtok(NULL, ",\0"); /* beer temp */ |
1262 target_lo_n = strtok(NULL, ",\0"); /* target low temp */ |
1265 // target_lo_n = strtok(NULL, ",\0"); /* target low temp */ |
1263 heater_n = strtok(NULL, ",\0"); /* current heater state */ |
1266 // heater_n = strtok(NULL, ",\0"); /* current heater state */ |
1264 cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
1267 // cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
1265 heater_u = strtok(NULL, ",\0"); /* current fan state */ |
1268 // heater_u = strtok(NULL, ",\0"); /* current fan state */ |
1266 heater_u = strtok(NULL, ",\0"); /* current door state */ |
1269 // heater_u = strtok(NULL, ",\0"); /* current door state */ |
1267 heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
1270 // heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
1268 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
1271 // cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
1269 room_n = strtok(NULL, ",\0"); /* fan use counter */ |
1272 // room_n = strtok(NULL, ",\0"); /* fan use counter */ |
1270 room_n = strtok(NULL, ",\0"); /* room temperature */ |
1273 // room_n = strtok(NULL, ",\0"); /* room temperature */ |
1271 target_hi_n = strtok(NULL, ",\0"); /* target high temp */ |
1274 // target_hi_n = strtok(NULL, ",\0"); /* target high temp */ |
1272 |
1275 // chiller_n = strtok(NULL, ",\0"); /* chiller temp */ |
1273 if (strncmp(mode_n, (char *)"Mode", 4)) { |
1276 |
|
1277 // if (strncmp(mode_n, (char *)"Mode", 4)) { |
1274 /* |
1278 /* |
1275 * Output a line at the right intervals |
1279 * Output a line at the right intervals |
1276 */ |
1280 */ |
1277 int hour = atoi(hr); |
1281 // int hour = atoi(hr); |
1278 if (((graphstep == 1)) || |
1282 // if (((graphstep == 1)) || |
1279 ((graphstep == 2) && (q[3] == '0' || q[3] == '5')) || |
1283 // ((graphstep == 2) && (q[3] == '0' || q[3] == '5')) || |
1280 ((graphstep == 3) && ((q[2] == '0' && q[3] == '0') || (q[2] == '1' && q[3] == '5') || (q[2] == '3' && q[3] == '0') || (q[2] == '4' && q[3] == '5'))) || |
1284 // ((graphstep == 3) && ((q[2] == '0' && q[3] == '0') || (q[2] == '1' && q[3] == '5') || (q[2] == '3' && q[3] == '0') || (q[2] == '4' && q[3] == '5'))) || |
1281 ((graphstep == 4) && ((q[2] == '0' && q[3] == '0') || (q[2] == '3' && q[3] == '0'))) || |
1285 // ((graphstep == 4) && ((q[2] == '0' && q[3] == '0') || (q[2] == '3' && q[3] == '0'))) || |
1282 ((graphstep == 5) && (q[2] == '0' && q[3] == '0')) || |
1286 // ((graphstep == 5) && (q[2] == '0' && q[3] == '0')) || |
1283 ((graphstep == 6) && (hour % 2 == 0) && (q[2] == '0' && q[3] == '0')) || /* 120 minutes */ |
1287 // ((graphstep == 6) && (hour % 2 == 0) && (q[2] == '0' && q[3] == '0')) || /* 120 minutes */ |
1284 ((graphstep == 7) && (hour % 4 == 0) && (q[2] == '0' && q[3] == '0')) || /* 240 minutes */ |
1288 // ((graphstep == 7) && (hour % 4 == 0) && (q[2] == '0' && q[3] == '0')) || /* 240 minutes */ |
1285 ((graphstep >= 8) && (hour % 8 == 0) && (q[2] == '0' && q[3] == '0')) ) { /* 480 minutes */ |
1289 // ((graphstep >= 8) && (hour % 8 == 0) && (q[2] == '0' && q[3] == '0')) ) { /* 480 minutes */ |
1286 heat_used = cool_used = 0; |
1290 // heat_used = cool_used = 0; |
1287 if (strcmp(heater_u, "NA") && (sscanf(heater_u, "%d", &h) == 1)) { |
1291 // if (strcmp(heater_u, "NA") && (sscanf(heater_u, "%d", &h) == 1)) { |
1288 if (h && heater_l) { |
1292 // if (h && heater_l) { |
1289 heat_used = ((h - heater_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
1293 // heat_used = ((h - heater_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
1290 } |
1294 // } |
1291 } |
1295 // } |
1292 if (strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) { |
1296 // if (strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) { |
1293 if (c && cooler_l) { |
1297 // if (c && cooler_l) { |
1294 cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
1298 // cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
1295 } |
1299 // } |
1296 } |
1300 // } |
1297 if (room_n) |
1301 // if (room_n) |
1298 sscanf(room_n, "%f", &room_t); |
1302 // sscanf(room_n, "%f", &room_t); |
1299 else |
1303 // else |
1300 room_t = 0.0; |
1304 // room_t = 0.0; |
1301 if (target_hi_n == NULL) |
1305 // if (target_hi_n == NULL) |
1302 target_hi_n = target_lo_n; |
1306 // target_hi_n = target_lo_n; |
1303 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f,%s", |
1307 // snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f,%s,%s", |
1304 date_n, mode_n, air_n, beer_n, target_lo_n, heater_n, cooler_n, heat_used, cool_used, room_t, target_hi_n); |
1308 // date_n, mode_n, air_n, beer_n, target_lo_n, heater_n, cooler_n, |
1305 srv_send(outbuf); |
1309 // heat_used, cool_used, room_t, target_hi_n, chiller_n); |
1306 if (h && strcmp(heater_u, "NA")) |
1310 // srv_send(outbuf); |
1307 heater_l = h; |
1311 // if (h && strcmp(heater_u, "NA")) |
1308 if (c & strcmp(cooler_u, "NA")) |
1312 // heater_l = h; |
1309 cooler_l = c; |
1313 // if (c & strcmp(cooler_u, "NA")) |
1310 } |
1314 // cooler_l = c; |
1311 } |
1315 // } |
1312 } |
1316 // } |
1313 } |
1317 // } |
1314 free(filename); |
1318 // } |
1315 filename = NULL; |
1319 // free(filename); |
1316 srv_send((char *)"."); |
1320 // filename = NULL; |
1317 return 0; |
1321 // srv_send((char *)"."); |
|
1322 // return 0; |
1318 } |
1323 } |
1319 |
1324 |
1320 srv_send((char *)"504 Subcommand error"); |
1325 srv_send((char *)"504 Subcommand error"); |
1321 return 0; |
1326 return 0; |
1322 } |
1327 } |