示例#1
0
        private void button6_Click(object sender, EventArgs e)
        {
            BACNET_EVENT_NOTIFICATION_DATA      data   = new BACNET_EVENT_NOTIFICATION_DATA();
            UnconfirmedEventNotificationService unconf = new UnconfirmedEventNotificationService();

            data.processIdentifier = 123;
            data.ackRequired       = true;
            BACNET_OBJECT_ID obj_id = new BACNET_OBJECT_ID();

            obj_id.type                = (UInt16)BACNET_OBJECT_TYPE.BACNET_LIFT;
            obj_id.instance            = Form_main.lift_list[0].Object_Identifier.instance;
            data.eventObjectIdentifier = obj_id;
            data.eventType             = BACNET_EVENT_TYPE.EVENT_CHANGE_OF_LIFE_SAFETY;
            data.fromState             = BACNET_EVENT_STATE.EVENT_STATE_NORMAL;
            data.timeStamp             = Form_main.lift_list[0].Time_Stamps;
            data.notifyType            = BACNET_NOTIFY_TYPE.NOTIFY_ALARM;
            data.toState               = BACNET_EVENT_STATE.EVENT_STATE_FAULT;
            data.priority              = 3;


            BACNET_OBJECT_ID obj_temp = new BACNET_OBJECT_ID();

            obj_temp.type     = (UInt16)BACNET_OBJECT_TYPE.OBJECT_DEVICE;
            obj_temp.instance = 9527;
            data.notificationParams.change_of_lifesafety.statusFlags.set_bits_used(1, 5);
            data.notificationParams.change_of_lifesafety.statusFlags.set_octet(0, 4);
            data.notificationParams.change_of_lifesafety.newState          = BACNET_LIFE_SAFETY_STATE.LIFE_SAFETY_STATE_ALARM;
            data.notificationParams.change_of_lifesafety.newMode           = BACNET_LIFE_SAFETY_MODE.LIFE_SAFETY_MODE_DISABLED;
            data.notificationParams.change_of_lifesafety.operationExpected = BACNET_LIFE_SAFETY_OPERATION.LIFE_SAFETY_OP_RESET_ALARM;

            //  data.notificationParams.newState.tag = BACNET_PROPERTY_STATE_TYPE.UNSIGNED_VALUE;
            //    data.notificationParams.newState.value = 100;
            //    data.notificationParams.statusFlags.set_bits_used(1, 5);
            //    data.notificationParams.statusFlags.set_octet(0,4);



            data.initiatingObjectIdentifier = obj_temp;
            data.notificationClass          = 123;



            Byte[] buff = new Byte[1024];


            int Send_len = unconf.Unconfirmed_Event_Notification_Pack(ref buff, ref data);

            IPEndPoint dest    = new IPEndPoint(IPAddress.Parse("10.10.161.153"), 60);//假设60测试?
            UdpSender  sendder = new UdpSender(ref buff, dest);

            sendder.Send(Send_len);
        }
        public void Decode(ref BACNET_ADDRESS src, ref byte[] apdu, UInt16 apdu_len, int pos = 0)
        {
            BACNET_CONFIRMED_SERVICE_DATA     service_data     = new BACNET_CONFIRMED_SERVICE_DATA();
            BACNET_CONFIRMED_SERVICE_ACK_DATA service_ack_data = new BACNET_CONFIRMED_SERVICE_ACK_DATA();
            Byte invoke_id      = 0;
            Byte service_choice = 0;

            Byte[] service_request;

            UInt16  service_request_len = 0;
            int     len         = 0; /* counts where we are in PDU */
            Byte    tag_number  = 0;
            UInt32  len_value   = 0;
            UInt32  error_code  = 0;
            UInt32  error_class = 0;
            Byte    reason      = 0;
            Boolean server      = false;

            //服务选择



            switch (apdu[pos] & 0xF0)
            {
            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST:
            {
                service_choice      = apdu[pos + 1];
                service_request_len = (ushort)(apdu_len - 2);

                service_request = new Byte[service_request_len];

                Array.Copy(apdu, pos + 2, service_request, 0, service_request_len);
                switch (service_choice)
                {
                case (Byte)BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_COV_NOTIFICATION:

                {
                    //  UnconFirmCovService un_cov = new UnconFirmCovService();
                    //     un_cov.Unconfirm_Cov_Handler(ref service_request,(ushort) service_request_len,ref src);
                    break;
                }

                case (Byte)BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_EVENT_NOTIFICATION:
                {
                    UnconfirmedEventNotificationService un_event_not = new UnconfirmedEventNotificationService();
                    un_event_not.Uevent_Notify_Handler(ref service_request, (ushort)service_request_len, ref src);

                    break;
                }
                }

                break;
            }

            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
            {
                len             = (int)Decode_confirmed_Service_Request(ref apdu, apdu_len, ref service_data, ref service_choice, ref service_request_len, pos);
                service_request = new Byte[service_request_len];
                Array.Copy(apdu, pos + len, service_request, 0, service_request_len);
                switch (service_choice)
                {
                case (Byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY:
                {
                    BACnet_Read_Property_Data data       = new BACnet_Read_Property_Data();
                    ReadPropertyService       rp_service = new ReadPropertyService();

                    rp_service.Read_Property_Handler(ref service_request, service_request_len, ref src, ref service_data);
                    break;
                }

                case (Byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_SUBSCRIBE_COV:
                {
                    CovSubscribeService cov_service = new CovSubscribeService();
                    cov_service.Cov_Subscribe_Handler(ref service_request, service_request_len, ref src, ref service_data);
                    break;
                }

                case (Byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM:
                {
                    AcknowledgeAlarmService ack_al = new AcknowledgeAlarmService();
                    ack_al.Acknowledge_Alarm_Handler(ref service_request, service_request_len, ref src, ref service_data);
                    break;
                }
                }

                break;
            }

            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_SIMPLE_ACK:
            {
                invoke_id      = apdu[pos + 1];
                service_choice = apdu[pos + 2];
                TsmProcessor.free_invoke_id(invoke_id);
                break;
            }

            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK:
            {
                if ((apdu[pos + 0] & BacnetConst.BIT3) != 0)
                {
                    service_ack_data.segmented_message = true;
                }

                if ((apdu[pos + 0] & BacnetConst.BIT2) != 0)
                {
                    service_ack_data.more_follows = true;
                }
                invoke_id = service_ack_data.invoke_id = apdu[pos + 1];
                len       = 2;
                if (service_ack_data.segmented_message)
                {
                    service_ack_data.sequence_number        = apdu[pos + len++];
                    service_ack_data.proposed_window_number = apdu[pos + len++];
                }
                service_choice      = apdu[pos + len++];
                service_request_len = (UInt16)(apdu_len - len);
                service_request     = new Byte[service_request_len];
                Array.Copy(apdu, pos + len, service_request, 0, service_request_len);

                switch (service_choice)
                {
                case (Byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY:
                    ReadPropertyService rp_ack = new ReadPropertyService();
                    rp_ack.Read_Property_Ack_Handler(ref service_request, service_request_len, ref src, ref service_ack_data);
                    break;
                }
                TsmProcessor.free_invoke_id(invoke_id);



                break;
            }

            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_ERROR:

            {
                break;
            }

            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_REJECT:
            {
                break;
            }

            case (Byte)BACNET_PDU_TYPE.PDU_TYPE_ABORT:
            {
                break;
            }
            }
        }