The context tag encodes the context number and length.
The datatype of the tagged data is determined by the context (production) in which it appears; without the context one cannot tell if a data item with four bytes is an INTEGER, Unsigned, REAL, Date, or Time, for example.
+---+---+---+---+---+---+---+---+
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+---+---+---+---+---+---+---+---+
| tag no. | c | l/v/t |
+---+---+---+---+---+---+---+---+
offset | meaning |
0 bits 7 - 4 | tag number |
0 bit 3 | class (1 for context tag) |
0 bits 2 - 0 | length, value, or type |
Tag Number
If the Tag Number is less than 15, it is the tag number for the following data.
If the Tag Number equals 15, and the Length = 5, the octet after the context tag contains the context number, the octet after that contains the extended length, and the data follows:
+---+---+---+---+---+---+---+---+
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+---+---+---+---+---+---+---+---+
| 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | (tag number = 15, class = context tag, L/v/t = 5 = length uses extension octets
+---+---+---+---+---+---+---+---+
| context number |
+---+---+---+---+---+---+---+---+
| data length |
+---+---+---+---+---+---+---+---+
| data ... |
+---+---+---+---+---+---+---+---+
Class
0 indicates an application tag. The tag number indicates the type.
1 indicates a context specific tag.
Length
For length = 0 to 4, this is the number of octets following containing the data.
For length = 5, the next octet after the context tag contains the 'extended length'. That value describes the number of octests following the extended length containing the data.
+---+---+---+---+---+---+---+---+
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+---+---+---+---+---+---+---+---+
| tag no. | 1 | 1 | 0 | 1 |
+---+---+---+---+---+---+---+---+
| data length |
+---+---+---+---+---+---+---+---+
| data ... |
+---+---+---+---+---+---+---+---+
Sample Context Specific Tag:0C 02 00 00 F5
0C => 0000 1100
tttt clll
field | name | value |
tttt | tag number | 0 |
c | class | 1 |
lll | length | 4 |
dddd dddd ddii iiii iiii iiii iiii iiii
0000 0010 0000 0000 0000 0000 1111 0101
020000F5 | Object type(top 10 bits) = 8 (device) |
020000F5 | Instance Number(bottom 22 bits) = 245 |
See also:
embedded systems - bacnet - Application Tag
embedded systems - bacnet - PD tags