mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-30 16:29:12 +00:00
5f6aff2255
- Restrict with 31 bytes length for remote and signal name - Don't stuck for 0 PWM cycle timings - Support timings > 65535 PWM cycles - Fix remote file open error - Add IRDA TX debug redirect - Add remote parse error print, improve parsing, support tabs - Fix stucks with uncorrect RAW signal values, long strings in remote file, etc - Fix HAL signals capturing (save previous read value) - Fix leak in case of failed parsing
91 lines
2.2 KiB
C++
91 lines
2.2 KiB
C++
#include "irda-app-brute-force.h"
|
|
#include "irda/irda-app-file-parser.h"
|
|
|
|
#include <memory>
|
|
#include <m-string.h>
|
|
#include <furi.h>
|
|
#include <file-worker-cpp.h>
|
|
|
|
void IrdaAppBruteForce::add_record(int index, const char* name) {
|
|
records[name].index = index;
|
|
records[name].amount = 0;
|
|
}
|
|
|
|
bool IrdaAppBruteForce::calculate_messages() {
|
|
bool fs_res = false;
|
|
furi_assert(!file_parser);
|
|
|
|
file_parser = std::make_unique<IrdaAppFileParser>();
|
|
fs_res = file_parser->open_irda_file_read(universal_db_filename);
|
|
if(!fs_res) {
|
|
file_parser.reset();
|
|
return false;
|
|
}
|
|
|
|
while(1) {
|
|
auto file_signal = file_parser->read_signal();
|
|
if(!file_signal) break;
|
|
|
|
auto element = records.find(file_signal->name);
|
|
if(element != records.cend()) {
|
|
++element->second.amount;
|
|
}
|
|
}
|
|
|
|
file_parser->close();
|
|
file_parser.reset();
|
|
|
|
return true;
|
|
}
|
|
|
|
void IrdaAppBruteForce::stop_bruteforce() {
|
|
furi_assert((current_record.size()));
|
|
|
|
if(current_record.size()) {
|
|
furi_assert(file_parser);
|
|
current_record.clear();
|
|
file_parser->close();
|
|
file_parser.reset();
|
|
}
|
|
}
|
|
|
|
bool IrdaAppBruteForce::send_next_bruteforce(void) {
|
|
furi_assert(current_record.size());
|
|
furi_assert(file_parser);
|
|
|
|
std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> file_signal;
|
|
|
|
do {
|
|
file_signal = file_parser->read_signal();
|
|
} while(file_signal && current_record.compare(file_signal->name));
|
|
|
|
if(file_signal) {
|
|
file_signal->signal.transmit();
|
|
}
|
|
return !!file_signal;
|
|
}
|
|
|
|
bool IrdaAppBruteForce::start_bruteforce(int index, int& record_amount) {
|
|
bool result = false;
|
|
record_amount = 0;
|
|
|
|
for(const auto& it : records) {
|
|
if(it.second.index == index) {
|
|
record_amount = it.second.amount;
|
|
if(record_amount) {
|
|
current_record = it.first;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(record_amount) {
|
|
file_parser = std::make_unique<IrdaAppFileParser>();
|
|
result = file_parser->open_irda_file_read(universal_db_filename);
|
|
if(!result) {
|
|
file_parser.reset();
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|