@Test public void producesValidSensorLog() { Faker faker = new Faker(); int mantissa = faker.number().numberBetween(0, 4096); int exponent = faker.number().numberBetween(0, 16); float lux = mantissa * (float)Math.pow(2, exponent) / 100.0f; SensorConfig config = new SensorConfig("someId", "thingy", null); ReplayProcessor<SensorLog> processor = ReplayProcessor.create(10); OpticalNotification notification = new OpticalNotification(config, processor); notification.run(new byte[] { (byte)(mantissa & 0xff), (byte)((mantissa >> 8 & 0x0f) | (exponent << 4))}); SensorLog createdLog = processor.blockingFirst(); assertThat(createdLog).isNotNull(); assertThat(createdLog.getSensorId()).matches(config.getId()); assertThat(createdLog.getAttributeValue()).containsKey(OpticalNotification.LIGHT_INTENSITY_VALUE_ID); assertThat((float)createdLog.getAttributeValue().get(OpticalNotification.LIGHT_INTENSITY_VALUE_ID)).isWithin(0.1f).of(lux); }
@Override public void run(byte[] bytes) { float lux = decodeLux(bytes[1], bytes[0]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(LIGHT_INTENSITY_VALUE_ID, lux)); processor.onNext(sensorLog); }
OpticalNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float lux = decodeLux(bytes[1], bytes[0]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(LIGHT_INTENSITY_VALUE_ID, lux)); processor.onNext(sensorLog); } }
OpticalNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float lux = decodeLux(bytes[1], bytes[0]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(LIGHT_INTENSITY_VALUE_ID, lux)); processor.onNext(sensorLog); } OpticalNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); }
OpticalNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float lux = decodeLux(bytes[1], bytes[0]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(LIGHT_INTENSITY_VALUE_ID, lux)); processor.onNext(sensorLog); } OpticalNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); }
OpticalNotification implements BluetoothNotification<byte[]> { @Override public void run(byte[] bytes) { float lux = decodeLux(bytes[1], bytes[0]); SensorLog sensorLog = new SensorLog(config.getId(), ImmutableMap.of(LIGHT_INTENSITY_VALUE_ID, lux)); processor.onNext(sensorLog); } OpticalNotification(SensorConfig config, FlowableProcessor<SensorLog> processor); @Override void run(byte[] bytes); static final String LIGHT_INTENSITY_VALUE_ID; }