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);
}
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());
}
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);
}
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);
}
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()]));
}
Aggregations