Search in sources :

Example 6 with GetResult

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

the class DeviceChannelsHelperTest method testGetChannelElementValuesInvalidManufacturerId.

@Test
void testGetChannelElementValuesInvalidManufacturerId() throws Exception {
    final GetResult manufacturerIdentificationInvalid = new GetResultImpl(DataObject.newUInteger16Data(123));
    final List<GetResult> resultList = new ArrayList<>(Arrays.asList(this.primaryAddress, this.identificationNumberInBcd, manufacturerIdentificationInvalid, this.version, this.deviceType));
    when(this.device.isWithListSupported()).thenReturn(true);
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.get(anyList())).thenReturn(resultList);
    assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
        this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, (short) 1);
    });
}
Also used : GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 7 with GetResult

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

the class DeviceChannelsHelperTest method testGetChannelElementValuesSmr5.

@Test
void testGetChannelElementValuesSmr5() throws Exception {
    final List<GetResult> resultList = new ArrayList<>(Arrays.asList(this.primaryAddress, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceType));
    when(this.device.isWithListSupported()).thenReturn(true);
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.get(anyList())).thenReturn(resultList);
    when(this.device.getProtocolName()).thenReturn("SMR");
    when(this.device.getProtocolVersion()).thenReturn("5.1");
    final ChannelElementValuesDto values = this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, (short) 1);
    assertThat(values.getPrimaryAddress()).isEqualTo(PRIMARY_ADDRESS);
    assertThat(values.getIdentificationNumber()).isEqualTo(IDENTIFICATION_NUMBER_AS_STRING);
    assertThat(values.getManufacturerIdentification()).isEqualTo(MANUFACTURER_IDENTIFICATION_AS_TEXT);
    assertThat(values.getVersion()).isEqualTo(VERSION);
    assertThat(values.getDeviceTypeIdentification()).isEqualTo(DEVICE_TYPE);
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 8 with GetResult

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

the class GetFirmwareVersionsCommandExecutorTest method returns4FirmwareVersionsForSmr51Device.

@Test
public void returns4FirmwareVersionsForSmr51Device() throws Exception {
    final DlmsDevice device = new DlmsDevice();
    device.setProtocol(Protocol.SMR_5_1);
    final GetResult getResult1 = new GetResultBuilder().build();
    final GetResult getResult2 = new GetResultBuilder().build();
    final GetResult getResult3 = new GetResultBuilder().build();
    final GetResult getResult4 = new GetResultBuilder().build();
    when(this.helperService.getAndCheck(same(this.connectionHolder), same(device), eq("retrieve firmware versions"), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_COMMUNICATION_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MBUS_DRIVER_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)))).thenReturn(asList(getResult1, getResult2, getResult3, getResult4));
    when(this.helperService.readString(getResult1.getResultData(), FirmwareModuleType.ACTIVE_FIRMWARE.getDescription())).thenReturn("string1");
    when(this.helperService.readString(getResult2.getResultData(), FirmwareModuleType.MODULE_ACTIVE.getDescription())).thenReturn("string2");
    when(this.helperService.readString(getResult3.getResultData(), FirmwareModuleType.COMMUNICATION.getDescription())).thenReturn("string3");
    when(this.helperService.readString(getResult4.getResultData(), FirmwareModuleType.M_BUS_DRIVER_ACTIVE.getDescription())).thenReturn("string4");
    final List<FirmwareVersionDto> result = this.executor.execute(this.connectionHolder, device, null, this.messageMetadata);
    Assertions.assertThat(result).usingRecursiveFieldByFieldElementComparator().containsExactly(new FirmwareVersionDto(FirmwareModuleType.ACTIVE_FIRMWARE, "string1"), new FirmwareVersionDto(FirmwareModuleType.MODULE_ACTIVE, "string2"), new FirmwareVersionDto(FirmwareModuleType.COMMUNICATION, "string3"), new FirmwareVersionDto(FirmwareModuleType.M_BUS_DRIVER_ACTIVE, "string4"));
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) GetResultBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultBuilder) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Example 9 with GetResult

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

the class GetFirmwareVersionsCommandExecutorTest method returns3FirmwareVersionsForDsmr422Device.

@Test
public void returns3FirmwareVersionsForDsmr422Device() throws Exception {
    final DlmsDevice device = new DlmsDevice();
    final GetResult getResult1 = new GetResultBuilder().build();
    final GetResult getResult2 = new GetResultBuilder().build();
    final GetResult getResult3 = new GetResultBuilder().build();
    when(this.helperService.getAndCheck(same(this.connectionHolder), same(device), eq("retrieve firmware versions"), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_COMMUNICATION_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)))).thenReturn(asList(getResult1, getResult2, getResult3));
    when(this.helperService.readString(getResult1.getResultData(), FirmwareModuleType.ACTIVE_FIRMWARE.getDescription())).thenReturn("string1");
    when(this.helperService.readString(getResult2.getResultData(), FirmwareModuleType.MODULE_ACTIVE.getDescription())).thenReturn("string2");
    when(this.helperService.readString(getResult3.getResultData(), FirmwareModuleType.COMMUNICATION.getDescription())).thenReturn("string3");
    final List<FirmwareVersionDto> result = this.executor.execute(this.connectionHolder, device, null, this.messageMetadata);
    Assertions.assertThat(result).usingRecursiveFieldByFieldElementComparator().containsExactly(new FirmwareVersionDto(FirmwareModuleType.ACTIVE_FIRMWARE, "string1"), new FirmwareVersionDto(FirmwareModuleType.MODULE_ACTIVE, "string2"), new FirmwareVersionDto(FirmwareModuleType.COMMUNICATION, "string3"));
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) GetResultBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultBuilder) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Example 10 with GetResult

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

the class GetAllAttributeValuesCommandExecutor method getAllDataFromAttribute.

private String getAllDataFromAttribute(final DlmsConnectionManager conn, final int classNumber, final DataObject obisCode, final int attributeValue) throws ProtocolAdapterException, IOException {
    if (!obisCode.isByteArray()) {
        this.throwUnexpectedTypeProtocolAdapterException();
    }
    final byte[] obisCodeByteArray = obisCode.getValue();
    if (obisCodeByteArray.length != OBIS_CODE_BYTE_ARRAY_LENGTH) {
        this.throwUnexpectedTypeProtocolAdapterException();
    }
    final AttributeAddress attributeAddress = new AttributeAddress(classNumber, new ObisCode(obisCodeByteArray), attributeValue);
    conn.getDlmsMessageListener().setDescription("RetrieveAllAttributeValues, retrieve attribute: " + JdlmsObjectToStringUtil.describeAttributes(attributeAddress));
    LOGGER.debug("Retrieving configuration objects data for class id: {}, obis code: {}, attribute id: {}", classNumber, obisCodeByteArray, attributeValue);
    final GetResult getResult = conn.getConnection().get(attributeAddress);
    LOGGER.debug("ResultCode: {}", getResult.getResultCode());
    return this.dlmsHelper.getDebugInfo(getResult.getResultData());
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode)

Aggregations

GetResult (org.openmuc.jdlms.GetResult)47 DataObject (org.openmuc.jdlms.datatypes.DataObject)23 ArrayList (java.util.ArrayList)16 AttributeAddress (org.openmuc.jdlms.AttributeAddress)16 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 Test (org.junit.jupiter.api.Test)13 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)11 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)8 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)8 DateTime (org.joda.time.DateTime)6 ObisCode (org.openmuc.jdlms.ObisCode)6 IOException (java.io.IOException)5 Date (java.util.Date)5 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)4 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)4 AccessResultCode (org.openmuc.jdlms.AccessResultCode)3 BufferedDateTimeValidationException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.BufferedDateTimeValidationException)3