3 uint16_t AD_POP(uint8_t bb[BITBUF_COLS], uint8_t bits, uint8_t bit) {
5 uint8_t i, byte_no, bit_no;
9 if (bb[byte_no]&(1<<bit_no)) val = val | (1<<i);
14 static int em1000_callback(bitbuffer_t *bitbuffer) {
16 bitrow_t *bb = bitbuffer->bb;
19 uint8_t bit=18; // preamble
21 char* types[] = {"S", "?", "GZ"};
22 uint8_t checksum_calculated = 0;
25 uint8_t checksum_received;
27 // check and combine the 3 repetitions
28 for (i = 0; i < 14; i++) {
29 if(bb[0][i]==bb[1][i] || bb[0][i]==bb[2][i]) bb_p[i]=bb[0][i];
30 else if(bb[1][i]==bb[2][i]) bb_p[i]=bb[1][i];
34 // read 9 bytes with stopbit ...
35 for (i = 0; i < 9; i++) {
36 dec[i] = AD_POP (bb_p, 8, bit); bit+=8;
37 stopbit=AD_POP (bb_p, 1, bit); bit+=1;
39 // fprintf(stdout, "!stopbit: %i\n", i);
42 checksum_calculated ^= dec[i];
47 checksum_received = AD_POP (bb_p, 8, bit); bit+=8;
48 if (checksum_received != checksum_calculated) {
49 // fprintf(stdout, "checksum_received != checksum_calculated: %d %d\n", checksum_received, checksum_calculated);
53 //for (i = 0; i < bytes; i++) fprintf(stdout, "%02X ", dec[i]); fprintf(stdout, "\n");
55 // based on 15_CUL_EM.pm
56 fprintf(stdout, "Energy sensor event:\n");
57 fprintf(stdout, "protocol = ELV EM 1000, %d bits\n",bitbuffer->bits_per_row[1]);
58 fprintf(stdout, "type = EM 1000-%s\n",dec[0]>=1&&dec[0]<=3?types[dec[0]-1]:"?");
59 fprintf(stdout, "code = %d\n",dec[1]);
60 fprintf(stdout, "seqno = %d\n",dec[2]);
61 fprintf(stdout, "total cnt = %d\n",dec[3]|dec[4]<<8);
62 fprintf(stdout, "current cnt = %d\n",dec[5]|dec[6]<<8);
63 fprintf(stdout, "peak cnt = %d\n",dec[7]|dec[8]<<8);
68 static int ws2000_callback(bitbuffer_t *bitbuffer) {
69 // based on http://www.dc3yc.privat.t-online.de/protocol.htm
70 bitrow_t *bb = bitbuffer->bb;
73 uint8_t bit=11; // preamble
74 char* types[]={"!AS3", "AS2000/ASH2000/S2000/S2001A/S2001IA/ASH2200/S300IA", "!S2000R", "!S2000W", "S2001I/S2001ID", "!S2500H", "!Pyrano", "!KS200/KS300"};
75 uint8_t length[16]={8, 8, 5, 8, 12, 9, 8, 8, 8};
76 uint8_t check_calculated=0, sum_calculated=0;
81 dec[0] = AD_POP (bb[0], 4, bit); bit+=4;
82 stopbit= AD_POP (bb[0], 1, bit); bit+=1;
84 if(debug_output) fprintf(stdout, "!stopbit\n");
87 check_calculated ^= dec[0];
88 sum_calculated += dec[0];
90 // read nibbles with stopbit ...
91 for (i = 1; i <= length[dec[0]]; i++) {
92 dec[i] = AD_POP (bb[0], 4, bit); bit+=4;
93 stopbit= AD_POP (bb[0], 1, bit); bit+=1;
95 if(debug_output) fprintf(stdout, "!stopbit %i\n", bit);
98 check_calculated ^= dec[i];
99 sum_calculated += dec[i];
102 if(debug_output) { for (i = 0; i < nibbles; i++) fprintf(stdout, "%02X ", dec[i]); fprintf(stdout, "\n"); }
104 if (check_calculated) {
105 if(debug_output) fprintf(stdout, "check_calculated (%d) != 0\n", check_calculated);
110 sum_received = AD_POP (bb[0], 4, bit); bit+=4;
113 if (sum_received != sum_calculated) {
114 if(debug_output) fprintf(stdout, "sum_received (%d) != sum_calculated (%d) ", sum_received, sum_calculated);
119 fprintf(stdout, "Weather station sensor event:\n");
120 fprintf(stdout, "protocol = ELV WS 2000, %d bits\n",bitbuffer->bits_per_row[1]);
121 fprintf(stdout, "type (!=ToDo) = %s\n", dec[0]<=7?types[dec[0]]:"?");
122 fprintf(stdout, "code = %d\n", dec[1]&7);
123 fprintf(stdout, "temp = %s%d.%d\n", dec[1]&8?"-":"", dec[4]*10+dec[3], dec[2]);
124 fprintf(stdout, "humidity = %d.%d\n", dec[7]*10+dec[6], dec[5]);
126 fprintf(stdout, "pressure = %d\n", 200+dec[10]*100+dec[9]*10+dec[8]);
132 r_device elv_em1000 = {
133 .name = "ELV EM 1000",
134 .modulation = OOK_PULSE_PPM_RAW,
137 .reset_limit = 30000,
138 .json_callback = &em1000_callback,
143 r_device elv_ws2000 = {
144 .name = "ELV WS 2000",
145 .modulation = OOK_PULSE_PWM_RAW,
146 .short_limit = (854+366)/2, // 0 => 854us, 1 => 366us according to link in top
147 .long_limit = 1000, // no repetitions
148 .reset_limit = 1000, // Longest pause is 854us according to link
149 .json_callback = &ws2000_callback,