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. - Alarm
Terminal Info - Terminal info bits carried in an alarm (
0x16) message. Same byte layout asStatusFlags, 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, or0x22whenLocation::extendedis 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. - Status
Flags - Terminal info bits carried in a status (
0x13) message.
Enums§
- Alarm
Event - Top-level alarm event carried in an alarm (
0x16) message. Distinct fromTerminalAlarm, 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.
- Terminal
Alarm - Alarm condition encoded in terminal info bits 3-5.
- Voltage
Level
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
0x7878start marker and0x0d0aend marker) into aMessage.