2022-01-05 19:10:18 +03:00
|
|
|
#include "rfid_timer_emulator.h"
|
2021-05-04 16:21:16 +03:00
|
|
|
|
|
|
|
RfidTimerEmulator::RfidTimerEmulator() {
|
|
|
|
}
|
|
|
|
|
|
|
|
RfidTimerEmulator::~RfidTimerEmulator() {
|
2021-06-10 14:53:59 +03:00
|
|
|
std::map<LfrfidKeyType, EncoderGeneric*>::iterator it;
|
2021-05-04 16:21:16 +03:00
|
|
|
|
|
|
|
for(it = encoders.begin(); it != encoders.end(); ++it) {
|
|
|
|
delete it->second;
|
|
|
|
}
|
2021-11-01 16:11:25 +03:00
|
|
|
|
|
|
|
encoders.clear();
|
2021-05-04 16:21:16 +03:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:53:59 +03:00
|
|
|
void RfidTimerEmulator::start(LfrfidKeyType type, const uint8_t* data, uint8_t data_size) {
|
2021-05-04 16:21:16 +03:00
|
|
|
if(encoders.count(type)) {
|
|
|
|
current_encoder = encoders.find(type)->second;
|
|
|
|
|
2021-06-28 17:42:30 +03:00
|
|
|
if(data_size >= lfrfid_key_get_type_data_count(type)) {
|
2021-06-10 14:53:59 +03:00
|
|
|
current_encoder->init(data, data_size);
|
2021-05-04 16:21:16 +03:00
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_rfid_tim_emulate(125000);
|
|
|
|
furi_hal_rfid_pins_emulate();
|
2021-05-04 16:21:16 +03:00
|
|
|
|
2022-03-26 01:56:18 +03:00
|
|
|
furi_hal_rfid_tim_emulate_start(RfidTimerEmulator::timer_update_callback, this);
|
2021-06-10 14:53:59 +03:00
|
|
|
}
|
2021-05-04 16:21:16 +03:00
|
|
|
} else {
|
|
|
|
// not found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RfidTimerEmulator::stop() {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_rfid_tim_emulate_stop();
|
|
|
|
furi_hal_rfid_tim_reset();
|
|
|
|
furi_hal_rfid_pins_reset();
|
2021-05-04 16:21:16 +03:00
|
|
|
}
|
|
|
|
|
2022-03-26 01:56:18 +03:00
|
|
|
void RfidTimerEmulator::timer_update_callback(void* ctx) {
|
2021-05-04 16:21:16 +03:00
|
|
|
RfidTimerEmulator* _this = static_cast<RfidTimerEmulator*>(ctx);
|
|
|
|
|
2022-03-26 01:56:18 +03:00
|
|
|
bool result;
|
|
|
|
bool polarity;
|
|
|
|
uint16_t period;
|
|
|
|
uint16_t pulse;
|
2021-05-04 16:21:16 +03:00
|
|
|
|
2022-03-26 01:56:18 +03:00
|
|
|
do {
|
|
|
|
_this->current_encoder->get_next(&polarity, &period, &pulse);
|
|
|
|
result = _this->pulse_joiner.push_pulse(polarity, period, pulse);
|
|
|
|
} while(result == false);
|
2021-05-04 16:21:16 +03:00
|
|
|
|
2022-03-26 01:56:18 +03:00
|
|
|
_this->pulse_joiner.pop_pulse(&period, &pulse);
|
2021-05-04 16:21:16 +03:00
|
|
|
|
2022-03-26 01:56:18 +03:00
|
|
|
furi_hal_rfid_set_emulate_period(period - 1);
|
|
|
|
furi_hal_rfid_set_emulate_pulse(pulse);
|
2021-05-04 16:21:16 +03:00
|
|
|
}
|