Documentation
¶
Index ¶
- Constants
- type Coordinates
- func (c Coordinates) DistanceTo(other Coordinates) float64
- func (c Coordinates) IsValid() bool
- func (c Coordinates) IsZero() bool
- func (c Coordinates) LatitudeBytes() []byte
- func (c Coordinates) LongitudeBytes() []byte
- func (c Coordinates) SignedLatitude() float64
- func (c Coordinates) SignedLongitude() float64
- func (c Coordinates) String() string
- func (c Coordinates) ToDecimalDegrees() (lat, lon float64)
- type CourseStatus
- func (c CourseStatus) Bytes() []byte
- func (c CourseStatus) DirectionName() string
- func (c CourseStatus) GetCourse() uint16
- func (c CourseStatus) GetIsEastLongitude() bool
- func (c CourseStatus) GetIsGPSRealtime() bool
- func (c CourseStatus) GetIsNorthLatitude() bool
- func (c CourseStatus) GetIsPositioned() bool
- func (c CourseStatus) String() string
- type DateTime
- func (dt DateTime) Add(d time.Duration) DateTime
- func (dt DateTime) After(other DateTime) bool
- func (dt DateTime) Before(other DateTime) bool
- func (dt DateTime) Format(layout string) string
- func (dt DateTime) InLocation(loc *time.Location) DateTime
- func (dt DateTime) IsZero() bool
- func (dt DateTime) String() string
- func (dt DateTime) Sub(other DateTime) time.Duration
- func (dt DateTime) ToBytes() []byte
- func (dt DateTime) Unix() int64
- func (dt DateTime) WithTimezoneOffset(offsetMinutes int) DateTime
- type DeviceStatus
- type IMEI
- type LBSInfo
- type TerminalInfo
- func (t TerminalInfo) ACCOn() bool
- func (t TerminalInfo) AlarmTypeBits() byte
- func (t TerminalInfo) GPSTrackingEnabled() bool
- func (t TerminalInfo) IsArmed() bool
- func (t TerminalInfo) IsCharging() bool
- func (t TerminalInfo) OilElectricityDisconnected() bool
- func (t TerminalInfo) Raw() byte
- func (t TerminalInfo) String() string
- type TerminalInfoBuilder
- func (b *TerminalInfoBuilder) Build() TerminalInfo
- func (b *TerminalInfoBuilder) SetACCOn(v bool) *TerminalInfoBuilder
- func (b *TerminalInfoBuilder) SetArmed(v bool) *TerminalInfoBuilder
- func (b *TerminalInfoBuilder) SetCharging(v bool) *TerminalInfoBuilder
- func (b *TerminalInfoBuilder) SetGPSTracking(v bool) *TerminalInfoBuilder
- func (b *TerminalInfoBuilder) SetOilElectricityDisconnected(v bool) *TerminalInfoBuilder
- type Timezone
Constants ¶
const CoordinatesDivisor = 1800000.0
CoordinatesDivisor is the divisor used in VL103M protocol Lat/Lon values in protocol are stored as: actual_value * 1,800,000
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Coordinates ¶
type Coordinates struct {
Latitude float64 // Decimal degrees (-90 to 90)
Longitude float64 // Decimal degrees (-180 to 180)
IsNorth bool // true if Northern hemisphere
IsEast bool // true if Eastern hemisphere
}
Coordinates represents GPS coordinates (latitude and longitude)
func MustNewCoordinates ¶
func MustNewCoordinates(lat, lon float64) Coordinates
MustNewCoordinates creates coordinates and panics if invalid Use this only when you're certain the coordinates are valid
func NewCoordinates ¶
func NewCoordinates(lat, lon float64) (Coordinates, error)
NewCoordinates creates coordinates from decimal degrees Latitude range: -90 to 90 (negative = South, positive = North) Longitude range: -180 to 180 (negative = West, positive = East)
func NewCoordinatesFromBytes ¶
func NewCoordinatesFromBytes(latBytes, lonBytes []byte, isNorth, isEast bool) (Coordinates, error)
NewCoordinatesFromBytes creates coordinates from VL103M protocol bytes latBytes: 4 bytes representing latitude * 1,800,000 lonBytes: 4 bytes representing longitude * 1,800,000 isNorth: true if Northern hemisphere isEast: true if Eastern hemisphere
func (Coordinates) DistanceTo ¶
func (c Coordinates) DistanceTo(other Coordinates) float64
DistanceTo calculates the distance to another coordinate in meters using the Haversine formula
func (Coordinates) IsValid ¶
func (c Coordinates) IsValid() bool
IsValid returns true if coordinates appear to be valid (non-zero and within reasonable range)
func (Coordinates) IsZero ¶
func (c Coordinates) IsZero() bool
IsZero returns true if coordinates are at 0,0 (likely invalid/no fix)
func (Coordinates) LatitudeBytes ¶
func (c Coordinates) LatitudeBytes() []byte
LatitudeBytes returns the latitude as 4 bytes (big-endian) for encoding back to VL103M protocol format
func (Coordinates) LongitudeBytes ¶
func (c Coordinates) LongitudeBytes() []byte
LongitudeBytes returns the longitude as 4 bytes (big-endian) for encoding back to VL103M protocol format
func (Coordinates) SignedLatitude ¶
func (c Coordinates) SignedLatitude() float64
SignedLatitude returns latitude with sign (negative for South)
func (Coordinates) SignedLongitude ¶
func (c Coordinates) SignedLongitude() float64
SignedLongitude returns longitude with sign (negative for West)
func (Coordinates) String ¶
func (c Coordinates) String() string
String returns coordinates in human-readable format Example: "23.125346°N, 113.251515°E"
func (Coordinates) ToDecimalDegrees ¶
func (c Coordinates) ToDecimalDegrees() (lat, lon float64)
ToDecimalDegrees returns latitude and longitude as signed decimal degrees Returns (lat, lon) where negative values indicate South/West
type CourseStatus ¶
type CourseStatus struct {
Course uint16 // Direction in degrees (0-360°, 0=North, clockwise)
IsGPSRealtime bool // true if GPS real-time positioning
IsPositioned bool // true if GPS has valid fix
IsEastLongitude bool // true if East longitude
IsNorthLatitude bool // true if North latitude
}
CourseStatus represents the course (direction) and GPS status from 2 bytes BYTE_1: bit7-bit6(0), bit5(GPS Real-time/Differential), bit4(Positioned),
bit3(East/West), bit2(North/South), bit1-bit0(Course high bits)
BYTE_2: bit7-bit0(Course low bits)
func MustNewCourseStatusFromBytes ¶
func MustNewCourseStatusFromBytes(data []byte) CourseStatus
MustNewCourseStatusFromBytes creates CourseStatus and panics if invalid
func NewCourseStatus ¶
func NewCourseStatus(course uint16, isRealtime, isPositioned, isEast, isNorth bool) CourseStatus
NewCourseStatus creates a CourseStatus from individual fields
func NewCourseStatusFromBytes ¶
func NewCourseStatusFromBytes(data []byte) (CourseStatus, error)
NewCourseStatusFromBytes creates CourseStatus from 2 bytes
func (CourseStatus) Bytes ¶
func (c CourseStatus) Bytes() []byte
Bytes returns the CourseStatus as 2 bytes for protocol encoding
func (CourseStatus) DirectionName ¶
func (c CourseStatus) DirectionName() string
DirectionName returns the compass direction name
func (CourseStatus) GetCourse ¶
func (c CourseStatus) GetCourse() uint16
GetCourse returns the course in degrees (0-360)
func (CourseStatus) GetIsEastLongitude ¶
func (c CourseStatus) GetIsEastLongitude() bool
GetIsEastLongitude returns true if longitude is in Eastern hemisphere
func (CourseStatus) GetIsGPSRealtime ¶
func (c CourseStatus) GetIsGPSRealtime() bool
GetIsGPSRealtime returns true if using real-time GPS positioning
func (CourseStatus) GetIsNorthLatitude ¶
func (c CourseStatus) GetIsNorthLatitude() bool
GetIsNorthLatitude returns true if latitude is in Northern hemisphere
func (CourseStatus) GetIsPositioned ¶
func (c CourseStatus) GetIsPositioned() bool
GetIsPositioned returns true if GPS has a valid fix
func (CourseStatus) String ¶
func (c CourseStatus) String() string
String returns a human-readable representation
type DateTime ¶
DateTime represents a timestamp from a VL103M device The protocol uses 6 bytes: YY MM DD HH MM SS
func DateTimeFromBytes ¶
DateTimeFromBytes decodes a DateTime from 6 protocol bytes Format: YY MM DD HH MM SS (decimal values, not BCD)
func NewDateTime ¶
NewDateTime creates a DateTime from a time.Time value
func (DateTime) InLocation ¶
InLocation returns the DateTime in the specified timezone
func (DateTime) WithTimezoneOffset ¶
WithTimezoneOffset applies a timezone offset in minutes
type DeviceStatus ¶
type DeviceStatus struct {
TerminalInfo TerminalInfo
VoltageLevel protocol.VoltageLevel
GSMSignal protocol.GSMSignalStrength
ExtendedStatus byte // Additional status byte if present
HasExtendedInfo bool
}
DeviceStatus represents extended device status information Some protocols include additional status bytes
func DeviceStatusFromBytes ¶
func DeviceStatusFromBytes(data []byte) (DeviceStatus, error)
DeviceStatusFromBytes parses device status from protocol bytes The number of bytes varies by protocol: - Basic: 2 bytes (terminal info + voltage) - Extended: 3+ bytes (+ GSM signal, etc.)
func (DeviceStatus) String ¶
func (s DeviceStatus) String() string
String returns a human-readable representation
func (DeviceStatus) ToBytes ¶
func (s DeviceStatus) ToBytes() []byte
ToBytes serializes the device status to bytes
type IMEI ¶
type IMEI struct {
// contains filtered or unexported fields
}
IMEI represents a validated International Mobile Equipment Identity number IMEI is a 15-digit unique identifier for mobile devices
func MustNewIMEI ¶
MustNewIMEI creates a new IMEI and panics if invalid Use this only when you're certain the IMEI is valid (e.g., in tests)
func NewIMEI ¶
NewIMEI creates a new IMEI from a string with validation The string must be exactly 15 digits
func NewIMEIFromBytes ¶
NewIMEIFromBytes creates an IMEI from BCD-encoded bytes (8 bytes) The VL103M protocol encodes IMEI as 8 bytes in BCD format Example: IMEI "123456789012345" → 0x01 0x23 0x45 0x67 0x89 0x01 0x23 0x45
func NewIMEIFromBytesUnchecked ¶
NewIMEIFromBytesUnchecked creates an IMEI from BCD bytes without checksum validation
func NewIMEIUnchecked ¶
NewIMEIUnchecked creates an IMEI without checksum validation Use this when dealing with devices that don't follow Luhn algorithm
func (IMEI) Bytes ¶
Bytes returns the IMEI in BCD-encoded format (8 bytes) Each byte contains two digits (high nibble and low nibble) The 16th nibble is set to 0 for padding
func (IMEI) CheckDigit ¶
CheckDigit returns the Luhn check digit (last digit)
type LBSInfo ¶
type LBSInfo struct {
MCC uint16 // Mobile Country Code
MNC uint16 // Mobile Network Code (1 or 2 bytes depending on 2G/4G)
LAC uint32 // Location Area Code (2 bytes for 2G, 4 bytes for 4G)
CellID uint64 // Cell Tower ID (3 bytes for 2G, 8 bytes for 4G)
}
LBSInfo represents Location-Based Service information from cell towers Used when GPS signal is not available
func NewLBSInfo ¶
NewLBSInfo creates a new LBSInfo with validation
func NewLBSInfoFromBytes ¶
NewLBSInfoFromBytes creates LBSInfo from raw bytes and returns bytes consumed. is4G: true for 4G packets (15-16 bytes), false for 2G/3G packets (8 bytes)
func NewLBSInfoFromBytes2G ¶
NewLBSInfoFromBytes2G creates LBSInfo from 2G/3G packet bytes (8 bytes total) Format: MCC(2) + MNC(1) + LAC(2) + CellID(3)
func NewLBSInfoFromBytes4G ¶
NewLBSInfoFromBytes4G creates LBSInfo from 4G packet bytes and returns bytes consumed. Format varies based on MCC bit15:
- If bit15=0: MCC(2) + MNC(1) + LAC(4) + CellID(8) = 15 bytes
- If bit15=1: MCC(2) + MNC(2) + LAC(4) + CellID(8) = 16 bytes
func (LBSInfo) Bytes4G ¶
Bytes4G returns the LBSInfo encoded as 4G format useTwoBytesMNC: if true, uses 2 bytes for MNC (sets bit15 of MCC)
func (LBSInfo) CountryCode ¶
CountryCode returns the country name based on MCC (common codes)
type TerminalInfo ¶
type TerminalInfo struct {
// contains filtered or unexported fields
}
TerminalInfo represents the terminal information status byte This byte contains various device status flags packed as bits
func NewTerminalInfo ¶
func NewTerminalInfo(b byte) TerminalInfo
NewTerminalInfo creates a new TerminalInfo from a raw byte
func TerminalInfoFromByte ¶
func TerminalInfoFromByte(b byte) TerminalInfo
TerminalInfoFromByte creates a TerminalInfo from a byte
func (TerminalInfo) ACCOn ¶
func (t TerminalInfo) ACCOn() bool
ACCOn returns true if ACC (accessory power) is on ACC is typically on when the vehicle ignition is in accessory or on position
func (TerminalInfo) AlarmTypeBits ¶ added in v0.2.1
func (t TerminalInfo) AlarmTypeBits() byte
AlarmTypeBits returns the alarm type encoded in bits 3-5 Values: 000=Normal, 001=Vibration, 010=PowerCut, 011=LowBattery, 100=SOS
func (TerminalInfo) GPSTrackingEnabled ¶
func (t TerminalInfo) GPSTrackingEnabled() bool
GPSTrackingEnabled returns true if GPS tracking is enabled
func (TerminalInfo) IsArmed ¶
func (t TerminalInfo) IsArmed() bool
IsArmed returns true if the device is in defense/armed mode
func (TerminalInfo) IsCharging ¶
func (t TerminalInfo) IsCharging() bool
IsCharging returns true if the device is charging
func (TerminalInfo) OilElectricityDisconnected ¶
func (t TerminalInfo) OilElectricityDisconnected() bool
OilElectricityDisconnected returns true if oil/electricity is disconnected This indicates power has been cut to the vehicle
func (TerminalInfo) String ¶
func (t TerminalInfo) String() string
String returns a human-readable representation
type TerminalInfoBuilder ¶
type TerminalInfoBuilder struct {
// contains filtered or unexported fields
}
TerminalInfoBuilder helps construct TerminalInfo values
func NewTerminalInfoBuilder ¶
func NewTerminalInfoBuilder() *TerminalInfoBuilder
NewTerminalInfoBuilder creates a new builder
func (*TerminalInfoBuilder) Build ¶
func (b *TerminalInfoBuilder) Build() TerminalInfo
Build creates the TerminalInfo
func (*TerminalInfoBuilder) SetACCOn ¶
func (b *TerminalInfoBuilder) SetACCOn(v bool) *TerminalInfoBuilder
SetACCOn sets the ACC status
func (*TerminalInfoBuilder) SetArmed ¶
func (b *TerminalInfoBuilder) SetArmed(v bool) *TerminalInfoBuilder
SetArmed sets the defense/armed status
func (*TerminalInfoBuilder) SetCharging ¶
func (b *TerminalInfoBuilder) SetCharging(v bool) *TerminalInfoBuilder
SetCharging sets the charging flag
func (*TerminalInfoBuilder) SetGPSTracking ¶
func (b *TerminalInfoBuilder) SetGPSTracking(v bool) *TerminalInfoBuilder
SetGPSTracking sets the GPS tracking flag
func (*TerminalInfoBuilder) SetOilElectricityDisconnected ¶
func (b *TerminalInfoBuilder) SetOilElectricityDisconnected(v bool) *TerminalInfoBuilder
SetOilElectricityDisconnected sets the oil/electricity disconnected flag
type Timezone ¶
type Timezone struct {
OffsetMinutes int // Timezone offset in minutes (e.g., 480 for UTC+8)
Language byte // Language code (0x01=Chinese, 0x02=English)
}
Timezone represents the timezone/language field from the protocol
func TimezoneFromBytes ¶
TimezoneFromBytes decodes the 2-byte timezone/language field
Format (2 bytes): Bit15-Bit4: Timezone value (expanded by 100, e.g., 800 for +08:00) Bit3: Direction (0=East, 1=West) Bit2: Undefined Bit1-Bit0: Language (0x01=Chinese, 0x02=English)
func (Timezone) LanguageString ¶
LanguageString returns the language name Language codes: 0x01 = English, 0x02 = Chinese