thermferm/one-wire.c

Thu, 11 Apr 2024 15:58:49 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 11 Apr 2024 15:58:49 +0200
changeset 674
6cabc02f4c8d
parent 672
0c2c66920d79
child 690
3a5b019e9acc
permissions
-rw-r--r--

Code cleanup

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;
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
86 uint8_t state, output, newval;
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;
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
145 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
146
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 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
148 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
149 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
150 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
151 } 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
152 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
153 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
154 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
155 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
156 }
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 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
160 }
670
6c62e99ade00 Stop logging ghost one-wire devices.
Michiel Broek <mbroek@mbse.eu>
parents: 662
diff changeset
161 } else if (strcmp(w1type, (char *)"00")) {
671
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
162 syslog(LOG_NOTICE, "One-wire device %ld %s unknown", strlen(buffer), buffer);
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
163 }
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 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
166 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
167
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 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
169
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
170 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
171 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
172 }
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 * 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
176 */
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 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
178 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
179 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
180 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
181 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
182 /*
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 * 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
184 */
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 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
186 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
187 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
188 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
189 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
190 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
191 // 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
192 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
193 // 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
194 }
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 }
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
197 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
198 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
199 }
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
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
201 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
202
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 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
204
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
205 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
206 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
207 }
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 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
210 if (strcmp(dev_w1->family, "3a") == 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
211 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
212 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
213 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
214 /*
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
215 * 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
216 * 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
217 */
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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 }
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 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
230 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
231 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
232 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
233 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
234 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
235 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
236 }
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
237
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
238 newval = ((state & 0x04) >> 1) + (state & 0x01);
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
239 if (newval != dev_w1->value) {
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
240 syslog(LOG_NOTICE, "One-wire device %s-%d in %02x value %d => %d", dev_w1->address, i, state, dev_w1->value, newval);
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
241 dev_w1->value = newval;
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
242 }
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
243
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
244 // 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
245 /*
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 * 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
247 */
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
248 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
249 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
250 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
251 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
252 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
253 // 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
254 }
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 mDelay(20);
671
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
256 } else if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_OUT_BIN)) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
257 /*
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
258 * Sync output state
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
259 */
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
260 if ((rc = read_w1(device->address, (char *)"state")) >= 0) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
261 state = (unsigned int)rc;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
262 newval = output = (state & 0x01) + ((state & 0x04) >> 1);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
263
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
264 if (device->subdevice == 0) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
265 newval = (newval & 0xfe);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
266 newval |= (device->value) ? 0x00 : 0x01;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
267 } else if (device->subdevice == 1) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
268 newval = (newval & 0xfd);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
269 newval |= (device->value) ? 0x00 : 0x02;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
270 }
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
271
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
272 if (output != newval) {
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
273 if ((write_w1(dev_w1->address, (char *)"output", newval)) == 0) {
671
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
274 syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, newval);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
275 dev_w1->value = newval;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
276 }
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
277 }
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
278 }
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
279 }
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
280 } /* 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
281 }
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
282 }
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
283 }
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
284
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
285 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
286
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
287 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
288
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
289 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
290 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
291 }
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
292
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
293 /*
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
294 * 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
295 */
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
296 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
297
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
298 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
299 (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
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 }
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 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
314 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
315
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 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
317 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
318 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
319 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
320 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
321 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
322 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
323 }
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 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
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 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
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 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
329 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
330 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
331 if ((fp = fopen(devfile, "r"))) {
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
332 // syslog(LOG_NOTICE, "One-wire device %s temperature is open, delay %d", cur_w1->address, conv_time);
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
333 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
334 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
335 sscanf(buffer, "%d", &value);
672
0c2c66920d79 Only log temperature error once. Only log temperature Ok again once. Do not log changed temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 671
diff changeset
336 // if (cur_w1->value != value)
0c2c66920d79 Only log temperature error once. Only log temperature Ok again once. Do not log changed temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 671
diff changeset
337 // syslog(LOG_NOTICE, "One-wire device %s temperature read %d => %d", cur_w1->address, cur_w1->value, value);
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
338 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
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 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
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 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
343 }
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
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
345 } 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
346 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
347 }
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
348 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
349 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
350 }
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
351
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
352 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
353 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
354 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
355 } 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
356 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
357 }
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
358 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
359 (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
360 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
361 }
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
362
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 } else {
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
364 mDelay(750);
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
365 }
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 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
368
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
369 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
370
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
371 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
372 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
373 }
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
374
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
375 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
376 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
377
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
378 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
379 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
380
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
381

mercurial