예제 #1
0
        private int Notify_Encode_Data(ref Byte[] apdu, BACNET_COV_DATA cov_data, int pos)
        {
            int len      = 0;                   /* length of each encoding */
            int apdu_len = 0;
            BACNET_PROPERTY_VALUE value = null; /* value in list */

            /* tag 0 - subscriberProcessIdentifier */
            len       = BasicalProcessor.Encode_Context_Unsigned(ref apdu, 0, cov_data.subscriberProcessIdentifier, pos + apdu_len);
            apdu_len += len;
            /* tag 1 - initiatingDeviceIdentifier */
            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 1, (int)BACNET_OBJECT_TYPE.OBJECT_DEVICE, cov_data.initiatingDeviceIdentifier, pos + apdu_len);
            apdu_len += len;
            /* tag 2 - monitoredObjectIdentifier */
            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 2, (int)cov_data.monitoredObjectIdentifier.type, cov_data.monitoredObjectIdentifier.instance, pos + apdu_len);
            apdu_len += len;
            /* tag 3 - timeRemaining */
            len       = BasicalProcessor.Encode_Context_Unsigned(ref apdu, 3, cov_data.timeRemaining, pos + apdu_len);
            apdu_len += len;
            /* tag 4 - listOfValues */
            len       = BasicalProcessor.Encode_Opening_Tag(ref apdu, 4, pos + apdu_len);
            apdu_len += len;
            /* the first value includes a pointer to the next value, etc */



            for (int count = 0; count < cov_data.listOfValues.Count; count++)
            {
                value = cov_data.listOfValues[count];
                /* tag 0 - propertyIdentifier */
                len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 0, (uint)value.propertyIdentifier, pos + apdu_len);
                apdu_len += len;
                /* tag 1 - propertyArrayIndex OPTIONAL */
                if (value.propertyArrayIndex != BacnetConst.BACNET_ARRAY_ALL)
                {
                    len =
                        BasicalProcessor.Encode_Context_Unsigned(ref apdu, 1,
                                                                 (uint)value.propertyArrayIndex, apdu_len);
                    apdu_len += len;
                }
                /* tag 2 - value */
                len       = BasicalProcessor.Encode_Opening_Tag(ref apdu, 2, pos + apdu_len);
                apdu_len += len;
                len       = BasicalProcessor.Encode_Application_Data(ref apdu, ref value.value, apdu_len + pos);
                apdu_len += len;
                len       = BasicalProcessor.Encode_Closing_Tag(ref apdu, 2, apdu_len + pos);
                apdu_len += len;
                /* tag 3 - priority OPTIONAL */
                if (value.priority != 0)
                {
                    len =
                        BasicalProcessor.Encode_Context_Unsigned(ref apdu, 3, value.priority, apdu_len);
                    apdu_len += len;
                }
            }

            len       = BasicalProcessor.Encode_Closing_Tag(ref apdu, 4, pos + apdu_len);
            apdu_len += len;

            return(apdu_len);
        }
예제 #2
0
        public int  Read_Property_ACK_Pack_Int(ref Byte[] apdu, Byte invoke_id, ref BACnet_Read_Property_Data rpdata, int pos)
        {
            int len      = 0;   /* length of each encoding */
            int apdu_len = 0;

            apdu[pos + 0] = (Byte)BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK;                     /* complex ACK service */
            apdu[pos + 1] = invoke_id;                                                      /* original invoke id from request */
            apdu[pos + 2] = (Byte)BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
            apdu_len      = 3;
            len           = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 0, (int)rpdata.object_type, rpdata.object_instance, pos + apdu_len);
            apdu_len     += len;
            len           = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 1, (UInt32)rpdata.object_property, pos + apdu_len);
            apdu_len     += len;
            //  if (rpdata->array_index != BACNET_ARRAY_ALL) {

            len       = BasicalProcessor.Encode_Opening_Tag(ref apdu, 3, pos + apdu_len);
            apdu_len += len;

            len       = Device_Read_Property(ref apdu, ref rpdata, pos + apdu_len);
            apdu_len += len;

            len       = BasicalProcessor.Encode_Closing_Tag(ref apdu, 3, 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);
        }