thermferm/rdconfig.c

Fri, 20 Jun 2014 17:42:36 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 20 Jun 2014 17:42:36 +0200
changeset 66
805f1d285acd
parent 58
e8e7b46b705b
child 69
df5d983dab1b
permissions
-rw-r--r--

Compiles with 1-wire bus on PC hardware

51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2014
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "thermferm.h"
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 bool debug = FALSE;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 static char *mypath;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 static char *k, *v;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 static int linecnt = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 sys_config Config; /* System configuration */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
34 //static int getstr(char **);
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
35 //static int getint(char **);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 static int getw1(char **);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
37 #ifdef HAVE_WIRINGPI_H
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 static int getrcs(char **);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
39 #endif
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
40 static int getuch(char **);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
41 static int getfloat(char **);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 //static int getbyt(char **);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 //static int gethex(char **);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 #define XSTR(x) #x
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #define STR(x) XSTR(x)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 * System configuration table
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 key_list keytab[] = {
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
52 {(char *)"w1therm", getw1, (char **)&Config.w1therms},
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
53 #ifdef HAVE_WIRINGPI_H
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
54 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
55 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
56 {(char *)"tx433", getint, (char **)&Config.tx433},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
57 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch},
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
58 #endif
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
59 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
60 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
61 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
62 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
63 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
64 {(char *)"cc_tempFormat", getuch, (char **)&Config.cc_tempFormat},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
65 {(char *)"cc_tempSetMin", getfloat, (char **)&Config.cc_tempSetMin},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
66 {(char *)"cc_tempSetMax", getfloat, (char **)&Config.cc_tempSetMax},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
67 {(char *)"cc_idleRangeH", getfloat, (char **)&Config.cc_idleRangeH},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
68 {(char *)"cc_idleRangeL", getfloat, (char **)&Config.cc_idleRangeL},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
69 {NULL, NULL, NULL}
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 };
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 void killconfig(void)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 w1_therm *tmp1, *old1;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
77 #ifdef HAVE_WIRINGPI_H
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 rc_switch *tmp2, *old2;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
79 #endif
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 if (Config.name)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 free(Config.name);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 Config.name = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 old1 = tmp1->next;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 if (tmp1->master)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 free(tmp1->master);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 if (tmp1->name)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 free(tmp1->name);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 if (tmp1->alias)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 free(tmp1->alias);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 free(tmp1);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 Config.w1therms = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 Config.my_port = 6554;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
98 #ifdef HAVE_WIRINGPI_H
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 Config.lcd_cols = 16;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 Config.lcd_rows = 2;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 Config.tx433 = -1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 for (tmp2 = Config.rcswitch; tmp2; tmp2 = old2) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 old2 = tmp2->next;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 if (tmp2->address)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 free(tmp2->address);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 tmp2->address = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 if (tmp2->alias)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 free(tmp2->alias);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 tmp2->alias = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 free(tmp2);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 Config.rcswitch = NULL;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
114 #endif
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
116 defaultControlSettings();
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
117 defaultControlConstants();
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
118 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
119
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
120
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
121
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
122 int wrconfig(char *config)
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
123 {
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
124 int rc = 0;
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
125 FILE *fp;
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
126 w1_therm *tmp1;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
127 #ifdef HAVE_WIRINGPI_H
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
128 rc_switch *tmp2;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
129 #endif
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
130
56
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
131 if (getenv((char *)"USER") == NULL) {
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
132 mypath = xstrcpy((char *)"/root");
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
133 } else {
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
134 mypath = xstrcpy(getenv((char *)"HOME"));
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
135 }
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
136 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
137 mypath = xstrcat(mypath, config);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
138
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
139 if (debug)
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
140 fprintf(stdout, "Writing %s\n", mypath);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
141
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
142 if ((fp = fopen(mypath, "w")) == NULL) {
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
143 syslog(LOG_NOTICE, "could not rewrite %s", mypath);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
144 return 1;
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
145 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
146
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
147 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
148 fprintf(fp, "\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
149
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
150 #ifdef HAVE_WIRINGPI_H
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
151 fprintf(fp, "# Radio controllers 433 MHz.\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
152 fprintf(fp, "#\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
153 fprintf(fp, "tx433 %d\n", Config.tx433);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
154 fprintf(fp, "\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
155
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
156 fprintf(fp, "# LCD display\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
157 fprintf(fp, "#\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
158 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
159 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
160 fprintf(fp, "\n");
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
161 #endif
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
162
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
163 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
164 fprintf(fp, "#\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
165 fprintf(fp, "# kwd master bus name alias\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
166 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
167 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
168 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
169 fprintf(fp, "\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
170
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
171 #ifdef HAVE_WIRINGPI_H
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
172 fprintf(fp, "# RC switches that we want to control.\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
173 fprintf(fp, "#\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
174 fprintf(fp, "# kwd address alias\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
175 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) {
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
176 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
177 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
178 fprintf(fp, "\n");
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
179 #endif
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
180
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
181 fprintf(fp, "# Control Settings.\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
182 fprintf(fp, "#\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
183 fprintf(fp, "cs_mode %c\n", Config.cs_mode);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
184 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
185 fprintf(fp, "cs_fridgeSet %.1f\n", Config.cs_fridgeSet);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
186 fprintf(fp, "cs_heatEstimator %.1f\n", Config.cs_heatEstimator);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
187 fprintf(fp, "cs_coolEstimator %.1f\n", Config.cs_coolEstimator);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
188 fprintf(fp, "\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
189
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
190 fprintf(fp, "# Control Constants.\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
191 fprintf(fp, "#\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
192 fprintf(fp, "cc_tempFormat %c\n", Config.cc_tempFormat);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
193 fprintf(fp, "cc_tempSetMin %.1f\n", Config.cc_tempSetMin);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
194 fprintf(fp, "cc_tempSetMax %.1f\n", Config.cc_tempSetMax);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
195 fprintf(fp, "cc_idleRangeH %.1f\n", Config.cc_idleRangeH);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
196 fprintf(fp, "cc_idleRangeL %.1f\n", Config.cc_idleRangeL);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
197 fprintf(fp, "\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
198
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
199 fprintf(fp, "# End of generated configuration\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
200 fclose(fp);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
201 syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
202 free(mypath);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
203 mypath = NULL;
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
204
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
205 return rc;
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 int rdconfig(char *config)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 char buf[256], *p;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 FILE *fp;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 int i, rc = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 killconfig();
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217
56
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
218 syslog(LOG_NOTICE, "HOME='%s' USER='%s' LOGNAME='%s'", MBSE_SS(getenv((char *)"HOME")), MBSE_SS(getenv((char *)"USER")), MBSE_SS(getenv((char *)"LOGNAME")));
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
219
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 * Search config file
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 */
56
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
223 if (getenv((char *)"USER") == NULL) {
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
224 mypath = xstrcpy((char *)"/root");
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
225 } else {
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
226 mypath = xstrcpy(getenv((char *)"HOME"));
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
227 }
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 mypath = xstrcat(mypath, config);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 if ((fp = fopen(mypath, "r")) == NULL) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 * Not in the users home directory
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 free(mypath);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 mypath = xstrcpy((char *)"/etc/mbsepi-apps/");
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 mypath = xstrcat(mypath, config);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 if ((fp = fopen(mypath, "r")) == NULL) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 * Try /usr/local/etc
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 free(mypath);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/");
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 mypath = xstrcat(mypath, config);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 if ((fp = fopen(mypath, "r")) == NULL) {
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
245 syslog(LOG_NOTICE, "rdconfig: could find %s", config);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 }
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
250 syslog(LOG_NOTICE, "rdconfig: using %s", mypath);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 linecnt = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 while (fgets(buf, sizeof(buf) -1, fp)) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 linecnt++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 if (*(p = buf + strlen(buf) -1) != '\n') {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 rc = 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 *p-- = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 while ((p >= buf) && isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 *p-- = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 k = buf;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 while (*k && isspace(*k))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 k++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 p = k;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 while (*p && !isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 p++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 *p++='\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 v = p;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 while (*v && isspace(*v))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 v++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 if ((*k == '\0') || (*k == '#')) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 continue;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 for (i = 0; keytab[i].key; i++)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 if (strcasecmp(k,keytab[i].key) == 0)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 if (keytab[i].key == NULL) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 rc = 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 } else if ((keytab[i].prc(keytab[i].dest))) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 rc = 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 fclose(fp);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 free(mypath);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 mypath = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 return rc;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
302 /*
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 static int getstr(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 *dest = xstrcpy(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 }
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
311 */
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
315 /*
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 static int getint(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 if (strspn(v,"0123456789") != strlen(v))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 else
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 *((int*)dest)=atoi(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 }
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
327 */
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 static int getw1(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 char *p, *q = NULL, *r = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 w1_therm **tmpm;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 int rc = 0, tmpp;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 for (p = v; *p && !isspace(*p); p++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 if (*p)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 *p++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 while (*p && isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 p++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 if (*p == '\0') {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 for (q = p; *q && !isspace(*q); q++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 if (*q && isspace(*q)) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 if (*q)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 *q++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 while (*q && isspace(*q))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 q++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 for (r = q; *r && !isspace(*r); r++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355 if (*r)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 *r++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 rc = sscanf(p, "%d", &tmpp);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 if (rc != 1) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s is not a integer value", mypath, linecnt, p);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s %d %s %s", mypath, linecnt, v, tmpp, q, r);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368 (*tmpm)->next = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 (*tmpm)->master = xstrcpy(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370 (*tmpm)->bus = tmpp;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 (*tmpm)->name = xstrcpy(q);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372 (*tmpm)->alias = xstrcpy(r);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373 (*tmpm)->present = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 (*tmpm)->lastval = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 (*tmpm)->update = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
382 #ifdef HAVE_WIRINGPI_H
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 static int getrcs(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 char *p, *q = NULL, *r = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 rc_switch **tmpm;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 for (p = v; *p && !isspace(*p); p++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 if (*p)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 *p++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 while (*p && isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 p++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 if (*p == '\0') {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 for (q = p; *q && !isspace(*q); q++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 if (*q && isspace(*q)) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 if (*q)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 *q++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 while (*q && isspace(*q))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 q++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 for (r = q; *r && !isspace(*r); r++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 if (*r)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 *r++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 syslog(LOG_NOTICE, "rdconfig: getrcs: %s(%d): %s %s", mypath, linecnt, v, p);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 for (tmpm = (rc_switch**)dest; *tmpm; tmpm=&((*tmpm)->next));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 (*tmpm) = (rc_switch *) xmalloc(sizeof(rc_switch));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 (*tmpm)->next = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 (*tmpm)->address = xstrcpy(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 (*tmpm)->alias = xstrcpy(p);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 }
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
420 #endif
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
423
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
424 static int getuch(char **dest)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
425 {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
426 if (debug)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
427 syslog(LOG_NOTICE, "rdconfig: getuch: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
428
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
429 if (isalnum(v[0])) {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
430 *((unsigned char*)dest) = v[0];
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
431 } else {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
432 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad character", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
433 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
434 return 0;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
435 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
436
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
437
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
438
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
439 static int getfloat(char **dest)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
440 {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
441 float val = 0.0;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
442 int rc;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
443
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
444 if (debug)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
445 syslog(LOG_NOTICE, "rdconfig: getfloat: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
446
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
447 rc = sscanf(v, "%f", &val);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
448 if (rc != 1) {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
449 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad float value", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
450 return 1;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
451 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
452 *((float*)dest) = val;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
453
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
454 return 0;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
455 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
456
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
457
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 static int getbyt(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 if (strspn(v,"0123456789") != strlen(v))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463 Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 else
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 *((Uint8*)dest)=atoi(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
469
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 static int gethex(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 unsigned int val = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 int rc;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 Log_Msg("[rdconfig] gethex: %s(%d): %s %s", mypath, linecnt, k, v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 rc = sscanf(v, "%08x", &val);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 if (rc != 1) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 Log_Msg("[rdconfig] %s(%d): %s %s - bad hex value", mypath, linecnt, S(k), S(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 *((int*)dest) = val;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489

mercurial