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