Search in sources :

Example 21 with CosemDateTime

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

the class DlmsHelperTest method testFromByteArraySummerTime.

@Test
public void testFromByteArraySummerTime() throws Exception {
    final CosemDateTimeDto cosemDateTime = this.dlmsHelper.fromDateTimeValue(this.byteArraySummerTime());
    assertThat(cosemDateTime.isDateTimeSpecified()).isTrue();
    final DateTime dateInSummerTime = cosemDateTime.asDateTime();
    assertThat(ISODateTimeFormat.dateTime().print(dateInSummerTime)).isEqualTo("2015-07-21T14:53:07.230+02:00");
}
Also used : DateTime(org.joda.time.DateTime) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) Test(org.junit.jupiter.api.Test)

Example 22 with CosemDateTime

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

the class DlmsHelperTest method testDateTimeSummerTimeWithDeviationAndDst.

@Test
public void testDateTimeSummerTimeWithDeviationAndDst() {
    final DataObject dateInSummerTimeDataObject = this.dlmsHelper.asDataObject(this.dateTimeSummerTime(), -120, true);
    assertThat(dateInSummerTimeDataObject.isCosemDateFormat()).isTrue();
    assertThat(dateInSummerTimeDataObject.getValue() instanceof CosemDateTime).isTrue();
    final CosemDateTime cosemDateTime = dateInSummerTimeDataObject.getValue();
    assertThat(cosemDateTime.encode()).isEqualTo(this.byteArraySummerTime());
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) Test(org.junit.jupiter.api.Test)

Example 23 with CosemDateTime

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

the class SetActivityCalendarCommandExecutorTest method verifyDataObjectSeason.

private void verifyDataObjectSeason(final DataObject season, final String seasonName, final CosemDateDto seasonStart, final String weekName) {
    assertThat(season.getType()).isEqualTo(Type.STRUCTURE);
    final List<DataObject> values = season.getValue();
    assertThat(values).hasSize(3);
    // Season Name
    assertThat(values.get(0).getType()).isEqualTo(Type.OCTET_STRING);
    assertThat((byte[]) values.get(0).getValue()).containsExactly(new BigInteger(seasonName, 10).toByteArray());
    // Season start time
    assertThat(values.get(1).getType()).isEqualTo(Type.OCTET_STRING);
    final CosemDateTime cosemDateTime = CosemDateTime.decode(values.get(1).getValue());
    final CosemDateTime expectedTime = new CosemDateTime(0xFFFF, seasonStart.getMonth(), seasonStart.getDayOfMonth(), 255, 0, 0, 0, 0, 0);
    assertThat(cosemDateTime).usingRecursiveComparison().isEqualTo(expectedTime);
    // Week name
    assertThat(values.get(2).getType()).isEqualTo(Type.OCTET_STRING);
    assertThat((byte[]) values.get(2).getValue()).containsExactly(new BigInteger(weekName, 10).toByteArray());
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) BigInteger(java.math.BigInteger) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime)

Example 24 with CosemDateTime

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

the class FindEventsCommandExecutorTest method generateDataObjectsAuxiliary.

private List<DataObject> generateDataObjectsAuxiliary() {
    final List<DataObject> dataObjects = new ArrayList<>();
    IntStream.rangeClosed(33664, 33697).forEach(code -> {
        final DataObject eventCode = DataObject.newUInteger16Data(code);
        final DataObject eventTime = DataObject.newDateTimeData(new CosemDateTime(2018, 12, 31, 23, code % 60, 0, 0));
        final DataObject struct = DataObject.newStructureData(eventTime, eventCode);
        dataObjects.add(struct);
    });
    return dataObjects;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime)

Example 25 with CosemDateTime

use of org.openmuc.jdlms.datatypes.CosemDateTime in project OpenMUC by isc-konstanz.

the class WriteHandle method createDoFor.

private static DataObject createDoFor(ChannelValueContainer channelValueContainer, Type type) throws UnsupportedOperationException {
    Flag flag = channelValueContainer.getFlag();
    if (flag != Flag.VALID) {
        return null;
    }
    Value value = channelValueContainer.getValue();
    switch(type) {
        case BCD:
            return DataObject.newBcdData(value.asByte());
        case BOOLEAN:
            return DataObject.newBoolData(value.asBoolean());
        case DOUBLE_LONG:
            return DataObject.newInteger32Data(value.asInt());
        case DOUBLE_LONG_UNSIGNED:
            // TODO: not safe!
            return DataObject.newUInteger32Data(value.asLong());
        case ENUMERATE:
            return DataObject.newEnumerateData(value.asInt());
        case FLOAT32:
            return DataObject.newFloat32Data(value.asFloat());
        case FLOAT64:
            return DataObject.newFloat64Data(value.asDouble());
        case INTEGER:
            return DataObject.newInteger8Data(value.asByte());
        case LONG64:
            return DataObject.newInteger64Data(value.asLong());
        case LONG64_UNSIGNED:
            // TODO: is not unsigned
            return DataObject.newUInteger64Data(value.asLong());
        case LONG_INTEGER:
            return DataObject.newInteger16Data(value.asShort());
        case LONG_UNSIGNED:
            // TODO: not safe!
            return DataObject.newUInteger16Data(value.asInt());
        case NULL_DATA:
            return DataObject.newNullData();
        case OCTET_STRING:
            return DataObject.newOctetStringData(value.asByteArray());
        case UNSIGNED:
            // TODO: not safe!
            return DataObject.newUInteger8Data(value.asShort());
        case UTF8_STRING:
            byte[] byteArrayValue = byteArrayValueOf(value);
            return DataObject.newUtf8StringData(byteArrayValue);
        case VISIBLE_STRING:
            byteArrayValue = byteArrayValueOf(value);
            return DataObject.newVisibleStringData(byteArrayValue);
        case DATE:
            Calendar calendar = getCalendar(value.asLong());
            return DataObject.newDateData(new CosemDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)));
        case DATE_TIME:
            calendar = getCalendar(value.asLong());
            return DataObject.newDateTimeData(new CosemDateTime(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_WEEK), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND) / 10, 0x8000, ClockStatus.INVALID_CLOCK_STATUS));
        case TIME:
            calendar = getCalendar(value.asLong());
            return DataObject.newTimeData(new CosemTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)));
        case ARRAY:
        case BIT_STRING:
        case COMPACT_ARRAY:
        case DONT_CARE:
        case STRUCTURE:
        default:
            String message = MessageFormat.format("DateType {0} not supported, yet.", type.toString());
            throw new UnsupportedOperationException(message);
    }
}
Also used : CosemTime(org.openmuc.jdlms.datatypes.CosemTime) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) CosemDate(org.openmuc.jdlms.datatypes.CosemDate) Flag(org.openmuc.framework.data.Flag)

Aggregations

CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)25 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 CosemDate (org.openmuc.jdlms.datatypes.CosemDate)4 ClockStatus (org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus)4 CosemTime (org.openmuc.jdlms.datatypes.CosemTime)4 Calendar (java.util.Calendar)3 List (java.util.List)2 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)2 BigInteger (java.math.BigInteger)1 LocalDateTime (java.time.LocalDateTime)1 GregorianCalendar (java.util.GregorianCalendar)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)1 Flag (org.openmuc.framework.data.Flag)1 StringValue (org.openmuc.framework.data.StringValue)1 Value (org.openmuc.framework.data.Value)1