Skip to main content

Crate gt06

Crate gt06 

Source
Expand description

Parser and stream decoder for the GT06 GPS tracker protocol.

GT06 is used by a large family of low-cost GPS trackers to report location, status and alarm events over a raw TCP connection.

Use Decoder to reassemble Messages out of a raw byte stream — it buffers partial reads, so it’s safe to feed it directly from a socket. Use parse_packet instead if you already have one complete, framed packet.

Login and status messages expect an acknowledgement written back to the device; check Message::ack_bytes after parsing.

use gt06::{Decoder, Message};

let mut decoder = Decoder::new();
for result in decoder.push(&raw_bytes_from_socket) {
    match result {
        Ok(message) => {
            if let Message::Login(login) = &message {
                println!("device {} connected", login.imei);
            }
            if let Some(ack) = message.ack_bytes() {
                // socket.write_all(&ack)?;
                assert_eq!(ack[3], 0x01);
            }
        }
        Err(err) => eprintln!("bad packet: {err}"),
    }
}

Structs§

Alarm
Alarm message (protocol 0x16): a location fix plus terminal/alarm state.
AlarmTerminalInfo
Terminal info bits carried in an alarm (0x16) message. Same byte layout as StatusFlags, but the protocol documentation names these bits differently for alarm messages.
Decoder
Buffers raw bytes from a GT06 connection and reassembles them into parsed messages, tracking the IMEI seen on a prior login so it can be backfilled onto later location/status/alarm messages on the same connection.
Fix
GPS fix data shared by location (0x12/0x22) and alarm (0x16) messages.
Location
Location message (protocol 0x12, or 0x22 when Location::extended is set).
Login
Login message (protocol 0x01). The device sends this once per connection to identify itself; the server must ack it.
Status
Status message (protocol 0x13). Devices send this periodically as a heartbeat; the server must ack it.
StatusFlags
Terminal info bits carried in a status (0x13) message.

Enums§

AlarmEvent
Top-level alarm event carried in an alarm (0x16) message. Distinct from TerminalAlarm, which is a different bitfield in the same message.
Error
Errors that can occur while parsing a GT06 packet.
GsmSignal
Language
Message
A single parsed GT06 message.
TerminalAlarm
Alarm condition encoded in terminal info bits 3-5.
VoltageLevel

Functions§

build_ack
Builds the 10-byte ack packet for the given protocol number and serial.
parse_packet
Parses one complete, framed GT06 packet (including the 0x7878 start marker and 0x0d0a end marker) into a Message.