示例#1
0
        public int Decode(byte[] buffer, int offset, uint count)
        {
            int len = 0;

            len++; //ignore apptag time ?
            len += ASN1.decode_bacnet_time(buffer, offset + len, out DateTime time);

            Time = new BacnetGenericTime(time, BacnetTimestampTags.TIME_STAMP_TIME);

            var tagLen = ASN1.decode_tag_number_and_value(buffer, offset + len, out BacnetApplicationTags tagNumber, out uint lenValueType);

            if (tagLen > 0)
            {
                len += tagLen;
                var decodeLen = ASN1.bacapp_decode_data(buffer, offset + len, offset + len + 1, tagNumber, lenValueType, out Value);
                len += decodeLen;
            }
            else
            {
                Value = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL, null);
            }

            return(len);
        }
        private void ReadEffectiveWeeklySchedule()
        {
            Schedule.BeginUpdate();
            Schedule.Nodes.Clear();

            byte[] InOutBuffer = null;

            try
            {
                // first gets the PROP_SCHEDULE_DEFAULT
                IList <BacnetValue> valuedefault;
                comm.ReadPropertyRequest(adr, schedule_id, BacnetPropertyIds.PROP_SCHEDULE_DEFAULT, out valuedefault);
                if ((valuedefault != null) && (valuedefault.Count != 0) && (valuedefault[0].Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL))
                {
                    ScheduleType            = valuedefault[0].Tag;
                    TxtScheduleDefault.Text = valuedefault[0].Value.ToString();
                }


                if (comm.RawEncodedDecodedPropertyConfirmedRequest(adr, schedule_id, BacnetPropertyIds.PROP_WEEKLY_SCHEDULE, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, ref InOutBuffer))
                {
                    int  offset = 0;
                    byte tag_number;
                    uint len_value_type;

                    // Tag 3
                    offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number);
                    if (tag_number != 3)
                    {
                        return;
                    }

                    for (int i = 1; i < 8; i++)
                    {
                        TreeNode tday = null;

                        tday = new TreeNode("[" + (i - 1).ToString() + "] : " + System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.DayNames[i % 7], 0, 0);

                        Schedule.Nodes.Add(tday);

                        // Tag 0
                        offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number);
                        while (!ASN1.IS_CLOSING_TAG(InOutBuffer[offset]))
                        {
                            BacnetValue value;
                            String      s;

                            // Time
                            offset += ASN1.decode_tag_number_and_value(InOutBuffer, offset, out tag_number, out len_value_type);
                            offset += ASN1.bacapp_decode_data(InOutBuffer, offset, InOutBuffer.Length, (BacnetApplicationTags)tag_number, len_value_type, out value);
                            DateTime dt = (DateTime)value.Value;

                            // Value
                            offset += ASN1.decode_tag_number_and_value(InOutBuffer, offset, out tag_number, out len_value_type);
                            offset += ASN1.bacapp_decode_data(InOutBuffer, offset, InOutBuffer.Length, (BacnetApplicationTags)tag_number, len_value_type, out value);

                            if (value.Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL)
                            {
                                s            = dt.ToString("T") + " = " + Property.SerializeValue(value, value.Tag); // Second value is the ... value (Bool, Int, Uint, Float, double or null)
                                ScheduleType = value.Tag;                                                            // all type must be the same for a valid schedule (maybe, not sure !), so remember it
                            }
                            else
                            {
                                s = dt.ToString("T") + " = null";
                            }

                            tday.Nodes.Add(new TreeNode(s, 1, 1));
                        }
                        offset++;
                    }
                    offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number);
                    if (tag_number != 3)
                    {
                        Schedule.Nodes.Clear();
                    }
                }
            }
            catch { }
            finally
            {
                Schedule.EndUpdate();

                Schedule.Sort(); // Time entries are not necesserary sorted, so do it (that's also why days are assign to [0], .. [6])
                Schedule.ExpandAll();
                Schedule.LabelEdit = true;
            }
        }