2023-10-19 09:33:40 +08:00
|
|
|
|
package message
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
"math"
|
2024-05-20 17:23:22 +08:00
|
|
|
|
"time"
|
2023-10-19 09:33:40 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DynamicsTurnoutInfo struct {
|
2024-01-17 17:01:43 +08:00
|
|
|
|
LifeSignal uint16
|
|
|
|
|
TurnoutInfos []*TurnoutInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TurnoutInfo struct {
|
|
|
|
|
Code uint16
|
|
|
|
|
NPosition bool
|
|
|
|
|
RPosition bool
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *DynamicsTurnoutInfo) Encode() []byte {
|
|
|
|
|
var data []byte
|
|
|
|
|
data = binary.BigEndian.AppendUint16(data, t.LifeSignal)
|
2024-01-17 17:01:43 +08:00
|
|
|
|
for _, info := range t.TurnoutInfos {
|
|
|
|
|
data = binary.BigEndian.AppendUint16(data, info.Code)
|
|
|
|
|
var b byte
|
|
|
|
|
if info.NPosition {
|
|
|
|
|
b |= 1 << 7
|
|
|
|
|
}
|
|
|
|
|
if info.RPosition {
|
|
|
|
|
b |= 1 << 6
|
|
|
|
|
}
|
|
|
|
|
data = append(data, b)
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DynamicsTrainInfo struct {
|
|
|
|
|
//生命信号
|
|
|
|
|
LifeSignal uint16
|
|
|
|
|
//列车号(车辆)
|
|
|
|
|
Number uint8
|
|
|
|
|
//列车长度 cm
|
2023-11-10 09:28:27 +08:00
|
|
|
|
Len uint32
|
2023-10-19 09:33:40 +08:00
|
|
|
|
//列车所在轨道link
|
|
|
|
|
Link uint8
|
|
|
|
|
//列车所在link偏移量(mm)
|
|
|
|
|
LinkOffset uint32
|
|
|
|
|
//列车所在位置坡度值(‰)
|
|
|
|
|
Slope uint16
|
|
|
|
|
//列车所在位置坡度走势(上/下坡)
|
|
|
|
|
UpSlope bool
|
|
|
|
|
//列车当前运行方向(偏移量增大/减小方向)
|
|
|
|
|
Up bool
|
|
|
|
|
//实际运行阻力(总)(N)
|
|
|
|
|
TotalResistance int32
|
|
|
|
|
//阻力1(空气阻力)(N)
|
|
|
|
|
AirResistance int32
|
|
|
|
|
//阻力2(坡道阻力)(N)
|
|
|
|
|
SlopeResistance int32
|
|
|
|
|
//阻力3(曲线阻力)(N)
|
|
|
|
|
CurveResistance int32
|
|
|
|
|
//列车运行速度(m/s)
|
|
|
|
|
Speed float32
|
|
|
|
|
//头车速传1速度值(m/s)
|
|
|
|
|
HeadSpeed1 float32
|
|
|
|
|
//头车速度2速度值(m/s)
|
|
|
|
|
HeadSpeed2 float32
|
|
|
|
|
//尾车速传1速度值(m/s)
|
|
|
|
|
TailSpeed1 float32
|
|
|
|
|
//尾车速度2速度值(m/s)
|
|
|
|
|
TailSpeed2 float32
|
|
|
|
|
//头车雷达速度值(m/s)
|
|
|
|
|
HeadRadarSpeed float32
|
|
|
|
|
//尾车雷达速度值(m/s)
|
|
|
|
|
TailRadarSpeed float32
|
|
|
|
|
//加速度(m/s^2)
|
|
|
|
|
Acceleration float32
|
2024-01-29 14:42:12 +08:00
|
|
|
|
//此次计算所使用的半实物消息的生命信号
|
2023-10-19 14:44:10 +08:00
|
|
|
|
VobcLifeSignal uint16
|
2024-01-29 14:42:12 +08:00
|
|
|
|
//位移(mm)
|
2024-05-20 15:21:22 +08:00
|
|
|
|
Displacement uint16
|
|
|
|
|
TrainActToMax bool
|
|
|
|
|
TrainActToMin bool
|
2024-05-20 17:23:22 +08:00
|
|
|
|
UpdateTime int64
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 解析动力学的列车信息
|
|
|
|
|
func (t *DynamicsTrainInfo) Decode(buf []byte) error {
|
|
|
|
|
t.LifeSignal = binary.BigEndian.Uint16(buf[0:2])
|
|
|
|
|
t.Number = buf[2]
|
2023-11-10 09:28:27 +08:00
|
|
|
|
t.Len = binary.BigEndian.Uint32(buf[3:7])
|
|
|
|
|
t.Link = buf[7]
|
|
|
|
|
t.LinkOffset = binary.BigEndian.Uint32(buf[8:12])
|
|
|
|
|
t.Slope = binary.BigEndian.Uint16(buf[12:14])
|
|
|
|
|
b := buf[14]
|
2024-05-20 15:21:22 +08:00
|
|
|
|
t.UpSlope = IsTrueForByte(GetBit(b, 7))
|
|
|
|
|
t.Up = IsTrueForByte(GetBit(b, 6))
|
|
|
|
|
t.TrainActToMax = IsTrueForByte(GetBit(b, 4))
|
|
|
|
|
t.TrainActToMin = IsTrueForByte(GetBit(b, 5))
|
|
|
|
|
|
|
|
|
|
//t.UpSlope = (b & (1 << 7)) != 0
|
|
|
|
|
//t.Up = (b & (1 << 6)) != 0
|
|
|
|
|
//t.TrainActToMax = (b & (1 << 5)) != 0
|
|
|
|
|
//t.TrainActToMin = (b & (1 << 4)) != 0
|
|
|
|
|
|
|
|
|
|
//t.TrainActToMax = (b & (1 << 4)) != 0
|
|
|
|
|
//t.TrainActToMin = (b & (1 << 5)) != 0
|
|
|
|
|
|
2023-11-10 09:28:27 +08:00
|
|
|
|
t.TotalResistance = int32(binary.BigEndian.Uint32(buf[16:20]))
|
|
|
|
|
t.AirResistance = int32(binary.BigEndian.Uint32(buf[20:24]))
|
|
|
|
|
t.SlopeResistance = int32(binary.BigEndian.Uint32(buf[24:28]))
|
|
|
|
|
t.CurveResistance = int32(binary.BigEndian.Uint32(buf[28:32]))
|
|
|
|
|
t.Speed = math.Float32frombits(binary.BigEndian.Uint32(buf[32:36]))
|
|
|
|
|
t.HeadSpeed1 = math.Float32frombits(binary.BigEndian.Uint32(buf[36:40]))
|
|
|
|
|
t.HeadSpeed2 = math.Float32frombits(binary.BigEndian.Uint32(buf[40:44]))
|
|
|
|
|
t.TailSpeed1 = math.Float32frombits(binary.BigEndian.Uint32(buf[44:48]))
|
|
|
|
|
t.TailSpeed2 = math.Float32frombits(binary.BigEndian.Uint32(buf[48:52]))
|
|
|
|
|
t.HeadRadarSpeed = math.Float32frombits(binary.BigEndian.Uint32(buf[52:56]))
|
|
|
|
|
t.TailRadarSpeed = math.Float32frombits(binary.BigEndian.Uint32(buf[56:60]))
|
|
|
|
|
t.Acceleration = math.Float32frombits(binary.BigEndian.Uint32(buf[60:64]))
|
|
|
|
|
t.VobcLifeSignal = binary.BigEndian.Uint16(buf[64:66])
|
2024-01-26 17:57:35 +08:00
|
|
|
|
t.Displacement = binary.BigEndian.Uint16(buf[66:68])
|
2024-05-20 17:23:22 +08:00
|
|
|
|
t.UpdateTime = time.Now().UnixMilli()
|
2023-10-19 09:33:40 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|