jt808

package module
v0.0.0-...-4b82122 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 9 Imported by: 0

README

jt808

JT808 协议Golang 实现

Documentation

Index

Constants

View Source
const (
	ResultSuccess     byte = 0x00
	ResultFailure     byte = 0x01
	ResultError       byte = 0x02
	ResultUnsupported byte = 0x03
	ResultWarnning    byte = 0x04
)
View Source
const (
	MsgHeadMuxMask        = 0x2000
	MsgHeadCryptoMask     = 0x0400
	MsgHeadBodyLengthMask = 0x03ff
)
View Source
const (
	// 终端通用应答
	MsgIdTerminalCommonResp uint16 = 0x0001
	// 终端心跳
	MsgIdTerminalHeartBeat uint16 = 0x0002
	// 终端注册
	MsgIdTerminalLogin uint16 = 0x0100
	// 终端注销
	MsgIdTerminalLogOut uint16 = 0x0003
	// 终端鉴权
	MsgIdTerminalAuthentication uint16 = 0x0102
	// 位置信息汇报
	MsgIdTerminalLocationInfoUpload uint16 = 0x0200
	// 胎压数据透传
	MsgIdTerminalTransmissionTyrePressure uint16 = 0x0600
	// 查询终端参数应答
	MsgIdTerminalParamQueryResp uint16 = 0x0104
)
View Source
const (
	// 平台通用应答
	MsgCmdCommonResp uint16 = 0x8001
	// 终端注册应答
	MsgCmdTerminalRegisterResp uint16 = 0x8100
	// 设置终端参数
	MsgCmdTerminalParamSettings uint16 = 0X8103
	// 查询终端参数
	MsgCmdTerminalParamQuery uint16 = 0x8104
)
View Source
const (
	FlagAcc      = 0x0001
	FlagLoc      = 0x0002
	FlagSouthLat = 0x0004
	FlagWestLng  = 0x0008
)

Variables

View Source
var EmptyRespMsg *emptyRespMsg = new(emptyRespMsg)
View Source
var (
	ErrContinue error = errors.New("err continue")
)
View Source
var (
	ErrNotSupport = fmt.Errorf("Not Support")
)

Functions

func JT808SendMsg

func JT808SendMsg(writer io.Writer, msghead, msgbody encoding.BinaryMarshaler) error

func JT808Split

func JT808Split(data []byte, atEOF bool) (int, []byte, error)

func NewCommonMsgResp

func NewCommonMsgResp(flowID, respID uint16, result byte, phoneNo []byte) (*MsgRespHead, *CommonRespMsg)

func NewScanner

func NewScanner(r io.Reader) *bufio.Scanner

func Processor

func Processor(w io.Writer, raw []byte, h Handler) error

func Restore

func Restore(bs []byte) ([]byte, error)

func TimeFlowID

func TimeFlowID() uint16

Types

type AuthMsg

type AuthMsg struct {
	AuthCode string
}

func DecodeAuthMsg

func DecodeAuthMsg(head *MsgHead, bd *BufDecoder) (*AuthMsg, error)

type BufDecoder

type BufDecoder struct {
	// contains filtered or unexported fields
}

func NewBufDecoder

func NewBufDecoder(bs []byte) *BufDecoder

func (*BufDecoder) BCD

func (d *BufDecoder) BCD(n int) (string, error)

func (*BufDecoder) Read

func (d *BufDecoder) Read(bs []byte) (int, error)

func (*BufDecoder) ReadByte

func (d *BufDecoder) ReadByte() (byte, error)

func (*BufDecoder) Uint16

func (d *BufDecoder) Uint16() (uint16, error)

func (*BufDecoder) Uint32

func (d *BufDecoder) Uint32() (uint32, error)

func (*BufDecoder) Uint64

func (d *BufDecoder) Uint64() (uint64, error)

type CommonRespMsg

type CommonRespMsg struct {
	FlowID     uint16
	ResponseID uint16
	Result     byte
}

func NewCommonRespMsg

func NewCommonRespMsg(f, r uint16, result byte) *CommonRespMsg

func (*CommonRespMsg) Len

func (msg *CommonRespMsg) Len() uint16

func (*CommonRespMsg) MarshalBinary

func (msg *CommonRespMsg) MarshalBinary() ([]byte, error)

type DefaultHandler

type DefaultHandler struct{}

func NewDefaultHandler

func NewDefaultHandler() *DefaultHandler

func (*DefaultHandler) Auth

func (h *DefaultHandler) Auth(w io.Writer, head *MsgHead, body *AuthMsg) error

func (*DefaultHandler) Err

func (h *DefaultHandler) Err(w io.Writer, err error) error

func (*DefaultHandler) Heartbeat

func (h *DefaultHandler) Heartbeat(w io.Writer, head *MsgHead) error

func (*DefaultHandler) Login

func (h *DefaultHandler) Login(w io.Writer, head *MsgHead, body *LoginMsg) error

func (*DefaultHandler) Logout

func (h *DefaultHandler) Logout(w io.Writer, head *MsgHead) error

func (*DefaultHandler) OtherMsg

func (h *DefaultHandler) OtherMsg(w io.Writer, head *MsgHead, bd *BufDecoder) error

func (*DefaultHandler) Raw

func (h *DefaultHandler) Raw(raw []byte)

func (*DefaultHandler) TerminalCommonResp

func (h *DefaultHandler) TerminalCommonResp(head *MsgHead, body *TerminalCommonRespBody) error

func (*DefaultHandler) UploadLocation

func (handler *DefaultHandler) UploadLocation(w io.Writer, head *MsgHead, body *LocMsg) error

type Handler

type Handler interface {
	Raw(raw []byte)
	TerminalCommonResp(head *MsgHead, body *TerminalCommonRespBody) error
	Heartbeat(w io.Writer, head *MsgHead) error
	Login(w io.Writer, head *MsgHead, body *LoginMsg) error
	Logout(w io.Writer, head *MsgHead) error
	Auth(w io.Writer, head *MsgHead, body *AuthMsg) error
	UploadLocation(w io.Writer, head *MsgHead, body *LocMsg) error

	Err(w io.Writer, err error) error

	OtherMsg(w io.Writer, head *MsgHead, bd *BufDecoder) error
}

type LocMsg

type LocMsg struct {
	Warn   uint32
	Status uint32

	Lat       uint32
	Lng       uint32
	Elevation uint16
	Speed     uint16
	Direction uint16

	UploadTime string
}

func DecodeLocMsg

func DecodeLocMsg(head *MsgHead, bd *BufDecoder) (*LocMsg, error)

type LoginMsg

type LoginMsg struct {
	ProvinceID uint16
	CityID     uint16

	ManufacturerID string
	TerminalType   string
	TerminalID     string

	VehicleColor uint16
	VehicleNo    string
}

func DecodeLoginMsg

func DecodeLoginMsg(head *MsgHead, bd *BufDecoder) (*LoginMsg, error)

type LoginRespMsg

type LoginRespMsg struct {
	FlowID   uint16
	Result   byte
	AuthCode string
}

func NewLoginRespMsg

func NewLoginRespMsg(fid uint16, result byte, code string) *LoginRespMsg

func (*LoginRespMsg) Len

func (msg *LoginRespMsg) Len() uint16

func (*LoginRespMsg) MarshalBinary

func (msg *LoginRespMsg) MarshalBinary() ([]byte, error)

type MsgHead

type MsgHead struct {
	MsgID    uint16
	Property uint16
	PhoneNo  string
	FlowID   uint16

	Crypto     bool
	BodyLength uint16
	Mux        bool

	PhoneNoBCD []byte

	TotalNumberPackets uint16
	PacketSerialNumber uint16
}

func DecodeMsgHead

func DecodeMsgHead(bd *BufDecoder) (*MsgHead, error)

type MsgRespHead

type MsgRespHead struct {
	MsgID    uint16
	Property uint16
	PhoneNo  []byte
	FlowID   uint16
}

func NewMsgRespHead

func NewMsgRespHead(msgID, property, flowID uint16, phoneNo []byte) *MsgRespHead

func (*MsgRespHead) MarshalBinary

func (msg *MsgRespHead) MarshalBinary() ([]byte, error)

type TerminalCommonRespBody

type TerminalCommonRespBody struct {
	FlowID     uint16
	ResponseID uint16
	Result     byte
}

func DecodeTerminalCommonRespBody

func DecodeTerminalCommonRespBody(head *MsgHead, bd *BufDecoder) (*TerminalCommonRespBody, error)

Jump to

Keyboard shortcuts

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