Преглед изворни кода

stack size increase, new work on adding settings

frux-c пре 2 година
родитељ
комит
f6eb23f57c
10 измењених фајлова са 89 додато и 11 уклоњено
  1. 1 1
      application.fam
  2. 1 0
      scenes/uhf_scene_config.h
  3. 0 3
      scenes/uhf_scene_read_tag.c
  4. 44 0
      scenes/uhf_scene_settings.c
  5. 6 0
      scenes/uhf_scene_start.c
  6. 1 1
      uhf_buffer.h
  7. 2 0
      uhf_module.c
  8. 26 0
      uhf_module_settings.h
  9. 4 3
      uhf_tag.h
  10. 4 3
      uhf_worker.c

+ 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) {

+ 44 - 0
scenes/uhf_scene_settings.c

@@ -0,0 +1,44 @@
+// #include "../uhf_app_i.h"
+
+// void uhf_settings_set_module_baudrate(VariableItem* item) {
+//     uint32_t baudrate =
+// }
+
+// void uhf_scene_on_enter(void* ctx) {
+//     UHFApp* uhf_app = ctx;
+//     view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewMenu);
+// }
+
+// bool uhf_scene_on_event(void* ctx, SceneManagerEvent event) {
+//     UHFApp* uhf_app = ctx;
+//     bool consumed = false;
+//     VariableItem* item;
+//     uint8_t value_index;
+//     // SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);
+//     // SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
+
+//     item = variable_item_list_add(
+//         subghz->variable_item_list,
+//         "Baud Rate:",
+//         subghz_setting_get_frequency_count(setting),
+//         subghz_scene_receiver_config_set_frequency,
+//         subghz);
+//     value_index = subghz_scene_receiver_config_next_frequency(preset.frequency, subghz);
+//     scene_manager_set_scene_state(
+//         subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
+//     variable_item_set_current_value_index(item, value_index);
+//     char text_buf[10] = {0};
+//     uint32_t frequency = subghz_setting_get_frequency(setting, value_index);
+//     snprintf(
+//         text_buf,
+//         sizeof(text_buf),
+//         "%lu.%02lu",
+//         frequency / 1000000,
+//         (frequency % 1000000) / 10000);
+//     variable_item_set_current_value_text(item, text_buf);
+// }
+
+// void uhf_scene_on_exit(void* ctx) {
+//     UHFApp* uhf_app = ctx;
+//     submenu_reset(uhf_app->submenu);
+// }

+ 6 - 0
scenes/uhf_scene_start.c

@@ -39,6 +39,12 @@ bool uhf_scene_start_on_event(void* ctx, SceneManagerEvent event) {
             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);

+ 1 - 1
uhf_buffer.h

@@ -3,7 +3,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 
-#define MAX_BUFFER_SIZE 128
+#define MAX_BUFFER_SIZE 256
 
 typedef struct Buffer {
     uint8_t* data;

+ 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;

+ 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);