model

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LocationAccuracy = 1000000
	SpeedAccuracy    = 10
)
View Source
const (
	LatitudeTypeBit  uint32 = 0b00000000000000000000000000000100
	LongitudeTypeBit uint32 = 0b00000000000000000000000000001000
)

地理位置信息状态位字段的bit位

View Source
const (
	MsgID0002 = 0x0002
	MsgID0100 = 0x0100
	MsgID0200 = 0x0200
	MsgID8004 = 0x8004
)

Variables

View Source
var (
	ErrDecodeDeviceParams   = errors.New("Fail to decode device params")
	ErrEncodeDeviceParams   = errors.New("Fail to encode device params")
	ErrParamIDNotSupportted = errors.New("Param id is not supportted")
)
View Source
var (
	ErrDecodeHeader = errors.New("Fail to decode header")
	ErrEncodeHeader = errors.New("Fail to encode header")
)
View Source
var (
	ErrDecodeMsg      = errors.New("Fail to decode msg")
	ErrEncodeMsg      = errors.New("Fail to encode msg")
	ErrGenOutgoingMsg = errors.New("Fail to generate outgoing msg")
)
View Source
var (
	ErrDecodeDeviceArgs = errors.New("Fail to decode device args")
)

Functions

This section is empty.

Types

type ArgData

type ArgData struct {
	ArgID    uint32 `json:"argID"`    // 参数ID
	ArgLen   uint8  `json:"argLen"`   // 参数长度
	ArgValue any    `json:"argValue"` // 参数值
}

func (*ArgData) Decode

func (a *ArgData) Decode(_ []byte) error

func (*ArgData) Encode

func (a *ArgData) Encode() (pkt []byte, err error)

type Device

type Device struct {
	ID    string `json:"id"` // ID是否可重复?
	Plate string `json:"plate"`
	Phone string `json:"phone"` // 默认通过PhoneNumber来索引设备

	SessionID      string            `json:"sessionId"`
	TransProto     TransportProtocol `json:"transProto"`
	Conn           net.Conn          `json:"-"`
	Keepalive      time.Duration     `json:"keepalive"`   // 保活时长
	LastestComTime time.Time         `json:"lastComTime"` // 最近一次交互时间
	Status         DeviceStatus      `json:"status"`

	VersionDesc     VersionType `json:"versionDesc"`     // jt808协议版本描述, 区分 2011 / 2013 / 2019
	ProtocolVersion uint8       `json:"protocolVersion"` // jt808协议版本定义, 区分 (2011&2013) / 2019后续版本修订
	AuthCode        string      `json:"authcode"`
	IMEI            string      `json:"imei"`
	SoftwareVersion string      `json:"softwareVersion"` // 终端软件版本号(非jt808协议版本)
}

终端设备的基础属性信息,用于数据缓存、持久化和保活相关流程处理

func NewDevice

func NewDevice(in *Msg0100, session *Session) *Device

func (*Device) ShouldClear

func (d *Device) ShouldClear() bool

func (*Device) ShouleTurnOffline

func (d *Device) ShouleTurnOffline() bool

type DeviceArgs

type DeviceArgs struct {
	ArgCnt uint8      `json:"argCnt"` // 参数项个数
	Args   []*ArgData `json:"args"`   // 参数项列表
	// contains filtered or unexported fields
}

func (*DeviceArgs) Decode

func (a *DeviceArgs) Decode(phone string, cnt uint8, pkt []byte) error

func (*DeviceArgs) Encode

func (a *DeviceArgs) Encode() (pkt []byte, err error)

type DeviceGeo

type DeviceGeo struct {
	Phone    string    `json:"phone"`
	Geo      *GeoMeta  `json:"gis"`
	Location *Location `json:"location"`
	Drive    *Drive    `json:"drive"`
	Time     time.Time `json:"time"`
}

终端设备地理位置状态相关信息

func (*DeviceGeo) Decode

func (dg *DeviceGeo) Decode(phone string, m *Msg0200) error

type DeviceMedia added in v0.3.2

type DeviceMedia struct {
	DeviceMediaQuery
	Size uint32 // 文件大小,单位Byte
}

func (*DeviceMedia) Decode added in v0.3.2

func (m *DeviceMedia) Decode(pkt []byte)

func (*DeviceMedia) Encode added in v0.3.2

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

type DeviceMediaQuery added in v0.3.2

type DeviceMediaQuery struct {
	LogicChannelID uint8      `json:"logicChannelId"` // 逻辑通道号
	StartTime      *time.Time `json:"startTime"`      // 开始时间
	EndTime        *time.Time `json:"endTime"`        // 结束时间
	AlarmSign      uint32     `json:"alarmSign"`      // 报警标志位。bit0-bit31为0x0200的报警标志位,
	AlarmSignExt   uint32     `json:"alarmSignExt"`   // 报警标志位。bit32-bit63?,全0表示无报警类型条件
	MediaType      uint8      `json:"mediaType"`      // 音视频类型。0:音视频;1:音频;2:视频;3:视频或音视频
	StreamType     uint8      `json:"streamType"`     // 码流类型。0:所有码流;1:主码流;2:子码流
	StorageType    uint8      `json:"storageType"`    // 存储器类型。0:所有存储器;1:主存储器;2:灾备存储器
}

func (*DeviceMediaQuery) Decode added in v0.3.2

func (q *DeviceMediaQuery) Decode(pkt []byte, idx *int)

func (*DeviceMediaQuery) Encode added in v0.3.2

func (q *DeviceMediaQuery) Encode() (pkt []byte)

type DeviceParams

type DeviceParams struct {
	DevicePhone string       `json:"-"`        // 关联device phone
	ParamCnt    uint8        `json:"paramCnt"` // 参数项个数
	Params      []*ParamData `json:"params"`   // 参数项列表
}

func (*DeviceParams) Decode

func (p *DeviceParams) Decode(phone string, cnt uint8, pkt []byte) error

func (*DeviceParams) Encode

func (p *DeviceParams) Encode() (pkt []byte, err error)

func (*DeviceParams) Update

func (p *DeviceParams) Update(newParams *DeviceParams)

type DeviceStatus

type DeviceStatus int8
const (
	DeviceStatusOffline  DeviceStatus = 0
	DeviceStatusOnline   DeviceStatus = 1
	DeviceStatusSleeping DeviceStatus = 2
)

type Drive

type Drive struct {
	Speed     float64 `json:"speed"`     // 速度,单位为公里每小时, 精度0.1km/h
	Direction uint16  `json:"direction"` // 方向,0-359,正北为 0,顺时针
}

func (*Drive) Decode

func (d *Drive) Decode(m *Msg0200)

type EncryptionType

type EncryptionType int8

加密类型

const (
	EncryptionUnknown EncryptionType = -1
	EncryptionNone    EncryptionType = 0b000
	EncryptionRSA     EncryptionType = 0b001
)

type FrameCtxKey

type FrameCtxKey struct{}

type GeoMeta

type GeoMeta struct {
	ACCStatus           uint8 `json:"accStatus"`           // bit0, 0:ACC 关;1: ACC 开
	LocationStatus      uint8 `json:"locationStatus"`      // bit1, 0:未定位;1:定位
	LatitudeType        uint8 `json:"latitudeType"`        // bit2, 0:北纬;1:南纬
	LongitudeType       uint8 `json:"longitudeType"`       // bit3, 0:东经;1:西经
	OperatingStatus     uint8 `json:"operatingStatus"`     // bit4, 0:运营状态;1:停运状态
	GeoEncryptionStatus uint8 `json:"geoEncryptionStatus"` // bit5, 0:经纬度未经保密插件加密;1:经纬度已经保密插件加密

	LoadStatus             uint8 `json:"loadStatus"`             // bit8-9, 00:空车;01:半载;10:保留;11:满载 (可用于客车的空、重车及货车的空载、满载状态表示,人工输入或传感器获取)
	FuelSystemStatus       uint8 `json:"FuelSystemStatus"`       // bit10, 0:车辆油路正常;1:车辆油路断开
	AlternatorSystemStatus uint8 `json:"AlternatorSystemStatus"` // bit11, 0:车辆电路正常;1:车辆电路断开
	DoorLockedStatus       uint8 `json:"DoorLockedStatus"`       // bit12, 0:车门解锁;1:车门加锁
	FrontDoorStatus        uint8 `json:"frontDoorStatus"`        // bit13, 0:门1关;1:门1开(前门)
	MidDoorStatus          uint8 `json:"midDoorStatus"`          // bit14, 0:门2关;1:门2开(中门)
	BackDoorStatus         uint8 `json:"backDoorStatus"`         // bit15, 0:门3关;1:门3开(后门)
	DriverDoorStatus       uint8 `json:"driverDoorStatus"`       // bit16, 0:门4关;1:门4开(驾驶席门)
	CustomDoorStatus       uint8 `json:"customDoorStatus"`       // bit17, 0:门5关;1:门5开(自定义)
	GPSLocationStatus      uint8 `json:"gpsLocationStatus"`      // bit18, 0:未使用 GPS 卫星进行定位;1:使用 GPS 卫星进行定位
	BeidouLocationStatus   uint8 `json:"beidouLocationStatus"`   // bit19, 0:未使用北斗卫星进行定位;1:使用北斗卫星进行定位
	GLONASSLocationStatus  uint8 `json:"glonassLocationStatus"`  // bit20, 0:未使用 GLONASS 卫星进行定位;1:使用 GLONASS 卫星进行定位
	GalileoLocationStatus  uint8 `json:"galileoLocationStatus"`  // bit21, 0:未使用 Galileo 卫星进行定位;1:使用 Galileo 卫星进行定位
	DrivingStatus          uint8 `json:"drivingStatus"`          // bit22, 0:车辆处于停止状态;1:车辆处于行驶状态

}

func (*GeoMeta) Decode

func (g *GeoMeta) Decode(status uint32)

输入Msg0200的Status,按照协议解码geoMeta结构体

func (*GeoMeta) Encode

func (g *GeoMeta) Encode() uint32

type IncomingMsgCtxKey

type IncomingMsgCtxKey struct{}

type JT808Msg

type JT808Msg interface {
	Decode(*PacketData) error            // Packet -> JT808Msg
	Encode() (pkt []byte, err error)     // JT808Msg -> Packet
	GetHeader() *MsgHeader               // 获取Header
	GenOutgoing(incoming JT808Msg) error // 根据incoming消息生成outgoing消息
}

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`  // 纬度,精确到百万分之一度
	Longitude float64 `json:"longitude"` // 精度,精确到百万分之一度
	Altitude  uint16  `json:"altitude"`  // 高程,海拔高度,单位为米(m)
}

func (*Location) Decode

func (l *Location) Decode(m *Msg0200)

type Msg0001

type Msg0001 struct {
	Header             *MsgHeader `json:"header"`
	AnswerSerialNumber uint16     `json:"answerSerialNumber"` // 2位,应答流水号,对应平台消息的流水号,
	AnswerMessageID    uint16     `json:"answerMessageId"`    // 2位,应答ID,对应平台消息的ID
	Result             uint8      `json:"result"`             // 1位,结果,0成功/确认,1失败,2消息有误,3不支持
}

终端通用应答

func (*Msg0001) Decode

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

func (*Msg0001) Encode

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

func (*Msg0001) GenOutgoing

func (m *Msg0001) GenOutgoing(incoming JT808Msg) error

func (*Msg0001) GetHeader

func (m *Msg0001) GetHeader() *MsgHeader

type Msg0002

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

终端心跳

func (*Msg0002) Decode

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

func (*Msg0002) Encode

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

func (*Msg0002) GenOutgoing

func (m *Msg0002) GenOutgoing(_ JT808Msg) error

func (*Msg0002) GetHeader

func (m *Msg0002) GetHeader() *MsgHeader

type Msg0003

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

终端注销

func (*Msg0003) Decode

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

func (*Msg0003) Encode

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

func (*Msg0003) GenOutgoing

func (m *Msg0003) GenOutgoing(_ JT808Msg) error

func (*Msg0003) GetHeader

func (m *Msg0003) GetHeader() *MsgHeader

type Msg0004

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

查询服务器时间请求,2019版消息

func (*Msg0004) Decode

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

func (*Msg0004) Encode

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

func (*Msg0004) GenOutgoing

func (m *Msg0004) GenOutgoing(_ JT808Msg) error

func (*Msg0004) GetHeader

func (m *Msg0004) GetHeader() *MsgHeader

type Msg0100

type Msg0100 struct {
	Header         *MsgHeader `json:"header"`
	ProvinceID     uint16     `json:"provinceId"`     // 省域ID,GBT2260 行政区号6位前2位。
	CityID         uint16     `json:"cityId"`         // 市县域ID,GBT2260 行政区号6位后4位
	ManufacturerID string     `json:"manufacturerId"` // 制造商ID
	DeviceMode     string     `json:"deviceMode"`     // 终端型号,2011版本8位,2013版本20位
	DeviceID       string     `json:"deviceId"`       // 终端ID,大写字母和数字

	// 车牌颜色
	//   2013版本按照JT415-2006定义,5.4.12节,0=未上牌,1=蓝,2=黄,3=黑,4=白,9=其他
	//   2019版本按照JT697.7-2014定义,5.6节,0=为上牌,1=蓝,2=黄,3=黑,4=白,5=绿,9=其他
	PlateColor byte `json:"plateColor"`

	PlateNumber  string `json:"plateNumber"`  // 车牌号
	LocationDesc string `json:"locationDesc"` // 省市地域中文名称,通过GBT2260解析
}

终端注册

func (*Msg0100) Decode

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

func (*Msg0100) Encode

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

func (*Msg0100) GenOutgoing

func (m *Msg0100) GenOutgoing(_ JT808Msg) error

func (*Msg0100) GetHeader

func (m *Msg0100) GetHeader() *MsgHeader

type Msg0102

type Msg0102 struct {
	Header          *MsgHeader `json:"header"`
	AuthCodeLen     uint8      `json:"authCodeLen"`     // 鉴权码长度,byte,2019版本有
	AuthCode        string     `json:"authCode"`        // 鉴权码,string
	IMEI            string     `json:"imei"`            // 终端IMEI,byte(15),2019版本有
	SoftwareVersion string     `json:"softwareVersion"` // 软件版本号,byte(20),2019版本有
}

终端鉴权

func (*Msg0102) Decode

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

func (*Msg0102) Encode

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

func (*Msg0102) GenOutgoing

func (m *Msg0102) GenOutgoing(incoming JT808Msg) error

func (*Msg0102) GetHeader

func (m *Msg0102) GetHeader() *MsgHeader

type Msg0104

type Msg0104 struct {
	Header             *MsgHeader    `json:"header"`
	AnswerSerialNumber uint16        `json:"answerSerialNumber"` // 应答流水号,对应平台消息的流水号
	AnswerParamCnt     uint8         `json:"answerParamCnt"`     // 应答参数个数
	Parameters         *DeviceParams `json:"parameters"`         // 参数项列表
}

查询终端参数应答

列表过大时需要分包

func (*Msg0104) Decode

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

func (*Msg0104) Encode

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

func (*Msg0104) GenOutgoing

func (m *Msg0104) GenOutgoing(incoming JT808Msg) error

func (*Msg0104) GetHeader

func (m *Msg0104) GetHeader() *MsgHeader

type Msg0200

type Msg0200 struct {
	Header     *MsgHeader `json:"header"`
	AlarmSign  uint32     `json:"alarmSign"`  // 报警标志位
	StatusSign uint32     `json:"statusSign"` // 状态标志位
	Latitude   uint32     `json:"latitude"`   // 纬度,以度为单位的纬度值乘以10的6次方,精确到百万分之一度
	Longitude  uint32     `json:"longitude"`  // 精度,以度为单位的经度值乘以10的6次方,精确到百万分之一度
	Altitude   uint16     `json:"altitude"`   // 高程,海拔高度,单位为米(m)
	Speed      uint16     `json:"speed"`      // 速度,单位为0.1公里每小时(1/10km/h)
	Direction  uint16     `json:"direction"`  // 方向,0-359,正北为 0,顺时针
	Time       string     `json:"time"`       // YY-MM-DD-hh-mm-ss(GMT+8 时间)
}

位置信息汇报

func (*Msg0200) Decode

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

func (*Msg0200) Encode

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

func (*Msg0200) GenOutgoing

func (m *Msg0200) GenOutgoing(_ JT808Msg) error

func (*Msg0200) GetHeader

func (m *Msg0200) GetHeader() *MsgHeader

type Msg0800 added in v0.3.2

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

todo: 多媒体事件消息上传

func (*Msg0800) Decode added in v0.3.2

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

func (*Msg0800) Encode added in v0.3.2

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

func (*Msg0800) GenOutgoing added in v0.3.2

func (m *Msg0800) GenOutgoing(_ JT808Msg) error

func (*Msg0800) GetHeader added in v0.3.2

func (m *Msg0800) GetHeader() *MsgHeader

type Msg0801 added in v0.3.2

type Msg0801 struct {
	Header              *MsgHeader `json:"header"`
	MultiMediaID        uint32     `json:"multiMediaId"`
	MultiMediaType      uint8      `json:"multiMediaType"`      // 多媒体类型。0:图像;1:音频;2:视频;
	MultiMediaContainer uint8      `json:"multiMediaContainer"` // 多媒体格式编码。0:JPEG;1:TIF;2:MP3;3:WAV;4:WMV; 其他保留
	EventID             uint8      `json:"eventId"`             // 事件项编码。0:平台下发指令;1:定时动作;2:抢劫报警触 发;3:碰撞侧翻报警触发;其他保留
	LogicChannelID      uint8      `json:"logicChannelId"`      // 逻辑通道ID
	GeoAlarmBody        []byte     `json:"geoAlarmBody"`        // 位置信息汇报消息体
	FragmentData        []byte     `json:"fragmentData"`        // 多媒体数据包
}

多媒体数据上传 与JT1078合用时,此消息只上传图片数据

func (*Msg0801) Decode added in v0.3.2

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

func (*Msg0801) Encode added in v0.3.2

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

func (*Msg0801) GenOutgoing added in v0.3.2

func (m *Msg0801) GenOutgoing(_ JT808Msg) error

func (*Msg0801) GetHeader added in v0.3.2

func (m *Msg0801) GetHeader() *MsgHeader

type Msg1205 added in v0.3.2

type Msg1205 struct {
	Header             *MsgHeader `json:"header"`
	AnswerSerialNumber uint16     `json:"answerSerialNumber"` // 流水号,对应查询音视频资源列表消息的流水号
	MediaCount         uint32     `json:"mediaCount"`         // 音视频资源总数
	DeviceMedia
}

JTT1078 终端上传音视频资源列表

列表过大时需要分包

func (*Msg1205) Decode added in v0.3.2

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

func (*Msg1205) Encode added in v0.3.2

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

func (*Msg1205) GenOutgoing added in v0.3.2

func (m *Msg1205) GenOutgoing(incoming JT808Msg) error

func (*Msg1205) GetHeader added in v0.3.2

func (m *Msg1205) GetHeader() *MsgHeader

type Msg8001

type Msg8001 struct {
	Header             *MsgHeader `json:"header"`
	AnswerSerialNumber uint16     `json:"answerSerialNumber"` // 应答流水号,对应平台消息的流水号
	AnswerMessageID    uint16     `json:"answerMessageId"`    // 应答ID,对应平台消息的ID
	Result             ResultCode `json:"result"`             // 结果,0成功/确认,1失败,2消息有误,3不支持
}

平台通用应答

func (*Msg8001) Decode

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

func (*Msg8001) Encode

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

func (*Msg8001) GenOutgoing

func (m *Msg8001) GenOutgoing(incoming JT808Msg) error

func (*Msg8001) GetHeader

func (m *Msg8001) GetHeader() *MsgHeader

type Msg8004

type Msg8004 struct {
	Header     *MsgHeader `json:"header"`
	ServerTime *time.Time `json:"serverTime"`
}

查询服务器时间应答

func (*Msg8004) Decode

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

func (*Msg8004) Encode

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

func (*Msg8004) GenOutgoing

func (m *Msg8004) GenOutgoing(incoming JT808Msg) error

func (*Msg8004) GetHeader

func (m *Msg8004) GetHeader() *MsgHeader

type Msg8100

type Msg8100 struct {
	Header             *MsgHeader     `json:"header"`
	AnswerSerialNumber uint16         `json:"answerSerialNumber"` // 应答流水号,对应平台消息的流水号
	Result             ResultCodeType `json:"result"`             // 结果,0成功,1车辆已被注册,2数据库中无此车辆,3此终端已被注册,4数据库中无此终端
	AuthCode           string         `json:"authCode"`           // 鉴权码
}

终端注册应答消息

func (*Msg8100) Decode

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

func (*Msg8100) Encode

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

func (*Msg8100) GenOutgoing

func (m *Msg8100) GenOutgoing(incoming JT808Msg) error

func (*Msg8100) GetHeader

func (m *Msg8100) GetHeader() *MsgHeader

type Msg8103

type Msg8103 struct {
	Header     *MsgHeader    `json:"header"`
	ParamCnt   uint8         `json:"paramCnt"`   // 参数个数
	Parameters *DeviceParams `json:"parameters"` // 参数项列表
}

设置终端参数

func (*Msg8103) Decode

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

client接收到消息,解析为结构体

func (*Msg8103) Encode

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

server端发送8103消息,编码为字节数组

func (*Msg8103) GenOutgoing

func (m *Msg8103) GenOutgoing(_ JT808Msg) error

func (*Msg8103) GetHeader

func (m *Msg8103) GetHeader() *MsgHeader

type Msg8104

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

查询终端参数

func (*Msg8104) Decode

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

func (*Msg8104) Encode

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

func (*Msg8104) GenOutgoing

func (m *Msg8104) GenOutgoing(_ JT808Msg) error

func (*Msg8104) GetHeader

func (m *Msg8104) GetHeader() *MsgHeader

type Msg8800 added in v0.3.2

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

多媒体数据上传应答

func (*Msg8800) Decode added in v0.3.2

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

func (*Msg8800) Encode added in v0.3.2

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

func (*Msg8800) GenOutgoing added in v0.3.2

func (m *Msg8800) GenOutgoing(_ JT808Msg) error

func (*Msg8800) GetHeader added in v0.3.2

func (m *Msg8800) GetHeader() *MsgHeader

type Msg9205 added in v0.3.2

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

JT1078 查询资源列表

func (*Msg9205) Decode added in v0.3.2

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

func (*Msg9205) Encode added in v0.3.2

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

func (*Msg9205) GenOutgoing added in v0.3.2

func (m *Msg9205) GenOutgoing(_ JT808Msg) error

func (*Msg9205) GetHeader added in v0.3.2

func (m *Msg9205) GetHeader() *MsgHeader

type MsgBodyAttr

type MsgBodyAttr struct {
	BodyLength       uint16 `json:"bodyLength"`       // 消息体长度
	Encryption       uint8  `json:"encryption"`       // 加密类型
	PacketFragmented uint8  `json:"packetFragmented"` // 分包标识,1:长消息,有分包;2:无分包
	VersionSign      uint8  `json:"versionSign"`      // 版本标识,1:2019版本;0:2013版本
	Extra            uint8  `json:"extra"`            // 预留一个bit位的保留字段

	EncryptionDesc       EncryptionType       `json:"encryptionDesc"`       // 加密类型描述
	PacketFragmentedDesc PacketFragmentedType `json:"packetFragmentedDesc"` // 是否分包描述
	VersionDesc          VersionType          `json:"versionDesc"`          // 版本类型描述
}

定义消息体属性

func (*MsgBodyAttr) Decode

func (attr *MsgBodyAttr) Decode(bitNum uint16) error

func (*MsgBodyAttr) Encode

func (attr *MsgBodyAttr) Encode() uint16

type MsgFragmentation

type MsgFragmentation struct {
	Total uint16 `json:"total"` // 分包后的包总数
	Index uint16 `json:"index"` // 包序号,从1开始
}

定义分包的封装项

func (*MsgFragmentation) Decode

func (frag *MsgFragmentation) Decode(pkt []byte, idx *int) error

func (*MsgFragmentation) Encode

func (frag *MsgFragmentation) Encode() []byte

type MsgHeader

type MsgHeader struct {
	MsgID           uint16            `json:"msgID"`           // 消息ID
	Attr            *MsgBodyAttr      `json:"attr"`            // 消息体属性
	ProtocolVersion uint8             `json:"protocolVersion"` // 协议版本号,默认0表示2011/2013版本,其他为2019后续版本,每次修订递增,初始为1
	PhoneNumber     string            `json:"phoneNumber"`     // 终端手机号,
	SerialNumber    uint16            `json:"serialNumber"`    // 消息流水号
	Frag            *MsgFragmentation `json:"frag"`            // 消息包封装项

	Idx int `json:"-"` // 读取的packet header下标ID
}

定义消息头

func GenMsgHeader

func GenMsgHeader(d *Device, msgID, serialNumber uint16) *MsgHeader

func (*MsgHeader) Decode

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

将[]byte解码成消息头结构体

func (*MsgHeader) Encode

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

将消息头结构体编码成[]byte

func (*MsgHeader) GetRawJt808Version

func (h *MsgHeader) GetRawJt808Version() uint8

func (*MsgHeader) GetVersionDesc

func (h *MsgHeader) GetVersionDesc() VersionType

func (*MsgHeader) IsFragmented added in v0.3.2

func (h *MsgHeader) IsFragmented() bool

type OutgoingMsgCtxKey

type OutgoingMsgCtxKey struct{}

type PacketData

type PacketData struct {
	Header       *MsgHeader // 消息头
	Body         []byte     // 消息体
	VerifyCode   byte       // 校验码
	SegCompleted bool       // 是否分包传输结束
}

定义Packet Data结构

type PacketDecodeCtxKey

type PacketDecodeCtxKey struct{}

type PacketEncodeCtxKey

type PacketEncodeCtxKey struct{}

type PacketFragmentedType

type PacketFragmentedType bool
const (
	PacketFragmentedFalse PacketFragmentedType = false
	PacketFragmentedTrue  PacketFragmentedType = true
)

type ParamData

type ParamData struct {
	ParamID    uint32 `json:"paramId"`    // 参数ID
	ParamLen   uint8  `json:"paramLen"`   // 参数长度
	ParamValue any    `json:"paramValue"` // 参数值
}

func (*ParamData) Decode

func (p *ParamData) Decode(pkt []byte, idx *int) error

func (*ParamData) Encode

func (p *ParamData) Encode() (pkt []byte, err error)

type ProcessData

type ProcessData struct {
	Incoming JT808Msg // 收到的消息
	Outgoing JT808Msg // 发出的消息, 无需回复时可为nil
}

定义消息处理结果数据

type ProcessDataCtxKey

type ProcessDataCtxKey struct{}

type ResultCode

type ResultCode uint8
const (
	ResultSuccess      ResultCode = 0
	ResultFail         ResultCode = 1
	ResultErrMsg       ResultCode = 2
	ResultNotSupported ResultCode = 3
)

type ResultCodeType

type ResultCodeType byte
const (
	ResSuccess               ResultCodeType = 0
	ResCarAlreadyRegister    ResultCodeType = 1
	ResCarNotExist           ResultCodeType = 2
	ResDeviceAlreadyRegister ResultCodeType = 3
	ResDeviceNotExist        ResultCodeType = 4
)

type Segment added in v0.3.2

type Segment struct {
	Phone    string `json:"phone"`
	MsgID    uint16 `json:"msgId"`
	SegTotal uint16 `json:"total"`
	SegNo    uint16 `json:"no"`
	Data     []byte `json:"data"`
}

分包消息结构

func NewSegment added in v0.3.2

func NewSegment(pd *PacketData) *Segment

func (*Segment) IsComplete added in v0.3.2

func (s *Segment) IsComplete() bool

func (*Segment) Merge added in v0.3.2

func (s *Segment) Merge(ns *Segment)

type Session

type Session struct {
	ID   string // remote addr
	Conn net.Conn
	// contains filtered or unexported fields
}

func (*Session) GetNextSerialNum

func (s *Session) GetNextSerialNum() uint16

func (*Session) GetTransProto

func (s *Session) GetTransProto() TransportProtocol

type SessionCtxKey

type SessionCtxKey struct{} // 定义全局session context key

type TransportProtocol

type TransportProtocol string
const (
	TCPProto TransportProtocol = "TCP"
	UDPProto TransportProtocol = "UDP"
)

type VersionType

type VersionType int8
const (
	Version2011 VersionType = 0
	Version2013 VersionType = 1
	Version2019 VersionType = 2
)

Jump to

Keyboard shortcuts

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