1167 nsim->timestamp = time(NULL); |
1166 nsim->timestamp = time(NULL); |
1168 nsim->s_yeast_heat = 0.0; |
1167 nsim->s_yeast_heat = 0.0; |
1169 nsim->s_yeast_started = nsim->s_cool_changed = nsim->s_heat_changed = (int)0; |
1168 nsim->s_yeast_started = nsim->s_cool_changed = nsim->s_heat_changed = (int)0; |
1170 |
1169 |
1171 if (Config.simulators == NULL) { |
1170 if (Config.simulators == NULL) { |
1172 syslog(LOG_NOTICE, "SIMULATOR ADD root"); |
|
1173 Config.simulators = nsim; |
1171 Config.simulators = nsim; |
1174 } else { |
1172 } else { |
1175 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
1173 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
1176 syslog(LOG_NOTICE, "SIMULATOR ADD no %d %s", simulator->simno, simulator->name); |
|
1177 if (simulator->next == NULL) { |
1174 if (simulator->next == NULL) { |
1178 simulator->next = nsim; |
1175 simulator->next = nsim; |
1179 syslog(LOG_NOTICE, "SIMULATOR ADD here"); |
|
1180 break; |
1176 break; |
1181 } |
1177 } |
1182 } |
1178 } |
1183 } |
1179 } |
1184 |
|
1185 my_simulator_command = THREAD_RUN; |
1180 my_simulator_command = THREAD_RUN; |
1186 while (my_simulator_state != THREAD_RUN) { mDelay(50); }; |
1181 while (my_simulator_state != THREAD_RUN) { mDelay(50); }; |
1187 syslog(LOG_NOTICE, "SIMULATOR ADD thread runs"); |
|
1188 |
1182 |
1189 syslog(LOG_NOTICE, "Simulator %s no %d added", param, highno + 1); |
1183 syslog(LOG_NOTICE, "Simulator %s no %d added", param, highno + 1); |
1190 srv_send(s, (char *)"211 Simulator %s added", param); |
1184 srv_send(s, (char *)"211 Simulator %s added", param); |
1191 return 1; |
1185 return 1; |
1192 } |
1186 } |
1193 |
1187 |
1194 if (strcmp(opt, (char *)"DEL") == 0) { |
1188 if (strcmp(opt, (char *)"DEL") == 0) { |
1195 // TODO: check devices in use. |
1189 // TODO: check devices in use. |
1196 // TODO: delete simulated devices. |
1190 // TODO: delete simulated devices. |
1197 syslog(LOG_NOTICE, "Simulator DEL %s", param); |
|
1198 |
1191 |
1199 my_simulator_command = THREAD_PAUSE; |
1192 my_simulator_command = THREAD_PAUSE; |
1200 while (my_simulator_state != THREAD_PAUSE) { mDelay(50); }; |
1193 while (my_simulator_state != THREAD_PAUSE) { mDelay(50); }; |
1201 syslog(LOG_NOTICE, "SIMULATOR DEL thread paused"); |
|
1202 rc = delete_Simulator(param); |
1194 rc = delete_Simulator(param); |
1203 my_simulator_command = THREAD_RUN; |
1195 my_simulator_command = THREAD_RUN; |
1204 while (my_simulator_state != THREAD_RUN) { mDelay(50); }; |
1196 while (my_simulator_state != THREAD_RUN) { mDelay(50); }; |
1205 syslog(LOG_NOTICE, "SIMULATOR DEL thread runs"); |
|
1206 |
1197 |
1207 if (rc) { |
1198 if (rc) { |
1208 syslog(LOG_NOTICE, "Simulator %s deleted", param); |
1199 syslog(LOG_NOTICE, "Simulator %s deleted", param); |
1209 srv_send(s, (char *)"211 Simulator %s deleted", param); |
1200 srv_send(s, (char *)"211 Simulator %s deleted", param); |
1210 return 1; |
1201 return 1; |
1211 } else { |
1202 } else { |
|
1203 syslog(LOG_NOTICE, "Simulator %s del error", param); |
1212 srv_send(s, (char *)"440 No such simulator"); |
1204 srv_send(s, (char *)"440 No such simulator"); |
1213 return 0; |
1205 return 0; |
1214 } |
1206 } |
1215 } |
1207 } |
1216 |
1208 |
1830 uuid_generate(uu); |
1822 uuid_generate(uu); |
1831 uuid_unparse(uu, unit->uuid); |
1823 uuid_unparse(uu, unit->uuid); |
1832 unit->product_uuid = NULL; |
1824 unit->product_uuid = NULL; |
1833 unit->product_code = xstrcpy((char *)"FAKE0000"); |
1825 unit->product_code = xstrcpy((char *)"FAKE0000"); |
1834 unit->product_name = xstrcpy(param); |
1826 unit->product_name = xstrcpy(param); |
|
1827 unit->yeast_lo = 17.0; |
|
1828 unit->yeast_hi = 24.0; |
1835 unit->alias = xstrcpy(an); |
1829 unit->alias = xstrcpy(an); |
1836 unit->air_address = unit->beer_address = unit->beer_address2 = unit->chiller_address = unit->heater_address = unit->cooler_address = \ |
1830 unit->air_address = unit->beer_address = unit->beer_address2 = unit->chiller_address = unit->heater_address = unit->cooler_address = \ |
1837 unit->fan_address = unit->door_address = unit->light_address = \ |
1831 unit->fan_address = unit->door_address = unit->light_address = \ |
1838 unit->psu_address = unit->profile_uuid = unit->profile_name = NULL; |
1832 unit->psu_address = unit->profile_uuid = unit->profile_name = NULL; |
1839 unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ |
1833 unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ |