Esempio n. 1
0
        private int Acknowledge_Alarm_Encode(ref Byte[] apdu, Byte invoke_id, ref ACKNOWLEDGE_ALARM_DATA Ack_data, 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_ACKNOWLEDGE_ALARM;
            apdu_len      = 4;

            /* tag 0 - processIdentifier */
            len       = BasicalProcessor.Encode_Context_Unsigned(ref apdu, 0, Ack_data.ProcessIdentifier, pos + apdu_len);
            apdu_len += len;
            /* tag 1 - eventObjectIdentifier */
            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 1, (int)Ack_data.EventIdentifier.type, Ack_data.EventIdentifier.instance, pos + apdu_len);
            apdu_len += len;
            /* tag 2 - toState */
            len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 2, (uint)Ack_data.StateAcknowledged, apdu_len + pos);
            apdu_len += len;
            /* tag 3 - timeStamp */
            len       = BasicalProcessor.Encode_Context_Timestamp(ref apdu, 3, ref Ack_data.TimeStamp, pos + apdu_len);
            apdu_len += len;
            /* tag 4 - Acknowledgment Source */

            len       = BasicalProcessor.Encode_Context_Character_String(ref apdu, 4, ref Ack_data.Source, pos + apdu_len);
            apdu_len += len;
            /* tag 5- timeStamp */
            len       = BasicalProcessor.Encode_Context_Timestamp(ref apdu, 5, ref Ack_data.TimeOfAcknowledgment, pos + apdu_len);
            apdu_len += len;
            return(apdu_len);
        }
        private int Encode_Service_Request(ref Byte[] apdu, ref BACNET_EVENT_NOTIFICATION_DATA data, int pos)
        {
            int len      = 0;   /* length of each encoding */
            int apdu_len = 0;

            /* tag 0 - processIdentifier */
            len       = BasicalProcessor.Encode_Context_Unsigned(ref apdu, 0, data.processIdentifier, pos + apdu_len);
            apdu_len += len;
            /* tag 1 - initiatingObjectIdentifier */
            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 1, (int)data.initiatingObjectIdentifier.type, data.initiatingObjectIdentifier.instance, pos + apdu_len);
            apdu_len += len;
            /* tag 2 - eventObjectIdentifier */
            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 2, (int)data.eventObjectIdentifier.type, data.eventObjectIdentifier.instance, pos + apdu_len);
            apdu_len += len;
            /* tag 3 - timeStamp */
            len       = BasicalProcessor.Encode_Context_Timestamp(ref apdu, 3, ref data.timeStamp, pos + apdu_len);
            apdu_len += len;
            /* tag 4 - noticicationClass */
            len       = BasicalProcessor.Encode_Context_Unsigned(ref apdu, 4, data.notificationClass, apdu_len + pos);
            apdu_len += len;
            /* tag 5 - priority */
            len       = BasicalProcessor.Encode_Context_Unsigned(ref apdu, 5, data.priority, apdu_len + pos);
            apdu_len += len;
            /* tag 6 - eventType */
            len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 6, (uint)data.eventType, apdu_len + pos);
            apdu_len += len;
            /* tag 7 - messageText */
            // if (data->messageText) 可选参数
            /* tag 8 - notifyType */
            len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 8, (uint)data.notifyType, apdu_len + pos);
            apdu_len += len;
            /* tag 9 - ackRequired */
            switch (data.notifyType)
            {
            case BACNET_NOTIFY_TYPE.NOTIFY_ALARM:
            case BACNET_NOTIFY_TYPE.NOTIFY_EVENT:
                /* tag 9 - ackRequired */
                len       = BasicalProcessor.Encode_Context_Boolean(ref apdu, 9, data.ackRequired, apdu_len + pos);
                apdu_len += len;
                /* tag 10 - fromState */
                len = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 10, (uint)data.fromState, apdu_len + pos);

                apdu_len += len;
                break;

            default:
                break;
            }
            /* tag 11 - toState */
            len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 11, (uint)data.toState, apdu_len + pos);
            apdu_len += len;

            /* tag 12 - event values */
            if (data.notifyType == BACNET_NOTIFY_TYPE.NOTIFY_ALARM || data.notifyType == BACNET_NOTIFY_TYPE.NOTIFY_EVENT)
            {
                switch (data.eventType)
                {
                //EVENT_CHANGE_OF_STATE:

                /*   case BACNET_EVENT_TYPE.EVENT_CHANGE_OF_STATE:
                 * {
                 * len = BasicalProcessor.Encode_Opening_Tag(ref apdu, 12,apdu_len+pos);
                 * apdu_len += len;
                 * len = BasicalProcessor.Encode_Opening_Tag(ref apdu, 1, apdu_len + pos);
                 * apdu_len += len;
                 * len = BasicalProcessor.Encode_Opening_Tag(ref apdu, 0, apdu_len + pos);
                 * apdu_len += len;
                 * len=BasicalProcessor.Encode_Property_State(ref apdu,ref data.notificationParams.newState,apdu_len+pos);
                 * apdu_len += len;
                 * len = BasicalProcessor.Encode_Closing_Tag(ref apdu, 0, apdu_len + pos);
                 * apdu_len += len;
                 * len = BasicalProcessor.Encode_Context_Bitstring(ref apdu, 1, ref data.notificationParams.statusFlags, apdu_len + pos);
                 * apdu_len += len;
                 * len = BasicalProcessor.Encode_Opening_Tag(ref apdu,1, apdu_len + pos);
                 * apdu_len += len;
                 * len = BasicalProcessor.Encode_Closing_Tag(ref apdu, 12,apdu_len+pos);
                 * apdu_len += len;
                 * break;
                 *  }*/
                case BACNET_EVENT_TYPE.EVENT_CHANGE_OF_LIFE_SAFETY:
                {
                    len       = BasicalProcessor.Encode_Opening_Tag(ref apdu, 8, apdu_len + pos);
                    apdu_len += len;

                    len = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 0, (UInt16)data.notificationParams.change_of_lifesafety.newState, apdu_len + pos);

                    apdu_len += len;
                    len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 1, (UInt16)data.notificationParams.change_of_lifesafety.newMode, apdu_len + pos);

                    apdu_len += len;
                    len       = BasicalProcessor.Encode_Context_Bitstring(ref apdu, 2, ref data.notificationParams.change_of_lifesafety.statusFlags, apdu_len + pos);
                    apdu_len += len;

                    len = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 3, (UInt16)data.notificationParams.change_of_lifesafety.operationExpected, apdu_len + pos);

                    apdu_len += len;


                    len       = BasicalProcessor.Encode_Closing_Tag(ref apdu, 8, apdu_len + pos);
                    apdu_len += len;
                    break;
                }
                }
            }
            return(apdu_len);
        }