Example #1
0
        // Create a new Application Tag

        public BACnetObjectIdentifier(byte[] buf, ref int offset, BACnetEnums.TAG tagType, BACnetEnums.BACNET_APPLICATION_TAG appTag)
        {
            // is the next parameter even an application tag
            if ((buf[offset] & 0x08) != 0x00)
            {
                // we have an unexpected context tag, sort this out
                BACnetLibraryCL.Panic("Not a context tag");
                // todo, now is there a way to avoid creating the object? Have to flag it at least...
                return;
            }

            if ((BACnetEnums.BACNET_APPLICATION_TAG)(((buf[offset] & 0xf0) >> 4)) != appTag)
            {
                // we have an unexpected context tag, sort this out
                BACnetLibraryCL.Panic("Unexpected application tag");
                // todo, now is there a way to avoid creating the object? Have to flag it at least...
                return;
            }

            int contextTagSize = buf[offset] & 0x07;

            offset++;

            switch (appTag)
            {
            case BACnetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID:
                if (contextTagSize != 4)
                {
                    // we dont have a legal object ID!
                    BACnetLibraryCL.Panic("Illegal length");
                    return;
                }

                this.objectType = (BACnetEnums.BACNET_OBJECT_TYPE)(((uint)buf[offset] << 2) | ((uint)buf[offset + 1] >> 6));

                objectInstance  = ((uint)buf[offset + 1] & 0x3f) << 16;
                objectInstance |= ((uint)buf[offset + 2]) << 8;
                objectInstance |= ((uint)buf[offset + 3]);

                offset += 4;
                return;
            }
        }
Example #2
0
        // Create a new Context Tag

        public BACnetObjectIdentifier(byte[] buf, ref int offset, BACnetEnums.TAG tagType, int tagValue)
        {
            // is the next parameter even a context tag
            if ((buf[offset] & 0x08) != 0x08)
            {
                // we have an unexpected context tag, sort this out
                throw new Exception("m0177-Not a context tag");
                // todo, now is there a way to avoid creating the object? Have to flag it at least...
                //return;
            }

            if ((buf[offset] & 0xf0) != (tagValue << 4))
            {
                // we have an unexpected context tag, sort this out
                throw new Exception("m0174-Unexpected context tag");
                // todo, now is there a way to avoid creating the object? Have to flag it at least...
                //return;
            }

            int contextTagSize = buf[offset] & 0x07;

            // the length of a bacnet object identifier better be 4

            if (contextTagSize != 4)
            {
                // we have an unexpected context tag, sort this out
                throw new Exception("m0175-Unbelievable length of object identifier");
                // todo, now is there a way to avoid creating the object? Have to flag it at least...
                //return;
            }


            objectType = (BACnetEnums.BACNET_OBJECT_TYPE)(((uint)buf[offset + 1] << 2) | ((uint)buf[offset + 2] >> 6));

            objectInstance  = ((uint)buf[offset + 2] & 0x3f) << 16;
            objectInstance |= ((uint)buf[offset + 3]) << 8;
            objectInstance |= ((uint)buf[offset + 4]);

            offset += 5;
        }