Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAD-5573 Improve scheduling and validation logic for Schedule Object #98

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ The dependency information is BACnet4J pre 5.0 is:
Releases
========
*Version 6.0.1*
- Allow NULL values for daily and exception schedule
- Allow NULL values for daily schedule, exception schedule and schedule default
- Fix scheduling issues when TimeValue sequences are not in chronological order

*Version 6.0.0*
- fix DeviceObjectTest.timeSynchronization test to pass
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/serotonin/bacnet4j/obj/ScheduleObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ protected boolean validateProperty(final ValueSource valueSource, final Property
final ObjectPropertyTypeDefinition def = ObjectProperties.getObjectPropertyTypeDefinition(
ref.getObjectIdentifier().getObjectType(), ref.getPropertyIdentifier());
if (def != null) {
if (scheduleDefault.getClass() != def.getPropertyTypeDefinition().getClazz()) {
boolean isNull = scheduleDefault.getClass().equals(Null.class);
if (!isNull && scheduleDefault.getClass() != def.getPropertyTypeDefinition().getClazz()) {
throw new BACnetServiceException(ErrorClass.property, ErrorCode.invalidDataType);
}
}
Expand All @@ -188,7 +189,8 @@ protected boolean validateProperty(final ValueSource valueSource, final Property
final BACnetArray<DailySchedule> weeklySchedule = value.getValue();
for (final DailySchedule daily : weeklySchedule) {
for (final TimeValue timeValue : daily.getDaySchedule()) {
if (!timeValue.getValue().getClass().equals(Null.class) && scheduleDefault.getClass() != timeValue.getValue().getClass()) {
boolean isNull = timeValue.getValue().getClass().equals(Null.class) || scheduleDefault.getClass().equals(Null.class);
if (!isNull && scheduleDefault.getClass() != timeValue.getValue().getClass()) {
throw new BACnetServiceException(ErrorClass.property, ErrorCode.invalidDataType);
}
if (!timeValue.getTime().isFullySpecified()) {
Expand All @@ -202,7 +204,8 @@ protected boolean validateProperty(final ValueSource valueSource, final Property
final SequenceOf<SpecialEvent> exceptionSchedule = value.getValue();
for (final SpecialEvent specialEvent : exceptionSchedule) {
for (final TimeValue timeValue : specialEvent.getListOfTimeValues()) {
if (!timeValue.getValue().getClass().equals(Null.class) && scheduleDefault.getClass() != timeValue.getValue().getClass()) {
boolean isNull = timeValue.getValue().getClass().equals(Null.class) || scheduleDefault.getClass().equals(Null.class);
if (!isNull && scheduleDefault.getClass() != timeValue.getValue().getClass()) {
throw new BACnetServiceException(ErrorClass.property, ErrorCode.invalidDataType);
}
if (!timeValue.getTime().isFullySpecified()) {
Expand Down Expand Up @@ -334,9 +337,10 @@ private void updatePresentValue(final DateTime now) {
final TimeValue tv = schedule.getBase1(tvIndex);

if (!tv.getTime().after(now.getTime())) {
// Found a time value entry that can be used.
currentTv = tv;
break;
// Find time value entry that should be used
if (currentTv == null || tv.getTime().after(currentTv.getTime())) {
currentTv = tv;
}
}
}

Expand Down
Loading