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(uint8_t bb[BITBUF_ROWS][BITBUF_COLS],int16_t bits_per_row[BITBUF_ROWS]) {
18 uint8_t bit=18; // preamble
20 char* types[] = {"S", "?", "GZ"};
21 uint8_t checksum_calculated = 0;
24 uint8_t checksum_received;
26 // check and combine the 3 repetitions
27 for (i = 0; i < 14; i++) {
28 if(bb[0][i]==bb[1][i] || bb[0][i]==bb[2][i]) bb_p[i]=bb[0][i];
29 else if(bb[1][i]==bb[2][i]) bb_p[i]=bb[1][i];
33 // read 9 bytes with stopbit ...
34 for (i = 0; i < 9; i++) {
35 dec[i] = AD_POP (bb_p, 8, bit); bit+=8;
36 stopbit=AD_POP (bb_p, 1, bit); bit+=1;
38 // fprintf(stderr, "!stopbit: %i\n", i);
41 checksum_calculated ^= dec[i];
46 checksum_received = AD_POP (bb_p, 8, bit); bit+=8;
47 if (checksum_received != checksum_calculated) {
48 // fprintf(stderr, "checksum_received != checksum_calculated: %d %d\n", checksum_received, checksum_calculated);
52 //for (i = 0; i < bytes; i++) fprintf(stderr, "%02X ", dec[i]); fprintf(stderr, "\n");
54 // based on 15_CUL_EM.pm
55 fprintf(stdout, "SENSOR:TYPE=ELV_ENERGY,");
56 fprintf(stdout, "MODEL=EM1000-%s,",dec[0]>=1&&dec[0]<=3?types[dec[0]-1]:"?");
57 fprintf(stdout, "ID=%d,",dec[1]);
58 fprintf(stdout, "SEQNO=%d,",dec[2]);
59 fprintf(stdout, "TOTAL=%d,",dec[3]|dec[4]<<8);
60 fprintf(stdout, "CURRENT=%d,",dec[5]|dec[6]<<8);
61 fprintf(stdout, "PEAK=%d\n",dec[7]|dec[8]<<8);
66 static int ws2000_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS],int16_t bits_per_row[BITBUF_ROWS]) {
67 // based on http://www.dc3yc.privat.t-online.de/protocol.htm
70 uint8_t bit=11; // preamble
71 char* types[]={"!AS3", "AS2000/ASH2000/S2000/S2001A/S2001IA/ASH2200/S300IA", "!S2000R", "!S2000W", "S2001I/S2001ID", "!S2500H", "!Pyrano", "!KS200/KS300"};
72 uint8_t check_calculated=0, sum_calculated=0;
77 dec[0] = AD_POP (bb[0], 4, bit); bit+=4;
78 stopbit= AD_POP (bb[0], 1, bit); bit+=1;
80 //fprintf(stderr, "!stopbit\n");
83 check_calculated ^= dec[0];
84 sum_calculated += dec[0];
86 // read nibbles with stopbit ...
87 for (i = 1; i <= (dec[0]==4?12:8); i++) {
88 dec[i] = AD_POP (bb[0], 4, bit); bit+=4;
89 stopbit= AD_POP (bb[0], 1, bit); bit+=1;
91 //fprintf(stderr, "!stopbit %i\n", i);
94 check_calculated ^= dec[i];
95 sum_calculated += dec[i];
99 if (check_calculated) {
100 //fprintf(stderr, "check_calculated (%d) != 0\n", check_calculated);
105 sum_received = AD_POP (bb[0], 4, bit); bit+=4;
108 if (sum_received != sum_calculated) {
109 //fprintf(stderr, "sum_received (%d) != sum_calculated (%d) ", sum_received, sum_calculated);
113 //for (i = 0; i < nibbles; i++) fprintf(stderr, "%02X ", dec[i]); fprintf(stderr, "\n");
115 fprintf(stdout, "SENSOR:TYPE=ELV_WEATHER,");
116 fprintf(stdout, "TYPE=%s,", dec[0]<=7?types[dec[0]]:"?");
117 fprintf(stdout, "ID= %d,", dec[1]&7);
119 fprintf(stdout, "PRESSURE=%d,", 200+dec[10]*100+dec[9]*10+dec[8]);
121 fprintf(stdout, "TEMPERATURE=%s%d.%d,", dec[1]&8?"-":"", dec[4]*10+dec[3], dec[2]);
122 fprintf(stdout, "HUMIDITY=%d.%d\n", dec[7]*10+dec[6], dec[5]);
127 r_device elv_em1000 = {
129 /* .name = */ "ELV EM 1000",
130 /* .modulation = */ OOK_PWM_D,
131 /* .short_limit = */ 750/4,
132 /* .long_limit = */ 7250/4,
133 /* .reset_limit = */ 30000/4,
134 /* .json_callback = */ &em1000_callback,
137 r_device elv_ws2000 = {
139 /* .name = */ "ELV WS 2000",
140 /* .modulation = */ OOK_PWM_D,
141 /* .short_limit = */ (602+(1155-602)/2)/4,
142 /* .long_limit = */ ((1755635-1655517)/2)/4, // no repetitions
143 /* .reset_limit = */ ((1755635-1655517)*2)/4,
144 /* .json_callback = */ &ws2000_callback,