Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
        public void Check()
        {
            for (int i = 0; i < Form_main.lift_count; i++)
            {
                if (Form_main.lift_list[i].cov_subcription.valid)
                {
                    if (Lift_Record[i].Service_Mode != Form_main.lift_list[i].Service_Mode)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Service_Mode = Form_main.lift_list[i].Service_Mode;
                        temp.propertyIdentifier     = BACNET_PROPERTY_ID.PROP_LIFT_Service_Mode;
                        temp.value.tag = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = (uint)Lift_Record[i].Service_Mode;
                        cov_value.Add(temp);

                        change = true;
                    }
                    if (Lift_Record[i].Car_Status != Form_main.lift_list[i].Car_Status)
                    {
                        Lift_Record[i].Car_Status = Form_main.lift_list[i].Car_Status;

                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;

                        temp.propertyIdentifier       = BACNET_PROPERTY_ID.PROP_LIFT_Car_Status;
                        temp.value.tag                = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = (uint)Lift_Record[i].Car_Status;
                        cov_value.Add(temp);

                        change = true;
                    }
                    if (Lift_Record[i].Car_Direction != Form_main.lift_list[i].Car_Direction)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific  = true;
                        temp.propertyArrayIndex      = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag       = 2;
                        Lift_Record[i].Car_Direction = Form_main.lift_list[i].Car_Direction;

                        temp.propertyIdentifier       = BACNET_PROPERTY_ID.PROP_LIFT_Car_Direction;
                        temp.value.tag                = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = (uint)Lift_Record[i].Car_Direction;
                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Door_Zone != Form_main.lift_list[i].Door_Zone)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Door_Zone    = Form_main.lift_list[i].Door_Zone;

                        temp.propertyIdentifier  = BACNET_PROPERTY_ID.PROP_LIFT_Door_Zone;
                        temp.value.tag           = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN;
                        temp.value.value.Boolean = Lift_Record[i].Door_Zone;
                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Car_Position != Form_main.lift_list[i].Car_Position)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Car_Position = Form_main.lift_list[i].Car_Position;

                        temp.propertyIdentifier       = BACNET_PROPERTY_ID.PROP_LIFT_Car_Position;
                        temp.value.tag                = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT;
                        temp.value.value.Unsigned_Int = Lift_Record[i].Car_Position;

                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Door_Status != Form_main.lift_list[i].Door_Status)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].Door_Status  = Form_main.lift_list[i].Door_Status;

                        temp.propertyIdentifier  = BACNET_PROPERTY_ID.PROP_LIFT_Door_Status;
                        temp.value.tag           = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN;
                        temp.value.value.Boolean = Lift_Record[i].Door_Status;
                        cov_value.Add(temp);
                        change = true;
                    }
                    if (Lift_Record[i].Passenger_Status != Form_main.lift_list[i].Passenger_Status)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific     = true;
                        temp.propertyArrayIndex         = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag          = 2;
                        Lift_Record[i].Passenger_Status = Form_main.lift_list[i].Passenger_Status;

                        temp.propertyIdentifier  = BACNET_PROPERTY_ID.PROP_LIFT_Passenger_Status;
                        temp.value.tag           = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_BOOLEAN;
                        temp.value.value.Boolean = Lift_Record[i].Passenger_Status;
                        cov_value.Add(temp);
                        change = true;
                    }
                    //Message Code未实现

                    if (change)
                    {
                        BACNET_PROPERTY_VALUE temp = new BACNET_PROPERTY_VALUE();
                        temp.value.context_specific = true;
                        temp.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp.value.context_tag      = 2;
                        Lift_Record[i].SetTimeStamp();
                        temp.propertyIdentifier = BACNET_PROPERTY_ID.PROP_LOCAL_DATE;

                        temp.value.tag        = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_DATE;
                        temp.value.value.Date = Lift_Record[i].Time_Stamps.value.date;
                        cov_value.Add(temp);


                        BACNET_PROPERTY_VALUE temp1 = new BACNET_PROPERTY_VALUE();
                        temp1.value.context_specific = true;
                        temp1.propertyArrayIndex     = BacnetConst.BACNET_ARRAY_ALL;
                        temp1.value.context_tag      = 2;
                        temp1.propertyIdentifier     = BACNET_PROPERTY_ID.PROP_LOCAL_TIME;
                        temp1.value.tag        = (Byte)BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_TIME;
                        temp1.value.value.Time = Lift_Record[i].Time_Stamps.value.time;
                        cov_value.Add(temp1);



                        //发送COV


                        BACNET_COV_DATA     cov_data = new BACNET_COV_DATA();
                        UnconFirmCovService Service  = new UnconFirmCovService();
                        cov_data.subscriberProcessIdentifier = Form_main.lift_list[i].cov_subcription.subscriberProcessIdentifier;
                        cov_data.monitoredObjectIdentifier   = Form_main.lift_list[i].cov_subcription.monitoredObjectIdentifier;
                        cov_data.timeRemaining = Form_main.lift_list[i].cov_subcription.lifetime;
                        cov_data.initiatingDeviceIdentifier = Form_main.lift_list[i].Device_Identifier;
                        cov_data.listOfValues = cov_value;

                        Byte[] buff = new Byte[1024];

                        int Send_len = Service.Unconfirm_Cov_Service_Pack(ref buff, ref cov_data);



                        IPEndPoint dest    = new IPEndPoint(IPAddress.Broadcast, 60);//假设60测试?
                        UdpSender  sendder = new UdpSender(ref buff, dest);
                        sendder.SendBrocast(Send_len);
                        change = false;
                    }


                    cov_value.Clear();
                }
            }
        }