Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
karasevia committed Jul 10, 2023
1 parent 17386d9 commit 8d00470
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
59 changes: 56 additions & 3 deletions eth_save_process.c
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -195,6 +197,7 @@ bool storage_read_config(File* file, EthernetSaveConfig* cfg) {
}
}

furi_string_free(fstring);
return true;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
9 changes: 5 additions & 4 deletions eth_save_process.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <stdint.h>
#include <storage/storage.h>

typedef struct EthernetSaveConfig {
uint8_t mac[6];
Expand All @@ -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 \
Expand All @@ -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);
1 change: 0 additions & 1 deletion eth_view_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions eth_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions eth_worker_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 8d00470

Please sign in to comment.