flipperzero-firmware/applications/lfrfid/helpers/decoder_indala.cpp
hedger 4d6b170769
[FL-2520] FW build with -Wextra (#1185)
* Fixing compiler warnings with -Wextra
* More warnings suppression, WIP
* Even more warning fixes
* Added new lines at end of text files.
* Padding fix
* Additional fixes to warnings on different build configurations; added -Wextra to default build pipeline
* Fixes for Secplus v1
* -additional warnings
* +-Wredundant-decls fixes
* FuriHal: print stack overflow task name in console
* FuriHal: add missing include

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-05-06 16:37:10 +03:00

77 lines
1.8 KiB
C++

#include "decoder_indala.h"
#include <furi_hal.h>
constexpr uint32_t clocks_in_us = 64;
constexpr uint32_t us_per_bit = 255;
bool DecoderIndala::read(uint8_t* data, uint8_t data_size) {
bool result = false;
if(ready) {
result = true;
if(cursed_data_valid) {
indala.decode(
reinterpret_cast<const uint8_t*>(&cursed_raw_data),
sizeof(uint64_t),
data,
data_size);
} else {
indala.decode(
reinterpret_cast<const uint8_t*>(&raw_data), sizeof(uint64_t), data, data_size);
}
reset_state();
}
return result;
}
void DecoderIndala::process_front(bool polarity, uint32_t time) {
if(ready) return;
process_internal(polarity, time, &raw_data);
if(ready) return;
if(polarity) {
time = time + 110;
} else {
time = time - 110;
}
process_internal(!polarity, time, &cursed_raw_data);
if(ready) {
cursed_data_valid = true;
}
}
void DecoderIndala::process_internal(bool polarity, uint32_t time, uint64_t* data) {
time /= clocks_in_us;
time += (us_per_bit / 2);
uint32_t bit_count = (time / us_per_bit);
if(bit_count < 64) {
for(uint32_t i = 0; i < bit_count; i++) {
*data = (*data << 1) | polarity;
if((*data >> 32) == 0xa0000000ULL) {
if(indala.can_be_decoded(
reinterpret_cast<const uint8_t*>(data), sizeof(uint64_t))) {
ready = true;
break;
}
}
}
}
}
DecoderIndala::DecoderIndala() {
reset_state();
}
void DecoderIndala::reset_state() {
raw_data = 0;
cursed_raw_data = 0;
ready = false;
cursed_data_valid = false;
}