| 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 | |
|---|
| 19 | struct usb_dev_handle *devh; |
|---|
| 20 | int ret,mempos=0,showall=0,shownone=0,resetws=0,pdebug=0,postprocess=0; |
|---|
| 21 | int o1,o2,o3,o4,o5,o6,o7,o8,o9,o10,o11,o12,o13,o14,o15; |
|---|
| 22 | char buf[1000],*endptr; |
|---|
| 23 | char buf2[400]; |
|---|
| 24 | |
|---|
| 25 | void _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 | |
|---|
| 32 | struct 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 | |
|---|
| 47 | struct 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 | |
|---|
| 71 | void 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 | } |
|---|
| 80 | void _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 | |
|---|
| 118 | void _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 | |
|---|
| 138 | 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] ) { |
|---|
| 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 | |
|---|
| 154 | void _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 | |
|---|
| 162 | void 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 | |
|---|
| 265 | int 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 | |
|---|
| 379 | ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x0000009, 0x0000200, 0x0000000, buf, 0x0000008, 1000); |
|---|
| 380 | // usleep(8*1000); |
|---|
| 381 | ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000020, 1000); |
|---|
| 382 | memcpy(buf2+256, buf, 0x0000020); |
|---|
| 383 | if ( ( pdebug==1) ) |
|---|
| 384 | { |
|---|
| 385 | printf("256-287: "); |
|---|
| 386 | print_bytes(buf2+256, 32); |
|---|
| 387 | printf("\n"); |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | buf4.delay1 = buf2[224]; |
|---|
| 391 | buf4.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"); |
|---|
| 408 | buf4.hindoor = buf2[225]; |
|---|
| 409 | buf4.tindoor =( (unsigned char) buf2[226] + (unsigned char) buf2[227] *256); |
|---|
| 410 | buf4.houtdoor = buf2[228]; |
|---|
| 411 | buf4.toutdoor =( (unsigned char) buf2[229] + (unsigned char) buf2[230] *256); |
|---|
| 412 | buf4.pressure = (unsigned char) buf2[231] + ( 256*buf2[232]); |
|---|
| 413 | buf4.swind = buf2[233]; |
|---|
| 414 | buf4.swind2 = buf2[234]; |
|---|
| 415 | buf4.oth1 = buf2[235]; |
|---|
| 416 | buf4.rain2 = (unsigned char) buf2[237]; |
|---|
| 417 | buf4.rain =( (unsigned char) buf2[238] + (unsigned char) buf2[239] *256); |
|---|
| 418 | buf4.rain1 = buf2[238]; |
|---|
| 419 | buf4.oth2 = buf2[239]; |
|---|
| 420 | |
|---|
| 421 | //------------------ |
|---|
| 422 | buf5.delay1 = buf2[240]; |
|---|
| 423 | buf5.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"); |
|---|
| 440 | buf5.hindoor = buf2[241]; |
|---|
| 441 | buf5.tindoor =( (unsigned char) buf2[242] + (unsigned char) buf2[243] *256); |
|---|
| 442 | buf5.tindoor &= 32767; |
|---|
| 443 | //buf5.tindoor = (unsigned char) buf2[242]; |
|---|
| 444 | buf5.houtdoor = buf2[244]; |
|---|
| 445 | buf5.toutdoor =( (unsigned char) buf2[245] + (unsigned char) buf2[246] *256); |
|---|
| 446 | buf5.toutdoor &= 32767; |
|---|
| 447 | //buf5.toutdoor = (unsigned char) buf2[245]; |
|---|
| 448 | buf5.pressure = (unsigned char) buf2[247] + ( 256*buf2[248]); |
|---|
| 449 | buf5.swind = buf2[249]; |
|---|
| 450 | buf5.swind2 = buf2[250]; |
|---|
| 451 | buf5.oth1 = buf2[251]; |
|---|
| 452 | buf5.rain2 = (unsigned char) buf2[253]; |
|---|
| 453 | buf5.rain =( (unsigned char) buf2[254] + (unsigned char) buf2[255] *256); |
|---|
| 454 | buf5.rain1 = buf2[254]; |
|---|
| 455 | buf5.oth2 = buf2[255]; |
|---|
| 456 | //------------------ |
|---|
| 457 | /* |
|---|
| 458 | buf4.delay1 = buf2[272]; |
|---|
| 459 | buf4.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"); |
|---|
| 476 | buf4.hindoor = buf2[273]; |
|---|
| 477 | buf4.tindoor =( (unsigned char) buf2[274] + (unsigned char) buf2[275] *256); |
|---|
| 478 | buf4.houtdoor = buf2[276]; |
|---|
| 479 | buf4.toutdoor =( (unsigned char) buf2[277] + (unsigned char) buf2[278] *256); |
|---|
| 480 | buf4.pressure = (unsigned char) buf2[279] + ( 256*buf2[280]); |
|---|
| 481 | buf4.swind = buf2[281]; |
|---|
| 482 | buf4.swind2 = buf2[282]; |
|---|
| 483 | buf4.oth1 = buf2[283]; |
|---|
| 484 | buf4.rain2 = (unsigned char) buf2[285]; |
|---|
| 485 | buf4.rain =( (unsigned char) buf2[286] + (unsigned char) buf2[287] *256); |
|---|
| 486 | buf4.rain1 = buf2[286]; |
|---|
| 487 | buf4.oth2 = buf2[287]; |
|---|
| 488 | */ |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | printf("Last saved values:\n"); |
|---|
| 493 | unsigned int remain; |
|---|
| 494 | if ( (showall==1) | ( o1==1) ) printf("224:\t\tinterval:\t\t%5d\n", buf4.delay1); |
|---|
| 495 | if ( (showall==1) | ( o2==1) ) printf("225:\t\tindoor humidity\t\t%5d\n", buf4.hindoor); |
|---|
| 496 | if ( (showall==1) | ( o2==1) ) printf("228:\t\toutdoor humidity\t%5d\n", buf4.houtdoor); |
|---|
| 497 | remain = buf4.tindoor%10; |
|---|
| 498 | if ((signed) remain<0) remain = remain * -1; |
|---|
| 499 | if ( (showall==1) | ( o3==1) ) printf("226 227:\tindoor temperature\t%5d.%d\n", buf4.tindoor / 10 ,remain); |
|---|
| 500 | remain = buf4.toutdoor%10; |
|---|
| 501 | |
|---|
| 502 | if ((signed) remain<0) remain = remain * -1; |
|---|
| 503 | if ( (showall==1) | ( o3==1) ) printf("229 230:\toutdoor temperature\t%5d.%d\n", buf4.toutdoor / 10 ,remain); |
|---|
| 504 | remain = buf4.swind%10; |
|---|
| 505 | if ( (showall==1) | ( o4==1) ) printf("233:\t\twind speed\t\t%5d.%d\n", buf4.swind / 10 , remain); |
|---|
| 506 | remain = buf4.swind2%10; |
|---|
| 507 | if ( (showall==1) | ( o4==1) ) printf("234:\t\twind gust\t\t%5d.%d\n", buf4.swind2 / 10 , remain); |
|---|
| 508 | if ( (showall==1) | ( o4==1) ) printf("236:\t\twind direction\t\t%5s\n", buf4.winddirection); |
|---|
| 509 | remain = buf4.rain%10; |
|---|
| 510 | if ( (showall==1) | ( o5==1) ) printf("238 239:\train?\t\t\t%5d.%d\n", buf4.rain / 10 , remain); |
|---|
| 511 | remain = (buf4.rain2)%10; |
|---|
| 512 | if ( (showall==1) | ( o5==1) ) printf("237:\t\train - ??\t\t%5d.%d\n", buf4.rain2 / 10 , remain); |
|---|
| 513 | if ( (showall==1) | ( o5==1) ) printf("248:\t\train1\t\t\t%5d\n", buf4.rain1); |
|---|
| 514 | if ( (showall==1) | ( o5==1) ) printf("\t\train2\t\t\t%5d\n", buf4.rain2); |
|---|
| 515 | if ( (showall==1) | ( o6==1) ) printf("235:\t\tother 1\t\t\t%5d\n", buf4.oth1); |
|---|
| 516 | if ( (showall==1) | ( o6==1) ) printf("239:\t\tother 2\t\t\t%5d\n", buf4.oth2); |
|---|
| 517 | remain = buf4.pressure%10; |
|---|
| 518 | if ( (showall==1) | ( o9==1) ) printf("231 232:\tpressure(hPa)\t\t%5d.%d\n", buf4.pressure / 10 , remain); |
|---|
| 519 | if ( (showall==1) | ( o7==1) ) printf("\t\tCurrent history pos:\t%5x\n", buf4.noffset); |
|---|
| 520 | printf("\n"); |
|---|
| 521 | |
|---|
| 522 | //------------------ |
|---|
| 523 | printf("Current values:\n"); |
|---|
| 524 | if ( (showall==1) | ( o1==1) ) printf("240:\t\tSince last save:\t%5dmin\n", buf5.delay1); |
|---|
| 525 | if ( (showall==1) | ( o2==1) ) printf("241:\t\tindoor humidity\t\t%5d\n", buf5.hindoor); |
|---|
| 526 | if ( (showall==1) | ( o2==1) ) printf("244:\t\toutdoor humidity\t%5d\n", buf5.houtdoor); |
|---|
| 527 | remain = buf5.tindoor%10; |
|---|
| 528 | if ((signed) remain<0) remain = remain * -1; |
|---|
| 529 | if ( (showall==1) | ( o3==1) ) printf("242 243:\tindoor temperature\t%5d.%d\n", buf5.tindoor / 10 ,remain); |
|---|
| 530 | remain = buf5.toutdoor%10; |
|---|
| 531 | if ((signed) remain<0) remain = remain * -1; |
|---|
| 532 | if ( (showall==1) | ( o3==1) ) printf("245 246:\toutdoor temperature\t%5d.%d\n", buf5.toutdoor / 10 ,remain); |
|---|
| 533 | remain = buf5.swind%10; |
|---|
| 534 | if ( (showall==1) | ( o4==1) ) printf("249:\t\twind speed\t\t%5d.%d\n", buf5.swind / 10 , remain); |
|---|
| 535 | remain = buf5.swind2%10; |
|---|
| 536 | if ( (showall==1) | ( o4==1) ) printf("250:\t\twind gust\t\t%5d.%d\n", buf5.swind2 / 10 , remain); |
|---|
| 537 | if ( (showall==1) | ( o4==1) ) printf("252:\t\twind direction\t\t%5s\n", buf5.winddirection); |
|---|
| 538 | remain = buf5.rain%10; |
|---|
| 539 | if ( (showall==1) | ( o5==1) ) printf("254 255:\train? this is always zero %5d.%d\n", buf5.rain / 10 , remain); |
|---|
| 540 | remain = (buf5.rain2)%10; |
|---|
| 541 | if ( (showall==1) | ( o5==1) ) printf("253:\t\train - 24h?\t\t%5d.%d\n", buf5.rain2 / 10 , remain); |
|---|
| 542 | if ( (showall==1) | ( o5==1) ) printf("254:\t\train1\t\t\t%5d\n", buf5.rain1); |
|---|
| 543 | if ( (showall==1) | ( o5==1) ) printf("\t\train2\t\t\t%5d\n", buf5.rain2); |
|---|
| 544 | if ( (showall==1) | ( o6==1) ) printf("251:\t\tother 1\t\t\t%5d\n", buf5.oth1); |
|---|
| 545 | if ( (showall==1) | ( o6==1) ) printf("255:\t\tother 2\t\t\t%5d\n", buf5.oth2); |
|---|
| 546 | remain = buf5.pressure%10; |
|---|
| 547 | if ( (showall==1) | ( o9==1) ) printf("247 248:\tpressure(hPa)\t\t%5d.%d\n", buf5.pressure / 10 , remain); |
|---|
| 548 | if ( (showall==1) | ( o7==1) ) printf("\t\tCurrent history pos:\t%5x\n", buf5.noffset); |
|---|
| 549 | printf("\n"); |
|---|
| 550 | |
|---|
| 551 | if (postprocess==1) { |
|---|
| 552 | printf ("For postprocessing\n"); |
|---|
| 553 | printf ("Interval\t%d min\n", buf5.delay1); |
|---|
| 554 | printf ("Humidity indoor\t%d %%\n", buf5.hindoor); |
|---|
| 555 | printf ("Humidity outdoor\t%d %%\n", buf5.houtdoor); |
|---|
| 556 | if ((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 | }; |
|---|
| 561 | if ((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 | }; |
|---|
| 566 | printf ("Wind speed\t%d.%d m/s\n", buf5.swind / 10, abs(buf5.swind %10)); |
|---|
| 567 | printf ("Wind gust\t%d.%d m/s\n", buf5.swind2 / 10, abs(buf5.swind2 %10)); |
|---|
| 568 | printf ("Wind direction\t%d %s\n", buf2[252], buf5.winddirection); |
|---|
| 569 | if (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 | } |
|---|
| 574 | printf ("Rain total\t%.1f mm\n", (double)(buf5.rain2 + buf5.rain1*256) * 0.3); |
|---|
| 575 | printf ("Pressure air\t%d.%d hPa\n", buf5.pressure / 10, buf5.pressure % 10); |
|---|
| 576 | printf ("\n"); |
|---|
| 577 | } |
|---|
| 578 | //------------------ |
|---|
| 579 | |
|---|
| 580 | _close_readw(); |
|---|
| 581 | return 0; |
|---|
| 582 | } |
|---|