This commit is contained in:
weizhihong 2023-10-19 16:38:54 +08:00
commit 0505dd3b70
10 changed files with 462 additions and 5 deletions

27
component/axle_section.go Normal file
View File

@ -0,0 +1,27 @@
package component
// AxleSectionState 计轴区段设备(由几个计轴检测点、一个或多个轨道区段、计轴器运算电路组成)
type AxleSectionState struct {
//true-计轴占用
Occ bool
//true-计轴出清
Clr bool
//true-计轴复位反馈
Rac bool
//true-运营原因拒绝计轴复位,如区段空闲时下发复位命令;或车轮压住传感器时收到复位命令。
Rjo bool
//true-技术原因拒绝计轴复位,主要指计轴相关设备故障时收到复位命令如车轮传感器的导线断开、AEB之间的通信故障等
Rjt bool
}
// AxleSectionDevice 计轴器设备(通过接收计轴物理区段的计轴检测点的信号来运算出计轴物理区段内的车轴数)
type AxleSectionDevice struct {
//计轴区段内车轴数
AxleCount int16
}
type AxleDeviceDrive struct {
//true-计轴直接复位
Drst bool
//true-计轴预复位
Pdrst bool
}

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

@ -0,0 +1,317 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc v4.23.1
// source: component/signal.proto
package component_proto
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// 信号机故障
type Signal_Fault int32
const (
// 灯丝断丝
Signal_DS Signal_Fault = 0
)
// Enum value maps for Signal_Fault.
var (
Signal_Fault_name = map[int32]string{
0: "DS",
}
Signal_Fault_value = map[string]int32{
"DS": 0,
}
)
func (x Signal_Fault) Enum() *Signal_Fault {
p := new(Signal_Fault)
*p = x
return p
}
func (x Signal_Fault) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (Signal_Fault) Descriptor() protoreflect.EnumDescriptor {
return file_component_signal_proto_enumTypes[0].Descriptor()
}
func (Signal_Fault) Type() protoreflect.EnumType {
return &file_component_signal_proto_enumTypes[0]
}
func (x Signal_Fault) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use Signal_Fault.Descriptor instead.
func (Signal_Fault) EnumDescriptor() ([]byte, []int) {
return file_component_signal_proto_rawDescGZIP(), []int{0, 0}
}
// 灯色
type Light_Color int32
const (
// 无
Light_N Light_Color = 0
// 绿
Light_L Light_Color = 1
// 红
Light_H Light_Color = 2
// 黄
Light_U Light_Color = 3
// 白
Light_B Light_Color = 4
// 蓝
Light_A Light_Color = 5
)
// Enum value maps for Light_Color.
var (
Light_Color_name = map[int32]string{
0: "N",
1: "L",
2: "H",
3: "U",
4: "B",
5: "A",
}
Light_Color_value = map[string]int32{
"N": 0,
"L": 1,
"H": 2,
"U": 3,
"B": 4,
"A": 5,
}
)
func (x Light_Color) Enum() *Light_Color {
p := new(Light_Color)
*p = x
return p
}
func (x Light_Color) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (Light_Color) Descriptor() protoreflect.EnumDescriptor {
return file_component_signal_proto_enumTypes[1].Descriptor()
}
func (Light_Color) Type() protoreflect.EnumType {
return &file_component_signal_proto_enumTypes[1]
}
func (x Light_Color) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use Light_Color.Descriptor instead.
func (Light_Color) EnumDescriptor() ([]byte, []int) {
return file_component_signal_proto_rawDescGZIP(), []int{1, 0}
}
// 信号机
type Signal struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 信号机故障列表
Fault []Signal_Fault `protobuf:"varint,1,rep,packed,name=fault,proto3,enum=component.Signal_Fault" json:"fault,omitempty"`
}
func (x *Signal) Reset() {
*x = Signal{}
if protoimpl.UnsafeEnabled {
mi := &file_component_signal_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Signal) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Signal) ProtoMessage() {}
func (x *Signal) ProtoReflect() protoreflect.Message {
mi := &file_component_signal_proto_msgTypes[0]
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 Signal.ProtoReflect.Descriptor instead.
func (*Signal) Descriptor() ([]byte, []int) {
return file_component_signal_proto_rawDescGZIP(), []int{0}
}
func (x *Signal) GetFault() []Signal_Fault {
if x != nil {
return x.Fault
}
return nil
}
type Light struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *Light) Reset() {
*x = Light{}
if protoimpl.UnsafeEnabled {
mi := &file_component_signal_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Light) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Light) ProtoMessage() {}
func (x *Light) ProtoReflect() protoreflect.Message {
mi := &file_component_signal_proto_msgTypes[1]
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 Light.ProtoReflect.Descriptor instead.
func (*Light) Descriptor() ([]byte, []int) {
return file_component_signal_proto_rawDescGZIP(), []int{1}
}
var File_component_signal_proto protoreflect.FileDescriptor
var file_component_signal_proto_rawDesc = []byte{
0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x2f, 0x73, 0x69, 0x67, 0x6e,
0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e,
0x65, 0x6e, 0x74, 0x22, 0x48, 0x0a, 0x06, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x12, 0x2d, 0x0a,
0x05, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x63,
0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x2e,
0x46, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x05, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x22, 0x0f, 0x0a, 0x05,
0x46, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x06, 0x0a, 0x02, 0x44, 0x53, 0x10, 0x00, 0x22, 0x3a, 0x0a,
0x05, 0x4c, 0x69, 0x67, 0x68, 0x74, 0x22, 0x31, 0x0a, 0x05, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x12,
0x05, 0x0a, 0x01, 0x4e, 0x10, 0x00, 0x12, 0x05, 0x0a, 0x01, 0x4c, 0x10, 0x01, 0x12, 0x05, 0x0a,
0x01, 0x48, 0x10, 0x02, 0x12, 0x05, 0x0a, 0x01, 0x55, 0x10, 0x03, 0x12, 0x05, 0x0a, 0x01, 0x42,
0x10, 0x04, 0x12, 0x05, 0x0a, 0x01, 0x41, 0x10, 0x05, 0x42, 0x1d, 0x5a, 0x1b, 0x2e, 0x2f, 0x63,
0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65,
0x6e, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_component_signal_proto_rawDescOnce sync.Once
file_component_signal_proto_rawDescData = file_component_signal_proto_rawDesc
)
func file_component_signal_proto_rawDescGZIP() []byte {
file_component_signal_proto_rawDescOnce.Do(func() {
file_component_signal_proto_rawDescData = protoimpl.X.CompressGZIP(file_component_signal_proto_rawDescData)
})
return file_component_signal_proto_rawDescData
}
var file_component_signal_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_component_signal_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_component_signal_proto_goTypes = []interface{}{
(Signal_Fault)(0), // 0: component.Signal.Fault
(Light_Color)(0), // 1: component.Light.Color
(*Signal)(nil), // 2: component.Signal
(*Light)(nil), // 3: component.Light
}
var file_component_signal_proto_depIdxs = []int32{
0, // 0: component.Signal.fault:type_name -> component.Signal.Fault
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_component_signal_proto_init() }
func file_component_signal_proto_init() {
if File_component_signal_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_component_signal_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Signal); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_component_signal_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Light); 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{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_component_signal_proto_rawDesc,
NumEnums: 2,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_component_signal_proto_goTypes,
DependencyIndexes: file_component_signal_proto_depIdxs,
EnumInfos: file_component_signal_proto_enumTypes,
MessageInfos: file_component_signal_proto_msgTypes,
}.Build()
File_component_signal_proto = out.File
file_component_signal_proto_rawDesc = nil
file_component_signal_proto_goTypes = nil
file_component_signal_proto_depIdxs = nil
}

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

@ -1,6 +1,9 @@
package component
import "joylink.club/ecs"
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component/component_proto"
)
// SignalLights 信号机灯位列表
type SignalLights struct {
@ -19,6 +22,29 @@ func (sl *SignalLights) GetLightByTag(dTag DsTag) *ecs.Entry {
return nil
}
// GetLightByColor 根据灯色取灯位列表中的某个灯
func (sl *SignalLights) GetLightByColor(light component_proto.Light_Color) *ecs.Entry {
switch light {
case component_proto.Light_L:
return sl.GetLightByTag(LdTag)
case component_proto.Light_H:
return sl.GetLightByTag(HdTag)
case component_proto.Light_U:
return sl.GetLightByTag(UdTag)
case component_proto.Light_B:
return sl.GetLightByTag(BdTag)
case component_proto.Light_A:
return sl.GetLightByTag(AdTag)
}
return nil
}
//////////////////////////////////////////////////////////////////
var (
LightFaultDsType = ecs.NewTag() //灯断丝故障
)
///////////////////////////////////////////////////
// Signal2XH1Electronic 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机

45
fi/signal.go Normal file
View File

@ -0,0 +1,45 @@
package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity"
)
// UpdateSignalLightFault 设置信号机灯故障
//
// light : 灯泡
// faultType :故障类型
// set : true-设置故障false-取消故障
func UpdateSignalLightFault(w ecs.World, signalId string, light component_proto.Light_Color, faultType component_proto.Signal_Fault, set bool) error {
r := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId]
if ok {
switch faultType {
case component_proto.Signal_DS: //断丝故障
{
lightEntry := component.SignalLightsType.Get(signalEntry).GetLightByColor(light)
if lightEntry == nil {
return ecs.NewErrResult(fmt.Errorf("信号机[%s]没有色灯[%d]", signalId, light))
}
if set {
if !lightEntry.HasComponent(component.LightFaultDsType) {
lightEntry.AddComponent(component.LightFaultDsType)
}
} else {
if lightEntry.HasComponent(component.LightFaultDsType) {
lightEntry.RemoveComponent(component.LightFaultDsType)
}
}
}
default:
return ecs.NewErrResult(fmt.Errorf("信号机[%s]不支持该故障类型[%s]", signalId, faultType))
}
}
return ecs.NewOkEmptyResult()
})
return r.Err
}

View File

@ -0,0 +1,35 @@
syntax = "proto3";
package component;
option go_package = "./component/component_proto";
//
message Signal {
//
enum Fault {
//
DS = 0;
}
//
repeated Fault fault = 1;
}
//
message Light{
//
enum Color {
//
N = 0;
//绿
L = 1;
//
H = 2;
//
U = 3;
//
B=4;
//
A=5;
}
}

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

View File

@ -25,5 +25,12 @@ func (ls *LightSys) Update(w ecs.World) {
if drive.Td != state.Val {
state.Val = drive.Td
}
//故障设置
state.Val = state.Val && !ls.calculateFault(entry)
})
}
func (ls *LightSys) calculateFault(entry *ecs.Entry) bool {
//断丝故障
haveFault := entry.HasComponent(component.LightFaultDsType)
return haveFault
}