Skip to content

Commit

Permalink
feat: uds manual sender option added
Browse files Browse the repository at this point in the history
  • Loading branch information
AdonaiDiazEsparza committed Nov 8, 2024
1 parent 6fcdbed commit 7a38d99
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 4 deletions.
Binary file modified Canbus_app/dist/canbus_app.fap
Binary file not shown.
Binary file modified Canbus_app/dist/debug/canbus_app_d.elf
Binary file not shown.
21 changes: 20 additions & 1 deletion Canbus_app/libraries/uds_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,26 @@ bool uds_init(UDS_SERVICE* uds_instance) {
}

// Free instance
free_uds(UDS_SERVICE* uds_instance) {
void free_uds(UDS_SERVICE* uds_instance) {
free_mcp2515(uds_instance->CAN);
free(uds_instance);
}

// Function to send a service
bool manual_uds_service_request(
UDS_SERVICE* uds_instance,
CANFRAME* frames_to_received,
uint8_t count_of_frames) {
MCP2515* CAN = uds_instance->CAN;
CANFRAME frame_to_send = {0};
frame_to_send.canId = uds_instance->id_to_send;
uint32_t id_to_received = uds_instance->id_to_received;

UNUSED(frame_to_send);
UNUSED(id_to_received);
UNUSED(frames_to_received);
UNUSED(count_of_frames);
UNUSED(CAN);

return false;
}
5 changes: 4 additions & 1 deletion Canbus_app/libraries/uds_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <furi_hal.h>
#include "mcp_can_2515.h"

#define DEFAULT_ECU_REQUEST 0x7e0
#define DEFAULT_ECU_RESPONSE 0x7e8

typedef struct {
MCP2515* CAN;
uint32_t id_to_send;
Expand All @@ -12,6 +15,6 @@ typedef struct {

UDS_SERVICE* uds_service_alloc(MCP2515* CAN, uint32_t id_to_send, uint32_t id_to_received);
bool uds_init(UDS_SERVICE* uds_instance);
free_uds(UDS_SERVICE* uds_instance);
void free_uds(UDS_SERVICE* uds_instance);

#endif
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
#include "../app_user.h"

// Variable to set the item selected
uint32_t selector_option = 0;

// Callback function
void uds_menu_callback(void* context, uint32_t index) {
App* app = context;

// Selector option set
selector_option = index;

switch(index) {
case 0: // Manual Sender UDS service
scene_manager_next_scene(app->scene_manager, app_scene_uds_manual_sender_option);
break;

default:
break;
}
}

// Scene on enter to submenu
void app_scene_uds_menu_on_enter(void* context) {
App* app = context;

submenu_reset(app->submenu);
submenu_set_header(app->submenu, "UDS Services");
submenu_add_item(app->submenu, "Send Manual UDS Service", 0, NULL, app);
submenu_add_item(app->submenu, "Send Manual UDS Service", 0, uds_menu_callback, app);

submenu_set_selected_item(app->submenu, selector_option);

view_dispatcher_switch_to_view(app->view_dispatcher, SubmenuView);
}
Expand Down
71 changes: 70 additions & 1 deletion Canbus_app/scenes/UDSOptions/UDSManualSender.c
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
#include "../../app_user.h"
#include "../../app_user.h"

static uint32_t id_request = DEFAULT_ECU_REQUEST;
static uint32_t id_response = DEFAULT_ECU_RESPONSE;

/*
Scene uds manual sender to set the values to send
*/

void app_scene_uds_manual_sender_on_enter(void* context) {
App* app = context;
FuriString* text = app->text;
VariableItem* item;

item = variable_item_list_add(app->varList, "ID REQUEST", 0, NULL, app);
variable_item_set_current_value_index(item, 0);
furi_string_reset(text);
furi_string_cat_printf(text, "%lx", id_request);
variable_item_set_current_value_text(item, furi_string_get_cstr(text));

item = variable_item_list_add(app->varList, "ID RESPONSE", 0, NULL, app);
variable_item_set_current_value_index(item, 0);
furi_string_reset(text);
furi_string_cat_printf(text, "%lx", id_response);
variable_item_set_current_value_text(item, furi_string_get_cstr(text));

view_dispatcher_switch_to_view(app->view_dispatcher, VarListView);
}

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

return consumed;
}

void app_scene_uds_manual_sender_on_exit(void* context) {
App* app = context;
variable_item_list_reset(app->varList);
}

/*
Scene for the response of the uds services
*/

void app_scene_uds_response_sender_on_enter(void* context) {
App* app = context;
text_box_reset(app->textBox);
text_box_set_focus(app->textBox, TextBoxFocusEnd);

view_dispatcher_switch_to_view(app->view_dispatcher, TextBoxView);
}

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

void app_scene_uds_response_sender_on_exit(void* context) {
App* app = context;
text_box_reset(app->textBox);
}

/*
Thread to work
*/
3 changes: 3 additions & 0 deletions Canbus_app/scenes_config/app_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ ADD_SCENE(app, play_logs, play_logs)
ADD_SCENE(app, file_browser, file_browser_option)
ADD_SCENE(app, play_logs_widget, play_logs_widget)

// For the UDS FUNCTIONS
ADD_SCENE(app, uds_menu, uds_menu_option)
ADD_SCENE(app, uds_manual_sender, uds_manual_sender_option)
ADD_SCENE(app, uds_response_sender, uds_response_sender_option)

0 comments on commit 7a38d99

Please sign in to comment.