rts-sim-testing-service/tmp/proto_test.go

87 lines
2.3 KiB
Go
Raw Normal View History

2023-12-20 10:37:54 +08:00
package memory_test
import (
"fmt"
"log/slog"
"testing"
"time"
"google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/ts/protos/state"
)
func TestTrainProto(t *testing.T) {
st := &state.TrainState{
Id: "1",
TrainLength: 96000,
Show: true,
HeadDeviceId: 682,
HeadOffset: 1017073,
PointTo: true,
RunDirection: true,
HeadDirection: true,
DynamicState: &state.TrainDynamicState{
Heartbeat: 24512,
HeadLinkId: "9",
HeadLinkOffset: 1095653,
TailLinkId: "9",
TailLinkOffset: 999653,
Slope: 5290,
RunningUp: true,
RunningResistanceSum: 1.787,
AirResistance: 9.136,
RampResistance: -8.295,
CurveResistance: 0.947,
Speed: 8011,
HeadSensorSpeed1: 8011,
HeadSensorSpeed2: 8011,
TailSensorSpeed1: 8011,
TailSensorSpeed2: 8011,
Acceleration: -0.011171325,
},
VobcState: &state.TrainVobcState{
LifeSignal: 23457,
Tc2Active: true,
TractionForce: 9040,
BrakeForce: 9040,
TrainLoad: 16000,
UpdateTime: 1702534082337,
},
TrainKilometer: 126984703,
ControlDelayTime: 22,
WheelDiameter: 800,
}
stopTime := time.Now().Add(5 * time.Second)
for {
if stopTime.Before(time.Now()) {
break
}
st.VobcState.UpdateTime = time.Now().Unix()
d, err := proto.Marshal(st)
if err != nil {
slog.Error("转换出错", err)
}
fmt.Println(d)
time.Sleep(20 * time.Millisecond)
}
// st2 := &state.TrainState{}
// dd := []byte{
// 10, 1, 49, 32, 128, 238, 5, 40, 1, 48, 170, 5, 56, 241, 137,
// 62, 72, 1, 80, 1, 88, 1, 98, 67, 8, 192, 191, 1, 18, 1, 57, 24,
// 229, 239, 66, 34, 1, 57, 40, 229, 129, 61, 56, 170, 41, 72, 1,
// 85, 106, 188, 228, 63, 93, 14, 45, 18, 65, 101, 82, 184, 4, 193,
// 109, 152, 110, 114, 63, 112, 203, 62, 120, 203, 62, 128, 1, 203,
// 62, 136, 1, 203, 62, 144, 1, 203, 62, 181, 1, 239, 7, 55, 188, 106,
// 35, 8, 161, 183, 1, 24, 1, 32, 1, 72, 1, 112, 1, 128, 1, 1, 136, 1, 208,
// 70, 144, 1, 208, 70, 152, 1, 128, 125, 208, 1, 247, 223, 193, 183,
// 198, 49, 112, 255, 195, 198, 60, 120, 22, 128, 1, 160, 6,
// }
// err2 := proto.Unmarshal(dd, st2)
// if err2 != nil {
// slog.Error("转换出错", err2)
// }
// fmt.Println(st2)
}