Documentation
¶
Index ¶
- func ExtractContent(data []byte) ([]byte, error)
- func ExtractSerialNumber(data []byte) (uint16, error)
- func Has(protocolNum byte) bool
- func IsLongPacket(data []byte) bool
- func IsShortPacket(data []byte) bool
- func MustRegister(p Parser)
- func Parse(protocolNum byte, data []byte) (packet.Packet, error)
- func Register(p Parser) error
- type Alarm4GParser
- type AlarmMultiFenceParser
- type AlarmParser
- type BaseParser
- type ChineseAddressParser
- type CommandResponseOldParser
- type CommandResponseParser
- type Context
- type EnglishAddressParser
- type GPSAddressRequestParser
- type HeartbeatParser
- type InfoTransferParser
- type LBS4GParser
- type LBSParser
- type Location4GParser
- type LocationParser
- type LoginParser
- type OnlineCommandParser
- type Parser
- type Registry
- func (r *Registry) Context() Context
- func (r *Registry) Count() int
- func (r *Registry) Get(protocolNum byte) (Parser, bool)
- func (r *Registry) Has(protocolNum byte) bool
- func (r *Registry) List() []byte
- func (r *Registry) MustRegister(p Parser)
- func (r *Registry) Parse(protocolNum byte, data []byte) (packet.Packet, error)
- func (r *Registry) Register(p Parser) error
- func (r *Registry) SetContext(ctx Context)
- func (r *Registry) Unregister(protocolNum byte)
- type TimeCalibrationParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractContent ¶
ExtractContent extracts the content portion of a packet (excluding header/footer) For 0x7878 packets: StartBit(2) + Length(1) + Protocol(1) + Content + Serial(2) + CRC(2) + StopBit(2) For 0x7979 packets: StartBit(2) + Length(2) + Protocol(1) + Content + Serial(2) + CRC(2) + StopBit(2)
func ExtractSerialNumber ¶
ExtractSerialNumber extracts the serial number from a packet
func IsLongPacket ¶
IsLongPacket returns true if the packet uses 0x7979 format
func IsShortPacket ¶
IsShortPacket returns true if the packet uses 0x7878 format
func MustRegister ¶
func MustRegister(p Parser)
MustRegister adds a parser to the default registry and panics on error
Types ¶
type Alarm4GParser ¶
type Alarm4GParser struct {
BaseParser
}
Alarm4GParser parses 4G alarm packets (Protocol 0xA4)
func NewAlarm4GParser ¶
func NewAlarm4GParser() *Alarm4GParser
NewAlarm4GParser creates a new 4G alarm parser
type AlarmMultiFenceParser ¶
type AlarmMultiFenceParser struct {
BaseParser
}
AlarmMultiFenceParser parses alarm packets with geo-fence data (Protocol 0x27)
func NewAlarmMultiFenceParser ¶
func NewAlarmMultiFenceParser() *AlarmMultiFenceParser
NewAlarmMultiFenceParser creates a new multi-fence alarm parser
type AlarmParser ¶
type AlarmParser struct {
BaseParser
}
AlarmParser parses alarm packets (Protocol 0x26)
func (*AlarmParser) Parse ¶
Parse implements Parser interface Alarm packet content structure (Protocol 0x26): - DateTime: 6 bytes (YY MM DD HH MM SS) - GPS Info Length: 1 byte - Latitude: 4 bytes - Longitude: 4 bytes - Speed: 1 byte - Course/Status: 2 bytes - LBS Length: 1 byte (total length of LBS info) - MCC: 2 bytes - MNC: 1 byte - LAC: 2 bytes - CellID: 3 bytes - Terminal Info: 1 byte - Voltage Level: 1 byte - GSM Signal: 1 byte - Alarm Type: 1 byte (Alert and Language byte 1) - Language: 1 byte (Alert and Language byte 2) - Mileage: 4 bytes Total content: 33 bytes minimum
type BaseParser ¶
type BaseParser struct {
// contains filtered or unexported fields
}
BaseParser provides common functionality for parsers
func NewBaseParser ¶
func NewBaseParser(protocolNum byte, name string) BaseParser
NewBaseParser creates a new base parser
func (*BaseParser) ProtocolNumber ¶
func (p *BaseParser) ProtocolNumber() byte
ProtocolNumber implements Parser
type ChineseAddressParser ¶
type ChineseAddressParser struct {
BaseParser
}
ChineseAddressParser parses Chinese address response packets (Protocol 0x17)
func NewChineseAddressParser ¶
func NewChineseAddressParser() *ChineseAddressParser
NewChineseAddressParser creates a new Chinese address parser
func (*ChineseAddressParser) Parse ¶
Parse implements Parser interface Chinese Address packet content structure (Protocol 0x17): - Content Length: 1 byte (length of data between server flag and serial number) - Server Flag: 4 bytes (server marker) - ALARMSMS: 8 bytes (ASCII, typically "ALARMSMS") - Separator "&&": 2 bytes (ASCII) - Address Content: M bytes (UNICODE - UTF-16 BE) - Separator "&&": 2 bytes (ASCII) - Phone Number: 21 bytes (ASCII, "0" repeated for alarm packets) - Separator "##": 2 bytes (ASCII) Minimum content: 1 + 4 + 8 + 2 + 0 + 2 + 21 + 2 = 40 bytes
type CommandResponseOldParser ¶
type CommandResponseOldParser struct {
BaseParser
}
CommandResponseOldParser parses old-format command response packets (Protocol 0x15)
func NewCommandResponseOldParser ¶
func NewCommandResponseOldParser() *CommandResponseOldParser
NewCommandResponseOldParser creates a new old-format command response parser
type CommandResponseParser ¶
type CommandResponseParser struct {
BaseParser
}
CommandResponseParser parses command response packets (Protocol 0x21 and 0x15)
func NewCommandResponseParser ¶
func NewCommandResponseParser() *CommandResponseParser
NewCommandResponseParser creates a new command response parser
type Context ¶
type Context struct {
// StrictMode enables strict validation
StrictMode bool
// ValidateIMEI enables IMEI checksum validation
ValidateIMEI bool
// TimezoneOffset is the default timezone offset in minutes
TimezoneOffset int
}
Context provides additional context for parsing
func DefaultContext ¶
func DefaultContext() Context
DefaultContext returns the default parser context
type EnglishAddressParser ¶
type EnglishAddressParser struct {
BaseParser
}
EnglishAddressParser parses English address response packets (Protocol 0x97)
func NewEnglishAddressParser ¶
func NewEnglishAddressParser() *EnglishAddressParser
NewEnglishAddressParser creates a new English address parser
func (*EnglishAddressParser) Parse ¶
Parse implements Parser interface English Address packet content structure (Protocol 0x97): Same as Chinese but: - Uses long packet format (0x7979 start bit, 2-byte length) - Address content is ASCII/UTF-8 instead of UNICODE - Content Length: 1 byte - Server Flag: 4 bytes - ALARMSMS: 8 bytes (ASCII) - Separator "&&": 2 bytes (ASCII) - Address Content: M bytes (ASCII/UTF-8) - Separator "&&": 2 bytes (ASCII) - Phone Number: 21 bytes (ASCII) - Separator "##": 2 bytes (ASCII) Minimum content: 40 bytes
type GPSAddressRequestParser ¶
type GPSAddressRequestParser struct {
BaseParser
}
GPSAddressRequestParser parses GPS address request packets (Protocol 0x2A)
func NewGPSAddressRequestParser ¶
func NewGPSAddressRequestParser() *GPSAddressRequestParser
NewGPSAddressRequestParser creates a new GPS address request parser
func (*GPSAddressRequestParser) Parse ¶
Parse implements Parser interface Content structure (41 bytes according to JM-VL03 spec): - DateTime: 6 bytes (YY MM DD HH MM SS) - GPS Info: 1 byte (satellites in low nibble) - Latitude: 4 bytes (raw / 1,800,000) - Longitude: 4 bytes (raw / 1,800,000) - Speed: 1 byte (km/h) - Course/Status: 2 bytes (heading + status flags) - Phone Number: 21 bytes (ASCII) - Alert/Language: 2 bytes (AlarmType + Language) Total content: 41 bytes
type HeartbeatParser ¶
type HeartbeatParser struct {
BaseParser
}
HeartbeatParser parses heartbeat packets (Protocol 0x13)
func NewHeartbeatParser ¶
func NewHeartbeatParser() *HeartbeatParser
NewHeartbeatParser creates a new heartbeat parser
type InfoTransferParser ¶
type InfoTransferParser struct {
BaseParser
}
InfoTransferParser parses information transfer packets (Protocol 0x94)
func NewInfoTransferParser ¶
func NewInfoTransferParser() *InfoTransferParser
NewInfoTransferParser creates a new info transfer parser
type LBS4GParser ¶
type LBS4GParser struct {
BaseParser
}
LBS4GParser parses 4G LBS packets (Protocol 0xA1)
type LBSParser ¶
type LBSParser struct {
BaseParser
}
LBSParser parses LBS packets (Protocol 0x28)
func (*LBSParser) Parse ¶
Parse implements Parser interface LBS packet content structure: - DateTime: 6 bytes - MCC: 2 bytes - MNC: 1 byte - LAC: 2 bytes - Cell ID: 3 bytes Optional: - Terminal Info: 1 byte - Voltage Level: 1 byte - GSM Signal: 1 byte - Upload Mode: 1 byte Minimum content: 14 bytes, with status: 18 bytes
type Location4GParser ¶
type Location4GParser struct {
BaseParser
}
Location4GParser parses 4G GPS location packets (Protocol 0xA0)
func NewLocation4GParser ¶
func NewLocation4GParser() *Location4GParser
NewLocation4GParser creates a new 4G location parser
type LocationParser ¶
type LocationParser struct {
BaseParser
}
LocationParser parses GPS location packets (Protocol 0x22)
func NewLocationParser ¶
func NewLocationParser() *LocationParser
NewLocationParser creates a new location parser
func (*LocationParser) Parse ¶
Parse implements Parser interface Location packet content structure (Protocol 0x22): - DateTime: 6 bytes (YY MM DD HH MM SS) - GPS Info Length: 1 byte (high nibble: satellites, low nibble: GPS data length / 2) - Latitude: 4 bytes (raw value / 1800000 = decimal degrees) - Longitude: 4 bytes (raw value / 1800000 = decimal degrees) - Speed: 1 byte (km/h) - Course/Status: 2 bytes - MCC: 2 bytes (Mobile Country Code) - MNC: 1 byte (Mobile Network Code) - LAC: 2 bytes (Location Area Code) - CellID: 3 bytes (Cell Tower ID) - ACC: 1 byte (0x00=OFF, 0x01=ON) - Data Upload Mode: 1 byte - GPS Data Re-upload: 1 byte (0x00=Real-time, 0x01=Re-upload) - Mileage Statistics: 4 bytes Total content: 33 bytes minimum (all fields are MANDATORY per protocol spec)
type LoginParser ¶
type LoginParser struct {
BaseParser
}
LoginParser parses login packets (Protocol 0x01)
type OnlineCommandParser ¶
type OnlineCommandParser struct {
BaseParser
}
OnlineCommandParser parses online command packets (Protocol 0x80)
func NewOnlineCommandParser ¶
func NewOnlineCommandParser() *OnlineCommandParser
NewOnlineCommandParser creates a new online command parser
type Parser ¶
type Parser interface {
// ProtocolNumber returns the protocol number this parser handles
ProtocolNumber() byte
// Parse decodes the raw packet data into a typed Packet
// The data parameter contains the full packet (including start bit, length, etc.)
// The ctx parameter provides parsing context and configuration
// Returns the parsed packet or an error if parsing fails
Parse(data []byte, ctx Context) (packet.Packet, error)
// Name returns the human-readable name of this parser
Name() string
}
Parser is the interface that all protocol parsers must implement
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maintains a mapping of protocol numbers to parsers
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns the default global registry
func (*Registry) MustRegister ¶
MustRegister adds a parser and panics if registration fails
func (*Registry) Register ¶
Register adds a parser to the registry Returns an error if a parser for the protocol is already registered
func (*Registry) SetContext ¶
SetContext sets the parser context
func (*Registry) Unregister ¶
Unregister removes a parser from the registry
type TimeCalibrationParser ¶
type TimeCalibrationParser struct {
BaseParser
}
TimeCalibrationParser parses time calibration request packets (Protocol 0x8A)
func NewTimeCalibrationParser ¶
func NewTimeCalibrationParser() *TimeCalibrationParser
NewTimeCalibrationParser creates a new time calibration parser