root/driver/wwsr2.c

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