From e33f0552cd56aaf0f716951d402d5ebad8da9e98 Mon Sep 17 00:00:00 2001 From: Jukka Oikarinen Date: Mon, 7 Feb 2022 10:45:51 +0200 Subject: [PATCH] Android source: Prepare for 3.2.7 release - Android SDK target lift from 29 to 31 - small enhancements and bug fixes --- .../android-communications/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- .../library/build.gradle | 14 +- .../library/src/main/AndroidManifest.xml | 32 ++- .../api/ble/exceptions/BleStartScanError.kt | 2 +- .../ble/model/gatt/client/pmd/BlePMDClient.kt | 2 +- .../client/pmd/PmdControlPointResponse.kt | 14 +- .../model/gatt/client/pmd/model/PpgData.kt | 18 +- .../gatt/client/psftp/BlePsFtpUtils.java | 4 +- .../bluedroid/host/BDDeviceListenerImpl.java | 6 +- .../ble/bluedroid/host/BDScanCallback.kt | 14 +- .../polar/sdk/api/PolarBleApiDefaultImpl.kt | 2 +- .../sdk/api/model/PolarAccelerometerData.java | 6 +- .../TestConnectionHandler.java | 94 +++---- .../gatt/client/pmd/model/PpgDataTest.kt | 264 +++++++----------- .../client/pmd/model/TemperatureDataTest.kt | 10 +- 16 files changed, 223 insertions(+), 267 deletions(-) diff --git a/sources/Android/android-communications/build.gradle b/sources/Android/android-communications/build.gradle index e811e015..d635443b 100755 --- a/sources/Android/android-communications/build.gradle +++ b/sources/Android/android-communications/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.5.31' + ext.kotlin_version = '1.6.10' ext.protobuf_version = '0.8.12' ext.dokka_version = '1.4.32' @@ -11,7 +11,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.google.protobuf:protobuf-gradle-plugin:$protobuf_version" classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" diff --git a/sources/Android/android-communications/gradle/wrapper/gradle-wrapper.properties b/sources/Android/android-communications/gradle/wrapper/gradle-wrapper.properties index ec2f8719..54bd7a34 100644 --- a/sources/Android/android-communications/gradle/wrapper/gradle-wrapper.properties +++ b/sources/Android/android-communications/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Aug 10 10:03:55 EEST 2021 +#Mon Feb 07 10:00:30 EET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/sources/Android/android-communications/library/build.gradle b/sources/Android/android-communications/library/build.gradle index aa849743..13ae33bd 100755 --- a/sources/Android/android-communications/library/build.gradle +++ b/sources/Android/android-communications/library/build.gradle @@ -34,11 +34,11 @@ def getVersion = { -> } android { - compileSdkVersion 29 + compileSdkVersion 31 defaultConfig { minSdkVersion 21 - targetSdkVersion 29 + targetSdkVersion 31 versionCode 14 versionName "14" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -155,16 +155,16 @@ protobuf { dependencies { implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' - implementation 'io.reactivex.rxjava3:rxjava:3.1.1' + implementation 'io.reactivex.rxjava3:rxjava:3.1.3' implementation 'commons-io:commons-io:2.10.0' - implementation 'androidx.annotation:annotation:1.2.0' - implementation "androidx.core:core-ktx:1.6.0" + implementation 'androidx.annotation:annotation:1.3.0' + implementation "androidx.core:core-ktx:1.7.0" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" sdkImplementation 'com.google.protobuf:protobuf-javalite:3.17.3' sdkProprietaryImplementation 'com.google.protobuf:protobuf-javalite:3.17.3' testImplementation 'junit:junit:4.13.2' - testImplementation "org.mockito:mockito-core:3.11.1" - testImplementation "io.mockk:mockk:1.10.6" + testImplementation 'org.mockito:mockito-core:4.3.1' + testImplementation 'io.mockk:mockk:1.12.2' testImplementation 'androidx.test:runner:1.4.0' testImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'junit:junit:4.13.2' diff --git a/sources/Android/android-communications/library/src/main/AndroidManifest.xml b/sources/Android/android-communications/library/src/main/AndroidManifest.xml index 1aa3e64a..503a8cca 100755 --- a/sources/Android/android-communications/library/src/main/AndroidManifest.xml +++ b/sources/Android/android-communications/library/src/main/AndroidManifest.xml @@ -1,8 +1,34 @@ + + - - - + + + + + + + + + + + + + diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/exceptions/BleStartScanError.kt b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/exceptions/BleStartScanError.kt index 226ef99a..9d93e9f3 100644 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/exceptions/BleStartScanError.kt +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/exceptions/BleStartScanError.kt @@ -1,3 +1,3 @@ package com.polar.androidcommunications.api.ble.exceptions -class BleStartScanError(message: String, val error: Int) : Exception("$message failed with error: $error") \ No newline at end of file +class BleStartScanError(message: String) : Exception(message) \ No newline at end of file diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/BlePMDClient.kt b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/BlePMDClient.kt index 4571574c..0cbe1f81 100644 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/BlePMDClient.kt +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/BlePMDClient.kt @@ -517,7 +517,7 @@ class BlePMDClient(txInterface: BleGattTxInterface) : BleGattBase(txInterface, P var offset = 0 var channelCount = 0 val mask = -0x1 shl resolution - 1 - val resolutionInBytes = Math.ceil(resolution / 8.0).toInt() + val resolutionInBytes = ceil(resolution / 8.0).toInt() while (channelCount++ < channels) { var sample: Int if (type == PmdDataFieldEncoding.SIGNED_INT) { diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/PmdControlPointResponse.kt b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/PmdControlPointResponse.kt index 40ae2d2a..9ef19120 100644 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/PmdControlPointResponse.kt +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/PmdControlPointResponse.kt @@ -5,17 +5,11 @@ import java.io.ByteArrayOutputStream class PmdControlPointResponse(data: ByteArray) { val responseCode: Byte = data[0] val opCode: PmdControlPointCommand = PmdControlPointCommand.values()[data[1].toInt()] - val measurementType: Byte - - @JvmField - val status: PmdControlPointResponseCode - - @JvmField + val measurementType: Byte = data[2] + val status: PmdControlPointResponseCode = PmdControlPointResponseCode.values()[data[3].toInt()] + val more: Boolean val parameters = ByteArrayOutputStream() - @JvmField - var more = false - enum class PmdControlPointResponseCode(val numVal: Int) { SUCCESS(0), ERROR_INVALID_OP_CODE(1), @@ -34,8 +28,6 @@ class PmdControlPointResponse(data: ByteArray) { } init { - measurementType = data[2] - status = PmdControlPointResponseCode.values()[data[3].toInt()] if (status == PmdControlPointResponseCode.SUCCESS) { more = data.size > 4 && data[4] != 0.toByte() if (data.size > 5) { diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgData.kt b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgData.kt index ab8879b4..7b1519b2 100644 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgData.kt +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgData.kt @@ -27,9 +27,9 @@ class PpgData internal constructor(val timeStamp: Long) { // PPG Data frame type 4 data class PpgDataSampleFrameType4 internal constructor( - val channel1GainTs: List, - val channel2GainTs: List, - val numIntTs: List + val numIntTs: List, + val channel1GainTs: List, + val channel2GainTs: List ) : PpgDataSample() // PPG Data frame type 5 @@ -86,18 +86,16 @@ class PpgData internal constructor(val timeStamp: Long) { val ppgData = PpgData(timeStamp) var offset = 0 while (offset < frame.size) { - val channel1GainTs = frame.sliceArray(offset..(offset + 11)).map { (it and 0x07).toInt() } - offset += 12 - val channel2GainTs = frame.sliceArray(offset..(offset + 11)).map { (it and 0x07).toInt() } - offset += 12 val numIntTs = frame.sliceArray(offset..(offset + 11)).map { it.toUByte().toUInt() } offset += 12 - + val channel1GainTs = frame.sliceArray(offset..(offset + 23)).toList().mapIndexedNotNull { idx, v -> if (idx % 2 == 0) (v and 0x07).toUInt() else null } + val channel2GainTs = frame.sliceArray(offset..(offset + 23)).toList().mapIndexedNotNull { idx, v -> if (idx % 2 == 1) (v and 0x07).toUInt() else null } + offset += 24 ppgData.ppgSamples.add( PpgDataSampleFrameType4( + numIntTs = numIntTs, channel1GainTs = channel1GainTs, - channel2GainTs = channel2GainTs, - numIntTs = numIntTs + channel2GainTs = channel2GainTs ) ) } diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/psftp/BlePsFtpUtils.java b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/psftp/BlePsFtpUtils.java index 9a92327c..fc02a7fb 100644 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/psftp/BlePsFtpUtils.java +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/api/ble/model/gatt/client/psftp/BlePsFtpUtils.java @@ -9,8 +9,6 @@ import java.util.List; import java.util.UUID; -import protocol.PftpError; - /** * RFC76 and RFC 60 related utils */ @@ -61,7 +59,7 @@ public static class PftpResponseError extends Exception { private final int error; public PftpResponseError(String detailMessage, int error) { - super(detailMessage + " Error: " + error + " : " + PftpError.PbPFtpError.forNumber(error)); + super(detailMessage + " Error: " + error); this.error = error; } diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceListenerImpl.java b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceListenerImpl.java index 285b6412..3a3bf1ec 100755 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceListenerImpl.java +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDDeviceListenerImpl.java @@ -269,11 +269,11 @@ public boolean isScanningNeeded() { } @Override - public void scanStartError(int error) { - RxUtils.postError(observers, new BleStartScanError("scan start failed ", error)); + public void scanStartError(@NonNull String error) { + RxUtils.postError(observers, new BleStartScanError(error)); } - public void deviceDiscovered(BluetoothDevice device, int rssi, byte[] scanRecord, BleUtils.EVENT_TYPE type) { + public void deviceDiscovered(BluetoothDevice device, int rssi, @NonNull byte[] scanRecord, @NonNull BleUtils.EVENT_TYPE type) { BDDeviceSessionImpl deviceSession = sessions.getSession(device); HashMap advData = BleUtils.advertisementBytes2Map(scanRecord); final String manufacturer = Build.MANUFACTURER; diff --git a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDScanCallback.kt b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDScanCallback.kt index 57f682bb..e63be4c7 100755 --- a/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDScanCallback.kt +++ b/sources/Android/android-communications/library/src/main/java/com/polar/androidcommunications/enpoints/ble/bluedroid/host/BDScanCallback.kt @@ -52,8 +52,8 @@ internal class BDScanCallback( private var opportunisticScanTimer: Disposable? = null internal interface BDScanCallbackInterface { - fun deviceDiscovered(device: BluetoothDevice?, rssi: Int, scanRecord: ByteArray?, type: EVENT_TYPE?) - fun scanStartError(error: Int) + fun deviceDiscovered(device: BluetoothDevice?, rssi: Int, scanRecord: ByteArray, type: EVENT_TYPE) + fun scanStartError(error: String) fun isScanningNeeded(): Boolean } @@ -102,8 +102,9 @@ internal class BDScanCallback( } override fun onScanFailed(errorCode: Int) { - BleLogger.e(TAG, "START scan error: $errorCode") - scanCallbackInterface.scanStartError(errorCode) + val scanFailureString = "Scan start failed to ScanCallback errorCode: $errorCode" + BleLogger.e(TAG, scanFailureString) + scanCallbackInterface.scanStartError(scanFailureString) } } @@ -131,6 +132,7 @@ internal class BDScanCallback( private fun scannerIdleState(action: ScanAction) { when (action) { ScanAction.ENTRY -> { + bluetoothAdapter.isEnabled if (bluetoothAdapter.isEnabled && scanCallbackInterface.isScanningNeeded()) { changeState(ScannerState.SCANNING) } @@ -297,7 +299,9 @@ internal class BDScanCallback( try { bluetoothAdapter.bluetoothLeScanner.startScan(filters, scanSettings, leScanCallback) } catch (e: Exception) { - BleLogger.e(TAG, "Failed to start scan e: " + e.localizedMessage) + val errorString = "Failed to start scan. Reason: ${e.message}" + BleLogger.e(TAG, errorString) + scanCallbackInterface.scanStartError(errorString) changeState(ScannerState.IDLE) return } diff --git a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt index c8fe39d9..cf732258 100644 --- a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt +++ b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/PolarBleApiDefaultImpl.kt @@ -25,6 +25,6 @@ object PolarBleApiDefaultImpl { */ @JvmStatic fun versionInfo(): String { - return "3.2.3" + return "3.2.7" } } \ No newline at end of file diff --git a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/model/PolarAccelerometerData.java b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/model/PolarAccelerometerData.java index 403ac180..92532876 100644 --- a/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/model/PolarAccelerometerData.java +++ b/sources/Android/android-communications/library/src/sdk/java/com/polar/sdk/api/model/PolarAccelerometerData.java @@ -12,15 +12,15 @@ public class PolarAccelerometerData { public static class PolarAccelerometerDataSample { /** - * x axis in millig + * x axis in millig (including gravity) */ public final int x; /** - * y axis in millig + * y axis in millig (including gravity) */ public final int y; /** - * z axis in millig + * z axis in millig (including gravity) */ public final int z; diff --git a/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/TestConnectionHandler.java b/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/TestConnectionHandler.java index 20f700e0..6c48fc26 100644 --- a/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/TestConnectionHandler.java +++ b/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/TestConnectionHandler.java @@ -17,7 +17,7 @@ public class TestConnectionHandler { private ConnectionHandler connectionHandler; - private ConnectionInterface connectionInterface = new ConnectionInterface() { + private final ConnectionInterface connectionInterface = new ConnectionInterface() { @Override public void connectDevice(BDDeviceSessionImpl session) { @@ -56,7 +56,7 @@ public void testConnectionHandler_1() { BDDeviceSessionImpl bleDeviceSession = new BDDeviceSessionImpl(); connectionHandler.connectDevice(bleDeviceSession, true); connectionHandler.deviceConnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); } @@ -64,13 +64,13 @@ public void testConnectionHandler_1() { public void testConnectionHandler_2() { BDDeviceSessionImpl bleDeviceSession = new BDDeviceSessionImpl(); connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); connectionHandler.deviceDisconnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); connectionHandler.advertisementHeadReceived(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); } @Test @@ -88,35 +88,35 @@ public boolean isConnectableAdvertisement() { // multi connections connectionHandler.connectDevice(bleDeviceSession, true); connectionHandler.connectDevice(bleDeviceSession2, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession2.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); connectionHandler.advertisementHeadReceived(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession2.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession2.getSessionState()); // multi disconnection connectionHandler.disconnectDevice(bleDeviceSession); connectionHandler.disconnectDevice(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession2.getSessionState()); connectionHandler.deviceDisconnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSED, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession2.getSessionState()); connectionHandler.deviceDisconnected(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSED, bleDeviceSession2.getSessionState()); // multi connect / disconnect bleDeviceSession2.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN); connectionHandler.connectDevice(bleDeviceSession, true); connectionHandler.disconnectDevice(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession2.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession2.getSessionState()); connectionHandler.deviceDisconnected(bleDeviceSession2); // maintaining multi connections @@ -124,77 +124,77 @@ public boolean isConnectableAdvertisement() { bleDeviceSession2.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN); connectionHandler.deviceDisconnected(bleDeviceSession); connectionHandler.deviceDisconnected(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession2.getSessionState()); connectionHandler.advertisementHeadReceived(bleDeviceSession); connectionHandler.advertisementHeadReceived(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession2.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession2.getSessionState()); connectionHandler.advertisementHeadReceived(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession2.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession2); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); - Assert.assertEquals(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession2.getSessionState()); // same state tests bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN); connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED); connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN, bleDeviceSession.getSessionState()); bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED); connectionHandler.disconnectDevice(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSED, bleDeviceSession.getSessionState()); bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN); connectionHandler.disconnectDevice(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession.getSessionState()); connectionHandler.disconnectDevice(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession.getSessionState()); connectionHandler.deviceDisconnected(bleDeviceSession); // bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED); connectTable[0] = false; connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); connectionHandler.advertisementHeadReceived(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); connectTable[0] = true; connectionHandler.advertisementHeadReceived(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPENING, bleDeviceSession.getSessionState()); connectionHandler.deviceConnected(bleDeviceSession); // connectionHandler.disconnectDevice(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSING, bleDeviceSession.getSessionState()); connectionHandler.connectDevice(bleDeviceSession, true); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); connectionHandler.deviceDisconnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED); connectionHandler.connectDevice(bleDeviceSession, false); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN); connectionHandler.setAutomaticReconnection(false); connectionHandler.deviceDisconnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_CLOSED, bleDeviceSession.getSessionState()); bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN); connectionHandler.setAutomaticReconnection(true); connectionHandler.deviceDisconnected(bleDeviceSession); - Assert.assertEquals(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK); + Assert.assertEquals(BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK, bleDeviceSession.getSessionState()); } } diff --git a/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgDataTest.kt b/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgDataTest.kt index 9d9102b9..0bc8c605 100644 --- a/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgDataTest.kt +++ b/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/PpgDataTest.kt @@ -56,33 +56,41 @@ class PpgDataTest { @Test fun `test raw PPG frame type 4`() { // Arrange - // HEX: 00 01 02 03 04 05 06 07 08 09 0A 0B - // F8 FF 00 01 00 02 02 00 02 03 00 07 - // 06 02 06 02 06 03 03 04 02 03 01 01 + // HEX: 02 7F 06 02 06 04 02 06 03 02 01 FF + // 01 07 FF 00 00 00 00 00 00 00 00 01 + // 00 7F 00 00 00 00 00 00 01 02 EF F8 // index type data: - // 0..11: channel1 Gain Ts 00 01 02 03 04 05 06 07 08 09 0A 0B - // 12..23: channel2 Gain Ts F8 FF 00 01 00 02 02 00 02 03 00 07 - // 24..35: num Int Ts 00 7F 00 00 00 02 02 00 02 03 00 FF + // 0..11: num Int Ts1-12 02 7F 06 02 06 04 02 06 03 02 01 FF + // 12: channel1 Gain Ts1 01 => 1 + // 13: channel2 Gain Ts1 07 => 7 + // 14: channel1 Gain Ts2 FF => 7 + // 15: channel2 Gain Ts2 00 => 0 + // .. + // 32: channel1 Gain Ts11 01 => 1 + // 33: channel2 Gain Ts11 02 => 2 + // 34: channel1 Gain Ts12 EF => 7 + // 35: channel2 Gain Ts12 F8 => 0 val frameType = BlePMDClient.PmdDataFrameType.TYPE_4 val isCompressed = false val timeStamp: Long = 0 - val expectedChannel1GainTs0 = 0 - val expectedChannel1GainTs11 = 0x3 - val expectedChannel2GainTs0 = 0 - val expectedChannel2GainTs1 = 7 - val expectedChannel2GainTs11 = 7 - val expectedNumIntTs0 = 0u - val expectedNumIntTs1 = 127u - val expectedNumIntTs11 = 0xFFu + val expectedNumIntTs1 = 2u + val expectedNumIntTs2 = 0x7Fu + val expectedNumIntTs12 = 0xFFu + + val expectedChannel1GainTs1 = 1u + val expectedChannel2GainTs1 = 7u + val expectedChannel1GainTs2 = 7u + val expectedChannel2GainTs2 = 0u + val expectedChannel1GainTs11 = 1u + val expectedChannel2GainTs11 = 2u + val expectedChannel1GainTs12 = 7u + val expectedChannel2GainTs12 = 0u val measurementFrame = byteArrayOf( - 0x00.toByte(), 0x01.toByte(), 0x02.toByte(), 0x03.toByte(), 0x04.toByte(), 0x05.toByte(), 0x06.toByte(), - 0x07.toByte(), 0x08.toByte(), 0x09.toByte(), 0x0A.toByte(), 0x0B.toByte(), - 0xF8.toByte(), 0xFF.toByte(), 0x00.toByte(), 0x01.toByte(), 0x00.toByte(), 0x02.toByte(), 0x02.toByte(), - 0x00.toByte(), 0x02.toByte(), 0x03.toByte(), 0x00.toByte(), 0x07.toByte(), - 0x00.toByte(), 0x7F.toByte(), 0x06.toByte(), 0x02.toByte(), 0x06.toByte(), 0x03.toByte(), 0x03.toByte(), - 0x04.toByte(), 0x02.toByte(), 0x03.toByte(), 0x01.toByte(), 0xFF.toByte() + 0x02.toByte(), 0x7F.toByte(), 0x06.toByte(), 0x02.toByte(), 0x06.toByte(), 0x04.toByte(), 0x02.toByte(), 0x06.toByte(), 0x03.toByte(), 0x02.toByte(), 0x01.toByte(), 0xFF.toByte(), + 0x01.toByte(), 0x07.toByte(), 0xFF.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x01.toByte(), + 0xF8.toByte(), 0x7F.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x01.toByte(), 0x02.toByte(), 0xEF.toByte(), 0xF8.toByte(), ) // Act @@ -96,19 +104,23 @@ class PpgDataTest { // Assert Assert.assertEquals(1, ppgData.ppgSamples.size) + + Assert.assertEquals(12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs.size) + Assert.assertEquals(expectedNumIntTs1, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs[0]) + Assert.assertEquals(expectedNumIntTs2, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs[1]) + Assert.assertEquals(expectedNumIntTs12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs[11]) + Assert.assertEquals(12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs.size) - Assert.assertEquals(expectedChannel1GainTs0, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs[0]) - Assert.assertEquals(expectedChannel1GainTs11, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs[11]) + Assert.assertEquals(expectedChannel1GainTs1, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs[0]) + Assert.assertEquals(expectedChannel1GainTs2, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs[1]) + Assert.assertEquals(expectedChannel1GainTs11, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs[10]) + Assert.assertEquals(expectedChannel1GainTs12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel1GainTs[11]) Assert.assertEquals(12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs.size) - Assert.assertEquals(expectedChannel2GainTs0, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[0]) - Assert.assertEquals(expectedChannel2GainTs1, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[1]) - Assert.assertEquals(expectedChannel2GainTs11, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[11]) - - Assert.assertEquals(12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs.size) - Assert.assertEquals(expectedNumIntTs0, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs[0]) - Assert.assertEquals(expectedNumIntTs1, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs[1]) - Assert.assertEquals(expectedNumIntTs11, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).numIntTs[11]) + Assert.assertEquals(expectedChannel2GainTs1, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[0]) + Assert.assertEquals(expectedChannel2GainTs2, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[1]) + Assert.assertEquals(expectedChannel2GainTs11, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[10]) + Assert.assertEquals(expectedChannel2GainTs12, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleFrameType4).channel2GainTs[11]) } @Test @@ -123,7 +135,7 @@ class PpgDataTest { val timeStamp: Long = 0 val expectedOperationMode = 0xFFFFFFFFu - val measurementFrame = byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(),) + val measurementFrame = byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte()) // Act val ppgData = PpgData.parseDataFromDataFrame( @@ -144,7 +156,7 @@ class PpgDataTest { // Arrange // HEX: 2C 2D 00 C2 77 00 D3 D2 FF 3D 88 FF 0A 29 B2 F0 EE 34 11 B2 EC EE 74 11 B1 E8 FE B4 11 B1 E8 FE B4 11 B1 E0 FE 34 12 B0 DC 0E 75 12 B0 D8 0E B5 12 AF D4 1E F5 12 AF D0 1E 35 13 AE CC 2E 75 13 AE C8 2E B5 13 AD C4 3E F5 13 AD BC 3E 75 14 AD BC 3E 75 14 AC B8 4E B5 14 AC B4 4E F5 14 AB B0 5E 35 15 AA AC 6E 75 15 AA A8 6E B5 15 AA A4 6E F5 15 A9 A0 7E 35 16 A9 9C 7E 75 16 A8 98 8E B5 16 A7 94 9E F5 16 A7 90 9E 35 17 A7 8C 9E 75 17 A6 88 AE B5 17 A5 88 BE B5 17 A5 80 BE 35 18 A4 7C CE 75 18 A4 78 CE B5 18 A3 78 DE B5 18 A2 70 EE 35 19 A2 6C EE 75 19 A2 6C EE 75 19 A1 68 FE B5 19 A0 60 0E 36 1A 9F 60 1E 36 1A 9F 5C 1E 76 1A 9F 58 1E B6 1A 9D 54 3E F6 1A // index type data: - // 0-11: Reference sample 0x2C 0x2D 0x00 0xC2 0x77 0x00 0xD3 0xD2 0xFF 0x3D 0x88 0xFF + // 0..11: Reference sample 0x2C 0x2D 0x00 0xC2 0x77 0x00 0xD3 0xD2 0xFF 0x3D 0x88 0xFF // Sample 0 (aka. reference sample): // channel 0: 2C 2D 00 => 0x002D2C => 11564 val refSample0Channel0 = 11564 @@ -221,143 +233,66 @@ class PpgDataTest { @Test fun `test compressed PPG frame type 7`() { - //HEX: 09 AE 20 - // 8A 7C 23 0 - // 58 3B 19 1 - // 80 B9 18 2 - // DB 2E 22 3 - // FA 88 1D 4 - // D7 BB 18 5 - // C2 B8 1F 6 - // 7A 44 26 7 - // 48 DF 23 8 - // A1 F2 17 9 - // 3A 37 1B 10 - // FF FF 00 11 - // 7C 08 00 12 - // 70 F5 02 13 + + // HEX: + // 09 AE 20 0 + // 8A 7C 23 1 + // 58 3B 19 2 + // 80 B9 18 3 + // DB 2E 22 4 + // FA 88 1D 5 + // D7 BB 18 6 + // C2 B8 1F 7 + // 7A 44 26 8 + // 48 DF 23 9 + // A1 F2 17 10 + // 3A 37 1B 11 + // FF FF 00 12 + // 7C 08 00 13 + // 70 F5 02 14 // FF FF 00 15 // 28 C4 11 16 // 18 // 01 - // 87 - // FE FF EC 02 00 01 FE FF FB 00 00 8D F9 FF B1 FF FF 0C FE FF 26 FE FF EE FE FF 89 02 00 DF 02 00 51 FE FF 00 00 00 00 00 00 00 00 00 00 00 00 AE A6 8F - // index type data: - // 0..3 Sample 0 - channel 0 (ref. sample) 09 AE 20 (0x20AE09 = 2141705) - // 0..3 Sample 0 - channel 15 (ref. sample) FF FF 00 (0x00FFFF = 65535) - // 0..3 Sample 0 - status (ref. sample) 28 C4 11 (0x11C428 = 1164328) + // 87 FE FF EC 02 00 01 FE FF FB 00 00 8D F9 FF B1 FF FF 0C FE FF 26 FE FF EE FE FF 89 02 00 DF 02 00 51 FE FF 00 00 00 00 00 00 00 00 00 00 00 00 AE A6 8F + + // index type data: + // 0..50: Reference sample 09 AE 20 ... + // Sample 0 (aka. reference sample): + // channel 0: 09 AE 20 => 0x20AE09 = 2141705 + val sample0Channel0 = 2141705 + // channel 1: 8A 7C 23 => 0x237C8A = 2325642 + val sample0Channel1 = 2325642 + // channel 15: FF FF 00 => 0x00FFFF = 65535 + val sample0Channel15 = 65535 + // status: 28 C4 11 => 0x11C428 = 1164328 + val sample0ChannelStatus = 1164328u + // 51: Delta size + // 52: Samples amount + // Delta dump: 18 01 | 87 FE FF EC 02 00 01 FE ... + // 51: Delta size size 1: 0x18 (24 bits) val amountOfSamples = 1 + 1 // reference sample + delta samples - val refSample0Channel0 = 2141705 - val refSample0Channel15 = 65535 - val refSample0ChannelStatus = 1164328u + // 52: Sample amount size 1: 0x01 (Delta block contains 1 sample) + // 53..55: 0x87 0xFE 0xFF (0xFFFE87 = -377) + val sample1Channel0 = sample0Channel0 - 377 + // 56..58: 0xEC 0x02 0x00 (0x0002EC = 748) + val sample1Channel1 = sample0Channel1 + 748 val factor = 1.0f val timeStamp = 0xFFFL val measurementFrame = byteArrayOf( - 0x09.toByte(), - 0xAE.toByte(), - 0x20.toByte(), - 0x8A.toByte(), - 0x7C.toByte(), - 0x23.toByte(), - 0x58.toByte(), - 0x3B.toByte(), - 0x19.toByte(), - 0x80.toByte(), - 0xB9.toByte(), - 0x18.toByte(), - 0xDB.toByte(), - 0x2E.toByte(), - 0x22.toByte(), - 0xFA.toByte(), - 0x88.toByte(), - 0x1D.toByte(), - 0xD7.toByte(), - 0xBB.toByte(), - 0x18.toByte(), - 0xC2.toByte(), - 0xB8.toByte(), - 0x1F.toByte(), - 0x7A.toByte(), - 0x44.toByte(), - 0x26.toByte(), - 0x48.toByte(), - 0xDF.toByte(), - 0x23.toByte(), - 0xA1.toByte(), - 0xF2.toByte(), - 0x17.toByte(), - 0x3A.toByte(), - 0x37.toByte(), - 0x1B.toByte(), - 0xFF.toByte(), - 0xFF.toByte(), - 0x00.toByte(), - 0x7C.toByte(), - 0x08.toByte(), - 0x00.toByte(), - 0x70.toByte(), - 0xF5.toByte(), - 0x02.toByte(), - 0xFF.toByte(), - 0xFF.toByte(), - 0x00.toByte(), - 0x28.toByte(), - 0xC4.toByte(), - 0x11.toByte(), - 0x18.toByte(), - 0x01.toByte(), - 0x87.toByte(), - 0xFE.toByte(), - 0xFF.toByte(), - 0xEC.toByte(), - 0x02.toByte(), - 0x00.toByte(), - 0x01.toByte(), - 0xFE.toByte(), - 0xFF.toByte(), - 0xFB.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x8D.toByte(), - 0xF9.toByte(), - 0xFF.toByte(), - 0xB1.toByte(), - 0xFF.toByte(), - 0xFF.toByte(), - 0x0C.toByte(), - 0xFE.toByte(), - 0xFF.toByte(), - 0x26.toByte(), - 0xFE.toByte(), - 0xFF.toByte(), - 0xEE.toByte(), - 0xFE.toByte(), - 0xFF.toByte(), - 0x89.toByte(), - 0x02.toByte(), - 0x00.toByte(), - 0xDF.toByte(), - 0x02.toByte(), - 0x00.toByte(), - 0x51.toByte(), - 0xFE.toByte(), - 0xFF.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0x00.toByte(), - 0xAE.toByte(), - 0xA6.toByte(), - 0x8F.toByte() + 0x09.toByte(), 0xAE.toByte(), 0x20.toByte(), 0x8A.toByte(), 0x7C.toByte(), 0x23.toByte(), 0x58.toByte(), 0x3B.toByte(), 0x19.toByte(), + 0x80.toByte(), 0xB9.toByte(), 0x18.toByte(), 0xDB.toByte(), 0x2E.toByte(), 0x22.toByte(), 0xFA.toByte(), 0x88.toByte(), 0x1D.toByte(), + 0xD7.toByte(), 0xBB.toByte(), 0x18.toByte(), 0xC2.toByte(), 0xB8.toByte(), 0x1F.toByte(), 0x7A.toByte(), 0x44.toByte(), 0x26.toByte(), + 0x48.toByte(), 0xDF.toByte(), 0x23.toByte(), 0xA1.toByte(), 0xF2.toByte(), 0x17.toByte(), 0x3A.toByte(), 0x37.toByte(), 0x1B.toByte(), + 0xFF.toByte(), 0xFF.toByte(), 0x00.toByte(), 0x7C.toByte(), 0x08.toByte(), 0x00.toByte(), 0x70.toByte(), 0xF5.toByte(), 0x02.toByte(), + 0xFF.toByte(), 0xFF.toByte(), 0x00.toByte(), 0x28.toByte(), 0xC4.toByte(), 0x11.toByte(), 0x18.toByte(), 0x01.toByte(), 0x87.toByte(), + 0xFE.toByte(), 0xFF.toByte(), 0xEC.toByte(), 0x02.toByte(), 0x00.toByte(), 0x01.toByte(), 0xFE.toByte(), 0xFF.toByte(), 0xFB.toByte(), + 0x00.toByte(), 0x00.toByte(), 0x8D.toByte(), 0xF9.toByte(), 0xFF.toByte(), 0xB1.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0x0C.toByte(), + 0xFE.toByte(), 0xFF.toByte(), 0x26.toByte(), 0xFE.toByte(), 0xFF.toByte(), 0xEE.toByte(), 0xFE.toByte(), 0xFF.toByte(), 0x89.toByte(), + 0x02.toByte(), 0x00.toByte(), 0xDF.toByte(), 0x02.toByte(), 0x00.toByte(), 0x51.toByte(), 0xFE.toByte(), 0xFF.toByte(), 0x00.toByte(), + 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), + 0x00.toByte(), 0x00.toByte(), 0xAE.toByte(), 0xA6.toByte(), 0x8F.toByte() ) // Act val ppgData = PpgData.parseDataFromDataFrame(true, BlePMDClient.PmdDataFrameType.TYPE_7, measurementFrame, factor, timeStamp) @@ -365,8 +300,11 @@ class PpgDataTest { // Assert Assert.assertEquals(amountOfSamples, ppgData.ppgSamples.size) Assert.assertEquals(16, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).ppgDataSamples.size) - Assert.assertEquals(refSample0Channel0, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).ppgDataSamples[0]) - Assert.assertEquals(refSample0Channel15, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).ppgDataSamples[15]) - Assert.assertEquals(refSample0ChannelStatus, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).status) + Assert.assertEquals(sample0Channel0, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).ppgDataSamples[0]) + Assert.assertEquals(sample0Channel1, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).ppgDataSamples[1]) + Assert.assertEquals(sample0Channel15, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).ppgDataSamples[15]) + Assert.assertEquals(sample0ChannelStatus, (ppgData.ppgSamples[0] as PpgData.PpgDataSampleType2).status) + Assert.assertEquals(sample1Channel0, (ppgData.ppgSamples[1] as PpgData.PpgDataSampleType2).ppgDataSamples[0]) + Assert.assertEquals(sample1Channel1, (ppgData.ppgSamples[1] as PpgData.PpgDataSampleType2).ppgDataSamples[1]) } } \ No newline at end of file diff --git a/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/TemperatureDataTest.kt b/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/TemperatureDataTest.kt index 7600740d..f3bf4822 100644 --- a/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/TemperatureDataTest.kt +++ b/sources/Android/android-communications/library/src/test/java/com/polar/androidcommunications/api/ble/model/gatt/client/pmd/model/TemperatureDataTest.kt @@ -3,7 +3,7 @@ package com.polar.androidcommunications.api.ble.model.gatt.client.pmd.model import com.polar.androidcommunications.api.ble.model.gatt.client.pmd.BlePMDClient import org.junit.Assert import org.junit.Test -import java.lang.Float +import java.lang.Float.intBitsToFloat class TemperatureDataTest { @Test @@ -20,9 +20,9 @@ class TemperatureDataTest { val expectedSamplesSize = 1 + 2 // reference sample + delta samples val expectedTimeStamp = 578437695752307201L - val sample0 = Float.intBitsToFloat(0x41DC51EC) - val sample1 = Float.intBitsToFloat(0x41DC51EC + 0x0) - val sample2 = Float.intBitsToFloat(0x41DC51EC + 0x0) + val sample0 = intBitsToFloat(0x41DC51EC) + val sample1 = intBitsToFloat(0x41DC51EC + 0x0) + val sample2 = intBitsToFloat(0x41DC51EC + 0x0) val measurementFrame = byteArrayOf( 0xEC.toByte(), 0x51.toByte(), 0xDC.toByte(), 0x41.toByte(), 0x03.toByte(), 0x02.toByte(), 0x00.toByte() @@ -52,7 +52,7 @@ class TemperatureDataTest { val frameType = BlePMDClient.PmdDataFrameType.TYPE_0 val isCompressed = false val expectedSamplesSize = 1 - val sample0 = Float.intBitsToFloat(0x41C028F6) + val sample0 = intBitsToFloat(0x41C028F6) val measurementFrame = byteArrayOf(0xF6.toByte(), 0x28.toByte(), 0xC0.toByte(), 0x41.toByte()) val factor = 1.0f