Bugfixes
[rtl-433.git] / src / devices / inovalley-kw9015b.c
1 #include "rtl_433.h"
2 #include "util.h"
3 /* Inovalley kw9015b rain and Temperature weather station
4  *
5  * Copyright (C) 2015 Alexandre Coffignal
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11
12 extern uint8_t reverse8(uint8_t x);
13
14 static int kw9015b_callback(bitbuffer_t *bitbuffer) {
15         bitrow_t *bb = bitbuffer->bb;
16
17
18         int i,iRain,device;
19         unsigned char chksum;
20         float fTemp;
21         char buf[255];
22         for(i=0;i<5;i++){
23                 if(bitbuffer->bits_per_row[i]!=36){
24                         /*10 24 bits frame*/
25                 }else{
26                         //AAAAAAAA BBBBBBBB BBBBBBBB CCCCCCCC DDDD
27                         //A : ID
28                         //B : Temp
29                         //C : Rain
30                         //D : checksum
31
32                         device=reverse8(bb[i][0]);
33                         fTemp=(float)((signed short)(reverse8(bb[i][2])*256+reverse8(bb[i][1]))) /160;
34                         iRain = reverse8(bb[i][3]);
35                         chksum=((reverse8(bb[i][0])>>4)+(reverse8(bb[i][0])&0x0F)+
36                                 (reverse8(bb[i][1])>>4)+(reverse8(bb[i][1])&0x0F)+
37                                 (reverse8(bb[i][2])>>4)+(reverse8(bb[i][2])&0x0F)+
38                                 (reverse8(bb[i][3])>>4)+(reverse8(bb[i][3])&0x0F));
39
40                         if( (chksum&0x0F) == ( reverse8(bb[i][4]) &0x0F)){
41                                 fprintf(stdout, "\nSensor        = Temperature and rain event\n");
42                                 fprintf(stdout, "Device        = %d\n", device);
43                                 fprintf(stdout, "Temp          = %f\n",fTemp);
44                                 fprintf(stdout, "Rain          = %d\n",iRain);
45                                 fprintf(stdout, "checksum      = %02x==%02x\n",chksum&0xF,reverse8(bb[i][4]));
46                                 fprintf(stdout, "Received Data = %02X %02X %02X %02X %02X\n",
47                                 reverse8(bb[i][0]),
48                                 reverse8(bb[i][1]),
49                                 reverse8(bb[i][2]),
50                                 reverse8(bb[i][3]),
51                                 reverse8(bb[i][4]));
52
53
54                                 return 1;
55                         }
56                 }
57         }
58
59
60         return 0;
61
62 }
63
64 r_device kw9015b = {
65   .name          = "Inovalley kw9015b rain and Temperature weather station",
66   .modulation    = OOK_PULSE_PPM_RAW,
67   .short_limit   = 3500,
68   .long_limit    = 4800,
69   .reset_limit   = 10000,
70   .json_callback = &kw9015b_callback,
71   .disabled      = 1,
72   .demod_arg     = 0,
73 };