Пример #1
0
        private void AckBt_Click(object sender, EventArgs e)
        {
            TreeNode tn = TAlarmList.SelectedNode;

            if (tn == null)
            {
                return;
            }
            while (tn.Parent != null)
            {
                tn = tn.Parent;                                                          // go up
            }
            BacnetGetEventInformationData alarm = (BacnetGetEventInformationData)tn.Tag; // the alam content

            bool SomeChanges = false;

            for (int i = 0; i < 3; i++)                                 // 3 transitions maybe to be ack To_Normal, To_OfNormal, To_Fault
            {
                if (alarm.acknowledgedTransitions.ToString()[i] == '0') // Transition to be ack, 1 means ok/already done
                {
                    BacnetGenericTime bgt;

                    if (alarm.eventTimeStamps != null)
                    {
                        bgt = alarm.eventTimeStamps[i];
                    }
                    else // Deprecate Execution of GetAlarmSummary
                    {
                        // Read the event time stamp, we do not have it
                        IList <BacnetValue> values;
                        if (comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_EVENT_TIME_STAMPS, out values, 0, (uint)i) == false)
                        {
                            Trace.TraceWarning("Error reading PROP_EVENT_TIME_STAMPS");
                            return;
                        }
                        String   s1 = ((BacnetValue[])(values[0].Value))[0].ToString(); // Date & 00:00:00 for Hour
                        String   s2 = ((BacnetValue[])(values[0].Value))[1].ToString(); // 00:00:00 & Time
                        DateTime dt = Convert.ToDateTime(s1.Split(' ')[0] + " " + s2.Split(' ')[1]);
                        bgt = new BacnetGenericTime(dt, BacnetTimestampTags.TIME_STAMP_DATETIME);
                    }

                    // something to clarify : BacnetEventStates or BacnetEventEnable !!!
                    BacnetEventNotificationData.BacnetEventStates eventstate = (BacnetEventNotificationData.BacnetEventStates)(2 - i);

                    if (comm.AlarmAcknowledgement(adr, alarm.objectIdentifier, eventstate, AckText.Text, bgt,
                                                  new BacnetGenericTime(DateTime.Now, BacnetTimestampTags.TIME_STAMP_DATETIME)) == true)
                    {
                        alarm.acknowledgedTransitions.SetBit((byte)i, true);
                        SomeChanges = true;
                    }
                }

                if (SomeChanges)
                {
                    FillTreeNode();
                }
            }
        }
        public void AnalogObjectEvent()
        {
            Last_PRESENT_VALUE = m_PROP_PRESENT_VALUE;

            for (int i = 0; i < 3; i++)
            {
                BacnetGenericTime stamp = new BacnetGenericTime(DateTime.Now, BacnetTimestampTags.TIME_STAMP_DATETIME);
                m_PROP_EVENT_TIME_STAMPS[i] = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_TIMESTAMP, stamp);
            }
            Enable_Reporting(false);
        }
Пример #3
0
        public void SendIntrinsectEvent(BacnetObjectId SenderObject,
                                        BacnetEventNotificationData.BacnetNotifyTypes notifyType,
                                        BacnetEventNotificationData.BacnetEventTypes evenType,
                                        BacnetEventNotificationData.BacnetEventStates fromstate,
                                        BacnetEventNotificationData.BacnetEventStates tostate)
        {
            if ((m_PROP_RECIPIENT_LIST == null) || (m_PROP_RECIPIENT_LIST.Count == 0))
            {
                return;
            }

            BacnetEventNotificationData bacnetEvent = new BacnetEventNotificationData();

            // The struct is the same of all recipients, except one attribut
            bacnetEvent.notificationClass          = m_PROP_OBJECT_IDENTIFIER.instance;
            bacnetEvent.initiatingObjectIdentifier = Device;
            bacnetEvent.eventObjectIdentifier      = SenderObject;
            bacnetEvent.toState    = tostate;
            bacnetEvent.fromState  = fromstate;
            bacnetEvent.notifyType = notifyType;
            bacnetEvent.eventType  = evenType;

            BacnetGenericTime timeStamp = new BacnetGenericTime();

            timeStamp.Tag  = BacnetTimestampTags.TIME_STAMP_DATETIME;
            timeStamp.Time = DateTime.Now;

            bacnetEvent.timeStamp = timeStamp;
            bacnetEvent.priority  = 127;

            for (int i = 0; i < m_PROP_RECIPIENT_LIST.Count; i++)
            {
                bool DoASend = true;

                DeviceReportingRecipient devReportEntry = (DeviceReportingRecipient)m_PROP_RECIPIENT_LIST[i].Value;

                // Time is OK ?
                if (TimeSpan.Compare(DateTime.Now.TimeOfDay, devReportEntry.fromTime.TimeOfDay) == -1)
                {
                    DoASend = false;
                }
                if (TimeSpan.Compare(devReportEntry.toTime.TimeOfDay, DateTime.Now.TimeOfDay) == -1)
                {
                    DoASend = false;
                }

                // Day is OK ?
                int DayOfWeek = (int)DateTime.Now.DayOfWeek;
                if (DayOfWeek == 0)
                {
                    DayOfWeek = 7;                  // Put Sunday at the end of the enumaration
                }
                DayOfWeek = DayOfWeek - 1;          // start at 0

                if ((devReportEntry.WeekofDay.value[0] & (1 << DayOfWeek)) == 0)
                {
                    DoASend = false;
                }

                // new State is OK ?
                if ((tostate == BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_OFFNORMAL) && ((devReportEntry.evenType.value[0] & 1) != 1))
                {
                    DoASend = false;
                }
                if ((tostate == BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_NORMAL) && ((devReportEntry.evenType.value[0] & 2) != 2))
                {
                    DoASend = false;
                }
                if ((tostate == BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_FAULT) && ((devReportEntry.evenType.value[0] & 4) != 4))
                {
                    DoASend = false;
                }

                // Find the receiver endPoint
                KeyValuePair <BacnetClient, BacnetAddress>?recipient = null;

                if ((devReportEntry.adr != null) && (Mydevice.DirectIp != null))
                {
                    recipient = new KeyValuePair <BacnetClient, BacnetAddress>
                                (
                        Mydevice.DirectIp,
                        devReportEntry.adr
                                );
                }
                else
                {
                    try
                    {
                        recipient = Mydevice.SuroundingDevices[devReportEntry.Id.instance];
                    }
                    catch { }
                }

                if (recipient == null)
                {
                    DoASend = false;
                }

                if (DoASend == true)
                {
                    uint processIdentifier = devReportEntry.processIdentifier;

                    object bacnetEventlock = new object();    // we need to change safely one element in the struct
                    System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                    {
                        lock (bacnetEventlock)
                        {
                            bacnetEvent.processIdentifier = processIdentifier;
                            recipient.Value.Key.SendUnconfirmedEventNotification(recipient.Value.Value, bacnetEvent);
                        }
                    }, null);
                }
            }
        }
        private void IntrinsicReportingManagement()
        {
            if (Mydevice == null)
            {
                return;
            }

            if (m_PROP_LIMIT_ENABLE.value[0] == 0)
            {
                Last_PRESENT_VALUE = m_PROP_PRESENT_VALUE;
                return;
            }

            // T type must be convertible to double of course
            double pv = Convert.ToDouble(m_PROP_PRESENT_VALUE);
            double hl = Convert.ToDouble(m_PROP_HIGH_LIMIT);
            double ll = Convert.ToDouble(m_PROP_LOW_LIMIT);
            double db = Convert.ToDouble(m_PROP_DEADBAND);

            bool LimitEnabledHigh = (m_PROP_LIMIT_ENABLE.value[0] & (uint)BacnetEventNotificationData.BacnetLimitEnable.EVENT_HIGH_LIMIT_ENABLE) != 0;
            bool LimitEnabledLow  = (m_PROP_LIMIT_ENABLE.value[0] & (uint)BacnetEventNotificationData.BacnetLimitEnable.EVENT_LOW_LIMIT_ENABLE) != 0;

            bool EventToOffNormal = (m_PROP_EVENT_ENABLE.value[0] & (uint)BacnetEventNotificationData.BacnetEventEnable.EVENT_ENABLE_TO_OFFNORMAL) != 0;
            bool EventToNormal    = (m_PROP_EVENT_ENABLE.value[0] & (uint)BacnetEventNotificationData.BacnetEventEnable.EVENT_ENABLE_TO_NORMAL) != 0;

            bool NotifyState = false;

            uint fromState = m_PROP_EVENT_STATE;
            int  toState   = -1;

            switch (fromState)
            {
            case (uint)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_NORMAL:
                /*  If LimitHigh flag is enabled and Present_Value exceed the High_Limit and Event to Offnormal is enabled then
                 * the notification must be done */
                if ((pv > hl) && LimitEnabledHigh)
                {
                    toState     = (int)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_HIGH_LIMIT;
                    NotifyState = EventToOffNormal;
                }

                /* If LowLimit flag is enabled and Present_Value exceed the Low_Limit and Event to Offnormal is enabled then
                 * the notification must be done */
                if ((pv < ll) & LimitEnabledLow)
                {
                    toState     = (int)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_LOW_LIMIT;
                    NotifyState = EventToOffNormal;
                }
                break;

            case (uint)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_HIGH_LIMIT:
                /* Present_Value fall below the High_Limit - Deadband ? */
                if (pv < (hl - db))
                {
                    toState     = (int)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_NORMAL;
                    NotifyState = EventToNormal;
                }
                /* Present_Value fall below the Low_Limit ? */
                if ((pv < ll) && LimitEnabledLow)
                {
                    toState = (int)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_LOW_LIMIT;
                    if (!NotifyState)
                    {
                        NotifyState = EventToOffNormal;
                    }
                }
                break;

            case (uint)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_LOW_LIMIT:
                /* Present_Value exceed the Low_Limit + Deadband ? */
                if (pv > (ll + db))
                {
                    toState     = (int)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_NORMAL;
                    NotifyState = EventToNormal;
                }
                /* Present_Value exceed the High_Limit ? */
                if ((pv > hl) && LimitEnabledHigh)
                {
                    toState = (int)BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_HIGH_LIMIT;
                    if (!NotifyState)
                    {
                        NotifyState = EventToOffNormal;
                    }
                }
                break;
            }

            if (toState != -1)
            {
                // Update Event_State
                m_PROP_EVENT_STATE = (uint)toState;

                BacnetGenericTime stamp = new BacnetGenericTime(DateTime.Now, BacnetTimestampTags.TIME_STAMP_DATETIME);

                // Update EVENT_TIME_STAMPS, 1 is for FAULT (not used)
                if (toState == 0)
                {
                    m_PROP_EVENT_TIME_STAMPS[2] = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_TIMESTAMP, stamp); // Normal
                }
                else
                {
                    m_PROP_EVENT_TIME_STAMPS[1] = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_TIMESTAMP, stamp); // Limit
                }
            }
            Last_PRESENT_VALUE = m_PROP_PRESENT_VALUE;

            if (NotifyState == false)
            {
                return;
            }

            // look for the related notification class object
            NotificationClass nc = (NotificationClass)Mydevice.FindBacnetObject(new BacnetObjectId(BacnetObjectTypes.OBJECT_NOTIFICATION_CLASS, m_PROP_NOTIFICATION_CLASS));

            if (nc != null)
            {
                nc.SendIntrinsectEvent(
                    m_PROP_OBJECT_IDENTIFIER,
                    (BacnetEventNotificationData.BacnetNotifyTypes)m_PROP_NOTIFY_TYPE,
                    BacnetEventNotificationData.BacnetEventTypes.EVENT_CHANGE_OF_VALUE,
                    (BacnetEventNotificationData.BacnetEventStates)fromState,
                    (BacnetEventNotificationData.BacnetEventStates)toState);
            }
        }
        public IAsyncResult BeginAlarmAcknowledgement(BacnetAddress adr, BacnetObjectId objid, BacnetEventNotificationData.BacnetEventStates eventState, String AckText, BacnetGenericTime evTimeStamp, BacnetGenericTime ackTimeStamp, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending AlarmAcknowledgement ... ", null);
            if (invoke_id == 0) invoke_id = unchecked(m_invoke_id++);

            EncodeBuffer b = GetEncodeBuffer(m_client.HeaderLength);
            NPDU.Encode(b, BacnetNpduControls.PriorityNormalMessage, adr.RoutedSource, null, DEFAULT_HOP_COUNT, BacnetNetworkMessageTypes.NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, 0);
            APDU.EncodeConfirmedServiceRequest(b, BacnetPduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (m_max_segments != BacnetMaxSegments.MAX_SEG0 ? BacnetPduTypes.SEGMENTED_RESPONSE_ACCEPTED : 0), BacnetConfirmedServices.SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeAlarmAcknowledge(b, 57, objid, (uint)eventState, AckText, evTimeStamp, ackTimeStamp);
            //send
            BacnetAsyncResult ret = new BacnetAsyncResult(this, adr, invoke_id, b.buffer, b.offset - m_client.HeaderLength, wait_for_transmit, m_transmit_timeout);
            ret.Resend();

            return ret;
        }
 // FChaxel
 public bool AlarmAcknowledgement(BacnetAddress adr, BacnetObjectId objid, BacnetEventNotificationData.BacnetEventStates eventState, String AckText, BacnetGenericTime evTimeStamp, BacnetGenericTime ackTimeStamp, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginAlarmAcknowledgement(adr, objid, eventState, AckText, evTimeStamp, ackTimeStamp, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndAlarmAcknowledgement(result, out ex);
                 if (ex != null) return false;
                 else return true;
             }
             if (r < (m_retries - 1))
                 result.Resend();
         }
     }
     return false;
 }