コード例 #1
0
        private int Decode_Service_Request(ref Byte[] apdu, uint request_len, ref ACKNOWLEDGE_ALARM_DATA Ack_data)
        {
            int len = 0;

            int    section_length = 0;
            UInt32 value          = 0;

            /* tag 0 - processIdentifier */
            section_length = BasicalProcessor.Decode_Context_Unsigned(ref apdu, 0, ref Ack_data.ProcessIdentifier, len);
            len           += section_length;
            /* tag 1 - eventObjectIdentifier */
            section_length = BasicalProcessor.Decode_Object_Id(ref apdu, ref Ack_data.EventIdentifier.type, ref Ack_data.EventIdentifier.instance, len);
            len           += section_length;
            /* tag2  EventStare */
            section_length             = BasicalProcessor.Decode_Enumerated(ref apdu, 2, ref value, len);
            Ack_data.StateAcknowledged = (BACNET_EVENT_STATE)value;
            len += section_length;

            /* tag 3 - timeStamp */
            section_length = BasicalProcessor.Decode_Context_Timestamp(ref apdu, 3, ref Ack_data.TimeStamp, len);
            len           += section_length;
            /* tag 4 Acknowledgment Source */
            section_length = BasicalProcessor.Decode_Context_Character_String(ref apdu, 4, ref Ack_data.Source, len);
            len           += section_length;

            /* tag 5 - AcktimeStamp */
            section_length = BasicalProcessor.Decode_Context_Timestamp(ref apdu, 5, ref Ack_data.TimeOfAcknowledgment, len);
            len           += section_length;

            return(len);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        private int Decode_Service_Request(ref Byte[] request, uint request_len, ref BACNET_SUBSCRIBE_COV_DATA data)
        {
            int    len           = 0;
            Byte   tag_number    = 0;
            UInt32 len_value     = 0;
            UInt32 decoded_value = 0; /* for decoding */
            UInt16 decoded_type  = 0; /* for decoding */

            // if (decode_is_context_tag(&apdu[len], 0))
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
            len += BasicalProcessor.Decode_Unsigned(ref request, len_value, ref decoded_value, len);
            data.subscriberProcessIdentifier = decoded_value;
            /* tag 1 - monitoredObjectIdentifier */
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
            len += BasicalProcessor.Decode_Object_Id(ref request, ref decoded_type, ref data.monitoredObjectIdentifier.instance, len);
            data.monitoredObjectIdentifier.type = decoded_type;
            /* optional parameters - if missing, means cancellation */
            if ((uint)len < request_len)
            {
                if (BasicalProcessor.Decode_Is_Context_Tag(ref request, 2, len))
                {
                    data.cancellationRequest = false;
                    len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
                    data.issueConfirmedNotifications = BasicalProcessor.Decode_Context_Boolean(ref request, len);
                    len += (int)len_value;
                    //  if (decode_is_context_tag(&apdu[len], 3))
                    len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);

                    len          += BasicalProcessor.Decode_Unsigned(ref request, len_value, ref decoded_value, len);
                    data.lifetime = decoded_value;
                }
                else
                {
                    data.cancellationRequest = true;
                }
            }
            else
            {
                data.cancellationRequest = true;
            }

            return(len);
        }
        public int Uevent_Notify_Decode(ref Byte[] apdu, uint apdu_len, ref BACNET_EVENT_NOTIFICATION_DATA data)
        {
            int    len            = 0; /* return value */
            int    section_length = 0;
            UInt32 value          = 0;
            Byte   tag_number     = 0;
            uint   len_value      = 0;

            /* tag 0 - processIdentifier */
            section_length = BasicalProcessor.Decode_Context_Unsigned(ref apdu, 0, ref data.processIdentifier, len);
            len           += section_length;

            /* tag 1 - initiatingObjectIdentifier */
            len           += BasicalProcessor.Decode_Tag_number_and_Value(ref apdu, ref tag_number, ref len_value, len);
            section_length = BasicalProcessor.Decode_Object_Id(ref apdu, ref data.initiatingObjectIdentifier.type, ref data.initiatingObjectIdentifier.instance, len);
            len           += section_length;
            /* tag 2 - eventObjectIdentifier */
            len           += BasicalProcessor.Decode_Tag_number_and_Value(ref apdu, ref tag_number, ref len_value, len);
            section_length = BasicalProcessor.Decode_Object_Id(ref apdu, ref data.eventObjectIdentifier.type, ref data.eventObjectIdentifier.instance, len);
            len           += section_length;
            /* tag 3 - timeStamp */
            section_length = BasicalProcessor.Decode_Context_Timestamp(ref apdu, 3, ref data.timeStamp, len);
            len           += section_length;
            /* tag 4 - noticicationClass */
            section_length = BasicalProcessor.Decode_Context_Unsigned(ref apdu, 4, ref data.notificationClass, len);
            len           += section_length;
            /* tag 5 - priority */
            section_length = BasicalProcessor.Decode_Context_Unsigned(ref apdu, 5, ref value, len);
            data.priority  = (Byte)value;
            len           += section_length;
            /* tag 6 - eventType */
            section_length = BasicalProcessor.Decode_Context_Enumerated(ref apdu, 6, ref value, len);
            data.eventType = (BACNET_EVENT_TYPE)value;
            len           += section_length;
            /* tag 7 - messageText */  //option
            //此处没写

            /* tag 8 - notifyType */
            section_length  = BasicalProcessor.Decode_Context_Enumerated(ref apdu, 8, ref value, len);
            data.notifyType = (BACNET_NOTIFY_TYPE)value;
            len            += section_length;

            switch (data.notifyType)
            {
            case BACNET_NOTIFY_TYPE.NOTIFY_ALARM:
            case BACNET_NOTIFY_TYPE.NOTIFY_EVENT:
                /* tag 9 - ackRequired */
                data.ackRequired = BasicalProcessor.Decode_Context_Boolean(ref apdu, len);
                len++;
                len++;
                /* tag 10 - fromState */
                section_length = BasicalProcessor.Decode_Context_Enumerated(ref apdu, 10, ref value, len);
                data.fromState = (BACNET_EVENT_STATE)value;

                len += section_length;
                break;

            default:
                break;
            }
            /* tag 11 - toState */
            section_length = BasicalProcessor.Decode_Context_Enumerated(ref apdu, 11, ref value, len);
            data.toState   = (BACNET_EVENT_STATE)value;
            len           += section_length;

            /* tag 12 - eventValues */
            if (BasicalProcessor.Decode_Is_Opening_Tag_Number(ref apdu, 12, len))
            {
                len++;
            }
            if (BasicalProcessor.Decode_Is_Opening_Tag_Number(ref apdu, (Byte )data.eventType, len))
            {
                len++;
            }

            if (data.notifyType == BACNET_NOTIFY_TYPE.NOTIFY_ALARM || data.notifyType == BACNET_NOTIFY_TYPE.NOTIFY_EVENT)
            {
                switch (data.eventType)
                {
                case BACNET_EVENT_TYPE.EVENT_CHANGE_OF_STATE:
                    //    section_length = BasicalProcessor.Decode_Context_Poroperty_State(ref apdu, 0, ref data.notificationParams.newState, len);
                    len += section_length;

                    //     section_length = BasicalProcessor.Decode_Context_Bitstring(ref apdu, 1, ref data.notificationParams.statusFlags, len);
                    len += section_length;

                    break;

                default:
                    break;
                }
                if (BasicalProcessor.Decode_Is_Closing_Tag_Number(ref apdu, (Byte)data.eventType, len))
                {
                    len++;
                }
                if (BasicalProcessor.Decode_Is_Closing_Tag_Number(ref apdu, 12, len))
                {
                    len++;
                }
            }


            return(len);
        }
コード例 #6
0
        private int Unconfirm_Cov_Decode(ref Byte[] request, uint service_len, ref BACNET_COV_DATA data)
        {
            int    len           = 0; /* return value */
            Byte   tag_number    = 0;
            UInt32 len_value     = 0;
            UInt32 decoded_value = 0; /* for decoding */
            UInt16 decoded_type  = 0; /* for decoding */
            UInt32 property      = 0; /* for decoding */

            /* value in list */
            /* tag 0 - subscriberProcessIdentifier */
            //  if (decode_is_context_tag(&apdu[len], 0))
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
            len += BasicalProcessor.Decode_Unsigned(ref request, len_value, ref decoded_value, len);
            data.subscriberProcessIdentifier = decoded_value;
            /* tag 1 - initiatingDeviceIdentifier */
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
            len += BasicalProcessor.Decode_Object_Id(ref request, ref decoded_type, ref data.initiatingDeviceIdentifier, len);
            /* tag 2 - monitoredObjectIdentifier */
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
            len += BasicalProcessor.Decode_Object_Id(ref request, ref decoded_type, ref data.monitoredObjectIdentifier.instance, len);
            /* tag 3 - timeRemaining */
            len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
            len += BasicalProcessor.Decode_Unsigned(ref request, len_value, ref decoded_value, len);
            data.timeRemaining = decoded_value;

            /* tag 4: opening context tag - listOfValues */
            //   if (!decode_is_opening_tag_number(&apdu[len], 4)) {
            len++;

            while (true) //应该设置遇到时间戳就BREAK? 下面CLOSING TAG有break
            {
                BACNET_PROPERTY_VALUE value = new BACNET_PROPERTY_VALUE();
                /* tag 0 - propertyIdentifier */

                if (BasicalProcessor.Decode_Is_Context_Tag(ref request, 0, len))
                {
                    len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
                    len += BasicalProcessor.Decode_Enumerated(ref request, len_value, ref property, len);
                    value.propertyIdentifier = (BACNET_PROPERTY_ID)property;
                }
                else
                {
                    return(-1);
                }
                /* tag 1 - propertyArrayIndex OPTIONAL */
                if (BasicalProcessor.Decode_Is_Context_Tag(ref request, 1, len))
                {
                    len += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
                    len += BasicalProcessor.Decode_Unsigned(ref request, len_value, ref decoded_value, len);
                    value.propertyArrayIndex = (UInt32)decoded_value;
                }
                else
                {
                    value.propertyArrayIndex = BacnetConst.BACNET_ARRAY_ALL;//#define BACNET_ARRAY_ALL (~(unsigned int)0)
                }
                /* tag 2: opening context tag - value */
                if (!BasicalProcessor.Decode_Is_Opening_Tag_Number(ref request, 2, len))
                {
                    return(-1);
                }
                len++;
                len += BasicalProcessor.Decode_Application_Data(ref request, (uint)(service_len - len), ref value.value, len);

                if (!BasicalProcessor.Decode_Is_Closing_Tag_Number(ref request, 2, len))
                {
                    return(-1);
                }
                len++;

                /* tag 3 - priority OPTIONAL */
                if (BasicalProcessor.Decode_Is_Context_Tag(ref request, 3, len))
                {
                    len           += BasicalProcessor.Decode_Tag_number_and_Value(ref request, ref tag_number, ref len_value, len);
                    len           += BasicalProcessor.Decode_Unsigned(ref request, len_value, ref decoded_value, len);
                    value.priority = (Byte)decoded_value;
                }
                else
                {
                    value.priority = 0;
                }
                data.listOfValues.Add(value);
                if (BasicalProcessor.Decode_Is_Closing_Tag_Number(ref request, 4, len))
                {
                    break;
                }
            }

            return(len);
        }