添加测试代码;增加bj-rtss-message作为git子模块
This commit is contained in:
parent
1c878c2962
commit
617b0b66b8
|
@ -0,0 +1,3 @@
|
|||
[submodule "bj-rtss-message"]
|
||||
path = bj-rtss-message
|
||||
url = https://git.code.tencent.com/beijing-rtss-test/bj-rtss-message.git
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package dynamics
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -7,21 +7,21 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github.com/panjf2000/gnet/v2"
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"joylink.club/bj-rtsts-server/dynamics"
|
||||
"log"
|
||||
"net"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 这里用来测试通信与数据传输是否正常
|
||||
|
||||
func main() {
|
||||
func TestAll(t *testing.T) {
|
||||
loadAndChangeConfig()
|
||||
//注册列车信息处理逻辑
|
||||
dynamics.RegisterTrainInfoHandler(&ExampleTrainInfoHandler{})
|
||||
RegisterTrainInfoHandler(&ExampleTrainInfoHandler{})
|
||||
//启动udp服务
|
||||
go dynamics.RunUdpServer()
|
||||
go RunUdpServer()
|
||||
////启动仅用于的测试的模拟远程udp服务
|
||||
go runTestUdpServer()
|
||||
////启动http服务
|
||||
|
@ -30,9 +30,9 @@ func main() {
|
|||
//向本地udp服务发送数据
|
||||
sendDataToLocalUdpServer()
|
||||
//向远程udp服务发送数据
|
||||
_ = dynamics.SendTurnoutInfo(&dynamics.TurnoutInfo{Code: 02})
|
||||
_ = SendTurnoutInfo(&TurnoutInfo{Code: 02})
|
||||
//发送http请求
|
||||
_, _, _ = dynamics.SendTrainInitReq(&dynamics.InitTrainInfo{Speed: 10})
|
||||
_, _, _ = SendTrainInitReq(&InitTrainInfo{Speed: 10})
|
||||
}
|
||||
|
||||
func loadAndChangeConfig() {
|
||||
|
@ -52,7 +52,7 @@ func sendDataToLocalUdpServer() {
|
|||
func runTestHttpServer() {
|
||||
engine := gin.Default()
|
||||
engine.POST("/api/aerodynamics/init/train", func(context *gin.Context) {
|
||||
info := dynamics.InitTrainInfo{}
|
||||
info := InitTrainInfo{}
|
||||
err := context.ShouldBindJSON(&info)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
|
@ -95,7 +95,7 @@ func (server *testUdpServer) OnTraffic(c gnet.Conn) gnet.Action {
|
|||
type ExampleTrainInfoHandler struct {
|
||||
}
|
||||
|
||||
func (handler *ExampleTrainInfoHandler) HandleTrainInfo(info dynamics.TrainInfo) {
|
||||
func (handler *ExampleTrainInfoHandler) HandleTrainInfo(info TrainInfo) {
|
||||
fmt.Println("处理列车信息...")
|
||||
fmt.Println(info)
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package dynamics
|
||||
|
||||
import (
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSendTrainInitReq(t *testing.T) {
|
||||
config.LoadConfig()
|
||||
SendTrainInitReq(&InitTrainInfo{
|
||||
TrainIndex: 1,
|
||||
LinkIndex: 2,
|
||||
LinkOffset: 3,
|
||||
Speed: 4,
|
||||
Up: true,
|
||||
})
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package dynamics
|
||||
|
||||
import (
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunUdpServer(t *testing.T) {
|
||||
config.LoadConfig()
|
||||
RegisterTrainInfoHandler(&ExampleTrainInfoHandler{})
|
||||
RunUdpServer()
|
||||
}
|
||||
|
||||
func TestSendTurnoutInfo(t *testing.T) {
|
||||
config.LoadConfig()
|
||||
SendTurnoutInfo(&TurnoutInfo{
|
||||
Code: 2,
|
||||
NPosition: true,
|
||||
RPosition: false,
|
||||
})
|
||||
}
|
|
@ -6,9 +6,10 @@ server:
|
|||
port: 8080
|
||||
# 动力学端口配置
|
||||
dynamics:
|
||||
ip: 127.0.0.1
|
||||
ip: 192.168.3.5
|
||||
udpLocalPort: 4000
|
||||
udpRemotePort: 3000
|
||||
httpPort: 9092
|
||||
|
||||
# 数据源
|
||||
datasource:
|
||||
|
|
Loading…
Reference in New Issue