Search in sources :

Example 1 with DlmsClock

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock in project open-smart-grid-platform by OSGP.

the class DlmsObjectConfigSmr50 method initObjects.

@Override
List<DlmsObject> initObjects() {
    final List<DlmsObject> objectList = new ArrayList<>();
    // Abstract objects
    final DlmsObject clock = new DlmsClock("0.0.1.0.0.255");
    final DlmsObject amrStatusIntervalE = new DlmsData(AMR_STATUS, "0.0.96.10.2.255");
    final DlmsObject amrStatusIntervalG = new DlmsData(AMR_STATUS, "0.<c>.96.10.3.255");
    final DlmsObject amrStatusDailyE = new DlmsData(AMR_STATUS, "0.0.96.10.4.255");
    final DlmsObject amrStatusDailyG = new DlmsData(AMR_STATUS, "0.<c>.96.10.5.255");
    final DlmsObject amrStatusMonthlyE = new DlmsData(AMR_STATUS, "0.0.96.10.6.255");
    final DlmsObject amrStatusMonthlyG = new DlmsData(AMR_STATUS, "0.<c>.96.10.7.255");
    final DlmsObject alarmFilter1 = new DlmsData(ALARM_FILTER_1, "0.0.97.98.10.255");
    final DlmsObject alarmRegister1 = new DlmsData(ALARM_REGISTER_1, "0.0.97.98.0.255");
    final DlmsObject randomisationSettings = new DlmsData(RANDOMISATION_SETTINGS, "0.1.94.31.12.255");
    objectList.addAll(Arrays.asList(clock, amrStatusIntervalE, amrStatusIntervalG, amrStatusDailyE, amrStatusDailyG, amrStatusMonthlyE, amrStatusMonthlyG, alarmFilter1, alarmRegister1, randomisationSettings));
    final DlmsObject pushScheduler = new DlmsSingleActionSchedule(PUSH_SCHEDULER, "0.0.15.0.4.255");
    final DlmsObject pushSetupScheduler = new DlmsPushSetup(PUSH_SETUP_SCHEDULER, "0.0.25.9.0.255");
    final DlmsObject externalTriggerSmsOrCsd = new DlmsAutoAnswer(EXTERNAL_TRIGGER, "0.0.2.2.0.255");
    final DlmsObject internalTriggerAlarm = new DlmsRegisterMonitor(INTERNAL_TRIGGER_ALARM, "0.0.16.1.0.255");
    final DlmsObject pushSetupAlarm = new DlmsPushSetup(PUSH_SETUP_ALARM, "0.1.25.9.0.255");
    objectList.addAll(Arrays.asList(pushScheduler, pushSetupScheduler, externalTriggerSmsOrCsd, internalTriggerAlarm, pushSetupAlarm));
    final DlmsObject standardEventLogCode = new DlmsData(STANDARD_EVENT_CODE, "0.0.96.11.0.255");
    final DlmsObject fraudDetectionEventLogCode = new DlmsData(FRAUD_DETECTION_EVENT_CODE, "0.0.96.11.1.255");
    final DlmsObject mbusEventLogCode = new DlmsData(MBUS_EVENT_CODE, "0.0.96.11.3.255");
    final DlmsObject communicationSessionsEventLogCode = new DlmsData(COMMUNICATION_SESSIONS_EVENT_CODE, "0.0.96.11.4.255");
    final DlmsObject powerQualityEventLogCode = new DlmsData(POWER_QUALITY_EVENT_CODE, "0.0.96.11.5.255");
    objectList.addAll(Arrays.asList(standardEventLogCode, fraudDetectionEventLogCode, mbusEventLogCode, communicationSessionsEventLogCode, powerQualityEventLogCode));
    // Electricity objects
    final DlmsObject activeEnergyImport = new DlmsRegister(ACTIVE_ENERGY_IMPORT, "1.0.1.8.0.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyExport = new DlmsRegister(ACTIVE_ENERGY_EXPORT, "1.0.2.8.0.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyImportRate1 = new DlmsRegister(ACTIVE_ENERGY_IMPORT_RATE_1, "1.0.1.8.1.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyImportRate2 = new DlmsRegister(ACTIVE_ENERGY_IMPORT_RATE_2, "1.0.1.8.2.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyExportRate1 = new DlmsRegister(ACTIVE_ENERGY_EXPORT_RATE_1, "1.0.2.8.1.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyExportRate2 = new DlmsRegister(ACTIVE_ENERGY_EXPORT_RATE_2, "1.0.2.8.2.255", 0, WH, ELECTRICITY);
    objectList.addAll(Arrays.asList(activeEnergyImport, activeEnergyExport, activeEnergyImportRate1, activeEnergyImportRate2, activeEnergyExportRate1, activeEnergyExportRate2));
    // Gas objects
    final DlmsObject mbusMasterValue = new DlmsExtendedRegister(MBUS_MASTER_VALUE, "0.<c>.24.2.2.255", 0, M3, GAS);
    final DlmsObject mbusClientSetup = new DlmsMbusClientSetup(MBUS_CLIENT_SETUP, "0.<c>.24.1.0.255", VERSION_1);
    objectList.addAll(Arrays.asList(mbusMasterValue, mbusClientSetup));
    final List<DlmsCaptureObject> captureObjectsIntervalE = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusIntervalE), DlmsCaptureObject.create(activeEnergyImport), DlmsCaptureObject.create(activeEnergyExport));
    objectList.add(new DlmsProfile(INTERVAL_VALUES, "1.0.99.1.0.255", captureObjectsIntervalE, QUARTER_HOUR, ELECTRICITY));
    final List<DlmsCaptureObject> captureObjectsIntervalG = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusIntervalG), DlmsCaptureObject.create(mbusMasterValue), DlmsCaptureObject.create(mbusMasterValue, 5));
    objectList.add(new DlmsProfile(INTERVAL_VALUES, "0.<c>.24.3.0.255", captureObjectsIntervalG, HOUR, GAS));
    final List<DlmsCaptureObject> captureObjectsDailyE = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusDailyE), DlmsCaptureObject.create(activeEnergyImportRate1), DlmsCaptureObject.create(activeEnergyImportRate2), DlmsCaptureObject.create(activeEnergyExportRate1), DlmsCaptureObject.create(activeEnergyExportRate2));
    objectList.add(new DlmsProfile(DAILY_LOAD_PROFILE, "1.0.99.2.0.255", captureObjectsDailyE, DAY, ELECTRICITY));
    final List<DlmsCaptureObject> captureObjectsDailyG = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusDailyG), DlmsCaptureObject.create(mbusMasterValue), DlmsCaptureObject.create(mbusMasterValue, 5));
    objectList.add(new DlmsProfile(DAILY_LOAD_PROFILE, "0.<c>.24.3.1.255", captureObjectsDailyG, DAY, GAS));
    final List<DlmsCaptureObject> captureObjectsMonthly = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusMonthlyE), DlmsCaptureObject.create(activeEnergyImportRate1), DlmsCaptureObject.create(activeEnergyImportRate2), DlmsCaptureObject.create(activeEnergyExportRate1), DlmsCaptureObject.create(activeEnergyExportRate2));
    objectList.add(new DlmsProfile(MONTHLY_BILLING_VALUES, "1.0.98.1.0.255", captureObjectsMonthly, MONTH, ELECTRICITY));
    final List<DlmsCaptureObject> captureObjectsMonthlyG = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusMonthlyG), DlmsCaptureObject.create(mbusMasterValue), DlmsCaptureObject.create(mbusMasterValue, 5));
    objectList.add(new DlmsProfile(MONTHLY_BILLING_VALUES, "0.<c>.24.3.2.255", captureObjectsMonthlyG, MONTH, GAS));
    // Event logs
    final List<DlmsCaptureObject> captureObjectsStandardEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(standardEventLogCode));
    objectList.add(new DlmsProfile(STANDARD_EVENT_LOG, "0.0.99.98.0.255", captureObjectsStandardEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsFraudDetectionEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(fraudDetectionEventLogCode));
    objectList.add(new DlmsProfile(FRAUD_DETECTION_EVENT_LOG, "0.0.99.98.1.255", captureObjectsFraudDetectionEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsMBusEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(mbusEventLogCode));
    objectList.add(new DlmsProfile(MBUS_EVENT_LOG, "0.0.99.98.3.255", captureObjectsMBusEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsCommunicationSessionsEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(communicationSessionsEventLogCode));
    objectList.add(new DlmsProfile(COMMUNICATION_SESSIONS_EVENT_LOG, "0.0.99.98.4.255", captureObjectsCommunicationSessionsEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsPowerQualityEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(powerQualityEventLogCode));
    objectList.add(new DlmsProfile(POWER_QUALITY_EVENT_LOG, "0.0.99.98.5.255", captureObjectsPowerQualityEvents, ASYNCHRONOUSLY, ABSTRACT));
    // Additional read mbus status for SMR5.0
    final DlmsObject readMBusStatus = new DlmsObject(READ_MBUS_STATUS, InterfaceClass.EXTENDED_REGISTER.id(), "0.<c>.24.2.6.255");
    final DlmsObject clientSetupMBus = new DlmsObject(CLIENT_SETUP_MBUS, InterfaceClass.MBUS_CLIENT.id(), "0.<c>.24.1.0.255");
    objectList.addAll(Arrays.asList(readMBusStatus, clientSetupMBus));
    return objectList;
}
Also used : DlmsSingleActionSchedule(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsSingleActionSchedule) ArrayList(java.util.ArrayList) DlmsMbusClientSetup(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsMbusClientSetup) DlmsClock(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock) DlmsRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegister) DlmsExtendedRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsExtendedRegister) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) DlmsPushSetup(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsPushSetup) DlmsAutoAnswer(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsAutoAnswer) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DlmsData(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsData) DlmsRegisterMonitor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegisterMonitor)

Example 2 with DlmsClock

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock in project open-smart-grid-platform by OSGP.

the class GetPeriodicMeterReadsCommandExecutorTest method testHappy.

@Test
void testHappy() throws Exception {
    // SETUP
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(periodType, new Date(this.from), new Date(this.to));
    // SETUP - dlms objects
    final DlmsObject dlmsClock = new DlmsClock("0.0.1.0.0.255");
    final DlmsCaptureObject captureObject1 = new DlmsCaptureObject(dlmsClock, 2);
    final DlmsObject activeEnergyImportRate1 = new DlmsObject(DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_1, 0, "1.0.1.8.1.255");
    final DlmsCaptureObject captureObject2 = new DlmsCaptureObject(activeEnergyImportRate1, 2);
    final DlmsObject activeEnergyImportRate2 = new DlmsObject(DlmsObjectType.ACTIVE_ENERGY_IMPORT_RATE_2, 0, "1.0.1.8.2.255");
    final DlmsCaptureObject captureObject3 = new DlmsCaptureObject(activeEnergyImportRate2, 2);
    final DlmsObject activeEnergyExportRate1 = new DlmsObject(DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_1, 0, "1.0.2.8.1.255");
    final DlmsCaptureObject captureObject4 = new DlmsCaptureObject(activeEnergyExportRate1, 2);
    final DlmsObject activeEnergyExportRate2 = new DlmsObject(DlmsObjectType.ACTIVE_ENERGY_EXPORT_RATE_2, 0, "1.0.2.8.2.255");
    final DlmsCaptureObject captureObject5 = new DlmsCaptureObject(activeEnergyExportRate2, 2);
    final List<DlmsCaptureObject> captureObjects = Arrays.asList(captureObject1, captureObject2, captureObject3, captureObject4, captureObject5);
    final DlmsProfile dlmsProfile = new DlmsProfile(DlmsObjectType.DAILY_LOAD_PROFILE, "1.0.99.2.0.255", captureObjects, ProfileCaptureTime.DAY, Medium.ELECTRICITY);
    // SETUP - mock dlms object config to return attribute addresses
    final AttributeAddressForProfile attributeAddressForProfile = this.createAttributeAddressForProfile(dlmsProfile, captureObjects);
    final AttributeAddress attributeAddress = this.createAttributeAddress(dlmsProfile);
    when(this.dlmsObjectConfigService.findAttributeAddressForProfile(this.device, DlmsObjectType.DAILY_LOAD_PROFILE, 0, this.fromDateTime, this.toDateTime, Medium.ELECTRICITY)).thenReturn(Optional.of(attributeAddressForProfile));
    final DlmsObject intervalTime = mock(DlmsObject.class);
    when(this.dlmsObjectConfigService.findDlmsObject(any(Protocol.class), any(DlmsObjectType.class), any(Medium.class))).thenReturn(Optional.of(intervalTime));
    // SETUP - mock dlms helper to return data objects on request
    final DataObject data0 = mock(DataObject.class);
    // make sure to set logTime on first dataObject
    final List<DataObject> bufferedObjectValue = new ArrayList<>();
    when(data0.getValue()).thenReturn(bufferedObjectValue);
    final DataObject data1 = mock(DataObject.class);
    when(data1.isNumber()).thenReturn(true);
    final DataObject data2 = mock(DataObject.class);
    final DataObject data3 = mock(DataObject.class);
    final DataObject data4 = mock(DataObject.class);
    final DataObject data5 = mock(DataObject.class);
    final DataObject bufferedObject1 = mock(DataObject.class);
    when(bufferedObject1.getValue()).thenReturn(asList(data0, data1, data2, data3, data4, data5));
    final DataObject bufferedObject2 = mock(DataObject.class);
    when(bufferedObject2.getValue()).thenReturn(asList(data0, data1, data2, data3, data4, data5));
    final DataObject resultData = mock(DataObject.class);
    when(resultData.getValue()).thenReturn(Arrays.asList(bufferedObject1, bufferedObject2));
    final String expectedDescription = "retrieve periodic meter reads for " + periodType;
    final GetResult result0 = mock(GetResult.class);
    final GetResult result1 = mock(GetResult.class);
    final GetResult result2 = mock(GetResult.class);
    final GetResult result3 = mock(GetResult.class);
    final GetResult result4 = mock(GetResult.class);
    final GetResult result5 = mock(GetResult.class);
    final GetResult getResult = mock(GetResult.class);
    when(this.dlmsHelper.getAndCheck(this.connectionManager, this.device, expectedDescription, attributeAddress)).thenReturn(asList(result0, result1, result2, result3, result4, result5));
    when(this.dlmsHelper.readDataObject(result0, PERIODIC_E_METER_READS)).thenReturn(resultData);
    when(this.dlmsHelper.getAndCheck(this.connectionManager, this.device, expectedDescription, attributeAddressForProfile.getAttributeAddress())).thenReturn(Collections.singletonList(getResult));
    when(this.dlmsHelper.getAndCheck(this.connectionManager, this.device, expectedDescription, attributeAddress)).thenReturn(Collections.singletonList(getResult));
    when(this.dlmsHelper.readDataObject(eq(getResult), any(String.class))).thenReturn(resultData);
    final CosemDateTimeDto cosemDateTime = mock(CosemDateTimeDto.class);
    final String expectedDateTimeDescription = String.format("Clock from %s buffer", periodType);
    when(this.dlmsHelper.readDateTime(data0, expectedDateTimeDescription)).thenReturn(cosemDateTime);
    final DateTime bufferedDateTime = DateTime.now();
    when(cosemDateTime.asDateTime()).thenReturn(bufferedDateTime);
    // CALL
    final PeriodicMeterReadsResponseDto result = this.executor.execute(this.connectionManager, this.device, request, this.messageMetadata);
    // VERIFY calls to mocks
    verify(this.dlmsMessageListener).setDescription(String.format("GetPeriodicMeterReads DAILY from %s until %s, retrieve attribute: {%s,%s,%s}", new DateTime(this.from), new DateTime(this.to), dlmsProfile.getClassId(), dlmsProfile.getObisCode(), dlmsProfile.getDefaultAttributeId()));
    verify(this.dlmsHelper, times(2)).validateBufferedDateTime(same(bufferedDateTime), argThat(new DateTimeMatcher(this.from)), argThat(new DateTimeMatcher(this.to)));
    verify(this.dlmsObjectConfigService).findDlmsObject(any(Protocol.class), any(DlmsObjectType.class), any(Medium.class));
    // ASSERT - the result should contain 2 values
    final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads = result.getPeriodicMeterReads();
    assertThat(periodicMeterReads.size()).isEqualTo(2);
    periodicMeterReads.forEach(p -> assertThat(p.getLogTime()).isNotNull());
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodicMeterReadsResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseItemDto) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ArrayList(java.util.ArrayList) PeriodicMeterReadsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsResponseDto) Date(java.util.Date) DateTime(org.joda.time.DateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) DlmsClock(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock) DataObject(org.openmuc.jdlms.datatypes.DataObject) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) DlmsCaptureObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) Test(org.junit.jupiter.api.Test)

Example 3 with DlmsClock

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock in project open-smart-grid-platform by OSGP.

the class DlmsObjectConfigDsmr422 method initObjects.

@Override
List<DlmsObject> initObjects() {
    final List<DlmsObject> objectList = new ArrayList<>();
    // Abstract objects
    final DlmsObject clock = new DlmsClock("0.0.1.0.0.255");
    final DlmsObject amrStatus = new DlmsData(AMR_STATUS, "0.0.96.10.2.255");
    final DlmsObject amrStatusMbus = new DlmsData(AMR_STATUS, "0.<c>.96.10.2.255");
    final DlmsObject alarmFilter1 = new DlmsData(ALARM_FILTER_1, "0.0.97.98.10.255");
    final DlmsObject alarmRegister1 = new DlmsData(ALARM_REGISTER_1, "0.0.97.98.0.255");
    final DlmsObject randomisationSettings = new DlmsData(RANDOMISATION_SETTINGS, "0.1.94.31.12.255");
    objectList.addAll(Arrays.asList(clock, amrStatus, amrStatusMbus, alarmFilter1, alarmRegister1, randomisationSettings));
    final DlmsObject pushScheduler = new DlmsSingleActionSchedule(PUSH_SCHEDULER, "0.0.15.0.4.255");
    final DlmsObject pushSetupScheduler = new DlmsPushSetup(PUSH_SETUP_SCHEDULER, "0.0.25.9.0.255");
    final DlmsObject externalTriggerSms = new DlmsMessageHandler(EXTERNAL_TRIGGER_SMS, "0.0.2.3.0.255");
    final DlmsObject externalTriggerCsd = new DlmsAutoAnswer(EXTERNAL_TRIGGER_CSD, "0.0.2.2.0.255");
    final DlmsObject internalTriggerAlarm = new DlmsRegisterMonitor(INTERNAL_TRIGGER_ALARM, "0.0.16.1.0.255");
    final DlmsObject pushSetupAlarm = new DlmsPushSetup(PUSH_SETUP_ALARM, "0.1.25.9.0.255");
    objectList.addAll(Arrays.asList(pushScheduler, pushSetupScheduler, externalTriggerSms, externalTriggerCsd, internalTriggerAlarm, pushSetupAlarm));
    final DlmsObject standardEventLogCode = new DlmsData(STANDARD_EVENT_CODE, "0.0.96.11.0.255");
    final DlmsObject fraudDetectionEventLogCode = new DlmsData(FRAUD_DETECTION_EVENT_CODE, "0.0.96.11.1.255");
    final DlmsObject mbusEventLogCode = new DlmsData(MBUS_EVENT_CODE, "0.0.96.11.3.255");
    final DlmsObject communicationSessionsEventLogCode = new DlmsData(COMMUNICATION_SESSIONS_EVENT_CODE, "0.0.96.11.4.255");
    objectList.addAll(Arrays.asList(standardEventLogCode, fraudDetectionEventLogCode, mbusEventLogCode));
    // Electricity objects
    final DlmsObject activeEnergyImport = new DlmsRegister(ACTIVE_ENERGY_IMPORT, "1.0.1.8.0.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyExport = new DlmsRegister(ACTIVE_ENERGY_EXPORT, "1.0.2.8.0.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyImportRate1 = new DlmsRegister(ACTIVE_ENERGY_IMPORT_RATE_1, "1.0.1.8.1.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyImportRate2 = new DlmsRegister(ACTIVE_ENERGY_IMPORT_RATE_2, "1.0.1.8.2.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyExportRate1 = new DlmsRegister(ACTIVE_ENERGY_EXPORT_RATE_1, "1.0.2.8.1.255", 0, WH, ELECTRICITY);
    final DlmsObject activeEnergyExportRate2 = new DlmsRegister(ACTIVE_ENERGY_EXPORT_RATE_2, "1.0.2.8.2.255", 0, WH, ELECTRICITY);
    objectList.addAll(Arrays.asList(activeEnergyImport, activeEnergyExport, activeEnergyImportRate1, activeEnergyImportRate2, activeEnergyExportRate1, activeEnergyExportRate2));
    // Gas objects
    final DlmsObject mbusMasterValue = new DlmsExtendedRegister(MBUS_MASTER_VALUE, "0.<c>.24.2.1.255", 0, M3, GAS);
    final DlmsObject mbusClientSetup = new DlmsMbusClientSetup(MBUS_CLIENT_SETUP, "0.<c>.24.1.0.255", VERSION_0);
    objectList.addAll(Arrays.asList(mbusMasterValue, mbusClientSetup));
    // Profiles
    final List<DlmsCaptureObject> captureObjectsIntervalE = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatus), DlmsCaptureObject.create(activeEnergyImport), DlmsCaptureObject.create(activeEnergyExport));
    objectList.add(new DlmsProfile(INTERVAL_VALUES, "1.0.99.1.0.255", captureObjectsIntervalE, QUARTER_HOUR, ELECTRICITY));
    final List<DlmsCaptureObject> captureObjectsIntervalG = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatusMbus), DlmsCaptureObject.create(mbusMasterValue), DlmsCaptureObject.create(mbusMasterValue, 5));
    objectList.add(new DlmsProfile(INTERVAL_VALUES, "0.<c>.24.3.0.255", captureObjectsIntervalG, HOUR, GAS));
    final List<DlmsCaptureObject> captureObjectsDaily = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(amrStatus), DlmsCaptureObject.create(activeEnergyImportRate1), DlmsCaptureObject.create(activeEnergyImportRate2), DlmsCaptureObject.create(activeEnergyExportRate1), DlmsCaptureObject.create(activeEnergyExportRate2), DlmsCaptureObject.createWithChannel(mbusMasterValue, 1), DlmsCaptureObject.createWithChannel(mbusMasterValue, 1, 5), DlmsCaptureObject.createWithChannel(mbusMasterValue, 2), DlmsCaptureObject.createWithChannel(mbusMasterValue, 2, 5), DlmsCaptureObject.createWithChannel(mbusMasterValue, 3), DlmsCaptureObject.createWithChannel(mbusMasterValue, 3, 5), DlmsCaptureObject.createWithChannel(mbusMasterValue, 4), DlmsCaptureObject.createWithChannel(mbusMasterValue, 4, 5));
    objectList.add(new DlmsProfile(DAILY_LOAD_PROFILE, "1.0.99.2.0.255", captureObjectsDaily, DAY, COMBINED));
    final List<DlmsCaptureObject> captureObjectsMonthly = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(activeEnergyImportRate1), DlmsCaptureObject.create(activeEnergyImportRate2), DlmsCaptureObject.create(activeEnergyExportRate1), DlmsCaptureObject.create(activeEnergyExportRate2), DlmsCaptureObject.createWithChannel(mbusMasterValue, 1), DlmsCaptureObject.createWithChannel(mbusMasterValue, 1, 5), DlmsCaptureObject.createWithChannel(mbusMasterValue, 2), DlmsCaptureObject.createWithChannel(mbusMasterValue, 2, 5), DlmsCaptureObject.createWithChannel(mbusMasterValue, 3), DlmsCaptureObject.createWithChannel(mbusMasterValue, 3, 5), DlmsCaptureObject.createWithChannel(mbusMasterValue, 4), DlmsCaptureObject.createWithChannel(mbusMasterValue, 4, 5));
    objectList.add(new DlmsProfile(MONTHLY_BILLING_VALUES, "0.0.98.1.0.255", captureObjectsMonthly, MONTH, COMBINED));
    // Event logs
    final List<DlmsCaptureObject> captureObjectsStandardEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(standardEventLogCode));
    objectList.add(new DlmsProfile(STANDARD_EVENT_LOG, "0.0.99.98.0.255", captureObjectsStandardEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsFraudDetectionEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(fraudDetectionEventLogCode));
    objectList.add(new DlmsProfile(FRAUD_DETECTION_EVENT_LOG, "0.0.99.98.1.255", captureObjectsFraudDetectionEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsMBusEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(mbusEventLogCode));
    objectList.add(new DlmsProfile(MBUS_EVENT_LOG, "0.0.99.98.3.255", captureObjectsMBusEvents, ASYNCHRONOUSLY, ABSTRACT));
    final List<DlmsCaptureObject> captureObjectsCommunicationSessionsEvents = Arrays.asList(DlmsCaptureObject.create(clock), DlmsCaptureObject.create(communicationSessionsEventLogCode));
    objectList.add(new DlmsProfile(COMMUNICATION_SESSIONS_EVENT_LOG, "0.0.99.98.4.255", captureObjectsCommunicationSessionsEvents, ASYNCHRONOUSLY, ABSTRACT));
    final DlmsObject clientSetupMBus = new DlmsObject(CLIENT_SETUP_MBUS, InterfaceClass.MBUS_CLIENT.id(), "0.<c>.24.1.0.255");
    objectList.addAll(Collections.singletonList(clientSetupMBus));
    return objectList;
}
Also used : DlmsSingleActionSchedule(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsSingleActionSchedule) ArrayList(java.util.ArrayList) DlmsMessageHandler(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsMessageHandler) DlmsMbusClientSetup(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsMbusClientSetup) DlmsClock(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock) DlmsRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegister) DlmsExtendedRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsExtendedRegister) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) DlmsPushSetup(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsPushSetup) DlmsAutoAnswer(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsAutoAnswer) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DlmsData(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsData) DlmsRegisterMonitor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegisterMonitor)

Example 4 with DlmsClock

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock in project open-smart-grid-platform by OSGP.

the class GetPeriodicMeterReadsGasCommandExecutorTest method testHappy.

@Test
public void testHappy() throws Exception {
    // SETUP - request
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final ChannelDto channel = ChannelDto.ONE;
    final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(periodType, this.fromDateTime.toDate(), this.toDateTime.toDate(), channel);
    // SETUP - dlms objects
    final DlmsObject dlmsClock = new DlmsClock("0.0.1.0.0.255");
    final DlmsCaptureObject captureObject1 = new DlmsCaptureObject(dlmsClock, 2);
    final DlmsObject dlmsExtendedRegister = new DlmsExtendedRegister(DlmsObjectType.MBUS_MASTER_VALUE, "0.0.24.0.0.255", 0, RegisterUnit.M3, Medium.GAS);
    final DlmsCaptureObject captureObject2 = new DlmsCaptureObject(dlmsExtendedRegister, 2);
    final DlmsCaptureObject captureObject3 = new DlmsCaptureObject(dlmsExtendedRegister, 5);
    final List<DlmsCaptureObject> captureObjects = Arrays.asList(captureObject1, captureObject2, captureObject3);
    final DlmsProfile dlmsProfile = new DlmsProfile(DlmsObjectType.DAILY_LOAD_PROFILE, "1.2.3.4.5.6", captureObjects, ProfileCaptureTime.DAY, Medium.COMBINED);
    // SETUP - mock dlms object config to return attribute addresses
    final AttributeAddressForProfile attributeAddressForProfile = this.createAttributeAddressForProfile(dlmsProfile, captureObjects);
    final AttributeAddress attributeAddressScalerUnit = this.createAttributeAddress(dlmsExtendedRegister);
    when(this.dlmsObjectConfigService.findAttributeAddressForProfile(eq(this.device), eq(DlmsObjectType.DAILY_LOAD_PROFILE), eq(channel.getChannelNumber()), eq(this.fromDateTime), eq(this.toDateTime), eq(Medium.GAS))).thenReturn(Optional.of(attributeAddressForProfile));
    when(this.dlmsObjectConfigService.getAttributeAddressesForScalerUnit(eq(attributeAddressForProfile), eq(channel.getChannelNumber()))).thenReturn(Collections.singletonList(attributeAddressScalerUnit));
    final DlmsObject intervalTime = mock(DlmsObject.class);
    when(this.dlmsObjectConfigService.findDlmsObject(any(Protocol.class), any(DlmsObjectType.class), any(Medium.class))).thenReturn(Optional.of(intervalTime));
    // SETUP - mock dlms helper to return data objects on request
    final DataObject data0 = mock(DataObject.class);
    final DataObject data1 = mock(DataObject.class);
    final DataObject data2 = mock(DataObject.class);
    final DataObject bufferedObject1 = mock(DataObject.class);
    when(bufferedObject1.getValue()).thenReturn(asList(data0, data1, data2));
    final DataObject data3 = mock(DataObject.class);
    final DataObject data4 = mock(DataObject.class);
    final DataObject data5 = mock(DataObject.class);
    final DataObject bufferedObject2 = mock(DataObject.class);
    when(bufferedObject2.getValue()).thenReturn(asList(data3, data4, data5));
    final DataObject resultData = mock(DataObject.class);
    when(resultData.getValue()).thenReturn(asList(bufferedObject1, bufferedObject2));
    final String expectedDescription = "retrieve periodic meter reads for " + periodType + ", channel " + channel;
    final GetResult getResult = mock(GetResult.class);
    when(this.dlmsHelper.getAndCheck(eq(this.connectionManager), eq(this.device), eq(expectedDescription), eq(attributeAddressForProfile.getAttributeAddress()))).thenReturn(Collections.singletonList(getResult));
    when(this.dlmsHelper.getAndCheck(this.connectionManager, this.device, expectedDescription, attributeAddressScalerUnit)).thenReturn(Collections.singletonList(getResult));
    when(this.dlmsHelper.readDataObject(eq(getResult), any(String.class))).thenReturn(resultData);
    // SETUP - mock dlms helper to handle converting the data objects
    final String expectedDateTimeDescriptionLogTime = String.format("Clock from %s buffer", periodType);
    final String expectedDateTimeDescriptionCaptureTime = "Clock from mbus interval extended register";
    final CosemDateTimeDto cosemDateTime = new CosemDateTimeDto(this.fromDateTime);
    when(this.dlmsHelper.readDateTime(data0, expectedDateTimeDescriptionLogTime)).thenReturn(cosemDateTime);
    when(this.dlmsHelper.readDateTime(data3, expectedDateTimeDescriptionLogTime)).thenReturn(cosemDateTime);
    when(this.dlmsHelper.readDateTime(data2, expectedDateTimeDescriptionCaptureTime)).thenReturn(cosemDateTime);
    when(this.dlmsHelper.readDateTime(data5, expectedDateTimeDescriptionCaptureTime)).thenReturn(cosemDateTime);
    final DlmsMeterValueDto meterValue1 = mock(DlmsMeterValueDto.class);
    final DlmsMeterValueDto meterValue2 = mock(DlmsMeterValueDto.class);
    when(this.dlmsHelper.getScaledMeterValue(data1, null, "gasValue")).thenReturn(meterValue1);
    when(this.dlmsHelper.getScaledMeterValue(data4, null, "gasValue")).thenReturn(meterValue2);
    // CALL
    final PeriodicMeterReadGasResponseDto result = this.executor.execute(this.connectionManager, this.device, request, this.messageMetadata);
    // VERIFY - the right functions should be called
    verify(this.dlmsMessageListener).setDescription(String.format("GetPeriodicMeterReadsGas for channel ONE, DAILY from %s until %s, retrieve attribute: {%s,%s,%s}", new DateTime(this.from), new DateTime(this.to), dlmsProfile.getClassId(), dlmsProfile.getObisCodeAsString(), dlmsProfile.getDefaultAttributeId()));
    verify(this.dlmsHelper, times(2)).validateBufferedDateTime(any(DateTime.class), argThat(new DateTimeMatcher(this.from)), argThat(new DateTimeMatcher(this.to)));
    verify(this.dlmsObjectConfigService).findDlmsObject(any(Protocol.class), any(DlmsObjectType.class), any(Medium.class));
    // ASSERT - the result should contain 2 values
    final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads = result.getPeriodicMeterReadsGas();
    assertThat(periodicMeterReads.size()).isEqualTo(2);
    assertThat(periodicMeterReads.stream().anyMatch(r -> r.getConsumption() == meterValue1)).isEqualTo(true);
    assertThat(periodicMeterReads.stream().anyMatch(r -> r.getConsumption() == meterValue2)).isEqualTo(true);
    assertThat(periodicMeterReads.stream().allMatch(r -> this.areDatesEqual(r.getLogTime(), cosemDateTime))).isEqualTo(true);
    assertThat(periodicMeterReads.stream().allMatch(r -> this.areDatesEqual(r.getCaptureTime(), cosemDateTime))).isEqualTo(true);
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) ChannelDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DateTime(org.joda.time.DateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) DlmsClock(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock) DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsExtendedRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsExtendedRegister) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) DlmsCaptureObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Aggregations

DlmsClock (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock)4 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)4 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)4 ArrayList (java.util.ArrayList)3 DlmsExtendedRegister (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsExtendedRegister)3 DateTime (org.joda.time.DateTime)2 Test (org.junit.jupiter.api.Test)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 GetResult (org.openmuc.jdlms.GetResult)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)2 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)2 DlmsCaptureObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject)2 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)2 DlmsAutoAnswer (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsAutoAnswer)2 DlmsData (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsData)2 DlmsMbusClientSetup (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsMbusClientSetup)2 DlmsPushSetup (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsPushSetup)2 DlmsRegister (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegister)2 DlmsRegisterMonitor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegisterMonitor)2 DlmsSingleActionSchedule (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsSingleActionSchedule)2