Skip to content

Commit

Permalink
feat: id to send and request can be modified & uds functions name wer…
Browse files Browse the repository at this point in the history
…e changed
  • Loading branch information
AdonaiDiazEsparza committed Nov 15, 2024
1 parent 227403e commit aa069aa
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 36 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.
2 changes: 1 addition & 1 deletion Canbus_app/libraries/uds_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool read_frames_uds(MCP2515* CAN, uint32_t id, CANFRAME* frame) {
}

// Function to send a service
bool uds_manual_service_request(
bool uds_single_frame_request(
UDS_SERVICE* uds_instance,
uint8_t* data_to_send,
uint8_t count_of_bytes,
Expand Down
2 changes: 1 addition & 1 deletion Canbus_app/libraries/uds_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ UDS_SERVICE* uds_service_alloc(
bool uds_init(UDS_SERVICE* uds_instance);

// send a manual request
bool uds_manual_service_request(
bool uds_single_frame_request(
UDS_SERVICE* uds_instance,
uint8_t* data_to_send,
uint8_t count_of_bytes,
Expand Down
6 changes: 4 additions & 2 deletions Canbus_app/scenes/UDSMenuOption.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void uds_menu_callback(void* context, uint32_t index) {

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

default:
Expand All @@ -26,7 +27,8 @@ void app_scene_uds_menu_on_enter(void* context) {

submenu_reset(app->submenu);
submenu_set_header(app->submenu, "UDS Services");
submenu_add_item(app->submenu, "Send Manual UDS Service", 0, uds_menu_callback, app);
submenu_add_item(app->submenu, "Send Single Frame Request", 0, uds_menu_callback, app);
submenu_add_item(app->submenu, "Send Multiple Frame Request", 1, uds_menu_callback, app);

submenu_set_selected_item(app->submenu, selector_option);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "../../app_user.h"

static uint32_t id_request = 0x7e1;
static uint32_t id_response = 0x7e9;
static uint32_t id_request;
static uint32_t id_response;

static uint8_t id_request_array[4] = {0, 0, 0x7, 0xe0};
static uint8_t id_response_array[4] = {0, 0, 0x7, 0xe8};
;

static uint8_t count_of_frames = 1;
static uint8_t count_of_bytes = 1;

static uint8_t data_to_send[7] = {0};

// Thread to work
static int32_t obdii_thread_response_manual_uds_sender_on_work(void* context);
static int32_t uds_single_frame_request_thread(void* context);

/*
Scene uds manual sender to set the values to send
Expand All @@ -18,20 +22,35 @@ static int32_t obdii_thread_response_manual_uds_sender_on_work(void* context);
void callback_input_manual_sender_uds(void* context, uint32_t index) {
App* app = context;
switch(index) {
case 0:
scene_manager_set_scene_state(
app->scene_manager, app_scene_uds_single_frame_data_option, 0);
scene_manager_next_scene(app->scene_manager, app_scene_uds_single_frame_data_option);
break;

case 1:
scene_manager_set_scene_state(
app->scene_manager, app_scene_uds_single_frame_data_option, 1);
scene_manager_next_scene(app->scene_manager, app_scene_uds_single_frame_data_option);
break;

case 4:
scene_manager_next_scene(app->scene_manager, app_scene_uds_set_data_option);
scene_manager_set_scene_state(
app->scene_manager, app_scene_uds_single_frame_data_option, 2);
scene_manager_next_scene(app->scene_manager, app_scene_uds_single_frame_data_option);
break;

case 5:
scene_manager_next_scene(app->scene_manager, app_scene_uds_response_sender_option);
scene_manager_next_scene(
app->scene_manager, app_scene_uds_single_frame_request_response_option);
break;

default:
break;
}
}

void callback_manual_sender_menu(VariableItem* item) {
void callback_single_frame_request_menu(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
uint8_t selected_index = variable_item_list_get_selected_item_index(app->varList);
Expand Down Expand Up @@ -59,11 +78,17 @@ void callback_manual_sender_menu(VariableItem* item) {
}
}

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

id_request = (id_request_array[0] << 24) | (id_request_array[1] << 16) |
(id_request_array[2] << 8) | (id_request_array[3]);

id_response = (id_response_array[0] << 24) | (id_response_array[1] << 16) |
(id_response_array[2] << 8) | (id_response_array[3]);

// ID REQUEST 0
item = variable_item_list_add(app->varList, "ID REQUEST", 0, NULL, app);
variable_item_set_current_value_index(item, 0);
Expand All @@ -80,14 +105,15 @@ void app_scene_uds_manual_sender_on_enter(void* context) {

// COUNT OF FRAMES TO GET 2
item = variable_item_list_add(
app->varList, "Frames to get", 100, callback_manual_sender_menu, app);
app->varList, "Frames to get", 100, callback_single_frame_request_menu, app);
variable_item_set_current_value_index(item, count_of_frames - 1);
furi_string_reset(text);
furi_string_cat_printf(text, "%u", count_of_frames);
variable_item_set_current_value_text(item, furi_string_get_cstr(text));

// SET COUNT OF BYTES 3
item = variable_item_list_add(app->varList, "Bytes", 7, callback_manual_sender_menu, app);
item =
variable_item_list_add(app->varList, "Bytes", 7, callback_single_frame_request_menu, app);
variable_item_set_current_value_index(item, count_of_bytes - 1);
furi_string_reset(text);
furi_string_cat_printf(text, "%u", count_of_bytes);
Expand All @@ -105,7 +131,7 @@ void app_scene_uds_manual_sender_on_enter(void* context) {
view_dispatcher_switch_to_view(app->view_dispatcher, VarListView);
}

bool app_scene_uds_manual_sender_on_event(void* context, SceneManagerEvent event) {
bool app_scene_uds_single_frame_request_sender_on_event(void* context, SceneManagerEvent event) {
App* app = context;
bool consumed = false;
UNUSED(app);
Expand All @@ -114,7 +140,7 @@ bool app_scene_uds_manual_sender_on_event(void* context, SceneManagerEvent event
return consumed;
}

void app_scene_uds_manual_sender_on_exit(void* context) {
void app_scene_uds_single_frame_request_sender_on_exit(void* context) {
App* app = context;
variable_item_list_reset(app->varList);
}
Expand All @@ -126,25 +152,76 @@ void app_scene_uds_manual_sender_on_exit(void* context) {
void input_manual_uds(void* context) {
App* app = context;

uint32_t state =
scene_manager_get_scene_state(app->scene_manager, app_scene_uds_single_frame_data_option);

switch(state) {
case 0:

id_request = (id_request_array[0] << 24) | (id_request_array[1] << 16) |
(id_request_array[2] << 8) | (id_request_array[3]);
break;

case 1:

id_response = (id_response_array[0] << 24) | (id_response_array[1] << 16) |
(id_response_array[2] << 8) | (id_response_array[3]);
break;

default:
break;
}

view_dispatcher_send_custom_event(app->view_dispatcher, ReturnEvent);
}

void app_scene_uds_set_data_on_enter(void* context) {
void app_scene_uds_single_frame_data_on_enter(void* context) {
App* app = context;
ByteInput* scene = app->input_byte_value;

for(int i = count_of_bytes; i < 7; i++) {
data_to_send[i] = 0x00;
}
uint32_t state =
scene_manager_get_scene_state(app->scene_manager, app_scene_uds_single_frame_data_option);

switch(state) {
case 0:

byte_input_set_result_callback(
scene, input_manual_uds, NULL, app, data_to_send, count_of_bytes);
byte_input_set_header_text(scene, "SET DATA");
id_request_array[3] = id_request;
id_request_array[2] = id_request >> 8;
id_request_array[1] = id_request >> 16;
id_request_array[0] = id_request >> 24;

byte_input_set_result_callback(scene, input_manual_uds, NULL, app, id_request_array, 4);
byte_input_set_header_text(scene, "SET DATA");
break;

case 1:

id_response_array[3] = id_response;
id_response_array[2] = id_response >> 8;
id_response_array[1] = id_response >> 16;
id_response_array[0] = id_response >> 24;

byte_input_set_result_callback(scene, input_manual_uds, NULL, app, id_response_array, 4);
byte_input_set_header_text(scene, "SET DATA");
break;

case 2:
for(int i = count_of_bytes; i < 7; i++) {
data_to_send[i] = 0x00;
}
byte_input_set_result_callback(
scene, input_manual_uds, NULL, app, data_to_send, count_of_bytes);
byte_input_set_header_text(scene, "SET DATA");
break;

default:
break;
}

view_dispatcher_switch_to_view(app->view_dispatcher, InputByteView);
}

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

Expand All @@ -161,34 +238,33 @@ bool app_scene_uds_set_data_on_event(void* context, SceneManagerEvent event) {
return consumed;
}

void app_scene_uds_set_data_on_exit(void* context) {
void app_scene_uds_single_frame_data_on_exit(void* context) {
UNUSED(context);
}

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

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

app->thread = furi_thread_alloc_ex(
"ManualUDS", 1024, obdii_thread_response_manual_uds_sender_on_work, app);
app->thread = furi_thread_alloc_ex("ManualUDS", 1024, uds_single_frame_request_thread, app);
furi_thread_start(app->thread);

view_dispatcher_switch_to_view(app->view_dispatcher, TextBoxView);
}

bool app_scene_uds_response_sender_on_event(void* context, SceneManagerEvent event) {
bool app_scene_uds_single_frame_request_response_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) {
void app_scene_uds_single_frame_request_response_on_exit(void* context) {
App* app = context;
furi_thread_join(app->thread);
furi_thread_free(app->thread);
Expand All @@ -199,7 +275,7 @@ void app_scene_uds_response_sender_on_exit(void* context) {
Thread to work
*/

static int32_t obdii_thread_response_manual_uds_sender_on_work(void* context) {
static int32_t uds_single_frame_request_thread(void* context) {
App* app = context;
MCP2515* CAN = app->mcp_can;

Expand Down Expand Up @@ -237,7 +313,7 @@ static int32_t obdii_thread_response_manual_uds_sender_on_work(void* context) {

text_box_set_text(app->textBox, furi_string_get_cstr(text));

if(uds_manual_service_request(
if(uds_single_frame_request(
uds_service, data, count_of_bytes, canframes, count_of_frames)) {
for(uint8_t i = 0; i < count_of_frames; i++) {
CANFRAME frame_received = canframes[i];
Expand Down
8 changes: 3 additions & 5 deletions Canbus_app/scenes_config/app_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ ADD_SCENE(app, input_text, input_text_option)
ADD_SCENE(app, read_logs, read_logs)
ADD_SCENE(app, settings, settings_option)
ADD_SCENE(app, about_us, about_us)

// On development
ADD_SCENE(app, obdii_menu, obdii_option)
ADD_SCENE(app, obdii_typical_codes, obdii_typical_codes_option)
ADD_SCENE(app, draw_obdii, draw_obii_option)
Expand All @@ -42,6 +40,6 @@ 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)
ADD_SCENE(app, uds_set_data, uds_set_data_option)
ADD_SCENE(app, uds_single_frame_request_sender, uds_single_frame_request_sender_option)
ADD_SCENE(app, uds_single_frame_request_response, uds_single_frame_request_response_option)
ADD_SCENE(app, uds_single_frame_data, uds_single_frame_data_option)

0 comments on commit aa069aa

Please sign in to comment.