Search in sources :

Example 6 with MethodResultCode

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

the class DeviceChannelsHelperTest method testDeinstallSlave4.

@Test
void testDeinstallSlave4() throws ProtocolAdapterException {
    // unsuccessful deinstall with unsigned integer parameter (second
    // attempt)
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.mBusSetup.callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any(DataObject.class))).thenReturn(MethodResultCode.TYPE_UNMATCHED).thenReturn(MethodResultCode.SCOPE_OF_ACCESS_VIOLATION);
    final MethodResultCode methodResultCode = this.deviceChannelsHelper.deinstallSlave(this.conn, this.device, (short) 1, this.mBusSetup);
    assertThat(methodResultCode).isEqualTo(MethodResultCode.SCOPE_OF_ACCESS_VIOLATION);
    verify(this.mBusSetup, times(2)).callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any());
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) Test(org.junit.jupiter.api.Test)

Example 7 with MethodResultCode

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

the class DeviceChannelsHelperTest method testDeinstallSlave.

@Test
void testDeinstallSlave() throws ProtocolAdapterException {
    // successful deinstall with signed integer parameter
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.mBusSetup.callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any())).thenReturn(MethodResultCode.SUCCESS);
    final MethodResultCode methodResultCode = this.deviceChannelsHelper.deinstallSlave(this.conn, this.device, (short) 1, this.mBusSetup);
    assertThat(methodResultCode).isEqualTo(MethodResultCode.SUCCESS);
    verify(this.mBusSetup, times(1)).callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any());
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) Test(org.junit.jupiter.api.Test)

Example 8 with MethodResultCode

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

the class DeviceChannelsHelperTest method testDeinstallSlave2.

@Test
void testDeinstallSlave2() throws ProtocolAdapterException {
    // successful deinstall with unsigned integer parameter after
    // unsuccessful
    // attempt with signed integer (TYPE_UNMATCHED)
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.mBusSetup.callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any(DataObject.class))).thenReturn(MethodResultCode.TYPE_UNMATCHED).thenReturn(MethodResultCode.SUCCESS);
    final MethodResultCode methodResultCode = this.deviceChannelsHelper.deinstallSlave(this.conn, this.device, (short) 1, this.mBusSetup);
    assertThat(methodResultCode).isEqualTo(MethodResultCode.SUCCESS);
    verify(this.mBusSetup, times(2)).callMethod(eq(MBusClientMethod.SLAVE_DEINSTALL), any());
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) Test(org.junit.jupiter.api.Test)

Example 9 with MethodResultCode

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

the class DeviceChannelsHelper method deinstallSlave.

protected MethodResultCode deinstallSlave(final DlmsConnectionManager conn, final DlmsDevice device, final short channel, final CosemObjectAccessor mBusSetup) throws ProtocolAdapterException {
    // in blue book version 10, the parameter is of type integer
    DataObject parameter = DataObject.newInteger8Data((byte) 0);
    conn.getDlmsMessageListener().setDescription("Call slave deinstall method");
    MethodResultCode slaveDeinstallResultCode = mBusSetup.callMethod(MBusClientMethod.SLAVE_DEINSTALL, parameter);
    if (slaveDeinstallResultCode == MethodResultCode.TYPE_UNMATCHED) {
        // in blue book version 12, the parameter is of type unsigned, we
        // will try again with that type
        parameter = DataObject.newUInteger8Data((byte) 0);
        slaveDeinstallResultCode = mBusSetup.callMethod(MBusClientMethod.SLAVE_DEINSTALL, parameter);
    }
    if (slaveDeinstallResultCode != MethodResultCode.SUCCESS) {
        log.warn("Slave deinstall was not successfull on device {} on channel {}", device.getDeviceIdentification(), channel);
    }
    return slaveDeinstallResultCode;
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject)

Example 10 with MethodResultCode

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

the class ImageTransfer method initiateImageTransfer.

/**
 * Initiates Image transfer.After a successful initiation, the value of the image_transfer_status
 * attribute is (1) Image transfer initiated and the COSEM server is prepared to accept
 * ImageBlocks.
 */
public void initiateImageTransfer() throws ProtocolAdapterException {
    final List<DataObject> params = new ArrayList<>();
    params.add(DataObject.newOctetStringData(this.imageIdentifier));
    params.add(DataObject.newUInteger32Data(this.getImageSize()));
    final DataObject parameter = DataObject.newStructureData(params);
    this.setDescriptionForMethodCall(ImageTransferMethod.IMAGE_TRANSFER_INITIATE, parameter);
    final MethodResultCode resultCode = this.imageTransferCosem.callMethod(ImageTransferMethod.IMAGE_TRANSFER_INITIATE, parameter);
    if (resultCode != MethodResultCode.SUCCESS) {
        log.warn("Method IMAGE_TRANSFER_INITIATE gave result {}", resultCode);
    }
}
Also used : MethodResultCode(org.openmuc.jdlms.MethodResultCode) DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList)

Aggregations

MethodResultCode (org.openmuc.jdlms.MethodResultCode)11 DataObject (org.openmuc.jdlms.datatypes.DataObject)6 Test (org.junit.jupiter.api.Test)4 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 MethodParameter (org.openmuc.jdlms.MethodParameter)1 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ImageTransferException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)1 GMeterInfoDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto)1 SetMbusUserKeyByChannelRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SetMbusUserKeyByChannelRequestDataDto)1 EncrypterException (org.opensmartgridplatform.shared.exceptionhandling.EncrypterException)1