@Test public void producesValidSensorLog() { Faker faker = new Faker(); int pressure = faker.number().numberBetween(-100000, 100000); float decimal = (float)faker.number().randomDouble(4, 0, 1); byte[] pressureBytes = Ints.toByteArray(pressure); SensorConfig config = new SensorConfig("someId", "thingy",null); ReplayProcessor<SensorLog> processor = ReplayProcessor.create(10); PressureNotification notification = new PressureNotification(config, processor); notification.run(new byte[] { pressureBytes[3], pressureBytes[2], pressureBytes[1], pressureBytes[0], (byte)(decimal * 256) }); SensorLog createdLog = processor.blockingFirst(); assertThat(createdLog).isNotNull(); assertThat(createdLog.getSensorId()).matches(config.getId()); assertThat(createdLog.getAttributeValue()).containsKey(PressureNotification.PRESSURE_VALUE_ID); assertThat((float)createdLog.getAttributeValue().get(PressureNotification.PRESSURE_VALUE_ID)).isWithin(0.01f).of(pressure + decimal); }
@Override public void run(byte[] bytes) { float pressure = decodePressure(bytes); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(PRESSURE_VALUE_ID, pressure)); processor.onNext(sensorLog); }
PressureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float pressure = decodePressure(bytes); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(PRESSURE_VALUE_ID, pressure)); processor.onNext(sensorLog); } }
PressureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float pressure = decodePressure(bytes); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(PRESSURE_VALUE_ID, pressure)); processor.onNext(sensorLog); } PressureNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); }
PressureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float pressure = decodePressure(bytes); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(PRESSURE_VALUE_ID, pressure)); processor.onNext(sensorLog); } PressureNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); }
PressureNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float pressure = decodePressure(bytes); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(PRESSURE_VALUE_ID, pressure)); processor.onNext(sensorLog); } PressureNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); static final String PRESSURE_VALUE_ID; }