From 1a8e3f8b7ff933fa95a2159cd64074faf30e373b Mon Sep 17 00:00:00 2001 From: andreock Date: Mon, 9 Sep 2024 19:35:38 +0200 Subject: [PATCH] Add initial IR support --- include/pins.h | 10 ++- lib/UI/navigation/IR/IRNavigation.cpp | 116 +++++++++++++++++++++++++ lib/UI/navigation/IR/IRNavigation.hpp | 12 +++ lib/UI/navigation/navigation.cpp | 12 +-- lib/UI/navigation/navigation.hpp | 2 + lib/UI/pages/IR/IREmulateRC.cpp | 44 ++++++++++ lib/UI/pages/IR/IREmulateRC.hpp | 46 ++++++++++ lib/UI/pages/IR/IRMainPage.cpp | 44 ++++++++++ lib/UI/pages/IR/IRMainPage.hpp | 46 ++++++++++ lib/UI/pages/IR/IRRecordSignalPage.cpp | 69 +++++++++++++++ lib/UI/pages/IR/IRRecordSignalPage.hpp | 49 +++++++++++ lib/UI/pages/main_page/MainPage.cpp | 2 +- lib/ir_attacks/ir_attacks.cpp | 59 +++++++++++++ lib/ir_attacks/ir_attacks.hpp | 6 ++ lib/ir_attacks/ir_attacks_task.cpp | 18 ++++ lib/ir_attacks/ir_attacks_task.hpp | 3 + lib/ir_attacks/ir_attacks_types.h | 13 +++ platformio.ini | 3 + 18 files changed, 545 insertions(+), 9 deletions(-) create mode 100644 lib/UI/navigation/IR/IRNavigation.cpp create mode 100644 lib/UI/navigation/IR/IRNavigation.hpp create mode 100644 lib/UI/pages/IR/IREmulateRC.cpp create mode 100644 lib/UI/pages/IR/IREmulateRC.hpp create mode 100644 lib/UI/pages/IR/IRMainPage.cpp create mode 100644 lib/UI/pages/IR/IRMainPage.hpp create mode 100644 lib/UI/pages/IR/IRRecordSignalPage.cpp create mode 100644 lib/UI/pages/IR/IRRecordSignalPage.hpp create mode 100644 lib/ir_attacks/ir_attacks.cpp create mode 100644 lib/ir_attacks/ir_attacks.hpp create mode 100644 lib/ir_attacks/ir_attacks_task.cpp create mode 100644 lib/ir_attacks/ir_attacks_task.hpp create mode 100644 lib/ir_attacks/ir_attacks_types.h diff --git a/include/pins.h b/include/pins.h index bcf361c..d3485d1 100644 --- a/include/pins.h +++ b/include/pins.h @@ -47,6 +47,9 @@ #define BATTERY_MONITOR 2 +#define IR_RECEIVER_PIN 6 +#define IR_EMITTER_PIN 14 + #elif ARDUINO_NANO_ESP32 // Define buttons pins @@ -70,9 +73,9 @@ #define SD_CARD_SCK D13 // SX1276(SubGHZ) -#define SX1276_DIO1 D3 +#define SX1276_DIO1 D0 #define SX1276_NSS D7 -#define SX1276_DIO2 D8 +#define SX1276_DIO2 D1 #define SX1276_MISO D9 // PN532(NFC) @@ -81,4 +84,7 @@ #define BATTERY_MONITOR A0 +#define IR_RECEIVER_PIN D8 +#define IR_EMITTER_PIN D3 + #endif diff --git a/lib/UI/navigation/IR/IRNavigation.cpp b/lib/UI/navigation/IR/IRNavigation.cpp new file mode 100644 index 0000000..ab0474e --- /dev/null +++ b/lib/UI/navigation/IR/IRNavigation.cpp @@ -0,0 +1,116 @@ + +#include "fm.hpp" +#include "gui.hpp" +#include "../../../../include/pins.h" +#include "pages/IR/IRMainPage.hpp" +#include "pages/IR/IREmulateRC.hpp" +#include "pages/IR/IRRecordSignalPage.hpp" +#include "pages/FileBrowser/FileBrowserPage.hpp" +#include "../navigation.hpp" +#include "ir_attacks.hpp" +#include "ArduinoJson.h" +#include "posixsd.hpp" +#include "sdcard_helper.hpp" + +static Gui *gui; + +static IRMainPage *ir_main_page = nullptr; +IRRecordSignalPage *ir_record_signal_page = nullptr; +static IREmulateRC *ir_emulate_rc = nullptr; +static IrFramework *ir_framework = nullptr; +static FileBrowserPage *file_browser_page = nullptr; + +void goto_ir_gui() { + gui->reset(); + ir_main_page = new IRMainPage(3, 0, 1, gui->get_screen(), gui); + gui->set_current_page(ir_main_page); +} + +void ir_goto_home() { + init_main_gui(); + ir_main_page = nullptr; + delete ir_framework; + ir_framework = nullptr; +} + +void goto_ir_record_signal_page() { + gui->reset(); + ir_record_signal_page = new IRRecordSignalPage(1, 1, 0, gui->get_screen(), gui); + gui->set_current_page(ir_record_signal_page); + ir_record_signal(ir_record_signal_page, ir_framework); +} + +void save_record_to_sd() { + Serial.println("Saving to SD"); + RecordedSignal signal = ir_framework->get_decoded_signal(); + JsonDocument doc; + doc["protocol"] = signal.protocol; + doc["address"] = signal.address; + doc["command"] = signal.command; + doc["number_of_bits"] = signal.numberOfBits; + doc["extra"] = signal.extra; + doc["decoded_raw_data"] = signal.decodedRawData; + doc["raw_len"] = signal.raw_len; + doc["flags"] = signal.flags; + JsonArray raw_data = doc["raw_data"].to(); + for (size_t i = 0; i < signal.raw_len; i++) + { + raw_data.add(signal.decodedRawDataArray[i]); + } + doc.shrinkToFit(); + File res = open("/IR/signals/" + (String)millis() + ".json", "w"); + serializeJsonPretty(doc, res); + res.close(); + goto_ir_gui(); +} + +#include + +static std::list ir_signal_files; +void send_signal(const char *path) { + ir_send_signal(ir_framework, ("/IR/signals/" + (String)path).c_str()); +} + +static std::list ir_rc_files; +JsonDocument rc_signals; + +void goto_ir_rc_emulator(const char *path) { + gui->reset(); + File rc_file = open("/IR/signal_rc/" + (String)path, "r"); + deserializeJson(rc_signals, rc_file); + const char* cmds[rc_signals.size()]; + for (size_t i = 0; i < rc_signals.size(); i++) + { + cmds[i] = rc_signals[i]["name"].as(); + } + ir_emulate_rc = new IREmulateRC(rc_signals.size(), 0,1, gui->get_screen(), gui); + ir_emulate_rc->display(cmds, rc_signals.size()); + gui->set_current_page(ir_emulate_rc, false); +} + +void goto_ir_rc_browser() { + gui->reset(); + ir_rc_files = list_dir(open("/IR/signal_rc", "r")); + file_browser_page = new FileBrowserPage(ir_rc_files.size() + 1, 1, 1 , gui->get_screen(), gui); + file_browser_page->display("IR RC Emulator", &ir_rc_files, goto_ir_rc_emulator, goto_ir_gui); + gui->set_current_page(file_browser_page, false); +} + +void emulate_ir_rc() { + size_t current_signal_index = ir_emulate_rc->get_current_element(); + JsonDocument current_signal = rc_signals[current_signal_index]; + ir_send_signal(ir_framework, current_signal); +} + +void goto_ir_send() { + gui->reset(); + ir_signal_files = list_dir(open("/IR/signals", "r")); + file_browser_page = new FileBrowserPage(ir_signal_files.size() + 1, 1, 1,gui->get_screen(), gui); + file_browser_page->display("IR File Browser", &ir_signal_files, send_signal, goto_ir_gui); + gui->set_current_page(file_browser_page, false); +} + +void init_ir_navigation(Gui *_gui) { + gui = _gui; + ir_framework = new IrFramework(IR_RECEIVER_PIN, IR_EMITTER_PIN); +} \ No newline at end of file diff --git a/lib/UI/navigation/IR/IRNavigation.hpp b/lib/UI/navigation/IR/IRNavigation.hpp new file mode 100644 index 0000000..1e731a2 --- /dev/null +++ b/lib/UI/navigation/IR/IRNavigation.hpp @@ -0,0 +1,12 @@ +#include "gui.hpp" + +void goto_ir_gui(); +void ir_goto_home(); +void goto_lg_ac_gui(); +void lg_ac_controller_go_back(); +void init_ir_navigation(Gui *_gui); +void goto_ir_record_signal_page(); +void save_record_to_sd(); +void goto_ir_send(); +void goto_ir_rc_browser(); +void emulate_ir_rc(); \ No newline at end of file diff --git a/lib/UI/navigation/navigation.cpp b/lib/UI/navigation/navigation.cpp index 68bf2d8..d552a01 100644 --- a/lib/UI/navigation/navigation.cpp +++ b/lib/UI/navigation/navigation.cpp @@ -21,16 +21,11 @@ #include "NFC/NFCNavigation.hpp" #include "buttons/btn_routines.hpp" #include "gui.hpp" +#include "IR/IRNavigation.hpp" #include "network_attacks/network_attacks_navigation.hpp" #include "wifi/wifi_navigation.hpp" #include "../../../include/debug.h" -#define WIFI_MODULE_POS 0 -#define BLE_MODULE_POS 1 -#define BADUSB_MODULE_POS 2 -#define SUBGHZ_MODULE_POS 3 -#define NFC_MODULE_POS 4 -#define NETWORK_ATTACKS_MODULE_POS 6 static Gui *gui; @@ -64,6 +59,11 @@ void init_nfc_ui() { goto_nfc_gui(); } +void init_ir_ui() { + init_ir_navigation(gui); + goto_ir_gui(); +} + void init_network_attacks_ui() { init_network_attacks_navigation(gui); goto_net_attacks_gui(); diff --git a/lib/UI/navigation/navigation.hpp b/lib/UI/navigation/navigation.hpp index 89a5b9b..795f27a 100644 --- a/lib/UI/navigation/navigation.hpp +++ b/lib/UI/navigation/navigation.hpp @@ -30,5 +30,7 @@ void init_subghz_ui(); void init_nfc_ui(); +void init_ir_ui(); + void init_network_attacks_ui(); #endif diff --git a/lib/UI/pages/IR/IREmulateRC.cpp b/lib/UI/pages/IR/IREmulateRC.cpp new file mode 100644 index 0000000..0f11015 --- /dev/null +++ b/lib/UI/pages/IR/IREmulateRC.cpp @@ -0,0 +1,44 @@ +#include "IREmulateRC.hpp" +#include "style.h" +#include "../../navigation/IR/IRNavigation.hpp" + +void IREmulateRC::display(const char* cmd[], size_t count) +{ + grid = new Grid(screen, 2, 4); + for (size_t i = 0; i < count; i++) + { + grid->add(new RectText(screen, cmd[i], HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT, + HOME_ICON_RADIUS, HOME_ICON_COLOR, emulate_ir_rc)); + } + go_back = new List(screen, "Go back", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_gui); + grid->add(go_back); + grid->set_pos(0, 10); + grid->set_space_between(10); + grid->set_padding(0, 20); + grid->display(); + grid->set_selected(0, true); +} + +void IREmulateRC::right() { + if(position_limit <= 4) + return; + if (current_position >= 0 && current_position < position_limit) { + grid->set_selected(current_position, false); + current_position++; + } + grid->set_selected(current_position, true); +} + +void IREmulateRC::left() { + if(position_limit <= 4) + return; + if (current_position > 0 && current_position <= position_limit) { + grid->set_selected(current_position, false); + current_position--; + } + grid->set_selected(current_position, true); +} + +void IREmulateRC::display() { + +} \ No newline at end of file diff --git a/lib/UI/pages/IR/IREmulateRC.hpp b/lib/UI/pages/IR/IREmulateRC.hpp new file mode 100644 index 0000000..a509140 --- /dev/null +++ b/lib/UI/pages/IR/IREmulateRC.hpp @@ -0,0 +1,46 @@ + +/* + * This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or + * https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../Page.hpp" +#include "Grid.hpp" +#include "List.hpp" +#include "widgets/RectText.hpp" + +#ifndef IR_EMULATE_RC_PAGE_H +#define IR_EMULATE_RC_PAGE_H + +class IREmulateRC : public Page { + private: + List *go_back; + + public: + IREmulateRC(uint8_t _position_limit, uint8_t _lower_limit, + uint8_t _position_increment, GFXForms *screen, Gui *_gui) : Page(_position_limit, _lower_limit, _position_increment, screen, _gui) {}; + ~IREmulateRC() {}; + void display(const char* cmd[], size_t count); + void display(); + void set_selected(int pos, bool status) { + grid->set_selected(pos, status); + }; + void click(int pos, void callback()) { grid->click(pos, callback); }; + void left(); + void right(); + size_t get_current_element() { return grid->get_selected(); }; +}; + +#endif diff --git a/lib/UI/pages/IR/IRMainPage.cpp b/lib/UI/pages/IR/IRMainPage.cpp new file mode 100644 index 0000000..62ab2dc --- /dev/null +++ b/lib/UI/pages/IR/IRMainPage.cpp @@ -0,0 +1,44 @@ + +/* + * This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or + * https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "IRMainPage.hpp" + +#include "../../i18n.hpp" +#include "../../navigation/IR/IRNavigation.hpp" +#include "gui.hpp" + +IRMainPage::~IRMainPage() {} + +void mock() { + +} + +void IRMainPage::display() { + grid = new Grid(screen, 4, 1); + record_signal = new List(screen, "Record signal", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_record_signal_page); + emulate_signal = new List(screen, "Emulate signal", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_send); + emulate_rc = new List(screen, "Emulate RC", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_rc_browser); + go_back = new List(screen, "Go back", 2, ST77XX_WHITE, 20, ST77XX_BLACK, ir_goto_home); + + grid->add(record_signal); + grid->add(emulate_signal); + grid->add(emulate_rc); + grid->add(go_back); + grid->set_selected(0, true); + grid->display(); +} diff --git a/lib/UI/pages/IR/IRMainPage.hpp b/lib/UI/pages/IR/IRMainPage.hpp new file mode 100644 index 0000000..bff3aa3 --- /dev/null +++ b/lib/UI/pages/IR/IRMainPage.hpp @@ -0,0 +1,46 @@ + +/* + * This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or + * https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../Page.hpp" +#include "Grid.hpp" +#include "List.hpp" + +#ifndef IR_MAIN_PAGE_H +#define IR_MAIN_PAGE_H + +class IRMainPage : public Page { + private: + List *record_signal; + List *emulate_signal; + List *emulate_list; + List *emulate_rc; + List *go_back; + + public: + IRMainPage(uint8_t _position_limit, uint8_t _lower_limit, + uint8_t _position_increment, GFXForms *screen, Gui *_gui) : Page(_position_limit, _lower_limit, _position_increment, screen, _gui) {}; + ~IRMainPage(); + void display(); + + void set_selected(int pos, bool status) { + grid->set_selected(pos, status); + }; + void click(int pos, void callback()) { grid->click(pos, callback); }; +}; + +#endif diff --git a/lib/UI/pages/IR/IRRecordSignalPage.cpp b/lib/UI/pages/IR/IRRecordSignalPage.cpp new file mode 100644 index 0000000..4270cbc --- /dev/null +++ b/lib/UI/pages/IR/IRRecordSignalPage.cpp @@ -0,0 +1,69 @@ + +/* + * This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or + * https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "IRRecordSignalPage.hpp" + +#include "../../i18n.hpp" +#include "../../navigation/IR/IRNavigation.hpp" +#include "gui.hpp" + +IRRecordSignalPage::~IRRecordSignalPage() { + Serial.println("Destroy"); + +} + +void IRRecordSignalPage::display() { + grid = new Grid(screen, 3, 1); + protocol = new Text(screen, ST77XX_WHITE, "Waiting for signal..."); + stop = new List(screen, "Stop", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_gui); + + grid->add(protocol); + grid->add(stop); + grid->set_selected(1, true); + grid->set_y_spacing(30); + grid->display(); +} + +void IRRecordSignalPage::set_signal(String _protocol, int _addr, int _cmd, uint32_t _len) { + grid->set_selected(1, false); + screen->reset(); + grid->remove(1); // Remove stop + if(_addr != -1 && _cmd != -1) { + addr = new Text(screen, ST77XX_WHITE, "Address: " + _addr); + cmd = new Text(screen, ST77XX_WHITE, "CMD:" + _cmd); + grid->add(addr); + grid->add(cmd); + } + Serial.println((String)_len); + len = new Text(screen, ST77XX_WHITE, "Length: " + (String)_len); + save = new List(screen, "Save", 2, ST77XX_WHITE, 20, ST77XX_BLUE, save_record_to_sd); + retry = new List(screen, "Retry", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_ir_record_signal_page); + grid->add(len); + grid->add(save); + grid->add(retry); + grid->add(stop); + size_t selected_widget = _addr == -1 ? 2 : 4; + size_t limit = _addr == -1 ? 4 : 6; + grid->set_selected(selected_widget, true); + current_position = selected_widget; + protocol->set_text("Protocol: " + _protocol); + position_limit = limit; + lower_limit = selected_widget; + position_increment = 1; + grid->display(); +} \ No newline at end of file diff --git a/lib/UI/pages/IR/IRRecordSignalPage.hpp b/lib/UI/pages/IR/IRRecordSignalPage.hpp new file mode 100644 index 0000000..db7a528 --- /dev/null +++ b/lib/UI/pages/IR/IRRecordSignalPage.hpp @@ -0,0 +1,49 @@ + +/* + * This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or + * https://capibarazero.github.io/). Copyright (c) 2024 Andrea Canale. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../Page.hpp" +#include "Grid.hpp" +#include "List.hpp" + +#ifndef IR_RECORD_SIGNAL_PAGE_H +#define IR_RECORD_SIGNAL_PAGE_H + +class IRRecordSignalPage : public Page { + private: + Text *protocol = nullptr; + Text *addr; + Text *cmd; + Text *len; + List *save; + List *retry; + List *stop; + + public: + IRRecordSignalPage(uint8_t _position_limit, uint8_t _lower_limit, + uint8_t _position_increment, GFXForms *screen, Gui *_gui) : Page(_position_limit, _lower_limit, _position_increment, screen, _gui) {}; + ~IRRecordSignalPage(); + void display(); + + void set_selected(int pos, bool status) { + grid->set_selected(pos, status); + }; + void click(int pos, void callback()) { grid->click(pos, callback); }; + void set_signal(String _protocol, int _addr, int _cmd, uint32_t len); +}; + +#endif diff --git a/lib/UI/pages/main_page/MainPage.cpp b/lib/UI/pages/main_page/MainPage.cpp index 7adb23f..80d652a 100644 --- a/lib/UI/pages/main_page/MainPage.cpp +++ b/lib/UI/pages/main_page/MainPage.cpp @@ -54,7 +54,7 @@ void MainPage::display() { HOME_ICON_COLOR, init_nfc_ui); IR = new RectText(screen, english_words->at(IR_HOME_KEY), HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS, - HOME_ICON_COLOR, section_not_ready); + HOME_ICON_COLOR, init_ir_ui); net_attacks = new RectText(screen, english_words->at(NET_ATTACKS_HOME_KEY), HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS, diff --git a/lib/ir_attacks/ir_attacks.cpp b/lib/ir_attacks/ir_attacks.cpp new file mode 100644 index 0000000..062a6e6 --- /dev/null +++ b/lib/ir_attacks/ir_attacks.cpp @@ -0,0 +1,59 @@ +#include "IrFramework.hpp" +#include "ir_attacks_task.hpp" +#include "ir_attacks_types.h" +#include "posixsd.hpp" +#include "ArduinoJson.h" + +#include "FreeRTOS.h" +#include "freertos/task.h" + +void ir_record_signal(IRRecordSignalPage *page, IrFramework *framework) { + IrAttackTaskParams params = { + .ir_framework = framework, + .page = page + }; + xTaskCreate(ir_record_signal_task, "ir_record_signal_task", 8000, ¶ms, 5, NULL); +} + +RecordedSignal json_to_signal(JsonDocument signal) { + RecordedSignal parsed_signal; + parsed_signal.protocol = signal["protocol"]; + JsonArray raw_data = signal["raw_data"]; + uint16_t len = signal["raw_len"]; + parsed_signal.address = signal["address"]; + parsed_signal.command = signal["command"]; + parsed_signal.decodedRawData = signal["decoded_raw_data"]; + parsed_signal.numberOfBits = signal["number_of_bits"]; + parsed_signal.flags = signal["flags"]; + /* Only PulseWidth/PulseDistance and Unknown require decodedRawDataArray, so memory for others protocols */ + if(parsed_signal.protocol >= 0 && parsed_signal.protocol <= 2) { + for (size_t i = 0; i < len; i++) + { + parsed_signal.decodedRawDataArray[i] = raw_data[i]; + } + } + parsed_signal.raw_len = len; + return parsed_signal; +} + +void ir_send_signal(IrFramework *framework, const char *signal_path) { + File signal_file = open(signal_path, "r"); + JsonDocument signal_doc; + deserializeJson(signal_doc, signal_file); + if(signal_doc.is()) { + Serial.println("JsonArray"); + for(JsonDocument signal : signal_doc.as()) { + RecordedSignal parsed_signal = json_to_signal(signal); + + framework->send_protocol_signal(parsed_signal); + } + } else { + RecordedSignal parsed_signal = json_to_signal(signal_doc); + framework->send_protocol_signal(parsed_signal); + } +} + +void ir_send_signal(IrFramework *framework, JsonDocument signal_doc) { + RecordedSignal parsed_signal = json_to_signal(signal_doc); + framework->send_protocol_signal(parsed_signal); +} \ No newline at end of file diff --git a/lib/ir_attacks/ir_attacks.hpp b/lib/ir_attacks/ir_attacks.hpp new file mode 100644 index 0000000..93be85b --- /dev/null +++ b/lib/ir_attacks/ir_attacks.hpp @@ -0,0 +1,6 @@ +#include "IrFramework.hpp" +#include "ArduinoJson.h" + +void ir_record_signal(IRRecordSignalPage *page, IrFramework *framework); +void ir_send_signal(IrFramework *framework, const char *signal_path); +void ir_send_signal(IrFramework *framework, JsonDocument signal_doc); \ No newline at end of file diff --git a/lib/ir_attacks/ir_attacks_task.cpp b/lib/ir_attacks/ir_attacks_task.cpp new file mode 100644 index 0000000..f03dd19 --- /dev/null +++ b/lib/ir_attacks/ir_attacks_task.cpp @@ -0,0 +1,18 @@ +#include "ir_attacks_types.h" +#include "IrFramework.hpp" + +void ir_record_signal_task(void *pv) { + IrAttackTaskParams *params = static_cast(pv); + IrFramework *ir_framework = params->ir_framework; + while(!ir_framework->read_signal()) { + NOP(); + } + RecordedSignal data = ir_framework->get_decoded_signal(); + Serial.println("Signal decoded successfully"); + Serial.println(data.protocol); + if(data.protocol == 0) // Unknown + params->page->set_signal(ir_framework->enum_to_str(data.protocol), -1, -1, data.raw_len); + else + params->page->set_signal(ir_framework->enum_to_str(data.protocol), -1, -1, data.raw_len); + vTaskDelete(NULL); +} \ No newline at end of file diff --git a/lib/ir_attacks/ir_attacks_task.hpp b/lib/ir_attacks/ir_attacks_task.hpp new file mode 100644 index 0000000..cae3a1b --- /dev/null +++ b/lib/ir_attacks/ir_attacks_task.hpp @@ -0,0 +1,3 @@ +#include "ir_attacks_types.h" + +void ir_record_signal_task(void *pv); \ No newline at end of file diff --git a/lib/ir_attacks/ir_attacks_types.h b/lib/ir_attacks/ir_attacks_types.h new file mode 100644 index 0000000..5d2b18a --- /dev/null +++ b/lib/ir_attacks/ir_attacks_types.h @@ -0,0 +1,13 @@ +#ifndef IR_ATTACK_TASK_PARAMS_H +#define IR_ATTACK_TASK_PARAMS_H + +#include "GFXForms.hpp" +#include "pages/IR/IRRecordSignalPage.hpp" +class IrFramework; + +typedef struct { + IrFramework *ir_framework; + IRRecordSignalPage *page; +}IrAttackTaskParams; + +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 8703298..6807d21 100755 --- a/platformio.ini +++ b/platformio.ini @@ -30,6 +30,7 @@ lib_deps_external = https://github.com/CapibaraZero/BLEScanner.git https://github.com/CapibaraZero/ESPShark.git https://github.com/CapibaraZero/ARP_Poisoner.git + https://github.com/CapibaraZero/IrFramework.git https://github.com/andreock/GFXForms.git https://github.com/spacehuhn/ArduinoPcap.git bblanchon/ArduinoJson@^7.1.0 @@ -63,6 +64,8 @@ platform = espressif32 framework = arduino board = arduino_nano_esp32 upload_protocol = esptool +build_type = debug +monitor_filters = esp32_exception_decoder lib_deps = ${common.lib_deps_builtin} ${common.lib_deps_external}