public UnconfirmedCOVnotification(byte[] apdu) { int len = 2; BacNetTag tag = new BacNetTag(apdu, len, ref len); ProccessId = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Device = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); Object = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); TimeRemaining = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); BacNetUInt value = new BacNetUInt(apdu, len, tag.Length, ref len); //{ tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); //Это не правильно!!!! /*BacNetReal analogvalue = new BacNetReal(apdu, len, tag.Length, ref len); //} tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len);*/ }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST); res.Add((byte)84); res.Add(BacNetDevice.Instance.InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_CREATE_OBJECT); BacNetTag openingTag = new BacNetTag { Class = true, Length = 6, Number = 0 }; res.AddRange(openingTag.GetBytes()); BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 1 }; res.AddRange(objectTag.GetBytes()); res.AddRange(NewObject.GetObjectBytes()); BacNetTag closingTag = new BacNetTag { Class = true, Length = 7, Number = 0 }; res.AddRange(closingTag.GetBytes()); objectTag.Class = false; objectTag.Number = 0; openingTag.Number = 1; res.AddRange(openingTag.GetBytes()); openingTag.Number = 2; closingTag.Number = 2; foreach (BacNetProperty property in NewObject.Properties) { BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)property.PropertyId.GetLength(), Number = 0 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(property.PropertyId.GetBytes()); res.AddRange(openingTag.GetBytes()); BacNetTag metaTag = new BacNetTag(); foreach (var value in property.Values) { int type; byte[] valueBytes = ByteConverter.GetPropertyValueBytes(value, out type); metaTag = new BacNetTag { Class = false, Length = (byte)valueBytes.Length, Number = (byte)type, LongTag = true }; res.AddRange(metaTag.GetBytes()); res.AddRange(valueBytes); } res.AddRange(closingTag.GetBytes()); } closingTag.Number = 1; res.AddRange(closingTag.GetBytes()); return (byte[])res.ToArray(typeof(byte)); }
public UnconfirmedEventNotification(byte[] apdu) { int len = 2; BacNetTag tag = new BacNetTag(apdu, len, ref len); ProccessId = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Device = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); Object = new BacNetObject(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); if (tag.Length == 6 && tag.Number == 3) { tag = new BacNetTag(apdu, len, ref len); if (tag.Length == 6 && tag.Number == 2) { TimeStamp = new BacNetTimeStamp(apdu, len, ref len); } tag = new BacNetTag(apdu, len, ref len); tag = new BacNetTag(apdu, len, ref len); if (tag.Length != 7 && tag.Number != 3) throw new Exception("Invalid TimeStamp"); } tag = new BacNetTag(apdu, len, ref len); NotificationClass = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Priority = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); EventType = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); Message = new BacNetString(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); NotifyType = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); AckRequired = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); FromState = new BacNetUInt(apdu, len, tag.Length, ref len); tag = new BacNetTag(apdu, len, ref len); ToState = new BacNetUInt(apdu, len, tag.Length, ref len); }
public WhoIs(byte[] apdu) { if(apdu.Length < 2) throw new Exception("Malformed APDU byte array"); if (apdu.Length == 2) return; int len = 2; //Low limit BacNetTag lowLimitTag = new BacNetTag(apdu, len, ref len); LowLimit = new BacNetUInt(apdu, len, lowLimitTag.Length, ref len); //High limit BacNetTag highLimitTag = new BacNetTag(apdu, len, ref len); HighLimit = new BacNetUInt(apdu, len, highLimitTag.Length, ref len); }
public ReadPropertyAck(byte[] apdu) { InvokeId = apdu[1]; int len = 3; //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) throw new Exception("Reject.Invalid_tag"); Obj = new BacNetObject(apdu, len, ref len); //Property Id BacNetTag propertyIdTag = new BacNetTag(apdu, len, ref len); if (propertyIdTag.Number != 1) throw new Exception("Reject.Invalid_tag"); BacNetUInt PropertyId = new BacNetUInt(apdu, len, propertyIdTag.Length, ref len); BacNetTag openingTag = new BacNetTag(apdu, len, ref len); ArrayList ValueList = new ArrayList(); if (openingTag.Length == 6) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7) { if (metaTag.Class == false) { object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); ValueList.Add(value); } else { if (metaTag.Length == 6 && PropertyId.Value == (int)BacNetEnums.BACNET_PROPERTY_ID.PROP_WEEKLY_SCHEDULE) { var value = BuildScheduleDay(apdu, ref len); ValueList.Add(value); } if (metaTag.Length == 4 && metaTag.Number == 0 && PropertyId.Value == (int)BacNetEnums.BACNET_PROPERTY_ID.PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES) { var value = BuildObjectPropertyReference(apdu, ref len); ValueList.Add(value); } } metaTag = new BacNetTag(apdu, len, ref len); } } var property = new BacNetProperty {PropertyId = PropertyId, Values = ValueList}; Obj.Properties.Add(property); }
public ReadPropertyMultiple(byte[] apdu) { Created = DateTime.Now; InvokeId = apdu[2]; int len = 4; if (apdu.Length < 7) throw new Exception("Reject.Missing_required_paramter"); //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) throw new Exception("Reject.Invalid_tag"); while (ReadObject(apdu, len, ref len)) { var obj = ObjectList[ObjectList.Count - 1]; if (obj == null) continue; ReadProperties(apdu, len, obj.ObjectId, ref len); } }
private List<BacNetProperty> ReadProperties(byte[] apdu, int startIndex, uint objectId, ref int len) { List<BacNetProperty> res = new List<BacNetProperty>(); var openingTag = new BacNetTag(apdu, len, ref len); if (openingTag.Length == 6 && openingTag.Number == 1) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while ((metaTag.Length != 7 || metaTag.LongTag) && metaTag.Number != 1) { var propertyId = new BacNetUInt(apdu, len, metaTag.Length, ref len); BacNetProperty prop = new BacNetProperty { PropertyId = propertyId}; prop.Values = ReadValues(apdu, len, ref len); res.Add(prop); metaTag = new BacNetTag(apdu, len, ref len); } } return res; }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST); res.Add((byte)BacNetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); if (LowLimit != null && HighLimit != null) { //Low limit BacNetTag lowLimitTag = new BacNetTag { Class = true, Length = (byte)LowLimit.GetLength(), Number = 0 }; res.AddRange(lowLimitTag.GetBytes()); res.AddRange(LowLimit.GetBytes()); //High limit BacNetTag highLimitTag = new BacNetTag { Class = true, Length = (byte)HighLimit.GetLength(), Number = 1 }; res.AddRange(highLimitTag.GetBytes()); res.AddRange(HighLimit.GetBytes()); } return (byte[]) res.ToArray(typeof (byte)); }
private bool ReadObject(byte[] apdu, int startIndex, ref int len) { bool res = false; if (apdu.Length - 1 > startIndex) { try { //Object tag BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len); if (objectIdTag.Class == false) throw new Exception("Reject.Invalid_tag"); var objectId = new BacNetObject(apdu, len, ref len); ObjectList.Add(objectId); res = true; } catch { throw new Exception("Reject.Invalid_object_tag"); } } return res; }
/// <summary> /// todo: реализовать выбор свойства для отправки /// </summary> /// <returns></returns> public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK); res.Add(InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); //Object ID BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(Obj.GetObjectBytes()); //Max APDU BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)Obj.Properties[0].PropertyId.GetLength(), Number = 1 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(Obj.Properties[0].PropertyId.GetBytes()); /*if (ArrayIndex != null) { BacNetTag arrayIndexTag = new BacNetTag { Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2 }; res.AddRange(arrayIndexTag.GetBytes()); res.AddRange(ArrayIndex.GetBytes()); }*/ return (byte[])res.ToArray(typeof(byte)); }
private object BuildObjectPropertyReference(byte[] apdu, ref int len) { var objId = new BacNetObject(apdu, len, ref len); var metaTag = new BacNetTag(apdu, len, ref len); var propId = new BacNetUInt(apdu, len, metaTag.Length, ref len); return new BacNetObjectPropertyRef {ObjectId = objId, PropertyId = propId}; }
private static Dictionary<BacNetTime, object> BuildScheduleDay(byte[] apdu, ref int len) { var value = new Dictionary<BacNetTime, object>(); var metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7) { var time = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len) as BacNetTime; metaTag = new BacNetTag(apdu, len, ref len); var timeValue = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); if (time != null) { value.Add(time, timeValue); } metaTag = new BacNetTag(apdu, len, ref len); } return value; }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST); res.Add((byte)3); res.Add((byte)InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_WRITE_PROPERTY); //Object ID BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(ObjectId.GetObjectBytes()); //Property ID BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)PropertyId.GetLength(), Number = 1 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(PropertyId.GetBytes()); if (ArrayIndex != null) { BacNetTag arrayIndexTag = new BacNetTag { Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2 }; res.AddRange(arrayIndexTag.GetBytes()); res.AddRange(ArrayIndex.GetBytes()); } //Opening Tag BacNetTag openingTag = new BacNetTag { Class = true, Length = 6, Number = 3 }; res.AddRange(openingTag.GetBytes()); BacNetTag metaTag = new BacNetTag(); foreach (var value in ValueList) { int type; byte[] valueBytes = ByteConverter.GetPropertyValueBytes(value, out type); if (type != 0) { metaTag = new BacNetTag {Class = false, Length = (byte) valueBytes.Length, Number = (byte) type}; res.AddRange(metaTag.GetBytes()); } res.AddRange(valueBytes); } //Closing Tag BacNetTag closingTag = new BacNetTag { Class = true, Length = 7, Number = 3 }; res.AddRange(closingTag.GetBytes()); BacNetTag priorityTag = new BacNetTag {Class = true, Number = 4, Length = 1}; res.AddRange(priorityTag.GetBytes()); res.Add((byte)0xA); return (byte[])res.ToArray(typeof(byte)); }
public byte[] GetBytes() { ArrayList res = new ArrayList(); res.Add((byte)((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (1 << 1))); res.Add((byte)84); res.Add((byte)InvokeId); res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROP_MULTIPLE); //Object ID foreach (BacNetObject obj in ObjectList) { BacNetTag objectTag = new BacNetTag { Class = true, Length = 4, Number = 0 }; res.AddRange(objectTag.GetBytes()); res.AddRange(obj.GetObjectBytes()); BacNetTag openingTag = new BacNetTag{Class = true, Length = 6, Number = 1}; res.AddRange(openingTag.GetBytes()); foreach (BacNetProperty property in obj.Properties) { //Property ID BacNetTag propertyIdTag = new BacNetTag { Class = true, Length = (byte)property.PropertyId.GetLength(), Number = 0 }; res.AddRange(propertyIdTag.GetBytes()); res.AddRange(property.PropertyId.GetBytes()); } BacNetTag closingTag = new BacNetTag { Class = true, Length = 7, Number = 1 }; res.AddRange(closingTag.GetBytes()); } return (byte[])res.ToArray(typeof(byte)); }
public BacNetBool(BacNetTag boolTag) { Value = (boolTag.Length & 1) == 1; }
private ArrayList ReadValues(byte[] apdu, int startIndex, ref int len) { var valueList = new ArrayList(); var openingTag = new BacNetTag(apdu, len, ref len); if (openingTag.Length == 6 && openingTag.Number == 4) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7 || metaTag.LongTag) { object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); valueList.Add(value); metaTag = new BacNetTag(apdu, len, ref len); } } if (openingTag.Length == 6 && openingTag.Number == 5) { BacNetTag metaTag = new BacNetTag(apdu, len, ref len); while (metaTag.Length != 7 || metaTag.LongTag) { object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len); //valueList.Add(value); metaTag = new BacNetTag(apdu, len, ref len); } } return valueList; }