unleashed-firmware/applications/lfrfid/helpers/decoder-hid26.cpp

99 lines
2.6 KiB
C++
Raw Normal View History

Low frequency RFID app [Read stage] (#385) * App Lfrfid: init * HAL-resources: add external gpios * HAL-pwm: fix frequency calculation * App LFRFID: generic manchester decoder * App LFRFID: em-marine decoder * App iButton: fix dwt timing acquire * App LFRFID: rfid reader * App LFRFID: temporary read keys on read scene * App LFRFID: remove atomic bool init. * App LFRFID: add *.c to build * App LFRFID: unstable HID decoder * App LFRFID: HID-26 reading * HAL OS: disable sleep * App LFRFID: HID-26 reader: remove debug * App LFRFID: static data decoder-analyzer * App LFRFID: very raw Indala decoder * App LFRFID: multiprotocol reader * App LFRFID: more reliable HID decoder * App LFRFID: syntax fix * App LFRFID: simple read scene * Gui: force redraw on screen stream connect * HAL-OS: allow sleep * App LFRFID: notify api, tune view, tune scene * App LFRFID: simple rfid emulator * App LFRFID: more scenes, more reliable EM decoder. * App LFRFID: format fix * App LFRFID: warning fix * Api-hal-resources: add rfid pins, rename external pins * App LFRFID: remove unused emulator * App LFRFID: use new gpio hal api * App accessor: use new ext gpio name * App LFRFID: remove unused emulator * App LFRFID: remove debug gpio * Api-hal-resources: alternate functions init * Api-hal-rfid: new api * Api-hal-ibutton: new api * Api-hal: new headers * App LFRFID: use new api in reader subroutines * App LFRFID: use new api in emulator subroutines * App LFRFID: remove old app * App LFRFID, App iButton: fix memleak * Api-hal-rfid: comments * App LFRFID: pulse joiner helper, it combines pulses of different polarity into one pulse suitable for a timer * App LFRFID: pulse joiner, now can accept only ne pulse * App LFRFID: pulse joiner, fixes * App LFRFID: EM encoder and emulation * App LFRFID: format fixes * App LFRFID: emmarine encoder cleanup * App LFRFID: HID Encoder blank * App LFRFID: Indala Encoder blank
2021-05-04 16:21:16 +03:00
#include "decoder-hid26.h"
#include <api-hal.h>
constexpr uint32_t clocks_in_us = 64;
constexpr uint32_t jitter_time_us = 20;
constexpr uint32_t min_time_us = 64;
constexpr uint32_t max_time_us = 80;
constexpr uint32_t min_time = (min_time_us - jitter_time_us) * clocks_in_us;
constexpr uint32_t mid_time = ((max_time_us - min_time_us) / 2 + min_time_us) * clocks_in_us;
constexpr uint32_t max_time = (max_time_us + jitter_time_us) * clocks_in_us;
bool DecoderHID26::read(uint8_t* data, uint8_t data_size) {
bool result = false;
furi_assert(data_size >= 3);
if(ready) {
result = true;
hid.decode(
reinterpret_cast<const uint8_t*>(&stored_data), sizeof(uint32_t) * 3, data, data_size);
Low frequency RFID app [Read stage] (#385) * App Lfrfid: init * HAL-resources: add external gpios * HAL-pwm: fix frequency calculation * App LFRFID: generic manchester decoder * App LFRFID: em-marine decoder * App iButton: fix dwt timing acquire * App LFRFID: rfid reader * App LFRFID: temporary read keys on read scene * App LFRFID: remove atomic bool init. * App LFRFID: add *.c to build * App LFRFID: unstable HID decoder * App LFRFID: HID-26 reading * HAL OS: disable sleep * App LFRFID: HID-26 reader: remove debug * App LFRFID: static data decoder-analyzer * App LFRFID: very raw Indala decoder * App LFRFID: multiprotocol reader * App LFRFID: more reliable HID decoder * App LFRFID: syntax fix * App LFRFID: simple read scene * Gui: force redraw on screen stream connect * HAL-OS: allow sleep * App LFRFID: notify api, tune view, tune scene * App LFRFID: simple rfid emulator * App LFRFID: more scenes, more reliable EM decoder. * App LFRFID: format fix * App LFRFID: warning fix * Api-hal-resources: add rfid pins, rename external pins * App LFRFID: remove unused emulator * App LFRFID: use new gpio hal api * App accessor: use new ext gpio name * App LFRFID: remove unused emulator * App LFRFID: remove debug gpio * Api-hal-resources: alternate functions init * Api-hal-rfid: new api * Api-hal-ibutton: new api * Api-hal: new headers * App LFRFID: use new api in reader subroutines * App LFRFID: use new api in emulator subroutines * App LFRFID: remove old app * App LFRFID, App iButton: fix memleak * Api-hal-rfid: comments * App LFRFID: pulse joiner helper, it combines pulses of different polarity into one pulse suitable for a timer * App LFRFID: pulse joiner, now can accept only ne pulse * App LFRFID: pulse joiner, fixes * App LFRFID: EM encoder and emulation * App LFRFID: format fixes * App LFRFID: emmarine encoder cleanup * App LFRFID: HID Encoder blank * App LFRFID: Indala Encoder blank
2021-05-04 16:21:16 +03:00
ready = false;
}
return result;
}
void DecoderHID26::process_front(bool polarity, uint32_t time) {
if(ready) return;
if(polarity == true) {
last_pulse_time = time;
} else {
last_pulse_time += time;
if(last_pulse_time > min_time && last_pulse_time < max_time) {
bool pulse;
if(last_pulse_time < mid_time) {
// 6 pulses
pulse = false;
} else {
// 5 pulses
pulse = true;
}
if(last_pulse == pulse) {
pulse_count++;
if(pulse) {
if(pulse_count > 4) {
pulse_count = 0;
store_data(1);
}
} else {
if(pulse_count > 5) {
pulse_count = 0;
store_data(0);
}
}
} else {
if(last_pulse) {
if(pulse_count > 2) {
store_data(1);
}
} else {
if(pulse_count > 3) {
store_data(0);
}
}
pulse_count = 0;
last_pulse = pulse;
}
}
}
}
DecoderHID26::DecoderHID26() {
reset_state();
}
void DecoderHID26::store_data(bool data) {
stored_data[0] = (stored_data[0] << 1) | ((stored_data[1] >> 31) & 1);
stored_data[1] = (stored_data[1] << 1) | ((stored_data[2] >> 31) & 1);
stored_data[2] = (stored_data[2] << 1) | data;
if(hid.can_be_decoded(reinterpret_cast<const uint8_t*>(&stored_data), sizeof(uint32_t) * 3)) {
ready = true;
Low frequency RFID app [Read stage] (#385) * App Lfrfid: init * HAL-resources: add external gpios * HAL-pwm: fix frequency calculation * App LFRFID: generic manchester decoder * App LFRFID: em-marine decoder * App iButton: fix dwt timing acquire * App LFRFID: rfid reader * App LFRFID: temporary read keys on read scene * App LFRFID: remove atomic bool init. * App LFRFID: add *.c to build * App LFRFID: unstable HID decoder * App LFRFID: HID-26 reading * HAL OS: disable sleep * App LFRFID: HID-26 reader: remove debug * App LFRFID: static data decoder-analyzer * App LFRFID: very raw Indala decoder * App LFRFID: multiprotocol reader * App LFRFID: more reliable HID decoder * App LFRFID: syntax fix * App LFRFID: simple read scene * Gui: force redraw on screen stream connect * HAL-OS: allow sleep * App LFRFID: notify api, tune view, tune scene * App LFRFID: simple rfid emulator * App LFRFID: more scenes, more reliable EM decoder. * App LFRFID: format fix * App LFRFID: warning fix * Api-hal-resources: add rfid pins, rename external pins * App LFRFID: remove unused emulator * App LFRFID: use new gpio hal api * App accessor: use new ext gpio name * App LFRFID: remove unused emulator * App LFRFID: remove debug gpio * Api-hal-resources: alternate functions init * Api-hal-rfid: new api * Api-hal-ibutton: new api * Api-hal: new headers * App LFRFID: use new api in reader subroutines * App LFRFID: use new api in emulator subroutines * App LFRFID: remove old app * App LFRFID, App iButton: fix memleak * Api-hal-rfid: comments * App LFRFID: pulse joiner helper, it combines pulses of different polarity into one pulse suitable for a timer * App LFRFID: pulse joiner, now can accept only ne pulse * App LFRFID: pulse joiner, fixes * App LFRFID: EM encoder and emulation * App LFRFID: format fixes * App LFRFID: emmarine encoder cleanup * App LFRFID: HID Encoder blank * App LFRFID: Indala Encoder blank
2021-05-04 16:21:16 +03:00
}
}
void DecoderHID26::reset_state() {
last_pulse = false;
pulse_count = 0;
ready = false;
last_pulse_time = 0;
}