-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
649 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
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); | ||
browser_options.base_path = PATHAPP; | ||
|
||
dialog_file_browser_show(model->dialogs_tx, selected_filepath, predefined_filepath, &browser_options); | ||
|
||
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; | ||
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); | ||
|
||
buffer[sizeof(buffer) - 1] = '\0'; // Ensure the string is null-terminated | ||
|
||
CANFRAME frame_to_send = {0}; // Initialize all fields to 0 | ||
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); | ||
|
||
// Fill the data buffer | ||
for (int i = 0; i < frame_to_send.data_length && i < MAX_LEN; i++) { | ||
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); | ||
else | ||
scene_manager_handle_custom_event(app->scene_manager, SEND_OK); | ||
} 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); | ||
} |
Oops, something went wrong.