flipperzero-firmware/lib/subghz/blocks/encoder.c
Skorpionm 163be139eb
SubGhz: add protocol BinRAW (binarization of data quantized by the minimum correlated duration) (#2322)
* SubGhz: add protocol DataRAW (binarization of data quantized by the minimum correlated duration)
* SubGhz: fix name history
* SubGhz: add encoder Data_RAW protocol
* SubGhz: decreasing the size of the LevelDuration structure
* SubGhz: history, added check that there is free RAM
* SubGhz: checking for free memory, support to pass without gap
* SubGhz: add running average to average the result, auto cut noise at the end of a burst
* SubGhz: support for repeating sequences
* SubGhz: fix secplus_v2 decoder
* SubGhz: bin_RAW fix add history
* SubGhz: add debug
* SubGhz: debug refactoring
* FURI_LOG: add FURI_LOG_RAW_x formatted string output like printf
* SubGhz: fix new FURI_LOG metod
* FURI_LOG: fix unit test
* SubGhz: add enable/disable BinRAW protocol decoding
* SubGhz: fix PVS
* SubGhz: forcibly turn off the speaker when exiting SubGhz
* SubGhz: adaptive adjustment to the noise level

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2023-02-09 13:48:06 +09:00

59 lines
1.9 KiB
C

#include "encoder.h"
#include "math.h"
#include <core/check.h>
#include "furi.h"
#define TAG "SubGhzBlockEncoder"
void subghz_protocol_blocks_set_bit_array(
bool bit_value,
uint8_t data_array[],
size_t set_index_bit,
size_t max_size_array) {
furi_assert(set_index_bit < max_size_array * 8);
bit_write(data_array[set_index_bit >> 3], 7 - (set_index_bit & 0x7), bit_value);
}
bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_index_bit) {
return bit_read(data_array[read_index_bit >> 3], 7 - (read_index_bit & 0x7));
}
size_t subghz_protocol_blocks_get_upload_from_bit_array(
uint8_t data_array[],
size_t count_bit_data_array,
LevelDuration* upload,
size_t max_size_upload,
uint32_t duration_bit,
SubGhzProtocolBlockAlignBit align_bit) {
size_t bias_bit = 0;
size_t size_upload = 0;
uint32_t duration = duration_bit;
if(align_bit == SubGhzProtocolBlockAlignBitRight) {
if(count_bit_data_array & 0x7) {
bias_bit = 8 - (count_bit_data_array & 0x7);
}
}
size_t index_bit = bias_bit;
bool last_bit = subghz_protocol_blocks_get_bit_array(data_array, index_bit++);
for(size_t i = 1 + bias_bit; i < count_bit_data_array + bias_bit; i++) {
if(last_bit == subghz_protocol_blocks_get_bit_array(data_array, index_bit)) {
duration += duration_bit;
} else {
if(size_upload > max_size_upload) {
furi_crash("SubGhz: Encoder buffer overflow");
}
upload[size_upload++] = level_duration_make(
subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration);
last_bit = !last_bit;
duration = duration_bit;
}
index_bit++;
}
upload[size_upload++] = level_duration_make(
subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration);
return size_upload;
}