Coder Social home page Coder Social logo

jt808-golang's Introduction

Build Status

部分实现和测试用例参考 https://github.com/SmallChi/JT808

Project is WIP

消息定义

type Body0001 struct {
	AcknowledgeMessageID uint16 `jt808:""`
	AcknowledgeSerialID  uint16 `jt808:""`
	AcknowledgeType      uint8  `jt808:""`
}

结构体字段顺序按照序列化的先后顺序。

字段类型映射

Golang 类型 协议数据类型 tag定义
uint8 byte
uint16 word
uint32 dword
[]byte byte[n] n,none
string bcd[n] n,bcd
string string n,gbk

复杂类型解析

./jt808/message/0200.go 。先将消息解析为 []byte 类型,然后在结构体中增加方法单独解析。

分包消息解析

如果消息头部中包含分包信息MessagePack.Package,则消息正文会被解析为message.PartialPackBody。 待消息全部接收完成后,使用 jt808.ConcatUnmarshal(...packs *MessagePack) 方法一并进行解析。

详情见 ./jt808/decoder_test.go:40 中的测试用例。

完成情况

消息ID 完成情况 测试覆盖 中文说明 备注
0x0001 [x] [x] 终端通用应答
0x0200 [x] [x] 位置信息汇报
0x0801 [x] [x] 多媒体数据上传

Benchmark

> go version
go version go1.14.6 darwin/amd64

> sysctl -a | grep machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz

> go test -bench=. -benchmem  ./...
BenchmarkUnmarshal0001-4   	  850024	      1380 ns/op	     392 B/op	      23 allocs/op

jt808-golang's People

Contributors

francistm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.