예제 #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
        private int Read_Property_Encode(ref byte[] apdu, Byte invoke_id, 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_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_READ_PROPERTY;
            apdu_len      = 4;

            len       = BasicalProcessor.Encode_Context_ObjectId(ref apdu, 0, (int)rpdata.object_type, rpdata.object_instance, pos + apdu_len);
            apdu_len += len;
            if ((int)rpdata.object_property <= 4194303)
            {
                len       = BasicalProcessor.Encode_Context_Enumerate(ref apdu, 1, (uint)rpdata.object_property, pos + apdu_len);
                apdu_len += len;
            }

            if (rpdata.array_index != BacnetConst.BACNET_ARRAY_ALL)
            {
                len =
                    BasicalProcessor.Encode_Context_Unsigned(ref apdu, 2,
                                                             (UInt32)rpdata.array_index, pos + apdu_len);
                apdu_len += len;
            }


            return(apdu_len);
        }
예제 #3
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);
        }
예제 #4
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);
        }