Skip to content

Commit

Permalink
fix: get data from the ECU
Browse files Browse the repository at this point in the history
  • Loading branch information
AdonaiDiazEsparza committed Nov 15, 2024
1 parent b720515 commit 227403e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 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.
17 changes: 10 additions & 7 deletions Canbus_app/libraries/uds_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,40 @@ 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;
}

// Function to send a service
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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Canbus_app/libraries/uds_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
28 changes: 13 additions & 15 deletions Canbus_app/scenes/UDSOptions/UDSManualSender.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -212,35 +212,33 @@ 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]);
}

furi_string_cat_printf(text, "\n");

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;
Expand Down

0 comments on commit 227403e

Please sign in to comment.