调整联锁驱采数据定义

修改道岔操作接口
完善道岔状态构造返回
This commit is contained in:
walker 2023-11-03 17:27:37 +08:00
parent 27a9a99d85
commit 1130277693
6 changed files with 99 additions and 52 deletions

View File

@ -256,7 +256,10 @@ func turnoutOperation(c *gin.Context) {
} }
simulation := checkDeviceDataAndReturn(req.SimulationId) simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", "request", req) slog.Info("传入状态参数", "request", req)
memory.HandleTurnoutOperation(simulation, req) err := memory.HandleTurnoutOperation(simulation, req)
if err != nil {
panic(sys_error.New(fmt.Sprintf("道岔操作失败, %s", err), err))
}
c.JSON(http.StatusOK, "ok") c.JSON(http.StatusOK, "ok")
} }

View File

@ -241,6 +241,7 @@ func (ms *SfpMs) collectTrainStates() ([]*state.TrainState, error) {
func (ms *SfpMs) collectTurnoutStates() ([]*state.SwitchState, error) { func (ms *SfpMs) collectTurnoutStates() ([]*state.SwitchState, error) {
s := ms.vs s := ms.vs
uidMap := memory.QueryMapUidMapByType(ms.mapId, &graphicData.Turnout{}) uidMap := memory.QueryMapUidMapByType(ms.mapId, &graphicData.Turnout{})
wd := entity.GetWorldData(s.World)
var switchArr []*state.SwitchState var switchArr []*state.SwitchState
for _, u := range uidMap { for _, u := range uidMap {
entry, ok := entity.GetEntityByUid(s.World, u.Uid) entry, ok := entity.GetEntityByUid(s.World, u.Uid)
@ -269,10 +270,27 @@ func (ms *SfpMs) collectTurnoutStates() ([]*state.SwitchState, error) {
// 挤岔 // 挤岔
s.Jc = entry.HasComponent(component.TurnoutFaultJcType) s.Jc = entry.HasComponent(component.TurnoutFaultJcType)
// if entry.HasComponent(component.Zdj9TwoElectronicType) { if entry.HasComponent(component.Zdj9TwoElectronicType) {
// elec := component.Zdj9TwoElectronicType.Get(entry) elec := component.Zdj9TwoElectronicType.Get(entry)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
// } s.Dc = dcj.Val
qdc, err := wd.QueryQdBit(component.UidType.Get(elec.TDC_DCJ).Id)
if err == nil {
s.Qdc = qdc
}
fcj := component.BitStateType.Get(elec.TDC_FCJ)
s.Fc = fcj.Val
qfc, err := wd.QueryQdBit(component.UidType.Get(elec.TDC_FCJ).Id)
if err == nil {
s.Qfc = qfc
}
ycj := component.BitStateType.Get(elec.TDC_YCJ)
s.Yc = ycj.Val
qyc, err := wd.QueryQdBit(component.UidType.Get(elec.TDC_YCJ).Id)
if err == nil {
s.Qyc = qyc
}
}
switchArr = append(switchArr, s) switchArr = append(switchArr, s)
} }
return switchArr, nil return switchArr, nil

View File

@ -1,15 +1,17 @@
package memory package memory_test
import ( import (
"fmt" "fmt"
"testing"
"time"
"joylink.club/bj-rtsts-server/dto/request_proto" "joylink.club/bj-rtsts-server/dto/request_proto"
"joylink.club/bj-rtsts-server/ts" "joylink.club/bj-rtsts-server/ts"
"joylink.club/bj-rtsts-server/ts/protos/graphicData" "joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
"joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts" "joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/entity"
"testing"
"time"
) )
// 先创建一个仿真再调 // 先创建一个仿真再调
@ -18,7 +20,7 @@ func TestHandlePsdOperation(t *testing.T) {
simId := simInfo.SimulationId simId := simInfo.SimulationId
var mapId int32 var mapId int32
for _, id := range simInfo.MapIds { for _, id := range simInfo.MapIds {
if QueryGiType(id) == graphicData.PictureType_StationLayout { if memory.QueryGiType(id) == graphicData.PictureType_StationLayout {
mapId = id mapId = id
} }
} }
@ -26,12 +28,12 @@ func TestHandlePsdOperation(t *testing.T) {
fmt.Println("无信号布置图") fmt.Println("无信号布置图")
return return
} }
data := QueryGiData[*graphicData.RtssGraphicStorage](mapId) data := memory.QueryGiData[*graphicData.RtssGraphicStorage](mapId)
deviceId := data.ScreenDoors[0].Common.Id deviceId := data.ScreenDoors[0].Common.Id
simulation := ts.FindSimulation(simId) simulation := ts.FindSimulation(simId)
wantErr := false wantErr := false
uid := QueryUidByMidAndComId(mapId, deviceId, &graphicData.Turnout{}) uid := memory.QueryUidByMidAndComId(mapId, deviceId, &graphicData.Turnout{})
entry, _ := entity.GetEntityByUid(simulation.World, uid) entry, _ := entity.GetEntityByUid(simulation.World, uid)
asdList := component.AsdListType.Get(entry) asdList := component.AsdListType.Get(entry)
psdModel := entity.GetWorldData(simulation.World).Repo.FindPsd(uid) psdModel := entity.GetWorldData(simulation.World).Repo.FindPsd(uid)
@ -45,7 +47,7 @@ func TestHandlePsdOperation(t *testing.T) {
Operation: request_proto.Psd_Operation(value), Operation: request_proto.Psd_Operation(value),
} }
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
if err := HandlePsdOperation(simulation, req); (err != nil) != wantErr { if err := memory.HandlePsdOperation(simulation, req); (err != nil) != wantErr {
t.Errorf("HandlePsdOperation() error = %v, wantErr %v", err, wantErr) t.Errorf("HandlePsdOperation() error = %v, wantErr %v", err, wantErr)
} }
tick := time.Tick(5 * time.Second) tick := time.Tick(5 * time.Second)

View File

@ -15,34 +15,36 @@ import (
) )
// 处理道岔操作 // 处理道岔操作
func HandleTurnoutOperation(simulation *VerifySimulation, req *request_proto.TurnoutOperationReq) { func HandleTurnoutOperation(simulation *VerifySimulation, req *request_proto.TurnoutOperationReq) error {
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Turnout{}) uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Turnout{})
var err error
switch req.Operation { switch req.Operation {
case request_proto.Turnout_DC: case request_proto.Turnout_DC:
fi.DriveTurnoutDCOn(simulation.World, uid) err = fi.DriveTurnoutDCOn(simulation.World, uid)
case request_proto.Turnout_CancelDC: case request_proto.Turnout_CancelDC:
fi.DriveTurnoutDCOff(simulation.World, uid) err = fi.DriveTurnoutDCOff(simulation.World, uid)
case request_proto.Turnout_FC: case request_proto.Turnout_FC:
fi.DriveTurnoutFCOn(simulation.World, uid) err = fi.DriveTurnoutFCOn(simulation.World, uid)
case request_proto.Turnout_CancelFC: case request_proto.Turnout_CancelFC:
fi.DriveTurnoutFCOff(simulation.World, uid) err = fi.DriveTurnoutFCOff(simulation.World, uid)
case request_proto.Turnout_SetSB: case request_proto.Turnout_SetSB:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_SB) err = fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
case request_proto.Turnout_CancelSB: case request_proto.Turnout_CancelSB:
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB) err = fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
case request_proto.Turnout_SetJC: case request_proto.Turnout_SetJC:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC) err = fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
case request_proto.Turnout_CancelJC: case request_proto.Turnout_CancelJC:
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC) err = fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
case request_proto.Turnout_ForceDw: case request_proto.Turnout_ForceDw:
fi.ForceTurnoutDw(simulation.World, uid) err = fi.ForceTurnoutDw(simulation.World, uid)
case request_proto.Turnout_ForceFw: case request_proto.Turnout_ForceFw:
fi.ForceTurnoutFw(simulation.World, uid) err = fi.ForceTurnoutFw(simulation.World, uid)
case request_proto.Turnout_CancelForce: case request_proto.Turnout_CancelForce:
fi.CancelTurnoutForce(simulation.World, uid) err = fi.CancelTurnoutForce(simulation.World, uid)
default: default:
panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation)) panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
} }
return err
} }
// 获取全部的道岔状态,动力学使用 // 获取全部的道岔状态,动力学使用

View File

@ -351,7 +351,7 @@ func (s *VerifySimulation) GetInterlockCodes() []*config.InterlockConfig {
// 处理接到的联锁消息 // 处理接到的联锁消息
func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) { func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) {
for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息 for _, m := range s.Repo.CiQcList() { // 获取继电器地图信息
if m.StationId != code { if m.StationId != code {
continue continue
} }
@ -370,7 +370,7 @@ func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) {
// 采集联锁中的继电器消息 // 采集联锁中的继电器消息
func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg { func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg {
for _, m := range s.Repo.CentralizedList() { // 获取继电器地图信息 for _, m := range s.Repo.CiQcList() { // 获取继电器地图信息
if m.StationId != code { if m.StationId != code {
continue continue
} }
@ -384,7 +384,7 @@ func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.Inter
} }
rs := true rs := true
for _, j := range l.RefRelays { for _, j := range l.RefRelays {
if j.Position == proto.CjDataItem_Q { if j.Q {
rs = rs && fi.CollectXQCircuitState(s.World, j.RelayId) rs = rs && fi.CollectXQCircuitState(s.World, j.RelayId)
} else { } else {
rs = rs && fi.CollectLXCircuitState(s.World, j.RelayId) rs = rs && fi.CollectLXCircuitState(s.World, j.RelayId)
@ -635,7 +635,32 @@ func buildAndRelateElectronicComponent(repo *proto.Repository, relayGi *graphicD
centralizedStationId := GenerateElementUid(city, lineId, nil, station) centralizedStationId := GenerateElementUid(city, lineId, nil, station)
ref := queryCentralizedStationRef(centralizedStationId, repo) ref := queryCentralizedStationRef(centralizedStationId, repo)
ref.CjList = append(ref.CjList, handlerRelayGiCj(uidsMap, centralizedStationId, relayGi.CiCjList)...) ref.CjList = append(ref.CjList, handlerRelayGiCj(uidsMap, centralizedStationId, relayGi.CiCjList)...)
sortQcTable(ref.CjList)
ref.QdList = append(ref.QdList, handlerRelayGiQd(uidsMap, centralizedStationId, relayGi.CiQdList)...) ref.QdList = append(ref.QdList, handlerRelayGiQd(uidsMap, centralizedStationId, relayGi.CiQdList)...)
sortQcTable(ref.QdList)
}
type IQcTable interface {
GetRow() int32
GetCol() int32
}
func sortQcTable[T IQcTable](s []T) {
sort.SliceStable(s, func(i, j int) bool {
a := s[i]
b := s[j]
if a.GetCol() < b.GetCol() {
return true
} else if a.GetCol() > b.GetCol() {
return false
} else {
if a.GetRow() < b.GetRow() {
return true
} else {
return false
}
}
})
} }
// 查询集中站配置信息 // 查询集中站配置信息
@ -668,11 +693,8 @@ func handlerRelayGiCj(uidsMap *RelayUidStructure, stationId string, ciCj *graphi
index := 0 index := 0
for ci, col := range ciCj.CjList { for ci, col := range ciCj.CjList {
for ri, row := range col.BitList { for ri, row := range col.BitList {
if len(row.RefRelays) == 0 {
index++
continue
}
r := &proto.CjData{Row: int32(ri), Col: int32(ci)} r := &proto.CjData{Row: int32(ri), Col: int32(ci)}
if len(row.RefRelays) > 0 {
for _, j := range row.RefRelays { for _, j := range row.RefRelays {
u := uidsMap.RelayIds[j.RelayId] u := uidsMap.RelayIds[j.RelayId]
if u == nil { if u == nil {
@ -680,12 +702,13 @@ func handlerRelayGiCj(uidsMap *RelayUidStructure, stationId string, ciCj *graphi
} }
d := &proto.CjDataItem{RelayId: u.Uid} d := &proto.CjDataItem{RelayId: u.Uid}
if j.Position == graphicData.CjDataItem_H { if j.Position == graphicData.CjDataItem_H {
d.Position = proto.CjDataItem_H d.Q = false
} else { } else {
d.Position = proto.CjDataItem_Q d.Q = true
} }
r.RefRelays = append(r.RefRelays, d) r.RefRelays = append(r.RefRelays, d)
} }
}
cjList[index] = r cjList[index] = r
index++ index++
} }
@ -707,11 +730,8 @@ func handlerRelayGiQd(uidsMap *RelayUidStructure, stationId string, ciQd *graphi
index := 0 index := 0
for ci, col := range ciQd.QdList { for ci, col := range ciQd.QdList {
for ri, row := range col.BitList { for ri, row := range col.BitList {
if len(row.RefRelays) == 0 {
index++
continue
}
r := &proto.QdData{Row: int32(ri), Col: int32(ci)} r := &proto.QdData{Row: int32(ri), Col: int32(ci)}
if len(row.RefRelays) > 0 {
for _, j := range row.RefRelays { for _, j := range row.RefRelays {
u := uidsMap.RelayIds[j] u := uidsMap.RelayIds[j]
if u == nil { if u == nil {
@ -719,6 +739,7 @@ func handlerRelayGiQd(uidsMap *RelayUidStructure, stationId string, ciQd *graphi
} }
r.RefRelays = append(r.RefRelays, u.Uid) r.RefRelays = append(r.RefRelays, u.Uid)
} }
}
qdList[index] = r qdList[index] = r
index++ index++
} }

View File

@ -1,6 +1,7 @@
package ts package ts
import ( import (
"fmt"
"log/slog" "log/slog"
"runtime" "runtime"
"strconv" "strconv"
@ -85,7 +86,7 @@ func initWorld(s *memory.VerifySimulation) error {
//创建仿真 //创建仿真
w, err := rtss_simulation.NewSimulation(s.Repo) w, err := rtss_simulation.NewSimulation(s.Repo)
if err != nil { if err != nil {
return sys_error.New("仿真创建失败", err) return sys_error.New(fmt.Sprintf("仿真创建失败: %s", err), err)
} }
s.World = w s.World = w
// 保证World关闭 // 保证World关闭