Documentation
¶
Overview ¶
Package calamp is CalAmp's LM Direct protocol of the LMU vehicle units over UDP: datagram decoding into track.Message, the acknowledgement the server owes, and user data commands correlated with the unit's acknowledgement. The codec is a track.DatagramCodec and a track.DatagramCommander; LM Direct has no stream framing here, so Decode (TCP) refuses.
A datagram is an optional options header, then the message header and the message:
options 0x80|flags, then for each flag set a length byte and that
many bytes: bit 0 mobile ID (BCD digits padded with F), bit 1
mobile ID type, bit 2 authentication, bit 3 routing, bit 4
forwarding, bit 5 response redirection
header service type (0 unacknowledged, 1 acknowledged, 2 a response),
message type, 2-byte sequence number
The mobile ID becomes Message.IMEI ("" without an options header: the server then knows the unit by its address). A message with service type 1 is acknowledged with service 2, type 1, its sequence number, its type, ACK code 0, a spare byte and a 3-byte application version (zero): Message.Reply.
Messages read:
2 event report update time, fix time, latitude and longitude
(1e-7 degree), altitude (cm), speed (cm/s), heading,
satellites, fix status, carrier, RSSI (dBm), comm
state, HDOP, inputs, unit status, event index and
code, accumulators
8 locate report the same without event index and code
10 mini event update time, latitude, longitude, heading, speed
(km/h), satellites and fix flags in one byte, comm
state, inputs, event code, accumulators
4 user data the event report's position fields, then route, ID,
length and the data (status userData)
1 ACK/NAK the unit's answer to a command (Response; a non-zero
code fails it)
3 ID report acknowledged, not decoded (Kind "id")
0 null acknowledged (Kind "heartbeat")
Other message types are acknowledged when asked and carry a warning. Inputs become ignition (bit 0) and din1..din7; accumulators acc0..accN (with accThreshold and accMask for accumulators of type 1). Event codes are defined by each unit's PEG script, so they are status values (event); profile.alerts maps codes to alert types. The fix status and HDOP are kept as reported (status fixStatus, hdop); a fix is valid when the fix status's invalid flag is clear. An options header whose extension bit (6) is set carries fields this codec does not read: the message is decoded as if it had none, with the warning optionsExtension.
Commands. {"text": "…"} is sent to the unit as user data (type 4) with service type 1, so the unit acknowledges it; the codec is a track.Correlator and the unit's ACK with the command's sequence number completes it. {"hex": "…"} sends a whole LM Direct message as written (not correlated). The named commands have no LM Direct form this package can vouch for: a unit acts on user data only as its PEG script says, and the unit request (type 7) action codes are not in a document we could read. They fail with track.ErrUnsupported unless profile.namedCommands gives the user data text for the action.
The profile (NewCodec; Profile):
alerts: {} # event code → alert type, such as {"13": "emergency"}
namedCommands: {} # action → user data text, with {imei} and {seconds}
Index ¶
Constants ¶
const ( TypeNull = 0 TypeAck = 1 TypeEventReport = 2 TypeIDReport = 3 TypeUserData = 4 TypeLocate = 8 TypeMiniEvent = 10 )
Message types.
const ( ServiceUnacknowledged = 0 ServiceAcknowledged = 1 ServiceResponse = 2 )
Service types.
Variables ¶
var Interval = track.IntervalRange{Min: 1, Max: 86400}
Interval bounds a profile's interval template, in seconds.
var NamedActions = []string{}
NamedActions are the named commands framed by default: none.
Functions ¶
Types ¶
type Profile ¶
type Profile struct {
// Alerts maps event codes (0 to 255, as the units' PEG scripts define
// them) to alert types.
Alerts map[string]string `json:"alerts,omitempty"`
// NamedCommands gives the user data text of a named action, with
// {imei} and {seconds}.
NamedCommands track.NamedTemplates `json:"namedCommands,omitempty"`
}
Profile is the deployment's settings.