Skip to content

Commit

Permalink
feat: play logs added to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
REGIOIGER committed Aug 23, 2024
1 parent 63f3072 commit f5e3938
Show file tree
Hide file tree
Showing 5 changed files with 649 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Canbus_app/app_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef enum {
SenderOption,
ObdiiOption,
ReadLOGOption,
PlayLOGOption,
SettingsOption,
AboutUsOption,
} MainMenuOptions;
Expand All @@ -91,6 +92,7 @@ typedef enum {
SettingsOptionEvent,
ObdiiOptionEvent,
ReadLOGOptionEvent,
PlayLOGOptionEvent,
AboutUsEvent,
} MainMenuEvents;

Expand Down
10 changes: 5 additions & 5 deletions Canbus_app/scenes/mainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void basic_scenes_menu_callback(void* context, uint32_t index) {
scene_manager_handle_custom_event(app->scene_manager, SenderOptionEvent);
break;

case PlayerOption:
scene_manager_handle_custom_event(app->scene_manager, PlayerOptionEvent);
case PlayLOGOption:
scene_manager_handle_custom_event(app->scene_manager, app_scene_play_logs);
break;

case SettingsOption:
Expand Down Expand Up @@ -109,7 +109,7 @@ void app_scene_menu_on_enter(void* context) {

submenu_add_item(app->submenu, "Sender", SenderOption, basic_scenes_menu_callback, app);

submenu_add_item(app->submenu, "Player", PlayerOption, basic_scenes_menu_callback, app);
submenu_add_item(app->submenu, "Player", PlayLOGOption, basic_scenes_menu_callback, app);

submenu_add_item(app->submenu, "Scanner OBD2", ObdiiOption, basic_scenes_menu_callback, app);

Expand Down Expand Up @@ -143,8 +143,8 @@ bool app_scene_menu_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(app->scene_manager, app_scene_sender_option);
break;

case PlayerOptionEvent:
scene_manager_next_scene(app->scene_manager, app_scene_player_option);
case PlayLOGOptionEvent:
scene_manager_next_scene(app->scene_manager, app_scene_play_logs);
break;

case SettingsOptionEvent:
Expand Down
129 changes: 129 additions & 0 deletions Canbus_app/scenes/playLogs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#include "../app_user.h"

uint32_t hex_to_int(const char* hex_str) {
uint32_t result = 0;
sscanf(hex_str, "%x", &result);

Check failure on line 5 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

format '%x' expects argument of type 'unsigned int *', but argument 3 has type 'uint32_t *' {aka 'long unsigned int *'} [-Werror=format=]
return result;
}

void send_data_frame(void* context) {

App* app = context;

app->mcp_can->mode = MCP_NORMAL;
ERROR_CAN debug = ERROR_OK;
ERROR_CAN error = ERROR_OK;
debug = mcp2515_init(app->mcp_can);

//#define PATHAPP "apps_data/canbus"
//DialogsApp* dialogs_tx; model or app?
//Storage* storage_tx;
//File* file_tx;

FuriString* predefined_filepath = furi_string_alloc_set_str(PATHAPP);
FuriString* selected_filepath = furi_string_alloc();
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, LORA_LOG_FILE_EXTENSION, NULL);

Check failure on line 26 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'LORA_LOG_FILE_EXTENSION' undeclared (first use in this function)
browser_options.base_path = PATHAPP;

dialog_file_browser_show(model->dialogs_tx, selected_filepath, predefined_filepath, &browser_options);

Check failure on line 29 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'model' undeclared (first use in this function); did you mean 'modfl'?

if(storage_file_open(
model->file_tx, furi_string_get_cstr(selected_filepath), FSAM_READ, FSOM_OPEN_EXISTING)) {

model->flag_tx_file = true;
model->test = 1;

char buffer[256];
size_t buffer_index = 0;
size_t bytes_read;

Check failure on line 39 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

variable 'bytes_read' set but not used [-Werror=unused-but-set-variable]
char c;

while ((bytes_read = storage_file_read(model->file_tx, &c, 1)) > 0 && model->flag_signal) {
if (c == '\n' || buffer_index >= 256 - 1) {
buffer[buffer_index] = '\0';

FURI_LOG_E(TAG,"%s\n", buffer);

Check failure on line 46 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'TAG' undeclared (first use in this function)

buffer[sizeof(buffer) - 1] = '\0'; // Ensure the string is null-terminated

CANFRAME frame_to_send = {0}; // Initialize all fields to 0

Check failure on line 50 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

variable 'frame_to_send' set but not used [-Werror=unused-but-set-variable]
char *saveptr;
char *token;

// Skip the timestamp
token = strtok_r(buffer, " ", &saveptr);
if (!token) return;

// CAN bus ID
token = strtok_r(NULL, " ", &saveptr);
if (!token) return;
frame_to_send.canId = hex_to_int(token);

// Data length
token = strtok_r(NULL, " ", &saveptr);
if (!token) return;
frame_to_send.data_length = (uint8_t)atoi(token);

Check failure on line 66 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'CANFRAME' has no member named 'data_length'; did you mean 'data_lenght'?

// Fill the data buffer
for (int i = 0; i < frame_to_send.data_length && i < MAX_LEN; i++) {

Check failure on line 69 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'CANFRAME' has no member named 'data_length'; did you mean 'data_lenght'?
token = strtok_r(NULL, " ", &saveptr);
if (!token) break;
frame_to_send.buffer[i] = (uint8_t)hex_to_int(token);
}

if (debug == ERROR_OK) {
error = send_can_frame(app->mcp_can, app->frame_to_send);
furi_delay_ms(500);

if (error != ERROR_OK)
scene_manager_handle_custom_event(app->scene_manager, SEND_ERROR);

Check failure on line 80 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'SEND_ERROR' undeclared (first use in this function)
else
scene_manager_handle_custom_event(app->scene_manager, SEND_OK);

Check failure on line 82 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

'SEND_OK' undeclared (first use in this function)
} else {
scene_manager_handle_custom_event(app->scene_manager, DEVICE_NO_CONNECTED);
}

buffer_index = 0;
} else {
buffer[buffer_index++] = c;
}
}

} else {
dialog_message_show_storage_error(model->dialogs_tx, "Cannot open File");
}
storage_file_close(model->file_tx);
model->test = 0;
furi_string_free(selected_filepath);
furi_string_free(predefined_filepath);

furi_hal_gpio_write(pin_led, true);
furi_delay_ms(50);
furi_hal_gpio_write(pin_led, false);

model->flag_tx_file = false;

}

void app_scene_play_logs_on_enter(void* context) {
App* app = context;
text_box_set_font(app->textBox, TextBoxFontText);
text_box_reset(app->textBox);
view_dispatcher_switch_to_view(app->view_dispatcher, TextBoxView);
text_box_set_text(app->textBox, furi_string_get_cstr(app->text));
}

bool app_scene_play_logs_on_event(void* context, SceneManagerEvent event) {
App* app = context;
bool consumed = false;
UNUSED(app);
UNUSED(event);
return consumed;
}

void app_scene_play_logs_on_exit(void* context) {
App* app = context;
furi_string_reset(app->text);
text_box_reset(app->textBox);
}
Loading

0 comments on commit f5e3938

Please sign in to comment.