Search in sources :

Example 6 with CosemDate

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.

the class CosemDateTimeConverter method convert.

@Override
public CosemDateTime convert(final byte[] source, final Type<? extends CosemDateTime> destinationType, final MappingContext context) {
    final ByteBuffer bb = ByteBuffer.wrap(source);
    final int year = bb.getShort() & 0xFFFF;
    final int month = bb.get() & 0xFF;
    final int dayOfMonth = bb.get() & 0xFF;
    final int dayOfWeek = bb.get() & 0xFF;
    final int hour = bb.get() & 0xFF;
    final int minute = bb.get() & 0xFF;
    final int second = bb.get() & 0xFF;
    final int hundredths = bb.get() & 0xFF;
    final int deviation = bb.getShort();
    final ClockStatus clockStatus = new ClockStatus(bb.get());
    final CosemTime time = new CosemTime(hour, minute, second, hundredths);
    final CosemDate date = new CosemDate(year, month, dayOfMonth, dayOfWeek);
    return new CosemDateTime(date, time, deviation, clockStatus);
}
Also used : ClockStatus(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) ByteBuffer(java.nio.ByteBuffer)

Example 7 with CosemDate

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.

the class ActivityCalendarMappingTest method checkCosemDateTimeMapping.

// method to test mapping of CosemDateTime objects
private void checkCosemDateTimeMapping(final CosemDateTime cosemDateTime, final CosemDateTimeDto cosemDateTimeDto) {
    // make sure neither is null
    assertThat(cosemDateTime).isNotNull();
    assertThat(cosemDateTimeDto).isNotNull();
    // check variables
    assertThat(cosemDateTimeDto.getDeviation()).isEqualTo(cosemDateTime.getDeviation());
    final ClockStatus clockStatus = cosemDateTime.getClockStatus();
    final ClockStatusDto clockStatusDto = cosemDateTimeDto.getClockStatus();
    assertThat(clockStatusDto.getStatus()).isEqualTo(clockStatus.getStatus());
    assertThat(clockStatusDto.isSpecified()).isEqualTo(clockStatus.isSpecified());
    final CosemDate cosemDate = cosemDateTime.getDate();
    final CosemDateDto cosemDateDto = cosemDateTimeDto.getDate();
    assertThat(cosemDateDto.getYear()).isEqualTo(cosemDate.getYear());
    assertThat(cosemDateDto.getMonth()).isEqualTo(cosemDate.getMonth());
    assertThat(cosemDateDto.getDayOfMonth()).isEqualTo(cosemDate.getDayOfMonth());
    assertThat(cosemDateDto.getDayOfWeek()).isEqualTo(cosemDate.getDayOfWeek());
    final CosemTime cosemTime = cosemDateTime.getTime();
    final CosemTimeDto cosemTimeDto = cosemDateTimeDto.getTime();
    assertThat(cosemTimeDto.getHour()).isEqualTo(cosemTime.getHour());
    assertThat(cosemTimeDto.getMinute()).isEqualTo(cosemTime.getMinute());
    assertThat(cosemTimeDto.getSecond()).isEqualTo(cosemTime.getSecond());
    assertThat(cosemTimeDto.getHundredths()).isEqualTo(cosemTime.getHundredths());
}
Also used : ClockStatus(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) ClockStatusDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ClockStatusDto) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)

Example 8 with CosemDate

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.

the class ActivityCalendarBuilder method withFilledList.

public ActivityCalendarBuilder withFilledList() {
    final CosemDate date = new CosemDate(2016, 3, 16);
    final CosemTime time = new CosemTime(11, 45, 33);
    final int deviation = 1;
    final ClockStatus clockStatus = new ClockStatus(ClockStatus.STATUS_NOT_SPECIFIED);
    final CosemDateTime seasonStart = new CosemDateTime(date, time, deviation, clockStatus);
    final CosemTime startTime = time;
    final DayProfileAction dayProfileAction = new DayProfileAction(new Integer(10), startTime);
    final List<DayProfileAction> dayProfileActionList = new ArrayList<>();
    dayProfileActionList.add(dayProfileAction);
    final DayProfile dayProfile = new DayProfile(new Integer(10), dayProfileActionList);
    final WeekProfile weekProfile = WeekProfile.newBuilder().withWeekProfileName("weekProfile1").withMonday(dayProfile).withTuesday(dayProfile).withWednesday(dayProfile).withThursday(dayProfile).withFriday(dayProfile).withSaturday(dayProfile).withSunday(dayProfile).build();
    final SeasonProfile seasonProfile = new SeasonProfile("profile1", seasonStart, weekProfile);
    this.seasonProfileList.add(seasonProfile);
    return this;
}
Also used : WeekProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WeekProfile) ClockStatus(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) ArrayList(java.util.ArrayList) DayProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfile) DayProfileAction(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfileAction) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SeasonProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SeasonProfile)

Example 9 with CosemDate

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.

the class CosemDateConverter method convert.

@Override
public CosemDate convert(final byte[] source, final Type<? extends CosemDate> destinationType, final MappingContext context) {
    final ByteBuffer bb = ByteBuffer.wrap(source);
    final int year = bb.getShort() & 0xFFFF;
    final int month = bb.get() & 0xFF;
    final int day = bb.get() & 0xFF;
    final int weekDay = bb.get() & 0xFF;
    return new CosemDate(year, month, day, weekDay);
}
Also used : CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) ByteBuffer(java.nio.ByteBuffer)

Example 10 with CosemDate

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.

the class PushSetupSmsMappingTest method checkCosemDateTimeMapping.

// method to test mapping of CosemDateTime objects
private void checkCosemDateTimeMapping(final CosemDateTime cosemDateTime, final CosemDateTimeDto cosemDateTimeDto) {
    // make sure neither is null
    assertThat(cosemDateTime).isNotNull();
    assertThat(cosemDateTimeDto).isNotNull();
    // check variables
    assertThat(cosemDateTimeDto.getDeviation()).isEqualTo(cosemDateTime.getDeviation());
    final ClockStatus clockStatus = cosemDateTime.getClockStatus();
    final ClockStatusDto clockStatusDto = cosemDateTimeDto.getClockStatus();
    assertThat(clockStatusDto.getStatus()).isEqualTo(clockStatus.getStatus());
    assertThat(clockStatusDto.isSpecified()).isEqualTo(clockStatus.isSpecified());
    final CosemDate cosemDate = cosemDateTime.getDate();
    final CosemDateDto cosemDateDto = cosemDateTimeDto.getDate();
    assertThat(cosemDateDto).isEqualToComparingFieldByField(cosemDate);
    final CosemTime cosemTime = cosemDateTime.getTime();
    final CosemTimeDto cosemTimeDto = cosemDateTimeDto.getTime();
    assertThat(cosemTimeDto).isEqualToComparingFieldByField(cosemTime);
}
Also used : ClockStatus(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) ClockStatusDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ClockStatusDto) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)

Aggregations

CosemDate (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate)13 CosemTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime)8 Test (org.junit.jupiter.api.Test)7 ClockStatus (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus)7 CosemDateTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime)5 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)5 ClockStatusDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ClockStatusDto)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)3 ByteBuffer (java.nio.ByteBuffer)2 CosemObisCode (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObisCode)2 CosemObjectDefinition (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)2 SpecialDay (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay)2 SpecialDaysRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest)2 SpecialDaysRequestData (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData)2 WindowElement (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement)2 SpecialDayDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto)2 SpecialDaysRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto)2 SpecialDaysRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto)2 ArrayList (java.util.ArrayList)1 DayProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfile)1