2024-03-19 08:28:50 +08:00
|
|
|
package message_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
|
|
|
"joylink.club/bj-rtsts-server/message_server/ms_api"
|
|
|
|
"joylink.club/bj-rtsts-server/mqtt"
|
|
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
|
|
|
"log/slog"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
func lowPower(power bool) bool {
|
|
|
|
if power {
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-19 08:28:50 +08:00
|
|
|
// 综合后备盘IBP消息服务
|
2024-03-19 14:49:44 +08:00
|
|
|
func NewTrainControlMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
|
|
|
|
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]列车控制", mapId), func() error {
|
2024-03-19 08:28:50 +08:00
|
|
|
allTrainMap := &vs.Memory.Status.TrainStateMap
|
|
|
|
allTrainMap.Range(func(key, value any) bool {
|
|
|
|
trainId := fmt.Sprintf("%v", key)
|
|
|
|
ts := value.(*state_proto.TrainState)
|
2024-07-04 17:26:46 +08:00
|
|
|
ttcc := ts.Tcc
|
2024-07-19 15:24:28 +08:00
|
|
|
vobc := ts.VobcState
|
2024-07-04 17:39:56 +08:00
|
|
|
lights := make([]*state_proto.TrainControlState_ControlLight, 0)
|
2024-07-19 15:24:28 +08:00
|
|
|
for lightKey, light := range ttcc.LightMaps {
|
|
|
|
switch lightKey {
|
|
|
|
case memory.LIGHT_JJZD:
|
|
|
|
state := lowPower(vobc.LightEmergencyBrakingStatus)
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: state})
|
|
|
|
case memory.LIGHT_QQY:
|
|
|
|
state := lowPower(vobc.LightTractionSafetyCircuit)
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: state})
|
|
|
|
case memory.LIGHT_JSSJH:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LightDriverActive})
|
|
|
|
case memory.LIGHT_TFZDHJ:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.StopNotAllBrake})
|
|
|
|
case memory.LIGHT_QYYX:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.TractionEffective})
|
|
|
|
case memory.LIGHT_ZDYX:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.BrakeEffective})
|
|
|
|
case memory.LIGHT_TFZDSJ:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.ParkingBrakeStatus})
|
|
|
|
case memory.LIGHT_CYZD:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.MostUseBrake})
|
|
|
|
case memory.LIGHT_ZDGL:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.BrakeQuarantine})
|
2024-07-04 17:39:56 +08:00
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
case memory.LIGHT_LSXH:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.NoSpeedSigle})
|
|
|
|
case memory.LIGHT_ZMYX:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LeftDoorState})
|
|
|
|
case memory.LIGHT_YMYX:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.RightDoorState})
|
|
|
|
case memory.LIGHT_ZFZSD:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.TurnbackStatus})
|
|
|
|
case memory.LIGHT_BDATPKC:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LocalAtpControl})
|
2024-08-29 16:09:07 +08:00
|
|
|
case memory.LIGHT_ATOFCZSD:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LightAtoSend})
|
2024-08-30 18:08:14 +08:00
|
|
|
case memory.LIGHT_ATO_OPEN_LEFT_DOOR:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.AtoOpenLeftDoor})
|
|
|
|
case memory.LIGHT_ATO_OPEN_RIGHT_DOOR:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.AtoOpenRightDoor})
|
|
|
|
case memory.LIGHT_ATO_CLOSE_LEFT_DOOR:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.AtoCloseLeftDoor})
|
|
|
|
case memory.LIGHT_ATO_CLOSE_RIGHT_DOOR:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.AtoCloseRightDoor})
|
2024-07-19 15:24:28 +08:00
|
|
|
default:
|
|
|
|
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: light.Val})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buttons := make([]*state_proto.TrainControlState_ControlButton, 0)
|
|
|
|
for _, button := range ttcc.Buttons {
|
|
|
|
buttons = append(buttons, button)
|
|
|
|
}
|
2024-08-22 13:12:03 +08:00
|
|
|
sks := make([]*state_proto.TrainControlState_SwitchKeyChange, 0)
|
|
|
|
for _, sk := range ttcc.SwitchKeyMap {
|
|
|
|
sks = append(sks, sk)
|
|
|
|
}
|
|
|
|
tcc := &state_proto.TrainControlStateMsg{Buttons: buttons, DriverKey: ttcc.DriverKey, SwitchKeys: sks, PushHandler: ttcc.PushHandler, Lights: lights}
|
2024-07-04 17:26:46 +08:00
|
|
|
err := mqtt.GetMsgClient().PubTrainControlState(vs.SimulationId, trainId, tcc)
|
2024-03-19 08:28:50 +08:00
|
|
|
if err != nil {
|
|
|
|
slog.Error("发送列车控制mqtt失败", err)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}, 200*time.Millisecond)
|
|
|
|
}
|