public ReadProperty(BacNetObject bacNetObject, BacNetEnums.BACNET_PROPERTY_ID propertyId) { ObjectId = bacNetObject; PropertyId = new BacNetUInt(); PropertyId.Value = (uint)propertyId; InvokeId = BacNetDevice.Instance.InvokeId; }
public WriteProperty(BacNetObject bacNetObject, BacNetEnums.BACNET_PROPERTY_ID propertyId, ArrayList valueList) { ObjectId = bacNetObject; PropertyId = new BacNetUInt(); PropertyId.Value = (uint)propertyId; ValueList = valueList; InvokeId = BacNetDevice.Instance.InvokeId; }
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 }); }
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 IAm(byte[] apdu) { int len = 2; /* OBJECT ID - BacNetObject */ BacNetTag deviceTag = new BacNetTag(apdu, len, ref len); if (deviceTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID) { throw new Exception("Device Id tag is missed."); } deviceObject = new BacNetObject(apdu, len, ref len); if (deviceObject.ObjectType != BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE) { throw new Exception("Device object is missed."); } /* MAX APDU - uint */ BacNetTag maxLengthTag = new BacNetTag(apdu, len, ref len); if (maxLengthTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT) { throw new Exception("Max APDU length tag is missed."); } MaxApduLength = new BacNetUInt(apdu, len, maxLengthTag.Length, ref len); /* Segmentation - enum */ BacNetTag segmentationTag = new BacNetTag(apdu, len, ref len); if (segmentationTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_ENUMERATED) { throw new Exception("Segmentation APDU tag is missed."); } BacNetEnumeration segmentation = new BacNetEnumeration(apdu, len, segmentationTag.Length, ref len); if (segmentation.Value > (int)BacNetEnums.BACNET_SEGMENTATION.MAX_BACNET_SEGMENTATION) { throw new Exception("Segmentation error."); } BacNetEnums.BACNET_SEGMENTATION tSegmentation; if (BacNetEnums.BACNET_SEGMENTATION.TryParse(segmentation.Value.ToString(), out tSegmentation)) { SegmentationSupported = tSegmentation; } /* Vendor ID - UShort */ BacNetTag vendorTag = new BacNetTag(apdu, len, ref len); if (vendorTag.Number != (int)BacNetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_UNSIGNED_INT) { throw new Exception("Vendor Id tag is missed."); } VendorId = new BacNetUInt(apdu, len, vendorTag.Length, ref len); }
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 static object GetAppTagValue(byte[] apdu, int startIndex, BacNetTag metaTag, ref int len) { object res = null; switch (metaTag.Number) { case 1: //UNSIGNED_INT var boolValue = new BacNetBool(metaTag); res = boolValue; break; case 2: //UNSIGNED_INT var uIntValue = new BacNetUInt(apdu, len, metaTag.Length, ref len); res = uIntValue; break; case 3: //SIGNED_INT var intValue = new BacNetInt(apdu, len, metaTag.Length, ref len); res = intValue; break; case 4: //REAL var realValue = new BacNetReal(apdu, len, metaTag.Length, ref len); res = realValue; break; case 5: //DOUBLE var doubleValue = new BacNetDouble(apdu, len, metaTag.Length, ref len); res = doubleValue; break; case 7: //CHARACTER STRING var str = new BacNetString(apdu, len, metaTag.Length, ref len); res = str; break; case 9: //ENUMERATION var enumValue = new BacNetEnumeration(apdu, len, metaTag.Length, ref len); res = enumValue; break; case 11: //TIME var time = new BacNetTime(apdu, len, ref len); res = time; break; case 12: //OBJECT IDENTIFIER var obj = new BacNetObject(apdu, len, ref len); res = obj; break; } return(res); }
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_SUBSCRIBE_COV); //Process ID var processIdTag = new BacNetTag { Class = true, Length = (byte)ProccessId.GetLength(), Number = 0 }; res.AddRange(processIdTag.GetBytes()); res.AddRange(ProccessId.GetBytes()); //Object ID var objectTag = new BacNetTag { Class = true, Length = 4, Number = 1 }; res.AddRange(objectTag.GetBytes()); res.AddRange(ObjectId.GetObjectBytes()); //Issue Confirmed Notifications var icn = new BacNetBool(); icn.Value = false; var icnTag = new BacNetTag { Class = true, Length = (byte)icn.GetLength(), Number = 2 }; res.AddRange(icnTag.GetBytes()); res.AddRange(icn.GetBytes()); //Lifetime var lifeTime = new BacNetUInt(); lifeTime.Value = 360; var lifeTimeTag = new BacNetTag { Class = true, Length = (byte)lifeTime.GetLength(), Number = 3 }; res.AddRange(lifeTimeTag.GetBytes()); res.AddRange(lifeTime.GetBytes()); return((byte[])res.ToArray(typeof(byte))); }
public ReadProperty(byte[] apdu) { 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"); } ObjectId = 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"); } PropertyId = new BacNetUInt(apdu, len, propertyIdTag.Length, ref len); if (len < apdu.Length) { BacNetTag arrayIndexTag = new BacNetTag(apdu, len, ref len); if (arrayIndexTag.Number == 2 && len < apdu.Length) { ArrayIndex = new BacNetUInt(apdu, len, arrayIndexTag.Length, ref len); } else { throw new Exception("Reject.InvalidTag"); } } if (len < apdu.Length) { throw new Exception("Reject.TooManyArguments"); } }
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 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 WhoIs(UInt16 startAddress = UInt16.MinValue, UInt16 endAddress = UInt16.MaxValue) { if (startAddress <= endAddress && endAddress != UInt16.MaxValue) { LowLimit = new BacNetUInt { Value = startAddress }; HighLimit = new BacNetUInt { Value = endAddress }; } /*ServiceNumber = (byte) BacNetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS; * if (startAddress != UInt16.MinValue && endAddress != UInt16.MaxValue) * { * byte[] start = ByteConverter.GetBytes(startAddress); * _params.AddRange((new BacNetTag { Class = true, Length = (byte)start.Length, Number = 0 }).GetBytes()); * _params.AddRange(start); * byte[] end = ByteConverter.GetBytes(endAddress); * _params.AddRange((new BacNetTag { Class = true, Length = (byte)end.Length, Number = 1 }).GetBytes()); * _params.AddRange(end); * }*/ }
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);*/ }