Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

报文解析问题 #1

Open
fxk2006 opened this issue Nov 13, 2024 · 2 comments
Open

报文解析问题 #1

fxk2006 opened this issue Nov 13, 2024 · 2 comments

Comments

@fxk2006
Copy link

fxk2006 commented Nov 13, 2024

1、使用您模拟器example/simulator/client/main.go
2、发送注册请求0x0100时,报"body length inconsistency"
原始报文:7e010000300000000015580001001f006e63643132337777772e3830382e636f6d0000000000000000003736353433323101b2e2413132333435363738357e
问题定位:jt808.go第98行,打印出来的start=12,j.Header.Property.BodyDayaLen=48,end+1=61,len(escapeData) =85

image

@cuteLittleDevil
Copy link
Owner

c6c0adfe2962971ae7f287afeeec81b1 可能是老版本的有问题 目前用最新版本的这个报文是正常的
package main

import (
	"encoding/hex"
	"fmt"
	"github.com/cuteLittleDevil/go-jt808/protocol/jt808"
	"github.com/cuteLittleDevil/go-jt808/protocol/model"
)

func main() {
	msg := "7e010000300000000015580001001f006e63643132337777772e3830382e636f6d0000000000000000003736353433323101b2e2413132333435363738357e"
	jtMsg := jt808.NewJTMessage()
	data, _ := hex.DecodeString(msg)
	fmt.Println(jtMsg.Decode(data))
	var t0x100 model.T0x0100
	fmt.Println(t0x100.Parse(jtMsg))
	fmt.Println(t0x100.String())
}

@cuteLittleDevil
Copy link
Owner

1、使用您模拟器example/simulator/client/main.go 2、发送注册请求0x0100时,报"body length inconsistency" 原始报文:7e010000300000000015580001001f006e63643132337777772e3830382e636f6d0000000000000000003736353433323101b2e2413132333435363738357e 问题定位:jt808.go第98行,打印出来的start=12,j.Header.Property.BodyDayaLen=48,end+1=61,len(escapeData) =85问题定位:jt808.go第98行,打印出来的start=12,j.Header.Property.BodyDayaLen=48,end+1=61,len(escapeData) =85

image

模拟器 example/simulator/client/main.go 这个我直接在本机跑也是没问题的

  1. 在main.go 加服务器端代码
type meRegister struct {
	model.T0x0100
}

func (m *meRegister) OnReadExecutionEvent(message *service.Message) {
	fmt.Println("注册信息", message.Header.TerminalPhoneNo)
	var t0x0100 model.T0x0100
	fmt.Println(t0x0100.Parse(message.JTMessage))
	fmt.Println(t0x0100.String())
}

func (m *meRegister) OnWriteExecutionEvent(message service.Message) {}

func init() {
	goJt808 := service.New(
		service.WithHostPorts("0.0.0.0:8080"),
		service.WithNetwork("tcp"),
		service.WithCustomHandleFunc(func() map[consts.JT808CommandType]service.Handler {
			return map[consts.JT808CommandType]service.Handler{
				consts.T0100Register: &meRegister{},
			}
		}),
	)
	go goJt808.Run()
}
  1. 在本机跑 使用的是默认的go mod
    https://github.com/cuteLittleDevil/go-jt808/blob/main/example/simulator/go.mod
go build
 ./client -ip=192.168.31.231 -max=2
1 iShot_2024-11-13_20 25 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants