models

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseSuccess        uint8 = 0x01
	ResponseFailed         uint8 = 0x02
	ResponseVINDuplicate   uint8 = 0x03
	ResponseCommandPackage uint8 = 0xFE

	EncryptNone uint8 = 0x01
	EncryptRSA  uint8 = 0x02
)
View Source
const (
	GBT32960TimeLayout = "060102150405" //"YYMMDDhhmmss"

)
View Source
const (
	ICCIDLength = 20
)
View Source
const (
	VINLength = 17
)

Variables

View Source
var (
	ErrInvalidParse   = errors.New("Fail to parse")
	ErrInvalidConvert = errors.New("Fail to convert msg")
	ErrDecodeMsg      = errors.New("Fail to decode msg")
	ErrEncodeMsg      = errors.New("Fail to encode msg")
	ErrGenOutgoingMsg = errors.New("Fail to generate outgoing msg")
	ErrNotAvailable   = errors.New("Not available")
	ErrMissmatch      = errors.New("Missmatch")
	ErrInvalidID      = errors.New("Invalid ID")
	ErrInvalidLength  = errors.New("Invalid length")
	ErrPreprocess     = errors.New("Invalid preprocess")
	ErrNotFound       = errors.New("Not found")
	ErrUnset          = errors.New("Unset")
	ErrDecryptMsg     = errors.New("Fail to decrypt msg")
	ErrEncryptMsg     = errors.New("Fail to encrypt msg")
)

Functions

func GBT32960Timezone

func GBT32960Timezone() *time.Location

func SetParameterPropertiesLookup added in v0.1.0

func SetParameterPropertiesLookup(lookup map[uint8]ParamProperties)

set custom parameter lookup for param decoder

func TimeDecode

func TimeDecode(pkt []byte, idx *int) (time.Time, error)

func TimeEncode

func TimeEncode(t time.Time) (pkt []byte)

func WriteHeader

func WriteHeader(m GBT32960Msg, pkt []byte) ([]byte, error)

Types

type Alarm

type Alarm struct {
	AlarmLevel         uint8    `json:"alarmLevel"`
	AlarmBatteryFlag   uint32   `json:"alarmBatteryFlag"`
	AlarmBatteryOthers []uint32 `json:"alarmBatteryOthers"`
	AlarmDriveMotor    []uint32 `json:"alarmDriveMotor"`
	AlarmEngines       []uint32 `json:"alarmEngines"`
	AlarmOthers        []uint32 `json:"alarmOthers"`
}

func (*Alarm) Decode

func (m *Alarm) Decode(pkt []byte, idx *int) error

func (Alarm) Encode

func (m Alarm) Encode() (pkt []byte, err error)

func (Alarm) GetID

func (m Alarm) GetID() uint8

func (*Alarm) MarshalJSON

func (m *Alarm) MarshalJSON() ([]byte, error)

type BatteriesTemperatures

type BatteriesTemperatures []*BatteryTemperature

func (*BatteriesTemperatures) Decode

func (m *BatteriesTemperatures) Decode(pkt []byte, idx *int) error

func (BatteriesTemperatures) Encode

func (m BatteriesTemperatures) Encode() (pkt []byte, err error)

func (BatteriesTemperatures) GetID

func (m BatteriesTemperatures) GetID() uint8

func (*BatteriesTemperatures) MarshalJSON

func (m *BatteriesTemperatures) MarshalJSON() ([]byte, error)

type BatteriesVoltages

type BatteriesVoltages []*BatteryVoltages

func (*BatteriesVoltages) Decode

func (m *BatteriesVoltages) Decode(pkt []byte, idx *int) error

func (BatteriesVoltages) Encode

func (m BatteriesVoltages) Encode() (pkt []byte, err error)

func (BatteriesVoltages) GetID

func (m BatteriesVoltages) GetID() uint8

func (*BatteriesVoltages) MarshalJSON

func (m *BatteriesVoltages) MarshalJSON() ([]byte, error)

type BatteryTemperature

type BatteryTemperature struct {
	AssyNo      uint8   `json:"assamblyNo                  "`
	Temperature []uint8 `json:"temperature                 "`
}

func (*BatteryTemperature) Decode

func (m *BatteryTemperature) Decode(pkt []byte, idx *int) error

func (*BatteryTemperature) Encode

func (m *BatteryTemperature) Encode() (pkt []byte, err error)

type BatteryVoltages

type BatteryVoltages struct {
	AssyNo                      uint8    `json:"assamblyNo"`
	Voltage                     uint16   `json:"voltage"`
	Current                     uint16   `json:"current"`
	BatteriesTotalNumber        uint16   `json:"batteriesTotalNumber"`
	BatteryStartNumberFrame     uint16   `json:"batteryStartNumberFrame"`
	SingleBatteryVoltageOnFrame []uint16 `json:"singleBatteryVoltageOnFrame"`
}

func (*BatteryVoltages) Decode

func (m *BatteryVoltages) Decode(pkt []byte, idx *int) error

func (*BatteryVoltages) Encode

func (m *BatteryVoltages) Encode() (pkt []byte, err error)

type Control

type Control uint8

func (*Control) Decode

func (m *Control) Decode(pkt []byte, idx *int) error

func (*Control) Encode

func (m *Control) Encode() (pkt []byte, err error)

func (Control) GetID

func (m Control) GetID() uint8

type DriveMotor

type DriveMotor struct {
	SerialNumber         uint8  `json:"serialNumber"`
	Status               uint8  `json:"status"`
	ControlerTemperature uint8  `json:"controlerTemperature"`
	Speed                uint16 `json:"speed"`
	Torque               uint16 `json:"torque"`
	Temperature          uint8  `json:"temperature"`
	InputVoltage         uint16 `json:"inputVoltage"`
	InputCurrent         uint16 `json:"inputCurrent"`
}

func (*DriveMotor) Decode

func (m *DriveMotor) Decode(pkt []byte, idx *int) error

func (*DriveMotor) Encode

func (m *DriveMotor) Encode() (pkt []byte, err error)

type DriveMotors

type DriveMotors []*DriveMotor

func (*DriveMotors) Decode

func (m *DriveMotors) Decode(pkt []byte, idx *int) error

func (DriveMotors) Encode

func (m DriveMotors) Encode() (pkt []byte, err error)

func (DriveMotors) GetID

func (m DriveMotors) GetID() uint8

func (*DriveMotors) MarshalJSON

func (m *DriveMotors) MarshalJSON() ([]byte, error)

type EnergyStorageSys

type EnergyStorageSys struct {
	Coding byte

	// todo : create interface for eatch coding
	Raw []byte
}

func (*EnergyStorageSys) Decode

func (m *EnergyStorageSys) Decode(pkt []byte, idx *int) error

func (*EnergyStorageSys) Encode

func (m *EnergyStorageSys) Encode() (pkt []byte)

type Engine

type Engine struct {
	Status   uint8  `json:"status"`
	Revs     uint16 `json:"revolution"`
	FuelRate uint16 `json:"fuelRate"`
}

func (*Engine) Decode

func (m *Engine) Decode(pkt []byte, idx *int) error

func (*Engine) Encode

func (m *Engine) Encode() (pkt []byte, err error)

func (Engine) GetID

func (m Engine) GetID() uint8

func (*Engine) MarshalJSON

func (m *Engine) MarshalJSON() ([]byte, error)

type Extreme

type Extreme struct {
	MaxVoltageBatAssyNo      uint8  `json:"maxVoltageBatAssyNo"`
	MaxVoltageSingleBatNo    uint8  `json:"maxVoltageSingleBatNo"`
	MaxVoltageSingleBatValue uint16 `json:"maxVoltageSingleBatValue"`
	MinVoltageBatAssyNo      uint8  `json:"minVoltageBatAssyNo"`
	MinVoltageSingleBatNo    uint8  `json:"minVoltageSingleBatNo"`
	MinVoltageSingleBatValue uint16 `json:"minVoltageSingleBatValue"`
	MaxTempBatProbeNo        uint8  `json:"maxTempBatProbeNo"`
	MaxTempBatAssyNo         uint8  `json:"maxTempBatAssyNo"`
	MaxTempBatProbeValue     uint8  `json:"maxTempBatProbeValue"`
	MinTempBatAssyNo         uint8  `json:"minTempBatAssyNo"`
	MinTempBatProbeNo        uint8  `json:"minTempBatProbeNo"`
	MinTempBatProbeValue     uint8  `json:"minTempBatProbeValue"`
}

func (*Extreme) Decode

func (m *Extreme) Decode(pkt []byte, idx *int) error

func (Extreme) Encode

func (m Extreme) Encode() (pkt []byte, err error)

func (Extreme) GetID

func (m Extreme) GetID() uint8

func (*Extreme) MarshalJSON

func (m *Extreme) MarshalJSON() ([]byte, error)

type FuelCell

type FuelCell struct {
	BatVoltage                     uint16  `json:"batVoltage"`
	BatCurrent                     uint16  `json:"batCurrent"`
	FuelRate                       uint16  `json:"fuelRate"`
	Temperatures                   []uint8 `json:"temperatures"`
	HydrogenSysMaxTemp             uint16  `json:"hydrogenSysMaxTemp"`
	HydrogenSysMaxTempNo           uint8   `json:"hydrogenSysMaxTempNo"`
	HydrogenSysMaxConcentrations   uint16  `json:"hydrogenSysMaxConcentrations"`
	HydrogenSysMaxConcentrationsNo uint8   `json:"hydrogenSysMaxConcentrationsNo"`
	HydrogenSysMaxPressure         uint16  `json:"hydrogenSysMaxPressure"`
	HydrogenSysMaxPressureNo       uint8   `json:"hydrogenSysMaxPressureNo"`
	DCStatus                       uint8   `json:"dcStatus"`
}

func (*FuelCell) Decode

func (m *FuelCell) Decode(pkt []byte, idx *int) error

func (*FuelCell) Encode

func (m *FuelCell) Encode() (pkt []byte, err error)

func (FuelCell) GetID

func (m FuelCell) GetID() uint8

func (*FuelCell) MarshalJSON

func (m *FuelCell) MarshalJSON() ([]byte, error)

type GBT32960Msg

type GBT32960Msg interface {
	Decode(*PacketData) error        // Packet -> GBT32960Msg
	Encode() (pkt []byte, err error) // GBT32960Msg -> Packet
	GetHeader() *MsgHeader           // Header
	Copy() GBT32960Msg
	GetMsgSN() string
}

type GBT32960MsgTime

type GBT32960MsgTime interface {
	GetTime() time.Time
}

type GeneralParameter

type GeneralParameter interface {
	Decode(pkt []byte, idx *int) error
	Encode() (pkt []byte, err error)
	GetID() uint8
}

type GeneralReport

type GeneralReport interface {
	Decode(pkt []byte, idx *int) error
	Encode() (pkt []byte, err error)
	GetID() uint8
	MarshalJSON() ([]byte, error)
}

type Location

type Location struct {
	Status    uint8  `json:"status"`
	Longitude uint32 `json:"longitude"`
	Latidude  uint32 `json:"latidude"`
}

func (*Location) Decode

func (m *Location) Decode(pkt []byte, idx *int) error

func (Location) Encode

func (m Location) Encode() (pkt []byte, err error)

func (Location) GetID

func (m Location) GetID() uint8

func (*Location) MarshalJSON

func (m *Location) MarshalJSON() ([]byte, error)

type Msg01

type Msg01 struct {
	Header               *MsgHeader       `json:"header"`
	Time                 time.Time        `json:"time"`
	SerialNumber         uint16           `json:"serialNumber"`
	ICCID                string           `json:"iccid"`
	EnerygyStorageSystem EnergyStorageSys `json:"energyStorageSystem"`
}

Login

func (*Msg01) Copy

func (m *Msg01) Copy() GBT32960Msg

func (*Msg01) Decode

func (m *Msg01) Decode(packet *PacketData) error

func (*Msg01) Encode

func (m *Msg01) Encode() (pkt []byte, err error)

func (*Msg01) GetHeader

func (m *Msg01) GetHeader() *MsgHeader

func (Msg01) GetMsgSN

func (m Msg01) GetMsgSN() string

func (Msg01) GetTime

func (m Msg01) GetTime() time.Time

type Msg02

type Msg02 struct {
	Header  *MsgHeader `json:"header"`
	Time    time.Time  `json:"time"`
	Reports Reports    `json:"reports"`
}

func (*Msg02) Copy

func (m *Msg02) Copy() GBT32960Msg

func (*Msg02) Decode

func (m *Msg02) Decode(packet *PacketData) error

func (*Msg02) Encode

func (m *Msg02) Encode() (pkt []byte, err error)

func (*Msg02) GetHeader

func (m *Msg02) GetHeader() *MsgHeader

func (Msg02) GetMsgSN

func (m Msg02) GetMsgSN() string

func (Msg02) GetTime

func (m Msg02) GetTime() time.Time

type Msg03

type Msg03 struct {
	Header  *MsgHeader `json:"header"`
	Time    time.Time  `json:"time"`
	Reports Reports    `json:"reports"`
}

func (*Msg03) Copy

func (m *Msg03) Copy() GBT32960Msg

func (*Msg03) Decode

func (m *Msg03) Decode(packet *PacketData) error

func (*Msg03) Encode

func (m *Msg03) Encode() (pkt []byte, err error)

func (*Msg03) GetHeader

func (m *Msg03) GetHeader() *MsgHeader

func (Msg03) GetMsgSN

func (m Msg03) GetMsgSN() string

func (Msg03) GetTime

func (m Msg03) GetTime() time.Time

type Msg04

type Msg04 struct {
	Header       *MsgHeader `json:"header"`
	Time         time.Time  `json:"time"`
	SerialNumber uint16     `json:"serialNumber"`
}

func (*Msg04) Copy

func (m *Msg04) Copy() GBT32960Msg

func (*Msg04) Decode

func (m *Msg04) Decode(packet *PacketData) error

func (*Msg04) Encode

func (m *Msg04) Encode() (pkt []byte, err error)

func (*Msg04) GetHeader

func (m *Msg04) GetHeader() *MsgHeader

func (Msg04) GetMsgSN

func (m Msg04) GetMsgSN() string

func (Msg04) GetTime

func (m Msg04) GetTime() time.Time

type Msg07

type Msg07 struct {
	Header *MsgHeader `json:"header"`
}

func (*Msg07) Copy

func (m *Msg07) Copy() GBT32960Msg

func (*Msg07) Decode

func (m *Msg07) Decode(packet *PacketData) error

func (*Msg07) Encode

func (m *Msg07) Encode() (pkt []byte, err error)

func (*Msg07) GetHeader

func (m *Msg07) GetHeader() *MsgHeader

func (Msg07) GetMsgSN

func (m Msg07) GetMsgSN() string

type Msg80Receive

type Msg80Receive struct {
	Header       *MsgHeader `json:"header"`
	Time         time.Time  `json:"time"`
	ParameterIDs []byte     `json:"parameterIDs"`
}

Parameter Query

func GenerateMsh80Receive

func GenerateMsh80Receive(vin string, timeNow time.Time, parameterID []byte) *Msg80Receive

func (*Msg80Receive) Copy

func (m *Msg80Receive) Copy() GBT32960Msg

func (*Msg80Receive) Decode

func (m *Msg80Receive) Decode(packet *PacketData) error

func (*Msg80Receive) Encode

func (m *Msg80Receive) Encode() (pkt []byte, err error)

func (*Msg80Receive) GetHeader

func (m *Msg80Receive) GetHeader() *MsgHeader

func (Msg80Receive) GetMsgSN

func (m Msg80Receive) GetMsgSN() string

type Msg80Reply

type Msg80Reply struct {
	Header     *MsgHeader `json:"header"`
	Time       time.Time  `json:"time"`
	Parameters Parameters `json:"parameters"`
}

Parameter Reply

func (*Msg80Reply) Copy

func (m *Msg80Reply) Copy() GBT32960Msg

func (*Msg80Reply) Decode

func (m *Msg80Reply) Decode(packet *PacketData) error

func (*Msg80Reply) Encode

func (m *Msg80Reply) Encode() (pkt []byte, err error)

func (*Msg80Reply) GetHeader

func (m *Msg80Reply) GetHeader() *MsgHeader

func (Msg80Reply) GetMsgSN

func (m Msg80Reply) GetMsgSN() string

func (Msg80Reply) GetTime

func (m Msg80Reply) GetTime() time.Time

type Msg81

type Msg81 struct {
	Header     *MsgHeader `json:"header"`
	Time       time.Time  `json:"time"`
	Parameters Parameters `json:"parameters"`
}

Parameter Set

func (*Msg81) Copy

func (m *Msg81) Copy() GBT32960Msg

func (*Msg81) Decode

func (m *Msg81) Decode(packet *PacketData) error

func (*Msg81) Encode

func (m *Msg81) Encode() (pkt []byte, err error)

func (*Msg81) GetHeader

func (m *Msg81) GetHeader() *MsgHeader

func (Msg81) GetMsgSN

func (m Msg81) GetMsgSN() string

func (Msg81) GetTime

func (m Msg81) GetTime() time.Time

type Msg82

type Msg82 struct {
	Header  *MsgHeader `json:"header"`
	Time    time.Time  `json:"time"`
	Control Control    `json:"control"`
}

Control

func (*Msg82) Copy

func (m *Msg82) Copy() GBT32960Msg

func (*Msg82) Decode

func (m *Msg82) Decode(packet *PacketData) error

func (*Msg82) Encode

func (m *Msg82) Encode() (pkt []byte, err error)

func (*Msg82) GetHeader

func (m *Msg82) GetHeader() *MsgHeader

func (Msg82) GetMsgSN

func (m Msg82) GetMsgSN() string

type MsgComponent

type MsgComponent interface {
	Decode(pkt []byte, idx *int) error
	Encode() (pkt []byte)
}

type MsgHeader

type MsgHeader struct {
	CommandID         uint8           `json:"commandID"`    // command id
	Response          uint8           `json:"responseFlag"` // command response flag
	VIN               string          `json:"VIN"`          // 17 char string
	Encription        uint8           `json:"encription"`   // metode enkripsi
	BodyLength        uint16          `json:"length"`       // panjang body
	Idx               int             `json:"-"`            // Read the PACKET Header.
	TimeCreated       time.Time       `json:"timeCreated"`  // Time msg create
	EncryptKey        *rsa.PublicKey  `json:"encryptKey"`   // key for encrypt
	PrivateEncryptKey *rsa.PrivateKey `json:"privateKey"`   // key for encrypt
}

func GenerateHeader

func GenerateHeader(vin string, cmdID, response uint8) *MsgHeader

func GenerateHeaderWithKey

func GenerateHeaderWithKey(vin string, cmdID, response uint8, rsaPublic *rsa.PublicKey) *MsgHeader

func GenerateHeaderWithKeyNoRSA

func GenerateHeaderWithKeyNoRSA(vin string, cmdID, response uint8, rsaPublic *rsa.PublicKey) *MsgHeader

func (*MsgHeader) Decode

func (m *MsgHeader) Decode(pkt []byte) error

Decoding [] byte into a message head structure

func (*MsgHeader) Encode

func (m *MsgHeader) Encode() (pkt []byte, err error)

Code the message head structure into [] byte

type MsgReply

type MsgReply struct {
	Header *MsgHeader `json:"header"`
	Time   time.Time  `json:"time"`
}

func (*MsgReply) Copy

func (m *MsgReply) Copy() GBT32960Msg

func (*MsgReply) Decode

func (m *MsgReply) Decode(packet *PacketData) error

func (*MsgReply) Encode

func (m *MsgReply) Encode() (pkt []byte, err error)

func (*MsgReply) GetHeader

func (m *MsgReply) GetHeader() *MsgHeader

func (MsgReply) GetMsgSN

func (m MsgReply) GetMsgSN() string

type Msgxx

type Msgxx struct {
	Header *MsgHeader `json:"header"`
	Raw    []byte     `json:"raw"`
}

func (*Msgxx) Copy

func (m *Msgxx) Copy() GBT32960Msg

func (*Msgxx) Decode

func (m *Msgxx) Decode(packet *PacketData) error

func (*Msgxx) Encode

func (m *Msgxx) Encode() (pkt []byte, err error)

func (*Msgxx) GetHeader

func (m *Msgxx) GetHeader() *MsgHeader

func (Msgxx) GetMsgSN

func (m Msgxx) GetMsgSN() string

type PacketData

type PacketData struct {
	Header     *MsgHeader
	Body       []byte
	VerifyCode uint8
}

type ParamProperties added in v0.1.0

type ParamProperties struct {
	GenerateValue func() any // value generator return []byte{}, string(""), uint8, or uint16
	LenID         uint8      // length of value from another id for string / []byte value
	FixedLen      uint8      // fixed length of value for string / []byte value
}

type Parameters

type Parameters map[uint8]any

func (Parameters) Add

func (m Parameters) Add(id uint8, val any) error

func (*Parameters) Decode

func (m *Parameters) Decode(pkt []byte, idx *int) error

func (Parameters) Delete

func (m Parameters) Delete(id uint8)

func (Parameters) Encode

func (m Parameters) Encode() (pkt []byte, err error)

func (Parameters) IsEqual

func (m Parameters) IsEqual(other Parameters) error

type ProcessData

type ProcessData struct {
	Incoming GBT32960Msg // received message
	Outgoing GBT32960Msg // message sent
}

type Reports

type Reports map[uint8]GeneralReport

func (Reports) As01

func (m Reports) As01() (*VehicleData, error)

func (Reports) As02

func (m Reports) As02() (*DriveMotors, error)

func (Reports) As03

func (m Reports) As03() (*FuelCell, error)

func (Reports) As04

func (m Reports) As04() (*Engine, error)

func (Reports) As05

func (m Reports) As05() (*Location, error)

func (Reports) As06

func (m Reports) As06() (*Extreme, error)

func (Reports) As07

func (m Reports) As07() (*Alarm, error)

func (Reports) As08

func (m Reports) As08() (*BatteriesVoltages, error)

func (Reports) As09

func (m Reports) As09() (*BatteriesTemperatures, error)

func (*Reports) Decode

func (m *Reports) Decode(pkt []byte, idx *int) error

func (Reports) Encode

func (m Reports) Encode() (pkt []byte, err error)

func (Reports) MarshalJSON

func (m Reports) MarshalJSON() ([]byte, error)

type VehicleData

type VehicleData struct {
	Status       uint8  `json:"status"`
	Charging     uint8  `json:"charging"`
	OpMode       uint8  `json:"operatingMode"`
	Speed        uint16 `json:"speed"`
	Odometer     uint32 `json:"odometer"`
	TotalVoltage uint16 `json:"totalVoltage"`
	TotalCurrent uint16 `json:"totalCurrent"`
	SoC          uint8  `json:"stateOfCharge"`
	DCDCStatus   uint8  `json:"dcDcStatus"`
	Gear         uint8  `json:"gear"`
	Insulator    uint16 `json:"insulator"`
	Throttle     uint8  `json:"trottle"`
	Brake        uint8  `json:"brake"`
}

func (*VehicleData) Decode

func (m *VehicleData) Decode(pkt []byte, idx *int) error

func (*VehicleData) Encode

func (m *VehicleData) Encode() (pkt []byte, err error)

func (VehicleData) GetID

func (m VehicleData) GetID() uint8

func (*VehicleData) MarshalJSON

func (m *VehicleData) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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