# Conflicts:
#	repository/repository_manager.go
This commit is contained in:
weizhihong 2023-10-17 15:08:30 +08:00
commit 8b5391554c
12 changed files with 432 additions and 109 deletions

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc-gen-go v1.31.0
// protoc v4.23.1
// source: component/common.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc-gen-go v1.31.0
// protoc v4.23.1
// source: component/psd.proto

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc-gen-go v1.31.0
// protoc v4.23.1
// source: component/turnout.proto

View File

@ -2,28 +2,21 @@ package component
import "joylink.club/ecs"
var MkxTag = ecs.NewTag()
var MkxCircuitType = ecs.NewComponentType[MkxCircuit]()
type MkxCircuit struct {
Pcb []*ecs.Entry
Pcbj *ecs.Entry
Pob1 []*ecs.Entry
Pobj *ecs.Entry
Pab1 []*ecs.Entry
Pabj *ecs.Entry
PcbList []*ecs.Entry
Pcbj *ecs.Entry
PobList []*ecs.Entry
Pobj *ecs.Entry
PabList []*ecs.Entry
Pabj *ecs.Entry
}
type Pcb struct {
PcbBtn *ecs.Entry
MkxplBtn *ecs.Entry
}
var MkxBoxType = ecs.NewComponentType[MkxBox]()
type Pob struct {
PobBtn *ecs.Entry
MkxplBtn *ecs.Entry
}
type Pab struct {
PabBtn *ecs.Entry
type MkxBox struct {
Btn *ecs.Entry
MkxplBtn *ecs.Entry
}

View File

@ -1 +1,57 @@
package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"strings"
)
func LoadMkx(w ecs.World) error {
data := GetWorldData(w)
mkxs := data.Repo.MkxList()
for _, mkx := range mkxs {
entry := NewMkxEntry(w, mkx.Id(), data)
loadMkxCircuit(w, entry, mkx, data.EntityMap)
}
return nil
}
func loadMkxCircuit(world ecs.World, entry *ecs.Entry, mkx *repository.Mkx, entryMap map[string]*ecs.Entry) {
circuit := &component.MkxCircuit{}
for _, group := range mkx.ComponentGroups() {
for _, ec := range group.Components() {
relay := ec.(*repository.Relay)
if strings.Contains(ec.Code(), "PCBJ") {
circuit.Pcbj = NewRelayEntity(world, relay, entryMap)
} else if strings.Contains(ec.Code(), "POBJ") {
circuit.Pobj = NewRelayEntity(world, relay, entryMap)
} else if strings.Contains(ec.Code(), "PABJ") {
circuit.Pabj = NewRelayEntity(world, relay, entryMap)
}
}
for i := 0; i < 3; i++ {
//NewRelayEntity()
circuit.PcbList = append(circuit.PcbList)
}
}
component.MkxCircuitType.Set(entry, circuit)
}
func NewMkxEntry(world ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
entry, ok := worldData.EntityMap[uid]
if !ok {
psd := world.Entry(world.Create(component.MkxTag, component.UidType, component.MkxCircuitType))
component.UidType.SetValue(psd, component.Uid{Id: uid})
worldData.EntityMap[uid] = psd
}
return entry
}
//func NewMkxBox(world ecs.World) *ecs.Entry {
// entry := world.Entry(world.Create(component.MkxBoxType))
// component.MkxBox{
// Btn: NewButtonEntity(),
// MkxplBtn: nil,
// }
//}

53
fi/psd.go Normal file
View File

@ -0,0 +1,53 @@
package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
func ClosePsd(world ecs.World, id string) {
worldData := entity.GetWorldData(world)
world.Execute(func() {
entry, ok := worldData.EntityMap[id]
if ok {
psdDriveCircuit := component.PsdDriveCircuitType.Get(entry)
psdDriveCircuit.GMJ = true
psdDriveCircuit.KMJ4 = false
psdDriveCircuit.KMJ8 = false
} else {
fmt.Printf("未找到id=%s的屏蔽门\n", id)
}
})
}
func Km4Psd(world ecs.World, id string) {
worldData := entity.GetWorldData(world)
world.Execute(func() {
entry, ok := worldData.EntityMap[id]
if ok {
psdDriveCircuit := component.PsdDriveCircuitType.Get(entry)
psdDriveCircuit.GMJ = false
psdDriveCircuit.KMJ4 = true
psdDriveCircuit.KMJ8 = false
} else {
fmt.Printf("未找到id=%s的屏蔽门\n", id)
}
})
}
func Km8Psd(world ecs.World, id string) {
worldData := entity.GetWorldData(world)
world.Execute(func() {
entry, ok := worldData.EntityMap[id]
if ok {
psdDriveCircuit := component.PsdDriveCircuitType.Get(entry)
psdDriveCircuit.GMJ = false
psdDriveCircuit.KMJ4 = false
psdDriveCircuit.KMJ8 = true
} else {
fmt.Printf("未找到id=%s的屏蔽门\n", id)
}
})
}

View File

@ -22,6 +22,7 @@ message Repository {
repeated Light lights = 15;
repeated Alarm alarms = 16;
repeated Station stations = 17;
repeated Mkx mkxs = 18;
}
//
@ -119,6 +120,7 @@ enum DeviceType {
DeviceType_Alarm = 14;
DeviceType_Psd = 15;
DeviceType_Station = 16;
DeviceType_Mkx = 17;
}
enum Port {
@ -206,9 +208,9 @@ message Light {
L = 0; //绿
H = 1; //
U = 2; //
HU= 3; //
B=4; //
A=5; //
HU = 3; //
B = 4; //
A = 5; //
}
string id = 1;
string code = 2;
@ -238,4 +240,10 @@ message ElectronicGroup {
message ElectronicComponent {
string id= 1; // ID
DeviceType deviceType = 3; //
}
//
message Mkx {
string id = 1;
repeated ElectronicComponentGroup electronicComponentGroups = 2; //
}

20
repository/mkx.go Normal file
View File

@ -0,0 +1,20 @@
package repository
type Mkx struct {
Identity
componentGroups []*ElectronicComponentGroup
}
func NewMkx(id string) *Mkx {
return &Mkx{
Identity: identity{
id: id,
deviceType: 0,
},
componentGroups: nil,
}
}
func (m *Mkx) ComponentGroups() []*ElectronicComponentGroup {
return m.componentGroups
}

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc-gen-go v1.31.0
// protoc v4.23.1
// source: model.proto
@ -40,6 +40,7 @@ const (
DeviceType_DeviceType_Alarm DeviceType = 14
DeviceType_DeviceType_Psd DeviceType = 15
DeviceType_DeviceType_Station DeviceType = 16
DeviceType_DeviceType_Mkx DeviceType = 17
)
// Enum value maps for DeviceType.
@ -62,6 +63,7 @@ var (
14: "DeviceType_Alarm",
15: "DeviceType_Psd",
16: "DeviceType_Station",
17: "DeviceType_Mkx",
}
DeviceType_value = map[string]int32{
"DeviceType_Unknown": 0,
@ -81,6 +83,7 @@ var (
"DeviceType_Alarm": 14,
"DeviceType_Psd": 15,
"DeviceType_Station": 16,
"DeviceType_Mkx": 17,
}
)
@ -514,6 +517,7 @@ type Repository struct {
Lights []*Light `protobuf:"bytes,15,rep,name=lights,proto3" json:"lights,omitempty"`
Alarms []*Alarm `protobuf:"bytes,16,rep,name=alarms,proto3" json:"alarms,omitempty"`
Stations []*Station `protobuf:"bytes,17,rep,name=stations,proto3" json:"stations,omitempty"`
Mkxs []*Mkx `protobuf:"bytes,18,rep,name=mkxs,proto3" json:"mkxs,omitempty"`
}
func (x *Repository) Reset() {
@ -667,6 +671,13 @@ func (x *Repository) GetStations() []*Station {
return nil
}
func (x *Repository) GetMkxs() []*Mkx {
if x != nil {
return x.Mkxs
}
return nil
}
// 物理区段
type PhysicalSection struct {
state protoimpl.MessageState
@ -1986,11 +1997,67 @@ func (x *ElectronicComponent) GetDeviceType() DeviceType {
return DeviceType_DeviceType_Unknown
}
// 门控箱
type Mkx struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
ElectronicComponentGroups []*ElectronicComponentGroup `protobuf:"bytes,2,rep,name=electronicComponentGroups,proto3" json:"electronicComponentGroups,omitempty"` // 关联的电子元件组合
}
func (x *Mkx) Reset() {
*x = Mkx{}
if protoimpl.UnsafeEnabled {
mi := &file_model_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Mkx) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Mkx) ProtoMessage() {}
func (x *Mkx) ProtoReflect() protoreflect.Message {
mi := &file_model_proto_msgTypes[21]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Mkx.ProtoReflect.Descriptor instead.
func (*Mkx) Descriptor() ([]byte, []int) {
return file_model_proto_rawDescGZIP(), []int{21}
}
func (x *Mkx) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Mkx) GetElectronicComponentGroups() []*ElectronicComponentGroup {
if x != nil {
return x.ElectronicComponentGroups
}
return nil
}
var File_model_proto protoreflect.FileDescriptor
var file_model_proto_rawDesc = []byte{
0x0a, 0x0b, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x6d,
0x6f, 0x64, 0x65, 0x6c, 0x22, 0xb3, 0x06, 0x0a, 0x0a, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74,
0x6f, 0x64, 0x65, 0x6c, 0x22, 0xd3, 0x06, 0x0a, 0x0a, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74,
0x6f, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x42, 0x0a,
@ -2041,7 +2108,9 @@ var file_model_proto_rawDesc = []byte{
0x2e, 0x41, 0x6c, 0x61, 0x72, 0x6d, 0x52, 0x06, 0x61, 0x6c, 0x61, 0x72, 0x6d, 0x73, 0x12, 0x2a,
0x0a, 0x08, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x11, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x0e, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x52, 0x08, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xab, 0x01, 0x0a, 0x0f, 0x50,
0x52, 0x08, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x04, 0x6d, 0x6b,
0x78, 0x73, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c,
0x2e, 0x4d, 0x6b, 0x78, 0x52, 0x04, 0x6d, 0x6b, 0x78, 0x73, 0x22, 0xab, 0x01, 0x0a, 0x0f, 0x50,
0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x53, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e,
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1e,
0x0a, 0x0a, 0x74, 0x75, 0x72, 0x6e, 0x6f, 0x75, 0x74, 0x49, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03,
@ -2230,46 +2299,54 @@ var file_model_proto_rawDesc = []byte{
0x0a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0e, 0x32, 0x11, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65,
0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65,
0x2a, 0xbc, 0x03, 0x0a, 0x0a, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12,
0x16, 0x0a, 0x12, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x55, 0x6e,
0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x1e, 0x0a, 0x1a, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x50, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x53, 0x65,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x19, 0x0a, 0x15, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x69, 0x6e, 0x74,
0x10, 0x02, 0x12, 0x16, 0x0a, 0x12, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65,
0x5f, 0x54, 0x75, 0x72, 0x6e, 0x6f, 0x75, 0x74, 0x10, 0x03, 0x12, 0x15, 0x0a, 0x11, 0x44, 0x65,
0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x10,
0x04, 0x12, 0x1a, 0x0a, 0x16, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f,
0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x10, 0x05, 0x12, 0x14, 0x0a,
0x10, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x53, 0x6c, 0x6f, 0x70,
0x65, 0x10, 0x06, 0x12, 0x21, 0x0a, 0x1d, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70,
0x65, 0x5f, 0x53, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x43, 0x75, 0x72, 0x76, 0x61,
0x74, 0x75, 0x72, 0x65, 0x10, 0x07, 0x12, 0x13, 0x0a, 0x0f, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65,
0x54, 0x79, 0x70, 0x65, 0x5f, 0x4c, 0x69, 0x6e, 0x6b, 0x10, 0x08, 0x12, 0x17, 0x0a, 0x13, 0x44,
0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4c, 0x69, 0x6e, 0x6b, 0x4e, 0x6f,
0x64, 0x65, 0x10, 0x09, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79,
0x70, 0x65, 0x5f, 0x52, 0x65, 0x6c, 0x61, 0x79, 0x10, 0x0a, 0x12, 0x24, 0x0a, 0x20, 0x44, 0x65,
0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x50, 0x68, 0x61, 0x73, 0x65, 0x46, 0x61,
0x69, 0x6c, 0x75, 0x72, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x10, 0x0b,
0x12, 0x15, 0x0a, 0x11, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x42,
0x75, 0x74, 0x74, 0x6f, 0x6e, 0x10, 0x0c, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4c, 0x69, 0x67, 0x68, 0x74, 0x10, 0x0d, 0x12, 0x14, 0x0a,
0x10, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x41, 0x6c, 0x61, 0x72,
0x6d, 0x10, 0x0e, 0x12, 0x12, 0x0a, 0x0e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70,
0x65, 0x5f, 0x50, 0x73, 0x64, 0x10, 0x0f, 0x12, 0x16, 0x0a, 0x12, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x53, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x10, 0x2a,
0x25, 0x0a, 0x04, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10,
0x00, 0x12, 0x05, 0x0a, 0x01, 0x41, 0x10, 0x01, 0x12, 0x05, 0x0a, 0x01, 0x42, 0x10, 0x02, 0x12,
0x05, 0x0a, 0x01, 0x43, 0x10, 0x03, 0x2a, 0x20, 0x0a, 0x09, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74,
0x69, 0x6f, 0x6e, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x45, 0x46, 0x54, 0x10, 0x00, 0x12, 0x09, 0x0a,
0x05, 0x52, 0x49, 0x47, 0x48, 0x54, 0x10, 0x01, 0x2a, 0x43, 0x0a, 0x0e, 0x43, 0x68, 0x65, 0x63,
0x6b, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x42, 0x6f,
0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x41, 0x78, 0x6c, 0x65,
0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x10, 0x01, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x6e, 0x73,
0x75, 0x6c, 0x61, 0x74, 0x65, 0x64, 0x4a, 0x6f, 0x69, 0x6e, 0x74, 0x10, 0x02, 0x42, 0x1a, 0x5a,
0x18, 0x2e, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x6d, 0x6f,
0x64, 0x65, 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x22, 0x74, 0x0a, 0x03, 0x4d, 0x6b, 0x78, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x5d, 0x0a, 0x19, 0x65, 0x6c, 0x65, 0x63, 0x74,
0x72, 0x6f, 0x6e, 0x69, 0x63, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x47, 0x72,
0x6f, 0x75, 0x70, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6d, 0x6f, 0x64,
0x65, 0x6c, 0x2e, 0x45, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x43, 0x6f, 0x6d,
0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x52, 0x19, 0x65, 0x6c, 0x65,
0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74,
0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x2a, 0xd0, 0x03, 0x0a, 0x0a, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54,
0x79, 0x70, 0x65, 0x5f, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x1e, 0x0a,
0x1a, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x50, 0x68, 0x79, 0x73,
0x69, 0x63, 0x61, 0x6c, 0x53, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x19, 0x0a,
0x15, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x43, 0x68, 0x65, 0x63,
0x6b, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x10, 0x02, 0x12, 0x16, 0x0a, 0x12, 0x44, 0x65, 0x76, 0x69,
0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x54, 0x75, 0x72, 0x6e, 0x6f, 0x75, 0x74, 0x10, 0x03,
0x12, 0x15, 0x0a, 0x11, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x53,
0x69, 0x67, 0x6e, 0x61, 0x6c, 0x10, 0x04, 0x12, 0x1a, 0x0a, 0x16, 0x44, 0x65, 0x76, 0x69, 0x63,
0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65,
0x72, 0x10, 0x05, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70,
0x65, 0x5f, 0x53, 0x6c, 0x6f, 0x70, 0x65, 0x10, 0x06, 0x12, 0x21, 0x0a, 0x1d, 0x44, 0x65, 0x76,
0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x53, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61,
0x6c, 0x43, 0x75, 0x72, 0x76, 0x61, 0x74, 0x75, 0x72, 0x65, 0x10, 0x07, 0x12, 0x13, 0x0a, 0x0f,
0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4c, 0x69, 0x6e, 0x6b, 0x10,
0x08, 0x12, 0x17, 0x0a, 0x13, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f,
0x4c, 0x69, 0x6e, 0x6b, 0x4e, 0x6f, 0x64, 0x65, 0x10, 0x09, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x65,
0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x52, 0x65, 0x6c, 0x61, 0x79, 0x10, 0x0a,
0x12, 0x24, 0x0a, 0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x50,
0x68, 0x61, 0x73, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x65,
0x63, 0x74, 0x6f, 0x72, 0x10, 0x0b, 0x12, 0x15, 0x0a, 0x11, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65,
0x54, 0x79, 0x70, 0x65, 0x5f, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x10, 0x0c, 0x12, 0x14, 0x0a,
0x10, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4c, 0x69, 0x67, 0x68,
0x74, 0x10, 0x0d, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70,
0x65, 0x5f, 0x41, 0x6c, 0x61, 0x72, 0x6d, 0x10, 0x0e, 0x12, 0x12, 0x0a, 0x0e, 0x44, 0x65, 0x76,
0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x50, 0x73, 0x64, 0x10, 0x0f, 0x12, 0x16, 0x0a,
0x12, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x53, 0x74, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x10, 0x10, 0x12, 0x12, 0x0a, 0x0e, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54,
0x79, 0x70, 0x65, 0x5f, 0x4d, 0x6b, 0x78, 0x10, 0x11, 0x2a, 0x25, 0x0a, 0x04, 0x50, 0x6f, 0x72,
0x74, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x05, 0x0a, 0x01, 0x41,
0x10, 0x01, 0x12, 0x05, 0x0a, 0x01, 0x42, 0x10, 0x02, 0x12, 0x05, 0x0a, 0x01, 0x43, 0x10, 0x03,
0x2a, 0x20, 0x0a, 0x09, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x08, 0x0a,
0x04, 0x4c, 0x45, 0x46, 0x54, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x52, 0x49, 0x47, 0x48, 0x54,
0x10, 0x01, 0x2a, 0x43, 0x0a, 0x0e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x69, 0x6e, 0x74,
0x54, 0x79, 0x70, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x42, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79,
0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x41, 0x78, 0x6c, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65,
0x72, 0x10, 0x01, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x6e, 0x73, 0x75, 0x6c, 0x61, 0x74, 0x65, 0x64,
0x4a, 0x6f, 0x69, 0x6e, 0x74, 0x10, 0x02, 0x42, 0x1a, 0x5a, 0x18, 0x2e, 0x2f, 0x72, 0x65, 0x70,
0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -2285,7 +2362,7 @@ func file_model_proto_rawDescGZIP() []byte {
}
var file_model_proto_enumTypes = make([]protoimpl.EnumInfo, 8)
var file_model_proto_msgTypes = make([]protoimpl.MessageInfo, 21)
var file_model_proto_msgTypes = make([]protoimpl.MessageInfo, 22)
var file_model_proto_goTypes = []interface{}{
(DeviceType)(0), // 0: model.DeviceType
(Port)(0), // 1: model.Port
@ -2316,6 +2393,7 @@ var file_model_proto_goTypes = []interface{}{
(*Station)(nil), // 26: model.Station
(*ElectronicGroup)(nil), // 27: model.ElectronicGroup
(*ElectronicComponent)(nil), // 28: model.ElectronicComponent
(*Mkx)(nil), // 29: model.Mkx
}
var file_model_proto_depIdxs = []int32{
9, // 0: model.Repository.physicalSections:type_name -> model.PhysicalSection
@ -2333,41 +2411,43 @@ var file_model_proto_depIdxs = []int32{
24, // 12: model.Repository.lights:type_name -> model.Light
25, // 13: model.Repository.alarms:type_name -> model.Alarm
26, // 14: model.Repository.stations:type_name -> model.Station
17, // 15: model.PhysicalSection.aDevicePort:type_name -> model.DevicePort
17, // 16: model.PhysicalSection.bDevicePort:type_name -> model.DevicePort
18, // 17: model.CheckPoint.km:type_name -> model.Kilometer
3, // 18: model.CheckPoint.type:type_name -> model.CheckPointType
17, // 19: model.CheckPoint.devicePorts:type_name -> model.DevicePort
18, // 20: model.Turnout.km:type_name -> model.Kilometer
17, // 21: model.Turnout.aDevicePort:type_name -> model.DevicePort
17, // 22: model.Turnout.bDevicePort:type_name -> model.DevicePort
17, // 23: model.Turnout.cDevicePort:type_name -> model.DevicePort
4, // 24: model.Turnout.switchMachineType:type_name -> model.Turnout.SwitchMachineType
22, // 25: model.Turnout.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
18, // 26: model.Signal.km:type_name -> model.Kilometer
17, // 27: model.Signal.turnoutPort:type_name -> model.DevicePort
22, // 28: model.Signal.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
22, // 29: model.Psd.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
18, // 30: model.Transponder.km:type_name -> model.Kilometer
17, // 31: model.Transponder.turnoutPort:type_name -> model.DevicePort
18, // 32: model.Slope.kms:type_name -> model.Kilometer
18, // 33: model.SectionalCurvature.kms:type_name -> model.Kilometer
0, // 34: model.DevicePort.deviceType:type_name -> model.DeviceType
1, // 35: model.DevicePort.port:type_name -> model.Port
2, // 36: model.Kilometer.direction:type_name -> model.Direction
18, // 37: model.KilometerConvert.kmA:type_name -> model.Kilometer
18, // 38: model.KilometerConvert.kmB:type_name -> model.Kilometer
5, // 39: model.Relay.model:type_name -> model.Relay.Model
6, // 40: model.Button.buttonType:type_name -> model.Button.ButtonType
7, // 41: model.Light.aspect:type_name -> model.Light.LightAspect
27, // 42: model.Station.electronicGroup:type_name -> model.ElectronicGroup
28, // 43: model.ElectronicGroup.components:type_name -> model.ElectronicComponent
0, // 44: model.ElectronicComponent.deviceType:type_name -> model.DeviceType
45, // [45:45] is the sub-list for method output_type
45, // [45:45] is the sub-list for method input_type
45, // [45:45] is the sub-list for extension type_name
45, // [45:45] is the sub-list for extension extendee
0, // [0:45] is the sub-list for field type_name
29, // 15: model.Repository.mkxs:type_name -> model.Mkx
17, // 16: model.PhysicalSection.aDevicePort:type_name -> model.DevicePort
17, // 17: model.PhysicalSection.bDevicePort:type_name -> model.DevicePort
18, // 18: model.CheckPoint.km:type_name -> model.Kilometer
3, // 19: model.CheckPoint.type:type_name -> model.CheckPointType
17, // 20: model.CheckPoint.devicePorts:type_name -> model.DevicePort
18, // 21: model.Turnout.km:type_name -> model.Kilometer
17, // 22: model.Turnout.aDevicePort:type_name -> model.DevicePort
17, // 23: model.Turnout.bDevicePort:type_name -> model.DevicePort
17, // 24: model.Turnout.cDevicePort:type_name -> model.DevicePort
4, // 25: model.Turnout.switchMachineType:type_name -> model.Turnout.SwitchMachineType
22, // 26: model.Turnout.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
18, // 27: model.Signal.km:type_name -> model.Kilometer
17, // 28: model.Signal.turnoutPort:type_name -> model.DevicePort
22, // 29: model.Signal.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
22, // 30: model.Psd.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
18, // 31: model.Transponder.km:type_name -> model.Kilometer
17, // 32: model.Transponder.turnoutPort:type_name -> model.DevicePort
18, // 33: model.Slope.kms:type_name -> model.Kilometer
18, // 34: model.SectionalCurvature.kms:type_name -> model.Kilometer
0, // 35: model.DevicePort.deviceType:type_name -> model.DeviceType
1, // 36: model.DevicePort.port:type_name -> model.Port
2, // 37: model.Kilometer.direction:type_name -> model.Direction
18, // 38: model.KilometerConvert.kmA:type_name -> model.Kilometer
18, // 39: model.KilometerConvert.kmB:type_name -> model.Kilometer
5, // 40: model.Relay.model:type_name -> model.Relay.Model
6, // 41: model.Button.buttonType:type_name -> model.Button.ButtonType
7, // 42: model.Light.aspect:type_name -> model.Light.LightAspect
27, // 43: model.Station.electronicGroup:type_name -> model.ElectronicGroup
28, // 44: model.ElectronicGroup.components:type_name -> model.ElectronicComponent
0, // 45: model.ElectronicComponent.deviceType:type_name -> model.DeviceType
22, // 46: model.Mkx.electronicComponentGroups:type_name -> model.ElectronicComponentGroup
47, // [47:47] is the sub-list for method output_type
47, // [47:47] is the sub-list for method input_type
47, // [47:47] is the sub-list for extension type_name
47, // [47:47] is the sub-list for extension extendee
0, // [0:47] is the sub-list for field type_name
}
func init() { file_model_proto_init() }
@ -2628,6 +2708,18 @@ func file_model_proto_init() {
return nil
}
}
file_model_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Mkx); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -2635,7 +2727,7 @@ func file_model_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_model_proto_rawDesc,
NumEnums: 8,
NumMessages: 21,
NumMessages: 22,
NumExtensions: 0,
NumServices: 0,
},

View File

@ -24,6 +24,7 @@ type Repository struct {
lightMap map[string]*Light
alarmMap map[string]*Alarm
stationMap map[string]*Station
mkxMap map[string]*Mkx
linkMap map[string]*Link
}
@ -48,6 +49,7 @@ func newRepository(id string, version string) *Repository {
lightMap: make(map[string]*Light),
alarmMap: make(map[string]*Alarm),
stationMap: make(map[string]*Station),
mkxMap: make(map[string]*Mkx),
}
}
@ -150,6 +152,13 @@ func (repo *Repository) PsdList() []*Psd {
}
return list
}
func (repo *Repository) MkxList() []*Mkx {
var list []*Mkx
for _, model := range repo.mkxMap {
list = append(list, model)
}
return list
}
func (repo *Repository) StationList() []*Station {
var list []*Station

View File

@ -95,6 +95,7 @@ func buildModels(source *proto.Repository, repository *Repository) {
m := newPsd(protoData.Id)
repository.psdMap[m.Id()] = m
}
for _, protoData := range source.Lights {
m := NewLight(protoData.Id, protoData.Code)
repository.lightMap[m.Id()] = m
@ -107,6 +108,11 @@ func buildModels(source *proto.Repository, repository *Repository) {
m := NewStation(protoData.Id, protoData.Code)
repository.stationMap[m.Id()] = m
}
for _, protoData := range source.Mkxs {
m := NewMkx(protoData.Id)
repository.mkxMap[m.Id()] = m
}
}
func buildModelRelationship(source *proto.Repository, repository *Repository) error {
@ -130,6 +136,11 @@ func buildModelRelationship(source *proto.Repository, repository *Repository) er
if err != nil {
return err
}
err = buildPsdRelationShip(source, repository)
if err != nil {
return err
}
buildMkxRelationShip(source, repository)
err = completeTurnoutPortKm(repository)
if err != nil {
return err
@ -141,6 +152,44 @@ func buildModelRelationship(source *proto.Repository, repository *Repository) er
return err
}
func buildMkxRelationShip(source *proto.Repository, repo *Repository) error {
for _, protoData := range source.Psds {
mkx := repo.mkxMap[protoData.Id]
for _, group := range protoData.ElectronicComponentGroups {
var components []IGroupedElectronicComponent
for _, id := range group.GetComponentIds() {
if relay := repo.relayMap[id]; relay != nil {
components = append(components, relay)
}
}
mkx.componentGroups = append(mkx.componentGroups, &ElectronicComponentGroup{
code: group.Code,
components: components,
})
}
}
return nil
}
func buildPsdRelationShip(source *proto.Repository, repo *Repository) error {
for _, protoData := range source.Psds {
psd := repo.psdMap[protoData.Id]
for _, group := range protoData.ElectronicComponentGroups {
var components []IGroupedElectronicComponent
for _, id := range group.GetComponentIds() {
if relay := repo.relayMap[id]; relay != nil {
components = append(components, relay)
}
}
psd.componentGroups = append(psd.componentGroups, &ElectronicComponentGroup{
code: group.Code,
components: components,
})
}
}
return nil
}
// 补全道岔端口的公里标
func completeTurnoutPortKm(repo *Repository) error {
ports := []proto.Port{proto.Port_A, proto.Port_B, proto.Port_C}
@ -240,8 +289,7 @@ func buildResponderRelationShip(source *proto.Repository, repository *Repository
tp := protoData.TurnoutPort
if tp != nil {
if tp.DeviceType != proto.DeviceType_DeviceType_Turnout {
return errors.New(fmt.Sprintf("应答器[%s]关联的[%s-%s-%s]并非道岔端口",
responder.Id(), tp.DeviceId, tp.DeviceType, tp.Port))
return fmt.Errorf("应答器[%s]关联的[%s-%s-%s]并非道岔端口", responder.Id(), tp.DeviceId, tp.DeviceType, tp.Port)
}
interrelateResponderAndTurnout(responder, repository.turnoutMap[tp.DeviceId], tp.Port)
}
@ -260,8 +308,7 @@ func buildSignalRelationShip(source *proto.Repository, repository *Repository) e
tp := protoData.TurnoutPort
if tp != nil {
if tp.DeviceType != proto.DeviceType_DeviceType_Turnout {
return errors.New(fmt.Sprintf("信号机[%s]关联的[%s-%s-%s]并非道岔端口",
signal.Id(), tp.DeviceId, tp.DeviceType, tp.Port))
return fmt.Errorf("信号机[%s]关联的[%s-%s-%s]并非道岔端口", signal.Id(), tp.DeviceId, tp.DeviceType, tp.Port)
}
interrelateSignalAndTurnout(signal, repository.turnoutMap[tp.DeviceId], tp.Port)
}
@ -350,7 +397,7 @@ func buildPhysicalSectionRelationShip(source *proto.Repository, repository *Repo
for _, turnoutId := range protoData.TurnoutIds {
turnout := repository.turnoutMap[turnoutId]
if turnout == nil {
return errors.New(fmt.Sprintf("id[%s]的道岔不存在", turnoutId))
return fmt.Errorf("id[%s]的道岔不存在", turnoutId)
}
section.bindTurnouts(turnout)
turnout.section = section
@ -398,7 +445,7 @@ func buildDevicePort(device Identity, port proto.Port) (DevicePort, error) {
port: port,
}
default:
return nil, errors.New(fmt.Sprintf("[%s]类型设备没有端口", device.Type()))
return nil, fmt.Errorf("[%s]类型设备没有端口", device.Type())
}
return dp, nil
}

45
sys/circuit_sys/mkx.go Normal file
View File

@ -0,0 +1,45 @@
package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type MkxSys struct {
query *ecs.Query
}
func NewMkxSys() *MkxSys {
return &MkxSys{
query: ecs.NewQuery(filter.Contains(component.PsdCircuitType, component.PsdDriveCircuitType)),
}
}
func (p *MkxSys) Update(world ecs.World) {
p.query.Each(world, func(entry *ecs.Entry) {
circuit := component.MkxCircuitType.Get(entry)
p.exciteRelay(circuit.PcbList, circuit.Pcbj)
p.exciteRelay(circuit.PobList, circuit.Pobj)
p.exciteRelay(circuit.PabList, circuit.Pabj)
})
}
func (p *MkxSys) exciteRelay(entries []*ecs.Entry, relay *ecs.Entry) {
on := false
for _, pcbEntry := range entries {
pcb := component.MkxBoxType.Get(pcbEntry)
btn := component.BitStateType.Get(pcb.Btn)
mkxplBtn := component.BitStateType.Get(pcb.MkxplBtn)
if btn.Val && mkxplBtn.Val {
on = true
}
}
if on {
component.RelayDriveType.Get(relay).Td = true
component.BitStateType.Get(relay).Val = true
} else {
component.RelayDriveType.Get(relay).Td = false
component.BitStateType.Get(relay).Val = false
}
}