Пример #1
0
        private void sendCovNotification(ObjectCovSubscription sub, long now)
        {
            try
            {
                UnsignedInteger timeLeft = new UnsignedInteger(sub.GetTimeRemaining(now));
                SequenceOf      values   = new SequenceOf(ObjectCovSubscription.GetValues(this));

                if (sub.IsIssueConfirmedNotifications)
                {
                    // Confirmed
                    ConfirmedCovNotificationRequest req = new ConfirmedCovNotificationRequest(
                        sub.SubscriberProcessIdentifier, localDevice.Configuration.Id, Id, timeLeft,
                        values);
                    RemoteDevice d = localDevice.getRemoteDevice(sub.Address);
                    localDevice.send(d, req);
                }
                else
                {
                    // Unconfirmed
                    UnconfirmedCovNotificationRequest req = new UnconfirmedCovNotificationRequest(
                        sub.SubscriberProcessIdentifier, localDevice.Configuration.Id, Id, timeLeft,
                        values);
                    localDevice.sendUnconfirmed(sub.Address, sub.LinkService, req);
                }
            }
            catch (BACnetException e)
            {
                throw e;
                //ExceptionDispatch.fireReceivedException(e);
            }
        }
Пример #2
0
//
//
// COV subscriptions
//

        public void addCovSubscription(Address from, OctetString linkService, UnsignedInteger subscriberProcessIdentifier,
                                       BBoolean issueConfirmedNotifications, UnsignedInteger lifetime)
        {
            //synchronized (covSubscriptions) {
            ObjectCovSubscription sub = findCovSubscription(from, subscriberProcessIdentifier);
            bool confirmed            = issueConfirmedNotifications.Value;

            if (sub == null)
            {
                // Ensure that this object is valid for COV notifications.
                if (!ObjectCovSubscription.SendCovNotification(Id.ObjectType, null, this.getCovIncrement()))
                {
                    throw new BACnetServiceException(ErrorClass.Services, ErrorCode.CovSubscriptionFailed,
                                                     "Object is invalid for COV notifications");
                }

                if (confirmed)
                {
                    // If the peer wants confirmed notifications, it must be in the remote device list.
                    RemoteDevice d = localDevice.getRemoteDevice(from);
                    if (d == null)
                    {
                        throw new BACnetServiceException(ErrorClass.Services, ErrorCode.CovSubscriptionFailed,
                                                         "From address not found in remote device list. Cannot send confirmed notifications");
                    }
                }

                sub = new ObjectCovSubscription(from, linkService, subscriberProcessIdentifier, this.getCovIncrement());
                covSubscriptions.Add(sub);
            }

            sub.SetIssueConfirmedNotifications(issueConfirmedNotifications.Value);
            sub.SetExpiryTime((int)lifetime.Value);
            // }
        }
Пример #3
0
        private void setPropertyImpl(PropertyIdentifier pid, Encodable value)
        {
            Encodable oldValue = (Encodable)properties[pid];

            properties[pid] = value;

            if (!value.Equals(oldValue))
            {
                // Check for subscriptions.
                if (ObjectCovSubscription.SendCovNotification(Id.ObjectType, pid, this.getCovIncrement()))
                {
                    //synchronized(covSubscriptions) {
                    long now = System.DateTime.Now.Ticks;
                    ObjectCovSubscription sub;
                    for (int i = covSubscriptions.Count - 1; i >= 0; i--)
                    {
                        sub = (ObjectCovSubscription)covSubscriptions[i];
                        if (sub.HasExpired(now))
                        {
                            covSubscriptions.RemoveAt(i);
                        }
                        else if (sub.IsNotificationRequired(pid, value))
                        {
                            sendCovNotification(sub, now);
                        }
                    }
                    //}
                }
            }
        }
Пример #4
0
        public void removeCovSubscription(Address from, UnsignedInteger subscriberProcessIdentifier)
        {
            //synchronized(covSubscriptions) {
            ObjectCovSubscription sub = findCovSubscription(from, subscriberProcessIdentifier);

            if (sub != null)
            {
                covSubscriptions.Remove(sub);
            }
            //}
        }