2023-08-01 14:54:11 +08:00
|
|
|
|
package memory
|
|
|
|
|
|
2023-08-01 17:08:45 +08:00
|
|
|
|
import (
|
2024-01-17 17:15:35 +08:00
|
|
|
|
"encoding/hex"
|
2023-10-26 15:06:26 +08:00
|
|
|
|
"encoding/json"
|
2023-09-20 15:14:40 +08:00
|
|
|
|
"fmt"
|
2023-10-19 09:33:40 +08:00
|
|
|
|
"log/slog"
|
|
|
|
|
"math"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
"sort"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
2023-09-22 11:29:56 +08:00
|
|
|
|
"sync"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
|
2023-10-26 15:06:26 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/config"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
2024-01-11 10:24:56 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
2023-10-20 15:08:47 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
2023-10-19 14:44:10 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/dynamics"
|
2023-11-17 16:22:22 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/electrical_machinery"
|
2023-10-19 09:33:40 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/message"
|
2023-10-19 14:44:10 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/semi_physical_train"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
"joylink.club/ecs"
|
2023-11-03 13:35:58 +08:00
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-10-24 10:57:04 +08:00
|
|
|
|
"joylink.club/rtsssimulation/fi"
|
2023-09-20 15:14:40 +08:00
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-08-01 17:08:45 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-08-01 14:54:11 +08:00
|
|
|
|
// 轨旁仿真定义
|
|
|
|
|
type VerifySimulation struct {
|
|
|
|
|
//地图id
|
2023-09-19 11:02:50 +08:00
|
|
|
|
MapIds []int32
|
2023-08-30 13:25:57 +08:00
|
|
|
|
// 项目ID
|
|
|
|
|
ProjectId int32
|
2023-08-01 14:54:11 +08:00
|
|
|
|
//仿真id
|
|
|
|
|
SimulationId string
|
|
|
|
|
//仿真内存数据
|
|
|
|
|
Memory *WaysideMemory
|
2023-09-20 15:14:40 +08:00
|
|
|
|
//模型仓库
|
|
|
|
|
Repo *repository.Repository
|
2023-10-26 15:06:26 +08:00
|
|
|
|
//Rtss仿真世界的
|
|
|
|
|
World ecs.World
|
2024-01-10 14:06:01 +08:00
|
|
|
|
//设备UID映射 key-uid
|
2023-09-25 17:05:17 +08:00
|
|
|
|
uidMap map[string]*elementIdStructure
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 运行环境配置
|
|
|
|
|
runConfig *config.ThridPartyConfig
|
2023-10-27 14:57:37 +08:00
|
|
|
|
// 运行状态
|
2024-01-11 10:24:56 +08:00
|
|
|
|
runState state_proto.SimulationStatus_SimulationState
|
2023-08-01 14:54:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 11:29:56 +08:00
|
|
|
|
// 轨旁仿真内存模型
|
|
|
|
|
type WaysideMemory struct {
|
|
|
|
|
//可变状态数据:轨旁仿真模型状态(全量数据)
|
|
|
|
|
Status *VerifyStatus
|
|
|
|
|
// 要变更的状态:用户操作过的状态记录在这里,增量推送次数据
|
|
|
|
|
ChangeStatus *ChangeVerifyStatus
|
|
|
|
|
//状态保护锁
|
|
|
|
|
rwLock *sync.RWMutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 轨旁仿真模型状态
|
|
|
|
|
type VerifyStatus struct {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//道岔状态,key为道岔id即索引 state_proto.SwitchState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
SwitchStateMap sync.Map
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//轨道状态,key为轨道id即索引 state_proto.LinkState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
LinkStateMap sync.Map
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//列车状态,key为列车id即索引 state_proto.TrainState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
TrainStateMap sync.Map
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//计轴区段状态,key为计轴区段的id即索引 state_proto.SectionState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
AxleSectionStateMap sync.Map
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//物理区段状态,key为物理区段id即索引 state_proto.SectionState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
PhysicalSectionStateMap sync.Map
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//逻辑区段状态,key为逻辑区段id即索引 state_proto.SectionState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
LogicSectionStateMap sync.Map
|
2024-01-11 10:24:56 +08:00
|
|
|
|
//信号机状态,key为信号机id,即索引 state_proto.SignalState
|
2023-09-22 11:29:56 +08:00
|
|
|
|
SignalStateMap sync.Map
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 轨旁仿真模型状态(变更)
|
|
|
|
|
type ChangeVerifyStatus struct {
|
|
|
|
|
VerifyStatus
|
|
|
|
|
//删除的列车ID列表
|
|
|
|
|
RemoveTrainId []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewWaysideMemory() *WaysideMemory {
|
|
|
|
|
return &WaysideMemory{
|
|
|
|
|
Status: &VerifyStatus{},
|
|
|
|
|
ChangeStatus: &ChangeVerifyStatus{},
|
|
|
|
|
rwLock: &sync.RWMutex{},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 14:54:11 +08:00
|
|
|
|
// 创建仿真对象
|
2023-10-26 18:09:09 +08:00
|
|
|
|
func CreateSimulation(projectId int32, mapIds []int32, runConfig *dto.ProjectRunConfigDto) (*VerifySimulation, error) {
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 地图信息
|
2023-09-20 15:14:40 +08:00
|
|
|
|
sort.Slice(mapIds, func(i, j int) bool {
|
2023-11-07 10:49:15 +08:00
|
|
|
|
return QueryGiType(mapIds[i]) < QueryGiType(mapIds[j])
|
2023-09-20 15:14:40 +08:00
|
|
|
|
})
|
2023-10-27 14:57:37 +08:00
|
|
|
|
verifySimulation := &VerifySimulation{
|
|
|
|
|
ProjectId: projectId,
|
|
|
|
|
MapIds: mapIds,
|
2024-01-11 10:24:56 +08:00
|
|
|
|
runState: state_proto.SimulationStatus_PAUSE,
|
2023-10-27 14:57:37 +08:00
|
|
|
|
}
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 设置运行环境
|
|
|
|
|
err := verifySimulation.initRunConfig(runConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 构建Repository
|
|
|
|
|
err = verifySimulation.initRepository()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
return verifySimulation, nil
|
2023-08-01 14:54:11 +08:00
|
|
|
|
}
|
2023-08-01 17:08:45 +08:00
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
|
// 启动
|
|
|
|
|
func (s *VerifySimulation) Start() {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
s.runState = state_proto.SimulationStatus_START
|
2023-10-17 14:35:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
|
// 销毁
|
|
|
|
|
func (s *VerifySimulation) Destroy() {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
s.runState = state_proto.SimulationStatus_DESTROY
|
2023-08-01 17:08:45 +08:00
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
|
2023-10-30 11:13:36 +08:00
|
|
|
|
// 暂停
|
|
|
|
|
func (s *VerifySimulation) Pause() {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
s.runState = state_proto.SimulationStatus_PAUSE
|
2023-10-30 11:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
|
// 获取状态
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func (s *VerifySimulation) GetRunState() state_proto.SimulationStatus_SimulationState {
|
2023-10-27 14:57:37 +08:00
|
|
|
|
return s.runState
|
2023-08-01 17:08:45 +08:00
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
|
2023-09-25 17:05:17 +08:00
|
|
|
|
// 获取仿真世界信息
|
2023-12-14 13:04:48 +08:00
|
|
|
|
func (s *VerifySimulation) GetComIdByUid(uid string) uint32 {
|
2023-09-25 17:05:17 +08:00
|
|
|
|
es := s.uidMap
|
|
|
|
|
if es == nil {
|
|
|
|
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无映射信息"})
|
|
|
|
|
}
|
|
|
|
|
if es[uid] == nil {
|
|
|
|
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无【uid】映射信息"})
|
|
|
|
|
}
|
|
|
|
|
return es[uid].CommonId
|
|
|
|
|
}
|
2023-11-24 15:20:05 +08:00
|
|
|
|
|
|
|
|
|
// GetBtmCanetConfig 获取CANET配置信息
|
|
|
|
|
func (s *VerifySimulation) GetBtmCanetConfig() config.BtmCanetConfig {
|
|
|
|
|
return s.runConfig.BtmCanet
|
|
|
|
|
}
|
2023-11-09 13:05:29 +08:00
|
|
|
|
func (s *VerifySimulation) GetLineAllRsspAxleCfgs() []config.RsspAxleConfig {
|
|
|
|
|
return s.runConfig.RsspAxleCfgs
|
|
|
|
|
}
|
2023-09-25 17:05:17 +08:00
|
|
|
|
|
2023-11-14 10:31:06 +08:00
|
|
|
|
// GetSectionCodePoints 获取集中站的区段码表
|
|
|
|
|
func (s *VerifySimulation) GetSectionCodePoints(city string, lineId string, centralizedStation string) []*proto.CiSectionCodePoint {
|
2023-11-07 17:47:47 +08:00
|
|
|
|
stationUid := GenerateElementUid(city, lineId, nil, centralizedStation)
|
|
|
|
|
ref := s.Repo.GetCentralizedStationRef(stationUid)
|
|
|
|
|
if ref == nil {
|
2023-11-14 10:31:06 +08:00
|
|
|
|
return nil
|
2023-11-07 17:47:47 +08:00
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-14 10:31:06 +08:00
|
|
|
|
return ref.SectionCodePoints
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CollectSectionStatus 收集仿真中计轴区段状态
|
|
|
|
|
func (s *VerifySimulation) CollectSectionStatus(city string, lineId string, centralizedStation string) ([]*message.SectionStatusMsg, error) {
|
|
|
|
|
stationUid := GenerateElementUid(city, lineId, nil, centralizedStation)
|
|
|
|
|
//
|
|
|
|
|
codePoints := s.GetSectionCodePoints(city, lineId, centralizedStation)
|
2023-11-07 17:47:47 +08:00
|
|
|
|
if len(codePoints) <= 0 {
|
|
|
|
|
return nil, fmt.Errorf("没有找到GetCentralizedStationRef[%s]的区段码表为空", stationUid)
|
|
|
|
|
}
|
2023-11-14 17:57:54 +08:00
|
|
|
|
//slog.Debug("收集计轴区段状态", "区段码表len", len(codePoints))
|
2023-11-07 17:47:47 +08:00
|
|
|
|
//
|
|
|
|
|
var msg []*message.SectionStatusMsg
|
|
|
|
|
var axleSectionIds []string
|
|
|
|
|
for _, section := range codePoints {
|
|
|
|
|
axleSectionIds = append(axleSectionIds, section.SectionId)
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-14 17:57:54 +08:00
|
|
|
|
//slog.Debug("收集计轴区段状态", "计轴区段len", len(axleSectionIds), "axleSectionIds", axleSectionIds)
|
2023-11-07 17:47:47 +08:00
|
|
|
|
as, e := fi.FindAxleSectionsStatus(s.World, axleSectionIds)
|
|
|
|
|
if e != nil { //从仿真中收集计轴区段状态的失败列表
|
|
|
|
|
return nil, e
|
|
|
|
|
}
|
2023-11-14 17:57:54 +08:00
|
|
|
|
//slog.Debug("收集计轴区段状态", "仿真中计轴状态len", len(as))
|
2023-11-07 17:47:47 +08:00
|
|
|
|
//
|
|
|
|
|
stateMap := make(map[string]*fi.AxleSectionState)
|
|
|
|
|
for _, a := range as {
|
|
|
|
|
stateMap[a.Id] = a
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
sort.SliceStable(codePoints, func(i, j int) bool {
|
|
|
|
|
return codePoints[i].Row < codePoints[j].Row
|
|
|
|
|
})
|
|
|
|
|
//
|
|
|
|
|
for _, codePoint := range codePoints {
|
|
|
|
|
sectionState, find := stateMap[codePoint.SectionId]
|
|
|
|
|
if find {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
state_proto := &message.SectionStatusMsg{}
|
|
|
|
|
state_proto.Rac = sectionState.Rac
|
|
|
|
|
state_proto.Rjt = sectionState.Rjt
|
|
|
|
|
state_proto.Rjo = sectionState.Rjo
|
|
|
|
|
state_proto.Occ = sectionState.Occ
|
|
|
|
|
state_proto.Clr = sectionState.Clr
|
|
|
|
|
msg = append(msg, state_proto)
|
2023-11-07 17:47:47 +08:00
|
|
|
|
} else {
|
|
|
|
|
return nil, fmt.Errorf("仿真中没有对应区段[%s]的状态", codePoint.SectionId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-11-14 17:57:54 +08:00
|
|
|
|
//slog.Debug("收集计轴区段状态", "区段计轴msgLen", len(msg))
|
2023-11-07 17:47:47 +08:00
|
|
|
|
return msg, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 09:33:40 +08:00
|
|
|
|
// 采集动力学道岔状态
|
2024-01-17 17:01:43 +08:00
|
|
|
|
func (s *VerifySimulation) CollectDynamicsTurnoutInfo() *message.DynamicsTurnoutInfo {
|
|
|
|
|
turnoutState := &message.DynamicsTurnoutInfo{}
|
|
|
|
|
for _, turnout := range s.Repo.TurnoutList() {
|
|
|
|
|
sta := s.uidMap[turnout.Id()]
|
2023-11-03 13:35:58 +08:00
|
|
|
|
if sta == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2024-01-17 17:01:43 +08:00
|
|
|
|
entry, ok := entity.GetEntityByUid(s.World, turnout.Id())
|
|
|
|
|
if !ok {
|
|
|
|
|
slog.Warn(fmt.Sprintf("id=%s的道岔不存在", turnout.Id()))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if !entry.HasComponent(component.TurnoutPositionType) {
|
|
|
|
|
return nil
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
2024-01-17 17:01:43 +08:00
|
|
|
|
pos := component.TurnoutPositionType.Get(entry)
|
|
|
|
|
turnoutState.TurnoutInfos = append(turnoutState.TurnoutInfos, &message.TurnoutInfo{
|
2024-01-19 11:17:36 +08:00
|
|
|
|
Code: uint16(sta.CommonId),
|
2024-01-17 17:01:43 +08:00
|
|
|
|
NPosition: pos.Dw,
|
|
|
|
|
RPosition: pos.Fw,
|
|
|
|
|
})
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
2024-01-17 17:01:43 +08:00
|
|
|
|
return turnoutState
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 13:22:47 +08:00
|
|
|
|
// HandleSectionCmdMsg 计轴设备接收到联锁发送来的控制命令
|
2023-11-07 17:47:47 +08:00
|
|
|
|
func (s *VerifySimulation) HandleSectionCmdMsg(city string, lineId string, centralizedStation string, msg *message.SectionCmdMsgPack) {
|
|
|
|
|
stationUid := GenerateElementUid(city, lineId, nil, centralizedStation)
|
|
|
|
|
ref := s.Repo.GetCentralizedStationRef(stationUid)
|
|
|
|
|
if ref == nil {
|
|
|
|
|
slog.Warn(fmt.Sprintf("没有找到GetCentralizedStationRef [%s]", stationUid))
|
|
|
|
|
return
|
2023-11-07 13:22:47 +08:00
|
|
|
|
}
|
2023-11-07 17:47:47 +08:00
|
|
|
|
//
|
|
|
|
|
codePoints := ref.SectionCodePoints
|
|
|
|
|
if len(codePoints) != len(msg.Scs) {
|
|
|
|
|
slog.Warn(fmt.Sprintf("本地配置区段码表个数[%d] != 联锁发送集中站[%s]的区段命令个数[%d]", len(codePoints), stationUid, len(msg.Scs)))
|
|
|
|
|
return
|
2023-11-07 13:22:47 +08:00
|
|
|
|
}
|
2023-11-07 17:47:47 +08:00
|
|
|
|
//
|
|
|
|
|
var cpSectionMap = make(map[int]*proto.CiSectionCodePoint)
|
|
|
|
|
for _, cp := range codePoints {
|
|
|
|
|
cpSectionMap[int(cp.Row)] = cp
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
var cmds []*fi.AxleSectionCmd
|
|
|
|
|
for index, cmdMsg := range msg.Scs {
|
|
|
|
|
cp := cpSectionMap[index]
|
|
|
|
|
cmd := &fi.AxleSectionCmd{}
|
|
|
|
|
cmd.SectionId = cp.SectionId
|
|
|
|
|
cmd.Drst = cmdMsg.Drst
|
|
|
|
|
cmd.Pdrst = cmdMsg.Pdrst
|
|
|
|
|
cmds = append(cmds, cmd)
|
|
|
|
|
}
|
|
|
|
|
fi.AxleSectionRstDrive(s.World, cmds)
|
2023-11-07 13:22:47 +08:00
|
|
|
|
}
|
2023-11-07 17:47:47 +08:00
|
|
|
|
|
2023-10-19 09:33:40 +08:00
|
|
|
|
// 处理动力学列车速度消息
|
|
|
|
|
func (s *VerifySimulation) HandleDynamicsTrainInfo(info *message.DynamicsTrainInfo) {
|
2023-11-09 15:58:16 +08:00
|
|
|
|
trainId := strconv.Itoa(int(info.Number))
|
|
|
|
|
_, ok := s.Memory.Status.TrainStateMap.Load(trainId)
|
2023-10-19 09:33:40 +08:00
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 给半实物仿真发送速度
|
2023-10-19 14:44:10 +08:00
|
|
|
|
semi_physical_train.Default().SendTrainControlMessage(info)
|
2023-10-19 09:33:40 +08:00
|
|
|
|
// 更新列车状态
|
2023-11-17 16:22:22 +08:00
|
|
|
|
trainState := UpdateTrainStateByDynamics(s, trainId, info)
|
|
|
|
|
// 更新电机转速
|
|
|
|
|
electrical_machinery.Default().SendElectricMachineryMessage(&message.ElectricMachinery{
|
|
|
|
|
Speed: info.Speed,
|
|
|
|
|
WheelDiameter: trainState.WheelDiameter,
|
|
|
|
|
IsBack: trainState.VobcState.DirectionBackward,
|
|
|
|
|
})
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 获取动力学配置信息
|
|
|
|
|
func (s *VerifySimulation) GetDynamicsRunConfig() *config.DynamicsConfig {
|
|
|
|
|
return &s.runConfig.Dynamics
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 11:22:30 +08:00
|
|
|
|
func (s *VerifySimulation) GetCidcModbusConfig() []config.CidcModbusConfig {
|
|
|
|
|
return s.runConfig.CidcModbus
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 获取动力学运行资源
|
|
|
|
|
func (s *VerifySimulation) GetDynamicsRunRepository() *message.LineBaseInfo {
|
|
|
|
|
info := &message.LineBaseInfo{}
|
|
|
|
|
for _, model := range s.Repo.LinkList() {
|
|
|
|
|
id, _ := strconv.Atoi(model.Id())
|
|
|
|
|
link := &message.Link{
|
|
|
|
|
ID: int32(id),
|
|
|
|
|
Len: int32(model.Length()),
|
|
|
|
|
}
|
|
|
|
|
info.LinkList = append(info.LinkList, link)
|
|
|
|
|
if model.ARelation() != nil {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnoutId := s.GetComIdByUid(model.ARelation().Device().Id())
|
2023-10-26 15:06:26 +08:00
|
|
|
|
link.ARelTurnoutId = int32(turnoutId)
|
|
|
|
|
switch model.ARelation().Port() {
|
|
|
|
|
case proto.Port_A:
|
|
|
|
|
link.ARelTurnoutPoint = "A"
|
|
|
|
|
case proto.Port_B:
|
|
|
|
|
link.ARelTurnoutPoint = "B"
|
|
|
|
|
case proto.Port_C:
|
|
|
|
|
link.ARelTurnoutPoint = "C"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if model.BRelation() != nil {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnoutId := s.GetComIdByUid(model.BRelation().Device().Id())
|
2023-10-26 15:06:26 +08:00
|
|
|
|
link.BRelTurnoutId = int32(turnoutId)
|
|
|
|
|
switch model.BRelation().Port() {
|
|
|
|
|
case proto.Port_A:
|
|
|
|
|
link.BRelTurnoutPoint = "A"
|
|
|
|
|
case proto.Port_B:
|
|
|
|
|
link.BRelTurnoutPoint = "B"
|
|
|
|
|
case proto.Port_C:
|
|
|
|
|
link.BRelTurnoutPoint = "C"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, model := range s.Repo.SlopeList() {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
id := s.GetComIdByUid(model.Id())
|
2023-10-26 15:06:26 +08:00
|
|
|
|
slope := &message.Slope{
|
|
|
|
|
ID: int32(id),
|
|
|
|
|
StartLinkOffset: int32(model.StartLinkPosition().Offset()),
|
|
|
|
|
EndLinkOffset: int32(model.EndLinkPosition().Offset()),
|
|
|
|
|
DegreeTrig: model.Degree(),
|
|
|
|
|
}
|
|
|
|
|
info.SlopeList = append(info.SlopeList, slope)
|
|
|
|
|
startLinkId, _ := strconv.Atoi(model.StartLinkPosition().Link().Id())
|
|
|
|
|
slope.StartLinkId = int32(startLinkId)
|
|
|
|
|
endLinkId, _ := strconv.Atoi(model.EndLinkPosition().Link().Id())
|
|
|
|
|
slope.EndLinkId = int32(endLinkId)
|
|
|
|
|
}
|
|
|
|
|
for _, model := range s.Repo.SectionalCurvatureList() {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
id := s.GetComIdByUid(model.Id())
|
2023-10-26 15:06:26 +08:00
|
|
|
|
curve := &message.Curve{
|
|
|
|
|
ID: int32(id),
|
|
|
|
|
StartLinkOffset: int32(model.StartLinkPosition().Offset()),
|
|
|
|
|
EndLinkOffset: int32(model.EndLinkPosition().Offset()),
|
|
|
|
|
Curvature: model.Radius(),
|
|
|
|
|
}
|
|
|
|
|
info.CurveList = append(info.CurveList, curve)
|
|
|
|
|
startLinkId, _ := strconv.Atoi(model.StartLinkPosition().Link().Id())
|
|
|
|
|
curve.StartLinkId = int32(startLinkId)
|
|
|
|
|
endLinkId, _ := strconv.Atoi(model.EndLinkPosition().Link().Id())
|
|
|
|
|
curve.EndLinkId = int32(endLinkId)
|
|
|
|
|
}
|
|
|
|
|
return info
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 09:33:40 +08:00
|
|
|
|
// 发送给前端的速度格式化
|
|
|
|
|
func speedParse(speed float32) int32 {
|
|
|
|
|
return int32(math.Abs(float64(speed * 3.6 * 100)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理半实物仿真列车控制消息
|
2023-10-19 14:44:10 +08:00
|
|
|
|
func (s *VerifySimulation) HandleSemiPhysicalTrainControlMsg(b []byte) {
|
|
|
|
|
s.Memory.Status.TrainStateMap.Range(func(_, value any) bool {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
train := value.(*state_proto.TrainState)
|
2023-10-19 14:44:10 +08:00
|
|
|
|
if !train.Show { // 下线列车
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
trainId, err := strconv.Atoi(train.Id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
|
|
|
|
}
|
|
|
|
|
d := append(b, uint8(trainId))
|
|
|
|
|
// 发送给动力学
|
|
|
|
|
dynamics.Default().SendTrainControlMessage(d)
|
|
|
|
|
// 存放至列车中
|
|
|
|
|
controlMessage := &message.TrainControlMsg{}
|
|
|
|
|
controlMessage.Decode(b)
|
|
|
|
|
train.VobcState = controlMessage.ControlInfo
|
|
|
|
|
return true
|
|
|
|
|
})
|
2023-10-19 09:33:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 获取半实物运行配置信息
|
|
|
|
|
func (s *VerifySimulation) GetSemiPhysicalRunConfig() *config.VobcConfig {
|
|
|
|
|
return &s.runConfig.Vobc
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 15:23:29 +08:00
|
|
|
|
// 获取所有联锁配置唯一Code
|
|
|
|
|
func (s *VerifySimulation) GetInterlockCodes() []*config.InterlockConfig {
|
|
|
|
|
stationMap := make(map[string]string)
|
|
|
|
|
for _, station := range s.Repo.StationList() {
|
|
|
|
|
stationMap[station.GetCode()] = station.Id()
|
|
|
|
|
}
|
|
|
|
|
var configs []*config.InterlockConfig
|
|
|
|
|
for _, c := range s.runConfig.Interlocks {
|
|
|
|
|
if stationMap[c.Code] == "" || !c.Open {
|
|
|
|
|
continue
|
2023-10-24 10:57:04 +08:00
|
|
|
|
}
|
2023-10-31 15:23:29 +08:00
|
|
|
|
configs = append(configs, &config.InterlockConfig{
|
|
|
|
|
Code: stationMap[c.Code],
|
|
|
|
|
Ip: c.Ip,
|
|
|
|
|
LocalPort: c.LocalPort,
|
|
|
|
|
RemotePort: c.RemotePort,
|
|
|
|
|
Open: c.Open,
|
|
|
|
|
})
|
2023-10-24 10:57:04 +08:00
|
|
|
|
}
|
2023-10-31 15:23:29 +08:00
|
|
|
|
return configs
|
2023-10-24 09:03:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 15:23:29 +08:00
|
|
|
|
// 处理接到的联锁消息
|
|
|
|
|
func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) {
|
2023-11-03 17:27:37 +08:00
|
|
|
|
for _, m := range s.Repo.CiQcList() { // 获取继电器地图信息
|
2023-10-31 15:23:29 +08:00
|
|
|
|
if m.StationId != code {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-11-01 16:55:16 +08:00
|
|
|
|
driverMsg := message.NewInterlockReceiveMsgPkg(0, len(m.QdList), len(m.TransponderId))
|
2023-10-31 15:23:29 +08:00
|
|
|
|
driverMsg.Decode(b)
|
|
|
|
|
driveState := driverMsg.DriveInfo
|
|
|
|
|
for i, r := range m.QdList {
|
|
|
|
|
ds := driveState[i]
|
|
|
|
|
for _, b := range r.RefRelays {
|
|
|
|
|
slog.Debug("继电器位【%s】获取到驱动状态【%v】", b, ds)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-01 16:55:16 +08:00
|
|
|
|
return
|
2023-10-31 15:23:29 +08:00
|
|
|
|
}
|
2023-10-26 15:06:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 10:57:04 +08:00
|
|
|
|
// 采集联锁中的继电器消息
|
2023-10-31 15:23:29 +08:00
|
|
|
|
func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.InterlockSendMsgPkg {
|
2023-11-03 17:27:37 +08:00
|
|
|
|
for _, m := range s.Repo.CiQcList() { // 获取继电器地图信息
|
2023-10-31 15:23:29 +08:00
|
|
|
|
if m.StationId != code {
|
2023-10-27 17:57:12 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2023-10-31 15:23:29 +08:00
|
|
|
|
if len(m.CjList) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2023-10-31 09:39:40 +08:00
|
|
|
|
collectInfo := make([]bool, len(m.CjList))
|
|
|
|
|
for i, l := range m.CjList {
|
|
|
|
|
if l == nil || len(l.RefRelays) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
rs := true
|
|
|
|
|
for _, j := range l.RefRelays {
|
2023-11-03 17:27:37 +08:00
|
|
|
|
if j.Q {
|
2023-10-31 09:39:40 +08:00
|
|
|
|
rs = rs && fi.CollectXQCircuitState(s.World, j.RelayId)
|
|
|
|
|
} else {
|
|
|
|
|
rs = rs && fi.CollectLXCircuitState(s.World, j.RelayId)
|
2023-10-27 17:57:12 +08:00
|
|
|
|
}
|
2023-11-01 16:55:16 +08:00
|
|
|
|
if !rs {
|
|
|
|
|
break
|
|
|
|
|
}
|
2023-10-27 17:57:12 +08:00
|
|
|
|
}
|
2023-10-31 09:39:40 +08:00
|
|
|
|
collectInfo[i] = rs
|
2023-10-24 10:57:04 +08:00
|
|
|
|
}
|
2023-11-06 15:20:45 +08:00
|
|
|
|
return message.NewInterlockSendMsgPkg(collectInfo)
|
2023-10-24 10:57:04 +08:00
|
|
|
|
}
|
2023-10-31 15:23:29 +08:00
|
|
|
|
return nil
|
2023-10-24 10:57:04 +08:00
|
|
|
|
}
|
2023-10-24 09:03:38 +08:00
|
|
|
|
|
2023-11-17 16:22:22 +08:00
|
|
|
|
// 获取电机转速参数
|
|
|
|
|
func (s *VerifySimulation) GetElectricMachineryRunConfig() *config.ElectricMachineryConfig {
|
|
|
|
|
return &s.runConfig.ElectricMachinery
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 初始化仿真运行配置
|
2023-10-26 18:09:09 +08:00
|
|
|
|
func (s *VerifySimulation) initRunConfig(runConfig *dto.ProjectRunConfigDto) error {
|
|
|
|
|
if runConfig == nil || runConfig.ConfigContent == "" {
|
2023-10-26 15:06:26 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
var configMap config.ThridPartyConfig
|
2023-10-26 18:09:09 +08:00
|
|
|
|
err := json.Unmarshal([]byte(runConfig.ConfigContent), &configMap)
|
2023-10-26 15:06:26 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
return sys_error.New("配置信息格式错误", err)
|
|
|
|
|
}
|
|
|
|
|
s.runConfig = &configMap
|
2023-10-26 18:09:09 +08:00
|
|
|
|
s.runConfig.Id = runConfig.Id
|
2023-10-26 15:06:26 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 09:12:40 +08:00
|
|
|
|
// 获取仿真运行参数ID
|
|
|
|
|
func (s *VerifySimulation) GetRunConfigId() int32 {
|
|
|
|
|
if s.runConfig == nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
return s.runConfig.Id
|
|
|
|
|
}
|
2023-11-24 15:20:05 +08:00
|
|
|
|
func (s *VerifySimulation) EvnWorld() ecs.World {
|
|
|
|
|
return s.World
|
|
|
|
|
}
|
2023-10-27 09:12:40 +08:00
|
|
|
|
|
2023-10-26 15:06:26 +08:00
|
|
|
|
// 初始化运行资源
|
|
|
|
|
func (s *VerifySimulation) initRepository() error {
|
|
|
|
|
// 构建Repository
|
|
|
|
|
var mapIdStrSlice []string
|
2023-12-15 17:02:42 +08:00
|
|
|
|
var mapVersion []string
|
2023-10-26 15:06:26 +08:00
|
|
|
|
for _, id := range s.MapIds {
|
|
|
|
|
mapIdStrSlice = append(mapIdStrSlice, strconv.Itoa(int(id)))
|
2023-12-15 17:02:42 +08:00
|
|
|
|
mapVersion = append(mapVersion, strconv.Itoa(int(QueryGiVersion(id))))
|
2023-10-26 15:06:26 +08:00
|
|
|
|
}
|
|
|
|
|
repoId := strings.Join(mapIdStrSlice, "|")
|
2023-12-15 17:02:42 +08:00
|
|
|
|
repoVersion := strings.Join(mapVersion, ".")
|
2023-10-26 15:06:26 +08:00
|
|
|
|
repo := repository.FindRepository(repoId, repoVersion)
|
|
|
|
|
if repo == nil {
|
|
|
|
|
protoRepo, err := buildProtoRepository(s.MapIds)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return sys_error.New("数据错误", err)
|
|
|
|
|
}
|
|
|
|
|
protoRepo.Id, protoRepo.Version = repoId, repoVersion
|
|
|
|
|
newRepo, err := repository.BuildRepository(protoRepo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return sys_error.New("数据错误", err)
|
|
|
|
|
}
|
|
|
|
|
repo = newRepo
|
|
|
|
|
}
|
|
|
|
|
s.Repo = repo
|
|
|
|
|
s.Memory = NewWaysideMemory()
|
|
|
|
|
// 构建所有UID映射关系,
|
|
|
|
|
s.uidMap = buildRepositoryAllUidsMap(s.MapIds, s.Repo)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:13:25 +08:00
|
|
|
|
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
repo := &proto.Repository{}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
var exceptStationGiMapIds []int32
|
|
|
|
|
//创建设备
|
|
|
|
|
for _, mapId := range mapIds {
|
|
|
|
|
giType := QueryGiType(mapId)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if giType == data_proto.PictureType_StationLayout {
|
|
|
|
|
stationGi := QueryGiData[*data_proto.RtssGraphicStorage](mapId)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
fillProtoRepository(repo, stationGi, mapId)
|
|
|
|
|
} else {
|
|
|
|
|
exceptStationGiMapIds = append(exceptStationGiMapIds, mapId)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-28 14:10:20 +08:00
|
|
|
|
//构建并关联电子元件
|
2023-09-22 15:13:25 +08:00
|
|
|
|
for _, mapId := range exceptStationGiMapIds {
|
|
|
|
|
giType := QueryGiType(mapId)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if giType == data_proto.PictureType_RelayCabinetLayout {
|
|
|
|
|
relayGi := QueryGiData[*data_proto.RelayCabinetGraphicStorage](mapId)
|
2023-09-28 14:10:20 +08:00
|
|
|
|
buildAndRelateElectronicComponent(repo, relayGi, mapId)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-07 15:10:19 +08:00
|
|
|
|
//构建信号平面图中物理区段码表与集中站的关系
|
|
|
|
|
for _, mapId := range mapIds {
|
|
|
|
|
giType := QueryGiType(mapId)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if giType == data_proto.PictureType_StationLayout {
|
|
|
|
|
stationGi := QueryGiData[*data_proto.RtssGraphicStorage](mapId)
|
2023-11-07 15:10:19 +08:00
|
|
|
|
buildSectionCodePoint(repo, stationGi, mapId)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
return repo, nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func buildSectionCodePoint(repo *proto.Repository, storage *data_proto.RtssGraphicStorage, mapId int32) {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
// city := storage.UniqueIdPrefix.City
|
|
|
|
|
// lineId := storage.UniqueIdPrefix.LineId
|
|
|
|
|
uidsMap := QueryUidStructure[*StationUidStructure](mapId)
|
2023-11-07 15:10:19 +08:00
|
|
|
|
for _, sscp := range storage.SectionCodePointList {
|
|
|
|
|
centralizedStation := sscp.CentralizedStation
|
|
|
|
|
sectionGIds := sscp.SectionIds
|
2023-12-14 13:04:48 +08:00
|
|
|
|
centralizedStationId := uidsMap.StationIds[centralizedStation].Uid // GenerateElementUid(city, lineId, nil, centralizedStation)
|
2023-11-07 15:10:19 +08:00
|
|
|
|
ref := queryCentralizedStationRef(centralizedStationId, repo)
|
|
|
|
|
var ccs []*proto.CiSectionCodePoint
|
|
|
|
|
for sectionPoint, sectionGId := range sectionGIds {
|
|
|
|
|
cc := &proto.CiSectionCodePoint{}
|
|
|
|
|
cc.Row = int32(sectionPoint)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
cc.SectionId = QueryUidByMidAndComId(mapId, sectionGId, &data_proto.Section{})
|
2023-11-07 15:10:19 +08:00
|
|
|
|
ccs = append(ccs, cc)
|
|
|
|
|
}
|
|
|
|
|
ref.SectionCodePoints = ccs
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func buildAndRelateElectronicComponent(repo *proto.Repository, relayGi *data_proto.RelayCabinetGraphicStorage, mapId int32) {
|
2023-11-07 14:30:08 +08:00
|
|
|
|
relayUidStructure := QueryUidStructure[*RelayUidStructure](mapId)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
city := relayGi.UniqueIdPrefix.City
|
|
|
|
|
lineId := relayGi.UniqueIdPrefix.LineId
|
|
|
|
|
station := relayGi.UniqueIdPrefix.BelongsConcentrationStation
|
2023-11-02 15:54:26 +08:00
|
|
|
|
stationUid := GenerateElementUid(city, lineId, nil, station)
|
2023-10-19 17:09:57 +08:00
|
|
|
|
relayMap := make(map[string]*proto.Relay)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
for _, relay := range relayGi.Relays {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
rid := GetMapElementId(relay.Common)
|
2023-10-19 17:09:57 +08:00
|
|
|
|
repoRelay := &proto.Relay{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: relayUidStructure.RelayIds[rid].Uid,
|
2023-11-02 15:54:26 +08:00
|
|
|
|
Code: relay.Code,
|
|
|
|
|
Model: convertRelayModel(relay.NewModel),
|
|
|
|
|
StationId: stationUid,
|
2023-10-19 17:09:57 +08:00
|
|
|
|
}
|
|
|
|
|
repo.Relays = append(repo.Relays, repoRelay)
|
|
|
|
|
relayMap[repoRelay.Id] = repoRelay
|
2023-09-28 14:10:20 +08:00
|
|
|
|
}
|
|
|
|
|
for _, pfp := range relayGi.PhaseFailureProtectors {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
pid := GetMapElementId(pfp.Common)
|
2023-09-28 14:10:20 +08:00
|
|
|
|
repo.PhaseFailureProtectors = append(repo.PhaseFailureProtectors, &proto.PhaseFailureProtector{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: relayUidStructure.RelayIds[pid].Uid,
|
2023-09-28 14:10:20 +08:00
|
|
|
|
Code: pfp.Code,
|
2023-09-22 15:13:25 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
turnoutMap := make(map[string]*proto.Turnout)
|
|
|
|
|
for _, turnout := range repo.Turnouts {
|
|
|
|
|
turnoutMap[turnout.Id] = turnout
|
|
|
|
|
}
|
|
|
|
|
signalMap := make(map[string]*proto.Signal)
|
|
|
|
|
for _, signal := range repo.Signals {
|
|
|
|
|
signalMap[signal.Id] = signal
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
stationMap := make(map[string]*proto.Station)
|
|
|
|
|
for _, station := range repo.Stations {
|
|
|
|
|
stationMap[station.Id] = station
|
|
|
|
|
}
|
2023-10-19 17:09:57 +08:00
|
|
|
|
psdMap := make(map[string]*proto.Psd)
|
|
|
|
|
for _, psd := range repo.Psds {
|
|
|
|
|
psdMap[psd.Id] = psd
|
|
|
|
|
}
|
|
|
|
|
platformMap := make(map[string]*proto.Platform)
|
|
|
|
|
for _, platform := range repo.Platforms {
|
|
|
|
|
platformMap[platform.Id] = platform
|
|
|
|
|
}
|
2023-11-09 14:27:35 +08:00
|
|
|
|
ciecs := stationMap[stationUid] //联锁集中站
|
2023-11-16 16:54:23 +08:00
|
|
|
|
if ciecs == nil {
|
|
|
|
|
panic(fmt.Errorf("联锁集中站[%s]不存在", stationUid))
|
|
|
|
|
}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
for _, relationship := range relayGi.DeviceRelateRelayList {
|
2023-09-26 09:34:23 +08:00
|
|
|
|
switch relationship.DeviceType {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Turnout:
|
2023-09-22 15:13:25 +08:00
|
|
|
|
turnout := turnoutMap[GenerateElementUid(city, lineId, []string{station}, relationship.Code)]
|
2023-09-26 10:25:01 +08:00
|
|
|
|
if turnout == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
for _, group := range relationship.Combinationtypes {
|
2023-09-28 14:10:20 +08:00
|
|
|
|
var componentIds []string
|
2023-09-26 13:45:01 +08:00
|
|
|
|
for _, relayId := range group.RefRelays {
|
2023-11-07 14:30:08 +08:00
|
|
|
|
if relayUidStructure.RelayIds[relayId] == nil {
|
2023-09-27 14:15:11 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2023-11-07 14:30:08 +08:00
|
|
|
|
componentIds = append(componentIds, relayUidStructure.RelayIds[relayId].Uid)
|
2023-09-26 13:45:01 +08:00
|
|
|
|
}
|
2023-09-28 14:10:20 +08:00
|
|
|
|
turnout.ElectronicComponentGroups = append(turnout.ElectronicComponentGroups,
|
|
|
|
|
&proto.ElectronicComponentGroup{
|
|
|
|
|
Code: group.Code,
|
|
|
|
|
ComponentIds: componentIds,
|
|
|
|
|
})
|
2023-09-22 15:13:25 +08:00
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_signal:
|
2023-09-22 15:13:25 +08:00
|
|
|
|
signal := signalMap[GenerateElementUid(city, lineId, []string{station}, relationship.Code)]
|
2023-09-26 10:25:01 +08:00
|
|
|
|
if signal == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-10-16 14:06:47 +08:00
|
|
|
|
//信号机只有一个组合类型
|
|
|
|
|
if len(relationship.Combinationtypes) != 1 {
|
|
|
|
|
panic(fmt.Sprintf("信号机[%s]须有一个组合类型", signal.Id))
|
|
|
|
|
}
|
|
|
|
|
group := relationship.Combinationtypes[0]
|
|
|
|
|
var componentIds []string
|
|
|
|
|
for _, relayId := range group.RefRelays {
|
2023-11-07 14:30:08 +08:00
|
|
|
|
if relayUidStructure.RelayIds[relayId] == nil {
|
2023-10-16 14:06:47 +08:00
|
|
|
|
continue
|
2023-09-26 13:45:01 +08:00
|
|
|
|
}
|
2023-11-07 14:30:08 +08:00
|
|
|
|
componentIds = append(componentIds, relayUidStructure.RelayIds[relayId].Uid)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
}
|
2023-10-16 14:06:47 +08:00
|
|
|
|
signal.Code = group.Code
|
|
|
|
|
signal.ElectronicComponentGroups = append(signal.ElectronicComponentGroups,
|
|
|
|
|
&proto.ElectronicComponentGroup{
|
|
|
|
|
Code: group.Code,
|
|
|
|
|
ComponentIds: componentIds,
|
|
|
|
|
})
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_station:
|
2023-10-16 14:52:58 +08:00
|
|
|
|
station := stationMap[GenerateElementUid(city, lineId, nil, relationship.Code)]
|
|
|
|
|
if station == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
for _, group := range relationship.Combinationtypes {
|
2023-10-16 14:52:58 +08:00
|
|
|
|
d := &proto.ElectronicGroup{Code: group.Code}
|
2023-09-26 13:45:01 +08:00
|
|
|
|
for _, relayId := range group.RefRelays {
|
2023-11-07 14:30:08 +08:00
|
|
|
|
if relayUidStructure.RelayIds[relayId] == nil {
|
2023-09-27 14:15:11 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
d.Components = append(d.Components, &proto.ElectronicComponent{
|
2023-11-07 14:30:08 +08:00
|
|
|
|
Id: relayUidStructure.RelayIds[relayId].Uid,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Relay,
|
2023-09-28 14:10:20 +08:00
|
|
|
|
})
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
|
|
|
|
station.ElectronicGroup = append(station.ElectronicGroup, d)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_ScreenDoor:
|
2023-10-19 17:09:57 +08:00
|
|
|
|
psd, ok := psdMap[GenerateElementUid(city, lineId, nil, relationship.Code)]
|
|
|
|
|
if !ok {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
for _, group := range relationship.Combinationtypes {
|
|
|
|
|
var componentIds []string
|
|
|
|
|
for _, relayId := range group.RefRelays {
|
2023-11-07 14:30:08 +08:00
|
|
|
|
if relayUidStructure.RelayIds[relayId] == nil {
|
2023-10-19 17:09:57 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2023-11-07 14:30:08 +08:00
|
|
|
|
componentIds = append(componentIds, relayUidStructure.RelayIds[relayId].Uid)
|
2023-10-19 17:09:57 +08:00
|
|
|
|
}
|
|
|
|
|
psd.ElectronicComponentGroups = append(psd.ElectronicComponentGroups,
|
|
|
|
|
&proto.ElectronicComponentGroup{
|
|
|
|
|
Code: group.Code,
|
|
|
|
|
ComponentIds: componentIds,
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_SignalFaultAlarm: // 信号机故障报警仪设备组合
|
2023-11-09 14:27:35 +08:00
|
|
|
|
{
|
|
|
|
|
egs := buildEgs(relationship.Combinationtypes, relayUidStructure)
|
|
|
|
|
ciecs.Deccs = append(ciecs.Deccs, &proto.DeviceEcc{
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_SignalFaultAlarm,
|
|
|
|
|
Egs: egs,
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Breakers: // 断路器
|
2023-11-09 14:27:35 +08:00
|
|
|
|
{
|
|
|
|
|
egs := buildEgs(relationship.Combinationtypes, relayUidStructure)
|
|
|
|
|
ciecs.Deccs = append(ciecs.Deccs, &proto.DeviceEcc{
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Breakers,
|
|
|
|
|
Egs: egs,
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_PowerScreen: // 电源屏
|
2023-11-09 14:27:35 +08:00
|
|
|
|
{
|
|
|
|
|
egs := buildEgs(relationship.Combinationtypes, relayUidStructure)
|
|
|
|
|
ciecs.Deccs = append(ciecs.Deccs, &proto.DeviceEcc{
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_PowerScreen,
|
|
|
|
|
Egs: egs,
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-10-19 17:09:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//门控箱
|
|
|
|
|
for _, mkx := range repo.Mkxs {
|
|
|
|
|
platform := platformMap[psdMap[mkx.PsdId].GetPlatformId()]
|
|
|
|
|
station := stationMap[platform.GetStationId()]
|
|
|
|
|
var s string
|
|
|
|
|
if strings.Contains(platform.GetCode(), "上行") {
|
|
|
|
|
s = "S"
|
|
|
|
|
} else if strings.Contains(platform.GetCode(), "下行") {
|
|
|
|
|
s = "X"
|
|
|
|
|
} else {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
for _, group := range station.ElectronicGroup {
|
|
|
|
|
if group.Code == "MKX" {
|
|
|
|
|
for _, component := range group.Components {
|
|
|
|
|
relay := relayMap[component.Id]
|
|
|
|
|
if strings.Contains(relay.GetCode(), s) {
|
2023-11-01 16:52:08 +08:00
|
|
|
|
if strings.Contains(relay.GetCode(), "PCB") {
|
|
|
|
|
mkx.PcbjId = relay.Id
|
|
|
|
|
} else if strings.Contains(relay.GetCode(), "POB") {
|
|
|
|
|
mkx.PobjId = relay.Id
|
2023-11-07 10:03:12 +08:00
|
|
|
|
} else if strings.Contains(relay.GetCode(), "PAB") || strings.Contains(relay.GetCode(), "PDB") {
|
2023-11-01 16:52:08 +08:00
|
|
|
|
mkx.PabjId = relay.Id
|
|
|
|
|
}
|
2023-10-19 17:09:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-11-09 10:53:32 +08:00
|
|
|
|
//cis := stationMap[stationUid]
|
|
|
|
|
//// 零散组合
|
|
|
|
|
//for _, com := range relayGi.CombinationtypeList {
|
|
|
|
|
// if com.Code == "LS" { // 零散组合
|
|
|
|
|
// d := &proto.ElectronicGroup{Code: com.Code}
|
|
|
|
|
// for _, relayId := range com.RefRelays {
|
|
|
|
|
// if relayUidStructure.RelayIds[relayId] == nil {
|
|
|
|
|
// continue
|
|
|
|
|
// }
|
|
|
|
|
// d.Components = append(d.Components, &proto.ElectronicComponent{
|
2024-01-10 14:06:01 +08:00
|
|
|
|
// BaliseId: relayUidStructure.RelayIds[relayId].Uid,
|
2023-11-09 10:53:32 +08:00
|
|
|
|
// DeviceType: proto.DeviceType_DeviceType_Relay,
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// cis.ElectronicGroup = append(cis.ElectronicGroup, d)
|
|
|
|
|
// fmt.Println("构建零散组合结果:", d)
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2023-10-31 09:39:40 +08:00
|
|
|
|
// 处理该集中站采集、驱动配置信息
|
|
|
|
|
centralizedStationId := GenerateElementUid(city, lineId, nil, station)
|
|
|
|
|
ref := queryCentralizedStationRef(centralizedStationId, repo)
|
2023-11-07 14:30:08 +08:00
|
|
|
|
ref.CjList = append(ref.CjList, handlerRelayGiCj(relayUidStructure, centralizedStationId, relayGi.CiCjList)...)
|
2023-11-03 17:27:37 +08:00
|
|
|
|
sortQcTable(ref.CjList)
|
2023-11-07 14:30:08 +08:00
|
|
|
|
ref.QdList = append(ref.QdList, handlerRelayGiQd(relayUidStructure, centralizedStationId, relayGi.CiQdList)...)
|
2023-11-03 17:27:37 +08:00
|
|
|
|
sortQcTable(ref.QdList)
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func buildEgs(cts []*data_proto.Combinationtype, relayUidStructure *RelayUidStructure) []*proto.ElectronicComponentGroup {
|
2023-11-09 14:27:35 +08:00
|
|
|
|
var egs []*proto.ElectronicComponentGroup
|
|
|
|
|
for _, ct := range cts {
|
|
|
|
|
d := &proto.ElectronicComponentGroup{Code: ct.Code}
|
|
|
|
|
for _, relayId := range ct.RefRelays {
|
|
|
|
|
if relayUidStructure.RelayIds[relayId] == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
d.ComponentIds = append(d.ComponentIds, relayUidStructure.RelayIds[relayId].Uid)
|
|
|
|
|
}
|
|
|
|
|
egs = append(egs, d)
|
|
|
|
|
}
|
|
|
|
|
return egs
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-03 17:27:37 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-10-31 09:39:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询集中站配置信息
|
|
|
|
|
func queryCentralizedStationRef(stationId string, repo *proto.Repository) *proto.CentralizedStationRef {
|
|
|
|
|
var ref *proto.CentralizedStationRef
|
|
|
|
|
for _, r := range repo.CentralizedStationRefs {
|
|
|
|
|
if r.StationId == stationId {
|
|
|
|
|
ref = r
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ref == nil {
|
|
|
|
|
ref = &proto.CentralizedStationRef{StationId: stationId}
|
|
|
|
|
repo.CentralizedStationRefs = append(repo.CentralizedStationRefs, ref)
|
|
|
|
|
}
|
|
|
|
|
return ref
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理继电器采集信息
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func handlerRelayGiCj(uidsMap *RelayUidStructure, stationId string, ciCj *data_proto.CiCj) []*proto.CjData {
|
2023-10-31 09:39:40 +08:00
|
|
|
|
if ciCj == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
// 采集信息
|
|
|
|
|
dataLenght := len(ciCj.CjList) * int(ciCj.DsCount)
|
|
|
|
|
if dataLenght == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
cjList := make([]*proto.CjData, dataLenght)
|
|
|
|
|
index := 0
|
|
|
|
|
for ci, col := range ciCj.CjList {
|
|
|
|
|
for ri, row := range col.BitList {
|
|
|
|
|
r := &proto.CjData{Row: int32(ri), Col: int32(ci)}
|
2023-11-03 17:27:37 +08:00
|
|
|
|
if len(row.RefRelays) > 0 {
|
|
|
|
|
for _, j := range row.RefRelays {
|
|
|
|
|
u := uidsMap.RelayIds[j.RelayId]
|
|
|
|
|
if u == nil {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
panic(sys_error.New(fmt.Sprintf("集中站【id:%s】不存在继电器的【comId:%d】UID映射关系", stationId, j.RelayId)))
|
2023-11-03 17:27:37 +08:00
|
|
|
|
}
|
|
|
|
|
d := &proto.CjDataItem{RelayId: u.Uid}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if j.Position == data_proto.CjDataItem_H {
|
2023-11-03 17:27:37 +08:00
|
|
|
|
d.Q = false
|
|
|
|
|
} else {
|
|
|
|
|
d.Q = true
|
|
|
|
|
}
|
|
|
|
|
r.RefRelays = append(r.RefRelays, d)
|
2023-10-31 09:39:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cjList[index] = r
|
|
|
|
|
index++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cjList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理继电器驱动信息
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func handlerRelayGiQd(uidsMap *RelayUidStructure, stationId string, ciQd *data_proto.CiQd) []*proto.QdData {
|
2023-10-31 09:39:40 +08:00
|
|
|
|
if ciQd == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
// 驱动信息
|
|
|
|
|
dataLenght := len(ciQd.QdList) * int(ciQd.DsCount)
|
|
|
|
|
if dataLenght == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
qdList := make([]*proto.QdData, dataLenght)
|
|
|
|
|
index := 0
|
|
|
|
|
for ci, col := range ciQd.QdList {
|
|
|
|
|
for ri, row := range col.BitList {
|
|
|
|
|
r := &proto.QdData{Row: int32(ri), Col: int32(ci)}
|
2023-11-03 17:27:37 +08:00
|
|
|
|
if len(row.RefRelays) > 0 {
|
|
|
|
|
for _, j := range row.RefRelays {
|
|
|
|
|
u := uidsMap.RelayIds[j]
|
|
|
|
|
if u == nil {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
panic(sys_error.New(fmt.Sprintf("集中站【id:%s】不存在继电器的【comId:%d】UID映射关系", stationId, j)))
|
2023-11-03 17:27:37 +08:00
|
|
|
|
}
|
|
|
|
|
r.RefRelays = append(r.RefRelays, u.Uid)
|
2023-10-31 09:39:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
qdList[index] = r
|
|
|
|
|
index++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return qdList
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func convertRelayModel(modelType data_proto.Relay_ModelType) proto.Relay_Model {
|
2023-09-28 14:10:20 +08:00
|
|
|
|
switch modelType {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_Unknown:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_Unknown
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JPXC_1000:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JPXC_1000
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JPXC_1700:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JPXC_1700
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JWJXC_480:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JWJXC_480
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JWJXC_H125_80:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JWJXC_H125_80
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JWXC_1700:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JWXC_1700
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JWXC_H340:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JWXC_H340
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JYJXC_160_260:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JYJXC_160_260
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Relay_JZXC_H18:
|
2023-09-28 14:10:20 +08:00
|
|
|
|
return proto.Relay_JZXC_H18
|
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Sprintf("意料之外的继电器型号:%s", modelType))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func fillProtoRepository(repo *proto.Repository, storage *data_proto.RtssGraphicStorage, mapId int32) {
|
2023-10-19 18:04:21 +08:00
|
|
|
|
repo.MainCoordinateSystem = storage.UniqueIdPrefix.MainCoordinateSystem
|
2024-01-11 10:24:56 +08:00
|
|
|
|
axleCountingMap := make(map[uint32]*data_proto.AxleCounting)
|
2023-10-27 14:57:37 +08:00
|
|
|
|
uidsMap := QueryUidStructure[*StationUidStructure](mapId)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
for _, data := range storage.AxleCountings {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
id := GetMapElementId(data.Common)
|
|
|
|
|
axleCountingMap[id] = data
|
2023-09-20 15:14:40 +08:00
|
|
|
|
cpType := proto.CheckPointType_AxleCounter
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if data.Type == data_proto.AxleCounting_SectionBoundary {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
cpType = proto.CheckPointType_Boundary
|
|
|
|
|
}
|
|
|
|
|
cp := &proto.CheckPoint{
|
2023-12-14 13:04:48 +08:00
|
|
|
|
Id: uidsMap.AxlePointIds[id].Uid,
|
|
|
|
|
Km: convertKm(data.KilometerSystem),
|
|
|
|
|
Type: cpType,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
for _, ref := range data.AxleCountingRef {
|
|
|
|
|
cp.DevicePorts = append(cp.DevicePorts, convertDevicePort(ref, uidsMap))
|
|
|
|
|
}
|
|
|
|
|
repo.CheckPoints = append(repo.CheckPoints, cp)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Section {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
var turnoutUids []string
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if data.SectionType == data_proto.Section_TurnoutPhysical {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnoutIds := findTurnoutIds(axleCountingMap, data.AxleCountings)
|
|
|
|
|
for _, tid := range turnoutIds {
|
|
|
|
|
turnoutUids = append(turnoutUids, uidsMap.TurnoutIds[tid].Uid)
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
var centralizedStation string
|
2023-10-31 16:53:39 +08:00
|
|
|
|
if len(data.CentralizedStations) > 0 {
|
2023-11-30 10:59:34 +08:00
|
|
|
|
s := uidsMap.StationIds[data.CentralizedStations[0]]
|
|
|
|
|
if s != nil {
|
|
|
|
|
centralizedStation = s.Code
|
|
|
|
|
}
|
2023-10-31 16:53:39 +08:00
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
physicalSection := &proto.PhysicalSection{
|
2023-12-14 13:04:48 +08:00
|
|
|
|
Id: uidsMap.PhysicalSectionIds[GetMapElementId(data.Common)].Uid,
|
|
|
|
|
ADevicePort: convertDevicePort(data.PaRef, uidsMap),
|
|
|
|
|
BDevicePort: convertDevicePort(data.PbRef, uidsMap),
|
|
|
|
|
TurnoutIds: turnoutUids,
|
2023-10-31 16:53:39 +08:00
|
|
|
|
CentralizedStation: centralizedStation,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
repo.PhysicalSections = append(repo.PhysicalSections, physicalSection)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Turnouts {
|
|
|
|
|
var km *proto.Kilometer
|
|
|
|
|
for _, ks := range data.KilometerSystem {
|
|
|
|
|
if ks.Kilometer != 0 {
|
|
|
|
|
km = convertKm(ks)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnout := &proto.Turnout{
|
|
|
|
|
Id: uidsMap.TurnoutIds[GetMapElementId(data.Common)].Uid,
|
|
|
|
|
Km: km,
|
|
|
|
|
ADevicePort: convertDevicePort(data.PaRef, uidsMap),
|
|
|
|
|
BDevicePort: convertDevicePort(data.PbRef, uidsMap),
|
|
|
|
|
CDevicePort: convertDevicePort(data.PcRef, uidsMap),
|
|
|
|
|
}
|
2023-09-28 17:45:08 +08:00
|
|
|
|
switch data.SwitchMachineType {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Turnout_ZDJ9_Single:
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnout.SwitchMachineType = proto.Turnout_ZDJ9_Single
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Turnout_ZDJ9_Double:
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnout.SwitchMachineType = proto.Turnout_ZDJ9_Double
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
repo.Turnouts = append(repo.Turnouts, turnout)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Signals {
|
2023-12-14 13:04:48 +08:00
|
|
|
|
signal := &proto.Signal{
|
|
|
|
|
Id: uidsMap.SignalIds[GetMapElementId(data.Common)].Uid,
|
|
|
|
|
Km: convertKm(data.KilometerSystem),
|
|
|
|
|
Model: convertToProtoSignalModel(data.Mt),
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
switch data.RefDev.DeviceType {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Section:
|
2023-12-14 13:04:48 +08:00
|
|
|
|
signal.SectionId = uidsMap.PhysicalSectionIds[data.RefDev.Id].Uid
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Turnout:
|
2023-12-14 13:04:48 +08:00
|
|
|
|
signal.TurnoutPort = convertDevicePort(data.RefDev, uidsMap)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
repo.Signals = append(repo.Signals, signal)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-10-31 09:39:40 +08:00
|
|
|
|
stm := make(map[string][]string)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
for _, data := range storage.Transponders {
|
2024-01-17 17:15:35 +08:00
|
|
|
|
fixedTelegram, err := hex.DecodeString(data.FixedTelegram)
|
|
|
|
|
if err != nil {
|
2024-01-22 11:06:30 +08:00
|
|
|
|
slog.Error(fmt.Sprintf("解析应答器[%s]的固定报文出错:", err.Error()))
|
|
|
|
|
}
|
2024-01-22 11:27:18 +08:00
|
|
|
|
fixedUserTelegram, err := hex.DecodeString(data.FixedUserTelegram)
|
2024-01-22 11:06:30 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("解析应答器[%s]的固定用户报文出错:", err.Error()))
|
2024-01-17 17:15:35 +08:00
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
responder := &proto.Transponder{
|
2024-01-22 11:06:30 +08:00
|
|
|
|
Id: uidsMap.TransponderIds[GetMapElementId(data.Common)].Uid,
|
|
|
|
|
Km: convertKm(data.KilometerSystem),
|
|
|
|
|
FixedTelegram: fixedTelegram,
|
|
|
|
|
Type: convertToProtoBaliseType(data.Type),
|
|
|
|
|
FixedUserTelegram: fixedUserTelegram,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
switch data.TransponderRef.DeviceType {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Section:
|
2023-12-14 13:04:48 +08:00
|
|
|
|
responder.SectionId = uidsMap.PhysicalSectionIds[data.TransponderRef.Id].Uid
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Turnout:
|
2023-12-14 13:04:48 +08:00
|
|
|
|
responder.TurnoutPort = convertDevicePort(data.TransponderRef, uidsMap)
|
|
|
|
|
}
|
2023-11-30 10:59:34 +08:00
|
|
|
|
for _, stationId := range data.CentralizedStations {
|
|
|
|
|
var stationName string
|
|
|
|
|
if uidsMap.StationIds[stationId] == nil {
|
|
|
|
|
stationName = uidsMap.StationIds[stationId].Code
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
stm[stationName] = append(stm[stationName], responder.Id)
|
2023-10-31 09:39:40 +08:00
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
repo.Transponders = append(repo.Transponders, responder)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
slopeKsMap := make(map[uint32]*data_proto.SlopeKiloMarker)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
for _, data := range storage.SlopeKiloMarker {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
slopeKsMap[GetMapElementId(data.Common)] = data
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Slopes {
|
|
|
|
|
var kms []*proto.Kilometer
|
|
|
|
|
for _, id := range data.RefDeviceId {
|
|
|
|
|
kms = append(kms, convertKm(slopeKsMap[id].KilometerSystem[0]))
|
|
|
|
|
}
|
|
|
|
|
slope := &proto.Slope{
|
2023-12-14 13:04:48 +08:00
|
|
|
|
Id: uidsMap.SlopeIds[GetMapElementId(data.Common)].Uid,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Kms: kms,
|
|
|
|
|
Degree: data.SlopeNumber,
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
repo.Slopes = append(repo.Slopes, slope)
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
curveKsMap := make(map[uint32]*data_proto.CurvatureKiloMarker)
|
2023-12-14 13:04:48 +08:00
|
|
|
|
for _, data := range storage.CurvatureKiloMarker {
|
|
|
|
|
curveKsMap[GetMapElementId(data.Common)] = data
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Curvatures {
|
|
|
|
|
var kms []*proto.Kilometer
|
|
|
|
|
for _, id := range data.RefDeviceId {
|
|
|
|
|
kms = append(kms, convertKm(curveKsMap[id].KilometerSystem[0]))
|
|
|
|
|
}
|
|
|
|
|
slope := &proto.SectionalCurvature{
|
2023-12-14 13:04:48 +08:00
|
|
|
|
Id: uidsMap.CurvatureIds[GetMapElementId(data.Common)].Uid,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Kms: kms,
|
|
|
|
|
Radius: data.CurvatureNumber,
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
repo.SectionalCurvatures = append(repo.SectionalCurvatures, slope)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-09-26 09:34:23 +08:00
|
|
|
|
for _, data := range storage.KilometerConvertList {
|
|
|
|
|
repo.KilometerConverts = append(repo.KilometerConverts, &proto.KilometerConvert{
|
|
|
|
|
KmA: convertKm(data.KmA),
|
|
|
|
|
KmB: convertKm(data.KmB),
|
|
|
|
|
SameTrend: data.SameTrend,
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
// 初始化站场图按钮
|
|
|
|
|
for _, data := range storage.EsbButtons {
|
|
|
|
|
repo.Buttons = append(repo.Buttons, &proto.Button{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: uidsMap.ButtonIds[GetMapElementId(data.Common)].Uid,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
Code: data.Code,
|
|
|
|
|
ButtonType: proto.Button_Reset_Press,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// 车站关联关系
|
2024-01-11 10:24:56 +08:00
|
|
|
|
relateMap := make(map[string]*data_proto.StationRelateDevice)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
for _, data := range storage.StationRelateDeviceList {
|
|
|
|
|
relateMap[data.Code] = data
|
|
|
|
|
}
|
|
|
|
|
// 处理车站信息
|
|
|
|
|
for _, data := range storage.Stations {
|
|
|
|
|
station := &proto.Station{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: uidsMap.StationIds[GetMapElementId(data.Common)].Uid,
|
2023-10-20 10:59:27 +08:00
|
|
|
|
Code: data.StationName,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
|
|
|
|
// 关联车站的设备
|
2023-12-07 10:17:48 +08:00
|
|
|
|
refs, ok := relateMap[station.Code]
|
2023-10-16 14:52:58 +08:00
|
|
|
|
if ok {
|
|
|
|
|
for _, c := range refs.Combinationtypes {
|
|
|
|
|
group := &proto.ElectronicGroup{Code: c.Code}
|
|
|
|
|
for _, d := range c.RefDevices {
|
|
|
|
|
var comp *proto.ElectronicComponent
|
|
|
|
|
if uidsMap.ButtonIds[d] != nil { // 目前只处理按钮
|
|
|
|
|
comp = &proto.ElectronicComponent{
|
|
|
|
|
Id: uidsMap.ButtonIds[d].Uid,
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Button,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
group.Components = append(group.Components, comp)
|
|
|
|
|
}
|
|
|
|
|
station.ElectronicGroup = append(station.ElectronicGroup, group)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 处理车站关联IBP的设备
|
2023-10-20 10:59:27 +08:00
|
|
|
|
handlerIBPDeviceToStation(station, repo, data.RefIbpMapCode)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
repo.Stations = append(repo.Stations, station)
|
2023-10-31 09:39:40 +08:00
|
|
|
|
// 处理集中站的信息
|
|
|
|
|
if stm[station.Code] != nil {
|
|
|
|
|
ref := queryCentralizedStationRef(station.Id, repo)
|
|
|
|
|
ref.TransponderId = append(ref.TransponderId, stm[station.Code]...)
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
2023-10-19 17:09:57 +08:00
|
|
|
|
//门控箱
|
|
|
|
|
for _, data := range storage.GateBoxs {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
boxUidInfo := uidsMap.GateBoxIds[GetMapElementId(data.Common)]
|
2023-11-01 16:52:08 +08:00
|
|
|
|
mkx := &proto.Mkx{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: boxUidInfo.Uid,
|
2023-11-01 16:52:08 +08:00
|
|
|
|
PsdId: uidsMap.PsdIds[data.RefScreenDoor].Uid,
|
2023-10-19 17:09:57 +08:00
|
|
|
|
}
|
2023-11-01 16:52:08 +08:00
|
|
|
|
repo.Mkxs = append(repo.Mkxs, mkx)
|
2024-01-11 10:24:56 +08:00
|
|
|
|
_, pslStorage := QueryGiDataByName[*data_proto.PslGraphicStorage](data.RefGatedBoxMapCode)
|
2023-10-19 17:09:57 +08:00
|
|
|
|
for _, button := range pslStorage.PslButtons {
|
|
|
|
|
repoButton := &proto.Button{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: boxUidInfo.Uid + "_" + button.Code,
|
2023-10-19 17:09:57 +08:00
|
|
|
|
Code: button.Code,
|
|
|
|
|
ButtonType: proto.Button_Reset_Press,
|
|
|
|
|
HasLight: true,
|
|
|
|
|
}
|
|
|
|
|
repo.Buttons = append(repo.Buttons, repoButton)
|
|
|
|
|
switch button.Code {
|
|
|
|
|
case "PCB":
|
2023-11-01 16:52:08 +08:00
|
|
|
|
mkx.PcbButtonId = repoButton.Id
|
2023-10-19 17:09:57 +08:00
|
|
|
|
case "POB":
|
2023-11-01 16:52:08 +08:00
|
|
|
|
mkx.PobButtonId = repoButton.Id
|
2023-10-19 17:09:57 +08:00
|
|
|
|
case "PAB":
|
2023-11-01 16:52:08 +08:00
|
|
|
|
mkx.PabButtonId = repoButton.Id
|
2023-10-19 17:09:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//站台
|
2024-01-11 10:24:56 +08:00
|
|
|
|
platformMap := make(map[uint32]*data_proto.Platform)
|
2023-10-19 17:09:57 +08:00
|
|
|
|
for _, data := range storage.Platforms {
|
2023-12-13 15:05:42 +08:00
|
|
|
|
platformId := GetMapElementId(data.Common)
|
|
|
|
|
platformMap[platformId] = data
|
2023-10-19 17:09:57 +08:00
|
|
|
|
platform := &proto.Platform{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: uidsMap.PlatformIds[platformId].Uid,
|
2023-10-19 17:09:57 +08:00
|
|
|
|
Code: data.Code,
|
|
|
|
|
}
|
|
|
|
|
repo.Platforms = append(repo.Platforms, platform)
|
|
|
|
|
platform.StationId = uidsMap.StationIds[data.RefStationId].Uid
|
|
|
|
|
platform.PhysicalSectionId = uidsMap.PhysicalSectionIds[data.RefSectionId].Uid
|
|
|
|
|
}
|
|
|
|
|
//屏蔽门
|
|
|
|
|
for _, data := range storage.ScreenDoors {
|
2023-11-01 16:52:08 +08:00
|
|
|
|
var asdGroups []*proto.AsdGroup
|
2023-11-09 10:53:32 +08:00
|
|
|
|
for _, group := range storage.ScreenDoorConfig.ScreenDoorGroupList {
|
2023-11-01 16:52:08 +08:00
|
|
|
|
asdGroups = append(asdGroups, &proto.AsdGroup{
|
|
|
|
|
Group: group.TrainGroupAmount,
|
|
|
|
|
Start: group.StartSmallDoor,
|
|
|
|
|
End: group.EndSmallDoor,
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-10-19 17:09:57 +08:00
|
|
|
|
psd := &proto.Psd{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: uidsMap.PsdIds[GetMapElementId(data.Common)].Uid,
|
2023-11-09 10:53:32 +08:00
|
|
|
|
AsdAmount: storage.ScreenDoorConfig.SonDoorAmount,
|
2023-11-01 16:52:08 +08:00
|
|
|
|
AsdGroups: asdGroups,
|
2023-10-19 17:09:57 +08:00
|
|
|
|
PlatformId: uidsMap.PlatformIds[data.RefPlatformId].Uid,
|
|
|
|
|
}
|
|
|
|
|
repo.Psds = append(repo.Psds, psd)
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将IBP的设备关联到车站中
|
2023-12-07 10:17:48 +08:00
|
|
|
|
func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, ibpMapCode string) {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
mapId, storage := QueryGiDataByName[*data_proto.IBPGraphicStorage](ibpMapCode)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
if storage == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-12-07 10:17:48 +08:00
|
|
|
|
uidMap := QueryUidStructure[*IBPUidStructure](mapId)
|
2023-12-14 13:04:48 +08:00
|
|
|
|
deviceMap := make(map[uint32]*proto.ElectronicComponent) // 对应的设备类型
|
2023-10-20 10:59:27 +08:00
|
|
|
|
for _, data := range storage.IbpButtons { // 处理按钮
|
2023-12-13 15:05:42 +08:00
|
|
|
|
id := GetMapElementId(data.Common)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
b := &proto.Button{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: station.Id + "_" + uidMap.IbpButtonIds[id].Uid,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
Code: data.Code,
|
2023-12-07 10:17:48 +08:00
|
|
|
|
ButtonType: proto.Button_NO_Reset_Press,
|
2023-10-18 14:09:36 +08:00
|
|
|
|
HasLight: data.HasLight,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
2023-12-07 10:17:48 +08:00
|
|
|
|
if data.IsSelfReset {
|
|
|
|
|
b.ButtonType = proto.Button_Reset_Press
|
|
|
|
|
}
|
2023-12-13 15:05:42 +08:00
|
|
|
|
deviceMap[id] = &proto.ElectronicComponent{
|
2023-10-20 10:59:27 +08:00
|
|
|
|
Id: b.Id,
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Button,
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
repo.Buttons = append(repo.Buttons, b)
|
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.IbpKeys { // 钥匙
|
2023-12-13 15:05:42 +08:00
|
|
|
|
id := GetMapElementId(data.Common)
|
2023-10-20 13:50:22 +08:00
|
|
|
|
b := &proto.Key{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: station.Id + "_" + uidMap.IbpKeyIds[id].Uid,
|
2023-10-20 13:50:22 +08:00
|
|
|
|
Code: data.Code,
|
|
|
|
|
Gear: 2,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
2023-12-13 15:05:42 +08:00
|
|
|
|
deviceMap[id] = &proto.ElectronicComponent{
|
2023-10-20 10:59:27 +08:00
|
|
|
|
Id: b.Id,
|
2023-10-20 13:50:22 +08:00
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Key,
|
2023-10-20 10:59:27 +08:00
|
|
|
|
}
|
2023-10-20 13:50:22 +08:00
|
|
|
|
repo.Keys = append(repo.Keys, b)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.IbpAlarms { // 报警器
|
2023-12-13 15:05:42 +08:00
|
|
|
|
id := GetMapElementId(data.Common)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
b := &proto.Alarm{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: station.Id + "_" + uidMap.IbpAlarmIds[id].Uid,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
Code: data.Code,
|
|
|
|
|
}
|
2023-12-13 15:05:42 +08:00
|
|
|
|
deviceMap[id] = &proto.ElectronicComponent{
|
2023-10-20 10:59:27 +08:00
|
|
|
|
Id: b.Id,
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Alarm,
|
|
|
|
|
}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
repo.Alarms = append(repo.Alarms, b)
|
|
|
|
|
}
|
2023-10-20 15:52:50 +08:00
|
|
|
|
for _, data := range storage.IbpLights { // 指示灯,
|
2023-12-13 15:05:42 +08:00
|
|
|
|
id := GetMapElementId(data.Common)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
b := &proto.Light{
|
2023-12-13 15:05:42 +08:00
|
|
|
|
Id: station.Id + "_" + uidMap.IbpLightIds[id].Uid,
|
2023-10-20 15:52:50 +08:00
|
|
|
|
Code: data.Code,
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
2023-12-13 15:05:42 +08:00
|
|
|
|
deviceMap[id] = &proto.ElectronicComponent{
|
2023-10-20 10:59:27 +08:00
|
|
|
|
Id: b.Id,
|
|
|
|
|
DeviceType: proto.DeviceType_DeviceType_Light,
|
|
|
|
|
}
|
2023-12-06 14:00:55 +08:00
|
|
|
|
repo.Lights = append(repo.Lights, b)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
2023-10-20 15:52:50 +08:00
|
|
|
|
for _, data := range storage.IbpRelatedDevices { // 组信息
|
2023-10-16 14:52:58 +08:00
|
|
|
|
for _, c := range data.Combinationtypes {
|
2023-12-06 14:00:55 +08:00
|
|
|
|
group := &proto.ElectronicGroup{Code: c.Code}
|
2023-10-16 14:52:58 +08:00
|
|
|
|
for _, d := range c.RefDevices {
|
2023-10-20 10:59:27 +08:00
|
|
|
|
deviceType, ok := deviceMap[d]
|
2023-10-16 14:52:58 +08:00
|
|
|
|
if !ok {
|
2023-12-06 14:00:55 +08:00
|
|
|
|
slog.Debug("IBP组合类型类型不存在设备id:%s", d)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
continue
|
|
|
|
|
}
|
2023-10-20 10:59:27 +08:00
|
|
|
|
group.Components = append(group.Components, deviceType)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
2023-12-06 14:00:55 +08:00
|
|
|
|
station.ElectronicGroup = append(station.ElectronicGroup, group)
|
2023-10-16 14:52:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func convertKm(ks *data_proto.KilometerSystem) *proto.Kilometer {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
var dir proto.Direction
|
|
|
|
|
switch ks.Direction {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.KilometerSystem_LEFT:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
dir = proto.Direction_LEFT
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.KilometerSystem_RIGHT:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
dir = proto.Direction_RIGHT
|
|
|
|
|
}
|
|
|
|
|
return &proto.Kilometer{
|
|
|
|
|
Value: ks.Kilometer,
|
|
|
|
|
CoordinateSystem: ks.CoordinateSystem,
|
|
|
|
|
Direction: dir,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func convertDevicePort(ref *data_proto.RelatedRef, uidsMap *StationUidStructure) *proto.DevicePort {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
if ref == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
var port proto.Port
|
|
|
|
|
switch ref.DevicePort {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_A:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
port = proto.Port_A
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_B:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
port = proto.Port_B
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_C:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
port = proto.Port_C
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
var elementId string
|
|
|
|
|
var deviceType proto.DeviceType
|
2023-09-20 15:14:40 +08:00
|
|
|
|
switch ref.DeviceType {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Section:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
deviceType = proto.DeviceType_DeviceType_PhysicalSection
|
2023-12-14 13:04:48 +08:00
|
|
|
|
elementId = uidsMap.PhysicalSectionIds[ref.Id].Uid
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.RelatedRef_Turnout:
|
2023-09-20 15:14:40 +08:00
|
|
|
|
deviceType = proto.DeviceType_DeviceType_Turnout
|
2023-12-14 13:04:48 +08:00
|
|
|
|
elementId = uidsMap.TurnoutIds[ref.Id].Uid
|
2023-09-20 15:14:40 +08:00
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Sprintf("异常的设备类型-%s", ref.DeviceType))
|
|
|
|
|
}
|
|
|
|
|
return &proto.DevicePort{
|
2023-12-14 13:04:48 +08:00
|
|
|
|
DeviceId: elementId,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
DeviceType: deviceType,
|
|
|
|
|
Port: port,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func findTurnoutIds(axleCountingMap map[uint32]*data_proto.AxleCounting, axleIds []uint32) []uint32 {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
if len(axleIds) <= 2 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
turnoutMap := make(map[uint32]int)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
for _, axleId := range axleIds {
|
|
|
|
|
axle := axleCountingMap[axleId]
|
|
|
|
|
for _, ref := range axle.AxleCountingRef {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
if ref.DeviceType == data_proto.RelatedRef_Turnout {
|
2023-11-09 15:58:16 +08:00
|
|
|
|
turnoutMap[ref.Id] = turnoutMap[ref.Id] + 1
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-14 13:04:48 +08:00
|
|
|
|
var turnoutIds []uint32
|
2023-11-09 15:58:16 +08:00
|
|
|
|
for id, num := range turnoutMap {
|
|
|
|
|
if num > 1 {
|
|
|
|
|
turnoutIds = append(turnoutIds, id)
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
return turnoutIds
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 17:21:05 +08:00
|
|
|
|
/*
|
|
|
|
|
enum Model{
|
|
|
|
|
HL = 0; //2XH-1 红绿
|
|
|
|
|
HLU_FU = 1; //2XH-1 红绿黄,封黄灯,无引导
|
|
|
|
|
HLU_DU_YY = 2; //3XH-1 红绿黄,不封灯,有单黄,带引导
|
|
|
|
|
HLU_YY = 3; //3XH-2或JDXH 红绿黄,不封灯,无单黄,带引导
|
|
|
|
|
HLU_FL_DU_YY = 4;//3XH-3 红绿黄,封绿灯,有单黄,带引导
|
|
|
|
|
HLU_DU = 5; //3XH-4 红绿黄,不封灯,有单黄,无引导
|
|
|
|
|
AB = 6; //DXCH 蓝白
|
|
|
|
|
HBU_DU = 7; //JCKXH 红白黄,不封灯,有单黄,无引导
|
|
|
|
|
}
|
|
|
|
|
*/
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func convertToProtoSignalModel(gSmt data_proto.Signal_Model) proto.Signal_Model {
|
2023-10-20 09:38:23 +08:00
|
|
|
|
switch gSmt {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HL:
|
2023-10-20 09:38:23 +08:00
|
|
|
|
return proto.Signal_HL
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HLU_FU:
|
2023-10-20 09:38:23 +08:00
|
|
|
|
return proto.Signal_HLU_FU
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HLU_DU_YY:
|
2023-11-16 17:21:05 +08:00
|
|
|
|
return proto.Signal_HLU_DU_YY
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HLU_YY:
|
2023-11-16 17:21:05 +08:00
|
|
|
|
return proto.Signal_HLU_YY
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HLU_FL_DU_YY:
|
2023-11-16 17:21:05 +08:00
|
|
|
|
return proto.Signal_HLU_FL_DU_YY
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HLU_DU:
|
2023-11-16 17:21:05 +08:00
|
|
|
|
return proto.Signal_HLU_DU
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_AB:
|
2023-10-20 09:38:23 +08:00
|
|
|
|
return proto.Signal_AB
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Signal_HBU_DU:
|
2023-11-16 17:21:05 +08:00
|
|
|
|
return proto.Signal_HBU_DU
|
2023-10-20 09:38:23 +08:00
|
|
|
|
default:
|
2024-01-11 10:24:56 +08:00
|
|
|
|
panic(fmt.Sprintf("data_proto.Signal_Model[%d]无法映射到proto.Signal_Model", gSmt))
|
2023-10-20 09:38:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 10:24:56 +08:00
|
|
|
|
func convertToProtoBaliseType(bt data_proto.Transponder_TransponderTypeEnum) proto.Transponder_Type {
|
2023-11-23 13:30:08 +08:00
|
|
|
|
switch bt {
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Transponder_FB:
|
2023-11-23 13:30:08 +08:00
|
|
|
|
return proto.Transponder_FB
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Transponder_WB:
|
2023-11-23 13:30:08 +08:00
|
|
|
|
return proto.Transponder_WB
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Transponder_DB:
|
2023-11-23 13:30:08 +08:00
|
|
|
|
return proto.Transponder_DB
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Transponder_VB:
|
2023-11-23 13:30:08 +08:00
|
|
|
|
return proto.Transponder_VB
|
2024-01-11 10:24:56 +08:00
|
|
|
|
case data_proto.Transponder_IB:
|
2023-11-23 13:30:08 +08:00
|
|
|
|
return proto.Transponder_IB
|
|
|
|
|
default:
|
2024-01-11 10:24:56 +08:00
|
|
|
|
panic(fmt.Sprintf("data_proto.Transponder_TransponderTypeEnum[%d]无法映射到proto.Transponder_Type", bt))
|
2023-11-23 13:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-24 15:20:05 +08:00
|
|
|
|
|
|
|
|
|
// VerifyEvn 测试环境
|
|
|
|
|
type VerifyEvn interface {
|
|
|
|
|
EvnWorld() ecs.World
|
|
|
|
|
}
|