Wheellog/Wheellog.Android

Inmotion way of querying

christophedemey opened this issue · 1 comments

Hi

I was hoping to get some info on how to correctly query the inmotion v11.
I have browsed the code but am still a bit lost, i am trying to read out the speed in c#.
So far i found that we are connecting to the device targetting the service
{ "6e400001-b5a3-f393-e0a9-e50e24dcca9e", "INMOTION_V2_SERVICE_UUID" },
Then we need to write the command : RealTimeInfo = 0x04,
But then i am lost at what characteristic we are writing and where the data comes from. :(
Any help is greatly appreciated.

Thanks

@christophedemey you're right. INMOTION_V2_SERVICE_UUID used for send command into device service.
The messages sends and accepted in the service BluetoothLeService. For v11 commands sends in INMOTION_V2_SERVICE_UUID -> INMOTION_V2_WRITE_CHARACTER_UUID

case INMOTION_V2:
BluetoothGattService inv2_service = this.mBluetoothGatt.getService(UUID.fromString(Constants.INMOTION_V2_SERVICE_UUID));
if (inv2_service == null) {
Timber.i("writeBluetoothGattCharacteristic service == null");
return false;
}
BluetoothGattCharacteristic inv2_characteristic = inv2_service.getCharacteristic(UUID.fromString(Constants.INMOTION_V2_WRITE_CHARACTER_UUID));
if (inv2_characteristic == null) {
Timber.i("writeBluetoothGattCharacteristic characteristic == null");
return false;
}
inv2_characteristic.setValue(cmd);
Timber.i("writeBluetoothGattCharacteristic writeType = %d", inv2_characteristic.getWriteType());
return this.mBluetoothGatt.writeCharacteristic(inv2_characteristic);

RealTimeInfo message - it is a byte array { 0xAA, 0xAA, 0x14, 0x01, 0x04, 0x11 }

AAAA - header
14 - type message = default
01 - length of data
04 - data = RealTimeInfo = 0x04
11 - checksum

You will receive a message in response. We parse it in the decode method.
Also look at the adapter test. It has examples of packages that come from the wheel and the expected result

fun `decode with v11 full data`() {
// Arrange.
val byteArray1 = "AAAA110882010206010201009C".hexToByteArray() // wheel type
val byteArray2 = "AAAA11178202313438304341313232323037303032420000000000FD".hexToByteArray() // s/n
val byteArray3 = "AAAA111D820622080004030F000602214000010110000602230D00010107000001F3".hexToByteArray() //versions
val byteArray4 = "AAAA141AA0207C15C800106464140000000058020000006400001500100010".hexToByteArray() // wtf
val byteArray5 = "AAAA142B900001142614000000803E498AE00FB209D109CEB000C7DF010000BE720000AB1300008F040000AB0600004C".hexToByteArray() // probably statistics
val byteArray6 = "AAAA141991E86C000066191C002DB2040064E60000974D050000C7DF01A4".hexToByteArray() // totals
val byteArray7 = "AAAA143184E61EEB0561094A11AE04A004DF01402958CBB000CE004A010000D4FF7C15641900000000492B00000000000000000000C6".hexToByteArray()
// 18:30:42.272: 278.80 km, 18415.10, 3077.57, 16:23:00, 96:32:23, 50944, 479
// 18:30:42.306: 79.10 V, 15.15 A, 24.01 Km/h, 44.26 Nm, bat 1198 Wh, mot 1184 Wh, 4.79 km, rem 105.60 km, 88%, 0, mos 27 C, mot 0 C, bat -176 C, board 30 C, lamp -176 C, pith 3.3, pithAim 0.0, roll 654.9, spd lim 55.0, cur lim 65.00, bright 0, br light 0, cpu -176 C, imu -176 C
// pc 1, mc 1, mot 1, chrg 0, light 1, decor 1, lifted 0, tail 1, fan 1
// Act.
val result1 = adapter.decode(byteArray1)
val result2 = adapter.decode(byteArray2)
val result3 = adapter.decode(byteArray3)
val result4 = adapter.decode(byteArray4)
val result5 = adapter.decode(byteArray5)
val result6 = adapter.decode(byteArray6)
val result7 = adapter.decode(byteArray7)
// Assert.
assertThat(result1).isFalse()
assertThat(result2).isFalse()
assertThat(result3).isFalse()
assertThat(result4).isFalse()
assertThat(result5).isFalse()
assertThat(result6).isFalse()
assertThat(result7).isTrue()
assertThat(data.serial).isEqualTo("1480CA122207002B")
assertThat(data.model).isEqualTo("Inmotion V11")
assertThat(data.version).isEqualTo("rev: 2.1")
assertThat(data.speedDouble).isEqualTo(24.01)
assertThat(data.temperature).isEqualTo(27)
assertThat(data.temperature2).isEqualTo(30)
assertThat(data.imuTemp).isEqualTo(-176)
assertThat(data.cpuTemp).isEqualTo(-176)
assertThat(data.motorPower).isEqualTo(1184.0)
assertThat(data.currentLimit).isEqualTo(65.00)
assertThat(data.speedLimit).isEqualTo(55.00)
assertThat(data.torque).isEqualTo(44.26)
assertThat(data.voltageDouble).isEqualTo(79.10)
assertThat(data.currentDouble).isEqualTo(15.15)
assertThat(data.wheelDistanceDouble).isEqualTo(4.79)
assertThat(data.totalDistance).isEqualTo(278800)
assertThat(data.batteryLevel).isEqualTo(88)
assertThat(data.powerDouble).isEqualTo(1198.0)
assertThat(data.angle).isEqualTo(3.3)
assertThat(data.roll).isEqualTo(-0.44)
}