Skip to content

Commit e4a1dd8

Browse files
committed
first commit
0 parents  commit e4a1dd8

21 files changed

+913
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Simple On/Off Remote
2+
## Sub-GHz
3+
4+
Main Display
5+
* Saved device 1
6+
* Saved device 2
7+
* Manage Devices
8+
9+
Saved device View
10+
* ON
11+
* OFF
12+
* other
13+
14+
15+
## File System Layout
16+
Inside the data folder, create sub-folders per device. Inside each of the device folders, store the raw files that contain the sub-ghz data, etc.
17+
18+
The device order list, and button list, is based on the sorted file order. This is enforced by the following naming convention:
19+
20+
```
21+
/data_folder
22+
- 00_Device_1
23+
- 01_Device_2
24+
- 00_Button_1.sub
25+
- 01_Button_2.sub
26+
```
27+
28+
The first two digits and underscore will be stripped before display. Additionally, underscores in folder and filenames will be replaced with spaces.
29+

actions/action.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
#include "app_state.h"
3+
#include "item.h"
4+
#include "action_i.h"
5+
6+
void action_tx(void* context, Item* item) {
7+
FURI_LOG_I(TAG, "action_run: %s : %s", furi_string_get_cstr(item->name), item->ext);
8+
9+
if(!strcmp(item->ext, ".sub")) {
10+
action_subghz_tx(context, item);
11+
} else if(!strcmp(item->ext, ".ir")) {
12+
action_ir_tx(context, item);
13+
} else if(!strcmp(item->ext, ".rfid")) {
14+
action_rfid_tx(context, item);
15+
} else {
16+
FURI_LOG_E(TAG, "Unknown item type! %s", item->ext);
17+
}
18+
}

actions/action.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
struct Item;
4+
5+
void action_tx(void* context, Item* item);

actions/action_i.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "../flipper.h"
4+
#include <furi.h>
5+
#include <furi_hal.h>
6+
7+
#include <flipper_format/flipper_format.h>
8+
9+
#include "../app_state.h"
10+
#include "../item.h"
11+
12+
void action_subghz_tx(void* context, Item* item);
13+
void action_rfid_tx(void* context, Item* item);
14+
void action_ir_tx(void* context, Item* item);

actions/action_ir.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Methods for IR transmission
2+
3+
#include "action_i.h"
4+
5+
void action_ir_tx(void* context, Item* item) {
6+
UNUSED(context);
7+
UNUSED(item);
8+
}

actions/action_rfid.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Methods for RFID transmission
2+
3+
// lfrid
4+
#include <lib/lfrfid/lfrfid_worker.h>
5+
#include <toolbox/protocols/protocol_dict.h>
6+
#include <lfrfid/protocols/lfrfid_protocols.h>
7+
#include <lfrfid/lfrfid_raw_file.h>
8+
#include <lib/toolbox/args.h>
9+
10+
#include "action_i.h"
11+
12+
// lifted from flipperzero-firmware/applications/main/lfrfid/lfrfid_cli.c
13+
void action_rfid_tx(void* context, Item* item) {
14+
App* app = context;
15+
FuriString* file_name = item->path;
16+
17+
FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
18+
FuriString* temp_str;
19+
temp_str = furi_string_alloc();
20+
uint32_t temp_data32;
21+
22+
FuriString* protocol_name;
23+
FuriString* data_text;
24+
protocol_name = furi_string_alloc();
25+
data_text = furi_string_alloc();
26+
27+
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
28+
ProtocolId protocol;
29+
size_t data_size = protocol_dict_get_max_data_size(dict);
30+
uint8_t* data = malloc(data_size);
31+
32+
FURI_LOG_I(TAG, "Max dict data size is %d", data_size);
33+
bool successful_read = false;
34+
do {
35+
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
36+
FURI_LOG_E(TAG, "Error opening %s", furi_string_get_cstr(file_name));
37+
break;
38+
}
39+
FURI_LOG_I(TAG, "Opened file");
40+
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
41+
FURI_LOG_E(TAG, "Missing or incorrect header");
42+
break;
43+
}
44+
FURI_LOG_I(TAG, "Read file headers");
45+
// TODO: add better header checks here...
46+
if(!strcmp(furi_string_get_cstr(temp_str), "Flipper RFID key")) {
47+
} else {
48+
FURI_LOG_E(TAG, "Type or version mismatch");
49+
break;
50+
}
51+
52+
// read and check the protocol field
53+
if(!flipper_format_read_string(fff_data_file, "Key type", protocol_name)) {
54+
FURI_LOG_E(TAG, "Error reading protocol");
55+
break;
56+
}
57+
protocol = protocol_dict_get_protocol_by_name(dict, furi_string_get_cstr(protocol_name));
58+
if(protocol == PROTOCOL_NO) {
59+
FURI_LOG_E(TAG, "Unknown protocol: %s", furi_string_get_cstr(protocol_name));
60+
break;
61+
}
62+
FURI_LOG_I(TAG, "Protocol OK");
63+
64+
// read and check data field
65+
size_t required_size = protocol_dict_get_data_size(dict, protocol);
66+
FURI_LOG_I(TAG, "Protocol req data size is %d", required_size);
67+
if(!flipper_format_read_hex(fff_data_file, "Data", data, required_size)) {
68+
FURI_LOG_E(TAG, "Error reading data");
69+
break;
70+
}
71+
// FURI_LOG_I(TAG, "Data: %s", furi_string_get_cstr(data_text));
72+
73+
// if(data_size != required_size) {
74+
// FURI_LOG_E(
75+
// TAG,
76+
// "%s data needs to be %zu bytes long",
77+
// protocol_dict_get_name(dict, protocol),
78+
// required_size);
79+
// break;
80+
// }
81+
82+
protocol_dict_set_data(dict, protocol, data, data_size);
83+
successful_read = true;
84+
FURI_LOG_I(TAG, "protocol dict setup complete!");
85+
} while(false);
86+
87+
if(successful_read) {
88+
LFRFIDWorker* worker = lfrfid_worker_alloc(dict);
89+
90+
lfrfid_worker_start_thread(worker);
91+
lfrfid_worker_emulate_start(worker, protocol);
92+
93+
printf("Emulating RFID...\r\nPress Ctrl+C to abort\r\n");
94+
int16_t time_ms = 3000;
95+
int16_t interval_ms = 200;
96+
while(time_ms > 0) {
97+
furi_delay_ms(interval_ms);
98+
time_ms -= interval_ms;
99+
}
100+
printf("Emulation stopped\r\n");
101+
102+
lfrfid_worker_stop(worker);
103+
lfrfid_worker_stop_thread(worker);
104+
lfrfid_worker_free(worker);
105+
}
106+
107+
furi_string_free(temp_str);
108+
furi_string_free(protocol_name);
109+
furi_string_free(data_text);
110+
free(data);
111+
112+
protocol_dict_free(dict);
113+
114+
flipper_format_free(fff_data_file);
115+
}

0 commit comments

Comments
 (0)