2023-10-26 16:41:18 +08:00
|
|
|
package message_server
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
import (
|
2023-12-26 13:27:09 +08:00
|
|
|
"fmt"
|
2024-01-29 14:42:12 +08:00
|
|
|
"joylink.club/iot/service/model"
|
2023-10-27 14:57:37 +08:00
|
|
|
"time"
|
|
|
|
|
2024-01-18 13:10:28 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
|
|
|
|
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"
|
2023-10-27 14:57:37 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
|
|
|
)
|
|
|
|
|
2023-12-20 10:37:54 +08:00
|
|
|
func NewRccMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
|
2023-12-26 13:27:09 +08:00
|
|
|
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]继电器状态", mapId), func() error {
|
2023-12-20 10:37:54 +08:00
|
|
|
relayStates, err := collectRelayState(vs.World, mapId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-29 14:42:12 +08:00
|
|
|
stationQc, err := collectStationQcState(vs, mapId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
ststes := &state_proto.PushedDevicesStatus{
|
2023-12-20 10:37:54 +08:00
|
|
|
All: true,
|
2024-01-11 10:24:56 +08:00
|
|
|
AllStatus: &state_proto.AllDevicesStatus{
|
2023-12-20 10:37:54 +08:00
|
|
|
ReplyState: relayStates,
|
2024-01-29 14:42:12 +08:00
|
|
|
StationQc: stationQc,
|
2023-12-20 10:37:54 +08:00
|
|
|
},
|
|
|
|
}
|
2023-12-25 14:15:22 +08:00
|
|
|
mqtt.GetMsgClient().PubRCCState(vs.SimulationId, mapId, ststes)
|
2023-12-20 10:37:54 +08:00
|
|
|
return nil
|
|
|
|
}, 200*time.Millisecond)
|
2023-10-27 14:57:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 获取仿真地图的继电器状态,前端推送
|
2024-01-11 10:24:56 +08:00
|
|
|
func collectRelayState(world ecs.World, mapId int32) ([]*state_proto.ReplyState, error) {
|
2023-10-27 14:57:37 +08:00
|
|
|
// 获取本地图下的继电器信息
|
2024-01-11 10:24:56 +08:00
|
|
|
uidMap := memory.QueryMapUidMapByType(mapId, &data_proto.Relay{})
|
|
|
|
var replyStateArr []*state_proto.ReplyState
|
2023-10-27 14:57:37 +08:00
|
|
|
for _, u := range uidMap {
|
2023-12-20 10:37:54 +08:00
|
|
|
entry, ok := entity.GetEntityByUid(world, u.Uid)
|
2023-10-27 14:57:37 +08:00
|
|
|
if !ok {
|
2023-10-27 15:45:43 +08:00
|
|
|
// 暂时注释,很多继电器都没初始化
|
2024-01-10 14:06:01 +08:00
|
|
|
//return nil, fmt.Errorf("继电器实体不存在: World id=%d, uid=%s", r.vs.World.BaliseId(), u.Uid)
|
2023-10-27 15:45:43 +08:00
|
|
|
continue
|
2023-10-27 14:57:37 +08:00
|
|
|
}
|
|
|
|
if entry.HasComponent(component.RelayTag) {
|
|
|
|
bit := component.BitStateType.Get(entry)
|
2024-01-18 13:10:28 +08:00
|
|
|
force := entry.HasComponent(component.RelayFaultForceType)
|
|
|
|
replyStateArr = append(replyStateArr, &state_proto.ReplyState{Id: u.CommonId, Xh: bit.Val, Force: force})
|
2023-10-27 14:57:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return replyStateArr, nil
|
2023-10-26 16:41:18 +08:00
|
|
|
}
|
2024-01-29 14:42:12 +08:00
|
|
|
|
|
|
|
// 收集车站联锁驱采表状态
|
|
|
|
func collectStationQcState(simulation *memory.VerifySimulation, mapId int32) (*state_proto.StationQc, error) {
|
|
|
|
state := &state_proto.StationQc{}
|
|
|
|
relayData := memory.QueryGiData[*data_proto.RelayCabinetGraphicStorage](mapId)
|
|
|
|
if relayData.CiQdList == nil && relayData.CiCjList == nil {
|
|
|
|
return state, nil
|
|
|
|
}
|
|
|
|
stationCode := relayData.UniqueIdPrefix.BelongsConcentrationStation
|
|
|
|
for _, qcEntry := range entity.GetWorldData(simulation.World).CiQcEntities {
|
|
|
|
qcTable := component.CiQcTableType.Get(qcEntry)
|
|
|
|
structure := simulation.UidMap[qcTable.EcsUid]
|
|
|
|
if structure.Code != stationCode {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
//驱采表实体与地图对应后->
|
|
|
|
qcState := component.CiQcStateType.Get(qcEntry)
|
|
|
|
if len(qcTable.QdBits) != 0 {
|
|
|
|
qdBits := model.DecodeBools(qcState.Qbs)
|
|
|
|
for i, qdData := range qcTable.QdBits {
|
|
|
|
state.QdStates = append(state.QdStates, &state_proto.StationQc_State{
|
|
|
|
Row: qdData.Row,
|
|
|
|
Col: qdData.Col,
|
|
|
|
On: qdBits[i],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(qcTable.CjBits) != 0 {
|
|
|
|
cjBits := model.DecodeBools(qcState.Cbs)
|
|
|
|
for i, cjData := range qcTable.CjBits {
|
|
|
|
state.CjStates = append(state.CjStates, &state_proto.StationQc_State{
|
|
|
|
Row: cjData.Row,
|
|
|
|
Col: cjData.Col,
|
|
|
|
On: cjBits[i],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state, nil
|
|
|
|
}
|