











{"author":"Faiq Najib Al-Aziz","body":"\nIn [Part 2](/en/writing/2026/tcp-listener-gps-go/), we built a listener that assembles incoming TCP streams into complete frames. Now it's time to read what's inside. Bytes like `0x78 0x78 0x0D 0x01 ...` need to become useful information, such as `IMEI 123456789012345, position -7.2575, 112.7521, heading 180°`.\n\nWhile writing this article, I was convinced that the GT06 datasheet's login packet example was `... 6C 00 01 8C ...` and that its CRC could use standard CRC-CCITT. **Both were wrong**, hahaha. I only realized it when my own code rejected the datasheet's example. Lesson: with binary protocols, trust test vectors over your memory.\n\nWe'll pick GT06 apart first, then look at Teltonika and where its design differs. All code below has been checked against official examples from the Concox GT06 v1.8.1 datasheet and the decoder structure of [Traccar](https://www.traccar.org/)[^traccar], an open-source engine that has been used in production for years.\n\n## Trap #1: GT06's \"CRC-ITU\" Isn't the CRC-CCITT You Think It Is\n\nThe GT06 datasheet just says that the CRC field contains a *CRC-ITU value*. The most common reference for CRC-ITU is CRC-16/CCITT using polynomial 0x1021. And here's the trap: more than a dozen CRC variants share that polynomial, differing in initial value (*init*), processing direction (*reflected*), and final XOR mask (*xor-out*).\n\nI brute-forced all common 0x1021 variants against the official datasheet sample, a login packet `78 78 0D 01 01 23 45 67 89 01 23 45 00 01 8C DD 0D 0A`, whose CRC is listed as `0x8CDD`:\n\n| Variant (poly 0x1021) | Init   | Reflected | XOR out    | Result          |\n| --------------------- | ------ | --------- | ---------- | --------------- |\n| CCITT-FALSE           | 0xFFFF | no        | 0x0000     | `0x81F6` ❌     |\n| XMODEM                | 0x0000 | no        | 0x0000     | `0x55F9` ❌     |\n| X25                   | 0xFFFF | **yes**   | **0xFFFF** | **`0x8CDD` ✅** |\n\nThe answer is **the X25 variant**, processed *reflected* with a final XOR of `0xFFFF`. The CRC scope doesn't start at the protocol number either. It spans **from the length byte up through the serial number (inclusive)**, matching the WD-209 datasheet wording: *\"from packet length to information serial number (including)\"*.\n\nHere is the implementation in Go:\n\n```go\n// crcITU = GT06's \"CRC-ITU\": CRC-16/X25 variant\n// (poly 0x1021, init 0xFFFF, reflected, xor-out 0xFFFF).\n// Scope: from packet LENGTH byte to SERIAL byte (inclusive).\nfunc crcITU(data []byte) uint16 {\n    crc := uint16(0xFFFF)\n    for _, b := range data {\n        crc ^= uint16(b)\n        for i := 0; i \u003c 8; i++ {\n            if crc\u00261 != 0 {\n                crc = (crc \u003e\u003e 1) ^ 0x8408 // reflected version of 0x1021\n            } else {\n                crc \u003e\u003e= 1\n            }\n        }\n    }\n    return crc ^ 0xFFFF\n}\n```\n\nIn production, Traccar (the most widely deployed open-source GPS tracking server) **does not validate inbound CRCs for GT06**. The market is full of GT06 clones and OEM variants with slightly different CRC calculations. Here we still validate the CRC and drop corrupt packets as the datasheet recommends. The catch: some cloned devices with quirky CRCs may get rejected too.\n\n## Frame Parser with CRC Validation\n\nExtending `readFrame` from Part 2, let's unpack an intact frame:\n\n```go\ntype GT06Frame struct {\n    Protocol byte\n    Data     []byte   // payload content\n    Serial   uint16   // used for ACK matching\n}\n\nfunc parseGT06(frame []byte) (*GT06Frame, error) {\n    if len(frame) \u003c 9 || frame[0] != 0x78 || frame[1] != 0x78 {\n        return nil, fmt.Errorf(\"not a GT06 frame\")\n    }\n    length := int(frame[2])\n    body := frame[2 : 3+length] // length..crc: CRC calculation scope!\n\n    got := binary.BigEndian.Uint16(body[len(body)-2:])\n    want := crcITU(body[:len(body)-2])\n    if got != want {\n        return nil, fmt.Errorf(\"CRC mismatch: packet=0x%04X calculated=0x%04X\", got, want)\n    }\n\n    return \u0026GT06Frame{\n        Protocol: body[1],\n        Data:     body[2 : len(body)-4],\n        Serial:   binary.BigEndian.Uint16(body[len(body)-4 : len(body)-2]),\n    }, nil\n}\n```\n\nThe first test that must pass: the datasheet login example has to pass validation, and our recalculated CRC must match exactly: `0x8CDD`.\n\n## Login: BCD IMEI and Mandatory ACK Responses\n\nThe login packet (protocol `0x01`) stores the **IMEI in BCD format**: 8 bytes storing 16 decimal digits, even though an IMEI is only 15 digits long. The first digit is simply a leading `0` padding that needs to be stripped:\n\n```go\n// IMEI: 8 bytes BCD -\u003e 16 hex digits -\u003e drop first digit -\u003e 15 digits\nfunc decodeIMEI(data []byte) string {\n    return fmt.Sprintf(\"%X\", data)[1:]\n}\n```\n\nDatasheet example: `01 23 45 67 89 01 23 45` -\u003e `\"0123456789012345\"` -\u003e IMEI `123456789012345`.\n\nOnce the IMEI is decoded, we have to reply. As noted in Part 1: a device that isn't acknowledged will keep retransmitting until it sulks. The login ACK packet format is `78 78 05 \u003cprotocol\u003e \u003cserial\u003e \u003ccrc\u003e 0D 0A`:\n\n```go\n// buildAck: 78 78 05 \u003cprotocol\u003e \u003cserial\u003e \u003ccrc\u003e 0D 0A\n// CRC is computed from length byte (05) up to serial number.\nfunc buildAck(f *GT06Frame) []byte {\n    body := []byte{0x05, f.Protocol, byte(f.Serial \u003e\u003e 8), byte(f.Serial)}\n    crc := crcITU(body)\n    out := []byte{0x78, 0x78}\n    out = append(out, body...)\n    out = append(out, byte(crc\u003e\u003e8), byte(crc), 0x0D, 0x0A)\n    return out\n}\n```\n\nThe test vector: for serial `0001`, the correct response is `78 78 05 01 00 01 D9 DC 0D 0A`, and our implementation above produces exactly that. (`D9 DC` comes from CRC X25 over `05 01 00 01`, so the length byte is part of the CRC scope.)\n\n## Location: Converting Raw Bytes into Coordinates\n\nThe most common position packet uses protocol `0x12`. Here is the GPS payload breakdown:\n\n| Offset | Size | Field          | Notes                                     |\n| ------ | ---- | -------------- | ----------------------------------------- |\n| +0     | 6    | Datetime       | BCD: YY MM DD HH MM SS                    |\n| +6     | 1    | Satellites     | low nibble only                           |\n| +7     | 4    | Latitude       | big-endian, unit in **minutes × 30,000**  |\n| +11    | 4    | Longitude      | big-endian, unit in minutes × 30,000      |\n| +15    | 1    | Speed          | km/h                                      |\n| +16    | 2    | Course + flags | see breakdown below                       |\n\nTwo things that are easy to miss:\n\n1. **Coordinates are not decimal degrees.** The raw integer value must be divided by `60 × 30,000 = 1,800,000`. For instance, Surabaya at -7.2575° is stored as `7.2575 × 60 × 30,000 = 13,063,500` -\u003e `00 C7 55 4C`.\n2. **Hemisphere signs (south/west) are not stored in the numbers**, all coordinate values are positive. The signs live in the *flags* bits within the course bytes.\n\nFlag layout (2 bytes): bit 0-9 = heading (0-359°), bit 10 = latitude direction (**1 = north/positive, 0 = south/negative**), bit 11 = longitude direction (**1 = west/negative**), bit 12 = GPS fix valid. (I took these bit assignments from Traccar's production-tested decoder, since datasheet wording varies between revisions. Once again: verify with real hardware.)\n\n```go\nfunc decodeLocation(data []byte, tz *time.Location) Location {\n    t := time.Date(\n        bcd(data[0])+2000, time.Month(bcd(data[1])), bcd(data[2]),\n        bcd(data[3]), bcd(data[4]), bcd(data[5]), 0, tz)\n\n    sat := int(data[6] \u0026 0x0F)\n    lat := float64(binary.BigEndian.Uint32(data[7:11])) / 60.0 / 30000.0\n    lng := float64(binary.BigEndian.Uint32(data[11:15])) / 60.0 / 30000.0\n    speed := int(data[15])\n\n    flags := binary.BigEndian.Uint16(data[16:18])\n    course := int(flags \u0026 0x3FF)\n    if flags\u0026(1\u003c\u003c10) == 0 { // bit 10: 0 = South\n        lat = -lat\n    }\n    if flags\u0026(1\u003c\u003c11) != 0 { // bit 11: 1 = West\n        lng = -lng\n    }\n    valid := flags\u0026(1\u003c\u003c12) != 0\n\n    return Location{t, sat, lat, lng, speed, course, valid}\n}\n\nfunc bcd(b byte) int { return int(b\u003e\u003e4)*10 + int(b\u00260x0F) }\n```\n\nHow to test the decoder without physical hardware: I constructed a synthetic `0x12` packet in the tests (Surabaya, 12 satellites, 42 km/h, heading 180°, valid fix) and decoded it back. The output was `-7.2575, 112.7521, heading 180, valid fix`. The full byte stream is `78 78 17 12 26 09 12 14 30 00 0C 00 C7 55 4C 0C 18 D4 34 2A 10 B4 00 01 00 A2 0D 0A`, which you can replay directly over `/dev/tcp` as shown in Part 2.\n\n\u003e Note: following the GPS block, a real `0x12` packet contains cellular base station (LBS) data for positioning fallback when GPS fix is lost, alongside terminal status info. We can parse that later if needed. For building core tracking, the GPS segment is all we need.\n\n## Teltonika: A Different Packet Design\n\nTeltonika covers the same needs with a different packet format and flow. The differences show up in its handshake, data batches, coordinates, and acknowledgements:\n\n**1. Handshake first, data later.** A new connection begins with an identification packet: 2 bytes of length (`00 0F`) + 15 ASCII digits of IMEI + `\\r\\n`. The server responds with a single byte: `01` (IMEI accepted) or `00` (rejected):\n\n```go\nfunc decodeIMEITeltonika(b []byte) (string, bool) {\n    n := int(binary.BigEndian.Uint16(b[0:2]))\n    if n != 15 || len(b) \u003c 2+n {\n        return \"\", false\n    }\n    imei := string(b[2 : 2+n])\n    for _, c := range imei {\n        if c \u003c '0' || c \u003e '9' {\n            return \"\", false\n        }\n    }\n    return imei, true // reply: 0x01 = accept, 0x00 = reject\n}\n```\n\n**2. Batches instead of one-by-one.** A single AVL packet carries multiple records at once. Here is the Codec 8 structure:\n\n```text\n00 00 00 00        preamble (4 zero bytes)\n00 00 00 39        data length (4 bytes: codec ID up to num2)\n08                 codec ID (0x08 = codec8)\n01                 number of records\n... AVL record ... (timestamp 8B, priority 1B, GPS element, IO elements)\n01                 number of records (repeated, for validation)\n00 00 0X XX        CRC-16 (4 bytes, 16-bit value in lower bytes)\n```\n\n**3. Degrees × 10,000,000, straight.** No minutes/30,000 gymnastics: longitude and latitude are signed 4-byte big-endian integers. Divide by 10,000,000 and you get plain decimal degrees. A single record's GPS element contains: longitude (4B), latitude (4B), altitude (2B), angle (2B), satellites (1B), and speed (2B).\n\n**4. CRC-16 IBM** (poly 0x8005, init 0, reflected: the CRC-16/ARC variant), calculated from the codec ID through *number of data 2*:\n\n```go\nfunc crc16IBM(data []byte) uint16 {\n    crc := uint16(0x0000)\n    for _, b := range data {\n        crc ^= uint16(b)\n        for i := 0; i \u003c 8; i++ {\n            if crc\u00261 != 0 {\n                crc = (crc \u003e\u003e 1) ^ 0xA001\n            } else {\n                crc \u003e\u003e= 1\n            }\n        }\n    }\n    return crc\n}\n```\n\nTo confirm receipt, the server replies with the **count of records received** as a 4-byte integer. For one record, it returns `00 00 00 01`. The device retransmits if the count does not match, so per-packet serial numbers are not needed.\n\n## Test Results\n\nAll code in this article passes 13 targeted assertions[^tests]:\n\n| Scenario                                                                | Result |\n| ----------------------------------------------------------------------- | ------ |\n| GT06 datasheet login packet (`8C DD`) passes CRC validation             | ✓      |\n| Recalculated CRC = `8CDD`; serial 1 ACK = `D9 DC`                       | ✓      |\n| BCD IMEI -\u003e `123456789012345` (15 digits)                               | ✓      |\n| Round-trip location 0x12: coordinates, course, speed, satellites, time  | ✓      |\n| Teltonika handshake with `356307042441013`                              | ✓      |\n| AVL Codec 8: valid CRC, correct coordinates \u0026 speed                     | ✓      |\n\n## Notes for Testing\n\n- **Verify the CRC variant and scope against a datasheet vector.** In GT06, both decide whether validation passes.\n- **Test IMEI decoding and the ACK against a login example.** Check the BCD result and response bytes against the packet serial.\n- **Use a round-trip test for coordinate conversion.** GT06 uses minutes × 30,000, Teltonika uses degrees × 10⁷.\n- **Decide your stance on CRC validation.** Traccar skips inbound CRC validation for GT06 and Teltonika because of firmware clones. Decide for yourself whether a mismatch gets dropped or just logged.\n\nNext up is storing the decoded positions. If 500 trackers report every 10 seconds, that's 4.3 million points per day. A plain PostgreSQL table will struggle without optimization, so Part 4 looks at TimescaleDB.\n\n## What's Next\n\nThis post is part of the **Building a GPS Tracking Backend from Scratch** series.\n\n- Previous: [Part 2 - Building a High-Throughput GPS TCP Listener in Go](/en/writing/2026/tcp-listener-gps-go/)\n- Next: [Part 4 - Storing High-Throughput GPS Data with PostgreSQL and TimescaleDB](/en/writing/2026/gps-data-postgresql-timescaledb/)\n\nIf you get different results when testing GT06 or Teltonika packets, let's talk via [Contact](/en/contact/). Subscribe via [RSS](/en/writing/index.xml) to catch the next article.\n\n[^traccar]: Traccar's decoder source code for [GT06](https://github.com/traccar/traccar/blob/master/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java) and [Teltonika](https://github.com/traccar/traccar/blob/master/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java) is a gold standard for production-tested behavior. I used it to cross-verify field layouts and unit scaling factors.\n\n[^tests]: The Concox GT06 v1.8.1 datasheet example (login and ACK) was used as an external test vector. Location packets and AVL records were validated via round-trip encoding and decoding with manually confirmed coordinates for Surabaya.\n","body_clean":"In Part 2, we built a listener that assembles incoming TCP streams into complete frames. Now it\u0026rsquo;s time to read what\u0026rsquo;s inside. Bytes like 0x78 0x78 0x0D 0x01 ... need to become useful information, such as IMEI 123456789012345, position -7.2575, 112.7521, heading 180°.\nWhile writing this article, I was convinced that the GT06 datasheet\u0026rsquo;s login packet example was ... 6C 00 01 8C ... and that its CRC could use standard CRC-CCITT. Both were wrong, hahaha. I only realized it when my own code rejected the datasheet\u0026rsquo;s example. Lesson: with binary protocols, trust test vectors over your memory.\nWe\u0026rsquo;ll pick GT06 apart first, then look at Teltonika and where its design differs. All code below has been checked against official examples from the Concox GT06 v1.8.1 datasheet and the decoder structure of Traccar1, an open-source engine that has been used in production for years.\nTrap #1: GT06\u0026rsquo;s \u0026ldquo;CRC-ITU\u0026rdquo; Isn\u0026rsquo;t the CRC-CCITT You Think It Is #The GT06 datasheet just says that the CRC field contains a CRC-ITU value. The most common reference for CRC-ITU is CRC-16/CCITT using polynomial 0x1021. And here\u0026rsquo;s the trap: more than a dozen CRC variants share that polynomial, differing in initial value (init), processing direction (reflected), and final XOR mask (xor-out).\nI brute-forced all common 0x1021 variants against the official datasheet sample, a login packet 78 78 0D 01 01 23 45 67 89 01 23 45 00 01 8C DD 0D 0A, whose CRC is listed as 0x8CDD:\nVariant (poly 0x1021) Init Reflected XOR out Result CCITT-FALSE 0xFFFF no 0x0000 0x81F6 ❌ XMODEM 0x0000 no 0x0000 0x55F9 ❌ X25 0xFFFF yes 0xFFFF 0x8CDD ✅ The answer is the X25 variant, processed reflected with a final XOR of 0xFFFF. The CRC scope doesn\u0026rsquo;t start at the protocol number either. It spans from the length byte up through the serial number (inclusive), matching the WD-209 datasheet wording: \u0026ldquo;from packet length to information serial number (including)\u0026rdquo;.\nHere is the implementation in Go:\n// crcITU = GT06\u0026#39;s \u0026#34;CRC-ITU\u0026#34;: CRC-16/X25 variant // (poly 0x1021, init 0xFFFF, reflected, xor-out 0xFFFF). // Scope: from packet LENGTH byte to SERIAL byte (inclusive). func crcITU(data []byte) uint16 { crc := uint16(0xFFFF) for _, b := range data { crc ^= uint16(b) for i := 0; i \u0026lt; 8; i++ { if crc\u0026amp;1 != 0 { crc = (crc \u0026gt;\u0026gt; 1) ^ 0x8408 // reflected version of 0x1021 } else { crc \u0026gt;\u0026gt;= 1 } } } return crc ^ 0xFFFF } In production, Traccar (the most widely deployed open-source GPS tracking server) does not validate inbound CRCs for GT06. The market is full of GT06 clones and OEM variants with slightly different CRC calculations. Here we still validate the CRC and drop corrupt packets as the datasheet recommends. The catch: some cloned devices with quirky CRCs may get rejected too.\nFrame Parser with CRC Validation #Extending readFrame from Part 2, let\u0026rsquo;s unpack an intact frame:\ntype GT06Frame struct { Protocol byte Data []byte // payload content Serial uint16 // used for ACK matching } func parseGT06(frame []byte) (*GT06Frame, error) { if len(frame) \u0026lt; 9 || frame[0] != 0x78 || frame[1] != 0x78 { return nil, fmt.Errorf(\u0026#34;not a GT06 frame\u0026#34;) } length := int(frame[2]) body := frame[2 : 3+length] // length..crc: CRC calculation scope! got := binary.BigEndian.Uint16(body[len(body)-2:]) want := crcITU(body[:len(body)-2]) if got != want { return nil, fmt.Errorf(\u0026#34;CRC mismatch: packet=0x%04X calculated=0x%04X\u0026#34;, got, want) } return \u0026amp;GT06Frame{ Protocol: body[1], Data: body[2 : len(body)-4], Serial: binary.BigEndian.Uint16(body[len(body)-4 : len(body)-2]), }, nil } The first test that must pass: the datasheet login example has to pass validation, and our recalculated CRC must match exactly: 0x8CDD.\nLogin: BCD IMEI and Mandatory ACK Responses #The login packet (protocol 0x01) stores the IMEI in BCD format: 8 bytes storing 16 decimal digits, even though an IMEI is only 15 digits long. The first digit is simply a leading 0 padding that needs to be stripped:\n// IMEI: 8 bytes BCD -\u0026gt; 16 hex digits -\u0026gt; drop first digit -\u0026gt; 15 digits func decodeIMEI(data []byte) string { return fmt.Sprintf(\u0026#34;%X\u0026#34;, data)[1:] } Datasheet example: 01 23 45 67 89 01 23 45 -\u0026gt; \u0026quot;0123456789012345\u0026quot; -\u0026gt; IMEI 123456789012345.\nOnce the IMEI is decoded, we have to reply. As noted in Part 1: a device that isn\u0026rsquo;t acknowledged will keep retransmitting until it sulks. The login ACK packet format is 78 78 05 \u0026lt;protocol\u0026gt; \u0026lt;serial\u0026gt; \u0026lt;crc\u0026gt; 0D 0A:\n// buildAck: 78 78 05 \u0026lt;protocol\u0026gt; \u0026lt;serial\u0026gt; \u0026lt;crc\u0026gt; 0D 0A // CRC is computed from length byte (05) up to serial number. func buildAck(f *GT06Frame) []byte { body := []byte{0x05, f.Protocol, byte(f.Serial \u0026gt;\u0026gt; 8), byte(f.Serial)} crc := crcITU(body) out := []byte{0x78, 0x78} out = append(out, body...) out = append(out, byte(crc\u0026gt;\u0026gt;8), byte(crc), 0x0D, 0x0A) return out } The test vector: for serial 0001, the correct response is 78 78 05 01 00 01 D9 DC 0D 0A, and our implementation above produces exactly that. (D9 DC comes from CRC X25 over 05 01 00 01, so the length byte is part of the CRC scope.)\nLocation: Converting Raw Bytes into Coordinates #The most common position packet uses protocol 0x12. Here is the GPS payload breakdown:\nOffset Size Field Notes +0 6 Datetime BCD: YY MM DD HH MM SS +6 1 Satellites low nibble only +7 4 Latitude big-endian, unit in minutes × 30,000 +11 4 Longitude big-endian, unit in minutes × 30,000 +15 1 Speed km/h +16 2 Course + flags see breakdown below Two things that are easy to miss:\nCoordinates are not decimal degrees. The raw integer value must be divided by 60 × 30,000 = 1,800,000. For instance, Surabaya at -7.2575° is stored as 7.2575 × 60 × 30,000 = 13,063,500 -\u0026gt; 00 C7 55 4C. Hemisphere signs (south/west) are not stored in the numbers, all coordinate values are positive. The signs live in the flags bits within the course bytes. Flag layout (2 bytes): bit 0-9 = heading (0-359°), bit 10 = latitude direction (1 = north/positive, 0 = south/negative), bit 11 = longitude direction (1 = west/negative), bit 12 = GPS fix valid. (I took these bit assignments from Traccar\u0026rsquo;s production-tested decoder, since datasheet wording varies between revisions. Once again: verify with real hardware.)\nfunc decodeLocation(data []byte, tz *time.Location) Location { t := time.Date( bcd(data[0])+2000, time.Month(bcd(data[1])), bcd(data[2]), bcd(data[3]), bcd(data[4]), bcd(data[5]), 0, tz) sat := int(data[6] \u0026amp; 0x0F) lat := float64(binary.BigEndian.Uint32(data[7:11])) / 60.0 / 30000.0 lng := float64(binary.BigEndian.Uint32(data[11:15])) / 60.0 / 30000.0 speed := int(data[15]) flags := binary.BigEndian.Uint16(data[16:18]) course := int(flags \u0026amp; 0x3FF) if flags\u0026amp;(1\u0026lt;\u0026lt;10) == 0 { // bit 10: 0 = South lat = -lat } if flags\u0026amp;(1\u0026lt;\u0026lt;11) != 0 { // bit 11: 1 = West lng = -lng } valid := flags\u0026amp;(1\u0026lt;\u0026lt;12) != 0 return Location{t, sat, lat, lng, speed, course, valid} } func bcd(b byte) int { return int(b\u0026gt;\u0026gt;4)*10 + int(b\u0026amp;0x0F) } How to test the decoder without physical hardware: I constructed a synthetic 0x12 packet in the tests (Surabaya, 12 satellites, 42 km/h, heading 180°, valid fix) and decoded it back. The output was -7.2575, 112.7521, heading 180, valid fix. The full byte stream is 78 78 17 12 26 09 12 14 30 00 0C 00 C7 55 4C 0C 18 D4 34 2A 10 B4 00 01 00 A2 0D 0A, which you can replay directly over /dev/tcp as shown in Part 2.\nNote: following the GPS block, a real 0x12 packet contains cellular base station (LBS) data for positioning fallback when GPS fix is lost, alongside terminal status info. We can parse that later if needed. For building core tracking, the GPS segment is all we need.\nTeltonika: A Different Packet Design #Teltonika covers the same needs with a different packet format and flow. The differences show up in its handshake, data batches, coordinates, and acknowledgements:\n1. Handshake first, data later. A new connection begins with an identification packet: 2 bytes of length (00 0F) + 15 ASCII digits of IMEI + \\r\\n. The server responds with a single byte: 01 (IMEI accepted) or 00 (rejected):\nfunc decodeIMEITeltonika(b []byte) (string, bool) { n := int(binary.BigEndian.Uint16(b[0:2])) if n != 15 || len(b) \u0026lt; 2+n { return \u0026#34;\u0026#34;, false } imei := string(b[2 : 2+n]) for _, c := range imei { if c \u0026lt; \u0026#39;0\u0026#39; || c \u0026gt; \u0026#39;9\u0026#39; { return \u0026#34;\u0026#34;, false } } return imei, true // reply: 0x01 = accept, 0x00 = reject } 2. Batches instead of one-by-one. A single AVL packet carries multiple records at once. Here is the Codec 8 structure:\n00 00 00 00 preamble (4 zero bytes) 00 00 00 39 data length (4 bytes: codec ID up to num2) 08 codec ID (0x08 = codec8) 01 number of records ... AVL record ... (timestamp 8B, priority 1B, GPS element, IO elements) 01 number of records (repeated, for validation) 00 00 0X XX CRC-16 (4 bytes, 16-bit value in lower bytes) 3. Degrees × 10,000,000, straight. No minutes/30,000 gymnastics: longitude and latitude are signed 4-byte big-endian integers. Divide by 10,000,000 and you get plain decimal degrees. A single record\u0026rsquo;s GPS element contains: longitude (4B), latitude (4B), altitude (2B), angle (2B), satellites (1B), and speed (2B).\n4. CRC-16 IBM (poly 0x8005, init 0, reflected: the CRC-16/ARC variant), calculated from the codec ID through number of data 2:\nfunc crc16IBM(data []byte) uint16 { crc := uint16(0x0000) for _, b := range data { crc ^= uint16(b) for i := 0; i \u0026lt; 8; i++ { if crc\u0026amp;1 != 0 { crc = (crc \u0026gt;\u0026gt; 1) ^ 0xA001 } else { crc \u0026gt;\u0026gt;= 1 } } } return crc } To confirm receipt, the server replies with the count of records received as a 4-byte integer. For one record, it returns 00 00 00 01. The device retransmits if the count does not match, so per-packet serial numbers are not needed.\nTest Results #All code in this article passes 13 targeted assertions2:\nScenario Result GT06 datasheet login packet (8C DD) passes CRC validation ✓ Recalculated CRC = 8CDD; serial 1 ACK = D9 DC ✓ BCD IMEI -\u0026gt; 123456789012345 (15 digits) ✓ Round-trip location 0x12: coordinates, course, speed, satellites, time ✓ Teltonika handshake with 356307042441013 ✓ AVL Codec 8: valid CRC, correct coordinates \u0026amp; speed ✓ Notes for Testing # Verify the CRC variant and scope against a datasheet vector. In GT06, both decide whether validation passes. Test IMEI decoding and the ACK against a login example. Check the BCD result and response bytes against the packet serial. Use a round-trip test for coordinate conversion. GT06 uses minutes × 30,000, Teltonika uses degrees × 10⁷. Decide your stance on CRC validation. Traccar skips inbound CRC validation for GT06 and Teltonika because of firmware clones. Decide for yourself whether a mismatch gets dropped or just logged. Next up is storing the decoded positions. If 500 trackers report every 10 seconds, that\u0026rsquo;s 4.3 million points per day. A plain PostgreSQL table will struggle without optimization, so Part 4 looks at TimescaleDB.\nWhat\u0026rsquo;s Next #This post is part of the Building a GPS Tracking Backend from Scratch series.\nPrevious: Part 2 - Building a High-Throughput GPS TCP Listener in Go Next: Part 4 - Storing High-Throughput GPS Data with PostgreSQL and TimescaleDB If you get different results when testing GT06 or Teltonika packets, let\u0026rsquo;s talk via Contact. Subscribe via RSS to catch the next article.\nTraccar\u0026rsquo;s decoder source code for GT06 and Teltonika is a gold standard for production-tested behavior. I used it to cross-verify field layouts and unit scaling factors.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\nThe Concox GT06 v1.8.1 datasheet example (login and ACK) was used as an external test vector. Location packets and AVL records were validated via round-trip encoding and decoding with manually confirmed coordinates for Surabaya.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\n","canonical":"https://najib.id/en/writing/2026/decode-packet-gt06-teltonika/","description":"Parsing binary GPS tracker packets in Go: why GT06's CRC-ITU isn't standard CCITT, decoding BCD IMEIs, extracting coordinates, and Teltonika AVL structures, all verified against datasheets.","language":"en","lastmod":"2026-11-11T23:31:00Z","publishedAt":"2026-10-14T00:00:00Z","readingTime":10,"section":"writing","series":"gps-backend-series","tags":["golang","gps","protocol","binary"],"title":"Decoding Packets: GT06 \u0026 Teltonika Protocols","type":"writing","url":"https://najib.id/en/writing/2026/decode-packet-gt06-teltonika/","wordCount":1931}
