Search in sources :

Example 91 with DataObject

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();
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 92 with DataObject

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()));
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Example 93 with DataObject

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);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 94 with DataObject

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());
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) Test(org.junit.jupiter.api.Test)

Example 95 with DataObject

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);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ObisCode(org.openmuc.jdlms.ObisCode)

Aggregations

DataObject (org.openmuc.jdlms.datatypes.DataObject)176 ArrayList (java.util.ArrayList)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)36 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)34 Test (org.junit.jupiter.api.Test)31 GetResult (org.openmuc.jdlms.GetResult)23 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)16 DateTime (org.joda.time.DateTime)15 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)14 SetParameter (org.openmuc.jdlms.SetParameter)12 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)11 BitString (org.openmuc.jdlms.datatypes.BitString)10 ObisCode (org.openmuc.jdlms.ObisCode)9 IOException (java.io.IOException)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)7 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)6 List (java.util.List)5 MethodResultCode (org.openmuc.jdlms.MethodResultCode)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)5 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)5