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);
        }
예제 #2
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);
        }