thermferm/server.c

changeset 714
24749c296a50
parent 708
13555c27b592
child 715
f5d85af156ab
equal deleted inserted replaced
713:ea24b4ce02b1 714:24749c296a50
24 #include "thermferm.h" 24 #include "thermferm.h"
25 #include "delay.h" 25 #include "delay.h"
26 #include "one-wire.h" 26 #include "one-wire.h"
27 #include "devices.h" 27 #include "devices.h"
28 #include "server.h" 28 #include "server.h"
29 #include "simulator.h"
29 #include "lcd-buffer.h" 30 #include "lcd-buffer.h"
30 #include "xutil.h" 31 #include "xutil.h"
31 #include "mqtt.h" 32 #include "mqtt.h"
32 33
33 34
1001 */ 1002 */
1002 int cmd_simulator(int s, char *buf) 1003 int cmd_simulator(int s, char *buf)
1003 { 1004 {
1004 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; 1005 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
1005 simulator_list *simulator, *tmps; 1006 simulator_list *simulator, *tmps;
1006 int rc, rlen, ival; 1007 int rc, rlen, ival, i;
1007 float fval; 1008 float fval;
1008 uuid_t uu; 1009 uuid_t uu;
1009 1010
1010 opt = strtok(buf, " \0"); 1011 opt = strtok(buf, " \0");
1011 opt = strtok(NULL, " \0"); 1012 opt = strtok(NULL, " \0");
1022 srv_send(s, (char *)"SIMULATOR ADD name Add a new Simulator with name"); 1023 srv_send(s, (char *)"SIMULATOR ADD name Add a new Simulator with name");
1023 srv_send(s, (char *)"SIMULATOR DEL uuid Delete Simulator by uuid"); 1024 srv_send(s, (char *)"SIMULATOR DEL uuid Delete Simulator by uuid");
1024 srv_send(s, (char *)"SIMULATOR LIST List all Simulators"); 1025 srv_send(s, (char *)"SIMULATOR LIST List all Simulators");
1025 srv_send(s, (char *)"SIMULATOR GET uuid Get Simulator record by uuid"); 1026 srv_send(s, (char *)"SIMULATOR GET uuid Get Simulator record by uuid");
1026 srv_send(s, (char *)"SIMULATOR PUT uuid Put Simulator record by uuid"); 1027 srv_send(s, (char *)"SIMULATOR PUT uuid Put Simulator record by uuid");
1028 srv_send(s, (char *)"SIMULATOR JSON Get json records");
1027 srv_send(s, (char *)"."); 1029 srv_send(s, (char *)".");
1028 return 0; 1030 return 0;
1029 } 1031 }
1030 1032
1031 if (strcmp(opt, (char *)"LIST") == 0) { 1033 if (strcmp(opt, (char *)"LIST") == 0) {
1032 srv_send(s, (char *)"212 Simulators list follows:"); 1034 srv_send(s, (char *)"212 Simulators list follows:");
1033 for (simulator = Config.simulators; simulator; simulator = simulator->next) { 1035 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
1034 srv_send(s, (char *)"%s,%s", simulator->uuid, simulator->name); 1036 srv_send(s, (char *)"%s,%d,%s", simulator->uuid, simulator->simno, simulator->name);
1035 } 1037 }
1036 srv_send(s, (char *)"."); 1038 srv_send(s, (char *)".");
1037 return 0; 1039 return 0;
1040 }
1041
1042 if (strcmp(opt, (char *)"JSON") == 0) {
1043 char *payload = NULL, *payloadu = NULL;
1044 bool comma = false;
1045
1046 if (param == NULL) {
1047 srv_send(s, (char *)"212 Simulators json list follows:");
1048 payload = xstrcpy((char *)"[");
1049 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
1050 if (comma)
1051 payload = xstrcat(payload, (char *)",");
1052 payloadu = simulator_json(simulator);
1053 payload = xstrcat(payload, payloadu);
1054 comma = true;
1055 free(payloadu);
1056 payloadu = NULL;
1057 }
1058 payload = xstrcat(payload, (char *)"]");
1059 large_send(s, payload);
1060 srv_send(s, (char *)".");
1061 free(payload);
1062 payload = NULL;
1063 return 0;
1064 }
1038 } 1065 }
1039 1066
1040 if (param == NULL) { 1067 if (param == NULL) {
1041 srv_send(s, (char *)"502 Parameter missing"); 1068 srv_send(s, (char *)"502 Parameter missing");
1042 return 0; 1069 return 0;
1043 } 1070 }
1044 1071
1045 if (strcmp(opt, (char *)"ADD") == 0) { 1072 if (strcmp(opt, (char *)"ADD") == 0) {
1073 int highno = 0, count = 0;
1074 char abuf[64];
1046 1075
1047 /* 1076 /*
1048 * For now, only one simulator is allowed. 1077 * For now, only one simulator is allowed.
1049 */ 1078 */
1050 if (Config.simulators) { 1079 if (Config.simulators) {
1080 for (tmps = Config.simulators; tmps; tmps = tmps->next) {
1081 if (tmps->simno > highno)
1082 highno = tmps->simno;
1083 count++;
1084 }
1085 }
1086 if (count >= 5) {
1051 srv_send(s, (char *)"441 Maximum simulators reached"); 1087 srv_send(s, (char *)"441 Maximum simulators reached");
1052 return 0; 1088 return 0;
1053 } 1089 }
1054 1090
1055 simulator = (simulator_list *)malloc(sizeof(simulator_list)); 1091 simulator = (simulator_list *)malloc(sizeof(simulator_list));
1056 simulator->next = NULL; 1092 simulator->next = NULL;
1057 simulator->uuid = malloc(37); 1093 simulator->uuid = malloc(37);
1058 uuid_generate(uu); 1094 uuid_generate(uu);
1059 uuid_unparse(uu, simulator->uuid); 1095 uuid_unparse(uu, simulator->uuid);
1060 simulator->name = xstrcpy(param); 1096 simulator->name = xstrcpy(param);
1097 simulator->simno = highno + 1;
1098 sprintf(abuf, "%d-", simulator->simno);
1061 simulator->volume_air = 150; 1099 simulator->volume_air = 150;
1062 simulator->volume_beer = 50; 1100 simulator->volume_beer = 50;
1063 simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0; 1101 simulator->room_tempaddress = xstrcpy(abuf);
1102 simulator->room_tempaddress = xstrcat(simulator->room_tempaddress, (char *)"SimRoomTemp");
1103 simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->beer_temperature2 = 20.0;
1104 simulator->s_cool_temp = simulator->s_heat_temp = 20.0;
1105 simulator->room_humaddress = xstrcpy(abuf);
1106 simulator->room_humaddress = xstrcat(simulator->room_humaddress, (char *)"SimRoomHum");
1064 simulator->room_humidity = 48.6; 1107 simulator->room_humidity = 48.6;
1108 simulator->air_address = xstrcpy(abuf);
1109 simulator->air_address = xstrcat(simulator->air_address, (char *)"SimAirTemp");
1110 simulator->beer_address = xstrcpy(abuf);
1111 simulator->beer_address = xstrcat(simulator->beer_address, (char *)"SimBeerTemp");
1112 simulator->beer_address2 = xstrcpy(abuf);
1113 simulator->beer_address2 = xstrcat(simulator->beer_address2, (char *)"SimBeerTemp2");
1114 simulator->chiller_address = xstrcpy(abuf);
1115 simulator->chiller_address = xstrcat(simulator->chiller_address, (char *)"SimChillerTemp");
1116 simulator->heater_address = xstrcpy(abuf);
1117 simulator->heater_address = xstrcat(simulator->heater_address, (char *)"SimHeater");
1118 simulator->cooler_address = xstrcpy(abuf);
1119 simulator->cooler_address = xstrcat(simulator->cooler_address, (char *)"SimCooler");
1120 simulator->fan_address = xstrcpy(abuf);
1121 simulator->fan_address = xstrcat(simulator->fan_address, (char *)"SimFan");
1122 simulator->light_address = xstrcpy(abuf);
1123 simulator->light_address = xstrcat(simulator->light_address, (char *)"SimLight");
1065 simulator->chiller_temperature = 1.5; /* Chiller temperature */ 1124 simulator->chiller_temperature = 1.5; /* Chiller temperature */
1066 simulator->cooler_temp = 1.5; /* Cooling temperature */ 1125 simulator->cooler_temp = 1.5; /* Cooling temperature */
1067 simulator->cooler_time = 720; /* About 12 minutes for the cooler plate */ 1126 simulator->cooler_time = 720; /* About 12 minutes for the cooler plate */
1068 simulator->cooler_size = 0.8; /* 0.8 square meter cooler plate */ 1127 simulator->cooler_size = 0.8; /* 0.8 square meter cooler plate */
1069 simulator->heater_temp = 150.0; /* Heating temperature */ 1128 simulator->heater_temp = 150.0; /* Heating temperature */
1070 simulator->heater_time = 3; /* 3 seconds to heat-up */ 1129 simulator->heater_time = 3; /* 3 seconds to heat-up */
1071 simulator->heater_size = 0.01; /* 0.01 square meter heater plate */ 1130 simulator->heater_size = 0.01; /* 0.01 square meter heater plate */
1072 simulator->heater_state = simulator->cooler_state = 0; 1131 simulator->air_present = simulator->beer_present = DEVPRESENT_YES;
1132 simulator->beer_present2 = simulator->chiller_present = simulator->cooler_present = simulator->heater_present = DEVPRESENT_UNDEF;
1073 simulator->frigo_isolation = 0.002; 1133 simulator->frigo_isolation = 0.002;
1134 simulator->timestamp = time(NULL);
1074 simulator->s_yeast_heat = 0.0; 1135 simulator->s_yeast_heat = 0.0;
1075 simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (int)0; 1136 simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (int)0;
1076 1137
1077 if (Config.simulators == NULL) { 1138 if (Config.simulators == NULL) {
1078 Config.simulators = simulator; 1139 Config.simulators = simulator;
1083 break; 1144 break;
1084 } 1145 }
1085 } 1146 }
1086 } 1147 }
1087 1148
1088 syslog(LOG_NOTICE, "Simulator %s added", simulator->uuid); 1149 syslog(LOG_NOTICE, "Simulator %s no %d added", simulator->uuid, simulator->simno);
1089 srv_send(s, (char *)"211 Simulator %s added", simulator->uuid); 1150 srv_send(s, (char *)"211 Simulator %s added", simulator->uuid);
1090 return 1; 1151 return 1;
1091 } 1152 }
1092 1153
1093 if (strcmp(opt, (char *)"DEL") == 0) { 1154 if (strcmp(opt, (char *)"DEL") == 0) {
1155 // TODO: check devices in use.
1156 // TODO: delete simulated devices.
1094 rc = delete_Simulator(param); 1157 rc = delete_Simulator(param);
1095 if (rc) { 1158 if (rc) {
1096 syslog(LOG_NOTICE, "Simulator %s deleted", param); 1159 syslog(LOG_NOTICE, "Simulator %s deleted", param);
1097 srv_send(s, (char *)"211 Simulator %s deleted", param); 1160 srv_send(s, (char *)"211 Simulator %s deleted", param);
1098 return 1; 1161 return 1;
1105 if (strcmp(opt, (char *)"GET") == 0) { 1168 if (strcmp(opt, (char *)"GET") == 0) {
1106 for (simulator = Config.simulators; simulator; simulator = simulator->next) { 1169 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
1107 if (strcmp(simulator->uuid, param) == 0) { 1170 if (strcmp(simulator->uuid, param) == 0) {
1108 srv_send(s, (char *)"213 Simulator record follows:"); 1171 srv_send(s, (char *)"213 Simulator record follows:");
1109 srv_send(s, (char *)"NAME,%s", simulator->name); 1172 srv_send(s, (char *)"NAME,%s", simulator->name);
1173 srv_send(s, (char *)"SIMNO,%d", simulator->simno);
1110 srv_send(s, (char *)"VOLUME_AIR,%d", simulator->volume_air); 1174 srv_send(s, (char *)"VOLUME_AIR,%d", simulator->volume_air);
1111 srv_send(s, (char *)"VOLUME_BEER,%d", simulator->volume_beer); 1175 srv_send(s, (char *)"VOLUME_BEER,%d", simulator->volume_beer);
1176 srv_send(s, (char *)"ROOM_TEMPADDRESS,%s", simulator->room_tempaddress);
1112 srv_send(s, (char *)"ROOM_TEMPERATURE,%.1f", simulator->room_temperature); 1177 srv_send(s, (char *)"ROOM_TEMPERATURE,%.1f", simulator->room_temperature);
1178 srv_send(s, (char *)"ROOM_HUMADDRESS,%s", simulator->room_humaddress);
1113 srv_send(s, (char *)"ROOM_HUMIDITY,%.1f", simulator->room_humidity); 1179 srv_send(s, (char *)"ROOM_HUMIDITY,%.1f", simulator->room_humidity);
1180 srv_send(s, (char *)"AIR_ADDRESS,%s", simulator->air_address);
1114 srv_send(s, (char *)"AIR_TEMPERATURE,%.3f", simulator->air_temperature); 1181 srv_send(s, (char *)"AIR_TEMPERATURE,%.3f", simulator->air_temperature);
1182 srv_send(s, (char *)"AIR_PRESENT,%s", DEVPRESENT[simulator->air_present]);
1183 srv_send(s, (char *)"BEER_ADDRESS,%s", simulator->beer_address);
1115 srv_send(s, (char *)"BEER_TEMPERATURE,%.3f", simulator->beer_temperature); 1184 srv_send(s, (char *)"BEER_TEMPERATURE,%.3f", simulator->beer_temperature);
1185 srv_send(s, (char *)"BEER_PRESENT,%s", DEVPRESENT[simulator->beer_present]);
1186 srv_send(s, (char *)"BEER_ADDRESS2,%s", simulator->beer_address2);
1187 srv_send(s, (char *)"BEER_TEMPERATURE2,%.3f", simulator->beer_temperature2);
1188 srv_send(s, (char *)"BEER_PRESENT2,%s", DEVPRESENT[simulator->beer_present2]);
1189 srv_send(s, (char *)"CHILLER_ADDRESS,%s", simulator->chiller_address);
1116 srv_send(s, (char *)"CHILLER_TEMPERATURE,%.3f", simulator->chiller_temperature); 1190 srv_send(s, (char *)"CHILLER_TEMPERATURE,%.3f", simulator->chiller_temperature);
1191 srv_send(s, (char *)"CHILLER_PRESENT,%s", DEVPRESENT[simulator->chiller_present]);
1192 srv_send(s, (char *)"COOLER_ADDRESS,%s", simulator->cooler_address);
1117 srv_send(s, (char *)"COOLER_TEMP,%.1f", simulator->cooler_temp); 1193 srv_send(s, (char *)"COOLER_TEMP,%.1f", simulator->cooler_temp);
1118 srv_send(s, (char *)"COOLER_TIME,%d", simulator->cooler_time); 1194 srv_send(s, (char *)"COOLER_TIME,%d", simulator->cooler_time);
1119 srv_send(s, (char *)"COOLER_SIZE,%.3f", simulator->cooler_size); 1195 srv_send(s, (char *)"COOLER_SIZE,%.3f", simulator->cooler_size);
1196 srv_send(s, (char *)"COOLER_PRESENT,%s", DEVPRESENT[simulator->cooler_present]);
1197 srv_send(s, (char *)"COOLER_POWER,%d", simulator->cooler_power);
1198 srv_send(s, (char *)"HEATER_ADDRESS,%s", simulator->heater_address);
1120 srv_send(s, (char *)"HEATER_TEMP,%.1f", simulator->heater_temp); 1199 srv_send(s, (char *)"HEATER_TEMP,%.1f", simulator->heater_temp);
1121 srv_send(s, (char *)"HEATER_TIME,%d", simulator->heater_time); 1200 srv_send(s, (char *)"HEATER_TIME,%d", simulator->heater_time);
1122 srv_send(s, (char *)"HEATER_SIZE,%.3f", simulator->heater_size); 1201 srv_send(s, (char *)"HEATER_SIZE,%.3f", simulator->heater_size);
1123 srv_send(s, (char *)"HEATER_STATE,%d", simulator->heater_state); 1202 srv_send(s, (char *)"HEATER_PRESENT,%s", DEVPRESENT[simulator->heater_present]);
1124 srv_send(s, (char *)"COOLER_STATE,%d", simulator->cooler_state); 1203 srv_send(s, (char *)"HEATER_POWER,%d", simulator->heater_power);
1204 srv_send(s, (char *)"FAN_ADDRESS,%s", simulator->fan_address);
1205 srv_send(s, (char *)"FAN_PRESENT,%s", DEVPRESENT[simulator->fan_present]);
1206 srv_send(s, (char *)"FAN_POWER,%d", simulator->fan_power);
1207 srv_send(s, (char *)"LIGHT_ADDRESS,%s", simulator->light_address);
1208 srv_send(s, (char *)"LIGHT_PRESENT,%s", DEVPRESENT[simulator->light_present]);
1209 srv_send(s, (char *)"LIGHT_POWER,%d", simulator->light_power);
1125 srv_send(s, (char *)"FRIGO_ISOLATION,%.3f", simulator->frigo_isolation); 1210 srv_send(s, (char *)"FRIGO_ISOLATION,%.3f", simulator->frigo_isolation);
1211 srv_send(s, (char *)"TIMESTAMP,%ld", (long)simulator->timestamp);
1126 srv_send(s, (char *)"."); 1212 srv_send(s, (char *)".");
1127 return 0; 1213 return 0;
1128 } 1214 }
1129 } 1215 }
1130 srv_send(s, (char *)"440 No such simulator"); 1216 srv_send(s, (char *)"440 No such simulator");
1140 return 0; 1226 return 0;
1141 } 1227 }
1142 if (strlen(ibuf)) { 1228 if (strlen(ibuf)) {
1143 if (strcmp(ibuf, (char *)".") == 0) { 1229 if (strcmp(ibuf, (char *)".") == 0) {
1144 srv_send(s, (char *)"219 Accepted Simulator record"); 1230 srv_send(s, (char *)"219 Accepted Simulator record");
1231 simulator->timestamp = time(NULL);
1145 return 1; 1232 return 1;
1146 } 1233 }
1147 kwd = strtok(ibuf, ",\0"); 1234 kwd = strtok(ibuf, ",\0");
1148 val = strtok(NULL, "\0"); 1235 val = strtok(NULL, "\0");
1149 if (kwd && val) { 1236 if (kwd && val) {
1189 if (simulator->air_temperature != fval) 1276 if (simulator->air_temperature != fval)
1190 syslog(LOG_NOTICE, "Simulator %s air temperature %.1f to %.1f", simulator->uuid, simulator->air_temperature, fval); 1277 syslog(LOG_NOTICE, "Simulator %s air temperature %.1f to %.1f", simulator->uuid, simulator->air_temperature, fval);
1191 simulator->air_temperature = fval; 1278 simulator->air_temperature = fval;
1192 } 1279 }
1193 1280
1281 } else if (strcmp(kwd, (char *)"AIR_PRESENT") == 0) {
1282 for (i = 0; i < 4; i++) {
1283 if (strcmp(val, DEVPRESENT[i]) == 0) {
1284 if (simulator->air_present != i)
1285 syslog(LOG_NOTICE, "Simulator %s air_present %s to %s", simulator->uuid, DEVPRESENT[simulator->air_present], DEVPRESENT[i]);
1286 simulator->air_present = i;
1287 break;
1288 }
1289 }
1290
1194 } else if (strcmp(kwd, (char *)"BEER_TEMPERATURE") == 0) { 1291 } else if (strcmp(kwd, (char *)"BEER_TEMPERATURE") == 0) {
1195 if (sscanf(val, "%f", &fval) == 1) { 1292 if (sscanf(val, "%f", &fval) == 1) {
1196 if (simulator->beer_temperature != fval) 1293 if (simulator->beer_temperature != fval)
1197 syslog(LOG_NOTICE, "Simulator %s beer temperature %.1f to %.1f", simulator->uuid, simulator->beer_temperature, fval); 1294 syslog(LOG_NOTICE, "Simulator %s beer temperature %.1f to %.1f", simulator->uuid, simulator->beer_temperature, fval);
1198 simulator->beer_temperature = fval; 1295 simulator->beer_temperature = fval;
1199 } 1296 }
1200 1297
1298 } else if (strcmp(kwd, (char *)"BEER_PRESENT") == 0) {
1299 for (i = 0; i < 4; i++) {
1300 if (strcmp(val, DEVPRESENT[i]) == 0) {
1301 if (simulator->beer_present != i)
1302 syslog(LOG_NOTICE, "Simulator %s beer_present %s to %s", simulator->uuid, DEVPRESENT[simulator->beer_present], DEVPRESENT[i]);
1303 simulator->beer_present = i;
1304 break;
1305 }
1306 }
1307
1308 } else if (strcmp(kwd, (char *)"BEER_TEMPERATURE2") == 0) {
1309 if (sscanf(val, "%f", &fval) == 1) {
1310 if (simulator->beer_temperature2 != fval)
1311 syslog(LOG_NOTICE, "Simulator %s beer temperature2 %.1f to %.1f", simulator->uuid, simulator->beer_temperature2, fval);
1312 simulator->beer_temperature2 = fval;
1313 }
1314
1315 } else if (strcmp(kwd, (char *)"BEER_PRESENT2") == 0) {
1316 for (i = 0; i < 4; i++) {
1317 if (strcmp(val, DEVPRESENT[i]) == 0) {
1318 if (simulator->beer_present2 != i)
1319 syslog(LOG_NOTICE, "Simulator %s beer_present2 %s to %s", simulator->uuid, DEVPRESENT[simulator->beer_present2], DEVPRESENT[i]);
1320 simulator->beer_present2 = i;
1321 break;
1322 }
1323 }
1324
1201 } else if (strcmp(kwd, (char *)"CHILLER_TEMPERATURE") == 0) { 1325 } else if (strcmp(kwd, (char *)"CHILLER_TEMPERATURE") == 0) {
1202 if (sscanf(val, "%f", &fval) == 1) { 1326 if (sscanf(val, "%f", &fval) == 1) {
1203 if (simulator->chiller_temperature != fval) 1327 if (simulator->chiller_temperature != fval)
1204 syslog(LOG_NOTICE, "Simulator %s chiller temperature %.1f to %.1f", simulator->uuid, simulator->chiller_temperature, fval); 1328 syslog(LOG_NOTICE, "Simulator %s chiller temperature %.1f to %.1f", simulator->uuid, simulator->chiller_temperature, fval);
1205 simulator->chiller_temperature = fval; 1329 simulator->chiller_temperature = fval;
1206 } 1330 }
1331
1332 } else if (strcmp(kwd, (char *)"CHILLER_PRESENT") == 0) {
1333 for (i = 0; i < 4; i++) {
1334 if (strcmp(val, DEVPRESENT[i]) == 0) {
1335 if (simulator->chiller_present != i)
1336 syslog(LOG_NOTICE, "Simulator %s chiller_present %s to %s", simulator->uuid, DEVPRESENT[simulator->chiller_present], DEVPRESENT[i]);
1337 simulator->chiller_present = i;
1338 break;
1339 }
1340 }
1207 1341
1208 } else if (strcmp(kwd, (char *)"COOLER_TEMP") == 0) { 1342 } else if (strcmp(kwd, (char *)"COOLER_TEMP") == 0) {
1209 if (sscanf(val, "%f", &fval) == 1) { 1343 if (sscanf(val, "%f", &fval) == 1) {
1210 if (simulator->cooler_temp != fval) 1344 if (simulator->cooler_temp != fval)
1211 syslog(LOG_NOTICE, "Simulator %s cooler temperature %.1f to %.1f", simulator->uuid, simulator->cooler_temp, fval); 1345 syslog(LOG_NOTICE, "Simulator %s cooler temperature %.1f to %.1f", simulator->uuid, simulator->cooler_temp, fval);
1224 if (simulator->cooler_size != fval) 1358 if (simulator->cooler_size != fval)
1225 syslog(LOG_NOTICE, "Simulator %s cooler size %.1f to %.1f", simulator->uuid, simulator->cooler_size, fval); 1359 syslog(LOG_NOTICE, "Simulator %s cooler size %.1f to %.1f", simulator->uuid, simulator->cooler_size, fval);
1226 simulator->cooler_size = fval; 1360 simulator->cooler_size = fval;
1227 } 1361 }
1228 1362
1363 } else if (strcmp(kwd, (char *)"COOLER_PRESENT") == 0) {
1364 for (i = 0; i < 4; i++) {
1365 if (strcmp(val, DEVPRESENT[i]) == 0) {
1366 if (simulator->cooler_present != i)
1367 syslog(LOG_NOTICE, "Simulator %s cooler_present %s to %s", simulator->uuid, DEVPRESENT[simulator->cooler_present], DEVPRESENT[i]);
1368 simulator->cooler_present = i;
1369 break;
1370 }
1371 }
1372
1373 } else if (strcmp(kwd, (char *)"COOLER_POWER") == 0) {
1374 if (sscanf(val, "%d", &ival) == 1) {
1375 if (simulator->cooler_power != ival)
1376 syslog(LOG_NOTICE, "Simulator %s cooler power %d to %d", simulator->uuid, simulator->cooler_power, ival);
1377 simulator->cooler_power = ival;
1378 }
1379
1229 } else if (strcmp(kwd, (char *)"HEATER_TEMP") == 0) { 1380 } else if (strcmp(kwd, (char *)"HEATER_TEMP") == 0) {
1230 if (sscanf(val, "%f", &fval) == 1) { 1381 if (sscanf(val, "%f", &fval) == 1) {
1231 if (simulator->heater_temp != fval) 1382 if (simulator->heater_temp != fval)
1232 syslog(LOG_NOTICE, "Simulator %s heater temperature %.1f to %.1f", simulator->uuid, simulator->heater_temp, fval); 1383 syslog(LOG_NOTICE, "Simulator %s heater temperature %.1f to %.1f", simulator->uuid, simulator->heater_temp, fval);
1233 simulator->heater_temp = fval; 1384 simulator->heater_temp = fval;
1245 if (simulator->heater_size != fval) 1396 if (simulator->heater_size != fval)
1246 syslog(LOG_NOTICE, "Simulator %s heater size %.1f to %.1f", simulator->uuid, simulator->heater_size, fval); 1397 syslog(LOG_NOTICE, "Simulator %s heater size %.1f to %.1f", simulator->uuid, simulator->heater_size, fval);
1247 simulator->heater_size = fval; 1398 simulator->heater_size = fval;
1248 } 1399 }
1249 1400
1250 } else if (strcmp(kwd, (char *)"HEATER_STATE") == 0) { 1401 } else if (strcmp(kwd, (char *)"HEATER_PRESENT") == 0) {
1251 if (sscanf(val, "%d", &ival) == 1) { 1402 for (i = 0; i < 4; i++) {
1252 if (simulator->heater_state != ival) 1403 if (strcmp(val, DEVPRESENT[i]) == 0) {
1253 syslog(LOG_NOTICE, "Simulator %s heater state %d to %d", simulator->uuid, simulator->heater_state, ival); 1404 if (simulator->heater_present != i)
1254 simulator->heater_state = ival; 1405 syslog(LOG_NOTICE, "Simulator %s heater_present %s to %s", simulator->uuid, DEVPRESENT[simulator->heater_present], DEVPRESENT[i]);
1255 } 1406 simulator->heater_present = i;
1256 1407 break;
1257 } else if (strcmp(kwd, (char *)"COOLER_STATE") == 0) { 1408 }
1258 if (sscanf(val, "%d", &ival) == 1) { 1409 }
1259 if (simulator->cooler_state != ival) 1410
1260 syslog(LOG_NOTICE, "Simulator %s cooler state %d to %d", simulator->uuid, simulator->cooler_state, ival); 1411 } else if (strcmp(kwd, (char *)"HEATER_POWER") == 0) {
1261 simulator->cooler_state = ival; 1412 if (sscanf(val, "%d", &ival) == 1) {
1262 } 1413 if (simulator->heater_power != ival)
1414 syslog(LOG_NOTICE, "Simulator %s heater power %d to %d", simulator->uuid, simulator->heater_power, ival);
1415 simulator->heater_power = ival;
1416 }
1417
1418 } else if (strcmp(kwd, (char *)"FAN_PRESENT") == 0) {
1419 for (i = 0; i < 4; i++) {
1420 if (strcmp(val, DEVPRESENT[i]) == 0) {
1421 if (simulator->fan_present != i)
1422 syslog(LOG_NOTICE, "Simulator %s fan_present %s to %s", simulator->uuid, DEVPRESENT[simulator->fan_present], DEVPRESENT[i]);
1423 simulator->fan_present = i;
1424 break;
1425 }
1426 }
1427
1428 } else if (strcmp(kwd, (char *)"FAN_POWER") == 0) {
1429 if (sscanf(val, "%d", &ival) == 1) {
1430 if (simulator->fan_power != ival)
1431 syslog(LOG_NOTICE, "Simulator %s fan power %d to %d", simulator->uuid, simulator->fan_power, ival);
1432 simulator->fan_power = ival;
1433 }
1434
1435 } else if (strcmp(kwd, (char *)"LIGHT_PRESENT") == 0) {
1436 for (i = 0; i < 4; i++) {
1437 if (strcmp(val, DEVPRESENT[i]) == 0) {
1438 if (simulator->light_present != i)
1439 syslog(LOG_NOTICE, "Simulator %s light_present %s to %s", simulator->uuid, DEVPRESENT[simulator->light_present], DEVPRESENT[i]);
1440 simulator->light_present = i;
1441 break;
1442 }
1443 }
1444
1445 } else if (strcmp(kwd, (char *)"LIGHT_POWER") == 0) {
1446 if (sscanf(val, "%d", &ival) == 1) {
1447 if (simulator->fan_power != ival)
1448 syslog(LOG_NOTICE, "Simulator %s light power %d to %d", simulator->uuid, simulator->light_power, ival);
1449 simulator->light_power = ival;
1450 }
1263 1451
1264 } else if (strcmp(kwd, (char *)"FRIGO_ISOLATION") == 0) { 1452 } else if (strcmp(kwd, (char *)"FRIGO_ISOLATION") == 0) {
1265 if (sscanf(val, "%f", &fval) == 1) { 1453 if (sscanf(val, "%f", &fval) == 1) {
1266 if (simulator->frigo_isolation != fval) 1454 if (simulator->frigo_isolation != fval)
1267 syslog(LOG_NOTICE, "Simulator %s frigo isolation %.1f to %.1f", simulator->uuid, simulator->frigo_isolation, fval); 1455 syslog(LOG_NOTICE, "Simulator %s frigo isolation %.1f to %.1f", simulator->uuid, simulator->frigo_isolation, fval);

mercurial