Skip to content

Commit

Permalink
feat: function to get ECU Name added
Browse files Browse the repository at this point in the history
  • Loading branch information
AdonaiDiazEsparza committed Oct 22, 2024
1 parent c1a8d74 commit a75fb11
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
43 changes: 39 additions & 4 deletions Canbus_app/libraries/pid_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ bool get_VIN(OBDII* obdii, FuriString* vin_number) {

uint32_t extension = canframes[0].buffer[1];

log_info("extension: %lu", extension);

uint8_t vin[40];

memset(vin, 0, sizeof(vin));
Expand All @@ -408,7 +406,6 @@ bool get_VIN(OBDII* obdii, FuriString* vin_number) {
} else {
letters_vin[i] = vin[i + 1];
}
log_info("letter: %c number: %x", letters_vin[i], vin[i + 1]);
}

furi_string_reset(vin_number);
Expand All @@ -417,7 +414,45 @@ bool get_VIN(OBDII* obdii, FuriString* vin_number) {
furi_string_cat_printf(vin_number, "%c", letters_vin[i]);
}

log_info("%s", furi_string_get_cstr(vin_number));
return true;
}

// Get the ECU Name
bool get_ECU_name(OBDII* obdii, FuriString* ecu_name) {
CANFRAME canframes[5];

memset(canframes, 0, sizeof(canframes));

if(!pid_manual_request(obdii, 0x7df, REQUEST_VEHICLE_INFORMATION, 0xA, canframes, 5, 2))
return false;

if(canframes[0].buffer[2] != 0x49) return false;

uint32_t extension = canframes[0].buffer[1];

uint8_t vin[40];

memset(vin, 0, sizeof(vin));

for(uint8_t i = 0; i < 5; i++) {
separate_VIN_data(canframes[i], vin, i);
}

char letters_vin[extension];

for(uint8_t i = 0; i < extension; i++) {
if(vin[i + 1] < 32) {
letters_vin[i] = ' ';
} else {
letters_vin[i] = vin[i + 1];
}
}

furi_string_reset(ecu_name);

for(uint8_t i = 0; i < extension; i++) {
furi_string_cat_printf(ecu_name, "%c", letters_vin[i]);
}

return true;
}
Expand Down
5 changes: 4 additions & 1 deletion Canbus_app/libraries/pid_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ bool request_dtc(OBDII* obdii, uint8_t* count, char* codes[]);
// Clear DTC
bool clear_dtc(OBDII* obdii);

// Get VIN
// Get VIN
bool get_VIN(OBDII* obdii, FuriString* String);

// Get ECU Name
bool get_ECU_name(OBDII* obdii, FuriString* ecu_name);

// Function to calculate the engine speed
uint16_t calculate_engine_speed(uint8_t value_a, uint8_t value_b);

Expand Down
8 changes: 7 additions & 1 deletion Canbus_app/scenes/Obd2MenuOption.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void obdii_menu_callback(void* context, uint32_t index) {
break;

case 2:
request_data = 1;
scene_manager_next_scene(app->scene_manager, app_scene_car_data_option);
break;

Expand Down Expand Up @@ -1183,7 +1184,12 @@ static int32_t obdii_get_car_data(void* context) {
bool run = pid_init(&scanner);

if(run) {
get_VIN(&scanner, app->text);
if(request_data == 1) {
get_VIN(&scanner, app->text);
}
if(request_data == 2) {
get_ECU_name(&scanner, app->text)

Check failure on line 1191 in Canbus_app/scenes/Obd2MenuOption.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

expected ';' before '}' token
}
}

pid_deinit(&scanner);
Expand Down

0 comments on commit a75fb11

Please sign in to comment.