rtl_433 icon indicating copy to clipboard operation
rtl_433 copied to clipboard

Add support for universal fan controller

Open marcelrv opened this issue 10 months ago • 8 comments

Adding support for universal (reversable) fan controller 24V incl the non standard CRC

marcelrv avatar Jan 11 '25 13:01 marcelrv

Thanks. Btw, the "CRC" is not CRC but actually a nibble sum without carry (xor), right?

zuckschwerdt avatar Jan 11 '25 16:01 zuckschwerdt

Thanks. Btw, the "CRC" is not CRC but actually a nibble sum without carry (xor), right?

:-) i directly believe you.... The formula works I know.. sum of each 4 bits xor'ed

It is not documented anywhere, I figured it out from looking to the occurring value... As the rotating counter is only 3 bits I tested out all possible values

If it is not a true crc...Should I rename it to checksum?

marcelrv avatar Jan 11 '25 19:01 marcelrv

Preferably rename crc to chk. The formular crc ^= (b[j / 8] >> (4 * (1 - (j % 8) / 4))) & 0x0F; seems strange, e.g. the first 8 counts b[0] will be shifted, the first 4 times by 4 then 4 times by 0, right? That's a no-op with xor as each two xor's cancel out?

zuckschwerdt avatar Jan 11 '25 21:01 zuckschwerdt

Preferably rename crc to chk. The formular crc ^= (b[j / 8] >> (4 * (1 - (j % 8) / 4))) & 0x0F; seems strange, e.g. the first 8 counts b[0] will be shifted, the first 4 times by 4 then 4 times by 0, right? That's a no-op with xor as each two xor's cancel out?

no, not really, the idea is that you xor eacht time 4 bits. As the array is in bytes, b[j / 8] makes that we 2x select byte 0, 2x byte 1 , etc. The (4 * (1 - (j % 8) / 4))) piece makes we either shift by 4 or we don't shift.. the final & 0F makes we always only take the 4 bits. for the xor' ing

marcelrv avatar Jan 11 '25 21:01 marcelrv

Yes! I Missed the j += 4 :) We usually write this with a byte-wise stepping and fold the nibbles, e.g chk ^= (b[j] >> 4) ^ (b[j] & 0xf), the last incomplete byte then needs a last chk ^= (b[3] >> 4). There is a utility function for this, e.g. int sum = add_nibbles(b, 3) + (b[3] >> 4);

zuckschwerdt avatar Jan 11 '25 22:01 zuckschwerdt

You need to run ./maintainer_update.py to get the build system changes. Commit those changes too.

zuckschwerdt avatar Jan 11 '25 22:01 zuckschwerdt

int sum = add_nibbles(b, 3) + (b[3] >> 4); did not work well, as it does not apply the xor. I added a new function to do that, indeed in a more readable way based on the add_nibbles.

marcelrv avatar Jan 11 '25 23:01 marcelrv

int sum = add_nibbles(b, 3) + (b[3] >> 4); did not work well, as it does not apply the xor.

Oops. Confused myself there. I should have given a different example. Also sum == chk for xor is the same as full xor and then sum == 0 ;)

int sum = xor_bytes(b, 4); // xor message bytes, last byte also has the checksum
sum = (sum >> 4) ^ (sum & 0xf); // fold nibbles
if (sum != 0xa) …

The xor_nibbles is a nice addition. Remove the init, sum full bytes then fold after the loop. Again sorry for the add-with-carry mixup.

zuckschwerdt avatar Jan 11 '25 23:01 zuckschwerdt

Merged with code style updates pushed on top.

zuckschwerdt avatar Oct 17 '25 20:10 zuckschwerdt