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

Unable to update NotificationClass priority #85

Open
envas opened this issue Aug 30, 2023 · 1 comment
Open

Unable to update NotificationClass priority #85

envas opened this issue Aug 30, 2023 · 1 comment

Comments

@envas
Copy link

envas commented Aug 30, 2023

There is a bug in the class NotificationClassObject.validateProperty. When updating the property priority, the following error occurs:

java.lang.ClassCastException: com.serotonin.bacnet4j.type.constructed.SequenceOf cannot be cast to com.serotonin.bacnet4j.type.constructed.BACnetArray
	at com.serotonin.bacnet4j.obj.NotificationClassObject.validateProperty(NotificationClassObject.java:117)
	at com.serotonin.bacnet4j.obj.BACnetObject.writeProperty(BACnetObject.java:486)
	at com.serotonin.bacnet4j.service.confirmed.WritePropertyRequest.handle(WritePropertyRequest.java:102)
	at com.serotonin.bacnet4j.transport.DefaultTransport.handleConfirmedRequest(DefaultTransport.java:870)
	at com.serotonin.bacnet4j.transport.DefaultTransport.incomingConfirmedRequest(DefaultTransport.java:827)
	at com.serotonin.bacnet4j.transport.DefaultTransport.receiveAPDU(DefaultTransport.java:640)
	at com.serotonin.bacnet4j.transport.DefaultTransport.receiveImpl(DefaultTransport.java:578)
	at com.serotonin.bacnet4j.transport.DefaultTransport.run(DefaultTransport.java:498)
	at java.lang.Thread.run(Thread.java:750)

In the source code, BACnetArray must be changed to SequenceOf

protected boolean validateProperty(final ValueSource valueSource, final PropertyValue value)
            throws BACnetServiceException {
        if (PropertyIdentifier.priority.equals(value.getPropertyIdentifier())) {
            final BACnetArray<UnsignedInteger> priority = value.getValue();  // <- type must be changed to SequenceOf
            if (priority.getCount() != 3)
                throw new BACnetServiceException(ErrorClass.property, ErrorCode.valueOutOfRange);
        }

        return false;
    }

The updated/extended test unit for the Notification class shows that the comparison must always be done as SequenceOf, even if the BACnetArray was written.

// Neopsis - update priority remotely:
        RequestUtils.writeProperty(d2, rd1, nc.getId(), PropertyIdentifier.priority,
                new BACnetArray<UnsignedInteger>( new UnsignedInteger(10),
                                                  new UnsignedInteger(20),
                                                  new UnsignedInteger(30)));
        Encodable ret = RequestUtils.getProperty(d2, rd1, nc.getId(), PropertyIdentifier.priority);
        assertEquals(ret, new SequenceOf<UnsignedInteger>(new UnsignedInteger(10),
                new UnsignedInteger(20), new UnsignedInteger(30)));

// Neopsis - update priority locally:
        nc.writePropertyInternal(PropertyIdentifier.priority,
                new BACnetArray<UnsignedInteger>( new UnsignedInteger(10),
                        new UnsignedInteger(20),
                        new UnsignedInteger(30)));
        ret = RequestUtils.getProperty(d2, rd1, nc.getId(), PropertyIdentifier.priority);
        assertEquals(ret, new SequenceOf<UnsignedInteger>(new UnsignedInteger(10),
                new UnsignedInteger(20), new UnsignedInteger(30)));
@kishorevenki
Copy link

The error is because Priority prooperty NC Object is of BACnetArray Data type whereas BACnet4J assigned its datatype as Sequence of. Sequence data type is typically used for List Data type in BACnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants