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);
        }