rts-sim-testing-service/ts/simulation/wayside/memory/wayside_simulation_train_pc.go

896 lines
39 KiB
Go
Raw Normal View History

2024-04-02 18:20:10 +08:00
package memory
import (
"encoding/binary"
"encoding/hex"
"fmt"
2024-08-05 16:32:21 +08:00
uuid2 "github.com/google/uuid"
2024-04-02 18:20:10 +08:00
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/const/balise_const"
2024-04-09 10:40:18 +08:00
"joylink.club/bj-rtsts-server/dto/data_proto"
2024-04-02 18:20:10 +08:00
"joylink.club/bj-rtsts-server/dto/request_proto"
"joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/third_party/can_btm"
"joylink.club/bj-rtsts-server/third_party/electrical_machinery"
2024-04-02 18:20:10 +08:00
"joylink.club/bj-rtsts-server/third_party/message"
train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"log/slog"
"math"
2024-04-02 18:20:10 +08:00
"strings"
"time"
)
2024-05-24 09:00:43 +08:00
func (s *VerifySimulation) GetTrainPcSimConfig() []config.VehiclePCSimConfig {
return s.runConfig.PcSimConfigs
2024-04-02 18:20:10 +08:00
}
// 列车控制
2024-04-09 10:40:18 +08:00
func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
2024-04-02 18:20:10 +08:00
allTrainMap := &s.Memory.Status.TrainStateMap
data, ok := allTrainMap.Load(ct.TrainId)
if !ok {
panic(sys_error.New(fmt.Sprintf("列车【%s】不存在", ct.TrainId)))
}
2024-04-09 10:40:18 +08:00
tccGraphicData := findTrainTccGraphicData(s)
if tccGraphicData == nil {
slog.Error("列车控制未找到TCC图形数据")
panic(sys_error.New("未找到TCC图形数据"))
}
2024-04-02 18:20:10 +08:00
sta := data.(*state_proto.TrainState)
vobc := sta.VobcState
tcc := sta.Tcc
var baseMsg []message.TrainPcSimBaseMessage = nil
2024-04-02 18:20:10 +08:00
if ct.ControlType == request_proto.TrainControl_EMERGENT_BUTTON {
baseMsg = trainControlButton(vobc, tcc.Buttons, ct.DeviceId, ct.ControlButton.Active, tccGraphicData)
2024-04-02 18:20:10 +08:00
} else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH {
baseMsg = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData)
2024-07-11 14:58:34 +08:00
train_pc_sim.Default().SendDriverActive(sta)
2024-04-02 18:20:10 +08:00
} else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH {
baseMsg = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.DirKey, ct.DeviceId, tccGraphicData)
2024-04-17 09:32:25 +08:00
//此处先注释,根据现场调试情况 2024-4-16
2024-06-27 10:37:52 +08:00
train_pc_sim.Default().SendTrainDirection(sta, sta.VobcState.DirectionForward, sta.VobcState.DirectionBackward)
2024-04-02 18:20:10 +08:00
} else if ct.ControlType == request_proto.TrainControl_HANDLER {
2024-08-05 16:32:21 +08:00
if !vobc.Tc1Active && !vobc.Tc2Active {
panic(sys_error.New("TC1和TC2都未激活不能搬动牵引制动手柄 "))
}
2024-04-02 18:20:10 +08:00
oldTraction := sta.VobcState.TractionForce
oldBrakeForce := sta.VobcState.BrakeForce
2024-04-18 11:14:05 +08:00
isTraction := ct.Handler.Val > 0 //是否制动
baseMsg = trainControlHandle(vobc, tcc, ct.Handler, ct.DeviceId, tccGraphicData)
2024-05-24 09:00:43 +08:00
train_pc_sim.Default().SendHandleSwitch(oldTraction, oldBrakeForce, isTraction, sta)
2024-04-02 18:20:10 +08:00
}
2024-07-11 14:58:34 +08:00
if vobc.DirectionForward && vobc.TractionForce == 0 {
baseMsg = append(baseMsg, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DIR_ZERO_FORWARD, 1}})
2024-07-11 14:58:34 +08:00
} else {
baseMsg = append(baseMsg, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DIR_ZERO_FORWARD, 0}})
2024-07-11 14:58:34 +08:00
}
if !vobc.DirectionForward && !vobc.DirectionBackward {
vobc.TractionStatus = false
vobc.TractionForce = 0
}
2024-05-10 08:23:50 +08:00
if vobc.EmergencyBrakingStatus {
vobc.TractionForce = 0
}
if sta.ConnState.Conn && (sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM) && baseMsg != nil {
train_pc_sim.Default().SendTrainControlMsg(sta, baseMsg)
2024-04-02 18:20:10 +08:00
}
}
func trainControlButton(vobc *state_proto.TrainVobcState, buttonMap map[string]*state_proto.TrainControlState_ControlButton, deviceId uint32, active bool, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
if graphicBtn, ok := findTrainTccGraphicDataButton(tccGraphic, deviceId); ok {
btn := buttonMap[graphicBtn.Code]
if btn == nil {
2024-07-04 14:47:24 +08:00
slog.Error("未找到对应的车载摁钮code:", graphicBtn.Code, "设备id:", deviceId)
return nil
}
2024-07-04 14:47:24 +08:00
switch graphicBtn.Code {
case JJZD: // 紧急制动
2024-07-04 14:47:24 +08:00
return controlEBBtn(vobc, active, btn)
case ATPQCKG: //atp切除
2024-07-04 14:47:24 +08:00
return controlAtpBtn(vobc, active, btn)
/* case "WBJJZDFK": //外部紧急制动反馈
return controlOutEbReportBtn(vobc, active, btn)*/
case KZM: //开左门按钮
2024-07-04 14:47:24 +08:00
return controlLeftDoorBtn(vobc, active, btn)
case GZM: //关左门按钮
2024-07-04 14:47:24 +08:00
return controlLeftDoorCloseBtn(vobc, active, btn)
case KYM: //开右门按钮
2024-07-04 14:47:24 +08:00
return controlRightDoorBtn(vobc, active, btn)
case GYM: //关右门按钮
2024-07-04 14:47:24 +08:00
return controlRightDoorCloseBtn(vobc, active, btn)
case ZF: //折返按钮
2024-07-04 14:47:24 +08:00
return controlReverseBtn(vobc, active, btn)
case QZMYX: //强制门允许
2024-07-04 14:47:24 +08:00
return controlDoorAllowBtn(vobc, active, btn)
case MSJJ: //模式降级按钮
2024-07-04 14:47:24 +08:00
return controlModeDownBtn(vobc, active, btn)
case MSSJ: //模式升级按钮
2024-07-04 14:47:24 +08:00
return controlModeUpBtn(vobc, active, btn)
case MSQR: //模式确认按钮
2024-07-04 14:47:24 +08:00
return controlModeConfirmBtn(vobc, active, btn)
case ZAWTGJC: //障碍物/脱轨检测
2024-07-04 14:47:24 +08:00
return controlObstacleDetectionBtn(vobc, active, btn)
case ZDZGZ: //制动重故障
2024-07-04 14:47:24 +08:00
return controlBrakeHeavyBtn(vobc, active, btn)
case ATPSD: //ATP上电按钮
2024-07-04 14:47:24 +08:00
return controlAtpPowerBtn(vobc, active, btn)
case HX: //唤醒按钮
2024-07-04 14:47:24 +08:00
return controlWakeUpBtn(vobc, active, btn)
case JX: //检修按钮
2024-07-04 14:47:24 +08:00
return controlOverhaulBtn(vobc, active, btn)
case XM: //休眠按钮
2024-07-04 14:47:24 +08:00
return controlSleepBtn(vobc, active, btn)
default:
return nil
}
} else {
return nil
}
2024-07-04 14:47:24 +08:00
}
// 应急摁钮
func controlEBBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
if !active {
2024-04-16 17:26:37 +08:00
return nil
2024-04-09 10:40:18 +08:00
}
2024-07-04 14:47:24 +08:00
tccBtn.Passed = active
vobc.EmergencyBrakingStatus = true
vobc.TractionForce = 0
vobc.BrakeForce = int64(DEFAULT_BRAKE_FORCE * 100)
2024-08-05 16:32:21 +08:00
vobc.BrakingStatus = true
return []message.TrainPcSimBaseMessage{
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 0}},
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_BRAKE_STATE, 1}}}
2024-07-04 14:47:24 +08:00
}
// atp 切除
func controlAtpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
vobc.AtpCutSwitch = active
tccBtn.Passed = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_CUT, status}}}
2024-07-04 14:47:24 +08:00
}
// 开左门按钮
func controlLeftDoorBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
vobc.LeftDoorOpenCommand = active
tccBtn.Passed = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.LEFT_OPEN_DOOR, status}}}
2024-07-04 14:47:24 +08:00
}
// 关左门按钮
func controlLeftDoorCloseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
vobc.LeftDoorCloseCommand = active
tccBtn.Passed = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CLOSE_LEFT_DOOR, status}}}
2024-07-04 14:47:24 +08:00
}
// 开右门
func controlRightDoorBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
vobc.RightDoorOpenCommand = active
tccBtn.Passed = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OPEN_RIGHT_DOOR, status}}}
2024-07-04 14:47:24 +08:00
}
// 关右门按钮
func controlRightDoorCloseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
vobc.RightDoorCloseCommand = active
tccBtn.Passed = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CLOSE_RIGHT_DOOR, status}}}
2024-07-04 14:47:24 +08:00
}
// 折返
func controlReverseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
//vobc.RightDoorCloseCommand = active
vobc.TurnbackStatus = active
2024-07-04 14:47:24 +08:00
tccBtn.Passed = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TURN_BACK, status}}}
2024-07-04 14:47:24 +08:00
}
// 强制门允许
func controlDoorAllowBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.ForceDoorAllow = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.FORCE_DOOR_ALLOW, status}}}
2024-07-04 14:47:24 +08:00
}
// 模式降级按钮
func controlModeDownBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.ModeLevelDownBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_MODE_DOWN, status}}}
2024-07-04 14:47:24 +08:00
}
// 模式升级按钮
func controlModeUpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.ModeLevelUpBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_MODE_UP, status}}}
2024-07-04 14:47:24 +08:00
}
// 模式确认按钮
func controlModeConfirmBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.ConfirmBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CONFIRM, status}}}
2024-07-04 14:47:24 +08:00
}
// 障碍物/脱轨检测
func controlObstacleDetectionBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.ObstacleCheckBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OBSTACLE_CHECK, status}}}
2024-07-04 14:47:24 +08:00
}
// 制动重故障
func controlBrakeHeavyBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.BrakeHeavyFault = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.BRAKE_HEAVY_FAULT, status}}}
2024-07-04 14:47:24 +08:00
}
// ATP上电按钮
func controlAtpPowerBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.AtpPowerOnBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_POWER_ON, status}}}
2024-07-04 14:47:24 +08:00
}
// 唤醒按钮
func controlWakeUpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.WakeUpBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.WAKE_UP, status}}}
2024-07-04 14:47:24 +08:00
}
// 检修按钮
func controlOverhaulBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.OverhaulBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OVERHAUL, status}}}
2024-07-04 14:47:24 +08:00
}
// 休眠按钮
func controlSleepBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
2024-07-04 14:47:24 +08:00
var status byte = 0
if active {
status = 1
}
tccBtn.Passed = active
vobc.SleepBtn = active
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.SLEEP, status}}}
2024-04-02 18:20:10 +08:00
}
// 列车方向
func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_DirectionKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
2024-04-09 10:40:18 +08:00
_, find := findTrainTccGraphicDataKey(tccGraphic, deviceId)
if !find {
slog.Error("未找到对应的列车方向键deviceId:", deviceId)
2024-05-09 14:36:13 +08:00
panic(sys_error.New("未找到对应的列车方向键"))
}
if tcc.DirKey == nil {
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: deviceId}
2024-04-09 10:40:18 +08:00
}
2024-05-09 14:36:13 +08:00
direction := request_proto.TrainControl_Direction(request.Val)
if trainSpeed > 0 {
panic(sys_error.New("列车未停稳时,不能变更方向"))
}
vobc.DirectionBackward = false
2024-05-09 14:36:13 +08:00
vobc.DirectionForward = false
if direction == request_proto.TrainControl_FORWARD {
vobc.DirectionForward = true
2024-05-09 14:36:13 +08:00
} else if direction == request_proto.TrainControl_BACKWARD {
vobc.DirectionBackward = true
2024-04-02 18:20:10 +08:00
}
tcc.DirKey.Val = request.Val
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_BACKWORD, message.IsTrue(vobc.DirectionBackward)}},
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_FORWORD, message.IsTrue(vobc.DirectionForward)}}}
2024-04-02 18:20:10 +08:00
}
// 列车驾驶端激活
func trainControlDriverKey(train *state_proto.TrainState, request *request_proto.TrainControl_DriverKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
2024-04-09 10:40:18 +08:00
obj, find := findTrainTccGraphicDataKey(tccGraphic, deviceId)
if !find {
slog.Error("未找到对应的驾驶端激活设备deviceId:", deviceId)
return nil
}
2024-05-20 15:21:22 +08:00
if train.DynamicState.Speed != 0 {
2024-05-09 14:36:13 +08:00
panic(sys_error.New("因列车未停稳,不支持此操作"))
}
2024-05-20 15:21:22 +08:00
vobc := train.VobcState
tcc := train.Tcc
if obj.Code == SKQYS1 {
vobc.Tc1Active = request.Val
} else if obj.Code == SKQYS2 {
vobc.Tc2Active = request.Val
}
if vobc.Tc1Active && vobc.Tc2Active {
if obj.Code == SKQYS1 {
vobc.Tc1Active = false
} else if obj.Code == SKQYS2 {
vobc.Tc2Active = false
2024-04-28 11:01:12 +08:00
}
panic(sys_error.New("驾驶端不能同时激活"))
}
2024-04-02 18:20:10 +08:00
var addNew = true
for _, k := range tcc.DriverKey {
2024-04-02 18:20:10 +08:00
if k.Id == deviceId {
k.Id = deviceId
k.Val = request.Val
addNew = false
break
}
}
if addNew {
tcc.DriverKey = append(tcc.DriverKey, &state_proto.TrainControlState_DriverKeySwitch{Id: deviceId, Val: request.Val})
2024-04-02 18:20:10 +08:00
}
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.KEY_STATE, message.IsTrue(request.Val)}}}
2024-04-02 18:20:10 +08:00
}
// 列车牵引控制
func trainControlHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_PushHandler, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
2024-04-09 10:40:18 +08:00
_, find := findTrainTccGraphicDataHandler(tccGraphic, deviceId)
if !find {
slog.Error("未找到对应的牵引制动手柄设备deviceId:", deviceId)
return nil
}
/*trainStart := false
if tcc.PushHandler.Val <= 0 {
trainStart = true
} else if tcc.PushHandler.Val > 0 {
}*/
jjzdBtn := tcc.Buttons[JJZD]
vobc.TractionStatus = false
vobc.TractionForce = 0
vobc.BrakingStatus = false
vobc.BrakeForce = 0
vobc.MaintainBrakeStatus = false
2024-08-05 16:32:21 +08:00
notBreak := byte(0)
2024-07-11 14:58:34 +08:00
var zeroState byte = 0
var brakeState byte = 0
2024-04-02 18:20:10 +08:00
if request.Val > 0 {
vobc.TractionStatus = true
vobc.TractionForce = int64(float32(request.Val)/100*DEFAULT_TRAIN_TRACTION) * 100
2024-08-05 16:32:21 +08:00
notBreak = 1
2024-04-02 18:20:10 +08:00
} else if request.Val < 0 {
vobc.BrakingStatus = true
vobc.BrakeForce = int64(math.Abs(float64(request.Val))/100*DEFAULT_BRAKE_FORCE) * 100
vobc.EmergencyBrakingStatus = false
2024-07-04 14:47:24 +08:00
jjzdBtn.Passed = false
2024-08-05 16:32:21 +08:00
brakeState = 0
2024-04-02 18:20:10 +08:00
} else {
2024-07-11 14:58:34 +08:00
zeroState = 1
2024-04-02 18:20:10 +08:00
}
if tcc.PushHandler == nil {
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: deviceId}
2024-04-02 18:20:10 +08:00
}
tcc.PushHandler.Val = request.Val
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_TO_ZERO, zeroState}},
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_BRAKE_STATE, brakeState}},
/*{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 1}},*/
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.NOT_BREAK, notBreak}}}
2024-04-02 18:20:10 +08:00
}
2024-04-09 08:55:33 +08:00
2024-05-24 09:00:43 +08:00
func (s *VerifySimulation) GetConnTrain2() []*state_proto.TrainState {
return s.findConnTrain2(state_proto.TrainConnState_PC_SIM)
2024-05-24 09:00:43 +08:00
}
func (s *VerifySimulation) findConnTrain2(ct1 ...state_proto.TrainConnState_TrainConnType) []*state_proto.TrainState {
2024-05-24 09:00:43 +08:00
var trains = make([]*state_proto.TrainState, 0)
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
train := v.(*state_proto.TrainState)
if train.Show {
connState := train.ConnState
finded := index(ct1, connState.ConnType)
if finded >= 0 {
2024-05-24 09:00:43 +08:00
trains = append(trains, train)
}
}
return true
})
return trains
2024-04-09 08:55:33 +08:00
}
func index(arr []state_proto.TrainConnState_TrainConnType, search state_proto.TrainConnState_TrainConnType) int {
for i, v := range arr {
if v == search {
return i
}
}
return -1
}
2024-06-06 17:57:30 +08:00
func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState {
2024-04-02 18:20:10 +08:00
var findTrain *state_proto.TrainState
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
train := v.(*state_proto.TrainState)
connState := train.ConnState
if connState.ConnType == ct {
findTrain = train
return false
}
return true
})
return findTrain
}
// 反馈atp输出数字量数据
func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState, data1, data3 byte, trainInit bool) bool {
vobc := train.VobcState
tcc := train.Tcc
tce := make([]message.TrainPcSimBaseMessage, 0)
tcc.Line12ConnErr = false
initResult := trainInit
if vobc.Tc1Active || vobc.Tc2Active {
state := message.GetBit(data1, 3)
if trainInit {
if data1 == 0 {
tcc.Line12ConnErr = true
}
if state == 0 {
2024-08-05 16:32:21 +08:00
jjzdBtn := tcc.Buttons[JJZD]
ebTce := controlEBBtn(vobc, true, jjzdBtn)
tce = append(tce, ebTce...)
} else if message.GetBit(data1, 0) == 0 {
jjzdBtn := tcc.Buttons[JJZD]
ebTce := controlEBBtn(vobc, true, jjzdBtn)
tce = append(tce, ebTce...)
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_TRACTION_CUTED, 1}})
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.NOT_BREAK, 0}})
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{0x38, 0}})
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_BACKWARD})
}
} else {
initResult = true
if tcc.LineInitTimeStamp12 <= 0 {
tcc.LineInitTimeStamp12 = time.Now().Add(time.Second * 6).Unix()
}
if tcc.LineInitTimeStamp12 > time.Now().Unix() {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
initData := s.ObtainTrainDigitalMockDataForStatus(train)
tce = append(tce, initData...)
initResult = false
}
}
//驾驶室激活反馈
if message.GetBit(data3, 3) == 0 {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}})
}
2024-07-25 14:55:46 +08:00
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_INTEGRITY, 1}})
}
train_pc_sim.Default().SendTrainControlMsg(train, tce)
return initResult
}
2024-07-11 14:58:34 +08:00
2024-04-02 18:20:10 +08:00
// 4.4.1. 车载输出数字量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, trainInit bool, data []byte) bool {
/*for i, d := range data {
slog.Info(fmt.Sprintf("atp模拟量分析index:%v ,bin:%2b,trainInit:%v", i, d, trainInit))
}*/
2024-07-11 14:58:34 +08:00
initResult := s.reportTrainMockInitMsg(train, data[4], data[1], trainInit)
vobc := train.VobcState
trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc)
trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc)
trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
trainPcSimDigitalOutInfoHandleCode31_24(data[1], vobc)
trainPcSimDigitalOutInfoHandleCode39_32(data[0], vobc)
2024-08-05 16:32:21 +08:00
/* if !vobc.EmergencyBrakingStatus {
train_pc_sim.Default().ResetPlusePlace(train)
}*/
return initResult
2024-04-02 18:20:10 +08:00
}
2024-04-11 08:55:12 +08:00
func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) {
2024-04-16 17:26:37 +08:00
vobc.MostUseBrake = message.IsTrueForByte(message.GetBit(d, 0)) //? 常用制动
vobc.SplittingOut = message.IsTrueForByte(message.GetBit(d, 1)) //? 过分相输出
vobc.ModeRelay = message.IsTrueForByte(message.GetBit(d, 2)) //? 模式继电器
vobc.TractionEffective = message.IsTrueForByte(message.GetBit(d, 3)) //? 牵引有效
vobc.BrakeEffective = message.IsTrueForByte(message.GetBit(d, 4)) //? 制动有效
vobc.LifeDoorState = message.IsTrueForByte(message.GetBit(d, 5)) //?逃生门使能
vobc.BrakeQuarantine = message.IsTrueForByte(message.GetBit(d, 6)) //? 制动隔离
vobc.StopNotAllBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? 停放制动缓解
2024-04-11 08:55:12 +08:00
}
func trainPcSimDigitalOutInfoHandleCode31_24(d byte, vobc *state_proto.TrainVobcState) {
2024-04-11 08:55:12 +08:00
vobc.AtoOpenLeftDoor = message.IsTrueForByte(message.GetBit(d, 0)) //?//ATO开左门
vobc.AtoOpenRightDoor = message.IsTrueForByte(message.GetBit(d, 1)) //?//ATO开右门
vobc.AtoCloseLeftDoor = message.IsTrueForByte(message.GetBit(d, 2)) //?//ATO关左门
/* if connType == state_proto.TrainConnState_PC_SIM_A {
vobc.Tc1Active = message.IsTrueForByte(message.GetBit(d, 3))
} else {
vobc.Tc2Active = message.IsTrueForByte(message.GetBit(d, 3))
}*/
2024-04-11 08:55:12 +08:00
vobc.LightDriverActive = message.IsTrueForByte(message.GetBit(d, 3)) //驾驶室激活
vobc.NoSpeedSigle = message.IsTrueForByte(message.GetBit(d, 4)) //?//零速信号
vobc.Fam = message.IsTrueForByte(message.GetBit(d, 5)) //FAM模式
vobc.Cam = message.IsTrueForByte(message.GetBit(d, 6)) //CAM模式
vobc.TrainStartedLed = message.IsTrueForByte(message.GetBit(d, 7)) //?//列车启动指示灯
2024-04-11 08:55:12 +08:00
}
2024-04-11 08:55:12 +08:00
func trainPcSimDigitalOutInfoHandleCode23_16(d byte, vobc *state_proto.TrainVobcState) {
vobc.LightDir1 = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
vobc.LightDir2 = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向1
//vobc.DirectionForward = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
//vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向2
2024-04-16 17:26:37 +08:00
vobc.AtoLazyCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO惰行命令输出
vobc.SleepBtn = message.IsTrueForByte(message.GetBit(d, 3)) //?休眠指令
vobc.WakeUpBtn = message.IsTrueForByte(message.GetBit(d, 4)) //?唤醒指令
vobc.AtoSendTrainBtn = message.IsTrueForByte(message.GetBit(d, 5)) //?ATO发车指示灯
vobc.TurnbackStatus = message.IsTrueForByte(message.GetBit(d, 6)) //?AR灯命令
vobc.AtoAlwaysBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? ATO保持制动
2024-04-11 08:55:12 +08:00
}
func trainPcSimDigitalOutInfoHandleCode15_8(d byte, vobc *state_proto.TrainVobcState) {
2024-04-16 17:26:37 +08:00
vobc.LocalAtpControl = message.IsTrueForByte(message.GetBit(d, 0)) //?本端ATP控车
2024-04-11 08:55:12 +08:00
vobc.Ato = message.IsTrueForByte(message.GetBit(d, 1)) //ATO模式
2024-04-16 17:26:37 +08:00
vobc.AtoTractionCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO牵引命令输出
vobc.AtoTractionCommand1 = message.IsTrueForByte(message.GetBit(d, 3)) //?ATO牵引指令1
vobc.AtoTractionCommand2 = message.IsTrueForByte(message.GetBit(d, 4)) //?ATO牵引指令2
vobc.AtoTractionCommand3 = message.IsTrueForByte(message.GetBit(d, 5)) //?ATO牵引指令3
vobc.AtoBrakeCommand = message.IsTrueForByte(message.GetBit(d, 6)) //?ATO制动命令输出
2024-04-11 08:55:12 +08:00
vobc.JumpStatus = message.IsTrueForByte(message.GetBit(d, 7)) //跳跃指令
}
func trainPcSimDigitalOutInfoHandleCode7_0(d byte, vobc *state_proto.TrainVobcState) {
vobc.TractionSafetyCircuit = message.AtpLowPowerByte(message.GetBit(d, 0)) //切牵引
vobc.TrainDoorOutLed = message.IsTrueForByte(message.GetBit(d, 1)) //? 车门外指示灯
vobc.ParkingBrakeStatus = message.IsTrueForByte(message.GetBit(d, 2)) //停放制动施加
vobc.EmergencyBrakingStatus = message.AtpLowPowerByte(message.GetBit(d, 3)) //紧急制动
vobc.LeftDoorState = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许
vobc.RightDoorState = message.IsTrueForByte(message.GetBit(d, 5)) //开右门允许
vobc.RightDoorCloseCommand = message.IsTrueForByte(message.GetBit(d, 6)) //关右门
vobc.AllDoorClose = message.IsTrueForByte(message.GetBit(d, 7)) //车门保持关闭
vobc.LightTractionSafetyCircuit = vobc.TractionSafetyCircuit //切牵引
vobc.LightEmergencyBrakingStatus = vobc.EmergencyBrakingStatus //紧急制动
2024-04-11 08:55:12 +08:00
}
2024-04-02 18:20:10 +08:00
// 4.4.2. 车载输出数字反馈量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte) {
2024-06-27 10:37:52 +08:00
slog.Info(fmt.Sprintf("车载输出数字量反馈信息", hex.EncodeToString(data)))
2024-04-02 18:20:10 +08:00
vobc := train.VobcState
2024-04-11 08:55:12 +08:00
//buf := bytes.NewBuffer(data)
//localEndAct, _ := buf.ReadByte()
//direction1, _ := buf.ReadByte()
//direction2, _ := buf.ReadByte()
//vobc.Tc1Active = message.IsTrueForByte(localEndAct) //本端驾驶室激活(钥匙)
//vobc.DirectionForward = message.IsTrueForByte(direction1) //方向手柄进位
//vobc.DirectionBackward = message.IsTrueForByte(direction2) //方向手柄退位
buf := data[0]
vobc.Tc1Active = message.IsTrueForByte(message.GetBit(buf, 0)) //本端驾驶室激活(钥匙)
vobc.DirectionForward = message.IsTrueForByte(message.GetBit(buf, 1)) //方向手柄进位
vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(buf, 2)) //方向手柄退位
2024-04-02 18:20:10 +08:00
}
// 创建/删除列车
2024-06-13 14:16:52 +08:00
func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) error {
connState := train.ConnState
if connState.ConnType == state_proto.TrainConnState_PC_SIM {
2024-06-27 10:37:52 +08:00
crErr := train_pc_sim.Default().CreateOrRemoveTrain(train, create)
//train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
2024-04-29 13:58:14 +08:00
if crErr != nil {
return crErr
}
2024-07-11 14:58:34 +08:00
} else if connState.ConnType == state_proto.TrainConnState_VOBC {
electrical_machinery.Default().ClearOrRemoveTrain(train)
2024-04-18 11:14:05 +08:00
}
return nil
2024-04-02 18:20:10 +08:00
}
// 门模式
2024-04-13 09:40:25 +08:00
/*func TrainDoorModeHandle(train *state_proto.TrainState) {
2024-04-02 18:20:10 +08:00
if !train.ConnState.Conn {
slog.Error("车载pc仿真门模式,列车未连接车载pc仿真")
return
}
switch state {
case 0x00:
//0x00表示自开自关AA
train.VobcState.DoorModeAA = true
case 0x01:
//0x01表示自开人关AM
train.VobcState.DoorModeAM = true
case 0x02:
//0x02表示人开人关MM
train.VobcState.DoorModeMM = true
}
2024-04-13 09:40:25 +08:00
}*/
2024-04-02 18:20:10 +08:00
// 4.4.3. 车载输出模拟量信息报文内容(0x03)
func (s *VerifySimulation) TrainPcSimMockInfo(train *state_proto.TrainState, data []byte) {
/*train := s.FindConnTrain(connType)
2024-04-02 18:20:10 +08:00
if train == nil {
slog.Error("车载输出模拟量,未找到连接车载pc仿真的列车")
return
}
if !train.ConnState.Conn {
slog.Error("车载输出模拟量,列车未连接车载pc仿真")
return
}*/
2024-04-02 18:20:10 +08:00
mockData := binary.BigEndian.Uint16(data)
train.VobcState.MockInfo = uint32(mockData)
}
// 4.4.4. 车载输出BTM查询同步帧报文内容0x04
func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []byte) {
2024-08-05 16:32:21 +08:00
uuid := uuid2.NewString()
ts := time.Now().UnixMilli()
//slog.Info(fmt.Sprintf("收到车载输出BTM查询同步帧uuid:%v,时间:%v, 报文内容:%v", uuid, ts, hex.EncodeToString(data)))
2024-04-02 18:20:10 +08:00
if len(data) < 12 {
slog.Error("列车btm查询报文长度错误:", len(data))
return
}
if train.BtmState == nil {
2024-07-25 14:55:46 +08:00
slog.Warn(fmt.Sprintf("列车暂时未获取到应答器信息,无法进行btm查询列车id:%v", train.Id))
2024-04-02 18:20:10 +08:00
return
}
2024-08-05 16:32:21 +08:00
notSendBtm, ok := can_btm.Default().FindNotSendState()
2024-07-25 14:55:46 +08:00
trainAtm := message.NewBtmHeadFrame(data)
atpReq := &message.AtpRequestFrame{}
2024-04-02 18:20:10 +08:00
2024-07-25 14:55:46 +08:00
if !atpReq.Decode2(trainAtm) {
2024-04-02 18:20:10 +08:00
slog.Warn("列车pc驾驶模拟-CanetFrame解码成AtpRequestFrame失败", "CanetFrame", trainAtm.String())
return
}
2024-07-25 14:55:46 +08:00
2024-04-02 18:20:10 +08:00
cl := clock(atpReq)
2024-07-25 14:55:46 +08:00
dsn := train_pc_sim.Default().DsnAddAndReturn()
2024-08-05 16:32:21 +08:00
//btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, train.BtmState, atpReq, cl, dsn)
btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, &notSendBtm, atpReq, cl, dsn)
2024-07-25 14:55:46 +08:00
//slog.Info(fmt.Sprintf("id1:%x,id2:%x,id3:%x,id4:%x,resendRequest:%v,reqTime:%v,dsn:%v", trainAtm.CanId.ID1, trainAtm.CanId.ID2, trainAtm.CanId.ID3, trainAtm.CanId.ID4, atpReq.ResendRequest, atpReq.Time, dsn))
2024-04-02 18:20:10 +08:00
if atpReq.ResendRequest == 2 {
2024-08-05 16:32:21 +08:00
slog.Info(fmt.Sprintf("rrrrrrrrrrrrrrrrr:%v", atpReq.String()))
2024-04-02 18:20:10 +08:00
//重新发送
2024-08-05 16:32:21 +08:00
//if len(train.BtmState.BaliseTelegramForPcSimResend) > 0 {
if len(notSendBtm.BaliseTelegramForPcSimResend) > 0 {
slog.Info(fmt.Sprintf("rrrrrrrrrrrrrrrrr111111111:%v", atpReq.String()))
//dd, _ := hex.DecodeString(train.BtmState.BaliseTelegramForPcSimResend)
dd, _ := hex.DecodeString(notSendBtm.BaliseTelegramForPcSimResend)
2024-06-27 10:37:52 +08:00
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, dd)
2024-07-25 14:55:46 +08:00
} else {
2024-08-05 16:32:21 +08:00
slog.Info(fmt.Sprintf("rrrrrrrrrrrrrrrrr2222222222222:%v", atpReq.String()))
2024-07-25 14:55:46 +08:00
timeSyncF := message.NewBtmTimeSyncCheckFrame(trainAtm.CanId.ID4)
timeSyncF.T2 = cl.BtmTk
timeSyncF.T3 = cl.TkNow()
queryData := make([]byte, 0)
queryData = append(queryData, btmRepFrame.EncodeBtmAtp().Encode()...)
queryData = append(queryData, timeSyncF.Encode().Encode()...)
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
2024-04-02 18:20:10 +08:00
}
} else {
2024-08-05 16:32:21 +08:00
2024-07-25 14:55:46 +08:00
timeSyncF := message.NewBtmTimeSyncCheckFrame(trainAtm.CanId.ID4)
2024-04-02 18:20:10 +08:00
timeSyncF.T2 = cl.BtmTk
timeSyncF.T3 = cl.TkNow()
2024-08-05 16:32:21 +08:00
//telCount := strings.Count(train.BtmState.Telegram, "00")
telCount := strings.Count(notSendBtm.Telegram, "00")
//if telCount >= balise_const.UserTelegramByteLen || train.BtmState.IsSend {
if !ok && (notSendBtm.Telegram == "" || telCount >= balise_const.UserTelegramByteLen) {
//slog.Info(fmt.Sprintf("准备发送无数据应答器id:%v", train.BtmState.BaliseId))
2024-07-25 14:55:46 +08:00
queryData := make([]byte, 0)
queryData = append(queryData, btmRepFrame.EncodeBtmAtp().Encode()...)
queryData = append(queryData, timeSyncF.EncodeBtmAtp().Encode()...)
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
2024-08-05 16:32:21 +08:00
//train.BtmState.IsSend = true
} else /*if !train.BtmState.IsSend*/
if !notSendBtm.IsSend {
slog.Info(fmt.Sprintf("准备发送应答id:%v,uuid :%v,接受时间:%v,发送时间:%v , 数据:%v 经过:%v,解报文:%v", notSendBtm.BaliseId, uuid, ts, time.Now().UnixMilli(), notSendBtm.Telegram, notSendBtm.BaliseCount, notSendBtm.MessageCounter))
//slog.Info(fmt.Sprintf("准备发送应答id:%v,uuid :%v,消耗时间:%v , 数据:%v", train.BtmState.BaliseId, uuid, ts-time.Now().UnixMilli(), train.BtmState.Telegram))
/* defer func() {
train.BtmState.IsSend = true
}()*/
2024-04-02 18:20:10 +08:00
//有数据
2024-08-05 16:32:21 +08:00
//aliseData, _ := hex.DecodeString(train.BtmState.Telegram)
aliseData, _ := hex.DecodeString(notSendBtm.Telegram)
2024-07-25 14:55:46 +08:00
stateRepFrame := btmRepFrame.EncodeBtmAtp()
statusDataCf, statusDataCfOk := message.CreateBtmAtpDataRspFramesData(stateRepFrame, aliseData, false, cl.BtmTk, cl.BtmTk, cl.BtmTk)
2024-04-02 18:20:10 +08:00
if statusDataCfOk {
2024-07-25 14:55:46 +08:00
timeSyncF.T2 = cl.BtmTk
timeSyncF.T3 = cl.TkNow()
queryData := make([]byte, 0)
queryData = append(queryData, stateRepFrame.Encode()...)
queryData = append(queryData, timeSyncF.EncodeBtmAtp().Encode()...)
queryData = append(queryData, statusDataCf...) //数据帧包含结束帧
2024-04-02 18:20:10 +08:00
train.BtmState.BaliseTelegramForPcSimResend = fmt.Sprintf("%X", statusDataCf)
2024-07-25 14:55:46 +08:00
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, queryData)
2024-04-02 18:20:10 +08:00
} else {
slog.Error("列车pc仿真 BtmCanetClient应答帧、数据帧编码失败")
}
}
}
}
2024-07-25 14:55:46 +08:00
func createBtmStatus(canIdSn byte, btmState *state_proto.BTMState, atpReq *message.AtpRequestFrame, cl can_btm.BtmClock, dsn byte) *message.BtmStatusRspFrame {
statusF := message.NewBtmStatusRspFrame(canIdSn)
2024-04-02 18:20:10 +08:00
statusF.PowerAmplifierOn = true
statusF.PowerAmplifierFailure = false
statusF.AtpReqCrcCheckWrong = !atpReq.Crc16CheckOk
statusF.AntennaFault = false
statusF.BaliseCounter = byte(btmState.BaliseCount)
statusF.MessageCounter = byte(btmState.MessageCounter)
2024-07-25 14:55:46 +08:00
//statusF.TkTimeA = cl.TkNow()
statusF.TkTimeA = cl.BtmTk
2024-04-02 18:20:10 +08:00
statusF.DetailedCode = 0
if btmState.AboveBalise {
statusF.DetailedCode = 0x07
}
2024-07-25 14:55:46 +08:00
btmState.DataSerialNumber = uint32(dsn)
statusF.Dsn = dsn
2024-04-02 18:20:10 +08:00
return statusF
}
func clock(atpReq *message.AtpRequestFrame) can_btm.BtmClock {
now := time.Now()
return can_btm.BtmClock{BtmTk: atpReq.Time, SysTk: now}
}
func (s *VerifySimulation) ObtainTrainDigitalMockDataForStatus(train *state_proto.TrainState) []message.TrainPcSimBaseMessage {
2024-06-27 10:37:52 +08:00
msgArr := make([]message.TrainPcSimBaseMessage, 0)
vs := train.VobcState
tcc := train.Tcc
if vs.Tc1Active || vs.Tc2Active {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //钥匙激活
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
} else {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
2024-06-27 10:37:52 +08:00
}
2024-07-11 14:58:34 +08:00
if vs.BrakeForce == 0 {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_TO_ZERO, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车制动状态
}
2024-06-27 10:37:52 +08:00
if vs.BrakingStatus {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_BRAKE_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车制动状态
}
2024-06-27 10:37:52 +08:00
if vs.EmergencyBrakingStatus {
2024-07-11 14:58:34 +08:00
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OUTER_EMERGENCY_BRAKE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急制动
2024-06-27 10:37:52 +08:00
}
2024-07-11 14:58:34 +08:00
2024-06-27 10:37:52 +08:00
dir := request_proto.TrainControl_Direction(tcc.DirKey.Val)
2024-07-11 14:58:34 +08:00
/*if vs.DirectionForward && vs.TractionForce == 0 {
2024-06-27 10:37:52 +08:00
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
2024-07-11 14:58:34 +08:00
} else*/if dir == request_proto.TrainControl_FORWARD {
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_FORWORD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_BACKWORD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
2024-06-27 10:37:52 +08:00
} else if dir == request_proto.TrainControl_BACKWARD {
2024-07-11 14:58:34 +08:00
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_FORWORD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_BACKWORD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
}
if vs.RightDoorCloseCommand {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CLOSE_RIGHT_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //关右门按钮
}
if vs.LeftDoorCloseCommand {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CLOSE_LEFT_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //关左门按钮
2024-06-27 10:37:52 +08:00
}
2024-07-11 14:58:34 +08:00
if vs.AllDoorClose {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DOOR_LOCK_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //车门锁闭状态
}
if vs.ObstacleCheckBtn {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OBSTACLE_CHECK, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //障碍物检测按钮
}
if vs.BrakeHeavyFault {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.BRAKE_HEAVY_FAULT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //制动重故障
}
if vs.AtpCutSwitch {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.ATP_CUT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //atp切除
}
if vs.AtpPowerOnBtn {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.ATP_POWER_ON, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //atp上电
}
if vs.TurnbackStatus {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TURN_BACK, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //atp上电
}
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.LIFE_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //逃生门状态
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.EMERGENT_HANDLE_DOWN, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急手柄拉下
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_TRACTION_CUTED, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急手柄拉下
return msgArr
}
func (s *VerifySimulation) ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage {
msgArr := make([]message.TrainPcSimBaseMessage, 0)
stateArr := s.ObtainTrainDigitalMockDataForStatus(train)
msgArr = append(msgArr, stateArr...)
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.ATO_SEND_TRAIN, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //ATO发车按钮
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.LEFT_DOOR_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //左门状态按钮
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.RIGHT_DOOR_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CONFIRM, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_INTEGRITY, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.NOT_BREAK, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //非制动
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{38, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //只牵引
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{40, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //本端机械钩
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{41, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //对端机械钩
train.BtmState = nil
2024-06-27 10:37:52 +08:00
return msgArr
}