Search in sources :

Example 1 with DlmsConnectionManager

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager in project open-smart-grid-platform by OSGP.

the class GetFirmwareVersionsCommandExecutorTest method setUp.

@BeforeEach
public void setUp() {
    this.executor = new GetFirmwareVersionsCommandExecutor(this.helperService);
    this.connectionHolder = new DlmsConnectionManager(null, null, null, this.listener, null);
    this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
}
Also used : DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DlmsConnectionManager

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager in project open-smart-grid-platform by OSGP.

the class DlmsHelperTest method testGetWithListWorkaround.

@Test
public void testGetWithListWorkaround() throws ProtocolAdapterException, IOException {
    final DlmsConnection dlmsConnection = mock(DlmsConnection.class);
    final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
    final DlmsDevice dlmsDevice = mock(DlmsDevice.class);
    when(connectionManager.getConnection()).thenReturn(dlmsConnection);
    final AttributeAddress[] attrAddresses = new AttributeAddress[1];
    attrAddresses[0] = mock(AttributeAddress.class);
    when(dlmsDevice.isWithListSupported()).thenReturn(false);
    this.dlmsHelper.getWithList(connectionManager, dlmsDevice, attrAddresses);
    verify(dlmsConnection).get(attrAddresses[0]);
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnection(org.openmuc.jdlms.DlmsConnection) Test(org.junit.jupiter.api.Test)

Example 3 with DlmsConnectionManager

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Processing {} response message", this.messageType.name());
    }
    // Get metadata from message and update message type to update
    // firmware
    final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
    final Serializable messageObject = message.getObject();
    final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = conn -> this.processMessageTasks(messageObject, messageMetadata, conn);
    try {
        this.createAndHandleConnectionForDevice(this.domainHelperService.findDlmsDevice(messageMetadata), messageMetadata, taskForConnectionManager);
    } catch (final OsgpException e) {
        LOGGER.error("Something went wrong with the DlmsConnection", e);
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) Logger(org.slf4j.Logger) OsgpResponseMessageProcessor(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.responses.from.core.OsgpResponseMessageProcessor) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) Component(org.springframework.stereotype.Component) FirmwareService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.FirmwareService) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)

Example 4 with DlmsConnectionManager

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager 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)

Example 5 with DlmsConnectionManager

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager in project open-smart-grid-platform by OSGP.

the class DlmsHelperTest method testGetWithListSupported.

@Test
public void testGetWithListSupported() throws ProtocolAdapterException, IOException {
    final DlmsConnection dlmsConnection = mock(DlmsConnection.class);
    final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
    final DlmsDevice dlmsDevice = mock(DlmsDevice.class);
    when(connectionManager.getConnection()).thenReturn(dlmsConnection);
    final AttributeAddress[] attrAddresses = new AttributeAddress[1];
    attrAddresses[0] = mock(AttributeAddress.class);
    when(dlmsDevice.isWithListSupported()).thenReturn(true);
    this.dlmsHelper.getWithList(connectionManager, dlmsDevice, attrAddresses);
    verify(dlmsConnection).get(Arrays.asList(attrAddresses));
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnection(org.openmuc.jdlms.DlmsConnection) Test(org.junit.jupiter.api.Test)

Aggregations

DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)9 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)8 AttributeAddress (org.openmuc.jdlms.AttributeAddress)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Serializable (java.io.Serializable)3 JMSException (javax.jms.JMSException)3 ObjectMessage (javax.jms.ObjectMessage)3 DlmsConnection (org.openmuc.jdlms.DlmsConnection)3 SilentException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)3 ThrowingConsumer (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer)3 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 PostConstruct (javax.annotation.PostConstruct)2 Test (org.junit.jupiter.api.Test)2 AccessResultCode (org.openmuc.jdlms.AccessResultCode)2 GetResult (org.openmuc.jdlms.GetResult)2