thermferm/one-wire.c

changeset 659
bfab45f4d5cd
parent 657
38162f374842
child 660
a28ef4d9afa4
equal deleted inserted replaced
658:b10d0f6337a3 659:bfab45f4d5cd
23 #include "thermferm.h" 23 #include "thermferm.h"
24 #include "statetbl.h" 24 #include "statetbl.h"
25 #include "one-wire.h" 25 #include "one-wire.h"
26 #include "devices.h" 26 #include "devices.h"
27 #include "delay.h" 27 #include "delay.h"
28 #include "futil.h"
28 #include "xutil.h" 29 #include "xutil.h"
29 30
30 31
31 extern sys_config Config; 32 extern sys_config Config;
32 extern int my_shutdown; 33 extern int my_shutdown;
60 61
61 62
62 63
63 SM_DECL(one_wire,(char *)"one-wire") 64 SM_DECL(one_wire,(char *)"one-wire")
64 SM_STATES 65 SM_STATES
65 Scan, 66 ScanNew,
67 ScanDel,
66 Read2413, 68 Read2413,
67 Reading, 69 Reading,
68 Missing 70 Missing
69 SM_NAMES 71 SM_NAMES
70 (char *)"Scan", 72 (char *)"ScanNew",
73 (char *)"ScanDel",
71 (char *)"Read2413", 74 (char *)"Read2413",
72 (char *)"Reading", 75 (char *)"Reading",
73 (char *)"Missing" 76 (char *)"Missing"
74 SM_EDECL 77 SM_EDECL
75 78
76 int found, i, rc; 79 int found, i, rc;
77 FILE *fp; 80 FILE *fp;
78 devices_list *device; 81 devices_list *device;
79 w1_list *dev_w1, *n_w1, *cur_w1 = NULL; 82 w1_list *dev_w1, *n_w1, *cur_w1 = NULL;
80 char buffer[25], w1type[10]; 83 char buffer[25], w1type[10], *devfile = NULL;
81 uint8_t state, output; 84 uint8_t state, output;
82 85
83 SM_START(Scan) 86 SM_START(ScanNew)
84 87
85 SM_STATE(Scan) 88 SM_STATE(ScanNew)
86 89
87 if (my_shutdown) { 90 if (my_shutdown) {
88 SM_SUCCESS; 91 SM_SUCCESS;
89 } 92 }
90 93
115 if (dev_w1->present != DEVPRESENT_YES) { 118 if (dev_w1->present != DEVPRESENT_YES) {
116 syslog(LOG_NOTICE, "One-wire device %s is back", buffer); 119 syslog(LOG_NOTICE, "One-wire device %s is back", buffer);
117 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]); 120 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]);
118 dev_w1->present = DEVPRESENT_YES; 121 dev_w1->present = DEVPRESENT_YES;
119 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]); 122 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]);
123 for (device = Config.devices; device; device = device->next) {
124 if (strcmp(dev_w1->address, device->address) == 0) {
125 pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
126 device->present = DEVPRESENT_YES;
127 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
128 }
129 }
120 } 130 }
121 break; 131 break;
122 } 132 }
123 } 133 }
124 if (found == FALSE) { 134 if (found == FALSE) {
149 } else { 159 } else {
150 syslog(LOG_NOTICE, "One-wire device %d %s unknown", strlen(buffer), buffer); 160 syslog(LOG_NOTICE, "One-wire device %d %s unknown", strlen(buffer), buffer);
151 } 161 }
152 } 162 }
153 fclose(fp); 163 fclose(fp);
164 SM_PROCEED(ScanDel);
165
166 SM_STATE(ScanDel)
167
168 if (my_shutdown) {
169 SM_SUCCESS;
170 }
171
172 /*
173 * Scan from the linked list if all devices are still present.
174 */
175 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
176 devfile = xstrcpy((char *)"/sys/bus/w1/devices/");
177 devfile = xstrcat(devfile, dev_w1->address);
178 devfile = xstrcat(devfile, (char *)"/uevent");
179 if (file_exist(devfile, R_OK) && (dev_w1->present == DEVPRESENT_YES)) {
180 /*
181 * Gone missing
182 */
183 syslog(LOG_NOTICE, "One-wire device %s is missing", dev_w1->address);
184 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]);
185 dev_w1->present = DEVPRESENT_NO;
186 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]);
187 for (device = Config.devices; device; device = device->next) {
188 if (strcmp(dev_w1->address, device->address) == 0) {
189 pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
190 device->present = DEVPRESENT_NO;
191 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
192 }
193 }
194 }
195 }
196
154 SM_PROCEED(Read2413); 197 SM_PROCEED(Read2413);
155 198
156 SM_STATE(Read2413) 199 SM_STATE(Read2413)
157 200
158 if (my_shutdown) { 201 if (my_shutdown) {
218 /* 261 /*
219 * cur_w1 points to the next not handled device. 262 * cur_w1 points to the next not handled device.
220 */ 263 */
221 if (cur_w1 != NULL) { 264 if (cur_w1 != NULL) {
222 265
223 syslog(LOG_NOTICE, "Reading %s", cur_w1->address); 266 if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) ||
224 267 (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) {
225 sleep(1); 268 syslog(LOG_NOTICE, "Reading %s", cur_w1->address);
269 sleep(1);
270 }
226 271
227 if (cur_w1->next != NULL) { 272 if (cur_w1->next != NULL) {
228 cur_w1 = cur_w1->next; 273 cur_w1 = cur_w1->next;
229 } else { 274 } else {
230 cur_w1 = w1_devices; 275 cur_w1 = w1_devices;
241 if (my_shutdown) { 286 if (my_shutdown) {
242 SM_SUCCESS; 287 SM_SUCCESS;
243 } 288 }
244 289
245 sleep(1); 290 sleep(1);
246 SM_PROCEED(Scan); 291 SM_PROCEED(ScanNew);
247 292
248 SM_END 293 SM_END
249 SM_RETURN 294 SM_RETURN
250 295
251 296

mercurial