thermferm/server.c

changeset 358
8b7ef338bf49
parent 356
44bcfe087f9e
child 362
c92651a54969
equal deleted inserted replaced
357:64cd9865bd11 358:8b7ef338bf49
1055 * LIST LOG 1055 * LIST LOG
1056 */ 1056 */
1057 int cmd_list(char *buf) 1057 int cmd_list(char *buf)
1058 { 1058 {
1059 char *opt, *param, *filename, q[5], buffer[256], outbuf[256]; 1059 char *opt, *param, *filename, q[5], buffer[256], outbuf[256];
1060 char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n; 1060 char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n, *room_n;
1061 char *heater_u, *cooler_u; 1061 char *heater_u, *cooler_u;
1062 int heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, lines = 0, graphstep = 0; 1062 int heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, lines = 0, graphstep = 0;
1063 units_list *unit; 1063 units_list *unit;
1064 FILE *fp; 1064 FILE *fp;
1065 float room_t;
1065 1066
1066 opt = strtok(buf, " \0"); 1067 opt = strtok(buf, " \0");
1067 opt = strtok(NULL, " \0"); 1068 opt = strtok(NULL, " \0");
1068 1069
1069 if (opt == NULL) { 1070 if (opt == NULL) {
1141 cooler_n = strtok(NULL, ",\0"); /* current cooler state */ 1142 cooler_n = strtok(NULL, ",\0"); /* current cooler state */
1142 heater_u = strtok(NULL, ",\0"); /* current fan state */ 1143 heater_u = strtok(NULL, ",\0"); /* current fan state */
1143 heater_u = strtok(NULL, ",\0"); /* current door state */ 1144 heater_u = strtok(NULL, ",\0"); /* current door state */
1144 heater_u = strtok(NULL, ",\0"); /* heater use counter */ 1145 heater_u = strtok(NULL, ",\0"); /* heater use counter */
1145 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ 1146 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */
1147 room_n = strtok(NULL, ",\0"); /* fan use counter */
1148 room_n = strtok(NULL, ",\0"); /* room temperature */
1146 1149
1147 if (strncmp(mode_n, (char *)"Mode", 4)) { 1150 if (strncmp(mode_n, (char *)"Mode", 4)) {
1148 /* 1151 /*
1149 * Output a line at the right intervals 1152 * Output a line at the right intervals
1150 */ 1153 */
1162 if (strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) { 1165 if (strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) {
1163 if (c && cooler_l) { 1166 if (c && cooler_l) {
1164 cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); 1167 cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60);
1165 } 1168 }
1166 } 1169 }
1167 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d", 1170 if (room_n)
1168 date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used); 1171 sscanf(room_n, "%f", &room_t);
1172 else
1173 room_t = 0.0;
1174 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f",
1175 date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used, room_t);
1169 srv_send(outbuf); 1176 srv_send(outbuf);
1170 if (h && strcmp(heater_u, "NA")) 1177 if (h && strcmp(heater_u, "NA"))
1171 heater_l = h; 1178 heater_l = h;
1172 if (c & strcmp(cooler_u, "NA")) 1179 if (c & strcmp(cooler_u, "NA"))
1173 cooler_l = c; 1180 cooler_l = c;

mercurial