Codec 8, Codec 8 Extended and Codec 16
Every AVL data field starts with a codec id and a record count. Codec 8 (0x08) is the original format: one-byte IO element ids, one-byte counts for each element width (1, 2, 4 and 8 bytes) and fixed-width values. Codec 8 Extended (0x8E) uses two-byte IO element ids and two-byte counts, and adds a group of variable-length (NX) elements whose value is a byte string rather than a number, which is how it carries iButton lists, barcode data and similar payloads. Codec 16 (0x10) also uses two-byte ids and adds a generation type byte that says why the record was created: on change, periodically, on entering or leaving a geofence, and so on.
Each record opens with a 64-bit UTC timestamp and a priority, then the GPS block: longitude and latitude in 1e-7 degrees, altitude, heading, satellites and speed. The record then names the IO element that triggered it, followed by the IO elements themselves.
TCP and UDP framing
Over TCP the packet is a four-byte zero preamble, a four-byte data field length, the data field and a four-byte CRC-16 of that data field. The CRC covers the data field only: from the codec id to the end of the records, without the preamble, the length or the CRC itself. Including any of those in the calculation produces a mismatch on a packet that is otherwise valid.
Over UDP there is no preamble and no CRC. The datagram starts with the payload length (2 bytes), a packet id (2 bytes), a one-byte AVL packet id, a two-byte IMEI length and the IMEI in ASCII, followed by the data field. The UDP header identifies the device, so a UDP packet can arrive without the separate login that TCP uses.
The acknowledgement the server must send
A device will not treat an AVL packet as delivered until the server acknowledges it. Over TCP the acknowledgement is a four-byte big-endian count of the records the server accepted: one record is 00000001, two records are 00000002. Over UDP it is seven bytes: 0005, the packet id, 01, the AVL packet id and the accepted record count. The decoder prints the exact acknowledgement for the packet you paste.
Codec 12, 13 and 14 commands
Commands travel the other way, from the server to the device. Codec 12 carries a text command and relies on the TCP connection to identify the device. Codec 13 adds a timestamp so the device can reject stale commands. Codec 14 carries the device IMEI inside the packet, for links where the connection itself does not identify the device. The device answers with Codec 12 type 0x06 (a response) or type 0x11 (a nACK, including an IMEI that did not match).
AVL IDs and open-source code
IO element names differ between device families, so the decoder shows the raw id and value even when no name is known. The Teltonika AVL ID list gives the names, byte widths and models for each id. The decoding runs on teltonika-codec, the open-source TypeScript library we publish under the MIT licence; it is also on npm, so the same parsing can run in your own server or script.