Search in sources :

Example 1 with InfoBlock

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

the class InfoTest method testInvalidBlockSize.

@Test
public void testInvalidBlockSize() {
    byte[] infoBlock = new byte[] { -29, -36, 1, 2, 0, -120, 69, 51, 47, 68, 67, 32, 71, 109, 98, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 32, 69, 32, 65, 73, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 78, 73, 78, 73, 84, 73, 65, 76, 73, 90, 69, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 95, 50, 48, 50, 48, 95, 48 };
    Parser mc = new Parser(DataType.INFO);
    mc.setArray(infoBlock);
    Optional<Data> infoOpt = mc.parse(DataType.INFO);
    InfoBlock b = (InfoBlock) infoOpt.get();
    // block still valid but data maybe corrupted => logged in warnings
    assertTrue(infoOpt.isPresent());
    assertNotNull(b);
}
Also used : InfoBlock(org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) Parser(org.openhab.binding.modbus.e3dc.internal.modbus.Parser) Test(org.junit.jupiter.api.Test)

Example 2 with InfoBlock

use of org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock 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 3 with InfoBlock

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

the class InfoTest method testvalidInformationBlock.

@Test
public void testvalidInformationBlock() {
    Optional<Data> infoOpt = mc.parse(DataType.INFO);
    assertTrue(infoOpt.isPresent());
    InfoBlock b = (InfoBlock) infoOpt.get();
    assertNotNull(b);
    assertEquals("E3DC", b.modbusId.toString(), "MagicByte");
    assertEquals("S10 E AIO", b.modelName.toString(), "Model");
    assertEquals("S10_2020_04", b.firmware.toString(), "Firmware");
    assertEquals("E3/DC GmbH", b.manufacturer.toString(), "Manufacturer");
}
Also used : InfoBlock(org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) Test(org.junit.jupiter.api.Test)

Example 4 with InfoBlock

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

the class E3DCThingHandler method handleInfoResult.

void handleInfoResult(AsyncModbusReadResult result) {
    if (infoRead != ReadStatus.READ_SUCCESS) {
        // update status only if bit switches
        infoRead = ReadStatus.READ_SUCCESS;
        updateStatus();
    }
    infoParser.handle(result);
    Optional<Data> blockOpt = infoParser.parse(DataType.INFO);
    if (blockOpt.isPresent()) {
        InfoBlock block = (InfoBlock) blockOpt.get();
        updateState(modbusIdChannel, block.modbusId);
        updateState(modbusVersionChannel, block.modbusVersion);
        updateState(supportedRegistersChannel, block.supportedRegisters);
        updateState(manufacturerChannel, block.manufacturer);
        updateState(modelNameChannel, block.modelName);
        updateState(serialNumberChannel, block.serialNumber);
        updateState(firmwareChannel, block.firmware);
    } else {
        logger.debug("Unable to get {} from provider {}", DataType.INFO, dataParser.toString());
    }
}
Also used : InfoBlock(org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data)

Aggregations

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