Beispiel #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);
        }
Beispiel #2
0
        public void Read_Property_Handler(ref Byte[] request, UInt16 request_len, ref BACNET_ADDRESS src, ref BACNET_CONFIRMED_SERVICE_DATA request_data)
        {
            Byte[] buffer = new Byte[1024];
            BACnet_Read_Property_Data rpdata = new BACnet_Read_Property_Data();
            int len      = 0;
            int pdu_len  = 0;
            int apdu_len = -1;
            int npdu_len = -1;
            BACNET_NPDU_DATA npdu_data = new BACNET_NPDU_DATA();
            bool             error     = true; /* assume that there is an error */
            int            bytes_sent  = 0;
            BACNET_ADDRESS my_address  = new BACNET_ADDRESS();

            BacnetAddresssProcessor.Get_My_Address(ref my_address);
            NpduProcessor n_pro = new NpduProcessor();
            BvlcProcessor b_pro = new BvlcProcessor();

            n_pro.Encode_NpduData(ref npdu_data, false, BACNET_MESSAGE_PRIORITY.MESSAGE_PRIORITY_NORMAL);
            npdu_len = n_pro.Encode(ref buffer, ref src, ref my_address, ref npdu_data);
            //  if (service_data.segmented_message)
            /* we don't support segmentation - send an abort */
            len = Decode_Service_Request(ref request, request_len, ref rpdata);

            len     = Read_Property_ACK_Pack_Int(ref buffer, request_data.invoke_id, ref rpdata, npdu_len);
            pdu_len = npdu_len + len;

            bytes_sent = b_pro.Encode(ref buffer, ref src, ref npdu_data, pdu_len);



            IPEndPoint Ipep = new IPEndPoint(
                IPAddress.Parse("10.10.161.153"), 60);
            UdpSender udpsendr = new UdpSender(ref buffer, Ipep);

            udpsendr.Send(bytes_sent);
        }
        public void Check()
        {
            for (int i = 0; i < Form_main.lift_count; i++)
            {
                if (Form_main.lift_list[i].cov_subcription.valid)
                {
                    if (Lift_Record[i].Service_Mode != Form_main.lift_list[i].Service_Mode)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Service_Mode = Form_main.lift_list[i].Service_Mode;
                        temp.propertyIdentifier     = BACNET_PROPERTY_ID.PROP_LIFT_Service_Mode;
                        temp.value.tag = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = (uint)Lift_Record[i].Service_Mode;
                        cov_value.Add(temp);

                        change = true;
                    }
                    if (Lift_Record[i].Car_Status != Form_main.lift_list[i].Car_Status)
                    {
                        Lift_Record[i].Car_Status = Form_main.lift_list[i].Car_Status;

                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;

                        temp.propertyIdentifier       = BACNET_PROPERTY_ID.PROP_LIFT_Car_Status;
                        temp.value.tag                = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = (uint)Lift_Record[i].Car_Status;
                        cov_value.Add(temp);

                        change = true;
                    }
                    if (Lift_Record[i].Car_Direction != Form_main.lift_list[i].Car_Direction)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific  = true;
                        temp.propertyArrayIndex      = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag       = 2;
                        Lift_Record[i].Car_Direction = Form_main.lift_list[i].Car_Direction;

                        temp.propertyIdentifier       = BACNET_PROPERTY_ID.PROP_LIFT_Car_Direction;
                        temp.value.tag                = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = (uint)Lift_Record[i].Car_Direction;
                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Door_Zone != Form_main.lift_list[i].Door_Zone)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Door_Zone    = Form_main.lift_list[i].Door_Zone;

                        temp.propertyIdentifier  = BACNET_PROPERTY_ID.PROP_LIFT_Door_Zone;
                        temp.value.tag           = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN;
                        temp.value.value.Boolean = Lift_Record[i].Door_Zone;
                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Car_Position != Form_main.lift_list[i].Car_Position)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Car_Position = Form_main.lift_list[i].Car_Position;

                        temp.propertyIdentifier       = BACNET_PROPERTY_ID.PROP_LIFT_Car_Position;
                        temp.value.tag                = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = Lift_Record[i].Car_Position;

                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Door_Status != Form_main.lift_list[i].Door_Status)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Door_Status  = Form_main.lift_list[i].Door_Status;

                        temp.propertyIdentifier  = BACNET_PROPERTY_ID.PROP_LIFT_Door_Status;
                        temp.value.tag           = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN;
                        temp.value.value.Boolean = Lift_Record[i].Door_Status;
                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Passenger_Status != Form_main.lift_list[i].Passenger_Status)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific     = true;
                        temp.propertyArrayIndex         = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag          = 2;
                        Lift_Record[i].Passenger_Status = Form_main.lift_list[i].Passenger_Status;

                        temp.propertyIdentifier  = BACNET_PROPERTY_ID.PROP_LIFT_Passenger_Status;
                        temp.value.tag           = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN;
                        temp.value.value.Boolean = Lift_Record[i].Passenger_Status;
                        cov_value.Add(temp);
                        change = true;
                    }
                    //Message Code未实现

                    if (change)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].SetTimeStamp();
                        temp.propertyIdentifier = BACNET_PROPERTY_ID.PROP_LOCAL_DATE;

                        temp.value.tag        = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_DATE;
                        temp.value.value.Date = Lift_Record[i].Time_Stamps.value.date;
                        cov_value.Add(temp);


                        BACNET_PROPERTY_VALUE temp1 = new BACNET_PROPERTY_VALUE();
                        temp1.value.context_specific = true;
                        temp1.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp1.value.context_tag      = 2;
                        temp1.propertyIdentifier     = BACNET_PROPERTY_ID.PROP_LOCAL_TIME;
                        temp1.value.tag        = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_TIME;
                        temp1.value.value.Time = Lift_Record[i].Time_Stamps.value.time;
                        cov_value.Add(temp1);



                        //发送COV


                        BACNET_COV_DATA     cov_data = new BACNET_COV_DATA();
                        UnconFirmCovService Service  = new UnconFirmCovService();
                        cov_data.subscriberProcessIdentifier = Form_main.lift_list[i].cov_subcription.subscriberProcessIdentifier;
                        cov_data.monitoredObjectIdentifier   = Form_main.lift_list[i].cov_subcription.monitoredObjectIdentifier;
                        cov_data.timeRemaining = Form_main.lift_list[i].cov_subcription.lifetime;
                        cov_data.initiatingDeviceIdentifier = Form_main.lift_list[i].Device_Identifier;
                        cov_data.listOfValues = cov_value;

                        Byte[] buff = new Byte[1024];

                        int Send_len = Service.Unconfirm_Cov_Service_Pack(ref buff, ref cov_data);



                        IPEndPoint dest    = new IPEndPoint(IPAddress.Broadcast, 60);//假设60测试?
                        UdpSender  sendder = new UdpSender(ref buff, dest);
                        sendder.SendBrocast(Send_len);
                        change = false;
                    }


                    cov_value.Clear();
                }
            }
        }