1 | 1 | simandl | /* |
2 | | | * wwsr - Wireless Weather Station Reader |
3 | | | * 2007 dec 19, Michael Pendec (michael.pendec@gmail.com) |
4 | | | * Version 0.5 |
5 | | | * 2008 jan 24 Svend Skafte (svend@skafte.net) |
6 | | | * 2008 sep 28 Adam Pribyl (covex@lowlevel.cz) |
7 | | | * Modifications for different firmware version(?) |
8 | | | */ |
9 | | | #include <stdio.h> |
10 | | | #include <string.h> |
11 | | | #include <stdlib.h> |
12 | | | #include <string.h> |
13 | | | #include <assert.h> |
14 | | | #include <signal.h> |
15 | | | #include <ctype.h> |
16 | | | #include <usb.h> |
17 | | | |
18 | | | struct usb_dev_handle *devh; |
19 | | | int ret,mempos=0,showall=0,shownone=0,resetws=0,pdebug=0,postprocess=0; |
20 | | | int o1,o2,o3,o4,o5,o6,o7,o8,o9,o10,o11,o12,o13,o14,o15; |
21 | | | char buf[1000],*endptr; |
22 | | | char buf2[400]; |
23 | | | |
24 | | | void _close_readw() { |
25 | | | ret = usb_release_interface(devh, 0); |
26 | | | if (ret!=0) printf("could not release interface: %d\n", ret); |
27 | | | ret = usb_close(devh); |
28 | | | if (ret!=0) printf("Error closing interface: %d\n", ret); |
29 | | | } |
30 | | | |
31 | | | struct usb_device *find_device(int vendor, int product) { |
32 | | | struct usb_bus *bus; |
33 | | | |
34 | | | for (bus = usb_get_busses(); bus; bus = bus->next) { |
35 | | | struct usb_device *dev; |
36 | | | |
37 | | | for (dev = bus->devices; dev; dev = dev->next) { |
38 | | | if (dev->descriptor.idVendor == vendor |
39 | | | && dev->descriptor.idProduct == product) |
40 | | | return dev; |
41 | | | } |
42 | | | } |
43 | | | return NULL; |
44 | | | } |
45 | | | |
46 | | | struct tempstat { |
47 | | | char ebuf[271]; |
48 | | | unsigned short noffset; |
49 | | | char delay1; |
50 | | | char hindoor; |
51 | | | signed int tindoor; |
52 | | | unsigned char houtdoor; |
53 | | | signed int toutdoor; |
54 | | | unsigned char swind; |
55 | | | unsigned char swind2; |
56 | | | unsigned char tempf; |
57 | | | int pressure; |
58 | | | unsigned char temph; |
59 | | | unsigned char tempi; |
60 | | | signed int rain; |
61 | | | signed int rain2; |
62 | | | unsigned char rain1; |
63 | | | unsigned char oth1; |
64 | | | unsigned char oth2; |
65 | | | char nbuf[250]; |
66 | | | char winddirection[100]; |
67 | | | } buf4; |
68 | | | |
69 | | | |
70 | | | void print_bytes(char *bytes, int len) { |
71 | | | int i; |
72 | | | if (len > 0) { |
73 | | | for (i=0; i<len; i++) { |
74 | | | printf("%02x ", (int)((unsigned char)bytes[i])); |
75 | | | } |
76 | | | // printf("\""); |
77 | | | } |
78 | | | } |
79 | | | void _open_readw() { |
80 | | | struct usb_device *dev; |
81 | | | int vendor, product; |
82 | | | #if 0 |
83 | | | usb_urb *isourb; |
84 | | | struct timeval isotv; |
85 | | | char isobuf[32768]; |
86 | | | #endif |
87 | | | |
88 | | | usb_init(); |
89 | | | // usb_set_debug(0); |
90 | | | usb_find_busses(); |
91 | | | usb_find_devices(); |
92 | | | |
93 | | | vendor = 0x1941; |
94 | | | product = 0x8021; |
95 | | | |
96 | | | dev = find_device(vendor, product); |
97 | | | assert(dev); |
98 | | | devh = usb_open(dev); |
99 | | | assert(devh); |
100 | | | signal(SIGTERM, _close_readw); |
101 | | | ret = usb_get_driver_np(devh, 0, buf, sizeof(buf)); |
102 | | | if (ret == 0) { |
103 | | | // printf("interface 0 already claimed by driver \"%s\", attempting to detach it\n", buf); |
104 | | | ret = usb_detach_kernel_driver_np(devh, 0); |
105 | | | // printf("usb_detach_kernel_driver_np returned %d\n", ret); |
106 | | | } |
107 | | | ret = usb_claim_interface(devh, 0); |
108 | | | if (ret != 0) { |
109 | | | printf("Could not open usb device, errorcode - %d\n", ret); |
110 | | | exit(1); |
111 | | | } |
112 | | | ret = usb_set_altinterface(devh, 0); |
113 | | | assert(ret >= 0); |
114 | | | } |
115 | | | |
116 | | | |
117 | | | void _init_wread() { |
118 | | | char tbuf[1000]; |
119 | | | ret = usb_get_descriptor(devh, 1, 0, tbuf, 0x12); |
120 | | | // usleep(14*1000); |
121 | | | ret = usb_get_descriptor(devh, 2, 0, tbuf, 9); |
122 | | | // usleep(10*1000); |
123 | | | ret = usb_get_descriptor(devh, 2, 0, tbuf, 0x22); |
124 | | | // usleep(22*1000); |
125 | | | ret = usb_release_interface(devh, 0); |
126 | | | if (ret != 0) printf("failed to release interface before set_configuration: %d\n", ret); |
127 | | | ret = usb_set_configuration(devh, 1); |
128 | | | ret = usb_claim_interface(devh, 0); |
129 | | | if (ret != 0) printf("claim after set_configuration failed with error %d\n", ret); |
130 | | | ret = usb_set_altinterface(devh, 0); |
131 | | | // usleep(22*1000); |
132 | | | ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0xa, 0, 0, tbuf, 0, 1000); |
133 | | | // usleep(4*1000); |
134 | | | ret = usb_get_descriptor(devh, 0x22, 0, tbuf, 0x74); |
135 | | | } |
136 | | | |
137 | | | void _send_usb_msg( char msg1[1],char msg2[1],char msg3[1],char msg4[1],char msg5[1],char msg6[1],char msg7[1],char msg8[1] ) { |
138 | | | char tbuf[1000]; |
139 | | | tbuf[0] = msg1[0]; |
140 | | | tbuf[1] = msg2[0]; |
141 | | | tbuf[2] = msg3[0]; |
142 | | | tbuf[3] = msg4[0]; |
143 | | | tbuf[4] = msg5[0]; |
144 | | | tbuf[5] = msg6[0]; |
145 | | | tbuf[6] = msg7[0]; |
146 | | | tbuf[7] = msg8[0]; |
147 | | | // print_bytes(tbuf, 8); |
148 | | | // printf(" - - - \n"); |
149 | | | ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 9, 0x200, 0, tbuf, 8, 1000); |
150 | | | // usleep(28*1000); |
151 | | | } |
152 | | | |
153 | | | void _read_usb_msg(char *buffer) { |
154 | | | char tbuf[1000]; |
155 | | | usb_interrupt_read(devh, 0x81, tbuf, 0x20, 1000); |
156 | | | memcpy(buffer, tbuf, 0x20); |
157 | | | // usleep(82*1000); |
158 | | | } |
159 | | | |
160 | | | |
161 | | | void read_arguments(int argc, char **argv) { |
162 | | | int c,pinfo=0; |
163 | | | char *mempos1=0,*endptr; |
164 | | | shownone=0; |
165 | | | o1=0; |
166 | | | while ((c = getopt (argc, argv, "akwosiurthp:zyx")) != -1) |
167 | | | { |
168 | | | switch (c) |
169 | | | { |
170 | | | case 'a': |
171 | | | showall=1; |
172 | | | shownone=1; |
173 | | | break; |
174 | | | case 'i': |
175 | | | o1=1; |
176 | | | shownone=1; |
177 | | | break; |
178 | | | case 'u': |
179 | | | o2=1; |
180 | | | shownone=1; |
181 | | | break; |
182 | | | case 't': |
183 | | | o3=1; |
184 | | | shownone=1; |
185 | | | break; |
186 | | | case 'w': |
187 | | | o4=1; |
188 | | | shownone=1; |
189 | | | break; |
190 | | | case 'r': |
191 | | | o5=1; |
192 | | | shownone=1; |
193 | | | break; |
194 | | | case 'o': |
195 | | | o6=1; |
196 | | | shownone=1; |
197 | | | break; |
198 | | | case 's': |
199 | | | o7=1; |
200 | | | shownone=1; |
201 | | | break; |
202 | | | case 'j': |
203 | | | o9=1; |
204 | | | shownone=1; |
205 | | | break; |
206 | | | case 'p': |
207 | | | mempos1=optarg; |
208 | | | break; |
209 | | | case 'h': |
210 | | | pinfo=1; |
211 | | | break; |
212 | | | case 'x': |
213 | | | pdebug=1; |
214 | | | break; |
215 | | | case 'y': |
216 | | | postprocess=1; |
217 | | | shownone=1; |
218 | | | break; |
219 | | | case 'z': |
220 | | | resetws=1; |
221 | | | shownone=1; |
222 | | | break; |
223 | | | case '?': |
224 | | | if (isprint (optopt)) |
225 | | | fprintf (stderr, "Unknown option `-%c'.\n", optopt); |
226 | | | else |
227 | | | fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt); |
228 | | | default: |
229 | | | abort (); |
230 | | | } |
231 | | | } |
232 | | | if ( (pinfo!=0) | (shownone==0) ) { |
233 | | | printf("Wireless Weather Station Reader v0.1\n"); |
234 | | | printf("(C) 2007 Michael Pendec\n\n"); |
235 | | | printf("options\n"); |
236 | | | printf(" -h help information\n"); |
237 | | | printf(" -p Start at offset (can be used together with below parameters\n"); |
238 | | | printf(" -x Show bytes retrieved from device\n"); |
239 | | | printf(" -z Reset log buffer (will ask for confirmation.\n\n"); |
240 | | | printf(" -a Show all stats (overrides below parameters)\n"); |
241 | | | printf(" -s Show current history position\n"); |
242 | | | printf(" -t Show temperature\n"); |
243 | | | printf(" -j Show Pressure (hPa)\n"); |
244 | | | printf(" -u Show humidity\n"); |
245 | | | printf(" -r Show rain\n"); |
246 | | | printf(" -w Show wind\n"); |
247 | | | printf(" -o other \n\n"); |
248 | | | exit(0); |
249 | | | } |
250 | | | if (mempos1!=0) { |
251 | | | mempos = strtol(mempos1, &endptr, 16); |
252 | | | } else { |
253 | | | printf("Reading last updated record from device\n"); |
254 | | | } |
255 | | | } |
256 | | | |
257 | | | int main(int argc, char **argv) { |
258 | | | int buftemp; |
259 | | | char ec='n'; |
260 | | | struct tempstat buf5; |
261 | | | |
262 | | | read_arguments(argc,argv); |
263 | | | _open_readw(); |
264 | | | _init_wread(); |
265 | | | |
266 | | | if (resetws==1) { |
267 | | | printf(" Resetting WetterStation history\n"); |
268 | | | printf("Sure you want to reset wetter station (y/N)?"); |
269 | | | fflush(stdin); |
270 | | | scanf("%c",&ec); |
271 | | | if ( (ec=='y') || (ec=='Y') ) { |
272 | | | _send_usb_msg("\xa0","\x00","\x00","\x20","\xa0","\x00","\x00","\x20"); |
273 | | | _send_usb_msg("\x55","\x55","\xaa","\xff","\xff","\xff","\xff","\xff"); |
274 | | | usleep(28*1000); |
275 | | | _send_usb_msg("\xff","\xff","\xff","\xff","\xff","\xff","\xff","\xff"); |
276 | | | usleep(28*1000); |
277 | | | _send_usb_msg("\x05","\x20","\x01","\x38","\x11","\x00","\x00","\x00"); |
278 | | | usleep(28*1000); |
279 | | | _send_usb_msg("\x00","\x00","\xaa","\x00","\x00","\x00","\x20","\x3e"); |
280 | | | usleep(28*1000); |
281 | | | } else { |
282 | | | printf(" Aborted reset of history buffer\n"); |
283 | | | } |
284 | | | _close_readw(); |
285 | | | return 0; |
286 | | | } |
287 | | | _send_usb_msg("\xa1","\x00","\x00","\x20","\xa1","\x00","\x00","\x20"); |
288 | | | _read_usb_msg(buf2); |
289 | | | if ( ( pdebug==1) ) |
290 | | | { |
291 | | | printf("000-031: "); |
292 | | | print_bytes(buf2, 32); |
293 | | | printf("\n"); |
294 | | | } |
295 | | | _send_usb_msg("\xa1","\x00","\x20","\x20","\xa1","\x00","\x20","\x20"); |
296 | | | _read_usb_msg(buf2+32); |
297 | | | if ( ( pdebug==1) ) |
298 | | | { |
299 | | | printf("032-063: "); |
300 | | | print_bytes(buf2+32, 32); |
301 | | | printf("\n"); |
302 | | | } |
303 | | | _send_usb_msg("\xa1","\x00","\x40","\x20","\xa1","\x00","\x40","\x20"); |
304 | | | _read_usb_msg(buf2+64); |
305 | | | if ( ( pdebug==1) ) |
306 | | | { |
307 | | | printf("064-095: "); |
308 | | | print_bytes(buf2+64, 32); |
309 | | | printf("\n"); |
310 | | | } |
311 | | | _send_usb_msg("\xa1","\x00","\x60","\x20","\xa1","\x00","\x60","\x20"); |
312 | | | _read_usb_msg(buf2+96); |
313 | | | if ( ( pdebug==1) ) |
314 | | | { |
315 | | | printf("096-123: "); |
316 | | | print_bytes(buf2+96, 32); |
317 | | | printf("\n"); |
318 | | | } |
319 | | | _send_usb_msg("\xa1","\x00","\x80","\x20","\xa1","\x00","\x80","\x20"); |
320 | | | _read_usb_msg(buf2+128); |
321 | | | if ( ( pdebug==1) ) |
322 | | | { |
323 | | | printf("124-159: "); |
324 | | | print_bytes(buf2+128, 32); |
325 | | | printf("\n"); |
326 | | | } |
327 | | | _send_usb_msg("\xa1","\x00","\xa0","\x20","\xa1","\x00","\xa0","\x20"); |
328 | | | _read_usb_msg(buf2+160); |
329 | | | if ( ( pdebug==1) ) |
330 | | | { |
331 | | | printf("160-191: "); |
332 | | | print_bytes(buf2+160, 32); |
333 | | | printf("\n"); |
334 | | | } |
335 | | | _send_usb_msg("\xa1","\x00","\xc0","\x20","\xa1","\x00","\xc0","\x20"); |
336 | | | _read_usb_msg(buf2+192); |
337 | | | if ( ( pdebug==1) ) |
338 | | | { |
339 | | | printf("192-223: "); |
340 | | | print_bytes(buf2+192, 32); |
341 | | | printf("\n"); |
342 | | | } |
343 | | | _send_usb_msg("\xa1","\x00","\xe0","\x20","\xa1","\x00","\xe0","\x20"); |
344 | | | _read_usb_msg(buf2+224); |
345 | | | if ( ( pdebug==1) ) |
346 | | | { |
347 | | | printf("224-255: "); |
348 | | | print_bytes(buf2+224, 32); |
349 | | | printf("\n"); |
350 | | | } |
351 | | | |
352 | | | |
353 | | | // buf4.noffset = (unsigned char) buf2[22] + ( 256 * buf2[23] ); |
354 | | | buf4.noffset = (unsigned char) buf2[30] + ( 256 * buf2[31] ); |
355 | | | if (mempos!=0) buf4.noffset = mempos; |
356 | | | buftemp = 0; |
357 | | | if (buf4.noffset!=0) buftemp = buf4.noffset - 0x10; |
358 | | | buf[1] = ( buftemp >>8 & 0xFF ) ; |
359 | | | buf[2] = buftemp & 0xFF; |
360 | | | buf[3] = ( buftemp >>8 & 0xFF ) ; |
361 | | | buf[4] = buftemp & 0xFF; |
362 | | | _send_usb_msg("\xa1",buf+1,buf+2,"\x20","\xa1",buf+3,buf+4,"\x20"); |
363 | | | _read_usb_msg(buf2+224); |
364 | | | if ( ( pdebug==1) ) |
365 | | | { |
366 | | | printf("224-255: "); |
367 | | | print_bytes(buf2+224, 32); |
368 | | | printf("\n"); |
369 | | | } |
370 | | | |
371 | | | ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x0000009, 0x0000200, 0x0000000, buf, 0x0000008, 1000); |
372 | | | // usleep(8*1000); |
373 | | | ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000020, 1000); |
374 | | | memcpy(buf2+256, buf, 0x0000020); |
375 | | | if ( ( pdebug==1) ) |
376 | | | { |
377 | | | printf("256-287: "); |
378 | | | print_bytes(buf2+256, 32); |
379 | | | printf("\n"); |
380 | | | } |
381 | | | |
382 | | | buf4.delay1 = buf2[224]; |
383 | | | buf4.tempi=buf2[236]; |
384 | | | if (buf4.tempi==0) strcpy(buf4.winddirection,"N"); |
385 | | | if (buf4.tempi==1) strcpy(buf4.winddirection,"NNE"); |
386 | | | if (buf4.tempi==2) strcpy(buf4.winddirection,"NE"); |
387 | | | if (buf4.tempi==3) strcpy(buf4.winddirection,"ENE"); |
388 | | | if (buf4.tempi==4) strcpy(buf4.winddirection,"E"); |
389 | | | if (buf4.tempi==5) strcpy(buf4.winddirection,"ESE"); |
390 | | | if (buf4.tempi==6) strcpy(buf4.winddirection,"SE"); |
391 | | | if (buf4.tempi==7) strcpy(buf4.winddirection,"SSE"); |
392 | | | if (buf4.tempi==8) strcpy(buf4.winddirection,"S"); |
393 | | | if (buf4.tempi==9) strcpy(buf4.winddirection,"SSW"); |
394 | | | if (buf4.tempi==10) strcpy(buf4.winddirection,"SW"); |
395 | | | if (buf4.tempi==11) strcpy(buf4.winddirection,"WSW"); |
396 | | | if (buf4.tempi==12) strcpy(buf4.winddirection,"W"); |
397 | | | if (buf4.tempi==13) strcpy(buf4.winddirection,"WNW"); |
398 | | | if (buf4.tempi==14) strcpy(buf4.winddirection,"NW"); |
399 | | | if (buf4.tempi==15) strcpy(buf4.winddirection,"NNW"); |
400 | | | buf4.hindoor = buf2[225]; |
401 | | | buf4.tindoor =( (unsigned char) buf2[226] + (unsigned char) buf2[227] *256); |
402 | | | buf4.houtdoor = buf2[228]; |
403 | | | buf4.toutdoor =( (unsigned char) buf2[229] + (unsigned char) buf2[230] *256); |
404 | | | buf4.pressure = (unsigned char) buf2[231] + ( 256*buf2[232]); |
405 | | | buf4.swind = buf2[233]; |
406 | | | buf4.swind2 = buf2[234]; |
407 | | | buf4.oth1 = buf2[235]; |
408 | | | buf4.rain2 = (unsigned char) buf2[237]; |
409 | | | buf4.rain =( (unsigned char) buf2[238] + (unsigned char) buf2[239] *256); |
410 | | | buf4.rain1 = buf2[238]; |
411 | | | buf4.oth2 = buf2[239]; |
412 | | | |
413 | | | //------------------ |
414 | | | buf5.delay1 = buf2[240]; |
415 | | | buf5.tempi=buf2[252]; |
416 | | | if (buf5.tempi==0) strcpy(buf5.winddirection,"N"); |
417 | | | if (buf5.tempi==1) strcpy(buf5.winddirection,"NNE"); |
418 | | | if (buf5.tempi==2) strcpy(buf5.winddirection,"NE"); |
419 | | | if (buf5.tempi==3) strcpy(buf5.winddirection,"ENE"); |
420 | | | if (buf5.tempi==4) strcpy(buf5.winddirection,"E"); |
421 | | | if (buf5.tempi==5) strcpy(buf5.winddirection,"ESE"); |
422 | | | if (buf5.tempi==6) strcpy(buf5.winddirection,"SE"); |
423 | | | if (buf5.tempi==7) strcpy(buf5.winddirection,"SSE"); |
424 | | | if (buf5.tempi==8) strcpy(buf5.winddirection,"S"); |
425 | | | if (buf5.tempi==9) strcpy(buf5.winddirection,"SSW"); |
426 | | | if (buf5.tempi==10) strcpy(buf5.winddirection,"SW"); |
427 | | | if (buf5.tempi==11) strcpy(buf5.winddirection,"WSW"); |
428 | | | if (buf5.tempi==12) strcpy(buf5.winddirection,"W"); |
429 | | | if (buf5.tempi==13) strcpy(buf5.winddirection,"WNW"); |
430 | | | if (buf5.tempi==14) strcpy(buf5.winddirection,"NW"); |
431 | | | if (buf5.tempi==15) strcpy(buf5.winddirection,"NNW"); |
432 | | | buf5.hindoor = buf2[241]; |
433 | | | buf5.tindoor =( (unsigned char) buf2[242] + (unsigned char) buf2[243] *256); |
434 | | | buf5.tindoor &= 32767; |
435 | | | //buf5.tindoor = (unsigned char) buf2[242]; |
436 | | | buf5.houtdoor = buf2[244]; |
437 | | | buf5.toutdoor =( (unsigned char) buf2[245] + (unsigned char) buf2[246] *256); |
438 | | | buf5.toutdoor &= 32767; |
439 | | | //buf5.toutdoor = (unsigned char) buf2[245]; |
440 | | | buf5.pressure = (unsigned char) buf2[247] + ( 256*buf2[248]); |
441 | | | buf5.swind = buf2[249]; |
442 | | | buf5.swind2 = buf2[250]; |
443 | | | buf5.oth1 = buf2[251]; |
444 | | | buf5.rain2 = (unsigned char) buf2[253]; |
445 | | | buf5.rain =( (unsigned char) buf2[254] + (unsigned char) buf2[255] *256); |
446 | | | buf5.rain1 = buf2[254]; |
447 | | | buf5.oth2 = buf2[255]; |
448 | | | //------------------ |
449 | | | /* |
450 | | | buf4.delay1 = buf2[272]; |
451 | | | buf4.tempi=buf2[284]; |
452 | | | if (buf4.tempi==0) strcpy(buf4.winddirection,"N"); |
453 | | | if (buf4.tempi==1) strcpy(buf4.winddirection,"NNE"); |
454 | | | if (buf4.tempi==2) strcpy(buf4.winddirection,"NE"); |
455 | | | if (buf4.tempi==3) strcpy(buf4.winddirection,"ENE"); |
456 | | | if (buf4.tempi==4) strcpy(buf4.winddirection,"E"); |
457 | | | if (buf4.tempi==5) strcpy(buf4.winddirection,"SEE"); |
458 | | | if (buf4.tempi==6) strcpy(buf4.winddirection,"SE"); |
459 | | | if (buf4.tempi==7) strcpy(buf4.winddirection,"SSE"); |
460 | | | if (buf4.tempi==8) strcpy(buf4.winddirection,"S"); |
461 | | | if (buf4.tempi==9) strcpy(buf4.winddirection,"SSW"); |
462 | | | if (buf4.tempi==10) strcpy(buf4.winddirection,"SW"); |
463 | | | if (buf4.tempi==11) strcpy(buf4.winddirection,"SWW"); |
464 | | | if (buf4.tempi==12) strcpy(buf4.winddirection,"W"); |
465 | | | if (buf4.tempi==13) strcpy(buf4.winddirection,"NWW"); |
466 | | | if (buf4.tempi==14) strcpy(buf4.winddirection,"NW"); |
467 | | | if (buf4.tempi==15) strcpy(buf4.winddirection,"NNW"); |
468 | | | buf4.hindoor = buf2[273]; |
469 | | | buf4.tindoor =( (unsigned char) buf2[274] + (unsigned char) buf2[275] *256); |
470 | | | buf4.houtdoor = buf2[276]; |
471 | | | buf4.toutdoor =( (unsigned char) buf2[277] + (unsigned char) buf2[278] *256); |
472 | | | buf4.pressure = (unsigned char) buf2[279] + ( 256*buf2[280]); |
473 | | | buf4.swind = buf2[281]; |
474 | | | buf4.swind2 = buf2[282]; |
475 | | | buf4.oth1 = buf2[283]; |
476 | | | buf4.rain2 = (unsigned char) buf2[285]; |
477 | | | buf4.rain =( (unsigned char) buf2[286] + (unsigned char) buf2[287] *256); |
478 | | | buf4.rain1 = buf2[286]; |
479 | | | buf4.oth2 = buf2[287]; |
480 | | | */ |
481 | | | |
482 | | | |
483 | | | |
484 | | | printf("Last saved values:\n"); |
485 | | | unsigned int remain; |
486 | | | if ( (showall==1) | ( o1==1) ) printf("224:\t\tinterval:\t\t%5d\n", buf4.delay1); |
487 | | | if ( (showall==1) | ( o2==1) ) printf("225:\t\tindoor humidity\t\t%5d\n", buf4.hindoor); |
488 | | | if ( (showall==1) | ( o2==1) ) printf("228:\t\toutdoor humidity\t%5d\n", buf4.houtdoor); |
489 | | | remain = buf4.tindoor%10; |
490 | | | if ((signed) remain<0) remain = remain * -1; |
491 | | | if ( (showall==1) | ( o3==1) ) printf("226 227:\tindoor temperature\t%5d.%d\n", buf4.tindoor / 10 ,remain); |
492 | | | remain = buf4.toutdoor%10; |
493 | | | |
494 | | | if ((signed) remain<0) remain = remain * -1; |
495 | | | if ( (showall==1) | ( o3==1) ) printf("229 230:\toutdoor temperature\t%5d.%d\n", buf4.toutdoor / 10 ,remain); |
496 | | | remain = buf4.swind%10; |
497 | | | if ( (showall==1) | ( o4==1) ) printf("233:\t\twind speed\t\t%5d.%d\n", buf4.swind / 10 , remain); |
498 | | | remain = buf4.swind2%10; |
499 | | | if ( (showall==1) | ( o4==1) ) printf("234:\t\twind gust\t\t%5d.%d\n", buf4.swind2 / 10 , remain); |
500 | | | if ( (showall==1) | ( o4==1) ) printf("236:\t\twind direction\t\t%5s\n", buf4.winddirection); |
501 | | | remain = buf4.rain%10; |
502 | | | if ( (showall==1) | ( o5==1) ) printf("238 239:\train?\t\t\t%5d.%d\n", buf4.rain / 10 , remain); |
503 | | | remain = (buf4.rain2)%10; |
504 | | | if ( (showall==1) | ( o5==1) ) printf("237:\t\train - ??\t\t%5d.%d\n", buf4.rain2 / 10 , remain); |
505 | | | if ( (showall==1) | ( o5==1) ) printf("248:\t\train1\t\t\t%5d\n", buf4.rain1); |
506 | | | if ( (showall==1) | ( o5==1) ) printf("\t\train2\t\t\t%5d\n", buf4.rain2); |
507 | | | if ( (showall==1) | ( o6==1) ) printf("235:\t\tother 1\t\t\t%5d\n", buf4.oth1); |
508 | | | if ( (showall==1) | ( o6==1) ) printf("239:\t\tother 2\t\t\t%5d\n", buf4.oth2); |
509 | | | remain = buf4.pressure%10; |
510 | | | if ( (showall==1) | ( o9==1) ) printf("231 232:\tpressure(hPa)\t\t%5d.%d\n", buf4.pressure / 10 , remain); |
511 | | | if ( (showall==1) | ( o7==1) ) printf("\t\tCurrent history pos:\t%5x\n", buf4.noffset); |
512 | | | printf("\n"); |
513 | | | |
514 | | | //------------------ |
515 | | | printf("Current values:\n"); |
516 | | | if ( (showall==1) | ( o1==1) ) printf("240:\t\tSince last save:\t%5dmin\n", buf5.delay1); |
517 | | | if ( (showall==1) | ( o2==1) ) printf("241:\t\tindoor humidity\t\t%5d\n", buf5.hindoor); |
518 | | | if ( (showall==1) | ( o2==1) ) printf("244:\t\toutdoor humidity\t%5d\n", buf5.houtdoor); |
519 | | | remain = buf5.tindoor%10; |
520 | | | if ((signed) remain<0) remain = remain * -1; |
521 | | | if ( (showall==1) | ( o3==1) ) printf("242 243:\tindoor temperature\t%5d.%d\n", buf5.tindoor / 10 ,remain); |
522 | | | remain = buf5.toutdoor%10; |
523 | | | if ((signed) remain<0) remain = remain * -1; |
524 | | | if ( (showall==1) | ( o3==1) ) printf("245 246:\toutdoor temperature\t%5d.%d\n", buf5.toutdoor / 10 ,remain); |
525 | | | remain = buf5.swind%10; |
526 | | | if ( (showall==1) | ( o4==1) ) printf("249:\t\twind speed\t\t%5d.%d\n", buf5.swind / 10 , remain); |
527 | | | remain = buf5.swind2%10; |
528 | | | if ( (showall==1) | ( o4==1) ) printf("250:\t\twind gust\t\t%5d.%d\n", buf5.swind2 / 10 , remain); |
529 | | | if ( (showall==1) | ( o4==1) ) printf("252:\t\twind direction\t\t%5s\n", buf5.winddirection); |
530 | | | remain = buf5.rain%10; |
531 | | | if ( (showall==1) | ( o5==1) ) printf("254 255:\train? this is always zero %5d.%d\n", buf5.rain / 10 , remain); |
532 | | | remain = (buf5.rain2)%10; |
533 | | | if ( (showall==1) | ( o5==1) ) printf("253:\t\train - 24h?\t\t%5d.%d\n", buf5.rain2 / 10 , remain); |
534 | | | if ( (showall==1) | ( o5==1) ) printf("254:\t\train1\t\t\t%5d\n", buf5.rain1); |
535 | | | if ( (showall==1) | ( o5==1) ) printf("\t\train2\t\t\t%5d\n", buf5.rain2); |
536 | | | if ( (showall==1) | ( o6==1) ) printf("251:\t\tother 1\t\t\t%5d\n", buf5.oth1); |
537 | | | if ( (showall==1) | ( o6==1) ) printf("255:\t\tother 2\t\t\t%5d\n", buf5.oth2); |
538 | | | remain = buf5.pressure%10; |
539 | | | if ( (showall==1) | ( o9==1) ) printf("247 248:\tpressure(hPa)\t\t%5d.%d\n", buf5.pressure / 10 , remain); |
540 | | | if ( (showall==1) | ( o7==1) ) printf("\t\tCurrent history pos:\t%5x\n", buf5.noffset); |
541 | | | printf("\n"); |
542 | | | |
543 | | | if (postprocess==1) { |
544 | | | printf ("For postprocessing\n"); |
545 | | | printf ("Interval\t%d min\n", buf5.delay1); |
546 | | | printf ("Humidity indoor\t%d %%\n", buf5.hindoor); |
547 | | | printf ("Humidity outdoor\t%d %%\n", buf5.houtdoor); |
548 | | | if ((buf2[243] & 128) > 0) { |
549 | | | printf ("Temperature indoor\t-%d.%d C\n", buf5.tindoor / 10, abs(buf5.tindoor % 10)); |
550 | | | } else { |
551 | | | printf ("Temperature indoor\t%d.%d C\n", buf5.tindoor / 10, abs(buf5.tindoor % 10)); |
552 | | | }; |
553 | | | if ((buf2[246] & 128) > 0) { |
554 | | | printf ("Temperature outdoor\t-%d.%d C\n", buf5.toutdoor / 10, abs(buf5.toutdoor % 10)); |
555 | | | } else { |
556 | | | printf ("Temperature outdoor\t%d.%d C\n", buf5.toutdoor / 10, abs(buf5.toutdoor % 10)); |
557 | | | }; |
558 | | | printf ("Wind speed\t%d.%d m/s\n", buf5.swind / 10, abs(buf5.swind %10)); |
559 | | | printf ("Wind gust\t%d.%d m/s\n", buf5.swind2 / 10, abs(buf5.swind %10)); |
560 | | | printf ("Wind direction\t%d %s\n", buf2[252], buf5.winddirection); |
561 | | | if (buf5.delay1 != 0) { |
562 | | | printf ("Rain 1h\t%.1f mm/h\n", (double)((buf5.rain2 - buf4.rain2) + (buf5.rain1 - buf4.rain1)*256)*0.3*(60/buf5.delay1) ); |
563 | | | } else { |
564 | | | printf ("Rain 1h\t%.1f mm/h\n", 0.0); |
565 | | | } |
566 | | | printf ("Rain total\t%.1f mm\n", (double)(buf5.rain2 + buf5.rain1*256) * 0.3); |
567 | | | printf ("Pressure air\t%d.%d hPa\n", buf5.pressure / 10, buf5.pressure % 10); |
568 | | | printf ("\n"); |
569 | | | } |
570 | | | //------------------ |
571 | | | |
572 | | | _close_readw(); |
573 | | | return 0; |
574 | | | } |