rts-sim-testing-service/third_party/acc/acc_server_test.go

29 lines
531 B
Go
Raw Normal View History

2024-01-26 17:57:35 +08:00
package acc
import (
"encoding/json"
"fmt"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/udp"
"testing"
)
func TestAccUdp(t *testing.T) {
2024-01-29 14:22:12 +08:00
fmt.Println("准备启动ACC服务...")
2024-04-19 16:55:51 +08:00
addr := fmt.Sprintf("%v:%v", "127.0.0.1", "9998")
2024-01-26 17:57:35 +08:00
server := udp.NewServer(addr, handle)
server.Listen()
2024-01-29 18:05:14 +08:00
select {}
2024-01-26 17:57:35 +08:00
}
func handle(d []byte) {
2024-01-29 14:22:12 +08:00
ri := message.Accelerometer{}
2024-01-26 17:57:35 +08:00
err := ri.Decode(d)
if err == nil {
jsonD, _ := json.Marshal(ri)
2024-04-19 16:55:51 +08:00
fmt.Println("接受数据:", string(jsonD))
2024-01-26 17:57:35 +08:00
}
}