Skip to content

Commit

Permalink
Merge pull request #20818 from osmandapp/add_obd_plugin
Browse files Browse the repository at this point in the history
Add obd plugin
  • Loading branch information
alex-osm committed Sep 21, 2024
2 parents 504cf03 + 602138b commit e8ab908
Show file tree
Hide file tree
Showing 25 changed files with 1,765 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public interface OsmAndCustomizationConstants {
String PLUGIN_ACCESSIBILITY = "osmand.accessibility";
String PLUGIN_WIKIPEDIA = "osmand.wikipedia";
String PLUGIN_ANT_PLUS = "osmand.antplus";
String PLUGIN_VEHICLE_METRICS = "osmand.vehicle.metrics";
String PLUGIN_WEATHER = "osmand.weather";

//Settings:
Expand Down
1 change: 0 additions & 1 deletion OsmAnd-shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ kotlin {
implementation("androidx.sqlite:sqlite:$sqliteVersion")
implementation("androidx.sqlite:sqlite-framework:$sqliteVersion")
implementation("net.sf.kxml:kxml2:$kxml2Version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
}
iosMain.dependencies {
implementation("co.touchlab:sqliter-driver:$sqliterVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.osmand.shared.obd

import net.osmand.shared.util.Localization

enum class FuelType(val code: String, val screenNamId: String) {
NO_PROVIDED("00", "obd_fuel_type_not_provided"),
GASOLINE("01", "obd_fuel_type_gasoline"),
METHANOL("02", "obd_fuel_type_methanol"),
ETHANOL("03", "obd_fuel_type_ethanol"),
DIESEL("04", "obd_fuel_type_diesel"),
LPG("05", "obd_fuel_type_lpg"),
CNG("06", "obd_fuel_type_cng"),
PROPANE("07", "obd_fuel_type_propane"),
ELECTRIC("08", "obd_fuel_type_electric"),
BIFUEL_RUNNING_GASOLINE("09", "obd_fuel_type_bifuel_gasoline"),
BIFUEL_RUNNING_METHANOL("0A", "obd_fuel_type_bifuel_methanol"),
BIFUEL_RUNNING_ETHANOL("0B", "obd_fuel_type_bifuel_ethanol"),
BIFUEL_RUNNING_LPG("0C", "obd_fuel_type_bifuel_lpg"),
BIFUEL_RUNNING_CNG("0D", "obd_fuel_type_bifuel_cng"),
BIFUEL_RUNNING_PROPANE("0E", "obd_fuel_type_bifuel_propane"),
BIFUEL_RUNNING_ELECTRICITY("0F", "obd_fuel_type_bifuel_electricity"),
BIFUEL_RUNNING_ELECTRIC_COMBUSTION_ENGINE("10", "obd_fuel_type_bifuel_electric_combustion"),
HYBRID_GASOLINE("11", "obd_fuel_type_hybrid_gasoline"),
HYBRID_ETHANOL("12", "obd_fuel_type_hybrid_ethanol"),
HYBRID_DIESEL("13", "obd_fuel_type_hybrid_diesel"),
HYBRID_ELECTRIC("14", "obd_fuel_type_hybrid_electric"),
HYBRID_ELECTRIC_COMBUSTION_ENGINE("15", "obd_fuel_type_hybrid_electric_combustion"),
HYBRID_REGENERATIVE("16", "obd_fuel_type_hybrid_regenerative"),
BIFUEL_RUNNING_HYDROGEN("17", "obd_fuel_type_bifuel_hydrogen"),
HYBRID_HYDROGEN("18", "obd_fuel_type_hybrid_hydrogen"),
HYDROGEN("19", "obd_fuel_type_hydrogen"),
UNKNOWN("FF", "obd_fuel_type_unknown");

fun getDisplayName(): String {
return Localization.getString(screenNamId)
}

companion object {
fun fromCode(code: String): FuelType {
return FuelType.entries.find { it.code == code.uppercase()} ?: UNKNOWN
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.osmand.shared.obd

enum class OBDCommand(
val command: String,
private val responseParser: (String) -> String,
val isStale: Boolean = false) {
OBD_SUPPORTED_LIST1_COMMAND("00", OBDUtils::parseSupportedCommandsResponse, true),
OBD_SUPPORTED_LIST2_COMMAND("20", OBDUtils::parseSupportedCommandsResponse, true),
OBD_SUPPORTED_LIST3_COMMAND("40", OBDUtils::parseSupportedCommandsResponse, true),
OBD_BATTERY_VOLTAGE_COMMAND("42", OBDUtils::parseBatteryVoltageResponse),
OBD_AMBIENT_AIR_TEMPERATURE_COMMAND("46", OBDUtils::parseAmbientTempResponse),
OBD_RPM_COMMAND("0C", OBDUtils::parseRpmResponse),
OBD_SPEED_COMMAND("0D", OBDUtils::parseSpeedResponse),
OBD_AIR_INTAKE_TEMP_COMMAND("0F", OBDUtils::parseIntakeAirTempResponse),
OBD_ENGINE_COOLANT_TEMP_COMMAND("05", OBDUtils::parseEngineCoolantTempResponse),
OBD_FUEL_CONSUMPTION_RATE_COMMAND("5E", OBDUtils::parseFuelConsumptionRateResponse),
OBD_FUEL_TYPE_COMMAND("51", OBDUtils::parseFuelTypeResponse, true),
OBD_FUEL_LEVEL_COMMAND("2F", OBDUtils::parseFuelLevelResponse);

fun parseResponse(response: String): String {
return responseParser.invoke(response.lowercase())
}
}
Loading

0 comments on commit e8ab908

Please sign in to comment.