atrack

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atrack is the ATrack (AK, AX, AT, AU and AY series) tracker protocol: frame reading, decoding into track.Message, and command framing. Our own implementation from ATrack's protocol document (revision 1.3.6); facts cross-checked against Traccar's decoder tests.

A device sends position packets in one of two forms, chosen with its AT$FORM command, each starting with a two-character prefix ("@P" by default; any two bytes but 0x0D0A, 0xFE02 and 0x00):

binary:  prefix, CRC (2), length (2), sequence (2), unit ID (8), records
ASCII:   prefix,CRC,length,sequence,unit ID,record CR LF [record CR LF …]

The CRC is CRC-16/ARC: over length..end in binary, and from the comma before the length to the end in ASCII. The length counts from the sequence (binary) or the comma after the length (ASCII) to the end. A binary packet with a bad CRC is dropped; an ASCII one is read with a warning, since some firmware's ASCII CRC does not follow that rule. The unit ID is the IMEI unless set otherwise with AT$UNID. A record holds GPS, RTC and sending times (Unix seconds, or year..second when AT$FORM's time format is 1: told apart by the year), longitude and latitude in millionths of a degree, heading, report ID, odometer (0.1 km), HDOP (0.1), inputs, speed (km/h), outputs, analogue input (mV), driver ID, two temperatures (0.1 °C; 2000 when no sensor), a text message, and the custom fields AT$FORM appends. When those start with %CI the record names its own layout; otherwise set profile.form to the device's.

Every position packet and keep-alive (0xFE02, unit ID, sequence) is answered with 0xFE02, the unit ID and the sequence. The first packet of a connection is its Login (the protocol has no login of its own).

Commands are text lines "AT$<command>[+tag]=[password,]<parameters>" ending CR LF. Answers are "$OK", "$ERROR=<code>" or, to a query, "$<command>=<values>", each repeating the tag. Command adds the sequence as tag (at most five digits) and the codec is a track.Correlator, so an answer completes the command whose tag it repeats (an untagged answer, from firmware that drops tags, is taken too). AT$GPOS is answered with a position report, not text, so it expects no answer.

The profile (NewCodec; Profile):

checkCrc: true            # default true; false accepts packets with a bad CRC
form: "%MV%BV%SA"         # the AT$FORM custom fields, when records do not carry %CI
alarms: {"101": emergency}   # report ID → alert type (user reports 101..164 mean what AT$REPT made them)
commandTag: true          # default true; false sends commands without a tag
commandPassword: "1234"   # AT$PASS password, put before the parameters of named commands
namedCommands: {engineStop: "AT$OUTC=2,1"}   # replaces a named command's text

Named commands (track.Named): engineStop "AT$OUTC=1,1" and engineResume "AT$OUTC=1,0" (digital output 1 on and off: wire the relay there or change the output), locate "AT$GPOS", reboot "AT$REST=1,0", interval "AT$TRAC=1,<seconds>" (time mode, 1 to 65535 s).

Index

Constants

This section is empty.

Variables

View Source
var (

	// Interval bounds the interval command, in seconds (AT$TRAC's time is
	// a 16-bit count of seconds).
	Interval = track.IntervalRange{Min: 1, Max: 65535}
	// NamedActions are the named commands ATrack has: all of them.
	NamedActions = track.Actions
)

Named commands as ATrack AT commands (protocol document 1.3.6: AT$OUTC, AT$GPOS, AT$REST, AT$TRAC).

View Source
var ErrCRC = errors.New("atrack: CRC mismatch")

ErrCRC is a packet whose CRC does not match.

Functions

func ASCIIFrame

func ASCIIFrame(prefix, body string) string

ASCIIFrame frames an ASCII packet: body is "<sequence>,<unit ID>,<record>\r\n…"; the result is "<prefix>,<CRC>,<length>,<body>".

func Ack

func Ack(unit uint64, seq uint16) []byte

Ack is the server's answer to a position packet or keep-alive: 0xFE02, the unit ID and the sequence (the device's keep-alive has the same form).

func BinaryFrame

func BinaryFrame(prefix string, seq uint16, unit uint64, records []byte) []byte

BinaryFrame frames binary records: prefix (two characters), CRC, length, sequence, unit ID and the records as they are.

func NewCodec

func NewCodec(raw json.RawMessage) (func() track.Codec, error)

NewCodec validates a profile (empty for the defaults) and returns a factory of codecs, one per connection.

Types

type Profile

type Profile struct {
	// CheckCRC (default true) drops packets whose CRC does not match.
	CheckCRC *bool `json:"checkCrc,omitempty"`
	// Form is the device's AT$FORM custom-information string ("%MV%BV"),
	// for records that do not carry it themselves (no %CI).
	Form string `json:"form,omitempty"`
	// Alarms maps report IDs to alert types.
	Alarms map[string]string `json:"alarms,omitempty"`
	// CommandTag (default true) tags each command with its sequence.
	CommandTag *bool `json:"commandTag,omitempty"`
	// CommandPassword is the AT$PASS password for named commands.
	CommandPassword string `json:"commandPassword,omitempty"`
	// NamedCommands replaces the text of a named command; placeholders
	// {seconds}, {password} and {imei}; "" turns one off.
	NamedCommands track.NamedTemplates `json:"namedCommands,omitempty"`
}

Profile is the manufacturer-variation settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL