types

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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

type DateTime struct {
	Time time.Time
}

DateTime represents a timestamp from a VL103M device The protocol uses 6 bytes: YY MM DD HH MM SS

func DateTimeFromBytes

func DateTimeFromBytes(data []byte) (DateTime, error)

DateTimeFromBytes decodes a DateTime from 6 protocol bytes Format: YY MM DD HH MM SS (decimal values, not BCD)

func NewDateTime

func NewDateTime(t time.Time) DateTime

NewDateTime creates a DateTime from a time.Time value

func Now

func Now() DateTime

Now returns the current time as a DateTime

func (DateTime) Add

func (dt DateTime) Add(d time.Duration) DateTime

Add returns a new DateTime with the given duration added

func (DateTime) After

func (dt DateTime) After(other DateTime) bool

After returns true if dt is after other

func (DateTime) Before

func (dt DateTime) Before(other DateTime) bool

Before returns true if dt is before other

func (DateTime) Format

func (dt DateTime) Format(layout string) string

Format returns the datetime using a custom format

func (DateTime) InLocation

func (dt DateTime) InLocation(loc *time.Location) DateTime

InLocation returns the DateTime in the specified timezone

func (DateTime) IsZero

func (dt DateTime) IsZero() bool

IsZero returns true if the datetime is the zero value

func (DateTime) String

func (dt DateTime) String() string

String returns the datetime in ISO format

func (DateTime) Sub

func (dt DateTime) Sub(other DateTime) time.Duration

Sub returns the duration between two DateTimes

func (DateTime) ToBytes

func (dt DateTime) ToBytes() []byte

ToBytes encodes the DateTime to 6 protocol bytes

func (DateTime) Unix

func (dt DateTime) Unix() int64

Unix returns the Unix timestamp

func (DateTime) WithTimezoneOffset

func (dt DateTime) WithTimezoneOffset(offsetMinutes int) DateTime

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

func MustNewIMEI(s string) IMEI

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

func NewIMEI(s string) (IMEI, error)

NewIMEI creates a new IMEI from a string with validation The string must be exactly 15 digits

func NewIMEIFromBytes

func NewIMEIFromBytes(data []byte) (IMEI, error)

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

func NewIMEIFromBytesUnchecked(data []byte) (IMEI, error)

NewIMEIFromBytesUnchecked creates an IMEI from BCD bytes without checksum validation

func NewIMEIUnchecked

func NewIMEIUnchecked(s string) (IMEI, error)

NewIMEIUnchecked creates an IMEI without checksum validation Use this when dealing with devices that don't follow Luhn algorithm

func (IMEI) Bytes

func (i IMEI) Bytes() []byte

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

func (i IMEI) CheckDigit() int

CheckDigit returns the Luhn check digit (last digit)

func (IMEI) IsValid

func (i IMEI) IsValid() bool

IsValid returns true if the IMEI is valid (non-empty and validated)

func (IMEI) SNR

func (i IMEI) SNR() string

SNR returns the Serial Number (next 6 digits after TAC)

func (IMEI) String

func (i IMEI) String() string

String returns the IMEI as a 15-digit string

func (IMEI) TAC

func (i IMEI) TAC() string

TAC returns the Type Allocation Code (first 8 digits) TAC identifies the device manufacturer and model

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

func NewLBSInfo(mcc, mnc uint16, lac uint32, cellID uint64) LBSInfo

NewLBSInfo creates a new LBSInfo with validation

func NewLBSInfoFromBytes

func NewLBSInfoFromBytes(data []byte, is4G bool) (LBSInfo, int, error)

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

func NewLBSInfoFromBytes2G(data []byte) (LBSInfo, error)

NewLBSInfoFromBytes2G creates LBSInfo from 2G/3G packet bytes (8 bytes total) Format: MCC(2) + MNC(1) + LAC(2) + CellID(3)

func NewLBSInfoFromBytes4G

func NewLBSInfoFromBytes4G(data []byte, mccHasBit15 bool) (LBSInfo, int, error)

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) Bytes2G

func (l LBSInfo) Bytes2G() []byte

Bytes2G returns the LBSInfo encoded as 2G/3G format (8 bytes)

func (LBSInfo) Bytes4G

func (l LBSInfo) Bytes4G(useTwoBytesMNC bool) []byte

Bytes4G returns the LBSInfo encoded as 4G format useTwoBytesMNC: if true, uses 2 bytes for MNC (sets bit15 of MCC)

func (LBSInfo) CountryCode

func (l LBSInfo) CountryCode() string

CountryCode returns the country name based on MCC (common codes)

func (LBSInfo) IsValid

func (l LBSInfo) IsValid() bool

IsValid returns true if LBS info appears to be valid (MCC is non-zero)

func (LBSInfo) String

func (l LBSInfo) String() string

String returns a human-readable representation of LBS info

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) Raw

func (t TerminalInfo) Raw() byte

Raw returns the raw byte value

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

SetACCOn sets the ACC status

func (*TerminalInfoBuilder) SetArmed

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

func TimezoneFromBytes(data []byte) (Timezone, error)

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

func (tz Timezone) LanguageString() string

LanguageString returns the language name Language codes: 0x01 = English, 0x02 = Chinese

func (Timezone) Location

func (tz Timezone) Location() *time.Location

Location returns a time.Location for this timezone

func (Timezone) String

func (tz Timezone) String() string

String returns the timezone as a string (e.g., "+08:00")

func (Timezone) ToBytes

func (tz Timezone) ToBytes() []byte

ToBytes encodes the Timezone to 2 bytes

Jump to

Keyboard shortcuts

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