2023-10-26 16:41:18 +08:00
|
|
|
|
package message_server
|
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2024-01-11 10:24:56 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
2024-03-26 13:12:17 +08:00
|
|
|
|
"log/slog"
|
2023-11-17 17:01:12 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
2023-10-27 14:57:37 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/message_server/ms_api"
|
2023-12-20 10:37:54 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/mqtt"
|
2023-10-27 14:57:37 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
2023-12-20 10:37:54 +08:00
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-10-27 14:57:37 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-12-20 10:37:54 +08:00
|
|
|
|
func NewPSLMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
mapData := memory.QueryGiData[*data_proto.RtssGraphicStorage](mapId)
|
2024-03-26 13:12:17 +08:00
|
|
|
|
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]PSL按钮状态", mapId), func() error {
|
2023-12-20 10:37:54 +08:00
|
|
|
|
for _, box := range mapData.GateBoxs {
|
|
|
|
|
did := memory.GetMapElementId(box.Common)
|
2024-03-26 13:12:17 +08:00
|
|
|
|
data, err := collectGateBoxPSLState(vs.World, mapId, box)
|
2023-12-20 10:37:54 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2024-03-26 13:12:17 +08:00
|
|
|
|
sendMsg(vs, mapId, did, data)
|
|
|
|
|
}
|
2024-03-29 14:59:20 +08:00
|
|
|
|
for _, ckm := range mapData.GarageDoors {
|
|
|
|
|
did := memory.GetMapElementId(ckm.Common)
|
|
|
|
|
data, err := collectGarageDoorBoxPSLState(vs.World, mapId, ckm)
|
2024-03-26 13:12:17 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
sendMsg(vs, mapId, did, data)
|
2023-10-27 14:57:37 +08:00
|
|
|
|
}
|
2023-12-20 10:37:54 +08:00
|
|
|
|
return nil
|
|
|
|
|
}, 200*time.Millisecond)
|
2023-10-27 14:57:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 13:12:17 +08:00
|
|
|
|
func sendMsg(vs *memory.VerifySimulation, mapId int32, pslId uint32, data *state_proto.PushedDevicesStatus) {
|
|
|
|
|
err := mqtt.GetMsgClient().PubPSLState(vs.SimulationId, mapId, pslId, data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("发送PSL状态出错:%s", err.Error()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func collectGateBoxPSLState(world ecs.World, mapId int32, box *data_proto.GatedBox) (*state_proto.PushedDevicesStatus, error) {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
did := memory.GetMapElementId(box.Common)
|
2023-12-20 10:37:54 +08:00
|
|
|
|
uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
|
2024-02-20 09:20:52 +08:00
|
|
|
|
boxUid := uidStructure.PslIds[did].Uid
|
2023-11-01 16:52:08 +08:00
|
|
|
|
mkxEntry, ok := entity.GetEntityByUid(world, boxUid)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, fmt.Errorf("[id:%s]的门控箱实体找不到", boxUid)
|
|
|
|
|
}
|
|
|
|
|
mkx := component.MkxType.Get(mkxEntry)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
var buttonStateArr []*state_proto.ButtonState
|
2023-11-01 16:52:08 +08:00
|
|
|
|
if ok {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
_, pslStorage := memory.QueryGiDataByName[*data_proto.PslGraphicStorage](box.RefGatedBoxMapCode)
|
2023-12-14 13:04:48 +08:00
|
|
|
|
btnUidMap := make(map[string]uint32, len(pslStorage.PslButtons))
|
|
|
|
|
for _, button := range pslStorage.PslButtons {
|
|
|
|
|
btnUidMap[boxUid+"_"+button.Code] = memory.GetMapElementId(button.Common)
|
|
|
|
|
}
|
2024-02-18 18:26:13 +08:00
|
|
|
|
btnArr := []*ecs.Entry{mkx.PCB, mkx.PCBPL, mkx.POB, mkx.POBPL, mkx.PAB, mkx.PABPL, mkx.WRZF, mkx.WRZFPL,
|
|
|
|
|
mkx.QKQR, mkx.QKQRPL, mkx.MPL, mkx.JXTCPL}
|
2023-11-01 16:52:08 +08:00
|
|
|
|
for _, btn := range btnArr {
|
|
|
|
|
if btn == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2024-02-04 18:22:52 +08:00
|
|
|
|
btnState := component.BitStateType.Get(btn)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
buttonStateArr = append(buttonStateArr, &state_proto.ButtonState{
|
2023-12-14 13:04:48 +08:00
|
|
|
|
Id: btnUidMap[component.UidType.Get(btn).Id],
|
2024-02-04 18:22:52 +08:00
|
|
|
|
Down: btnState.Val,
|
|
|
|
|
Active: btnState.Val,
|
2024-02-06 10:49:46 +08:00
|
|
|
|
//Bypass: btnState.BypassEnable,
|
2023-11-01 16:52:08 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
return &state_proto.PushedDevicesStatus{
|
2023-11-01 16:52:08 +08:00
|
|
|
|
All: true,
|
2024-01-11 10:24:56 +08:00
|
|
|
|
AllStatus: &state_proto.AllDevicesStatus{
|
2023-11-01 16:52:08 +08:00
|
|
|
|
ButtonState: buttonStateArr,
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
2023-10-26 16:41:18 +08:00
|
|
|
|
}
|
2024-03-26 13:12:17 +08:00
|
|
|
|
|
2024-03-29 14:59:20 +08:00
|
|
|
|
func collectGarageDoorBoxPSLState(world ecs.World, mapId int32, box *data_proto.GarageDoor) (*state_proto.PushedDevicesStatus, error) {
|
2024-03-26 13:12:17 +08:00
|
|
|
|
return nil, nil
|
|
|
|
|
//did := memory.GetMapElementId(box.Common)
|
|
|
|
|
//uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
|
|
|
|
|
//boxUid := uidStructure.PslIds[did].Uid
|
|
|
|
|
//mkxEntry, ok := entity.GetEntityByUid(world, boxUid)
|
|
|
|
|
//if !ok {
|
|
|
|
|
// return nil, fmt.Errorf("[id:%s]的门控箱实体找不到", boxUid)
|
|
|
|
|
//}
|
|
|
|
|
//mkx := component.MkxType.Get(mkxEntry)
|
|
|
|
|
//var buttonStateArr []*state_proto.ButtonState
|
|
|
|
|
//if ok {
|
|
|
|
|
// _, pslStorage := memory.QueryGiDataByName[*data_proto.PslGraphicStorage](box.RefGatedBoxMapCode)
|
|
|
|
|
// btnUidMap := make(map[string]uint32, len(pslStorage.PslButtons))
|
|
|
|
|
// for _, button := range pslStorage.PslButtons {
|
|
|
|
|
// btnUidMap[boxUid+"_"+button.Code] = memory.GetMapElementId(button.Common)
|
|
|
|
|
// }
|
|
|
|
|
// btnArr := []*ecs.Entry{mkx.PCB, mkx.PCBPL, mkx.POB, mkx.POBPL, mkx.PAB, mkx.PABPL, mkx.WRZF, mkx.WRZFPL,
|
|
|
|
|
// mkx.QKQR, mkx.QKQRPL, mkx.MPL, mkx.JXTCPL}
|
|
|
|
|
// for _, btn := range btnArr {
|
|
|
|
|
// if btn == nil {
|
|
|
|
|
// continue
|
|
|
|
|
// }
|
|
|
|
|
// btnState := component.BitStateType.Get(btn)
|
|
|
|
|
// buttonStateArr = append(buttonStateArr, &state_proto.ButtonState{
|
|
|
|
|
// Id: btnUidMap[component.UidType.Get(btn).Id],
|
|
|
|
|
// Down: btnState.Val,
|
|
|
|
|
// Active: btnState.Val,
|
|
|
|
|
// //Bypass: btnState.BypassEnable,
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//return &state_proto.PushedDevicesStatus{
|
|
|
|
|
// All: true,
|
|
|
|
|
// AllStatus: &state_proto.AllDevicesStatus{
|
|
|
|
|
// ButtonState: buttonStateArr,
|
|
|
|
|
// },
|
|
|
|
|
//}, nil
|
|
|
|
|
}
|