Search in sources :

Example 1 with StringBlock

use of org.openhab.binding.modbus.e3dc.internal.dto.StringBlock in project openhab-addons by openhab.

the class Parser method parse.

public Optional<Data> parse(DataType type) {
    synchronized (bArray) {
        if (type.equals(DataType.INFO) && callbackType.equals(DataType.INFO)) {
            return Optional.of(new InfoBlock(Arrays.copyOfRange(bArray, INFO_REG_START, INFO_REG_SIZE * 2)));
        } else if (type.equals(DataType.POWER) && callbackType.equals(DataType.DATA)) {
            int start = (POWER_REG_START - INFO_REG_SIZE) * 2;
            int end = start + POWER_REG_SIZE * 2;
            return Optional.of(new PowerBlock(Arrays.copyOfRange(bArray, start, end)));
        } else if (type.equals(DataType.EMERGENCY) && callbackType.equals(DataType.DATA)) {
            int start = (EMS_REG_START - INFO_REG_SIZE) * 2;
            int end = start + EMS_REG_SIZE * 2;
            return Optional.of(new EmergencyBlock(Arrays.copyOfRange(bArray, start, end)));
        } else if (type.equals(DataType.WALLBOX) && callbackType.equals(DataType.DATA)) {
            int start = (WALLBOX_REG_START - INFO_REG_SIZE) * 2;
            int end = start + WALLBOX_REG_SIZE * 2;
            return Optional.of(new WallboxArray(Arrays.copyOfRange(bArray, start, end)));
        } else if (type.equals(DataType.STRINGS) && callbackType.equals(DataType.DATA)) {
            int start = (STRINGS_REG_START - INFO_REG_SIZE) * 2;
            int end = start + STRINGS_REG_SIZE * 2;
            return Optional.of(new StringBlock(Arrays.copyOfRange(bArray, start, end)));
        }
    }
    logger.warn("Wrong Block requested. Request is {} but type is {}", type, callbackType);
    return Optional.empty();
}
Also used : InfoBlock(org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock) PowerBlock(org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock) EmergencyBlock(org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock) StringBlock(org.openhab.binding.modbus.e3dc.internal.dto.StringBlock) WallboxArray(org.openhab.binding.modbus.e3dc.internal.dto.WallboxArray)

Example 2 with StringBlock

use of org.openhab.binding.modbus.e3dc.internal.dto.StringBlock in project openhab-addons by openhab.

the class DataBlockTest method testValidStringDetailsStringBlock.

@Test
public void testValidStringDetailsStringBlock() {
    Optional<Data> dataOpt = mc.parse(DataType.STRINGS);
    assertTrue(dataOpt.isPresent());
    StringBlock b = (StringBlock) dataOpt.get();
    assertEquals(381, b.string1Volt.intValue(), "String 1 V");
    assertEquals("V", b.string1Volt.getUnit().toString(), "String 1 V");
    assertEquals(533, b.string2Volt.intValue(), "String 2 V");
    assertEquals("V", b.string2Volt.getUnit().toString(), "String 1 V");
    assertEquals(0, b.string3Volt.intValue(), "String 3 V");
    assertEquals("V", b.string3Volt.getUnit().toString(), "String 1 V");
    assertEquals(0.27, b.string1Ampere.doubleValue(), 0.01, "String 1 A");
    assertEquals("A", b.string1Ampere.getUnit().toString(), "String 1 A");
    assertEquals(0.26, b.string2Ampere.doubleValue(), 0.01, "String 2 A");
    assertEquals("A", b.string2Ampere.getUnit().toString(), "String 2 A");
    assertEquals(0, b.string3Ampere.doubleValue(), 0.01, "String 3 A");
    assertEquals("A", b.string3Ampere.getUnit().toString(), "String 3 A");
    assertEquals(103, b.string1Watt.intValue(), "String 1 W");
    assertEquals("W", b.string1Watt.getUnit().toString(), "String 1 W");
    assertEquals(139, b.string2Watt.intValue(), "String 2 W");
    assertEquals("W", b.string2Watt.getUnit().toString(), "String 2 W");
    assertEquals(0, b.string3Watt.intValue(), "String 3 W");
    assertEquals("W", b.string3Watt.getUnit().toString(), "String 3 W");
}
Also used : Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) StringBlock(org.openhab.binding.modbus.e3dc.internal.dto.StringBlock) Test(org.junit.jupiter.api.Test)

Aggregations

StringBlock (org.openhab.binding.modbus.e3dc.internal.dto.StringBlock)2 Test (org.junit.jupiter.api.Test)1 EmergencyBlock (org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock)1 InfoBlock (org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock)1 PowerBlock (org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock)1 WallboxArray (org.openhab.binding.modbus.e3dc.internal.dto.WallboxArray)1 Data (org.openhab.binding.modbus.e3dc.internal.modbus.Data)1