Example #1
0
        public static void EncodeApplicationTag(byte[] buf, ref int optr, BACnetEnums.BACNET_APPLICATION_TAG appTag, int value)
        {
            // http://www.bacnetwiki.com/wiki/index.php?title=Application_Tags

            // establish the number of bytes required to encode the tag (i.e. length)

            if (value > 15)
            {
                throw new Exception("Todo-encode values greater than one byte");
            }

            buf[optr++] = (byte)((int)appTag << 4 | 1);
            buf[optr++] = (byte)(value & 0xff);
        }
Example #2
0
        static public void InsertApplicationTag(byte[] buffer, ref int optr, BACnetEnums.BACNET_APPLICATION_TAG apptag, UInt32 value)
        {
            int saveOptr = optr++;
            int length   = 1;

            if (value >= (1 << 24))
            {
                buffer[optr++] = (byte)((value >> 24) & 0xff);
                length++;
            }
            if (value >= (1 << 16))
            {
                buffer[optr++] = (byte)((value >> 16) & 0xff);
                length++;
            }
            if (value >= (1 << 8))
            {
                buffer[optr++] = (byte)((value >> 8) & 0xff);
                length++;
            }
            buffer[optr++]   = (byte)(value & 0xff);
            buffer[saveOptr] = (byte)(((int)apptag << 4) | length);
        }
Example #3
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
                throw new Exception("m0515-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
                throw new Exception("m0519 - Unexpected application tag xxx , expecting " + appTag.ToString());
            }

            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!
                    throw new Exception("m0176-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;
            }
        }