[新增]11号线联锁通信逻辑(未完);
[修改]proto编译插件指定版本
This commit is contained in:
parent
3bf7a146af
commit
518c3d3f6e
@ -5403,8 +5403,8 @@ type LianSuoIndexData struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // 设备id
|
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // 设备id
|
||||||
Index int32 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` //设备联锁编号
|
Index uint32 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` //设备联锁编号
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LianSuoIndexData) Reset() {
|
func (x *LianSuoIndexData) Reset() {
|
||||||
@ -5439,14 +5439,14 @@ func (*LianSuoIndexData) Descriptor() ([]byte, []int) {
|
|||||||
return file_stationLayoutGraphics_proto_rawDescGZIP(), []int{54}
|
return file_stationLayoutGraphics_proto_rawDescGZIP(), []int{54}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LianSuoIndexData) GetId() int32 {
|
func (x *LianSuoIndexData) GetId() uint32 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Id
|
return x.Id
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *LianSuoIndexData) GetIndex() int32 {
|
func (x *LianSuoIndexData) GetIndex() uint32 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Index
|
return x.Index
|
||||||
}
|
}
|
||||||
@ -6661,8 +6661,8 @@ var file_stationLayoutGraphics_proto_rawDesc = []byte{
|
|||||||
0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x03, 0x69,
|
0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x03, 0x69,
|
||||||
0x64, 0x73, 0x22, 0x38, 0x0a, 0x10, 0x4c, 0x69, 0x61, 0x6e, 0x53, 0x75, 0x6f, 0x49, 0x6e, 0x64,
|
0x64, 0x73, 0x22, 0x38, 0x0a, 0x10, 0x4c, 0x69, 0x61, 0x6e, 0x53, 0x75, 0x6f, 0x49, 0x6e, 0x64,
|
||||||
0x65, 0x78, 0x44, 0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
|
0x65, 0x78, 0x44, 0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||||
0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18,
|
0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18,
|
||||||
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x83, 0x06, 0x0a,
|
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x83, 0x06, 0x0a,
|
||||||
0x0b, 0x4c, 0x69, 0x61, 0x6e, 0x53, 0x75, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x12, 0x39, 0x0a, 0x08,
|
0x0b, 0x4c, 0x69, 0x61, 0x6e, 0x53, 0x75, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x12, 0x39, 0x0a, 0x08,
|
||||||
0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d,
|
0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d,
|
||||||
0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x4c, 0x69, 0x61,
|
0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x4c, 0x69, 0x61,
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//先安装以下插件
|
//先安装以下插件
|
||||||
//go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
//go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.33.0
|
||||||
|
|
||||||
protoFiles := getProtoFiles()
|
protoFiles := getProtoFiles()
|
||||||
// 编译proto文件为Go文件
|
// 编译proto文件为Go文件
|
||||||
|
63
third_party/interlock/beijing11/interlock.go
vendored
63
third_party/interlock/beijing11/interlock.go
vendored
@ -1,63 +0,0 @@
|
|||||||
// Package beijing11 北京11号线联锁通信
|
|
||||||
package beijing11
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"joylink.club/bj-rtsts-server/config"
|
|
||||||
"joylink.club/bj-rtsts-server/third_party/udp"
|
|
||||||
"log/slog"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
initMutex = sync.Mutex{}
|
|
||||||
logTag = "[北京11号线联锁通信]"
|
|
||||||
running = false
|
|
||||||
server udp.UdpServer
|
|
||||||
)
|
|
||||||
|
|
||||||
func Start(interlockConfig *config.InterlockConfig) {
|
|
||||||
if interlockConfig == nil || interlockConfig.Ip == "" || !interlockConfig.Open {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if running {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
initMutex.Lock()
|
|
||||||
defer initMutex.Unlock()
|
|
||||||
if running {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//UDP通信设施
|
|
||||||
server = udp.NewServer(fmt.Sprintf(":%d", interlockConfig.LocalPort), func(b []byte) {
|
|
||||||
slog.Info(fmt.Sprintf("%s收到消息:%x", logTag, b))
|
|
||||||
frame := &FromInterlockFrame{}
|
|
||||||
err := frame.Decode(b)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error(fmt.Sprintf("%s解析数据出错:%s", logTag, err))
|
|
||||||
} else {
|
|
||||||
marshal, err := json.Marshal(frame)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error(fmt.Sprintf("%s解析为json出错:%s", logTag, err))
|
|
||||||
} else {
|
|
||||||
slog.Info(fmt.Sprintf("%s解析为json:%s", logTag, string(marshal)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
err := server.Listen()
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("%s启动UDP服务失败:%s", logTag, err))
|
|
||||||
}
|
|
||||||
running = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func Stop() {
|
|
||||||
initMutex.Lock()
|
|
||||||
defer initMutex.Unlock()
|
|
||||||
running = false
|
|
||||||
if server != nil {
|
|
||||||
server.Close()
|
|
||||||
server = nil
|
|
||||||
}
|
|
||||||
}
|
|
34
third_party/interlock/beijing11/repo.go
vendored
Normal file
34
third_party/interlock/beijing11/repo.go
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package beijing11
|
||||||
|
|
||||||
|
// StationDeviceIndexRepo 联锁站设备索引映射
|
||||||
|
type StationDeviceIndexRepo struct {
|
||||||
|
StationName string
|
||||||
|
TurnoutMap map[uint32]string
|
||||||
|
PsdMap map[uint32]string
|
||||||
|
EsbMap map[uint32]string
|
||||||
|
HoldTrainMap map[uint32]string
|
||||||
|
SignalMap map[uint32]string
|
||||||
|
AxleSectionMap map[uint32]string
|
||||||
|
WrzfMap map[uint32]string
|
||||||
|
FymMap map[uint32]string
|
||||||
|
SpksMap map[uint32]string
|
||||||
|
CkmMap map[uint32]string
|
||||||
|
XcjMap map[uint32]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStationDeviceIndexRepo() *StationDeviceIndexRepo {
|
||||||
|
return &StationDeviceIndexRepo{
|
||||||
|
StationName: "",
|
||||||
|
TurnoutMap: make(map[uint32]string),
|
||||||
|
PsdMap: make(map[uint32]string),
|
||||||
|
EsbMap: make(map[uint32]string),
|
||||||
|
HoldTrainMap: make(map[uint32]string),
|
||||||
|
SignalMap: make(map[uint32]string),
|
||||||
|
AxleSectionMap: make(map[uint32]string),
|
||||||
|
WrzfMap: make(map[uint32]string),
|
||||||
|
FymMap: make(map[uint32]string),
|
||||||
|
SpksMap: make(map[uint32]string),
|
||||||
|
CkmMap: make(map[uint32]string),
|
||||||
|
XcjMap: make(map[uint32]string),
|
||||||
|
}
|
||||||
|
}
|
107
third_party/interlock/beijing11/service.go
vendored
Normal file
107
third_party/interlock/beijing11/service.go
vendored
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
// Package beijing11 北京11号线联锁通信
|
||||||
|
package beijing11
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"joylink.club/bj-rtsts-server/config"
|
||||||
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
||||||
|
"joylink.club/bj-rtsts-server/third_party/udp"
|
||||||
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
||||||
|
"log/slog"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
const logTag = "[北京11号线联锁通信]"
|
||||||
|
|
||||||
|
var (
|
||||||
|
initMutex = sync.Mutex{}
|
||||||
|
running = false
|
||||||
|
server udp.UdpServer
|
||||||
|
sim *memory.VerifySimulation //启动服务所使用的仿真
|
||||||
|
iConfig *config.InterlockConfig //启动服务使用的联锁配置
|
||||||
|
//联锁区设备的联锁编号与uid的映射
|
||||||
|
stationMap map[string]*StationDeviceIndexRepo
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
memory.RegisterListener(func(uidStructure *memory.StationUidStructure, data *data_proto.RtssGraphicStorage) {
|
||||||
|
//if data.LianSuoData == nil {
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
////初始化所有集中站设备映射结构体
|
||||||
|
//for _, station := range data.Stations {
|
||||||
|
// stationMap[station.StationName] = NewStationDeviceIndexRepo()
|
||||||
|
//}
|
||||||
|
////填充
|
||||||
|
//stationIdMap := uidStructure.StationIds
|
||||||
|
////道岔
|
||||||
|
//turnoutUidMap := uidStructure.TurnoutIds
|
||||||
|
//turnoutIndexMap := make(map[uint32]uint32)
|
||||||
|
//for _, turnout := range data.LianSuoData.Switchs {
|
||||||
|
// turnoutIndexMap[turnout.Id] =
|
||||||
|
//}
|
||||||
|
//for _, turnout := range data.Turnouts {
|
||||||
|
// for _, stationCid := range turnout.CentralizedStations {
|
||||||
|
// stationIdStruct := stationIdMap[stationCid]
|
||||||
|
// stationDeviceIndexRepo := stationMap[stationIdStruct.Code]
|
||||||
|
// stationDeviceIndexRepo.TurnoutMap[]
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start(interlockConfig *config.InterlockConfig, simulation *memory.VerifySimulation) {
|
||||||
|
if interlockConfig == nil || interlockConfig.Ip == "" || !interlockConfig.Open {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if running {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
initMutex.Lock()
|
||||||
|
defer initMutex.Unlock()
|
||||||
|
if running {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//UDP通信设施
|
||||||
|
server = udp.NewServer(fmt.Sprintf(":%d", interlockConfig.LocalPort), func(b []byte) {
|
||||||
|
slog.Info(fmt.Sprintf("%s收到消息:%x", logTag, b))
|
||||||
|
frame := &FromInterlockFrame{}
|
||||||
|
err := frame.Decode(b)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(fmt.Sprintf("%s解析数据出错:%s", logTag, err))
|
||||||
|
} else {
|
||||||
|
marshal, err := json.Marshal(frame)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(fmt.Sprintf("%s解析为json出错:%s", logTag, err))
|
||||||
|
} else {
|
||||||
|
slog.Info(fmt.Sprintf("%s解析为json:%s", logTag, string(marshal)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
err := server.Listen()
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("%s启动UDP服务失败:%s", logTag, err))
|
||||||
|
}
|
||||||
|
running = true
|
||||||
|
sim = simulation
|
||||||
|
iConfig = interlockConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func Stop() {
|
||||||
|
initMutex.Lock()
|
||||||
|
defer initMutex.Unlock()
|
||||||
|
running = false
|
||||||
|
if server != nil {
|
||||||
|
server.Close()
|
||||||
|
server = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//func CollectRelayInfo() *FromInterlockFrame {
|
||||||
|
// sim.World
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//func HandleDriveInfo(frame *FromInterlockFrame) {
|
||||||
|
//
|
||||||
|
//}
|
@ -13,6 +13,15 @@ import (
|
|||||||
"joylink.club/rtsssimulation/repository"
|
"joylink.club/rtsssimulation/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 地图数据处理方法。目前用于不同通信协议所需数据的预处理
|
||||||
|
type MapDataHandler func(uidStructure *StationUidStructure, data *data_proto.RtssGraphicStorage)
|
||||||
|
|
||||||
|
var mapDataHandlerList = make([]MapDataHandler, 0)
|
||||||
|
|
||||||
|
func RegisterListener(handler MapDataHandler) {
|
||||||
|
mapDataHandlerList = append(mapDataHandlerList, handler)
|
||||||
|
}
|
||||||
|
|
||||||
var giUidMap sync.Map
|
var giUidMap sync.Map
|
||||||
|
|
||||||
type elementIdStructure struct {
|
type elementIdStructure struct {
|
||||||
@ -426,6 +435,10 @@ func initStationUid(data *data_proto.RtssGraphicStorage) *StationUidStructure {
|
|||||||
Uid: GenerateElementUid(city, lineId, nil, xcj.Code),
|
Uid: GenerateElementUid(city, lineId, nil, xcj.Code),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//通信协议预处理所需数据
|
||||||
|
for _, handler := range mapDataHandlerList {
|
||||||
|
handler(gus, data)
|
||||||
|
}
|
||||||
return gus
|
return gus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ func runThirdParty(s *memory.VerifySimulation) error {
|
|||||||
for _, c := range s.GetInterlockCodes() {
|
for _, c := range s.GetInterlockCodes() {
|
||||||
switch c.Line {
|
switch c.Line {
|
||||||
case "11":
|
case "11":
|
||||||
beijing11.Start(c)
|
beijing11.Start(c, s)
|
||||||
default:
|
default:
|
||||||
beijing12.Default(c).Start(s)
|
beijing12.Default(c).Start(s)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user