karasevIA 2 лет назад
Родитель
Сommit
8d00470597
5 измененных файлов с 71 добавлено и 14 удалено
  1. 56 3
      eth_save_process.c
  2. 5 4
      eth_save_process.h
  3. 0 1
      eth_view_process.c
  4. 9 6
      eth_worker.c
  5. 1 0
      eth_worker_i.h

+ 56 - 3
eth_save_process.c

@@ -1,7 +1,9 @@
 #include "eth_save_process.h"
 
 #include <furi.h>
+#include <furi_hal.h>
 #include <storage/storage.h>
+#include <locale/locale.h>
 
 #define TAG "EthSave"
 
@@ -195,6 +197,7 @@ bool storage_read_config(File* file, EthernetSaveConfig* cfg) {
         }
     }
 
+    furi_string_free(fstring);
     return true;
 }
 
@@ -223,8 +226,6 @@ void ethernet_save_process_write(const EthernetSaveConfig* config) {
 }
 
 void ethernet_save_process_read(EthernetSaveConfig* config) {
-    set_default_config(config);
-
     Storage* storage = furi_record_open(RECORD_STORAGE);
 
     File* file = storage_file_alloc(storage);
@@ -249,5 +250,57 @@ void ethernet_save_process_read(EthernetSaveConfig* config) {
     furi_record_close(RECORD_STORAGE);
 }
 
-void ehternet_save_process_print(char* str) {
+EthernetSaveConfig* ehternet_save_process_malloc() {
+    EthernetSaveConfig* config = malloc(sizeof(EthernetSaveConfig));
+
+    set_default_config(config);
+
+    ethernet_save_process_read(config);
+
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+
+    FURI_LOG_E(TAG, "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);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    config->log_file = file;
+
+    ehternet_save_process_print(config, "Finik Ethernet [RUN]");
+    FURI_LOG_E(TAG, "storage_file_alloc after print");
+
+    return config;
+}
+
+void ehternet_save_process_print(EthernetSaveConfig* config, const char* str) {
+    furi_assert(config);
+    FuriHalRtcDateTime datetime = {0};
+    furi_hal_rtc_get_datetime(&datetime);
+    bool res = storage_printf(
+        config->log_file,
+        "%4d.%02d.%02d-%02d:%2d:%02d || %s",
+        datetime.year,
+        datetime.month,
+        datetime.day,
+        datetime.hour,
+        datetime.minute,
+        datetime.second,
+        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);
+    furi_record_close(RECORD_STORAGE);
+    free(config);
 }

+ 5 - 4
eth_save_process.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stdint.h>
+#include <storage/storage.h>
 
 typedef struct EthernetSaveConfig {
     uint8_t mac[6];
@@ -9,6 +10,7 @@ typedef struct EthernetSaveConfig {
     uint8_t gateway[4];
     uint8_t dns[4];
     uint8_t ping_ip[4];
+    File* log_file;
 } EthernetSaveConfig;
 
 #define ETHERNET_SAVE_DEFAULT_MAC \
@@ -24,7 +26,6 @@ typedef struct EthernetSaveConfig {
 #define ETHERNET_SAVE_DEFAULT_PING_IP \
     { 8, 8, 8, 8 }
 
-void ethernet_save_process_write(const EthernetSaveConfig* config);
-void ethernet_save_process_read(EthernetSaveConfig* config);
-
-void ehternet_save_process_print(char* str);
+EthernetSaveConfig* ehternet_save_process_malloc();
+void ehternet_save_process_free(EthernetSaveConfig* config);
+void ehternet_save_process_print(EthernetSaveConfig* config, const char* str);

+ 0 - 1
eth_view_process.c

@@ -413,7 +413,6 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) {
         uint8_t carriage = process->carriage;
         uint8_t carriage1 = (carriage + 1) % process->strings_cnt;
         uint8_t carriage2 = (carriage + 2) % process->strings_cnt;
-        FURI_LOG_I(TAG, "print %d %d %d %d %d", max_width, len, start, carriage, carriage1);
         memset(process->fifo[carriage].data, 0, SCREEN_SYMBOLS_WIDTH);
         memset(process->fifo[carriage1].data, 0, SCREEN_SYMBOLS_WIDTH);
         memset(process->fifo[carriage2].data, 0, SCREEN_SYMBOLS_WIDTH);

+ 9 - 6
eth_worker.c

@@ -13,7 +13,7 @@
 
 EthWorker* eth_worker_alloc() {
     EthWorker* eth_worker = malloc(sizeof(EthWorker));
-    // Worker thread attributes
+
     eth_worker->thread = furi_thread_alloc();
     furi_thread_set_name(eth_worker->thread, "EthWorker");
     furi_thread_set_stack_size(eth_worker->thread, 8192);
@@ -22,9 +22,8 @@ EthWorker* eth_worker_alloc() {
 
     eth_worker_change_state(eth_worker, EthWorkerStateModuleInit);
 
-    eth_worker->config = malloc(sizeof(EthernetSaveConfig));
-
-    ethernet_save_process_read(eth_worker->config);
+    eth_worker->config = ehternet_save_process_malloc();
+    furi_assert(eth_worker->config);
 
     eth_worker->init_process =
         ethernet_view_process_malloc(EthWorkerProcessInit, eth_worker->config);
@@ -43,14 +42,13 @@ EthWorker* eth_worker_alloc() {
 
 void eth_worker_free(EthWorker* eth_worker) {
     furi_assert(eth_worker);
-    ethernet_save_process_write(eth_worker->config);
     furi_thread_free(eth_worker->thread);
     ethernet_view_process_free(eth_worker->init_process);
     ethernet_view_process_free(eth_worker->dhcp_process);
     ethernet_view_process_free(eth_worker->stat_process);
     ethernet_view_process_free(eth_worker->ping_process);
     ethernet_view_process_free(eth_worker->reset_process);
-    free(eth_worker->config);
+    ehternet_save_process_free(eth_worker->config);
     free(eth_worker);
 }
 
@@ -80,6 +78,11 @@ void eth_worker_set_active_process(EthWorker* eth_worker, EthWorkerProcess state
     }
 }
 
+void eth_worker_log(EthWorker* eth_worker, const char* str) {
+    furi_assert(eth_worker);
+    ehternet_save_process_print(eth_worker->config, str);
+}
+
 /************************** Ethernet Worker Thread *****************************/
 
 int32_t eth_worker_task(void* context) {

+ 1 - 0
eth_worker_i.h

@@ -32,5 +32,6 @@ struct EthWorker {
 };
 
 void eth_worker_change_state(EthWorker* eth_worker, EthWorkerState state);
+void eth_worker_log(EthWorker* eth_worker, const char* str);
 
 int32_t eth_worker_task(void* context);