Bool extends Ordinal { public Boolean boolValue() { if(category != null) { return ((BoolScale)scale).isTrue(category); } else if(rawValue != null) { return (rawValue == 0 ? false : true); } else { return null; } } Bool(EepDataField dataField, BoolScale scale);  Bool(EepDataField dataField, boolean rawValue); static Bool createBoolWithRange(String name, int offset, int size,
                                         String trueName, int trueMin, int trueMax,
                                         String falseName, int falseMin, int falseMax); static Bool createBool(String name, int offset, int size,
                                String trueName, int trueValue,
                                String falseName, int falseValue); static Bool createTeachInFlag4BS(); Boolean boolValue(); @Override void updateSensor(Sensor sensor);  }
@Test public void testBasicConstruction() throws Exception { EepDataField dataField = new EepDataField("EDF1", 7, 1); ScaleCategory trueCategory = new ScaleCategory("True category" , 1, 1, "on", 1); ScaleCategory falseCategory = new ScaleCategory("False category" , 0, 0, "off", 0); BoolScale scale = new BoolScale(trueCategory, falseCategory); Bool b = new Bool(dataField, scale); Assert.assertNull(b.boolValue()); b = new Bool(dataField, false); Assert.assertFalse(b.boolValue()); b = new Bool(dataField, true); Assert.assertTrue(b.boolValue()); }
@Test public void testUpdateValue() throws Exception { EepDataField dataField = new EepDataField("EDF1", 7, 1); ScaleCategory trueCategory = new ScaleCategory("True category" , 1, 1, "on", 1); ScaleCategory falseCategory = new ScaleCategory("False category" , 0, 0, "off", 0); BoolScale scale = new BoolScale(trueCategory, falseCategory); Bool bool = new Bool(dataField, scale); EepData data = new EepData(EepType.EEP_TYPE_F60201, 1, bool); data.update(new byte[] {0x01}); Assert.assertTrue(bool.boolValue()); data.update(new byte[] {0x00}); Assert.assertFalse(bool.boolValue()); trueCategory = new ScaleCategory("True category" , 0, 0, "on", 1); falseCategory = new ScaleCategory("False category" , 1, 1, "off", 0); scale = new BoolScale(trueCategory, falseCategory); bool = new Bool(dataField, scale); data = new EepData(EepType.EEP_TYPE_F60201, 1, bool); data.update(new byte[] {0x01}); Assert.assertFalse(bool.boolValue()); data.update(new byte[] {0x00}); Assert.assertTrue(bool.boolValue()); dataField = new EepDataField("EDF1", 0, 8); trueCategory = new ScaleCategory("True category" , 0, 5, "on", 1); falseCategory = new ScaleCategory("False category" , 6, 9, "off", 0); scale = new BoolScale(trueCategory, falseCategory); bool = new Bool(dataField, scale); data = new EepData(EepType.EEP_TYPE_F60201, 1, bool); data.update(new byte[] {0x00}); Assert.assertTrue(bool.boolValue()); data.update(new byte[] {0x05}); Assert.assertTrue(bool.boolValue()); data.update(new byte[] {0x06}); Assert.assertFalse(bool.boolValue()); data.update(new byte[] {0x09}); Assert.assertFalse(bool.boolValue()); data.update(new byte[] {(byte)0xFF}); Assert.assertFalse(bool.boolValue()); }