5 static int newkaku_callback(bitbuffer_t *bitbuffer) {
6 /* Two bits map to 2 states, 0 1 -> 0 and 1 1 -> 1 */
7 /* Status bit can be 1 1 -> 1 which indicates DIM value. 4 extra bits are present with value */
8 /*start pulse: 1T high, 10.44T low */
10 /*- 1 bit: group bit*/
11 /*- 1 bit: Status bit on/off/[dim]*/
13 /*- [4 bit: dim level. Present if [dim] is used, but might be present anyway...]*/
14 /*- stop pulse: 1T high, 40T low */
16 bitrow_t *bb = bitbuffer->bb;
24 char *group_call, *command, *dim;
25 char time_str[LOCAL_TIME_BUFLEN];
26 local_time_str(0, time_str);
28 if (bb[0][0] == 0xac || bb[0][0] == 0xb2) {//allways starts with ac or b2
29 // first bit is from startbit sequence, not part of payload!
30 // check protocol if value is 10 or 01, else stop processing as it is no vallid KAKU packet!
31 //get id=24bits, remember 1st 1 bit = startbit, no payload!
32 for (packet = 0; packet < 6; packet++) {//get first part kakuid
33 tmp = bb[0][packet] << 1;
34 if ((bb[0][packet + 1]&(1 << 7)) != 0) {// if set add bit to current
38 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process bitstream, check protocol!
40 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
45 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
49 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
53 tmp = bb[0][6] << 1; //Get last part ID
54 for (bitcount = 0; bitcount < 4; bitcount += 2) {
55 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
60 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
65 return 0; //00 and 11 indicates packet error. no valid packet! do exit
70 if ((bb[0][8]&(1 << 7)) != 0) {// if set add bit to current
73 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process bitstream, check protocol!
74 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
79 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
83 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
86 group_call = (((bb[0][6] & (0x04)) == 0x04)&((bb[0][6] & (0x02)) == 0)) ? "Yes" : "No";
87 command = (((bb[0][6] & (0x01)) == 0x01)&((bb[0][7] & (0x80)) == 0)) ? "On" : "Off";
88 if (((bb[0][6] & (0x01)) == 0x01)&((bb[0][7] & (0x80)) == 0x80)) {//11 indicates DIM command, 4 extra bits indicate DIM value
90 tmp = bb[0][8] << 1; // get packet, loose first bit
92 if ((bb[0][9]&(1 << 7)) != 0) {// if bit is set Add to current packet
94 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process last bit outside
95 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
100 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
104 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
112 data = data_make("time", "", DATA_STRING, time_str,
113 "model", "", DATA_STRING, "KlikAanKlikUit Wireless Switch",
114 "id", "", DATA_INT, kakuid,
115 "unit", "Unit", DATA_INT, unit,
116 "group_call", "Group Call", DATA_STRING, group_call,
117 "command", "Command", DATA_STRING, command,
118 "dim", "Dim", DATA_STRING, dim,
119 "dim_value", "Dim Value", DATA_INT, dv,
121 data_acquired_handler(data);
128 static char *output_fields[] = {
141 .name = "KlikAanKlikUit Wireless Switch",
142 .modulation = OOK_PULSE_PPM_RAW,
145 .reset_limit = 10000,
146 .json_callback = &newkaku_callback,
149 .fields = output_fields