Fri, 05 Apr 2024 19:30:41 +0200
Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @brief One-wire devices |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Copyright (C) 2024 |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This is free software; you can redistribute it and/or modify it |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * under the terms of the GNU General Public License as published by the |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * Free Software Foundation; either version 2, or (at your option) any |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * later version. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * mbsePi-apps is distributed in the hope that it will be useful, but |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * General Public License for more details. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * You should have received a copy of the GNU General Public License |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * along with MBSE BBS; see the file COPYING. If not, write to the Free |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | |
655
780cc08df263
State machine logging only when debug is active.
Michiel Broek <mbroek@mbse.eu>
parents:
654
diff
changeset
|
21 | extern int debug; |
780cc08df263
State machine logging only when debug is active.
Michiel Broek <mbroek@mbse.eu>
parents:
654
diff
changeset
|
22 | |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | #include "thermferm.h" |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | #include "statetbl.h" |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | #include "one-wire.h" |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
26 | #include "devices.h" |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
27 | #include "delay.h" |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
28 | #include "futil.h" |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | #include "xutil.h" |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
31 | #define W1_TEMP_RESOLUTION 12 |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
32 | |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | extern sys_config Config; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | extern pthread_mutex_t mutexes[5]; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | int my_one_wire_state = 0; |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
38 | int my_one_wire_shutdown = 0; |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | w1_list *w1_devices = NULL; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | static int one_wire(void); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | void *my_one_wire_loop(void *threadid) |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | my_one_wire_state = 1; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | syslog(LOG_NOTICE, "Thread my_one_wire_loop started"); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | /* |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | * Run the state machine |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | one_wire(); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | /* |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | * Remove the dynamic tables. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | syslog(LOG_NOTICE, "Thread my_one_wire_loop stopped"); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | my_one_wire_state = 0; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | return 0; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | SM_DECL(one_wire,(char *)"one-wire") |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | SM_STATES |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
68 | ScanNew, |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
69 | ScanDel, |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
70 | Read2413, |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
71 | ReadTemp, |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | Missing |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | SM_NAMES |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
74 | (char *)"ScanNew", |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
75 | (char *)"ScanDel", |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
76 | (char *)"Read2413", |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
77 | (char *)"ReadTemp", |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | (char *)"Missing" |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | SM_EDECL |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
81 | int found, i, rc, value, conv_time; |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | FILE *fp; |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
83 | devices_list *device; |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | w1_list *dev_w1, *n_w1, *cur_w1 = NULL; |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
85 | char buffer[25], w1type[10], *devfile = NULL; |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
86 | uint8_t state, output; |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
88 | SM_START(ScanNew) |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
90 | SM_STATE(ScanNew) |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
92 | if (my_one_wire_shutdown) { |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | SM_SUCCESS; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | /* |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | * Scan for current one-wire devices. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | fp = fopen("/sys/devices/w1_bus_master1/w1_master_slaves", "r"); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | if (fp == NULL) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | syslog(LOG_NOTICE, "No w1_bus_master: %s", strerror(errno)); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | SM_ERROR; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | while ((fgets(buffer, 25, fp))) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | buffer[strlen(buffer)-1] = '\0'; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | strncpy(w1type, buffer, 2); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | w1type[2] = '\0'; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | /* |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | * Check if device is known and already detected. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | if ((strcmp(w1type, (char *)"3a") == 0) || (strcmp(w1type, (char *)"10") == 0) || |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | (strcmp(w1type, (char *)"22") == 0) || (strcmp(w1type, (char *)"28") == 0) || |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | (strcmp(w1type, (char *)"3b") == 0) || (strcmp(w1type, (char *)"42") == 0)) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | found = FALSE; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | if (strcmp(dev_w1->address, buffer) == 0) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | found = TRUE; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | dev_w1->timestamp = time(NULL); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | if (dev_w1->present != DEVPRESENT_YES) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | syslog(LOG_NOTICE, "One-wire device %s is back", buffer); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | dev_w1->present = DEVPRESENT_YES; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
125 | for (device = Config.devices; device; device = device->next) { |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
126 | if (strcmp(dev_w1->address, device->address) == 0) { |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
127 | // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
128 | device->present = DEVPRESENT_YES; |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
129 | // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
130 | } |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
131 | } |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | break; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | if (found == FALSE) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | syslog(LOG_NOTICE, "One-wire device %s add new", buffer); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | n_w1 = (w1_list *)malloc(sizeof(w1_list)); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | n_w1->next = NULL; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | n_w1->address = xstrcpy(buffer); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | strncpy(n_w1->family, buffer, 2); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | n_w1->family[2] = '\0'; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | n_w1->present = DEVPRESENT_YES; |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
144 | n_w1->value = (strcmp(w1type, (char *)"3a") == 0) ? 3:-1; |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
145 | // n_w1->subdevices = (strcmp(w1type, (char *)"3a") == 0) ? 2:1; |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | n_w1->timestamp = time(NULL); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
148 | pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | if (w1_devices == NULL) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | w1_devices = n_w1; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | cur_w1 = w1_devices; /* Point to first device */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | } else { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | if (dev_w1->next == NULL) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | dev_w1->next = n_w1; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | break; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | } else { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | syslog(LOG_NOTICE, "One-wire device %d %s unknown", strlen(buffer), buffer); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
165 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
166 | fclose(fp); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
167 | SM_PROCEED(ScanDel); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
168 | |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
169 | SM_STATE(ScanDel) |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
170 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
171 | if (my_one_wire_shutdown) { |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
172 | SM_SUCCESS; |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
173 | } |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
174 | |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
175 | /* |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
176 | * Scan from the linked list if all devices are still present. |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
177 | */ |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
178 | for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) { |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
179 | devfile = xstrcpy((char *)"/sys/bus/w1/devices/"); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
180 | devfile = xstrcat(devfile, dev_w1->address); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
181 | devfile = xstrcat(devfile, (char *)"/uevent"); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
182 | if (file_exist(devfile, R_OK) && (dev_w1->present == DEVPRESENT_YES)) { |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
183 | /* |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
184 | * Gone missing |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
185 | */ |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
186 | syslog(LOG_NOTICE, "One-wire device %s is missing", dev_w1->address); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
187 | pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
188 | dev_w1->present = DEVPRESENT_NO; |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
189 | pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]); |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
190 | for (device = Config.devices; device; device = device->next) { |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
191 | if (strcmp(dev_w1->address, device->address) == 0) { |
661
8c1e7a52e24f
Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents:
660
diff
changeset
|
192 | // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
193 | device->present = DEVPRESENT_NO; |
661
8c1e7a52e24f
Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents:
660
diff
changeset
|
194 | // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
195 | } |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
196 | } |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
197 | } |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
198 | free(devfile); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
199 | devfile = NULL; |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
200 | } |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
201 | |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
202 | SM_PROCEED(Read2413); |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
203 | |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
204 | SM_STATE(Read2413) |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
205 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
206 | if (my_one_wire_shutdown) { |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
207 | SM_SUCCESS; |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
208 | } |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
209 | |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
210 | for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) { |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
211 | if (strcmp(dev_w1->family, "3a") == 0) { |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
212 | // syslog(LOG_NOTICE, "ds2413 %s", dev_w1->address); |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
213 | for (i = 0; i < 2; i++) { |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
214 | for (device = Config.devices; device; device = device->next) { |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
215 | if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) { |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
216 | /* |
657
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
217 | * First make sure that this device is configured as input |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
218 | * to drive the output high. Fix if programmed as output. |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
219 | */ |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
220 | if ((rc = read_w1(device->address, (char *)"state")) >= 0) { |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
221 | state = (unsigned int)rc; |
657
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
222 | output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */ |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
223 | if ((i == 0) && ((state & 0x02) == 0)) { /* Fix A side */ |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
224 | syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, output | 0x01); |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
225 | output |= 0x01; |
657
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
226 | write_w1(device->address, (char *)"output", output); |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
227 | mDelay(10); |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
228 | if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */ |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
229 | state = (unsigned int)rc; |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
230 | } |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
231 | if ((i == 1) && ((state & 0x08) == 0)) { /* Fix B side */ |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
232 | syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, output | 0x02); |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
233 | output |= 0x02; |
657
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
234 | write_w1(device->address, (char *)"output", output); |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
235 | mDelay(10); |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
236 | if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */ |
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
237 | state = (unsigned int)rc; |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
238 | } |
657
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
239 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
240 | dev_w1->value = ((state & 0x04) >> 1) + (state & 0x01); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
241 | syslog(LOG_NOTICE, "One-wire device %s-%d in %02x value %d", dev_w1->address, i, state, dev_w1->value); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
242 | |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
243 | // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
244 | /* |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
245 | * Read PIOA or PIOB pin state bits |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
246 | */ |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
247 | if (device->subdevice == 0) |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
248 | device->value = (state & 0x01) ? 0 : 1; |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
249 | else if (device->subdevice == 1) |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
250 | device->value = (state & 0x04) ? 0 : 1; |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
251 | device->timestamp = time(NULL); |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
252 | // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
253 | } |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
254 | mDelay(20); |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
255 | } |
657
38162f374842
Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents:
656
diff
changeset
|
256 | } /* for (device = Config.devices; ... */ |
656
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
257 | } |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
258 | } |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
259 | } |
ca47c742a25d
One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents:
655
diff
changeset
|
260 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
261 | SM_PROCEED(ReadTemp); |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
263 | SM_STATE(ReadTemp) |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
264 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
265 | if (my_one_wire_shutdown) { |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | SM_SUCCESS; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | /* |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | * cur_w1 points to the next not handled device. |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | */ |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | if (cur_w1 != NULL) { |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
274 | if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) || |
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
275 | (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) { |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
276 | // syslog(LOG_NOTICE, "Reading %s", cur_w1->address); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
277 | /* |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
278 | * 1. Read sensor resolution. This is a present check too. |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
279 | * 2. Fix resolution if wrong. |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
280 | * 3. Read conversion time. |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
281 | * 4. Open temperature for read. |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
282 | * 5. Wait conversion time. |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
283 | * 6. Read temperature. |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
284 | */ |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
285 | devfile = xstrcpy((char *)"/sys/bus/w1/devices/"); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
286 | devfile = xstrcat(devfile, cur_w1->address); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
287 | devfile = xstrcat(devfile, (char *)"/resolution"); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
288 | if ((fp = fopen(devfile, "r+"))) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
289 | if ((fgets(buffer, 25, fp))) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
290 | sscanf(buffer, "%d", &value); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
291 | if (value != W1_TEMP_RESOLUTION) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
292 | syslog(LOG_NOTICE, "One-wire device %s set resolution from %d to %d", cur_w1->address, value, W1_TEMP_RESOLUTION); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
293 | fseek(fp, 0L, SEEK_SET); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
294 | sprintf(buffer, "%d", W1_TEMP_RESOLUTION); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
295 | fputs(buffer, fp); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
296 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
297 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
298 | fclose(fp); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
299 | free(devfile); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
300 | |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
301 | conv_time = 760; |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
302 | devfile = xstrcpy((char *)"/sys/bus/w1/devices/"); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
303 | devfile = xstrcat(devfile, cur_w1->address); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
304 | devfile = xstrcat(devfile, (char *)"/conv_time"); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
305 | if ((fp = fopen(devfile, "r"))) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
306 | if ((fgets(buffer, 25, fp))) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
307 | sscanf(buffer, "%d", &conv_time); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
308 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
309 | fclose(fp); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
310 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
311 | free(devfile); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
312 | |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
313 | devfile = xstrcpy((char *)"/sys/bus/w1/devices/"); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
314 | devfile = xstrcat(devfile, cur_w1->address); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
315 | devfile = xstrcat(devfile, (char *)"/temperature"); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
316 | if ((fp = fopen(devfile, "r"))) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
317 | syslog(LOG_NOTICE, "One-wire device %s temperature is open, delay %d", cur_w1->address, conv_time); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
318 | mDelay(conv_time); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
319 | if ((fgets(buffer, 25, fp))) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
320 | sscanf(buffer, "%d", &value); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
321 | syslog(LOG_NOTICE, "One-wire device %s temperature read %d", cur_w1->address, value); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
322 | cur_w1->value = value; /* devices.c will pick this up */ |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
323 | } else { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
324 | syslog(LOG_NOTICE, "One-wire device %s temperature read error", cur_w1->address); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
325 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
326 | fclose(fp); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
327 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
328 | |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
329 | } else { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
330 | syslog(LOG_NOTICE, "One-wire device %s open: %s", cur_w1->address, strerror(errno)); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
331 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
332 | free(devfile); |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
333 | devfile = NULL; |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
334 | } |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
336 | for (;;) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
337 | if (cur_w1->next != NULL) { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
338 | cur_w1 = cur_w1->next; |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
339 | } else { |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
340 | cur_w1 = w1_devices; |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
341 | } |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
342 | if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) || |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
343 | (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) |
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
344 | break; |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
345 | } |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
346 | syslog(LOG_NOTICE, "One-wire device %s next sensor %s", cur_w1->address, cur_w1->family); |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
347 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | } else { |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
349 | syslog(LOG_NOTICE, "cur_w1 == NULL"); |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
350 | sleep(1); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
351 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
352 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
353 | SM_PROCEED(Missing); |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
354 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
355 | SM_STATE(Missing) |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | |
660
a28ef4d9afa4
Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents:
659
diff
changeset
|
357 | if (my_one_wire_shutdown) { |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | SM_SUCCESS; |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
359 | } |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
361 | sleep(1); |
659
bfab45f4d5cd
Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents:
657
diff
changeset
|
362 | SM_PROCEED(ScanNew); |
654
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | SM_END |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
365 | SM_RETURN |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
366 | |
e981d0185485
Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
367 |