diff --git a/Canbus_app/dist/canbus_app.fap b/Canbus_app/dist/canbus_app.fap index ca631a6..b89d38b 100644 Binary files a/Canbus_app/dist/canbus_app.fap and b/Canbus_app/dist/canbus_app.fap differ diff --git a/Canbus_app/dist/debug/canbus_app_d.elf b/Canbus_app/dist/debug/canbus_app_d.elf index ac0b502..73c0969 100644 Binary files a/Canbus_app/dist/debug/canbus_app_d.elf and b/Canbus_app/dist/debug/canbus_app_d.elf differ diff --git a/Canbus_app/libraries/uds_library.c b/Canbus_app/libraries/uds_library.c index 5a3c0e1..c9a822d 100644 --- a/Canbus_app/libraries/uds_library.c +++ b/Canbus_app/libraries/uds_library.c @@ -42,18 +42,22 @@ void free_uds(UDS_SERVICE* uds_instance) { } // Get Frames -bool read_frames_uds(MCP2515* CAN, uint8_t id, CANFRAME* frame) { +bool read_frames_uds(MCP2515* CAN, uint32_t id, CANFRAME* frame) { uint32_t time_delay = 0; do { if(read_can_message(CAN, frame) == ERROR_OK) { - if(frame->canId == id) return true; + if(frame->canId == id) { + return true; + } } furi_delay_us(1); time_delay++; } while((time_delay < 6000)); + log_exception("Error"); + return false; } @@ -61,19 +65,17 @@ bool read_frames_uds(MCP2515* CAN, uint8_t id, CANFRAME* frame) { bool uds_manual_service_request( UDS_SERVICE* uds_instance, uint8_t* data_to_send, + uint8_t count_of_bytes, 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; - frame_to_send.data_lenght = 8; + frame_to_send.data_lenght = count_of_bytes + 1; uint32_t id_to_received = uds_instance->id_to_received; ERROR_CAN ret = ERROR_OK; - UNUSED(id_to_received); - UNUSED(frames_to_received); - - for(uint8_t i = 0; i < 8; i++) + for(uint8_t i = 0; i < frame_to_send.data_lenght; i++) frame_to_send.buffer[i] = data_to_send[i]; ret = send_can_frame(CAN, &frame_to_send); @@ -82,6 +84,7 @@ bool uds_manual_service_request( memset(frame_to_send.buffer, 0, sizeof(frame_to_send.buffer)); frame_to_send.buffer[0] = 0x30; + frame_to_send.data_lenght = 3; for(uint8_t i = 0; i < count_of_frames; i++) { if(i == 1) { diff --git a/Canbus_app/libraries/uds_library.h b/Canbus_app/libraries/uds_library.h index a8b6dea..5e2edbd 100644 --- a/Canbus_app/libraries/uds_library.h +++ b/Canbus_app/libraries/uds_library.h @@ -27,6 +27,7 @@ bool uds_init(UDS_SERVICE* uds_instance); bool uds_manual_service_request( UDS_SERVICE* uds_instance, uint8_t* data_to_send, + uint8_t count_of_bytes, CANFRAME* frames_to_received, uint8_t count_of_frames); diff --git a/Canbus_app/scenes/UDSOptions/UDSManualSender.c b/Canbus_app/scenes/UDSOptions/UDSManualSender.c index df7dd4b..b009b3c 100644 --- a/Canbus_app/scenes/UDSOptions/UDSManualSender.c +++ b/Canbus_app/scenes/UDSOptions/UDSManualSender.c @@ -1,7 +1,7 @@ #include "../../app_user.h" -static uint32_t id_request = DEFAULT_ECU_REQUEST; -static uint32_t id_response = DEFAULT_ECU_RESPONSE; +static uint32_t id_request = 0x7e1; +static uint32_t id_response = 0x7e9; static uint8_t count_of_frames = 1; static uint8_t count_of_bytes = 1; @@ -134,7 +134,7 @@ void app_scene_uds_set_data_on_enter(void* context) { ByteInput* scene = app->input_byte_value; for(int i = count_of_bytes; i < 7; i++) { - data_to_send[i] = 0xAA; + data_to_send[i] = 0x00; } byte_input_set_result_callback( @@ -212,27 +212,24 @@ static int32_t obdii_thread_response_manual_uds_sender_on_work(void* context) { bool run = uds_init(uds_service); - uint8_t data[8]; + uint8_t size = count_of_bytes + 1; - memset(data, 0xaa, sizeof(data)); + uint8_t data[size]; data[0] = count_of_bytes; - for(uint8_t i = 1; i < (count_of_bytes + 1); i++) { + for(uint8_t i = 1; i < size; i++) { data[i] = data_to_send[i - 1]; } - CANFRAME canframes[count_of_frames]; - - memset(canframes, 0, sizeof(canframes)); - if(run) { - // Time delay added to initialize - furi_delay_ms(500); + CANFRAME canframes[count_of_frames]; + memset(canframes, 0, sizeof(canframes)); + furi_delay_ms(500); // Time delay added to initialize furi_string_printf(text, "DEVICE CONNECTED!...\n"); - furi_string_cat_printf(text, "%lx ", id_request); + furi_string_cat_printf(text, "-> %lx ", id_request); - for(uint8_t i = 0; i < 8; i++) { + for(uint8_t i = 0; i < size; i++) { furi_string_cat_printf(text, "%x ", data[i]); } @@ -240,7 +237,8 @@ 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(uds_service, data, canframes, count_of_frames)) { + if(uds_manual_service_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]; if(frame_received.canId == 0x00) break;