thermferm/one-wire.c

Thu, 11 Apr 2024 13:18:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 11 Apr 2024 13:18:20 +0200
changeset 671
b2e2cbb13cb3
parent 670
6c62e99ade00
child 672
0c2c66920d79
permissions
-rw-r--r--

Finished one-wire ds2413 output

654
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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;
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
145 // n_w1->subdevices = (strcmp(w1type, (char *)"3a") == 0) ? 2:1;
654
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 n_w1->timestamp = time(NULL);
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]);
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 if (w1_devices == NULL) {
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 w1_devices = n_w1;
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 cur_w1 = w1_devices; /* Point to first device */
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 } else {
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 if (dev_w1->next == NULL) {
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 dev_w1->next = n_w1;
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 break;
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]);
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 }
670
6c62e99ade00 Stop logging ghost one-wire devices.
Michiel Broek <mbroek@mbse.eu>
parents: 662
diff changeset
162 } else if (strcmp(w1type, (char *)"00")) {
671
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
163 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
164 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 fclose(fp);
659
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
167 SM_PROCEED(ScanDel);
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
168
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
169 SM_STATE(ScanDel)
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
170
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
171 if (my_one_wire_shutdown) {
659
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
172 SM_SUCCESS;
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
173 }
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
174
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
175 /*
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
176 * Scan from the linked list if all devices are still present.
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
177 */
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
178 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
179 devfile = xstrcpy((char *)"/sys/bus/w1/devices/");
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
180 devfile = xstrcat(devfile, dev_w1->address);
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
181 devfile = xstrcat(devfile, (char *)"/uevent");
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
182 if (file_exist(devfile, R_OK) && (dev_w1->present == DEVPRESENT_YES)) {
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
183 /*
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
184 * Gone missing
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
185 */
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
186 syslog(LOG_NOTICE, "One-wire device %s is missing", dev_w1->address);
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
187 pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]);
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
188 dev_w1->present = DEVPRESENT_NO;
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
189 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]);
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
190 for (device = Config.devices; device; device = device->next) {
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
191 if (strcmp(dev_w1->address, device->address) == 0) {
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
192 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
659
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
193 device->present = DEVPRESENT_NO;
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
194 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
659
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
195 }
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
196 }
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
197 }
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
198 free(devfile);
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
199 devfile = NULL;
659
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
200 }
bfab45f4d5cd Added state to scan vanished one-wire devices. Update devices if a one-wire device returns on the bus.
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
201
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
202 SM_PROCEED(Read2413);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
203
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
204 SM_STATE(Read2413)
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
205
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
206 if (my_one_wire_shutdown) {
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
207 SM_SUCCESS;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
208 }
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
209
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
210 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
211 if (strcmp(dev_w1->family, "3a") == 0) {
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
212 // syslog(LOG_NOTICE, "ds2413 %s", dev_w1->address);
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
213 for (i = 0; i < 2; i++) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
214 for (device = Config.devices; device; device = device->next) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
215 if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
216 /*
657
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
217 * First make sure that this device is configured as input
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
218 * to drive the output high. Fix if programmed as output.
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
219 */
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
220 if ((rc = read_w1(device->address, (char *)"state")) >= 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
221 state = (unsigned int)rc;
657
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
222 output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
223 if ((i == 0) && ((state & 0x02) == 0)) { /* Fix A side */
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
224 syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, output | 0x01);
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
225 output |= 0x01;
657
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
226 write_w1(device->address, (char *)"output", output);
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
227 mDelay(10);
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
228 if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
229 state = (unsigned int)rc;
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
230 }
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
231 if ((i == 1) && ((state & 0x08) == 0)) { /* Fix B side */
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
232 syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, output | 0x02);
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
233 output |= 0x02;
657
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
234 write_w1(device->address, (char *)"output", output);
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
235 mDelay(10);
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
236 if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
237 state = (unsigned int)rc;
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
238 }
657
38162f374842 Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output.
Michiel Broek <mbroek@mbse.eu>
parents: 656
diff changeset
239
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
240 newval = ((state & 0x04) >> 1) + (state & 0x01);
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
241 if (newval != dev_w1->value) {
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
242 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
243 dev_w1->value = newval;
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
244 }
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
245
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
246 // 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
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 * 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
249 */
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 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
251 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
252 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
253 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
254 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
255 // 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
256 }
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 655
diff changeset
257 mDelay(20);
671
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
258 } 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
259 /*
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
260 * Sync output state
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
261 */
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
262 if ((rc = read_w1(device->address, (char *)"state")) >= 0) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
263 state = (unsigned int)rc;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
264 newval = output = (state & 0x01) + ((state & 0x04) >> 1);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
265
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
266 if (device->subdevice == 0) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
267 newval = (newval & 0xfe);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
268 newval |= (device->value) ? 0x00 : 0x01;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
269 } else if (device->subdevice == 1) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
270 newval = (newval & 0xfd);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
271 newval |= (device->value) ? 0x00 : 0x02;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
272 }
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
273
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
274 if (output != newval) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
275 if ((rc = write_w1(dev_w1->address, (char *)"output", newval)) == 0) {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
276 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
277 dev_w1->value = newval;
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
278 } else {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
279 syslog(LOG_NOTICE, "One-wire device %s-%d write output rc=%d", dev_w1->address, i, rc);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
280 }
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
281 }
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
282 } else {
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
283 syslog(LOG_NOTICE, "One-wire device %s-%d read state rc=%d", dev_w1->address, i, rc);
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 670
diff changeset
284 }
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
285 }
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
286 } /* 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
287 }
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
288 }
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
289 }
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
290
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
291 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
292
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
293 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
294
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
295 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
296 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
297 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 /*
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 * 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
301 */
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 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
303
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
304 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
305 (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
306 // syslog(LOG_NOTICE, "Reading %s", cur_w1->address);
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 659
diff changeset
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 }
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 }
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 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
321 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
322
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 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
324 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
325 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
326 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
327 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
328 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
329 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
330 }
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 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
332 }
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 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
334
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 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
336 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
337 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
338 if ((fp = fopen(devfile, "r"))) {
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
339 // 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
340 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
341 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
342 sscanf(buffer, "%d", &value);
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
343 if (cur_w1->value != value)
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
344 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
345 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
346 } 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
347 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
348 }
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 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
350 }
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
351
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 } 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
353 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
354 }
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 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
356 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
357 }
654
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358
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
359 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
360 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
361 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
362 } 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
363 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
364 }
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
365 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
366 (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
367 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
368 }
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
369 // syslog(LOG_NOTICE, "One-wire device %s next sensor %s", cur_w1->address, cur_w1->family);
654
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 } else {
662
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
372 // syslog(LOG_NOTICE, "cur_w1 == NULL");
56c72393ca26 One-wire tread more relaxed logging.
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
373 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
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
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 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
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_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
379
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
380 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
381 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
382 }
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 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
385 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
386
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 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
388 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
389
e981d0185485 Added one-wire thread and some old state table macro's. The state machine first state scans new one-wire devices and stores them in a linked list.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390

mercurial