【发送给前端的速度修改int】

This commit is contained in:
weizhihong 2023-09-05 15:12:11 +08:00
parent 453b0bcafa
commit 31da644b0e
5 changed files with 600 additions and 530 deletions

File diff suppressed because it is too large Load Diff

View File

@ -607,19 +607,19 @@ type TrainDynamicState struct {
// 阻力3曲线阻力NcurveResistance,1=1KN
CurveResistance float32 `protobuf:"fixed32,13,opt,name=curveResistance,proto3" json:"curveResistance,omitempty"`
// 列车运行速度m/sspeed,1=1km/h
Speed float32 `protobuf:"fixed32,14,opt,name=speed,proto3" json:"speed,omitempty"`
Speed int32 `protobuf:"varint,14,opt,name=speed,proto3" json:"speed,omitempty"`
// 头车速传1速度值m/sheadSpeed1,1=1km/h
HeadSensorSpeed1 float32 `protobuf:"fixed32,15,opt,name=headSensorSpeed1,proto3" json:"headSensorSpeed1,omitempty"`
HeadSensorSpeed1 int32 `protobuf:"varint,15,opt,name=headSensorSpeed1,proto3" json:"headSensorSpeed1,omitempty"`
// 头车速度2速度值m/sheadSpeed2,1=1km/h
HeadSensorSpeed2 float32 `protobuf:"fixed32,16,opt,name=headSensorSpeed2,proto3" json:"headSensorSpeed2,omitempty"`
HeadSensorSpeed2 int32 `protobuf:"varint,16,opt,name=headSensorSpeed2,proto3" json:"headSensorSpeed2,omitempty"`
// 尾车速传1速度值m/stailSpeed1,1=1km/h
TailSensorSpeed1 float32 `protobuf:"fixed32,17,opt,name=tailSensorSpeed1,proto3" json:"tailSensorSpeed1,omitempty"`
TailSensorSpeed1 int32 `protobuf:"varint,17,opt,name=tailSensorSpeed1,proto3" json:"tailSensorSpeed1,omitempty"`
// 尾车速度2速度值m/stailSpeed2,1=1km/h
TailSensorSpeed2 float32 `protobuf:"fixed32,18,opt,name=tailSensorSpeed2,proto3" json:"tailSensorSpeed2,omitempty"`
TailSensorSpeed2 int32 `protobuf:"varint,18,opt,name=tailSensorSpeed2,proto3" json:"tailSensorSpeed2,omitempty"`
// 头车雷达速度值m/sheadRadarSpeed,1=1km/h
HeadRadarSpeed float32 `protobuf:"fixed32,19,opt,name=headRadarSpeed,proto3" json:"headRadarSpeed,omitempty"`
HeadRadarSpeed int32 `protobuf:"varint,19,opt,name=headRadarSpeed,proto3" json:"headRadarSpeed,omitempty"`
// 尾车雷达速度值m/stailRadarSpeed,1=1km/h
TailRadarSpeed float32 `protobuf:"fixed32,20,opt,name=tailRadarSpeed,proto3" json:"tailRadarSpeed,omitempty"`
TailRadarSpeed int32 `protobuf:"varint,20,opt,name=tailRadarSpeed,proto3" json:"tailRadarSpeed,omitempty"`
}
func (x *TrainDynamicState) Reset() {
@ -745,49 +745,49 @@ func (x *TrainDynamicState) GetCurveResistance() float32 {
return 0
}
func (x *TrainDynamicState) GetSpeed() float32 {
func (x *TrainDynamicState) GetSpeed() int32 {
if x != nil {
return x.Speed
}
return 0
}
func (x *TrainDynamicState) GetHeadSensorSpeed1() float32 {
func (x *TrainDynamicState) GetHeadSensorSpeed1() int32 {
if x != nil {
return x.HeadSensorSpeed1
}
return 0
}
func (x *TrainDynamicState) GetHeadSensorSpeed2() float32 {
func (x *TrainDynamicState) GetHeadSensorSpeed2() int32 {
if x != nil {
return x.HeadSensorSpeed2
}
return 0
}
func (x *TrainDynamicState) GetTailSensorSpeed1() float32 {
func (x *TrainDynamicState) GetTailSensorSpeed1() int32 {
if x != nil {
return x.TailSensorSpeed1
}
return 0
}
func (x *TrainDynamicState) GetTailSensorSpeed2() float32 {
func (x *TrainDynamicState) GetTailSensorSpeed2() int32 {
if x != nil {
return x.TailSensorSpeed2
}
return 0
}
func (x *TrainDynamicState) GetHeadRadarSpeed() float32 {
func (x *TrainDynamicState) GetHeadRadarSpeed() int32 {
if x != nil {
return x.HeadRadarSpeed
}
return 0
}
func (x *TrainDynamicState) GetTailRadarSpeed() float32 {
func (x *TrainDynamicState) GetTailRadarSpeed() int32 {
if x != nil {
return x.TailRadarSpeed
}
@ -1473,22 +1473,22 @@ var file_device_state_proto_rawDesc = []byte{
0x28, 0x0a, 0x0f, 0x63, 0x75, 0x72, 0x76, 0x65, 0x52, 0x65, 0x73, 0x69, 0x73, 0x74, 0x61, 0x6e,
0x63, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0f, 0x63, 0x75, 0x72, 0x76, 0x65, 0x52,
0x65, 0x73, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x70, 0x65,
0x65, 0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x73, 0x70, 0x65, 0x65, 0x64, 0x12,
0x65, 0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x70, 0x65, 0x65, 0x64, 0x12,
0x2a, 0x0a, 0x10, 0x68, 0x65, 0x61, 0x64, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65,
0x65, 0x64, 0x31, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x02, 0x52, 0x10, 0x68, 0x65, 0x61, 0x64, 0x53,
0x65, 0x64, 0x31, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x68, 0x65, 0x61, 0x64, 0x53,
0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x31, 0x12, 0x2a, 0x0a, 0x10, 0x68,
0x65, 0x61, 0x64, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x32, 0x18,
0x10, 0x20, 0x01, 0x28, 0x02, 0x52, 0x10, 0x68, 0x65, 0x61, 0x64, 0x53, 0x65, 0x6e, 0x73, 0x6f,
0x10, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x68, 0x65, 0x61, 0x64, 0x53, 0x65, 0x6e, 0x73, 0x6f,
0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x32, 0x12, 0x2a, 0x0a, 0x10, 0x74, 0x61, 0x69, 0x6c, 0x53,
0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x31, 0x18, 0x11, 0x20, 0x01, 0x28,
0x02, 0x52, 0x10, 0x74, 0x61, 0x69, 0x6c, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65,
0x05, 0x52, 0x10, 0x74, 0x61, 0x69, 0x6c, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65,
0x65, 0x64, 0x31, 0x12, 0x2a, 0x0a, 0x10, 0x74, 0x61, 0x69, 0x6c, 0x53, 0x65, 0x6e, 0x73, 0x6f,
0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x32, 0x18, 0x12, 0x20, 0x01, 0x28, 0x02, 0x52, 0x10, 0x74,
0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x32, 0x18, 0x12, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x74,
0x61, 0x69, 0x6c, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x32, 0x12,
0x26, 0x0a, 0x0e, 0x68, 0x65, 0x61, 0x64, 0x52, 0x61, 0x64, 0x61, 0x72, 0x53, 0x70, 0x65, 0x65,
0x64, 0x18, 0x13, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0e, 0x68, 0x65, 0x61, 0x64, 0x52, 0x61, 0x64,
0x64, 0x18, 0x13, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x68, 0x65, 0x61, 0x64, 0x52, 0x61, 0x64,
0x61, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x12, 0x26, 0x0a, 0x0e, 0x74, 0x61, 0x69, 0x6c, 0x52,
0x61, 0x64, 0x61, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x02, 0x52,
0x61, 0x64, 0x61, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x05, 0x52,
0x0e, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x61, 0x64, 0x61, 0x72, 0x53, 0x70, 0x65, 0x65, 0x64, 0x22,
0xba, 0x07, 0x0a, 0x0e, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x56, 0x6f, 0x62, 0x63, 0x53, 0x74, 0x61,
0x74, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x66, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c,

View File

@ -2,6 +2,7 @@ package simulation
import (
"encoding/binary"
"math"
"fmt"
"net/http"
@ -52,8 +53,8 @@ func init() {
}
trainState := sta.(*state.TrainState)
// 给半实物仿真发送速度
zap.S().Info("发送到vobc发送的速度", info.Speed*36)
vobc.SendTrainSpeedTask(info.Speed * 36)
zap.S().Infof("发送到vobc发送的速度%d, %d \n", info.Speed, math.Abs(float64(info.Speed*36)))
vobc.SendTrainSpeedTask(math.Abs(float64(info.Speed * 36)))
// 更新列车状态
memory.UpdateTrainState(simulation, convert(info, trainState, simulation))
}
@ -175,13 +176,13 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory
sta.DynamicState.AirResistance = float32(info.AirResistance) / 1000
sta.DynamicState.RampResistance = float32(info.SlopeResistance) / 1000
sta.DynamicState.CurveResistance = float32(info.CurveResistance) / 1000
sta.DynamicState.Speed = info.Speed * 3.6
sta.DynamicState.HeadSensorSpeed1 = info.HeadSpeed1 * 3.6
sta.DynamicState.HeadSensorSpeed2 = info.HeadSpeed2 * 3.6
sta.DynamicState.TailSensorSpeed1 = info.TailSpeed1 * 3.6
sta.DynamicState.TailSensorSpeed2 = info.TailSpeed2 * 3.6
sta.DynamicState.HeadRadarSpeed = info.HeadRadarSpeed * 3.6
sta.DynamicState.TailRadarSpeed = info.TailRadarSpeed * 3.6
sta.DynamicState.Speed = speedParse(info.Speed)
sta.DynamicState.HeadSensorSpeed1 = speedParse(info.HeadSpeed1)
sta.DynamicState.HeadSensorSpeed2 = speedParse(info.HeadSpeed2)
sta.DynamicState.TailSensorSpeed1 = speedParse(info.TailSpeed1)
sta.DynamicState.TailSensorSpeed2 = speedParse(info.TailSpeed2)
sta.DynamicState.HeadRadarSpeed = speedParse(info.HeadRadarSpeed)
sta.DynamicState.TailRadarSpeed = speedParse(info.TailRadarSpeed)
return sta
}
@ -271,3 +272,8 @@ func decoderVobcTrainState(buf []byte) *state.TrainVobcState {
trainVobcInfo.AllDoorClose = (b4 & (1 << 4)) != 0
return trainVobcInfo
}
// 发送给前端的速度格式化
func speedParse(speed float32) int32 {
return int32(speed * 3.6 * 100)
}

@ -1 +1 @@
Subproject commit e33f466f120e257e2b6a30e8d85281aad5f21ec1
Subproject commit 9f5ab0590cccd317295c67cf05f4599dc9f51fca

View File

@ -109,7 +109,7 @@ func RunUdpServer() {
}
// 发送列车速度到VOBC
func SendTrainSpeedTask(speed float32) error {
func SendTrainSpeedTask(speed float64) error {
if running {
return nil
}