decoder.c 791 B

123456789101112131415161718192021222324252627
  1. #include "decoder.h"
  2. #define TAG "SubGhzBlockDecoder"
  3. void subghz_protocol_blocks_add_bit(SubGhzBlockDecoder* decoder, uint8_t bit) {
  4. decoder->decode_data = decoder->decode_data << 1 | bit;
  5. decoder->decode_count_bit++;
  6. }
  7. void subghz_protocol_blocks_add_to_128_bit(
  8. SubGhzBlockDecoder* decoder,
  9. uint8_t bit,
  10. uint64_t* head_64_bit) {
  11. if(++decoder->decode_count_bit > 64) {
  12. (*head_64_bit) = ((*head_64_bit) << 1) | (decoder->decode_data >> 63);
  13. }
  14. decoder->decode_data = decoder->decode_data << 1 | bit;
  15. }
  16. uint8_t subghz_protocol_blocks_get_hash_data(SubGhzBlockDecoder* decoder, size_t len) {
  17. uint8_t hash = 0;
  18. uint8_t* p = (uint8_t*)&decoder->decode_data;
  19. for(size_t i = 0; i < len; i++) {
  20. hash ^= p[i];
  21. }
  22. return hash;
  23. }