1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! 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 [`Message`]s 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 raw_bytes_from_socket: [u8; 18] = [
//! # 0x78, 0x78, 0x0d, 0x01, 0x03, 0x56, 0x93, 0x80, 0x35, 0x64, 0x38, 0x09,
//! # 0x00, 0x01, 0x91, 0x1f, 0x0d, 0x0a,
//! # ];
//! 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}"),
//! }
//! }
//! ```
pub use Error;
pub use Decoder;
pub use *;
pub use parse_packet;
pub use build_ack;