Search in sources :

Example 26 with AttributeAddress

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

the class SetAlarmNotificationsCommandExecutorTest method setUp.

@BeforeEach
public void setUp() {
    this.setParametersReceived = new ArrayList<>();
    this.device = new DlmsDevice("SuperAwesomeHeroicRockstarDevice");
    this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    final DlmsObjectConfigConfiguration dlmsObjectConfigConfiguration = new DlmsObjectConfigConfiguration();
    final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(new DlmsHelper(), dlmsObjectConfigConfiguration.getDlmsObjectConfigs()) {

        @Override
        public Optional<AttributeAddress> findAttributeAddress(final DlmsDevice device, final DlmsObjectType type, final Integer channel) {
            switch(type) {
                case ALARM_FILTER_1:
                    return Optional.of(new AttributeAddress(40, "0.0.97.98.10.255", 2));
                case ALARM_FILTER_2:
                    return Optional.of(new AttributeAddress(40, "0.0.97.98.11.255", 2));
            }
            return Optional.empty();
        }
    };
    this.executor = new SetAlarmNotificationsCommandExecutor(dlmsObjectConfigService);
    final DlmsConnectionStub conn = new DlmsConnectionStub() {

        @Override
        public AccessResultCode set(final SetParameter setParameter) {
            SetAlarmNotificationsCommandExecutorTest.this.setParametersReceived.add(setParameter);
            return AccessResultCode.SUCCESS;
        }
    };
    // Set the return value to 10 (0b1010):
    // REPLACE_BATTERY enabled, AUXILIARY_EVENT enabled.
    conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.10.255", 2), DataObject.newInteger32Data(10));
    conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.11.255", 2), DataObject.newInteger32Data(0));
    this.connMgr = new DlmsConnectionManagerStub(conn);
}
Also used : DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SetParameter(org.openmuc.jdlms.SetParameter) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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);
    }
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) AttributeAddress(org.openmuc.jdlms.AttributeAddress) IOException(java.io.IOException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

Example 28 with AttributeAddress

use of org.openmuc.jdlms.AttributeAddress 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)

Example 29 with AttributeAddress

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

the class GetGsmDiagnosticCommandExecutor method createAttributeAddresses.

private AttributeAddress[] createAttributeAddresses(final DlmsObject dlmsObject) {
    final int classId = dlmsObject.getClassId();
    final ObisCode obisCode = dlmsObject.getObisCode();
    return new AttributeAddress[] { new AttributeAddress(classId, obisCode, OPERATOR.attributeId()), new AttributeAddress(classId, obisCode, MODEM_REGISTRATION_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CIRCUIT_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, PACKET_SWITCHED_STATUS.attributeId()), new AttributeAddress(classId, obisCode, CELL_INFO.attributeId()), new AttributeAddress(classId, obisCode, ADJACENT_CELLS.attributeId()) // Reading of capture_time is disabled for now, because the jDLMS library appears to handle
    // the COSEM date-time in the response incorrectly. Also see comment in getCaptureTime.
    // new AttributeAddress(classId, obisCode, CAPTURE_TIME.attributeId())
    };
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode)

Example 30 with AttributeAddress

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

the class GetGsmDiagnosticCommandExecutor method execute.

@Override
public GetGsmDiagnosticResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetGsmDiagnosticRequestDto getGsmDiagnosticQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
    final DlmsObject dlmsObject = this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(device, DlmsObjectType.GSM_DIAGNOSTIC);
    final AttributeAddress[] addresses = this.createAttributeAddresses(dlmsObject);
    final String addressesDescriptions = JdlmsObjectToStringUtil.describeAttributes(addresses);
    conn.getDlmsMessageListener().setDescription("Get GsmDiagnostic, retrieve attributes: " + addressesDescriptions);
    LOGGER.info("Get GsmDiagnostic, retrieve attributes: {}", addressesDescriptions);
    final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "Get GsmDiagnostic", addresses);
    LOGGER.info("GetResultList: {}", describeGetResults(getResultList));
    if (!getResultList.stream().allMatch(result -> result.getResultCode() == AccessResultCode.SUCCESS)) {
        throw new ProtocolAdapterException("Get gsm diagnostic failed for " + device.getDeviceId());
    }
    return this.createGetGsmDiagnosticResponse(getResultList);
}
Also used : DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) GetResult(org.openmuc.jdlms.GetResult) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) JdlmsObjectToStringUtil.describeGetResults(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.JdlmsObjectToStringUtil.describeGetResults) BitErrorRateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BitErrorRateDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) MODEM_REGISTRATION_STATUS(org.opensmartgridplatform.dlms.interfaceclass.attribute.GsmDiagnosticAttribute.MODEM_REGISTRATION_STATUS) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) AttributeAddress(org.openmuc.jdlms.AttributeAddress) PACKET_SWITCHED_STATUS(org.opensmartgridplatform.dlms.interfaceclass.attribute.GsmDiagnosticAttribute.PACKET_SWITCHED_STATUS) ObisCode(org.openmuc.jdlms.ObisCode) CircuitSwitchedStatusDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CircuitSwitchedStatusDto) GetGsmDiagnosticRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticRequestDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) ModemRegistrationStatusDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ModemRegistrationStatusDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) PacketSwitchedStatusDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PacketSwitchedStatusDto) Logger(org.slf4j.Logger) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) AbstractCommandExecutor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor) OPERATOR(org.opensmartgridplatform.dlms.interfaceclass.attribute.GsmDiagnosticAttribute.OPERATOR) DataObject(org.openmuc.jdlms.datatypes.DataObject) Collectors(java.util.stream.Collectors) AdjacentCellInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AdjacentCellInfoDto) StandardCharsets(java.nio.charset.StandardCharsets) ActionRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionRequestDto) CELL_INFO(org.opensmartgridplatform.dlms.interfaceclass.attribute.GsmDiagnosticAttribute.CELL_INFO) List(java.util.List) Component(org.springframework.stereotype.Component) ADJACENT_CELLS(org.opensmartgridplatform.dlms.interfaceclass.attribute.GsmDiagnosticAttribute.ADJACENT_CELLS) SignalQualityDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SignalQualityDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) CIRCUIT_SWITCHED_STATUS(org.opensmartgridplatform.dlms.interfaceclass.attribute.GsmDiagnosticAttribute.CIRCUIT_SWITCHED_STATUS) Collections(java.util.Collections) CellInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CellInfoDto) JdlmsObjectToStringUtil(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.JdlmsObjectToStringUtil) GetGsmDiagnosticResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticResponseDto) GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)

Aggregations

AttributeAddress (org.openmuc.jdlms.AttributeAddress)77 DataObject (org.openmuc.jdlms.datatypes.DataObject)38 ObisCode (org.openmuc.jdlms.ObisCode)18 Test (org.junit.jupiter.api.Test)16 GetResult (org.openmuc.jdlms.GetResult)16 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)16 SetParameter (org.openmuc.jdlms.SetParameter)15 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)14 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)8 DateTime (org.joda.time.DateTime)7 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)6 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)6 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 Collectors (java.util.stream.Collectors)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5