Пример #1
0
        private int Read_Property_Encode(ref byte[] apdu, Byte invoke_id, BACnet_Read_Property_Data rpdata, int pos)
        {
            int len      = 0;    /* length of each encoding */
            int apdu_len = 0;

            apdu[pos + 0] = (byte)BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
            apdu[pos + 1] = BasicalProcessor.Encode_MaxSegsandApdu(0, 1476);
            apdu[pos + 2] = invoke_id;
            apdu[pos + 3] = (byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY;
            apdu_len      = 4;

            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 0, (int)rpdata.object_type, rpdata.object_instance, pos + apdu_len);
            apdu_len += len;
            if ((int)rpdata.object_property <= 4194303)
            {
                len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 1, (uint)rpdata.object_property, pos + apdu_len);
                apdu_len += len;
            }

            if (rpdata.array_index != BacnetConst.BACNET_ARRAY_ALL)
            {
                len =
                    BasicalProcessor.Encode_Context_Unsigned(ref apdu, 2,
                                                             (UInt32)rpdata.array_index, pos + apdu_len);
                apdu_len += len;
            }


            return(apdu_len);
        }
Пример #2
0
        public int  Read_Property_ACK_Pack_Int(ref Byte[] apdu, Byte invoke_id, ref BACnet_Read_Property_Data rpdata, int pos)
        {
            int len      = 0;   /* length of each encoding */
            int apdu_len = 0;

            apdu[pos + 0] = (Byte)BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK;                     /* complex ACK service */
            apdu[pos + 1] = invoke_id;                                                      /* original invoke id from request */
            apdu[pos + 2] = (Byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
            apdu_len      = 3;
            len           = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 0, (int)rpdata.object_type, rpdata.object_instance, pos + apdu_len);
            apdu_len     += len;
            len           = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 1, (UInt32)rpdata.object_property, pos + apdu_len);
            apdu_len     += len;
            //  if (rpdata->array_index != BACNET_ARRAY_ALL) {

            len       = BasicalProcessor.Encode_Opening_Tag(ref apdu, 3, pos + apdu_len);
            apdu_len += len;

            len       = Device_Read_Property(ref apdu, ref rpdata, pos + apdu_len);
            apdu_len += len;

            len       = BasicalProcessor.Encode_Closing_Tag(ref apdu, 3, pos + apdu_len);
            apdu_len += len;
            return(apdu_len);
        }
Пример #3
0
        public int Decode_Ack_Service_Request(ref Byte[] apdu, UInt16 apdu_len, ref BACnet_Read_Property_Data rpdata, int pos = 0)
        {
            Byte   tag_number     = 0;
            UInt32 len_value_type = 0;
            int    tag_len        = 0; /* length of tag decode */
            int    len            = 0; /* total length of decodes */
            UInt16 object_type    = 0; /* object type */
            UInt32 property       = 0; /* for decoding */
            UInt32 array_value    = 0; /* for decoding */

            len  = 1;
            len += BasicalProcessor.Decode_Object_Id(ref apdu, ref object_type, ref rpdata.object_instance, len);
            rpdata.object_type = (BACNET_OBJECT_TYPE)object_type;
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref apdu, ref tag_number, ref len_value_type, len);
            if (tag_number != 1)
            {
                return(-1);
            }
            len += BasicalProcessor.Decode_Enumerated(ref apdu, len_value_type, ref property, len);
            rpdata.object_property = (BACNET_PROPERTY_ID)property;
            /* Tag 2: Optional Array Index 没有 */
            rpdata.array_index = BacnetConst.BACNET_ARRAY_ALL;
            if (BasicalProcessor.Decode_Is_Opening_Tag_Number(ref apdu, 3, pos + len))
            {
                len++;
            }
            rpdata.application_data_pos = len;
            rpdata.application_data_len = (int)apdu_len - len - 1;
            return(len);
        }
Пример #4
0
        private int Decode_Service_Request(ref Byte[] request, uint request_len, ref BACnet_Read_Property_Data rpdata)
        {
            int    len            = 0;
            Byte   tag_number     = 0;
            UInt32 len_value_type = 0;
            UInt16 type           = 0; /* for decoding */
            UInt32 property       = 0; /* for decoding */
            UInt32 array_value    = 0; /* for decoding */

            //此处有对于错误请求的判断 decode_is_context_tag(&apdu[len++], 0)
            len++;
            len += BasicalProcessor.Decode_Object_Id(ref request, ref type, ref rpdata.object_instance, len);
            rpdata.object_type = (BACNET_OBJECT_TYPE)type;



            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value_type, len);
            //if (tag_number != 1)...


            len += BasicalProcessor.Decode_Enumerated(ref request, len_value_type, ref property, len);
            rpdata.object_property = (BACNET_PROPERTY_ID)property;
            // /* Tag 2: Optional Array Index */if (len < apdu_len)

            rpdata.application_data_len = (int)request_len - len - 1;
            return(len);
        }
Пример #5
0
        public int Device_Read_Property(ref Byte[] apdu, ref BACnet_Read_Property_Data rpdata, int pos)
        {
            int len = 0;
            BACNET_APPLICATION_DATA_VALUE value = new BACNET_APPLICATION_DATA_VALUE();

            value.context_specific = false;
            switch (rpdata.object_property)
            {
            case BACNET_PROPERTY_ID.PROP_LIFT_Car_Direction:
            {
                value.tag = 2;
                value.value.Unsigned_Int = Form_main.true_lift.Car_Direction;
                break;
            }

            case BACNET_PROPERTY_ID.PROP_LIFT_Car_Position:
            {
                value.tag = 2;
                value.value.Unsigned_Int = 4;
                break;
            }

            case BACNET_PROPERTY_ID.PROP_LIFT_Device_Identifer:
            {
                value.tag = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_CHARACTER_STRING;
                for (int i = 0; i < Form_main.lift_count; i++)
                {
                    if (Form_main.lift_list[i].Object_Identifier.instance == rpdata.object_instance)
                    {
                        String result = Form_main.lift_list[i].Identification_Number;

                        value.value.Character_String          = new BACNET_CHARACTER_STRING(result.Length);
                        value.value.Character_String.size     = (uint)result.Length;
                        value.value.Character_String.encoding = 1;
                        value.value.Character_String.value    = result.ToCharArray();
                    }
                }


                break;
            }
            }


            len = BasicalProcessor.Encode_Application_Data(ref apdu, ref value, pos);

            //此处读出属性 加打入编码app类型和值
            //X
            // uint 61
            return(len);
        }
Пример #6
0
        public void Read_Property_Ack_Handler(ref Byte[] request, UInt16 request_len, ref BACNET_ADDRESS src, ref BACNET_CONFIRMED_SERVICE_ACK_DATA service_data)
        {
            int len = 0;
            BACnet_Read_Property_Data data = new BACnet_Read_Property_Data();

            len = Decode_Ack_Service_Request(ref request, request_len, ref data);

            BACNET_APPLICATION_DATA_VALUE value = new BACNET_APPLICATION_DATA_VALUE();

            BasicalProcessor.Decode_Application_Data(ref request, (uint)data.application_data_len, ref value, data.application_data_pos);


            MessageBox.Show(value.value.Unsigned_Int.ToString(), data.object_property.ToString());
            //  if (len > 0)
            //   rp_ack_print_data(ref data);
            //此处添加对读取到的data的处理
        }
Пример #7
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 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;
            }
            }
        }