Skip to content

Commit

Permalink
Merge pull request #405 from ESurge/420
Browse files Browse the repository at this point in the history
Restored Infrared and RFID CLI
  • Loading branch information
RogueMaster authored Nov 4, 2022
2 parents 6c967bf + 1c68c77 commit 53d5177
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 14 deletions.
10 changes: 1 addition & 9 deletions applications/main/infrared/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@ App(
"gui",
"dialogs",
],
provides=["infrared_start"],
# provides=["infrared_start"],
# icon="A_Infrared_14",
stack_size=3 * 1024,
order=40,
fap_category="Main",
fap_icon="ir_10px.png",
fap_icon_assets="images",
)

App(
appid="infrared_start",
apptype=FlipperAppType.STARTUP,
entry_point="infrared_on_system_start",
requires=["infrared"],
order=20,
)
4 changes: 1 addition & 3 deletions applications/main/lfrfid/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ App(
"gui",
"dialogs",
],
provides=[
"lfrfid_start",
],
# provides=[ "lfrfid_start", ],
# icon="A_125khz_14",
stack_size=2 * 1024,
order=20,
Expand Down
1 change: 0 additions & 1 deletion applications/main/lfrfid/lfrfid_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <gui/view.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <cli/cli.h>
#include <notification/notification_messages.h>

#include <gui/modules/submenu.h>
Expand Down
2 changes: 2 additions & 0 deletions applications/services/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ App(
"loader",
"power",
"ibuttonsrv",
"infraredsrv",
"lfrfidsrv",
"namechangersrv",
],
)
7 changes: 7 additions & 0 deletions applications/services/infraredsrv/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
App(
appid="infraredsrv",
apptype=FlipperAppType.STARTUP,
entry_point="infrared_on_system_start",
requires=["infrared"],
order=20,
)
158 changes: 158 additions & 0 deletions applications/services/infraredsrv/infrared_brute_force.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include "infrared_brute_force.h"

#include <stdlib.h>
#include <m-dict.h>
#include <flipper_format/flipper_format.h>

#include "infrared_signal.h"

typedef struct {
uint32_t index;
uint32_t count;
} InfraredBruteForceRecord;

DICT_DEF2(
InfraredBruteForceRecordDict,
FuriString*,
FURI_STRING_OPLIST,
InfraredBruteForceRecord,
M_POD_OPLIST);

struct InfraredBruteForce {
FlipperFormat* ff;
const char* db_filename;
FuriString* current_record_name;
InfraredSignal* current_signal;
InfraredBruteForceRecordDict_t records;
bool is_started;
};

InfraredBruteForce* infrared_brute_force_alloc() {
InfraredBruteForce* brute_force = malloc(sizeof(InfraredBruteForce));
brute_force->ff = NULL;
brute_force->db_filename = NULL;
brute_force->current_signal = NULL;
brute_force->is_started = false;
brute_force->current_record_name = furi_string_alloc();
InfraredBruteForceRecordDict_init(brute_force->records);
return brute_force;
}

void infrared_brute_force_clear_records(InfraredBruteForce* brute_force) {
furi_assert(!brute_force->is_started);
InfraredBruteForceRecordDict_reset(brute_force->records);
}

void infrared_brute_force_free(InfraredBruteForce* brute_force) {
furi_assert(!brute_force->is_started);
InfraredBruteForceRecordDict_clear(brute_force->records);
furi_string_free(brute_force->current_record_name);
free(brute_force);
}

void infrared_brute_force_set_db_filename(InfraredBruteForce* brute_force, const char* db_filename) {
furi_assert(!brute_force->is_started);
brute_force->db_filename = db_filename;
}

bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) {
furi_assert(!brute_force->is_started);
furi_assert(brute_force->db_filename);
bool success = false;

Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);

success = flipper_format_buffered_file_open_existing(ff, brute_force->db_filename);
if(success) {
FuriString* signal_name;
signal_name = furi_string_alloc();
while(flipper_format_read_string(ff, "name", signal_name)) {
InfraredBruteForceRecord* record =
InfraredBruteForceRecordDict_get(brute_force->records, signal_name);
if(record) {
++(record->count);
}
}
furi_string_free(signal_name);
}

flipper_format_free(ff);
furi_record_close(RECORD_STORAGE);
return success;
}

bool infrared_brute_force_start(
InfraredBruteForce* brute_force,
uint32_t index,
uint32_t* record_count) {
furi_assert(!brute_force->is_started);
bool success = false;
*record_count = 0;

InfraredBruteForceRecordDict_it_t it;
for(InfraredBruteForceRecordDict_it(it, brute_force->records);
!InfraredBruteForceRecordDict_end_p(it);
InfraredBruteForceRecordDict_next(it)) {
const InfraredBruteForceRecordDict_itref_t* record = InfraredBruteForceRecordDict_cref(it);
if(record->value.index == index) {
*record_count = record->value.count;
if(*record_count) {
furi_string_set(brute_force->current_record_name, record->key);
}
break;
}
}

if(*record_count) {
Storage* storage = furi_record_open(RECORD_STORAGE);
brute_force->ff = flipper_format_buffered_file_alloc(storage);
brute_force->current_signal = infrared_signal_alloc();
brute_force->is_started = true;
success =
flipper_format_buffered_file_open_existing(brute_force->ff, brute_force->db_filename);
if(!success) infrared_brute_force_stop(brute_force);
}
return success;
}

bool infrared_brute_force_is_started(InfraredBruteForce* brute_force) {
return brute_force->is_started;
}

void infrared_brute_force_stop(InfraredBruteForce* brute_force) {
furi_assert(brute_force->is_started);
furi_string_reset(brute_force->current_record_name);
infrared_signal_free(brute_force->current_signal);
flipper_format_free(brute_force->ff);
brute_force->current_signal = NULL;
brute_force->ff = NULL;
brute_force->is_started = false;
furi_record_close(RECORD_STORAGE);
}

bool infrared_brute_force_send_next(InfraredBruteForce* brute_force) {
furi_assert(brute_force->is_started);
const bool success = infrared_signal_search_and_read(
brute_force->current_signal, brute_force->ff, brute_force->current_record_name);
if(success) {
infrared_signal_transmit(brute_force->current_signal);
}
return success;
}

void infrared_brute_force_add_record(
InfraredBruteForce* brute_force,
uint32_t index,
const char* name) {
InfraredBruteForceRecord value = {.index = index, .count = 0};
FuriString* key;
key = furi_string_alloc_set(name);
InfraredBruteForceRecordDict_set_at(brute_force->records, key, value);
furi_string_free(key);
}

void infrared_brute_force_reset(InfraredBruteForce* brute_force) {
furi_assert(!brute_force->is_started);
InfraredBruteForceRecordDict_reset(brute_force->records);
}
23 changes: 23 additions & 0 deletions applications/services/infraredsrv/infrared_brute_force.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

typedef struct InfraredBruteForce InfraredBruteForce;

InfraredBruteForce* infrared_brute_force_alloc();
void infrared_brute_force_free(InfraredBruteForce* brute_force);
void infrared_brute_force_set_db_filename(InfraredBruteForce* brute_force, const char* db_filename);
bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force);
bool infrared_brute_force_start(
InfraredBruteForce* brute_force,
uint32_t index,
uint32_t* record_count);
bool infrared_brute_force_is_started(InfraredBruteForce* brute_force);
void infrared_brute_force_stop(InfraredBruteForce* brute_force);
bool infrared_brute_force_send_next(InfraredBruteForce* brute_force);
void infrared_brute_force_clear_records(InfraredBruteForce* brute_force);
void infrared_brute_force_add_record(
InfraredBruteForce* brute_force,
uint32_t index,
const char* name);
File renamed without changes.
Loading

0 comments on commit 53d5177

Please sign in to comment.