Exemplo n.º 1
0
  @Override
  public Sensor.SensorDataSet parseBuffer(byte[] buffer) {
    Sensor.SensorDataSet.Builder sds =
        Sensor.SensorDataSet.newBuilder().setCreationTime(System.currentTimeMillis());

    Sensor.SensorData.Builder heartrate =
        Sensor.SensorData.newBuilder()
            .setValue(buffer[12] & 0xFF)
            .setState(Sensor.SensorState.SENDING);
    sds.setHeartRate(heartrate);

    Sensor.SensorData.Builder batteryLevel =
        Sensor.SensorData.newBuilder().setValue(buffer[11]).setState(Sensor.SensorState.SENDING);
    sds.setBatteryLevel(batteryLevel);

    setCadence(sds, buffer);

    return sds.build();
  }
Exemplo n.º 2
0
  private void setCadence(Sensor.SensorDataSet.Builder sds, byte[] buffer) {
    // Device Firmware ID, Firmware Version, Hardware ID, Hardware Version
    // 0x1A00316550003162 produces erroneous values for Cadence and needs
    // a workaround based on the stride counter.
    // Firmware values range from field 3 to 10 (inclusive) of the byte buffer.
    byte[] hardwareFirmwareId = ApiAdapterFactory.getApiAdapter().copyByteArray(buffer, 3, 11);
    Sensor.SensorData.Builder cadence = Sensor.SensorData.newBuilder();

    if (Arrays.equals(hardwareFirmwareId, CADENCE_BUG_FW_ID)) {
      if (strideReadings == null) {
        strideReadings = new StrideReadings();
      }
      strideReadings.updateStrideReading(buffer[54] & 0xFF);

      if (strideReadings.getCadence() != StrideReadings.CADENCE_NOT_AVAILABLE) {
        cadence.setValue(strideReadings.getCadence()).setState(Sensor.SensorState.SENDING);
      }
    } else {
      cadence
          .setValue(SensorUtils.unsignedShortToIntLittleEndian(buffer, 56) / 16)
          .setState(Sensor.SensorState.SENDING);
    }
    sds.setCadence(cadence);
  }