Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pecham pressure parsing #29

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/phone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ val clearTestOutputFilesFolder by tasks.creating(ClearTestOutputFilesFolder::cla
}

val downloadTestOutputFiles by tasks.creating(DownloadTestOutputFiles::class) {
dependsOn("connectedDemoDebugAndroidTest")
adbExecutable = android.adbExecutable
destination = layout.buildDirectory.dir("test_outputfiles")
}
Expand Down Expand Up @@ -125,5 +126,4 @@ tasks.withType<UpdatePlayStoreScreenshots> {

tasks.matching { it.name == "connectedDemoDebugAndroidTest" }.configureEach {
dependsOn(clearTestOutputFilesFolder)
downloadTestOutputFiles.dependsOn(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import android.bluetooth.le.ScanResult
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.masselis.tpmsadvanced.core.common.now
import com.masselis.tpmsadvanced.data.vehicle.model.Pressure.CREATOR.psi
import com.masselis.tpmsadvanced.data.vehicle.model.Pressure.CREATOR.kpa
import com.masselis.tpmsadvanced.data.vehicle.model.Temperature.CREATOR.celsius
import com.masselis.tpmsadvanced.data.vehicle.model.Tyre
import java.nio.ByteBuffer
import java.nio.ByteOrder

@OptIn(ExperimentalStdlibApi::class)
@Suppress("DataClassPrivateConstructor")
Expand All @@ -20,15 +18,9 @@ internal data class RawPecham private constructor(
) : Raw {

fun id() = macAddress.hashCode()
fun pressure() = data
.copyOfRange(3, 5)
.let {
ByteBuffer.wrap(it)
.order(ByteOrder.BIG_ENDIAN)
.getShort()
}
.div(10f)
.psi
fun pressure() = (data[3].toUInt() shl 8 and 0xFF00u or data[4].toUInt() and 255u) // Found into the SYTPMS app
.toFloat()
.kpa

fun battery() = data[1].toUShort() // Returns 27 for 2.7 volts

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.masselis.tpmsadvanced.data.vehicle.interfaces.impl

import com.masselis.tpmsadvanced.core.common.now
import com.masselis.tpmsadvanced.data.vehicle.model.Tyre
import io.mockk.every
import io.mockk.mockk
import org.junit.Test
Expand Down Expand Up @@ -33,6 +31,9 @@ internal class PechamTest {
// D8:51:00:00:AE:49 3D R.R.
// Tyre(timestamp=1.70168790933E9, location=REAR_RIGHT, id=0, pressure=Pressure(kpa=100.667), temperature=Temperature(celsius=20.0), battery=28, isAlarm=false)
"0303A5270308425208FF401C1400921A7F",

// Unlocated(timestamp=1.71585143556E9, rssi=-60, sensorId=-341438080, pressure=Pressure(kpa=212.0), temperature=Temperature(celsius=20.0), battery=29, isAlarm=false)
"0303A5270308425208FF241D1401D4BFEC"
)

// byteArrayEleven= 0308425208FF101B0F026A
Expand Down
Loading