Search in sources :

Example 16 with CosemDateTimeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto in project open-smart-grid-platform by OSGP.

the class DlmsHelper method buildWindowElementFromDataObjects.

private WindowElementDto buildWindowElementFromDataObjects(final List<DataObject> elements, final String description) throws ProtocolAdapterException {
    if (elements.size() != 2) {
        LOGGER.error("Unexpected number of ResultData elements for WindowElement value: {}", elements.size());
        throw new ProtocolAdapterException("Expected list for WindowElement to contain 2 elements, got: " + elements.size());
    }
    final CosemDateTimeDto startTime = this.readDateTime(elements.get(0), "Start Time from " + description);
    final CosemDateTimeDto endTime = this.readDateTime(elements.get(1), "End Time from " + description);
    return new WindowElementDto(startTime, endTime);
}
Also used : WindowElementDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WindowElementDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 17 with CosemDateTimeDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto in project open-smart-grid-platform by OSGP.

the class DlmsHelper method fromDateTimeValue.

public CosemDateTimeDto fromDateTimeValue(final byte[] dateTimeValue) {
    final ByteBuffer bb = ByteBuffer.wrap(dateTimeValue);
    final int year = bb.getShort() & 0xFFFF;
    final int monthOfYear = bb.get() & 0xFF;
    final int dayOfMonth = bb.get() & 0xFF;
    final int dayOfWeek = bb.get() & 0xFF;
    final int hourOfDay = bb.get() & 0xFF;
    final int minuteOfHour = bb.get() & 0xFF;
    final int secondOfMinute = bb.get() & 0xFF;
    final int hundredthsOfSecond = bb.get() & 0xFF;
    final int deviation = bb.getShort();
    final byte clockStatusValue = bb.get();
    final CosemDateDto date = new CosemDateDto(year, monthOfYear, dayOfMonth, dayOfWeek);
    final CosemTimeDto time = new CosemTimeDto(hourOfDay, minuteOfHour, secondOfMinute, hundredthsOfSecond);
    final ClockStatusDto clockStatus = new ClockStatusDto(clockStatusValue);
    return new CosemDateTimeDto(date, time, deviation, clockStatus);
}
Also used : CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) ClockStatusDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ClockStatusDto) ByteBuffer(java.nio.ByteBuffer) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Aggregations

CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)17 DateTime (org.joda.time.DateTime)6 GetResult (org.openmuc.jdlms.GetResult)6 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)6 Date (java.util.Date)5 Test (org.junit.jupiter.api.Test)5 AttributeAddress (org.openmuc.jdlms.AttributeAddress)4 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)4 ArrayList (java.util.ArrayList)3 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)3 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)3 LocalDateTime (java.time.LocalDateTime)2 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)2 DlmsCaptureObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject)2 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)2 DlmsClock (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock)2 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)2 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)2