Пример #1
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);
        }
Пример #2
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的处理
        }
        public static int Encode_Application_Data(ref Byte[] apdu, ref BACNET_APPLICATION_DATA_VALUE value, int pos)
        {
            int apdu_len = 0;

            switch (value.tag)
            {
            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT:
            {
                apdu_len  = BasicalProcessor.Encode_Unsigned(ref apdu, value.value.Unsigned_Int, pos + 1);
                apdu_len += BasicalProcessor.Encode_Tag(ref apdu, (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT, false, (uint)apdu_len, pos);

                break;
            }

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN:
            {
                apdu_len += BasicalProcessor.Encode_Application_Boolbean(ref apdu, value.value.Boolean, pos);
                break;
            }

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_DATE:
            {
                apdu_len = BasicalProcessor.Encode_Application_Date(ref apdu, ref value.value.Date, pos);

                break;
            }

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_TIME:
            {
                apdu_len = BasicalProcessor.Encode_Application_Time(ref apdu, ref value.value.Time, pos);
                break;
            }

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_CHARACTER_STRING:
            {
                apdu_len = BasicalProcessor.Encode_Application_Character_String(ref apdu, ref value.value.Character_String, pos);
                break;
            }
            }


            return(apdu_len);
        }
        public static int Decode_Data(ref Byte[] apdu, Byte tag_data_type, UInt32 len_value_type, ref BACNET_APPLICATION_DATA_VALUE value, int pos)
        {
            int len = 0;

            switch (tag_data_type)
            {
            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_NULL:
                break;

            case  (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN:
                value.value.Boolean = Decode_Boolean(len_value_type);
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT:
                len = Decode_Unsigned(ref apdu, len_value_type, ref value.value.Unsigned_Int, pos);
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_SIGNED_INT:
                len = Decode_Signed(ref apdu, len_value_type, ref value.value.Signed_Int, pos);
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_REAL:

                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_DOUBLE:
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OCTET_STRING:
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_CHARACTER_STRING:
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BIT_STRING:
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_ENUMERATED:
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_DATE:
                len = Decode_Date(ref apdu, ref value.value.Date, pos);
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_TIME:
                len = Decode_Time(ref apdu, ref value.value.Time, pos);
                break;

            case (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID:
                break;
            }
            if (len == 0 && tag_data_type != (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_NULL &&
                tag_data_type != (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN)
            {
                /* indicate that we were not able to decode the value */
                value.tag = (Byte)BACNET_APPLICATION_TAG.MAX_BACNET_APPLICATION_TAG;
            }
            return(len);
        }
        public static int Decode_Application_Data(ref Byte[] apdu, uint max_apdu_len, ref BACNET_APPLICATION_DATA_VALUE value, int pos)
        {
            int    len            = 0;
            int    tag_len        = 0;
            int    decode_len     = 0;
            Byte   tag_number     = 0;
            UInt32 len_value_type = 0;

            // if (apdu && value && !IS_CONTEXT_SPECIFIC(*apdu))
            value.context_specific = false;
            tag_len    = BasicalProcessor.Decode_Tag_number_and_Value(ref apdu, ref tag_number, ref len_value_type, pos);
            len       += tag_len;
            value.tag  = tag_number;
            decode_len = BasicalProcessor.Decode_Data(ref apdu, tag_number, len_value_type, ref value, pos + len);
            //  if (value->tag != MAX_BACNET_APPLICATION_TAG)

            len       += decode_len;
            value.next = null;
            return(len);
        }