-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathte923con.c
More file actions
336 lines (302 loc) · 10.5 KB
/
Copy pathte923con.c
File metadata and controls
336 lines (302 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/***************************************************************************
* Copyright (C) 2010 by Sebastian John *
* te923@fukz.org *
* for more informations visit http://te923.fukz.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "te923con.h"
#include "te923usb.h"
#include "te923com.h"
#define MEMSIZE 208
#define MEMSIZE_BIG 3442
unsigned short debug = FALSE;
unsigned short bigmem = FALSE;
enum output { rtdata, memdump, status };
void usage() {
printf( "te923con, connector for TE923 weatherstations v%s - (c) 2010 - 2013 by Sebastian John (te923@fukz.org)\n", VERSION );
printf( "This program is free software, distributed under the terms of the GNU General Public Licens.\n\n");
printf( "usage: te923con [options]\n" );
printf( " -D - Debug output (please send this output for bugfixing)\n" );
printf( " -d - dump all values from internal (small) memory\n" );
printf( " -b - dump all values from internal (big) memory (new hardware version)\n" );
printf( " -s - get status from weather station\n" );
printf( " -i - set the output for invalid values (unreachable sensors), default it is i\n" );
printf (" -h - print this help informations\n" );
printf( " -v - print version number of this program\n" );
printf( "\n" );
printf( "Output format is colon separatet values. Invalid values or values from not present sensors\n" );
printf( "are hidden by default. You can set output for invalid with -i option. Output format:\n\n" );
printf( "T0:H0:T1:H1:T2:H2:T3:H3:T4:H4:T5:H5:PRESS:UV:FC:STORM:WD:WS:WG:WC:RC\n\n" );
printf( " T0 - temperature from internal sensor in °C\n" );
printf( " H0 - humidity from internal sensor in %% rel\n" );
printf( " T1..5 - temperature from external sensor 1..4 in °C\n" );
printf( " H1..5 - humidity from external sensor 1...4 in %% rel\n" );
printf( " PRESS - air pressure in mBar\n" );
printf( " UV - UV index from UV sensor\n" );
printf( " FC - station forecast, see below for more details\n" );
printf( " STORM - stormwarning; 0 - no warning, 1 - fix your dog \n" );
printf( " WD - wind direction in n x 22.5°; 0 -> north\n" );
printf( " WS - wind speed in m/s\n" );
printf( " WG - wind gust speed in m/s\n" );
printf( " WC - windchill temperature in °C\n" );
printf( " RC - rain counter (maybe since station starts measurement) as value\n" );
printf( "\n" );
printf( " weather forecast means (as precisely as possible)\n" );
printf( " 0 - heavy snow\n" );
printf( " 1 - little snow\n" );
printf( " 2 - heavy rain\n" );
printf( " 3 - little rain\n" );
printf( " 4 - cloudy\n" );
printf( " 5 - some clouds\n" );
printf( " 6 - sunny\n" );
printf( "\n" );
printf( "Status output means:\n\n" );
printf( "SYSSW:BARSW:EXTSW:RCCSW:WINSW:BATR:BATU:BATW:BAT5:BAT4:BAT5:BAT2:BAT1\n\n" );
printf( " SYSSW - software version of system controller\n" );
printf( " BARSW - software version of barometer\n" );
printf( " EXTSW - software version of UV and channel controller\n" );
printf( " RCCSW - software version of rain controller\n" );
printf( " WINSW - software version of wind controller\n" );
printf( " BATR - battery of rain sensor (1-good (not present), 0-low)\n" );
printf( " BATU - battery of UV sensor (1-good (not present), 0-low)\n" );
printf( " BATW - battery of wind sensor (1-good (not present), 0-low)\n" );
printf( " BAT5 - battery of sensor 5 (1-good (not present), 0-low)\n" );
printf( " BAT4 - battery of sensor 4 (1-good (not present), 0-low)\n" );
printf( " BAT3 - battery of sensor 3 (1-good (not present), 0-low)\n" );
printf( " BAT2 - battery of sensor 2 (1-good (not present), 0-low)\n" );
printf( " BAT1 - battery of sensor 1 (1-good (not present), 0-low)\n" );
printf("\n");
printf( "For updates, bugfixes and support visit http://te923.fukz.org.\n" );
}
void printData( Te923DataSet_t *data, char *iText ) {
int i;
printf( "%d:" , data->timestamp );
for ( i = 0; i <= 5; i++ ) {
if ( data->_t[i] == 0 )
printf( "%0.2f:", data->t[i] );
else
printf( "%s:", iText );
if ( data->_h[i] == 0 )
printf( "%d:", data->h[i] );
else
printf( "%s:", iText );
}
if ( data->_press == 0 )
printf( "%0.1f:", data->press );
else
printf( "%s:", iText );
if ( data->_uv == 0 )
printf( "%0.1f:", data->uv );
else
printf( "%s:", iText );
if ( data->_forecast == 0 )
printf( "%d:", data->forecast );
else
printf( "%s:", iText );
if ( data->_storm == 0 )
printf( "%d:", data->storm );
else
printf( "%s:", iText );
if ( data->_wDir == 0 )
printf( "%d:", data->wDir );
else
printf( "%s:", iText );
if ( data->_wSpeed == 0 )
printf( "%0.1f:", data->wSpeed );
else
printf( "%s:", iText );
if ( data->_wGust == 0 )
printf( "%0.1f:", data->wGust );
else
printf( "%s:", iText );
if ( data->_wChill == 0 )
printf( "%0.1f:", data->wChill );
else
printf( "%s:", iText );
if ( data->_RainCount == 0 )
printf( "%d", data->RainCount );
else
printf( "%s:", iText );
printf( "\n" );
}
Te923DataSet_t *poll_memdump(int is_big) {
struct usb_dev_handle *devh;
devh = te923_handle();
if ( devh == NULL ) {
return NULL;
}
int i;
int count;
count = 208;
if ( bigmem == TRUE ) {
count = 3442;
}
Te923DataSet_t *data;
data = ( Te923DataSet_t* )malloc( sizeof( Te923DataSet_t[count] ) );
memset ( data, 0, sizeof ( Te923DataSet_t[count] ) );
for ( i = 0; i < count; i++ ) {
get_te923_memdata( devh, &(data[i]), bigmem );
}
return data;
}
Te923DataSet_t *poll_rtdata() {
struct usb_dev_handle *devh;
devh = te923_handle();
if ( devh == NULL ) {
return NULL;
}
Te923DataSet_t *data;
data = ( Te923DataSet_t* )malloc( sizeof( Te923DataSet_t ) );
memset ( data, 0, sizeof ( Te923DataSet_t ) );
if (get_te923_lifedata( devh, data )) {
free(data);
return NULL;
}
te923_close( devh );
return data;
}
Te923DevSet_t *poll_status() {
struct usb_dev_handle *devh;
devh = te923_handle();
if ( devh == NULL ) {
return NULL;
}
Te923DevSet_t *status;
status = ( Te923DevSet_t* )malloc( sizeof( Te923DevSet_t ) );
if (get_te923_devstate( devh, status )){
free(status);
return NULL;
}
te923_close( devh );
return status;
}
// Te923DataSet_t get_memdump(int is_big) {
// Te923DataSet_t *data = poll_memdump(is_big);
// Te923DataSet_t r_data;
// if (data) {
// r_data = *data;
// free(data);
// }
// else {
// //set r_data to 0
// memset ( &r_data, 0, sizeof ( Te923DataSet_t ) );
// }
// return r_data;
// }
Te923DataSet_t get_rtdata() {
Te923DataSet_t *data = poll_rtdata();
Te923DataSet_t r_data;
if (data) {
r_data = *data;
free(data);
}
else {
//set r_data to 0
memset ( &r_data, 0, sizeof ( Te923DataSet_t ) );
}
return r_data;
}
Te923DevSet_t get_status() {
Te923DevSet_t *data = poll_status();
Te923DevSet_t r_data;
if (data) {
r_data = *data;
free(data);
}
else {
//set r_data to 0
memset ( &r_data, 0, sizeof ( Te923DevSet_t ) );
}
return(r_data);
}
int main( int argc, char **argv ) {
char *iText = NULL;
signed int opt;
enum output output = rtdata;
while (( opt = getopt( argc, argv, "Ddhi:svb" ) ) != -1 ) {
switch ( opt ) {
case 'h':
usage();
return 0;
case 'v':
printf( "te923con version %s\n" , VERSION );
return 0;
case 'D':
debug = TRUE;
break;
case 's':
output = status;
break;
case 'd':
output = memdump;
break;
case 'i':
iText = optarg;
break;
case 'b':
bigmem = TRUE;
output = memdump;
break;
case '?':
if ( optopt == 'i' )
fprintf( stderr, "Option -%c requires an argument.\n", optopt );
else if ( isprint( optopt ) )
fprintf( stderr, "Unknown option `-%c'.\n", optopt );
else
fprintf( stderr, "Unknown option character `\\x%x'.\n", optopt );
return 1;
break;
}
}
if ( iText == NULL )
iText = "i";
if (debug > 0)
printf("[DEBUG] VER %s\n",VERSION);
if ( output == rtdata ) {
Te923DataSet_t *data;
data = poll_rtdata();
printData( data, iText);
free(data);
}
if ( output == memdump ) {
int i;
int count;
count = MEMSIZE;
if ( bigmem == TRUE ) {
count = MEMSIZE_BIG;
}
Te923DataSet_t *data = poll_memdump(bigmem);
for ( i = 0; i < count; i++ ) {
printData( &(data[i]), iText);
}
free(data);
}
if ( output == status ) {
Te923DevSet_t *status;
status = poll_status();
printf( "0x%x:0x%x:0x%x:0x%x:0x%x:%d:%d:%d:%d:%d:%d:%d:%d\n",
status->SysVer, status->BarVer, status->UvVer, status->RccVer, status->WindVer,
status->batteryRain, status->batteryUV, status->batteryWind, status->battery5,
status->battery4, status->battery3, status->battery2, status->battery1);
free(status);
}
return 0;
}