use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method getAccessSelectionTimeRangeParameter.
public DataObject getAccessSelectionTimeRangeParameter(final DateTime from, final DateTime to, final DataObject selectedValues) {
/*
* Define the clock object {8,0-0:1.0.0.255,2,0} to be used as
* restricting object in a range descriptor with a from value and to
* value to determine which elements from the buffered array should be
* retrieved.
*/
final DataObject clockDefinition = this.getClockDefinition();
final DataObject fromValue = this.asDataObject(from);
final DataObject toValue = this.asDataObject(to);
return DataObject.newStructureData(Arrays.asList(clockDefinition, fromValue, toValue, selectedValues));
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelper method readObjectDefinition.
public CosemObjectDefinitionDto readObjectDefinition(final DataObject resultData, final String description) throws ProtocolAdapterException {
final List<DataObject> objectDefinitionElements = this.readList(resultData, description);
if (objectDefinitionElements == null) {
return null;
}
if (objectDefinitionElements.size() != 4) {
LOGGER.error("Unexpected ResultData for Object Definition value: {}", this.getDebugInfo(resultData));
throw new ProtocolAdapterException("Expected list for Object Definition to contain 4 elements, got: " + objectDefinitionElements.size());
}
final Long classId = this.readLongNotNull(objectDefinitionElements.get(0), "Class ID from " + description);
final CosemObisCodeDto logicalName = this.readLogicalName(objectDefinitionElements.get(1), "Logical Name from " + description);
final Long attributeIndex = this.readLongNotNull(objectDefinitionElements.get(2), "Attribute Index from " + description);
final Long dataIndex = this.readLongNotNull(objectDefinitionElements.get(3), "Data Index from " + description);
return new CosemObjectDefinitionDto(classId.intValue(), logicalName, attributeIndex.intValue(), dataIndex.intValue());
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class SetEncryptionKeyExchangeOnGMeterCommandExecutor method getTransferKeyMethodParameter.
private MethodParameter getTransferKeyMethodParameter(final String mbusDeviceIdentification, final int channel, final byte[] gMeterUserKey, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByDeviceIdentification(mbusDeviceIdentification);
if (mbusDevice == null) {
throw new ProtocolAdapterException("Unknown M-Bus device: " + mbusDeviceIdentification);
}
final byte[] mbusDefaultKey = this.secretManagementService.getKey(messageMetadata, mbusDeviceIdentification, G_METER_MASTER);
final byte[] encryptedUserKey = this.encryptMbusUserKey(mbusDefaultKey, gMeterUserKey);
final DataObject methodParameter = DataObject.newOctetStringData(encryptedUserKey);
final MBusClientMethod method = MBusClientMethod.TRANSFER_KEY;
return new MethodParameter(method.getInterfaceClass().id(), OBIS_HASHMAP.get(channel), method.getMethodId(), methodParameter);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class GetAllAttributeValuesCommandExecutor method execute.
@Override
public String execute(final DlmsConnectionManager conn, final DlmsDevice device, final DataObject object, final MessageMetadata messageMetadata) throws OsgpException {
final AttributeAddress attributeAddress = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
LOGGER.debug("Retrieving all attribute values for class id: {}, obis code: {}, attribute id: {}", CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);
final DataObject objectList = this.dlmsHelper.getAttributeValue(conn, attributeAddress);
if (!objectList.isComplex()) {
this.throwUnexpectedTypeProtocolAdapterException();
}
final List<DataObject> objectListElements = objectList.getValue();
final List<ClassIdObisAttr> allObisCodes = this.getAllObisCodes(objectListElements);
this.logAllObisCodes(allObisCodes);
try {
final String output = this.createOutput(conn, allObisCodes);
LOGGER.debug("Total output is: {}", output);
return output;
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class GetAllAttributeValuesCommandExecutor method getAllObisCodes.
private List<ClassIdObisAttr> getAllObisCodes(final List<DataObject> objectListElements) throws ProtocolAdapterException {
final List<ClassIdObisAttr> allObisCodes = new ArrayList<>();
for (final DataObject objectListElement : objectListElements) {
final List<DataObject> objectListElementValues = objectListElement.getValue();
final ClassIdObisAttr classIdObisAttr = new ClassIdObisAttr(this.getClassId(objectListElementValues.get(CLASS_ID_INDEX)), objectListElementValues.get(OBIS_CODE_INDEX), this.getNoOffAttributes(objectListElementValues));
allObisCodes.add(classIdObisAttr);
}
return allObisCodes;
}
Aggregations