Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public ErrorAck(byte[] apdu)
        {
            if (apdu.Length > 2)
            {
                InvokeId      = apdu[1];
                ServiceChoise = apdu[2];
            }
            int len = 3;
            //Error class
            BacNetTag errorClassTag = new BacNetTag(apdu, len, ref len);

            if (errorClassTag.Class)
            {
                throw new Exception("Reject.Invalid_tag");
            }
            BacNetEnumeration errorClass = new BacNetEnumeration(apdu, len, errorClassTag.Length, ref len);

            if (errorClass.Value > (int)BacNetEnums.BACNET_ERROR_CLASS.MAX_BACNET_ERROR_CLASS)
            {
                throw new Exception("Error class error.");
            }
            BacNetEnums.BACNET_ERROR_CLASS tErrorClass;
            if (BacNetEnums.BACNET_ERROR_CLASS.TryParse(errorClass.Value.ToString(), out tErrorClass))
            {
                ErrorClass = tErrorClass;
            }
            //Error code
            BacNetTag errorCodeTag = new BacNetTag(apdu, len, ref len);

            if (errorCodeTag.Class)
            {
                throw new Exception("Reject.Invalid_tag");
            }
            BacNetEnumeration errorCode = new BacNetEnumeration(apdu, len, errorCodeTag.Length, ref len);

            if (errorCode.Value > (int)BacNetEnums.BACNET_ERROR_CODE.MAX_BACNET_ERROR_CODE)
            {
                throw new Exception("Error class error.");
            }
            BacNetEnums.BACNET_ERROR_CODE tErrorCode;
            if (BacNetEnums.BACNET_ERROR_CODE.TryParse(errorCode.Value.ToString(), out tErrorCode))
            {
                ErrorCode = tErrorCode;
            }
        }