karasevIA 2 lat temu
rodzic
commit
fa03054cdb
4 zmienionych plików z 46 dodań i 6 usunięć
  1. 0 6
      eth_save_process.c
  2. 44 0
      eth_worker.c
  3. 1 0
      eth_worker.h
  4. 1 0
      eth_worker_i.h

+ 0 - 6
eth_save_process.c

@@ -263,8 +263,6 @@ EthernetSaveConfig* ehternet_save_process_malloc() {
 
     File* file = storage_file_alloc(storage);
 
-    FURI_LOG_E(TAG, "storage_file_alloc");
-
     if(!storage_file_open(file, APP_DATA_PATH("log.txt"), FSAM_WRITE, FSOM_OPEN_APPEND)) {
         FURI_LOG_E(TAG, "Failed to open file or file not exists");
         storage_file_free(file);
@@ -274,9 +272,6 @@ EthernetSaveConfig* ehternet_save_process_malloc() {
 
     config->log_file = file;
 
-    ehternet_save_process_print(config, "Finik Ethernet [RUN]");
-    FURI_LOG_E(TAG, "storage_file_alloc after print");
-
     return config;
 }
 
@@ -297,7 +292,6 @@ void ehternet_save_process_print(EthernetSaveConfig* config, const char* str) {
 }
 
 void ehternet_save_process_free(EthernetSaveConfig* config) {
-    ehternet_save_process_print(config, "Finik Ethernet [STOP]");
     ethernet_save_process_write(config);
     storage_file_close(config->log_file);
     storage_file_free(config->log_file);

+ 44 - 0
eth_worker.c

@@ -11,6 +11,8 @@
 
 #define TAG "EthWorker"
 
+static EthWorker* static_worker = NULL;
+
 EthWorker* eth_worker_alloc() {
     EthWorker* eth_worker = malloc(sizeof(EthWorker));
 
@@ -37,10 +39,17 @@ EthWorker* eth_worker_alloc() {
         ethernet_view_process_malloc(EthWorkerProcessReset, eth_worker->config);
     eth_worker->active_process = eth_worker->init_process;
 
+    static_worker = eth_worker;
+
+    eth_log(EthWorkerProcessReset, "Finik Ethernet [START]");
+
     return eth_worker;
 }
 
 void eth_worker_free(EthWorker* eth_worker) {
+    eth_log(EthWorkerProcessReset, "Finik Ethernet [STOP]");
+
+    static_worker = NULL;
     furi_assert(eth_worker);
     furi_thread_free(eth_worker->thread);
     ethernet_view_process_free(eth_worker->init_process);
@@ -83,6 +92,41 @@ void eth_worker_log(EthWorker* eth_worker, const char* str) {
     ehternet_save_process_print(eth_worker->config, str);
 }
 
+static EthViewProcess* get_process(EthWorker* worker, EthWorkerProcess process) {
+    furi_assert(worker);
+    switch(process) {
+    case EthWorkerProcessInit:
+        return worker->init_process;
+    case EthWorkerProcessDHCP:
+        return worker->dhcp_process;
+    case EthWorkerProcessStatic:
+        return worker->stat_process;
+    case EthWorkerProcessPing:
+        return worker->ping_process;
+    case EthWorkerProcessReset:
+        return worker->reset_process;
+    case EthWorkerProcessActive:
+        return worker->active_process;
+    default:
+        NULL;
+    }
+}
+
+void eth_log(EthWorkerProcess process, const char* format, ...) {
+    furi_assert(static_worker);
+    va_list args;
+    va_start(args, format);
+    FuriString* fstring = furi_string_alloc_vprintf(format, args);
+    const char* string = furi_string_get_cstr(fstring);
+    va_end(args);
+
+    FURI_LOG_I(TAG, "%s", string);
+    ehternet_save_process_print(static_worker->config, string);
+    ethernet_view_process_print(get_process(static_worker, process), string);
+
+    furi_string_free(fstring);
+}
+
 /************************** Ethernet Worker Thread *****************************/
 
 int32_t eth_worker_task(void* context) {

+ 1 - 0
eth_worker.h

@@ -23,6 +23,7 @@ typedef enum {
     EthWorkerProcessStatic,
     EthWorkerProcessPing,
     EthWorkerProcessReset,
+    EthWorkerProcessActive,
 } EthWorkerProcess;
 
 typedef enum {

+ 1 - 0
eth_worker_i.h

@@ -33,5 +33,6 @@ struct EthWorker {
 
 void eth_worker_change_state(EthWorker* eth_worker, EthWorkerState state);
 void eth_worker_log(EthWorker* eth_worker, const char* str);
+void eth_log(EthWorkerProcess process, const char* format, ...);
 
 int32_t eth_worker_task(void* context);