Search in sources :

Example 1 with ClockStatus

use of org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus 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 ClockStatus

use of org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus 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 ClockStatus

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

the class DlmsHelper 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.
 *
 * <p>If a DateTime for an instant in time is known with the correct time zone set, you can use
 * {@link #asDataObject(DateTime)} as a simpler alternative.
 *
 * @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.newDateTimeData(cosemDateTime);
}
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 4 with ClockStatus

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

the class DlmsHelper method asDataObject.

/**
 * Creates a COSEM date-time object based on the given {@code dateTime}.
 *
 * <p>The deviation and clock status (is daylight saving active or not) are based on the zone of
 * the given {@code dateTime}.
 *
 * <p>To use a DateTime as indication of the instant of time to be used with a specific deviation
 * (that does not have to match the zone of the DateTime), use {@link #asDataObject(DateTime, int,
 * boolean)} instead.
 *
 * @param dateTime a DateTime to translate into COSEM date-time format.
 * @return a DataObject having a CosemDateTime matching the given DateTime as value.
 */
public DataObject asDataObject(final DateTime dateTime) {
    final CosemDate cosemDate = new CosemDate(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth());
    final CosemTime cosemTime = new CosemTime(dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute(), dateTime.getMillisOfSecond() / 10);
    final int deviation = -(dateTime.getZone().getOffset(dateTime.getMillis()) / MILLISECONDS_PER_MINUTE);
    final ClockStatus[] clockStatusBits;
    if (dateTime.getZone().isStandardOffset(dateTime.getMillis())) {
        clockStatusBits = new ClockStatus[0];
    } else {
        clockStatusBits = new ClockStatus[1];
        clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE;
    }
    final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits);
    return DataObject.newDateTimeData(cosemDateTime);
}
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)

Example 5 with ClockStatus

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

the class CosemDateTimeConverter method convertTo.

@Override
public org.openmuc.jdlms.datatypes.CosemDateTime convertTo(final CosemDateTimeDto source, final Type<org.openmuc.jdlms.datatypes.CosemDateTime> destinationType, final MappingContext context) {
    final CosemTimeDto time = source.getTime();
    final CosemDateDto date = source.getDate();
    final Set<ClockStatus> clockStatus = ClockStatus.clockStatusFrom((byte) source.getClockStatus().getStatus());
    return new org.openmuc.jdlms.datatypes.CosemDateTime(date.getYear(), date.getMonth(), date.getDayOfMonth(), date.getDayOfWeek(), time.getHour(), time.getMinute(), time.getSecond(), time.getHundredths(), source.getDeviation(), clockStatus.toArray(new ClockStatus[clockStatus.size()]));
}
Also used : ClockStatus(org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)

Aggregations

ClockStatus (org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus)5 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)4 CosemDate (org.openmuc.jdlms.datatypes.CosemDate)3 CosemTime (org.openmuc.jdlms.datatypes.CosemTime)3 DateTime (org.joda.time.DateTime)2 Calendar (java.util.Calendar)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)1 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)1 AuxiliaryEventLog (org.opensmartgridplatform.simulator.protocol.dlms.cosem.AuxiliaryEventLog)1 GsmDiagnostic (org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic)1 AdjacentCellInfo (org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.AdjacentCellInfo)1 CellInfo (org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.CellInfo)1 MBusClearStatusMask (org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusClearStatusMask)1 MBusReadStatus (org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusReadStatus)1 Value (org.springframework.beans.factory.annotation.Value)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1