Range implements DataType, EepDataListener { public Double rangeValue() { if(scaledValue != null) { return scaledValue.doubleValue(); } else if(rawValue != null) { return (double)rawValue; } else { return null; } } Range(EepDataField dataField, LinearScale scale);  Range(EepDataField dataField, int rawValue); static Range createRange(String name, int offset, int size,
                                  int rawDataRangeMin, int rawDataRangeMax,
                                  double unitsDataRangeMin, double unitsDataRangeMax,
                                  int fractionalDigits); Double rangeValue(); @Override void didUpdateData(EepData data); @Override void updateData(EepData data); @Override void updateSensor(Sensor sensor);  }
@Test public void testBasicConstruction() throws Exception { EepDataField dataField = new EepDataField("EDF1", 0, 8); DataRange rawDataRange = new DataRange(0, 255); DataRange unitsDataRange = new DataRange(0, 100); LinearScale scale = new LinearScale(rawDataRange, unitsDataRange, 2); Range range = new Range(dataField, scale); Assert.assertNull(range.rangeValue()); range = new Range(dataField, 100); Assert.assertEquals(100, range.rangeValue().intValue()); }
@Test public void testUpdateValue() throws Exception { EepDataField dataField = new EepDataField("EDF1", 0, 8); DataRange rawDataRange = new DataRange(0, 255); DataRange unitsDataRange = new DataRange(0, 100); LinearScale scale = new LinearScale(rawDataRange, unitsDataRange, 2); Range range = new Range(dataField, scale); EepData data = new EepData(EepType.EEP_TYPE_F60201, 1, range); data.update(new byte[] {0x00}); Assert.assertEquals(0.0, range.rangeValue(), 0.0); data.update(new byte[] {(byte)0xFF}); Assert.assertEquals(100.0, range.rangeValue(), 0.0); }
@Test public void testUpdateWithOutOfRangeValue() throws Exception { EepDataField dataField = new EepDataField("EDF1", 0, 8); DataRange rawDataRange = new DataRange(0x05, 0x0A); DataRange unitsDataRange = new DataRange(0, 100); LinearScale scale = new LinearScale(rawDataRange, unitsDataRange, 2); Range range = new Range(dataField, scale); EepData data = new EepData(EepType.EEP_TYPE_F60201, 1, range); data.update(new byte[] {0x00}); Assert.assertNull(range.rangeValue()); data.update(new byte[] {0x0A}); Assert.assertEquals(100.0, range.rangeValue(), 0.0); data.update(new byte[] {0x0B}); Assert.assertEquals(100.0, range.rangeValue(), 0.0); }