23 #include "rdconfig.h" |
23 #include "rdconfig.h" |
24 #include "thermferm.h" |
24 #include "thermferm.h" |
25 #include "logger.h" |
25 #include "logger.h" |
26 #include "devices.h" |
26 #include "devices.h" |
27 #include "server.h" |
27 #include "server.h" |
|
28 #include "lcd-buffer.h" |
28 #include "xutil.h" |
29 #include "xutil.h" |
29 |
30 |
30 |
31 |
31 extern int my_shutdown; |
32 extern int my_shutdown; |
32 extern int debug; |
33 extern int debug; |
|
34 extern int run_pause; |
|
35 extern int run_hold; |
33 extern sys_config Config; |
36 extern sys_config Config; |
34 extern const char UNITMODE[5][8]; |
37 extern const char UNITMODE[5][8]; |
35 extern const char UNITmode[5]; |
|
36 extern const char TEMPSTATE[3][8]; |
38 extern const char TEMPSTATE[3][8]; |
37 extern const char DEVTYPE[7][6]; |
39 extern const char DEVTYPE[7][6]; |
38 extern const char DEVPRESENT[4][6]; |
40 extern const char DEVPRESENT[4][6]; |
39 extern const char DEVDIR[7][11]; |
41 extern const char DEVDIR[7][11]; |
40 extern const char PROFSTATE[5][6]; |
42 extern const char PROFSTATE[5][6]; |
961 free(current->door_address); |
963 free(current->door_address); |
962 current->door_address = NULL; |
964 current->door_address = NULL; |
963 if (current->profile) |
965 if (current->profile) |
964 free(current->profile); |
966 free(current->profile); |
965 current->profile = NULL; |
967 current->profile = NULL; |
|
968 previous->next = current->next; |
966 free(current); |
969 free(current); |
967 current = previous->next; |
970 current = previous->next; |
968 return 1; |
971 return 1; |
969 } |
972 } |
970 } else { |
973 } else { |
988 { |
991 { |
989 char *opt, *param = NULL, *kwd, *val, ibuf[SS_BUFSIZE]; |
992 char *opt, *param = NULL, *kwd, *val, ibuf[SS_BUFSIZE]; |
990 units_list *unit, *tmpu; |
993 units_list *unit, *tmpu; |
991 uuid_t uu; |
994 uuid_t uu; |
992 socklen_t fromlen; |
995 socklen_t fromlen; |
993 int ival, i, rlen; |
996 int ival, i, rc, rlen; |
994 float fval; |
997 float fval; |
995 |
998 |
996 opt = strtok(buf, " \0"); |
999 opt = strtok(buf, " \0"); |
997 opt = strtok(NULL, " \0"); |
1000 opt = strtok(NULL, " \0"); |
998 |
1001 |
1036 unit->idle_rangeH = 1.0; |
1039 unit->idle_rangeH = 1.0; |
1037 unit->idle_rangeL = -1.0; |
1040 unit->idle_rangeL = -1.0; |
1038 unit->prof_started = unit->prof_paused = (time_t)0; |
1041 unit->prof_started = unit->prof_paused = (time_t)0; |
1039 unit->PID_err_old = unit->PID_I_err = 0.0; |
1042 unit->PID_err_old = unit->PID_I_err = 0.0; |
1040 |
1043 |
|
1044 /* |
|
1045 * Block main process |
|
1046 */ |
|
1047 run_pause = TRUE; |
|
1048 for (;;) { |
|
1049 usleep(100000); |
|
1050 if (run_hold) |
|
1051 break; |
|
1052 } |
|
1053 |
1041 if (Config.units == NULL) { |
1054 if (Config.units == NULL) { |
1042 Config.units = unit; |
1055 Config.units = unit; |
1043 } else { |
1056 } else { |
1044 for (tmpu = Config.units; tmpu; tmpu = tmpu->next) { |
1057 for (tmpu = Config.units; tmpu; tmpu = tmpu->next) { |
1045 if (tmpu->next == NULL) { |
1058 if (tmpu->next == NULL) { |
1046 tmpu->next = unit; |
1059 tmpu->next = unit; |
1047 break; |
1060 break; |
1048 } |
1061 } |
1049 } |
1062 } |
1050 } |
1063 } |
|
1064 lcd_buf_reset(); |
|
1065 run_pause = FALSE; |
1051 |
1066 |
1052 syslog(LOG_NOTICE, "Unit %s added", unit->uuid); |
1067 syslog(LOG_NOTICE, "Unit %s added", unit->uuid); |
1053 srv_send((char *)"211 Unit %s added", unit->uuid); |
1068 srv_send((char *)"211 Unit %s added", unit->uuid); |
1054 return 0; |
1069 return 0; |
1055 } |
1070 } |
1056 |
1071 |
1057 if (strcmp(opt, (char *)"DEL") == 0) { |
1072 if (strcmp(opt, (char *)"DEL") == 0) { |
1058 if (delete_Unit(param)) { |
1073 /* |
|
1074 * Block main process. |
|
1075 */ |
|
1076 run_pause = TRUE; |
|
1077 for (;;) { |
|
1078 usleep(100000); |
|
1079 if (run_hold) |
|
1080 break; |
|
1081 } |
|
1082 |
|
1083 rc = delete_Unit(param); |
|
1084 lcd_buf_reset(); |
|
1085 run_pause = FALSE; |
|
1086 |
|
1087 if (rc) { |
1059 syslog(LOG_NOTICE, "Unit %s deleted", param); |
1088 syslog(LOG_NOTICE, "Unit %s deleted", param); |
1060 srv_send((char *)"211 Unit %s deleted", param); |
1089 srv_send((char *)"211 Unit %s deleted", param); |
1061 return 0; |
1090 return 0; |
1062 } else { |
1091 } else { |
1063 srv_send((char *)"440 No such unit"); |
1092 srv_send((char *)"440 No such unit"); |