Search in sources :

Example 1 with BitString

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

the class Smr5Profile method configurationObject.

@Bean
public ConfigurationObject configurationObject() {
    final Byte[] bytes = new Byte[this.configurationObjectFlags.size()];
    this.configurationObjectFlags.toArray(bytes);
    this.dynamicValues().setDefaultAttributeValue(InterfaceClass.DATA.id(), new ObisCode(0, 1, 94, 31, 3, 255), ConfigurationObject.ATTRIBUTE_ID_VALUE, DataObject.newBitStringData(new BitString(ArrayUtils.toPrimitive(bytes), 16)));
    return new ConfigurationObject();
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationObject(org.opensmartgridplatform.simulator.protocol.dlms.cosem.ConfigurationObject) ObisCode(org.openmuc.jdlms.ObisCode) Bean(org.springframework.context.annotation.Bean)

Example 2 with BitString

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

the class DefaultDeviceProfile method configurationObject.

@Bean
public ConfigurationObject configurationObject() {
    final Byte[] bytes = new Byte[this.configurationObjectFlags.size()];
    this.configurationObjectFlags.toArray(bytes);
    this.dynamicValues().setDefaultAttributeValue(InterfaceClass.DATA.id(), new ObisCode(0, 1, 94, 31, 3, 255), ConfigurationObject.ATTRIBUTE_ID_VALUE, DataObject.newStructureData(DataObject.newEnumerateData(this.gprsOperationMode), DataObject.newBitStringData(new BitString(ArrayUtils.toPrimitive(bytes), 16))));
    return new ConfigurationObject();
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationObject(org.opensmartgridplatform.simulator.protocol.dlms.cosem.ConfigurationObject) ObisCode(org.openmuc.jdlms.ObisCode) Bean(org.springframework.context.annotation.Bean)

Example 3 with BitString

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

the class DlmsAttributeValuesClient method setBitStringValue.

private void setBitStringValue(final ObjectNode attributeNode, final DataObject dataObject) {
    if (!dataObject.isBitString()) {
        throw new IllegalArgumentException("DataObject must be bit-string: " + dataObject);
    }
    final BitString bitStringValue = dataObject.getValue();
    final byte[] bitStringBytes = bitStringValue.getBitString();
    final StringBuilder sb = new StringBuilder();
    for (final byte b : bitStringBytes) {
        sb.append(String.format("%08d", Integer.parseInt(Integer.toBinaryString(b & 0xFF))));
    }
    final JsonNode valueNode = TextNode.valueOf(sb.substring(0, bitStringValue.getNumBits()));
    attributeNode.set(JSON_VALUE_FIELD, valueNode);
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 4 with BitString

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

the class SetConfigurationObjectCommandExecutorSmr5IT method execute.

@Test
public void execute() throws IOException, ProtocolAdapterException {
    // SETUP
    // configurationToSet: ------1---10101-
    // GPRS operation mode is not part of the ConfigurationObject in SMR5
    final GprsOperationModeTypeDto gprsMode = null;
    final ConfigurationObjectDto configurationToSet = this.createConfigurationObjectDto(gprsMode, this.createFlagDto(ConfigurationFlagTypeDto.HLS_5_ON_P_3_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.DIRECT_ATTACH_AT_POWER_ON, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_6_ON_P3_ENABLE, false), this.createFlagDto(ConfigurationFlagTypeDto.HLS_7_ON_P3_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_6_ON_P0_ENABLE, false), this.createFlagDto(ConfigurationFlagTypeDto.HLS_7_ON_P0_ENABLE, true));
    // flagsOnDevice: 0000000001110100
    final byte[] flagsOnDevice = this.createFlagBytes(ConfigurationFlagTypeDto.HLS_5_ON_PO_ENABLE, ConfigurationFlagTypeDto.DIRECT_ATTACH_AT_POWER_ON, ConfigurationFlagTypeDto.HLS_6_ON_P3_ENABLE, ConfigurationFlagTypeDto.HLS_6_ON_P0_ENABLE);
    // result of merging configurationToSet and flagsOnDevice
    final byte firstExpectedByte = this.asByte("00000010");
    final byte secondExpectedByte = this.asByte("01101010");
    final DataObject deviceData = this.createBitStringData(flagsOnDevice);
    when(this.getResult.getResultData()).thenReturn(deviceData);
    final DlmsDevice device = new DlmsDevice();
    device.setProtocol(Protocol.SMR_5_0_0);
    // CALL
    final AccessResultCode result = this.instance.execute(this.conn, device, configurationToSet, this.messageMetadata);
    // VERIFY
    assertThat(result).isEqualTo(AccessResultCode.SUCCESS);
    final BitString configurationFlags = this.captureSetParameterBitStringData();
    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)

Example 5 with BitString

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

the class DlmsHelper method getObjectTextForDebugInfo.

private String getObjectTextForDebugInfo(final DataObject dataObject) {
    final String objectText;
    if (dataObject.isComplex()) {
        if (dataObject.getValue() instanceof List) {
            final StringBuilder builder = new StringBuilder();
            builder.append("[");
            builder.append(System.lineSeparator());
            this.appendItemValues(dataObject, builder);
            builder.append("]");
            builder.append(System.lineSeparator());
            objectText = builder.toString();
        } else {
            objectText = String.valueOf(dataObject.getRawValue());
        }
    } else if (dataObject.isByteArray()) {
        objectText = this.getDebugInfoByteArray(dataObject.getValue());
    } else if (dataObject.isBitString()) {
        final BitString bitString = dataObject.getValue();
        objectText = this.getDebugInfoBitStringBytes(bitString.getBitString());
    } else if (dataObject.isCosemDateFormat() && dataObject.getValue() instanceof CosemDateTime) {
        final CosemDateTime cosemDateTime = dataObject.getValue();
        objectText = this.getDebugInfoDateTimeBytes(cosemDateTime.encode());
    } else {
        objectText = String.valueOf(dataObject.getRawValue());
    }
    return objectText;
}
Also used : BitString(org.openmuc.jdlms.datatypes.BitString) List(java.util.List) ArrayList(java.util.ArrayList) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) BitString(org.openmuc.jdlms.datatypes.BitString)

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