29 lines
531 B
Go
29 lines
531 B
Go
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) {
|
|
|
|
fmt.Println("准备启动ACC服务...")
|
|
addr := fmt.Sprintf("%v:%v", "127.0.0.1", "9998")
|
|
server := udp.NewServer(addr, handle)
|
|
server.Listen()
|
|
select {}
|
|
}
|
|
|
|
func handle(d []byte) {
|
|
ri := message.Accelerometer{}
|
|
err := ri.Decode(d)
|
|
if err == nil {
|
|
|
|
jsonD, _ := json.Marshal(ri)
|
|
fmt.Println("接受数据:", string(jsonD))
|
|
}
|
|
}
|