-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
46 lines (41 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"github.com/cuteLittleDevil/go-jt808/attachment"
"github.com/cuteLittleDevil/go-jt808/service"
"github.com/cuteLittleDevil/go-jt808/shared/consts"
"log/slog"
"os"
)
var goJt808 *service.GoJT808
func init() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
ReplaceAttr: nil,
}))
slog.SetDefault(logger)
attach := attachment.New(
attachment.WithNetwork("tcp"),
attachment.WithHostPorts("0.0.0.0:10001"),
attachment.WithActiveSafetyType(consts.ActiveSafetyJS), // 默认苏标 支持黑标 广东标 湖南标 四川标
attachment.WithFileEventerFunc(func() attachment.FileEventer {
return &meFileEvent{} // 自定义文件处理 开始 结束 当前进度 补传 完成等事件
}),
)
go attach.Run()
}
func main() {
goJt808 = service.New(
service.WithHostPorts("0.0.0.0:808"),
service.WithNetwork("tcp"),
service.WithCustomTerminalEventer(func() service.TerminalEventer {
return &meTerminal{} // 自定义终端事件 终端进入 离开 读写报文事件
}),
service.WithCustomHandleFunc(func() map[consts.JT808CommandType]service.Handler {
return map[consts.JT808CommandType]service.Handler{
consts.T0200LocationReport: &meLocation{}, // 自定义0x0200位置解析等
}
}),
)
goJt808.Run()
}