@Test public void producesValidSensorLog() { Faker faker = new Faker(); int objectTemp = faker.number().numberBetween(-50, 50); float objectTempDecimal = (float)faker.number().randomDouble(4, 0, 1); int ambientTemp = faker.number().numberBetween(-50, 50); float ambientTempDecimal = (float)faker.number().randomDouble(4, 0, 1); int objectTempNorm = ((objectTemp) << 7) | (int)(objectTempDecimal * 128); int ambientTempNorm = ((ambientTemp) << 7) | (int)(ambientTempDecimal * 128); SensorConfig config = new SensorConfig("someId", "sensortag",null); ReplayProcessor<SensorLog> processor = ReplayProcessor.create(10); TemperatureNotification notification = new TemperatureNotification(config, processor); notification.run(new byte[] { (byte)(objectTempNorm & 0xff), (byte)(objectTempNorm >> 8), (byte)(ambientTempNorm & 0xff), (byte)(ambientTempNorm >> 8) }); SensorLog createdLog = processor.blockingFirst(); assertThat(createdLog).isNotNull(); assertThat(createdLog.getSensorId()).matches(config.getId()); assertThat((float)createdLog.getAttributeValue().get(TemperatureNotification.OBJECT_TEMP_VALUE_ID)).isWithin(0.1f).of(objectTemp + objectTempDecimal); assertThat((float)createdLog.getAttributeValue().get(TemperatureNotification.AMBIENT_TEMP_VALUE_ID)).isWithin(0.1f).of(ambientTemp + ambientTempDecimal); }
@Override public void run(byte[] bytes) { float objectTemp = decodeTemperature(bytes[1], bytes[0]); float ambientTemp = decodeTemperature(bytes[3], bytes[2]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(OBJECT_TEMP_VALUE_ID, objectTemp, AMBIENT_TEMP_VALUE_ID, ambientTemp)); processor.onNext(sensorLog); }
TemperatureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float objectTemp = decodeTemperature(bytes[1], bytes[0]); float ambientTemp = decodeTemperature(bytes[3], bytes[2]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(OBJECT_TEMP_VALUE_ID, objectTemp, AMBIENT_TEMP_VALUE_ID, ambientTemp)); processor.onNext(sensorLog); } }
TemperatureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float objectTemp = decodeTemperature(bytes[1], bytes[0]); float ambientTemp = decodeTemperature(bytes[3], bytes[2]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(OBJECT_TEMP_VALUE_ID, objectTemp, AMBIENT_TEMP_VALUE_ID, ambientTemp)); processor.onNext(sensorLog); } TemperatureNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); }
TemperatureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float objectTemp = decodeTemperature(bytes[1], bytes[0]); float ambientTemp = decodeTemperature(bytes[3], bytes[2]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(OBJECT_TEMP_VALUE_ID, objectTemp, AMBIENT_TEMP_VALUE_ID, ambientTemp)); processor.onNext(sensorLog); } TemperatureNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); }
TemperatureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float objectTemp = decodeTemperature(bytes[1], bytes[0]); float ambientTemp = decodeTemperature(bytes[3], bytes[2]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(OBJECT_TEMP_VALUE_ID, objectTemp, AMBIENT_TEMP_VALUE_ID, ambientTemp)); processor.onNext(sensorLog); } TemperatureNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); static final String OBJECT_TEMP_VALUE_ID; static final String AMBIENT_TEMP_VALUE_ID; }