Search in sources :

Example 1 with CosemDateTime

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

the class Smr51Profile method gsmGprsDiagnostic.

@Bean
public GsmDiagnostic gsmGprsDiagnostic() {
    final CellInfo cellInfo = new CellInfo(this.gsmDiagnosticCellInfoCellId, this.gsmDiagnosticCellInfoLocationId, this.gsmDiagnosticCellInfoSignalQuality, this.gsmDiagnosticCellInfoBer, this.gsmDiagnosticCellInfoMcc, this.gsmDiagnosticCellInfoMnc, this.gsmDiagnosticCellInfoChannelNumber);
    final List<AdjacentCellInfo> adjacentCellInfos = IntStream.range(0, this.gsmDiagnosticAdjacentCellsCellIds.size()).mapToObj(i -> new AdjacentCellInfo(this.gsmDiagnosticAdjacentCellsCellIds.get(i), this.gsmDiagnosticAdjacentCellsSignalQualities.get(i))).collect(Collectors.toList());
    final CosemDateTime captureTime = new CosemDateTime(this.gsmDiagnosticYear, this.gsmDiagnosticMonth, this.gsmDiagnosticDayOfMonth, this.gsmDiagnosticDayOfWeek, this.gsmDiagnosticHour, this.gsmDiagnosticMinute, this.gsmDiagnosticSecond, this.gsmDiagnosticHundredths, this.gsmDiagnosticDeviation, ClockStatus.clockStatusFrom(this.gsmDiagnosticClockStatus).toArray(new ClockStatus[0]));
    return new GsmDiagnostic("0.0.25.6.0.255", this.gsmDiagnosticOperator, this.gsmDiagnosticStatus, this.gsmDiagnosticCsAttachment, this.gsmDiagnosticPsStatus, cellInfo, adjacentCellInfos, captureTime);
}
Also used : IntStream(java.util.stream.IntStream) MBusClearStatusMask(org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusClearStatusMask) MBusReadStatus(org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusReadStatus) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) AdjacentCellInfo(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.AdjacentCellInfo) Value(org.springframework.beans.factory.annotation.Value) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Calendar(java.util.Calendar) AuxiliaryEventLog(org.opensmartgridplatform.simulator.protocol.dlms.cosem.AuxiliaryEventLog) CellInfo(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.CellInfo) Bean(org.springframework.context.annotation.Bean) GsmDiagnostic(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic) ClockStatus(org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus) AdjacentCellInfo(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.AdjacentCellInfo) CellInfo(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.CellInfo) ClockStatus(org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) GsmDiagnostic(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic) AdjacentCellInfo(org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.AdjacentCellInfo) Bean(org.springframework.context.annotation.Bean)

Example 2 with CosemDateTime

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

the class CosemDateTimeFilterTest method asDataObject.

/**
 * Creates a COSEM date-time object based on the given {@code dateTime}. This COSEM date-time will
 * be for the same instant in time as the given {@code dateTime} but may be for another time zone.
 *
 * <p>Because the time zone with the {@code deviation} may be different than the one with the
 * {@code dateTime}, and the {@code deviation} alone does not provide sufficient information on
 * whether daylight savings is active for the given instant in time, {@code dst} has to be
 * provided to indicate whether daylight savings are active.
 *
 * @param dateTime a DateTime indicating an instant in time to be used for the COSEM date-time.
 * @param deviation the deviation in minutes of local time to GMT to be included in the COSEM
 *     date-time.
 * @param dst {@code true} if daylight savings are active for the instant of the COSEM date-time,
 *     otherwise {@code false}.
 * @return a DataObject having a CosemDateTime for the instant of the given DateTime, with the
 *     given deviation and DST status information, as value.
 */
public DataObject asDataObject(final DateTime dateTime, final int deviation, final boolean dst) {
    /*
     * Create a date time that may not point to the right instant in time,
     * but that will give proper values getting the different fields for the
     * COSEM date and time objects.
     */
    final DateTime dateTimeWithOffset = dateTime.toDateTime(DateTimeZone.UTC).minusMinutes(deviation);
    final CosemDate cosemDate = new CosemDate(dateTimeWithOffset.getYear(), dateTimeWithOffset.getMonthOfYear(), dateTimeWithOffset.getDayOfMonth());
    final CosemTime cosemTime = new CosemTime(dateTimeWithOffset.getHourOfDay(), dateTimeWithOffset.getMinuteOfHour(), dateTimeWithOffset.getSecondOfMinute(), dateTimeWithOffset.getMillisOfSecond() / 10);
    final ClockStatus[] clockStatusBits;
    if (dst) {
        clockStatusBits = new ClockStatus[1];
        clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE;
    } else {
        clockStatusBits = new ClockStatus[0];
    }
    final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits);
    return DataObject.newOctetStringData(cosemDateTime.encode());
}
Also used : ClockStatus(org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus) CosemTime(org.openmuc.jdlms.datatypes.CosemTime) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) CosemDate(org.openmuc.jdlms.datatypes.CosemDate) DateTime(org.joda.time.DateTime) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime)

Example 3 with CosemDateTime

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

the class ClockTest method transistionFromDst.

private void transistionFromDst(final Clock clock, final String hexDateTime) throws InterruptedException {
    Thread.sleep(CLOCK_TRANSITION_TIME);
    final CosemDateTime dateTime = this.getCosemDateTime(hexDateTime);
    final CosemDateTime returned = clock.getTime().getValue();
    /*
     * Transition from 02:59:59 to 3 o'clock is a transition from DST, so
     * the clock is set back to 2 o'clock. The hour therefore stays the
     * same.
     */
    this.doDstTansitionAssertions(dateTime, returned, 0, false);
}
Also used : CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime)

Example 4 with CosemDateTime

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

the class CosemDateTimeProcessor method create.

@Override
public DataObject create(final Object data) {
    if (!(data instanceof Calendar)) {
        throw new IllegalArgumentException(this.getClass().getSimpleName() + " can not create expected DataObject from type " + data.getClass().getSimpleName());
    }
    final Calendar cal = (Calendar) data;
    final CosemDateTime dateTime = new CosemDateTime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), 0xff, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), 0, 0);
    return DataObject.newDateTimeData(dateTime);
}
Also used : Calendar(java.util.Calendar) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime)

Example 5 with CosemDateTime

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

the class FindEventsCommandExecutorTest method generateDataObjectsExtendedPowerQuality.

private List<DataObject> generateDataObjectsExtendedPowerQuality() {
    final List<DataObject> dataObjects = new ArrayList<>();
    IntStream.rangeClosed(93, 98).forEach(code -> {
        final DataObject eventCode = DataObject.newInteger16Data((short) code);
        final DataObject eventTime = DataObject.newDateTimeData(new CosemDateTime(2018, 12, 31, 23, code - 60, 0, 0));
        final DataObject magnitude = DataObject.newInteger32Data(5);
        final DataObject duration = DataObject.newInteger32Data(6);
        final DataObject struct = DataObject.newStructureData(eventTime, eventCode, magnitude, duration);
        dataObjects.add(struct);
    });
    return dataObjects;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime)

Aggregations

CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)24 DataObject (org.openmuc.jdlms.datatypes.DataObject)11 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)5 DateTime (org.joda.time.DateTime)4 ClockStatus (org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus)4 CosemDate (org.openmuc.jdlms.datatypes.CosemDate)3 CosemTime (org.openmuc.jdlms.datatypes.CosemTime)3 Calendar (java.util.Calendar)2 List (java.util.List)2 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)2 BigInteger (java.math.BigInteger)1 LocalDateTime (java.time.LocalDateTime)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 IllegalAttributeAccessException (org.openmuc.jdlms.IllegalAttributeAccessException)1 SetParameter (org.openmuc.jdlms.SetParameter)1 BitString (org.openmuc.jdlms.datatypes.BitString)1 AuxiliaryEventLog (org.opensmartgridplatform.simulator.protocol.dlms.cosem.AuxiliaryEventLog)1 GsmDiagnostic (org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic)1