Search in sources :

Example 6 with BitString

use of org.openmuc.jdlms.datatypes.BitString in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceSmr5 method getConfigurationObject.

@Override
ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException {
    final DataObject resultData = result.getResultData();
    if (resultData == null || !resultData.isBitString()) {
        LOGGER.warn("Configuration object result data is not a BitString: {}", resultData);
        throw new ProtocolAdapterException("Expected bit-string data as Configuration object result data, but got: " + (resultData == null ? "null" : resultData.getType()));
    }
    LOGGER.info("SMR5 Configuration object current BitString: {}", this.dlmsHelper.getDebugInfo(resultData));
    final BitString bitString = resultData.getValue();
    final byte[] flagByteArray = bitString.getBitString();
    final List<ConfigurationFlagDto> configurationFlagDtos = this.toConfigurationFlags(flagByteArray);
    final ConfigurationFlagsDto configurationFlagsDto = new ConfigurationFlagsDto(configurationFlagDtos);
    return new ConfigurationObjectDto(configurationFlagsDto);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 7 with BitString

use of org.openmuc.jdlms.datatypes.BitString in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectServiceDsmr4 method addFlags.

private void addFlags(final ConfigurationObjectDto configurationToSet, final ConfigurationObjectDto configurationOnDevice, final List<DataObject> dataObjects) throws ProtocolAdapterException {
    final BitString flags = this.getFlags(configurationToSet, configurationOnDevice);
    final DataObject bitString = DataObject.newBitStringData(flags);
    dataObjects.add(bitString);
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 8 with BitString

use of org.openmuc.jdlms.datatypes.BitString in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceDsmr4 method getConfigurationFlags.

private ConfigurationFlagsDto getConfigurationFlags(final DataObject flags) throws ProtocolAdapterException {
    if (flags == null || !flags.isBitString()) {
        final String message = String.format("Expected ConfigurationObject flags as BitString, but got: %s", flags);
        LOGGER.warn(message);
        throw new ProtocolAdapterException(message);
    }
    final BitString bitString = flags.getValue();
    final byte[] flagBytes = bitString.getBitString();
    final List<ConfigurationFlagDto> configurationFlags = this.toConfigurationFlags(flagBytes);
    return new ConfigurationFlagsDto(configurationFlags);
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationFlagDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto) ConfigurationFlagsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto) BitString(org.openmuc.jdlms.datatypes.BitString) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 9 with BitString

use of org.openmuc.jdlms.datatypes.BitString in project open-smart-grid-platform by OSGP.

the class DlmsAttributeValuesClient method asBitString.

private static BitString asBitString(final JsonNode valueNode) {
    String bitStringText = valueNode.textValue();
    if (bitStringText == null) {
        throw new IllegalArgumentException("JSON node for BitString must have a text value: " + valueNode);
    }
    final int numBits = bitStringText.length();
    if (numBits == 0) {
        return new BitString(new byte[0], 0);
    }
    if (numBits % 8 != 0) {
        final String trailingZerosFormat = "%0" + (8 - (numBits % 8)) + "d";
        bitStringText = bitStringText + String.format(trailingZerosFormat, 0);
    }
    final int numBytes = bitStringText.length() / 8;
    final byte[] bitStringBytes = new byte[numBytes];
    for (int i = 0; i < numBytes; i++) {
        final String bytePart = bitStringText.substring(i * 8, (i + 1) * 8);
        bitStringBytes[i] = Byte.parseByte(bytePart, 2);
    }
    return new BitString(bitStringBytes, numBits);
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) BitString(org.openmuc.jdlms.datatypes.BitString)

Example 10 with BitString

use of org.openmuc.jdlms.datatypes.BitString in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectCommandExecutorDsmr4IT method execute.

@Test
public void execute() throws IOException, ProtocolAdapterException {
    // SETUP
    // configurationToSet: 0111-----1------
    final GprsOperationModeTypeDto gprsModeToSet = GprsOperationModeTypeDto.TRIGGERED;
    final ConfigurationObjectDto configurationToSet = this.createConfigurationObjectDto(gprsModeToSet, this.createFlagDto(ConfigurationFlagTypeDto.DISCOVER_ON_OPEN_COVER, false), this.createFlagDto(ConfigurationFlagTypeDto.DISCOVER_ON_POWER_ON, true), this.createFlagDto(ConfigurationFlagTypeDto.DYNAMIC_MBUS_ADDRESS, true), this.createFlagDto(ConfigurationFlagTypeDto.PO_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_5_ON_PO_ENABLE, true));
    // flagsOnDevice: 1000101010000000
    final byte[] flagsOnDevice = this.createFlagBytes(ConfigurationFlagTypeDto.DISCOVER_ON_OPEN_COVER, ConfigurationFlagTypeDto.HLS_3_ON_P_3_ENABLE, ConfigurationFlagTypeDto.HLS_5_ON_P_3_ENABLE, ConfigurationFlagTypeDto.HLS_4_ON_PO_ENABLE);
    // result of merging configurationToSet and flagsOnDevice
    final byte firstExpectedByte = this.asByte("01111010");
    final byte secondExpectedByte = this.asByte("11000000");
    final GprsOperationModeTypeDto gprsModeOnDevice = GprsOperationModeTypeDto.ALWAYS_ON;
    final DataObject deviceData = this.createStructureData(flagsOnDevice, gprsModeOnDevice);
    when(this.getResult.getResultData()).thenReturn(deviceData);
    final DlmsDevice device = new DlmsDevice();
    device.setProtocol(Protocol.DSMR_4_2_2);
    // CALL
    final AccessResultCode result = this.instance.execute(this.conn, device, configurationToSet, this.messageMetadata);
    // VERIFY
    assertThat(result).isEqualTo(AccessResultCode.SUCCESS);
    final List<DataObject> elements = this.captureSetParameterStructureData();
    final Number gprsOperationMode = elements.get(INDEX_OF_GPRS_OPERATION_MODE).getValue();
    assertThat(gprsOperationMode).isEqualTo(gprsModeToSet.getNumber());
    final BitString configurationFlags = elements.get(INDEX_OF_CONFIGURATION_FLAGS).getValue();
    final byte[] flagsSentToDevice = configurationFlags.getBitString();
    assertThat(flagsSentToDevice[0]).isEqualTo(firstExpectedByte);
    assertThat(flagsSentToDevice[1]).isEqualTo(secondExpectedByte);
}
Also used : GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test)

Aggregations

BitString (org.openmuc.jdlms.datatypes.BitString)13 DataObject (org.openmuc.jdlms.datatypes.DataObject)5 Test (org.junit.jupiter.api.Test)3 ConfigurationObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)3 AccessResultCode (org.openmuc.jdlms.AccessResultCode)2 ObisCode (org.openmuc.jdlms.ObisCode)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 ConfigurationFlagDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagDto)2 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)2 GprsOperationModeTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto)2 ConfigurationObject (org.opensmartgridplatform.simulator.protocol.dlms.cosem.ConfigurationObject)2 Bean (org.springframework.context.annotation.Bean)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 List (java.util.List)1 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)1