diff --git a/.github/scripts/install-test.sh b/.github/scripts/install-test.sh index 0c0ddf423..3b3e1ddcc 100755 --- a/.github/scripts/install-test.sh +++ b/.github/scripts/install-test.sh @@ -955,7 +955,14 @@ adb logcat -c # Opens the Record and replay sheet from Diagnostics. Returns 1 if the row isn't there. open_replies() { diag_top - find_scrolled 'text="Record and replay"' "$OUT/ui-replies.xml" || return 1 + if ! find_scrolled 'text="Record and replay"' "$OUT/ui-replies.xml"; then + # Its section (Car and connection) can have closed again, if the app started up with a car + # chosen: open any closed section once more, then look again. + cp "$OUT/ui-replies.xml" "$OUT/ui-replies-missing.xml" 2>/dev/null + GROUPS_OPEN=; diag_top + find_scrolled 'text="Record and replay"' "$OUT/ui-replies.xml" || return 1 + log "record and replay: its section had closed, opened it again" + fi tap_text "Record and replay" > /dev/null; sleep 2 } # Picks a style from the Dashboard's Style list (it closes when one is tapped). diff --git a/CHANGELOG.md b/CHANGELOG.md index 796cc82bf..001a451f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ Every change to OBD2 Reader, newest first. Each GitHub release shows the entry for its version. +## 2.5.24 (1 December 2026) +- **Transmission temperature for Nissan and Infiniti.** Enhanced diagnostics now shows the CVT or automatic transmission fluid temperature on Nissans and Infinitis that give it, from the transmission computer on most cars up to about 2020, and on the 2021 and later X-Trail (Rogue). +- **Transmission and oil temperature for Hyundai, Kia and Genesis.** Enhanced diagnostics now shows the transmission fluid temperature on older and newer models, and the engine oil temperature. +- **Transmission temperature for Honda and Acura.** Enhanced diagnostics now shows the transmission fluid temperature on Hondas and Acuras that give it. Honda's transmission computer talks a little differently from the engine's, so the app briefly switches the adapter over to ask it, then back. +- **Transmission temperature for Mazda.** Mazda's own cars now show it too, the same way as Fords; the Ford-based Tribute and 2011–2020 BT-50 already had it. +- **Where these readings come from.** Like the other manufacturer readings, these come from owners testing them on their own cars rather than from the makers. Each was checked against answers recorded from real cars before it went in. Volkswagen and Audi readings were left out for now, because owners' lists disagree on how to read the transmission temperature. + ## 2.5.23 (30 November 2026) - **More Subaru CVT and all-wheel-drive readings.** Enhanced diagnostics now reads, from Subaru's transmission computer, the CVT ratio, the primary and secondary pulley speeds, the torque converter's turbine speed and lock-up duty, and the all-wheel-drive clutch duty, along with the transmission fluid temperature. - **Subaru transmission temperature on more cars.** It was only asked for where the 2023 and later Outback keeps it, so many 2013–2022 CVT Subarus may not have shown it. Owners have found these readings under different numbers on different Subarus, so the app now tries each number known and shows the first your car answers. Like the other manufacturer readings, they come from owners testing them on their own cars rather than from Subaru, and the app says so. diff --git a/app/src/main/java/com/obdreader/app/obd/ElmClient.kt b/app/src/main/java/com/obdreader/app/obd/ElmClient.kt index 53dc21d6a..2c0972e6b 100644 --- a/app/src/main/java/com/obdreader/app/obd/ElmClient.kt +++ b/app/src/main/java/com/obdreader/app/obd/ElmClient.kt @@ -1,6 +1,7 @@ package com.obdreader.app.obd import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext @@ -32,7 +33,9 @@ class ElmClient( try { commands.map { (cmd, timeout) -> try { send(cmd, timeout) } catch (e: AdapterTimeoutException) { emptyList() } } } finally { - for (cmd in after) try { send(cmd, 2000) } catch (ignored: Exception) {} + // Puts the adapter back (header, protocol) even when the read was cancelled part way, + // say by closing its sheet; otherwise it could stay on another protocol until reconnecting. + withContext(NonCancellable) { for (cmd in after) try { send(cmd, 2000) } catch (ignored: Exception) {} } } } diff --git a/app/src/main/java/com/obdreader/app/obd/EnhancedReadings.kt b/app/src/main/java/com/obdreader/app/obd/EnhancedReadings.kt index 2c884806f..09ec5561d 100644 --- a/app/src/main/java/com/obdreader/app/obd/EnhancedReadings.kt +++ b/app/src/main/java/com/obdreader/app/obd/EnhancedReadings.kt @@ -53,8 +53,10 @@ object EnhancedReadings { private fun r(id: String, name: String, module: String, header: String?, request: String, unit: String, decimals: Int, decode: (IntArray) -> Double?) = Reading(id, name, module, header, header?.let { replyFor(it) }, request, unit, decimals, decode) - /** The usual answer address: + 8 for 11-bit addresses. */ - private fun replyFor(h: String): String = String.format(Locale.US, "%03X", h.toInt(16) + 8) + /** The usual answer address: + 8 for 11-bit addresses; for 29-bit ones ("18DA1EF1"), the two addresses swapped ("18DAF11E"). */ + internal fun replyFor(h: String): String = + if (h.length == 8) h.substring(0, 4) + h.substring(6, 8) + h.substring(4, 6) + else String.format(Locale.US, "%03X", h.toInt(16) + 8) private const val PCM = "Engine computer" private const val TCM = "Transmission" @@ -171,6 +173,45 @@ object EnhancedReadings { r("gm.trans_temp", "Transmission fluid temperature", PCM, "7E0", "221940", "°C", 0) { b -> u(b, 0, 1)?.minus(40) }, ) + /** + * Nissan and Infiniti: transmission (CVT and automatic) fluid temperature, from the transmission + * computer at 7E1 on most cars up to about 2020, and on the 29-bit address 18DA18F1 on newer ones + * such as the 2021-on Rogue/X-Trail, where it's the 30th byte of a longer answer. + */ + private val NISSAN = listOf( + r("nissan.trans_temp", "Transmission fluid temperature", TCM, "7E1", "22110C", "°C", 0) { b -> u(b, 0, 1)?.minus(40) }, + r("nissan.trans_temp", "Transmission fluid temperature", TCM, "18DA18F1", "222170", "°C", 0) { b -> u(b, 29, 1)?.minus(40) }, + ) + + /** + * Hyundai, Kia and Genesis: transmission fluid temperature from the transmission computer (UDS 22 + * on newer cars, KWP 21 on older ones; the 14th byte either way), and engine oil temperature from + * the engine computer (the 35th byte, in steps of 0.75 °C from -48 °C). + */ + private val HYUNDAI_KIA = listOf( + r("hk.trans_temp", "Transmission fluid temperature", TCM, "7E1", "2201A0", "°C", 0) { b -> u(b, 13, 1)?.minus(40) }, + r("hk.trans_temp", "Transmission fluid temperature", TCM, "7E1", "21A0", "°C", 0) { b -> u(b, 13, 1)?.minus(40) }, + r("hk.oil_temp", "Engine oil temperature", PCM, "7E0", "22E001", "°C", 0) { b -> u(b, 34, 1)?.let { it * 0.75 - 48 } }, + r("hk.oil_temp", "Engine oil temperature", PCM, "7E0", "2101", "°C", 0) { b -> u(b, 34, 1)?.let { it * 0.75 - 48 } }, + ) + + /** + * Honda and Acura: transmission (CVT and automatic) fluid temperature. Honda's transmission + * computer answers on 29-bit addresses even on cars that talk OBD2 on 11-bit ones, so the + * adapter switches for it (see ObdSession.readEnhanced): 18DA1EF1 on newer cars, 18DA1DF1 on older. + */ + private val HONDA = listOf( + r("honda.trans_temp", "Transmission fluid temperature", TCM, "18DA1EF1", "223083", "°C", 0) { b -> u(b, 14, 1)?.minus(40) }, + r("honda.trans_temp", "Transmission fluid temperature", TCM, "18DA1EF1", "222201", "°C", 0) { b -> u(b, 26, 1)?.minus(40) }, + r("honda.trans_temp", "Transmission fluid temperature", TCM, "18DA1DF1", "222201", "°C", 0) { b -> u(b, 26, 1)?.minus(40) }, + ) + + /** Mazda's own cars (the Ford-built ones get Ford's list): transmission fluid temperature, under the number Ford uses too. */ + private val MAZDA = listOf( + r("mazda.trans_temp", "Transmission fluid temperature", TCM, "7E1", "221E1C", "°C", 1) { b -> s(b, 0, 2)?.div(16) }, + r("mazda.trans_temp", "Transmission fluid temperature", PCM, "7E0", "221E1C", "°C", 1) { b -> s(b, 0, 2)?.div(16) }, + ) + /** Opel and Vauxhall: GM's own read service, 1A, on the engine computer. */ private val OPEL = listOf( r("opel.oil_life", "Oil life remaining", PCM, "7E0", "1A6D", "%", 0) { b -> u(b, 0, 1)?.div(2.55) }, @@ -183,12 +224,19 @@ object EnhancedReadings { fun forCar(make: String?, model: String?, year: Int?): List { val m = mk(make); val mo = md(model) val list = mutableListOf() - val fordBuiltMazda = m == "mazda" && (mo == "tribute" || (mo == "bt-50" && (year ?: 0) >= 2011)) + // The 2011 to 2020 BT-50 is built on Ford's Ranger; the 2021 and later one on Isuzu's D-Max, + // so it gets neither Ford's readings nor Mazda's own. + val isuzuBuiltMazda = m == "mazda" && mo == "bt-50" && (year ?: 0) >= 2021 + val fordBuiltMazda = m == "mazda" && (mo == "tribute" || (mo == "bt-50" && (year ?: 0) in 2011..2020)) if (m in setOf("ford", "lincoln", "mercury") || fordBuiltMazda) list += FORD if (m in setOf("toyota", "lexus", "scion")) list += TOYOTA if (m == "subaru") list += SUBARU if (m == "subaru" && (mo == "ascent" || ((mo == "forester" || mo == "wrx / sti") && (year == null || year >= 2014)))) list += SUBARU_ENGINE if (m in setOf("chevrolet", "gmc", "holden", "buick", "cadillac", "pontiac", "saturn", "hummer")) list += GM + if (m in setOf("nissan", "infiniti") && mo != "leaf") list += NISSAN + if (m in setOf("hyundai", "kia", "genesis")) list += HYUNDAI_KIA + if (m in setOf("honda", "acura")) list += HONDA + if (m == "mazda" && !fordBuiltMazda && !isuzuBuiltMazda) list += MAZDA if (m == "nissan" && mo == "leaf" && (year == null || year <= 2017)) list += LEAF if (m == "renault" && mo == "zoe" && (year == null || year <= 2019)) list += ZOE if (m == "opel / vauxhall" || m == "opel" || m == "vauxhall") list += OPEL @@ -206,7 +254,7 @@ object EnhancedReadings { fun known(tried: List): Int = tried.distinctBy { it.id }.size /** Every reading, for tests. */ - val ALL: List get() = FORD + TOYOTA + SUBARU + SUBARU_ENGINE + GM + LEAF + ZOE + OPEL + val ALL: List get() = FORD + TOYOTA + SUBARU + SUBARU_ENGINE + GM + NISSAN + HYUNDAI_KIA + HONDA + MAZDA + LEAF + ZOE + OPEL /** * Module information: the identifiers every UDS module is meant to answer (ISO 14229), so it diff --git a/app/src/main/java/com/obdreader/app/session/ObdSession.kt b/app/src/main/java/com/obdreader/app/session/ObdSession.kt index cd019c618..5a813f4ae 100644 --- a/app/src/main/java/com/obdreader/app/session/ObdSession.kt +++ b/app/src/main/java/com/obdreader/app/session/ObdSession.kt @@ -876,8 +876,17 @@ object ObdSession { val (header, request) = key val first = group.first() if (group.all { it.id in found }) { group.forEach { out[it] = null }; continue } - val point = if (header == null) emptyList() else listOfNotNull("ATSH $header", first.reply?.let { "ATCRA $it" }, "ATFCSH $header", "ATFCSD 300000", "ATFCSM 1") - val back = if (header == null) emptyList() else ModuleScan.pointBack(defaultHeader) + // A 29-bit address (Honda's transmission computer, newer Nissans): on a car that talks OBD2 on + // 11-bit addresses, the adapter switches to the 29-bit form of the same speed for it, then back. + val wide = header != null && header.length == 8 + val switch = if (wide && !carIs29Bit()) ModuleScan.protocolSwitch(_state.value.protocolCode) else null + if (wide && !carIs29Bit() && switch == null) { group.forEach { out[it] = null }; continue } + val point = when { + header == null -> emptyList() + wide -> listOfNotNull(switch?.first) + ModuleScan.pointAt(ModuleScan.Module(first.module, header!!, first.reply ?: com.obdreader.app.obd.EnhancedReadings.replyFor(header))) + else -> listOfNotNull("ATSH $header", first.reply?.let { "ATCRA $it" }, "ATFCSH $header", "ATFCSD 300000", "ATFCSM 1") + } + val back = if (header == null) emptyList() else ModuleScan.pointBack(defaultHeader) + listOfNotNull(switch?.second) val lines = c.sequence(point.map { it to 1500L } + (request to 2000L), back).last() val data = if (ElmParser.errorIn(lines) != null) null else ElmParser.extractData(lines, first.replyHeader) group.forEach { r -> out[r] = data?.let { d -> try { r.decode(d)?.takeIf { !it.isNaN() && !it.isInfinite() } } catch (e: Exception) { null } }?.also { found += r.id } } diff --git a/app/src/test/java/com/obdreader/app/obd/EnhancedReadingsTest.kt b/app/src/test/java/com/obdreader/app/obd/EnhancedReadingsTest.kt index 04c3ad7cb..b0a8056f2 100644 --- a/app/src/test/java/com/obdreader/app/obd/EnhancedReadingsTest.kt +++ b/app/src/test/java/com/obdreader/app/obd/EnhancedReadingsTest.kt @@ -1,5 +1,6 @@ package com.obdreader.app.obd +import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Assert.assertNull @@ -13,9 +14,14 @@ class EnhancedReadingsTest { @Test fun readingsOnlyGoToTheMakesTheyWereFoundOn() { assertTrue(EnhancedReadings.forCar("Ford", "Focus", 2012).any { it.id == "ford.trans_temp" }) - // The Tribute is Ford-built, so it gets Ford's readings; a Mazda3 doesn't. + // The Tribute is Ford-built, so it gets Ford's readings; a Mazda3 gets Mazda's own. assertTrue(EnhancedReadings.forCar("Mazda", "Tribute", 2006).any { it.id == "ford.trans_temp" }) - assertTrue(EnhancedReadings.forCar("Mazda", "Mazda3", 2015).isEmpty()) + assertTrue(EnhancedReadings.forCar("Mazda", "Tribute", 2006).none { it.id.startsWith("mazda.") }) + // The 2011-2020 BT-50 is a Ford Ranger underneath; the 2021 and later one is an Isuzu D-Max. + assertTrue(EnhancedReadings.forCar("Mazda", "BT-50", 2015).any { it.id == "ford.trans_temp" }) + assertTrue(EnhancedReadings.forCar("Mazda", "BT-50", 2015).none { it.id.startsWith("mazda.") }) + assertTrue(EnhancedReadings.forCar("Mazda", "BT-50", 2022).none { it.id.startsWith("ford.") || it.id.startsWith("mazda.") }) + assertEquals(setOf("mazda.trans_temp"), EnhancedReadings.forCar("Mazda", "Mazda3", 2015).map { it.id }.toSet()) assertTrue(EnhancedReadings.forCar("Nissan", "Leaf", 2015).any { it.id == "leaf.soc" }) assertTrue(EnhancedReadings.forCar("Nissan", "Leaf", 2020).none { it.id.startsWith("leaf") }) assertTrue(EnhancedReadings.forCar("Peugeot", "308", 2018).isEmpty()) @@ -127,6 +133,44 @@ class EnhancedReadingsTest { assertEquals("80.0 °C", ford[2].format(80.0)) } + @Test + fun nissanHyundaiKiaHondaAndMazdaReadings() { + fun ids(make: String, model: String) = EnhancedReadings.forCar(make, model, 2018).map { it.id }.toSet() + assertEquals(setOf("nissan.trans_temp"), ids("Nissan", "Rogue")) + assertEquals(setOf("nissan.trans_temp"), ids("Infiniti", "QX60")) + assertTrue(ids("Nissan", "Leaf").none { it == "nissan.trans_temp" }) + listOf("Hyundai" to "Tucson", "Kia" to "Sorento", "Genesis" to "G70").forEach { (make, model) -> + assertEquals(make, setOf("hk.trans_temp", "hk.oil_temp"), ids(make, model)) + } + assertEquals(setOf("honda.trans_temp"), ids("Honda", "CR-V")) + assertEquals(setOf("honda.trans_temp"), ids("Acura", "MDX")) + + fun at(id: String, header: String, request: String) = EnhancedReadings.ALL.first { it.id == id && it.header == header && it.request == request } + fun bytes(n: Int, at: Int, v: Int) = IntArray(n).also { it[at] = v } + // Nissan: the first byte at 7E1; the 30th of a longer answer on the 29-bit address, which answers from 18DAF118. + assertEquals(59.0, at("nissan.trans_temp", "7E1", "22110C").decode(intArrayOf(0x63))!!, 1e-9) + val wide = at("nissan.trans_temp", "18DA18F1", "222170") + assertEquals("18DAF118", wide.reply) + assertEquals(67.0, wide.decode(bytes(31, 29, 0x6B))!!, 1e-9) + assertNull(wide.decode(IntArray(20))) + // Hyundai and Kia: the 14th byte, newer and older requests; oil in 0.75 °C steps from -48 °C. + assertEquals(73.0, at("hk.trans_temp", "7E1", "21A0").decode(bytes(20, 13, 0x71))!!, 1e-9) + assertEquals(49.0, at("hk.trans_temp", "7E1", "2201A0").decode(bytes(20, 13, 0x59))!!, 1e-9) + assertEquals(93.0, at("hk.oil_temp", "7E0", "2101").decode(bytes(40, 34, 188))!!, 1e-9) + assertEquals(72.75, at("hk.oil_temp", "7E0", "22E001").decode(bytes(40, 34, 161))!!, 1e-9) + // Honda: 29-bit transmission computer, newer address first. + val honda = EnhancedReadings.forCar("Honda", "Pilot", 2017).filter { it.id == "honda.trans_temp" } + assertEquals(listOf("18DA1EF1", "18DA1EF1", "18DA1DF1"), honda.map { it.header }) + assertEquals(listOf("18DAF11E", "18DAF11E", "18DAF11D"), honda.map { it.reply }) + assertEquals(15.0, honda[0].decode(bytes(20, 14, 0x37))!!, 1e-9) + assertEquals(45.0, honda[2].decode(bytes(30, 26, 0x55))!!, 1e-9) + // Mazda: signed sixteenths of a degree, as on Fords. + val mazda = at("mazda.trans_temp", "7E1", "221E1C") + assertEquals(32.0, mazda.decode(intArrayOf(0x02, 0x00))!!, 1e-9) + assertEquals(-0.3125, mazda.decode(intArrayOf(0xFF, 0xFB))!!, 1e-9) + assertEquals("621E1C", mazda.replyHeader) + } + @Test fun aReadingUnderSeveralNumbersShowsOnce() { val tried = EnhancedReadings.forCar("Subaru", "Outback", 2018) @@ -164,4 +208,25 @@ class EnhancedReadingsTest { assertEquals("1L8T-2C219-AB", EnhancedReadings.identifierText(ElmParser.extractData(abs, "62F187"))) assertTrue(ElmParser.errorIn(c.sequence(listOf("ATSH 7E0" to 1000L, "220462" to 2000L), listOf("ATSH 7DF")).last()) != null) } + + @Test + fun theAdapterIsPutBackEvenWhenAReadIsCancelled() = runBlocking { + val sent = java.util.Collections.synchronizedList(mutableListOf()) + val started = kotlinx.coroutines.CompletableDeferred() + val transport = object : ObdTransport { + override val name = "test" + override fun open() {} + override fun close() {} + override fun exchange(command: String, timeoutMs: Long): String { + sent += command + if (command == "222201") { started.complete(Unit); Thread.sleep(300) } + return "OK\r\r>" + } + } + val c = ElmClient(transport) + val job = launch(kotlinx.coroutines.Dispatchers.Default) { c.sequence(listOf("ATSP7" to 1000L, "222201" to 2000L, "222202" to 2000L), listOf("ATSH 7DF", "ATSP6")) } + started.await(); job.cancel(); job.join() + assertTrue(sent.toString(), sent.containsAll(listOf("ATSH 7DF", "ATSP6"))) + assertTrue(sent.toString(), "222202" !in sent) + } } diff --git a/gradle.properties b/gradle.properties index 6198f5ed3..586520bf7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ android.nonTransitiveRClass=true kotlin.code.style=official # The app version shown to users. Bump it with each release and add a CHANGELOG.md entry. -obdVersion=2.5.23 +obdVersion=2.5.24