diff --git a/Canbus_app/libraries/pid_library.c b/Canbus_app/libraries/pid_library.c index 1b2fee9..40b7758 100644 --- a/Canbus_app/libraries/pid_library.c +++ b/Canbus_app/libraries/pid_library.c @@ -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)); @@ -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); @@ -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; } diff --git a/Canbus_app/libraries/pid_library.h b/Canbus_app/libraries/pid_library.h index 6cc157e..b8a9759 100644 --- a/Canbus_app/libraries/pid_library.h +++ b/Canbus_app/libraries/pid_library.h @@ -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); diff --git a/Canbus_app/scenes/Obd2MenuOption.c b/Canbus_app/scenes/Obd2MenuOption.c index b1751fc..2a1b57d 100644 --- a/Canbus_app/scenes/Obd2MenuOption.c +++ b/Canbus_app/scenes/Obd2MenuOption.c @@ -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; @@ -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) + } } pid_deinit(&scanner);