public int Decode(byte[] buffer, int offset, uint count) { int len = 0; byte periodType; len += ASN1.decode_tag_number(buffer, offset + len, out periodType); // -> type switch (periodType) { case 0: //calendarEntry var calendar = new BACnetCalendarEntry(); len += calendar.Decode(buffer, offset + len, count); Period = calendar; len += 1; // -> closingtag break; case 1: //calendarReference var calRef = new BacnetObjectId(); len += ASN1.decode_object_id(buffer, offset + len, out calRef.type, out calRef.instance); Period = calRef; break; } ListOfTimeValues = new List <BacnetTimeValue>(); if (ASN1.IS_OPENING_TAG(buffer[offset + len])) { len++; //end of daily sched while (!ASN1.IS_CLOSING_TAG(buffer[offset + len])) { var timeVal = new BacnetTimeValue(); len += timeVal.Decode(buffer, offset + len, count); ListOfTimeValues.Add(timeVal); } //closing tag len++; } uint evPr; len += ASN1.decode_context_unsigned(buffer, offset + len, 3, out evPr); EventPriority = (byte)evPr; return(len); }
public int Decode(byte[] buffer, int offset, uint count) { int len = 0; DaySchedule = new List <BacnetTimeValue>(); //begin of daily sched if (ASN1.IS_OPENING_TAG(buffer[offset + len])) { len++; //end of daily sched while (!ASN1.IS_CLOSING_TAG(buffer[offset + len])) { var timeVal = new BacnetTimeValue(); len += timeVal.Decode(buffer, offset + len, count); DaySchedule.Add(timeVal); } //closing tag len++; } 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; } }
private void ReadExceptionSchedule() { byte[] InOutBuffer = null; try { if (comm.RawEncodedDecodedPropertyConfirmedRequest(adr, schedule_id, BacnetPropertyIds.PROP_EXCEPTION_SCHEDULE, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, ref InOutBuffer)) { int offset = 0; byte tag_number; // Tag 3 offset += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); if (tag_number != 3) { return; } int i = 1; while (!ASN1.IS_CLOSING_TAG(InOutBuffer[offset])) { TreeNode tday = null; var bse = new BACnetSpecialEvent(); offset += bse.ASN1decode(InOutBuffer, offset); tday = new TreeNode(string.Format("[{0}] {1}", i++, bse.period.ToString())); tday.Nodes.Add(new TreeNode(String.Format("priority: {0}", bse.eventPriority), 1, 1)); exceptionSchedules.Nodes.Add(tday); foreach (var tv in bse.Values) { var value = tv.value; var dt = tv.dt; string s; 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 += ASN1.decode_tag_number(InOutBuffer, offset, out tag_number); if (tag_number != 3) { exceptionSchedules.Nodes.Clear(); } exceptionSchedules.ExpandAll(); } } catch { } finally { exceptionSchedules.EndUpdate(); exceptionSchedules.Sort(); // Time entries are not necesserary sorted, so do it (that's also why days are assign to [0], .. [6]) exceptionSchedules.ExpandAll(); exceptionSchedules.LabelEdit = true; } }