1 /*
2     OWFS -- One-Wire filesystem
3     OWHTTPD -- One-Wire Web Server
4     Written 2003 Paul H Alfille
5     email: paul.alfille@gmail.com
6     Released under the GPL
7     See the header file: ow.h for full attribution
8     1wire/iButton system from Dallas Semiconductor
9 */
10 
11 #include <config.h>
12 #include "owfs_config.h"
13 #include "ow.h"
14 #include "ow_devices.h"
15 
16 /* Globals for port and bus communication */
17 /* connections globals stored in ow_connect.c */
18 
19 /* char * pid_file in ow_opt.c */
20 
21 // some improbably sub-absolute-zero number
22 #define GLOBAL_UNTOUCHED_TEMP_LIMIT	(-999.)
23 
24 /* State information, sent to remote or kept locally */
25 /* cacheenabled, presencecheck, tempscale, devform */
26 int32_t LocalControlFlags ;
27 
28 // This structure is defined in ow_global.h
29 // These are all the tunable constants and flags. Usually they have
30 // 1 A command line entry (ow_opt.h)
31 // 2 A help entry (ow_help.c)
32 // An entry in /settings (ow_settings.c)
33 struct global Globals = {
34 	.announce_off = 0,
35 	.announce_name = NULL,
36 	.program_type = program_type_swig,
37 	.allow_other = 0 , // for fuse
38 
39 	.temp_scale = temp_celsius,
40 	.pressure_scale = pressure_mbar,
41 	.format = fdi,
42 
43 	.uncached = 0,
44 	.unaliased = 0,
45 
46 	.daemon_status = e_daemon_want_bg ,
47 
48 	.error_level = e_err_default,
49 	.error_level_restore = e_err_default,
50 	.error_print = e_err_print_mixed,
51 	.fatal_debug = 1,
52 	.fatal_debug_file = NULL,
53 
54 	.readonly = 0,
55 	.max_clients = 250,
56 
57 	.cache_size = 0,
58 
59 	.one_device = 0,
60 
61 	.altUSB = 0,
62 	.usb_flextime = 1,
63 	.serial_flextime = 1,
64 	.serial_reverse = 0,  // 1 is "reverse" polarity
65 	.serial_hardflow = 0, // hardware flow control
66 
67 	.timeout_volatile = 15,
68 	.timeout_stable = 300,
69 	.timeout_directory = 60,
70 	.timeout_presence = 120,
71 	.timeout_serial = 5, // serial read and write use the same timeout currently
72 	.timeout_usb = 5,			// 5 seconds
73 	.timeout_network = 1,
74 	.timeout_server = 10,
75 	.timeout_ftp = 900,
76 	.timeout_ha7 = 60,
77 	.timeout_w1 = 30,
78 	.timeout_persistent_low = 600,
79 	.timeout_persistent_high = 3600,
80 	.clients_persistent_low = 10,
81 	.clients_persistent_high = 20,
82 
83 	.pingcrazy = 0,
84 	.no_dirall = 0,
85 	.no_get = 0,
86 	.no_persistence = 0,
87 	.eightbit_serial = 0,
88 	.trim = 0, // don't whitespace trim results by default
89 	.zero = zero_unknown ,
90 	.i2c_APU = 1 ,
91 	.i2c_PPM = 0 , // to prevent confusing the DS2483
92 	.baud = B9600 ,
93 	.traffic = 0, // show bus traffic
94 	.locks = 0, // show locks (mutexes)
95 
96 	.templow = GLOBAL_UNTOUCHED_TEMP_LIMIT,
97 	.temphigh = GLOBAL_UNTOUCHED_TEMP_LIMIT,
98 
99 	.argc = 0,
100 	.argv = NULL,
101 	.inet_type = inet_none,
102 	.exitmode = exit_early, // how long to pause after closing sockets before exit
103 	.restart_seconds = 5 ,
104 
105 //	.allow_external = 1 , // for testing
106 	.allow_external = 0 , // unless program == owexternal
107 
108 #if OW_USB
109 	.luc = NULL ,
110 #endif /* OW_USB */
111 };
112 
113 // generic value for ignorable function returns
114 int ignore_result ;
115 
116 /* Statistics globals are stored in ow_stats.c */
117 
118 /* State information, sent to remote or kept locally */
119 /* cacheenabled, presencecheck, tempscale, devform */
SetLocalControlFlags(void)120 void SetLocalControlFlags( void )
121 {
122 	CONTROLFLAGSLOCK;
123 	// Clear
124 	LocalControlFlags = 0 ;
125 	// Device format
126 	LocalControlFlags |= (Globals.format) << DEVFORMAT_BIT ;
127 	// Pressure scale
128 	LocalControlFlags |= (Globals.pressure_scale) << PRESSURESCALE_BIT ;
129 	// Temperature scale
130 	LocalControlFlags |= (Globals.temp_scale) << TEMPSCALE_BIT ;
131 	// Uncached
132 	LocalControlFlags |= Globals.uncached ? UNCACHED : 0 ;
133 	// Unaliased
134 	LocalControlFlags |= Globals.unaliased ? 0 : ALIAS_REQUEST ;
135 	// Trim
136 	LocalControlFlags |= Globals.trim ? 0 : TRIM ;
137 	// OWNet flag or Presence check
138 	LocalControlFlags |= OWNET ;
139 	CONTROLFLAGSUNLOCK;
140 }
141