watch

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: 10 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 watch is the text protocol of 3G / SeTracker-style children's watches and many low-cost trackers ("[SG*id*len*content]"): frame reading, decoding into track.Message, and command framing. Our own implementation from the watch "Communication Protocol" V1.7_C (3G Electronics, published on traccar.org); facts cross-checked against Traccar's decoder tests.

A frame is "[" vendor (two characters: SG, 3G, CS, ZJ, …) "*" device ID "*" [index "*"] length (four hexadecimal digits) "*" content "]". Binary content (voice) escapes "}" "[" "]" "," "*" as 0x7D followed by 0x01 to 0x05; frames are found by matching brackets, so a WiFi name holding brackets stays inside its frame. Read:

LK[,steps,rolls,battery]   link keep-alive, answered LK (the first frame is the Login)
UD, UD2 (history), UD3, UD_LTE, UD_WCDMA, WT, WG, WAD   positions, not answered
AL, AL_LTE, ALCUSTOMER…    alarm positions, answered AL
INIT, TKQ, TKQ2            answered with themselves (INIT,1)
PULSE, heart, BLOOD, bphrt, TEMP, btemp2, oxygen   health readings
anything else              the device's answer to a command, named by its keyword

A position is date (ddMMyy), time, A/V, latitude, N/S, longitude, E/W, speed, course, altitude, satellites, GSM signal (0-100), battery (%), steps, rolls, a hexadecimal status word (alarms in its high half: 16 SOS, 17 low battery, 18 out of fence, 19 into fence, 20 watch taken off; low half: 0 low battery, 1 out of fence, 2 in fence), the cells (count, timing advance, MCC, MNC, then LAC, cell ID and signal each; decimal or hexadecimal) and the WiFi access points (count, then name, MAC and RSSI each). Voice, pictures and audio parts (TK, img, JXTK) are passed over with a warning (JXTK is acknowledged).

Commands are frames with the device's vendor, ID and index form; devices that send "3G" are sent "SG", as Traccar does. Every command's answer repeats its keyword, so the codec is a strict track.Correlator. Forms: {"text": "CR"}, a named command, or {"sos": ["number", …]} (one to three SOS numbers, "SOS,a,b,c"). Useful texts: CR (locate now), UPLOAD,<seconds>, RESET, POWEROFF, SOS1,<number>, VERNO, TS.

The profile (NewCodec; Profile):

speedUnit: kmh            # kmh (default, as devices send it), mph (as the document says), knots
commandVendor: ""         # vendor written on commands; default the device's (3G → SG)
namedCommands: {interval: "UPLOAD,{seconds}"}   # replaces a named command's text

Named commands (track.Named): locate "CR", reboot "RESET", interval "UPLOAD,<seconds>" (10 to 86400 s). Watches have no engine relay.

Index

Constants

This section is empty.

Variables

View Source
var (

	// Interval bounds the interval command, in seconds.
	Interval = track.IntervalRange{Min: 10, Max: 86400}
	// NamedActions are the named commands watches have: no engine relay.
	NamedActions = []string{track.ActionLocate, track.ActionReboot, track.ActionInterval}
)

Named commands as watch protocol commands (Communication Protocol V1.7_C: CR, RESET, UPLOAD).

Functions

func Encode

func Encode(vendor, id, index string, content []byte) []byte

Encode builds a frame: vendor, ID, index ("" none), length and content.

func Escape

func Escape(b []byte) []byte

Escape escapes binary content.

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.

func Unescape

func Unescape(b []byte) []byte

Unescape reverses Escape.

Types

type Frame

type Frame struct {
	Vendor, ID string
	// Index is the frame index of devices that send one ("" none).
	Index   string
	Length  int
	Content []byte
}

Frame is a decoded frame.

func ReadFrame

func ReadFrame(r *bufio.Reader) (*Frame, error)

ReadFrame reads one frame, skipping bytes until "[" and matching brackets to its end.

type Profile

type Profile struct {
	SpeedUnit     string               `json:"speedUnit,omitempty"`
	CommandVendor string               `json:"commandVendor,omitempty"`
	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