use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class ImageTransfer method getImageFirstNotTransferredBlockNumber.
private int getImageFirstNotTransferredBlockNumber() throws ProtocolAdapterException {
this.connector.getDlmsMessageListener().setDescription("ImageTransfer read image_first_not_transferred_block_number, read attribute: " + JdlmsObjectToStringUtil.describeAttributes(this.imageTransferCosem.createAttributeAddress(ImageTransferAttribute.IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER)));
final DataObject imageFirstNotReadBlockNumberData = this.imageTransferCosem.readAttribute(ImageTransferAttribute.IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER);
if (imageFirstNotReadBlockNumberData == null || !imageFirstNotReadBlockNumberData.isNumber()) {
throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_FIRST_NOT_TRANSFERRED_BLOCK_NUMBER_NOT_READ);
}
final Long imageFirstNotReadBlockNumber = imageFirstNotReadBlockNumberData.getValue();
return imageFirstNotReadBlockNumber.intValue();
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class ImageTransfer method verifyImage.
/**
* The Image is verified. This is done by invoking the image_verify method by the client and
* testing the image transfer status.
*/
public void verifyImage() throws OsgpException {
final DataObject parameter = DataObject.newInteger8Data((byte) 0);
this.setDescriptionForMethodCall(ImageTransferMethod.IMAGE_VERIFY, parameter);
final MethodResultCode verified = this.imageTransferCosem.callMethod(ImageTransferMethod.IMAGE_VERIFY, parameter);
if (verified == null) {
throw new ProtocolAdapterException(EXCEPTION_MSG_IMAGE_VERIFY_NOT_CALLED);
}
if (verified == MethodResultCode.SUCCESS) {
return;
}
if (verified == MethodResultCode.TEMPORARY_FAILURE) {
this.waitForImageVerification();
}
// If activation was triggered the device will not verify again.
if (this.imageIsVerified()) {
return;
}
final int status = this.getImageTransferStatus();
throw new ImageTransferException(String.format(EXCEPTION_MSG_IMAGE_VERIFICATION_ERROR, ImageTransferStatus.getByValue(status).name(), verified.name()));
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class InvocationCounterManagerTest method initializesInvocationCounterForDevice.
@Test
void initializesInvocationCounterForDevice() throws Exception {
final long invocationCounterValueOnDevice = 123;
final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
final DataObject dataObject = DataObject.newUInteger32Data(invocationCounterValueOnDevice);
when(this.dlmsHelper.getAttributeValue(eq(connectionManager), refEq(ATTRIBUTE_ADDRESS_INVOCATION_COUNTER_VALUE))).thenReturn(dataObject);
when(this.deviceRepository.save(this.device)).thenReturn(new DlmsDeviceBuilder().withDeviceIdentification(this.device.getDeviceIdentification()).withInvocationCounter(this.device.getInvocationCounter()).withVersion(this.device.getVersion() + 1).build());
this.manager.initializeWithInvocationCounterStoredOnDeviceTask(this.device, connectionManager);
verify(this.deviceRepository).save(this.device);
verify(this.deviceRepository).save(this.device);
assertThat(this.device.getVersion()).isGreaterThan(this.initialDeviceVersion);
assertThat(this.device.getInvocationCounter()).isEqualTo(invocationCounterValueOnDevice);
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class DlmsHelperTest method testDateTimeWinterTime.
@Test
public void testDateTimeWinterTime() {
final DataObject dateInWinterTimeDataObject = this.dlmsHelper.asDataObject(this.dateTimeWinterTime());
assertThat(dateInWinterTimeDataObject.isCosemDateFormat()).isTrue();
assertThat(dateInWinterTimeDataObject.getValue() instanceof CosemDateTime).isTrue();
final CosemDateTime cosemDateTime = dateInWinterTimeDataObject.getValue();
assertThat(cosemDateTime.encode()).isEqualTo(this.byteArrayWinterTime());
}
use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.
the class CaptureObject method newCaptureObject.
public static CaptureObject newCaptureObject(final DataObject dataObject) {
if (!dataObject.isComplex()) {
throw new IllegalArgumentException("The given data is not a valid capture object definition: " + dataObject);
}
final List<DataObject> elements = dataObject.getValue();
if (!elements.get(0).isNumber() || !elements.get(1).isByteArray() || !elements.get(2).isNumber() || !elements.get(3).isNumber()) {
throw new IllegalArgumentException("The given data does not contain the elements of a valid capture object definition: " + elements);
}
final int classId = elements.get(0).getValue();
final ObisCode obisCode = new ObisCode((byte[]) elements.get(1).getValue());
final byte attributeId = elements.get(2).getValue();
final int dataIndex = elements.get(3).getValue();
return new CaptureObject(classId, obisCode, attributeId, dataIndex);
}
Aggregations