【bug】mqtt没有正确发送PSL状态
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 1m32s

This commit is contained in:
thesai 2024-04-08 09:25:06 +08:00
parent b394b3128c
commit a24ae0a14e

View File

@ -17,22 +17,31 @@ import (
func NewPSLMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask { func NewPSLMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
mapData := memory.QueryGiData[*data_proto.RtssGraphicStorage](mapId) mapData := memory.QueryGiData[*data_proto.RtssGraphicStorage](mapId)
uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]PSL按钮状态", mapId), func() error { return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]PSL按钮状态", mapId), func() error {
for _, box := range mapData.GateBoxs { for _, psl := range mapData.PslBoxs {
did := memory.GetMapElementId(box.Common) data, err := collectPslStates(vs.World, psl.RefPslMapCode, uidStructure.PslIds[psl.Common.Id].Uid)
data, err := collectGateBoxPSLState(vs.World, mapId, box)
if err != nil { if err != nil {
return err slog.Error(err.Error())
continue
} }
sendMsg(vs, mapId, did, data) sendMsg(vs, mapId, psl.Common.Id, data)
} }
for _, ckm := range mapData.GarageDoors { for _, psl := range mapData.GarageDoors {
did := memory.GetMapElementId(ckm.Common) data, err := collectPslStates(vs.World, psl.RefPslMapCode, uidStructure.PslIds[psl.Common.Id].Uid)
data, err := collectGarageDoorBoxPSLState(vs.World, mapId, ckm)
if err != nil { if err != nil {
return err slog.Error(err.Error())
continue
} }
sendMsg(vs, mapId, did, data) sendMsg(vs, mapId, psl.Common.Id, data)
}
for _, psl := range mapData.FloodGates {
data, err := collectPslStates(vs.World, psl.RefPslMapCode, uidStructure.PslIds[psl.Common.Id].Uid)
if err != nil {
slog.Error(err.Error())
continue
}
sendMsg(vs, mapId, psl.Common.Id, data)
} }
return nil return nil
}, 200*time.Millisecond) }, 200*time.Millisecond)
@ -45,81 +54,25 @@ func sendMsg(vs *memory.VerifySimulation, mapId int32, pslId uint32, data *state
} }
} }
func collectGateBoxPSLState(world ecs.World, mapId int32, box *data_proto.GatedBox) (*state_proto.PushedDevicesStatus, error) { func collectPslStates(world ecs.World, pslMapCode string, pslUid string) (*state_proto.PushedDevicesStatus, error) {
did := memory.GetMapElementId(box.Common) var btnStates []*state_proto.ButtonState
uidStructure := memory.QueryUidStructure[*memory.StationUidStructure](mapId) _, pslStorage := memory.QueryGiDataByName[*data_proto.PslGraphicStorage](pslMapCode)
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 { for _, button := range pslStorage.PslButtons {
btnUidMap[boxUid+"_"+button.Code] = memory.GetMapElementId(button.Common) btnEntry, ok := entity.GetEntityByUid(world, memory.BuildUid(pslUid, button.Code))
} if !ok {
btnArr := []*ecs.Entry{mkx.PCB, mkx.PCBPL, mkx.POB, mkx.POBPL, mkx.PAB, mkx.PABPL, mkx.WRZF, mkx.WRZFPL, slog.Error(fmt.Sprintf("[id:%s]的PSL的按钮[code:%s]对应的实体找不到", pslUid, button.Code))
mkx.QKQR, mkx.QKQRPL, mkx.MPL, mkx.JXTCPL}
for _, btn := range btnArr {
if btn == nil {
continue continue
} }
btnState := component.BitStateType.Get(btn) btnStates = append(btnStates, &state_proto.ButtonState{
buttonStateArr = append(buttonStateArr, &state_proto.ButtonState{ Id: button.Common.Id,
Id: btnUidMap[component.UidType.Get(btn).Id], Down: component.BitStateType.Get(btnEntry).Val,
Down: btnState.Val, Active: component.BitStateType.Get(btnEntry).Val,
Active: btnState.Val,
//Bypass: btnState.BypassEnable,
}) })
} }
}
return &state_proto.PushedDevicesStatus{ return &state_proto.PushedDevicesStatus{
All: true, All: true,
AllStatus: &state_proto.AllDevicesStatus{ AllStatus: &state_proto.AllDevicesStatus{
ButtonState: buttonStateArr, ButtonState: btnStates,
}, },
}, nil }, nil
} }
func collectGarageDoorBoxPSLState(world ecs.World, mapId int32, box *data_proto.GarageDoor) (*state_proto.PushedDevicesStatus, error) {
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
}