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();
}
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();
}
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);
}
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);
}
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;
}
Aggregations