Explorar el Código

Merge branch 'dev' of https://github.com/frux-c/uhf_rfid into dev

Chaka hace 2 años
padre
commit
47d6bd49cc

+ 1 - 1
application.fam

@@ -8,7 +8,7 @@ App(
         "storage",
         "gui",
     ],
-    stack_size=4 * 1024,
+    stack_size=12 * 1024,
     order=30,
     fap_icon="icons/uhf_10px.png",
     fap_category="RFID",

+ 1 - 0
scenes/uhf_scene_config.h

@@ -12,6 +12,7 @@ ADD_SCENE(uhf, delete, Delete)
 ADD_SCENE(uhf, delete_success, DeleteSuccess)
 ADD_SCENE(uhf, write_tag, WriteTag)
 ADD_SCENE(uhf, write_tag_success, WriteTagSuccess)
+ADD_SCENE(uhf, settings, Settings)
 // ADD_SCENE(uhf, read_factory_success, ReadFactorySuccess)
 // ADD_SCENE(uhf, write_key, WriteKey)
 // ADD_SCENE(uhf, key_menu, KeyMenu)

+ 0 - 3
scenes/uhf_scene_read_tag.c

@@ -6,9 +6,6 @@ void uhf_read_tag_worker_callback(UHFWorkerEvent event, void* ctx) {
     if(event == UHFWorkerEventSuccess) {
         view_dispatcher_send_custom_event(uhf_app->view_dispatcher, UHFCustomEventWorkerExit);
     }
-    // } else if(event == UHFWorkerEventAborted) {
-    //     scene_manager_search_and_switch_to_previous_scene(uhf_app->scene_manager, UHFSceneStart);
-    // }
 }
 
 void uhf_scene_read_tag_on_enter(void* ctx) {

+ 43 - 0
scenes/uhf_scene_settings.c

@@ -0,0 +1,43 @@
+#include "../uhf_app_i.h"
+#include "../uhf_module.h"
+
+void uhf_settings_set_module_baudrate(VariableItem* item) {
+    UNUSED(item);
+}
+
+void uhf_scene_settings_on_enter(void* ctx) {
+    UHFApp* uhf_app = ctx;
+    VariableItem* item;
+    uint8_t value_index = 0;
+    M100Module* uhf_module = uhf_app->worker->module;
+
+    item = variable_item_list_add(
+        uhf_app->variable_item_list,
+        "Baud Rate:",
+        sizeof(BAUD_RATES),
+        uhf_settings_set_module_baudrate,
+        uhf_module);
+    scene_manager_set_scene_state(uhf_app->scene_manager, UHFSceneSettings, (uint32_t)item);
+    variable_item_set_current_value_index(item, value_index);
+    char text_buf[10] = {0};
+    snprintf(text_buf, sizeof(text_buf), "%d", uhf_module->baudrate);
+    variable_item_set_current_value_text(item, text_buf);
+    view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewMenu);
+}
+
+bool uhf_scene_settings_on_event(void* ctx, SceneManagerEvent event) {
+    UHFApp* uhf_app = ctx;
+    bool consumed = false;
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UHFCustomEventSceneSettingLock) {
+            scene_manager_previous_scene(uhf_app->scene_manager);
+            consumed = true;
+        }
+    }
+    return consumed;
+}
+
+void uhf_scene_settings_on_exit(void* ctx) {
+    UHFApp* uhf_app = ctx;
+    submenu_reset(uhf_app->submenu);
+}

+ 5 - 7
scenes/uhf_scene_start.c

@@ -38,14 +38,12 @@ bool uhf_scene_start_on_event(void* ctx, SceneManagerEvent event) {
                 uhf_app->scene_manager, UHFSceneStart, SubmenuIndexSaved);
             scene_manager_next_scene(uhf_app->scene_manager, UHFSceneFileSelect);
             consumed = true;
+        } else if(event.event == SubmenuIndexSettings) {
+            scene_manager_set_scene_state(
+                uhf_app->scene_manager, UHFSceneStart, SubmenuIndexSettings);
+            scene_manager_next_scene(uhf_app->scene_manager, UHFSceneSettings);
+            consumed = true;
         }
-        // } else if(event.event == SubmenuIndexEliteDictAttack) {
-        //     scene_manager_set_scene_state(
-        //         uhf_app->scene_manager, UHFSceneStart, SubmenuIndexEliteDictAttack);
-        //     scene_manager_next_scene(uhf_app->scene_manager, UHFSceneEliteDictAttack);
-        //     consumed = true;
-        // }
-        // consumed = true;
     }
     return consumed;
 }

+ 6 - 0
uhf_app.c

@@ -69,6 +69,9 @@ UHFApp* uhf_alloc() {
     // Open Notification record
     uhf_app->notifications = furi_record_open(RECORD_NOTIFICATION);
 
+    // Variable Item List
+    uhf_app->variable_item_list = variable_item_list_alloc();
+
     // Submenu
     uhf_app->submenu = submenu_alloc();
     view_dispatcher_add_view(
@@ -140,6 +143,9 @@ void uhf_free(UHFApp* uhf_app) {
     furi_record_close(RECORD_GUI);
     uhf_app->gui = NULL;
 
+    // Variable Item List
+    variable_item_list_free(uhf_app->variable_item_list);
+
     // Notifications
     furi_record_close(RECORD_NOTIFICATION);
     uhf_app->notifications = NULL;

+ 3 - 0
uhf_app_i.h

@@ -11,6 +11,7 @@
 #include <gui/modules/loading.h>
 #include <gui/modules/text_input.h>
 #include <gui/modules/widget.h>
+#include <gui/modules/variable_item_list.h>
 
 #include <input/input.h>
 
@@ -42,6 +43,7 @@ enum UHFCustomEvent {
     UHFCustomEventWorkerExit,
     UHFCustomEventByteInputDone,
     UHFCustomEventTextInputDone,
+    UHFCustomEventSceneSettingLock,
 };
 
 typedef enum {
@@ -55,6 +57,7 @@ struct UHFApp {
     Gui* gui;
     NotificationApp* notifications;
     SceneManager* scene_manager;
+    VariableItemList* variable_item_list;
     // Storage* storage;
     UHFDevice* uhf_device;
     char text_store[UHF_TEXT_STORE_SIZE + 1];

+ 0 - 2
uhf_data_i.h

@@ -1,2 +0,0 @@
-// todo : probably will move some of the uhf_data functions to internal only
-// once i figure out how to structure the method calls

+ 2 - 0
uhf_module.c

@@ -260,6 +260,8 @@ M100ResponseType m100_read_label_data_storage(
     payload_len = (payload_len << 8) + data[4];
     size_t ptr_offset = 5 /*<-ptr offset*/ + uhf_tag->epc->size + 3 /*<-pc + ul*/;
     size_t bank_data_length = payload_len - (ptr_offset - 5 /*dont include the offset*/);
+    // print paylod length ptr offset and bank data length
+    FURI_LOG_E("TAG", "payload_len: %d, ptr_offset: %d, bank_data_length: %d", payload_len, ptr_offset, bank_data_length);
     if(data[2] == 0xFF) {
         if(payload_len == 0x0001) return M100NoTagResponse;
         return M100MemoryOverrun;

+ 1 - 16
uhf_module.h

@@ -6,6 +6,7 @@
 #include "uhf_buffer.h"
 #include "uhf_tag.h"
 #include <furi_hal.h>
+#include "uhf_module_settings.h"
 
 #define FRAME_END 0x7E
 #define DEFAULT_BAUDRATE 115200
@@ -16,22 +17,6 @@ typedef struct {
     char* manufacturer;
 } M100ModuleInfo;
 
-typedef enum {
-    WA_CHINA_900 = 1,   // Freq_CH-920.125M
-    WA_US,              // Freq_CH-902.25M
-    WA_EU,              // Freq_CH-865.1M
-    WA_CHINA_800,       // Freq_CH-840.125M
-    WA_KOREA = 6        // Freq_CH-917.1M
-} WorkingArea;
-
-typedef enum {
-    WC_CHINA_900 = 1,   // CH_Index(CN,900MHz) = (Freq_CH-920.125M)/0.25M
-    WC_US,              // CH_Index(US) = (Freq_CH-902.25M)/0.5M
-    WC_EU,              // CH_Index(EU) = (Freq_CH-865.1M)/0.2M
-    WC_CHINA_800,       // CH_Index(CN,800MHz) = (Freq_CH-840.125M)/0.25M
-    WC_KOREA = 6        // CH_Index(Korea) = (Freq_CH-917.1M)/0.2M
-} WorkingChannel;
-
 typedef enum {
     M100Success,
     M100ValidationFail,

+ 26 - 0
uhf_module_settings.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include <stdint.h>
+
+// UHF module baudrates
+static const uint32_t BAUD_RATES[] = {9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600};
+
+// UHF module regions
+typedef enum {
+    WA_CHINA_900 = 1, // Freq_CH-920.125M
+    WA_US, // Freq_CH-902.25M
+    WA_EU, // Freq_CH-865.1M
+    WA_CHINA_800, // Freq_CH-840.125M
+    WA_KOREA = 6 // Freq_CH-917.1M
+} WorkingArea;
+
+typedef enum {
+    WC_CHINA_900 = 1, // CH_Index(CN,900MHz) = (Freq_CH-920.125M)/0.25M
+    WC_US, // CH_Index(US) = (Freq_CH-902.25M)/0.5M
+    WC_EU, // CH_Index(EU) = (Freq_CH-865.1M)/0.2M
+    WC_CHINA_800, // CH_Index(CN,800MHz) = (Freq_CH-840.125M)/0.25M
+    WC_KOREA = 6 // CH_Index(Korea) = (Freq_CH-917.1M)/0.2M
+} WorkingChannel;
+
+// RF Power Setting
+static const uint8_t POWER_DBM[] = {12, 14, 17, 20}; // To be determined ...

+ 4 - 3
uhf_tag.h

@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#define MAX_BANK_SIZE 256
 // storage enum
 typedef enum { ReservedBank, EPCBank, TIDBank, UserBank } BankType;
 
@@ -16,7 +17,7 @@ typedef struct {
 // EPC Memory Bank
 typedef struct {
     size_t size; // Size of EPC memory data
-    uint8_t data[18]; // 2 bytes for CRC16, 2 bytes for PC, and max 14 bytes for EPC
+    uint8_t data[MAX_BANK_SIZE]; // 2 bytes for CRC16, 2 bytes for PC, and max 14 bytes for EPC
     uint16_t pc;
     uint16_t crc;
 } EPCMemoryBank;
@@ -24,13 +25,13 @@ typedef struct {
 // TID Memory Bank
 typedef struct {
     size_t size; // Size of TID memory data
-    uint8_t data[16]; // 4 bytes for Class ID and max 12 bytes for TID data
+    uint8_t data[MAX_BANK_SIZE]; // 4 bytes for Class ID
 } TIDMemoryBank;
 
 // User Memory Bank
 typedef struct {
     size_t size; // Size of user memory data
-    uint8_t data[64]; // Assuming max 512 bits (64 bytes) for User Memory
+    uint8_t data[MAX_BANK_SIZE]; // Assuming max 512 bits (64 bytes) for User Memory
 } UserMemoryBank;
 
 // EPC Gen 2 Tag containing all memory banks

+ 4 - 3
uhf_worker.c

@@ -26,8 +26,7 @@ UHFTag* send_polling_command(UHFWorker* uhf_worker) {
     return uhf_tag;
 }
 
-static UHFWorkerEvent
-    read_bank_till_max_length(UHFWorker* uhf_worker, UHFTag* uhf_tag, BankType bank) {
+UHFWorkerEvent read_bank_till_max_length(UHFWorker* uhf_worker, UHFTag* uhf_tag, BankType bank) {
     unsigned int retry = 3, word_low = 5, word_high = 100;
     unsigned int word_size;
     M100ResponseType status;
@@ -51,7 +50,7 @@ UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
     UHFTag* uhf_tag = send_polling_command(uhf_worker);
     if(uhf_tag == NULL) return UHFWorkerEventAborted;
     uhf_tag_wrapper_set_tag(uhf_worker->uhf_tag_wrapper, uhf_tag);
-    // Todo : set select here
+    // set select
     if(m100_set_select(uhf_worker->module, uhf_tag) != M100Success) return UHFWorkerEventFail;
     // read tid
     UHFWorkerEvent event;
@@ -90,7 +89,9 @@ int32_t uhf_worker_task(void* ctx) {
         uhf_worker->callback(event, uhf_worker->ctx);
     } else if(uhf_worker->state == UHFWorkerStateDetectSingle) {
         UHFWorkerEvent event = read_single_card(uhf_worker);
+        FURI_LOG_E("TAG", "read single card success");
         uhf_worker->callback(event, uhf_worker->ctx);
+        FURI_LOG_E("TAG", "read single card callback success %d", event);
     } else if(uhf_worker->state == UHFWorkerStateWriteSingle) {
         UHFWorkerEvent event = write_single_card(uhf_worker);
         uhf_worker->callback(event, uhf_worker->ctx);