屏蔽门测试

This commit is contained in:
xzb 2023-08-25 10:50:39 +08:00
parent 84fc264d62
commit 747c9a2347
13 changed files with 328 additions and 265 deletions

View File

@ -17,9 +17,11 @@ var DeviceIdentityComponent = ecs.NewComponentType[cstate.DeviceIdentity]()
// 持有实体标签的组件
var EntityTagHandlerComponent = ecs.NewComponentType[cstate.EntityTagHandler]()
// 百分比设备组件
var PercentageDeviceComponent = ecs.NewComponentType[cstate.PercentageDeviceState]()
var PercentageDeviceOperatingComponent = ecs.NewComponentType[cstate.PercentageDeviceOperating]()
// 可移动设备组件
var MovableDeviceStateComponent = ecs.NewComponentType[cstate.MovableDeviceState]()
// 比率设备组件
var PercentageDeviceStateComponent = ecs.NewComponentType[cstate.PercentageDeviceState]()
// 道岔继电器状态组件
var SwitchRelayStateComponent = ecs.NewComponentType[cstate.SwitchRelayState]()

View File

@ -535,14 +535,16 @@ func (x *PsdState) GetInterlockReleased() bool {
return false
}
// 百分比设备,具体如道岔、门等
// 设备
type PercentageDeviceState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 当前百分比值,值范围[0,100],L=0,H=100
Rate int32 `protobuf:"varint,1,opt,name=rate,proto3" json:"rate,omitempty"`
// 当前比率,值范围[0,100000]
Rate int64 `protobuf:"varint,1,opt,name=rate,proto3" json:"rate,omitempty"`
// 最终目标比率
Target int64 `protobuf:"varint,2,opt,name=target,proto3" json:"target,omitempty"`
}
func (x *PercentageDeviceState) Reset() {
@ -577,33 +579,37 @@ func (*PercentageDeviceState) Descriptor() ([]byte, []int) {
return file_status_proto_rawDescGZIP(), []int{6}
}
func (x *PercentageDeviceState) GetRate() int32 {
func (x *PercentageDeviceState) GetRate() int64 {
if x != nil {
return x.Rate
}
return 0
}
// 百分比设备操作
type PercentageDeviceOperating struct {
func (x *PercentageDeviceState) GetTarget() int64 {
if x != nil {
return x.Target
}
return 0
}
// 按速度移动的设备,具体如道岔、门等
type MovableDeviceState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 变动方向
// true-位置增大false-位置变小
ToH bool `protobuf:"varint,1,opt,name=toH,proto3" json:"toH,omitempty"`
// 0-100总距离单位ms
LhDistance int64 `protobuf:"varint,2,opt,name=lhDistance,proto3" json:"lhDistance,omitempty"`
// 本次操作开始时已经移动的距离单位ms
InitDistance int64 `protobuf:"varint,3,opt,name=initDistance,proto3" json:"initDistance,omitempty"`
// 本次操作一共要移动的距离单位ms
SumDistance int64 `protobuf:"varint,4,opt,name=sumDistance,proto3" json:"sumDistance,omitempty"`
// 剩余移动距离单位ms
RemainingDistance int64 `protobuf:"varint,5,opt,name=remainingDistance,proto3" json:"remainingDistance,omitempty"`
// 变动速率一个world tick的位置变动率
Speed int32 `protobuf:"varint,2,opt,name=speed,proto3" json:"speed,omitempty"`
// 被移动的物体的位置
Position int64 `protobuf:"varint,3,opt,name=position,proto3" json:"position,omitempty"`
}
func (x *PercentageDeviceOperating) Reset() {
*x = PercentageDeviceOperating{}
func (x *MovableDeviceState) Reset() {
*x = MovableDeviceState{}
if protoimpl.UnsafeEnabled {
mi := &file_status_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -611,13 +617,13 @@ func (x *PercentageDeviceOperating) Reset() {
}
}
func (x *PercentageDeviceOperating) String() string {
func (x *MovableDeviceState) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PercentageDeviceOperating) ProtoMessage() {}
func (*MovableDeviceState) ProtoMessage() {}
func (x *PercentageDeviceOperating) ProtoReflect() protoreflect.Message {
func (x *MovableDeviceState) ProtoReflect() protoreflect.Message {
mi := &file_status_proto_msgTypes[7]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -629,42 +635,28 @@ func (x *PercentageDeviceOperating) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use PercentageDeviceOperating.ProtoReflect.Descriptor instead.
func (*PercentageDeviceOperating) Descriptor() ([]byte, []int) {
// Deprecated: Use MovableDeviceState.ProtoReflect.Descriptor instead.
func (*MovableDeviceState) Descriptor() ([]byte, []int) {
return file_status_proto_rawDescGZIP(), []int{7}
}
func (x *PercentageDeviceOperating) GetToH() bool {
func (x *MovableDeviceState) GetToH() bool {
if x != nil {
return x.ToH
}
return false
}
func (x *PercentageDeviceOperating) GetLhDistance() int64 {
func (x *MovableDeviceState) GetSpeed() int32 {
if x != nil {
return x.LhDistance
return x.Speed
}
return 0
}
func (x *PercentageDeviceOperating) GetInitDistance() int64 {
func (x *MovableDeviceState) GetPosition() int64 {
if x != nil {
return x.InitDistance
}
return 0
}
func (x *PercentageDeviceOperating) GetSumDistance() int64 {
if x != nil {
return x.SumDistance
}
return 0
}
func (x *PercentageDeviceOperating) GetRemainingDistance() int64 {
if x != nil {
return x.RemainingDistance
return x.Position
}
return 0
}
@ -1191,80 +1183,75 @@ var file_status_proto_rawDesc = []byte{
0x09, 0x61, 0x6c, 0x6c, 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x12, 0x2c, 0x0a, 0x11, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x18,
0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6c, 0x6f, 0x63, 0x6b,
0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x22, 0x2b, 0x0a, 0x15, 0x50, 0x65, 0x72, 0x63,
0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x22, 0x43, 0x0a, 0x15, 0x50, 0x65, 0x72, 0x63,
0x65, 0x6e, 0x74, 0x61, 0x67, 0x65, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74,
0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
0x04, 0x72, 0x61, 0x74, 0x65, 0x22, 0xc1, 0x01, 0x0a, 0x19, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e,
0x74, 0x61, 0x67, 0x65, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74,
0x69, 0x6e, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6f, 0x48, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
0x52, 0x03, 0x74, 0x6f, 0x48, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x68, 0x44, 0x69, 0x73, 0x74, 0x61,
0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x6c, 0x68, 0x44, 0x69, 0x73,
0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x69, 0x6e, 0x69, 0x74, 0x44, 0x69, 0x73,
0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x69, 0x6e, 0x69,
0x74, 0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x75, 0x6d,
0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b,
0x73, 0x75, 0x6d, 0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2c, 0x0a, 0x11, 0x72,
0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, 0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x72, 0x65, 0x6d, 0x61, 0x69, 0x6e, 0x69, 0x6e,
0x67, 0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x22, 0x3e, 0x0a, 0x0b, 0x42, 0x61, 0x6c,
0x69, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x2f, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74,
0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x63, 0x73, 0x74, 0x61,
0x74, 0x65, 0x2e, 0x42, 0x61, 0x6c, 0x69, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x4d, 0x0a, 0x0d, 0x42, 0x61, 0x6c,
0x69, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79,
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52,
0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x6e, 0x0a, 0x14, 0x4f, 0x63, 0x63, 0x75,
0x70, 0x69, 0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x12, 0x16, 0x0a, 0x06, 0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72,
0x74, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x73,
0x74, 0x61, 0x72, 0x74, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x6e,
0x64, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65,
0x6e, 0x64, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x22, 0x89, 0x01, 0x0a, 0x0a, 0x54, 0x72, 0x61,
0x69, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x37, 0x0a, 0x0a, 0x61, 0x63, 0x74, 0x69, 0x76,
0x65, 0x48, 0x65, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x63, 0x73,
0x74, 0x61, 0x74, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65,
0x45, 0x6e, 0x75, 0x6d, 0x52, 0x0a, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x48, 0x65, 0x61, 0x64,
0x12, 0x42, 0x0a, 0x0d, 0x6f, 0x63, 0x63, 0x75, 0x70, 0x69, 0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b,
0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x63, 0x73, 0x74, 0x61, 0x74, 0x65,
0x2e, 0x4f, 0x63, 0x63, 0x75, 0x70, 0x69, 0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b, 0x50, 0x6f, 0x73,
0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x6f, 0x63, 0x63, 0x75, 0x70, 0x69, 0x65, 0x64, 0x4c,
0x69, 0x6e, 0x6b, 0x73, 0x22, 0x40, 0x0a, 0x16, 0x54, 0x6f, 0x77, 0x50, 0x6f, 0x73, 0x69, 0x74,
0x69, 0x6f, 0x6e, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12,
0x0a, 0x04, 0x70, 0x6f, 0x73, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x70, 0x6f,
0x73, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x73, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08,
0x52, 0x04, 0x70, 0x6f, 0x73, 0x32, 0x22, 0x2b, 0x0a, 0x0b, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e,
0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x72, 0x65, 0x73, 0x73, 0x44, 0x6f,
0x77, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x70, 0x72, 0x65, 0x73, 0x73, 0x44,
0x6f, 0x77, 0x6e, 0x22, 0x84, 0x01, 0x0a, 0x14, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x50, 0x72,
0x65, 0x73, 0x73, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x14, 0x0a, 0x05,
0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x74, 0x61,
0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x6f, 0x77, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08,
0x52, 0x04, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x6f, 0x70, 0x65,
0x72, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6e, 0x65, 0x65, 0x64,
0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x6e,
0x65, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x22, 0x4a, 0x0a, 0x16, 0x42, 0x75,
0x74, 0x74, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x4f, 0x70, 0x65, 0x72, 0x61,
0x74, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18,
0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x12, 0x16,
0x0a, 0x06, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06,
0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x2a, 0x81, 0x01, 0x0a, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x61,
0x6c, 0x41, 0x73, 0x70, 0x65, 0x63, 0x74, 0x12, 0x06, 0x0a, 0x02, 0x4e, 0x6f, 0x10, 0x00, 0x12,
0x05, 0x0a, 0x01, 0x52, 0x10, 0x01, 0x12, 0x05, 0x0a, 0x01, 0x47, 0x10, 0x02, 0x12, 0x05, 0x0a,
0x01, 0x59, 0x10, 0x03, 0x12, 0x05, 0x0a, 0x01, 0x57, 0x10, 0x04, 0x12, 0x05, 0x0a, 0x01, 0x42,
0x10, 0x05, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x59, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x57,
0x10, 0x07, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x47, 0x10, 0x08, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x59,
0x10, 0x09, 0x12, 0x06, 0x0a, 0x02, 0x59, 0x59, 0x10, 0x0a, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x46,
0x10, 0x0b, 0x12, 0x06, 0x0a, 0x02, 0x59, 0x46, 0x10, 0x0c, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x46,
0x10, 0x0d, 0x12, 0x06, 0x0a, 0x02, 0x57, 0x46, 0x10, 0x0e, 0x2a, 0x35, 0x0a, 0x0f, 0x54, 0x72,
0x61, 0x69, 0x6e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0a, 0x0a,
0x06, 0x48, 0x45, 0x41, 0x44, 0x5f, 0x4e, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x48, 0x45, 0x41,
0x44, 0x5f, 0x41, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x48, 0x45, 0x41, 0x44, 0x5f, 0x42, 0x10,
0x02, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x63, 0x73, 0x74, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52,
0x04, 0x72, 0x61, 0x74, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18,
0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x22, 0x58, 0x0a,
0x12, 0x4d, 0x6f, 0x76, 0x61, 0x62, 0x6c, 0x65, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74,
0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6f, 0x48, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
0x52, 0x03, 0x74, 0x6f, 0x48, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x70, 0x65, 0x65, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x70, 0x65, 0x65, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70,
0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70,
0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3e, 0x0a, 0x0b, 0x42, 0x61, 0x6c, 0x69, 0x73,
0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x2f, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x63, 0x73, 0x74, 0x61, 0x74, 0x65,
0x2e, 0x42, 0x61, 0x6c, 0x69, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x52, 0x07,
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x4d, 0x0a, 0x0d, 0x42, 0x61, 0x6c, 0x69, 0x73,
0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07,
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x6e, 0x0a, 0x14, 0x4f, 0x63, 0x63, 0x75, 0x70, 0x69,
0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16,
0x0a, 0x06, 0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4f,
0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x73, 0x74, 0x61,
0x72, 0x74, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x4f,
0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65, 0x6e, 0x64,
0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x22, 0x89, 0x01, 0x0a, 0x0a, 0x54, 0x72, 0x61, 0x69, 0x6e,
0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x37, 0x0a, 0x0a, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x48,
0x65, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x63, 0x73, 0x74, 0x61,
0x74, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x45, 0x6e,
0x75, 0x6d, 0x52, 0x0a, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x48, 0x65, 0x61, 0x64, 0x12, 0x42,
0x0a, 0x0d, 0x6f, 0x63, 0x63, 0x75, 0x70, 0x69, 0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b, 0x73, 0x18,
0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x63, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x4f,
0x63, 0x63, 0x75, 0x70, 0x69, 0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b, 0x50, 0x6f, 0x73, 0x69, 0x74,
0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x6f, 0x63, 0x63, 0x75, 0x70, 0x69, 0x65, 0x64, 0x4c, 0x69, 0x6e,
0x6b, 0x73, 0x22, 0x40, 0x0a, 0x16, 0x54, 0x6f, 0x77, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
0x6e, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04,
0x70, 0x6f, 0x73, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x70, 0x6f, 0x73, 0x31,
0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x73, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04,
0x70, 0x6f, 0x73, 0x32, 0x22, 0x2b, 0x0a, 0x0b, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x53, 0x74,
0x61, 0x74, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x72, 0x65, 0x73, 0x73, 0x44, 0x6f, 0x77, 0x6e,
0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x70, 0x72, 0x65, 0x73, 0x73, 0x44, 0x6f, 0x77,
0x6e, 0x22, 0x84, 0x01, 0x0a, 0x14, 0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x50, 0x72, 0x65, 0x73,
0x73, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74,
0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74,
0x12, 0x12, 0x0a, 0x04, 0x64, 0x6f, 0x77, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04,
0x64, 0x6f, 0x77, 0x6e, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x65, 0x54,
0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61,
0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6e, 0x65, 0x65, 0x64, 0x43, 0x6f,
0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x6e, 0x65, 0x65,
0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x22, 0x4a, 0x0a, 0x16, 0x42, 0x75, 0x74, 0x74,
0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69,
0x6e, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18, 0x01, 0x20,
0x01, 0x28, 0x08, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06,
0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x63, 0x61,
0x6e, 0x63, 0x65, 0x6c, 0x2a, 0x81, 0x01, 0x0a, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x41,
0x73, 0x70, 0x65, 0x63, 0x74, 0x12, 0x06, 0x0a, 0x02, 0x4e, 0x6f, 0x10, 0x00, 0x12, 0x05, 0x0a,
0x01, 0x52, 0x10, 0x01, 0x12, 0x05, 0x0a, 0x01, 0x47, 0x10, 0x02, 0x12, 0x05, 0x0a, 0x01, 0x59,
0x10, 0x03, 0x12, 0x05, 0x0a, 0x01, 0x57, 0x10, 0x04, 0x12, 0x05, 0x0a, 0x01, 0x42, 0x10, 0x05,
0x12, 0x06, 0x0a, 0x02, 0x52, 0x59, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x57, 0x10, 0x07,
0x12, 0x06, 0x0a, 0x02, 0x47, 0x47, 0x10, 0x08, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x59, 0x10, 0x09,
0x12, 0x06, 0x0a, 0x02, 0x59, 0x59, 0x10, 0x0a, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x46, 0x10, 0x0b,
0x12, 0x06, 0x0a, 0x02, 0x59, 0x46, 0x10, 0x0c, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x46, 0x10, 0x0d,
0x12, 0x06, 0x0a, 0x02, 0x57, 0x46, 0x10, 0x0e, 0x2a, 0x35, 0x0a, 0x0f, 0x54, 0x72, 0x61, 0x69,
0x6e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0a, 0x0a, 0x06, 0x48,
0x45, 0x41, 0x44, 0x5f, 0x4e, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x48, 0x45, 0x41, 0x44, 0x5f,
0x41, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x48, 0x45, 0x41, 0x44, 0x5f, 0x42, 0x10, 0x02, 0x42,
0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x63, 0x73, 0x74, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
@ -1282,24 +1269,24 @@ func file_status_proto_rawDescGZIP() []byte {
var file_status_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_status_proto_msgTypes = make([]protoimpl.MessageInfo, 16)
var file_status_proto_goTypes = []interface{}{
(SignalAspect)(0), // 0: cstate.SignalAspect
(TrainActiveEnum)(0), // 1: cstate.TrainActiveEnum
(*DeviceIdentity)(nil), // 2: cstate.DeviceIdentity
(*SwitchRelayState)(nil), // 3: cstate.SwitchRelayState
(*PhysicalSectionState)(nil), // 4: cstate.PhysicalSectionState
(*SignalState)(nil), // 5: cstate.SignalState
(*SignalDisplayOperating)(nil), // 6: cstate.SignalDisplayOperating
(*PsdState)(nil), // 7: cstate.PsdState
(*PercentageDeviceState)(nil), // 8: cstate.PercentageDeviceState
(*PercentageDeviceOperating)(nil), // 9: cstate.PercentageDeviceOperating
(*BaliseState)(nil), // 10: cstate.BaliseState
(*BaliseContent)(nil), // 11: cstate.BaliseContent
(*OccupiedLinkPosition)(nil), // 12: cstate.OccupiedLinkPosition
(*TrainState)(nil), // 13: cstate.TrainState
(*TowPositionButtonState)(nil), // 14: cstate.TowPositionButtonState
(*ButtonState)(nil), // 15: cstate.ButtonState
(*ButtonPressOperating)(nil), // 16: cstate.ButtonPressOperating
(*ButtonConfirmOperating)(nil), // 17: cstate.ButtonConfirmOperating
(SignalAspect)(0), // 0: cstate.SignalAspect
(TrainActiveEnum)(0), // 1: cstate.TrainActiveEnum
(*DeviceIdentity)(nil), // 2: cstate.DeviceIdentity
(*SwitchRelayState)(nil), // 3: cstate.SwitchRelayState
(*PhysicalSectionState)(nil), // 4: cstate.PhysicalSectionState
(*SignalState)(nil), // 5: cstate.SignalState
(*SignalDisplayOperating)(nil), // 6: cstate.SignalDisplayOperating
(*PsdState)(nil), // 7: cstate.PsdState
(*PercentageDeviceState)(nil), // 8: cstate.PercentageDeviceState
(*MovableDeviceState)(nil), // 9: cstate.MovableDeviceState
(*BaliseState)(nil), // 10: cstate.BaliseState
(*BaliseContent)(nil), // 11: cstate.BaliseContent
(*OccupiedLinkPosition)(nil), // 12: cstate.OccupiedLinkPosition
(*TrainState)(nil), // 13: cstate.TrainState
(*TowPositionButtonState)(nil), // 14: cstate.TowPositionButtonState
(*ButtonState)(nil), // 15: cstate.ButtonState
(*ButtonPressOperating)(nil), // 16: cstate.ButtonPressOperating
(*ButtonConfirmOperating)(nil), // 17: cstate.ButtonConfirmOperating
}
var file_status_proto_depIdxs = []int32{
0, // 0: cstate.SignalState.display:type_name -> cstate.SignalAspect
@ -1405,7 +1392,7 @@ func file_status_proto_init() {
}
}
file_status_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PercentageDeviceOperating); i {
switch v := v.(*MovableDeviceState); i {
case 0:
return &v.state
case 1:

View File

@ -44,7 +44,8 @@ func initEntites(config *WorldConfig, world ecs.World) {
entry := CreateSwitchEntity(world)
components.DeviceIdentityComponent.Set(entry, &cstate.DeviceIdentity{Id: md.GetId()})
components.SwitchRelayStateComponent.Set(entry, &cstate.SwitchRelayState{DcJ: false, FcJ: false, DbJ: true, FbJ: false})
components.PercentageDeviceComponent.Set(entry, &cstate.PercentageDeviceState{Rate: system.SwitchNormalRate})
components.PercentageDeviceStateComponent.Set(entry, &cstate.PercentageDeviceState{Rate: system.SwitchNormalVaule, Target: system.SwitchNormalVaule})
components.MovableDeviceStateComponent.Set(entry, &cstate.MovableDeviceState{ToH: false, Speed: 0, Position: system.SwitchNormalVaule})
})
//
foreachModels(config.ModelManager, umi.Signal, func(md umi.IDeviceModel) {
@ -62,7 +63,8 @@ func initEntites(config *WorldConfig, world ecs.World) {
for _, psdCell := range psd.AllDeviceCells() {
cellEntry := CreatePsdCellEntity(world, psdEntry)
components.DeviceIdentityComponent.Set(cellEntry, &cstate.DeviceIdentity{Id: psdCell.GetId()})
components.PercentageDeviceComponent.Set(cellEntry, &cstate.PercentageDeviceState{Rate: system.PsdCellWholeCloseRate})
components.PercentageDeviceStateComponent.Set(cellEntry, &cstate.PercentageDeviceState{Rate: system.PsdCellWholeCloseValue, Target: system.PsdCellWholeCloseValue})
components.MovableDeviceStateComponent.Set(cellEntry, &cstate.MovableDeviceState{ToH: true, Speed: 0, Position: system.PsdCellWholeCloseValue})
}
})
//
@ -87,7 +89,7 @@ func CreateModelStorageRefEntity(w ecs.World) *ecs.Entry {
// 创建道岔实体
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent)
return w.Create(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent)
}
// 创建信号机实体
@ -109,7 +111,7 @@ func CreatePsdEntity(w ecs.World) *ecs.Entry {
// 创建屏蔽门cell实体
func CreatePsdCellEntity(w ecs.World, psdEntry *ecs.Entry) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.PercentageDeviceComponent, components.EntityTagHandlerComponent.Get(psdEntry).Tag)
return w.Create(components.DeviceIdentityComponent, components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent, components.EntityTagHandlerComponent.Get(psdEntry).Tag)
}
// 创建应答器实体

View File

@ -26,12 +26,14 @@ func main() {
ModelManager: woldModelStorage,
Tick: 300,
InitTime: time.Now(),
Systems: []ecs.ISystem{system.NewPercentageSystem(), system.NewSwitchSystem(), system.NewPsdSystem(), system.NewTimerSystem(), system.NewDebugSystem()},
Systems: []ecs.ISystem{system.NewMovableDeviceSystem(), system.NewPercentageDeviceSystem(), system.NewSwitchSystem(), system.NewPsdSystem(), system.NewTimerSystem(), system.NewDebugSystem()},
}
world := creator.InitializeWorld(config)
//
world.StartUp()
//
time.Sleep(2 * time.Second)
//
testPsdOpt(world)
//
time.Sleep(120 * time.Second)
@ -100,9 +102,9 @@ func testPsdCellOpt(w ecs.World) {
operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
}
func testSwitchTurn(w ecs.World) {
operate.FireSwitchTurn(w, "switch1", system.SwitchReverseRate)
operate.FireSwitchTurn(w, "switch1", operate.SwitchReverseRate)
time.Sleep(8 * time.Second)
operate.FireSwitchTurn(w, "switch1", system.SwitchNormalRate)
operate.FireSwitchTurn(w, "switch1", operate.SwitchNormalRate)
}
func testSignalOpt(w ecs.World) {

View File

@ -5,45 +5,33 @@ import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/system"
)
// 触发操作百分比设备
// deviceEntry 百分比组件所在的实体
// lhDistance 百分比设备从0-100的距离单位ms
// toRate 本次操作最终目标百分比
func FirePercentageDeviceOperation(w ecs.World, deviceEntry *ecs.Entry, lhDistance int64, toRate int32) error {
if !deviceEntry.HasComponent(components.PercentageDeviceComponent) {
entityId := components.DeviceIdentityComponent.Get(deviceEntry).Id
return fmt.Errorf("实体[%s]中不存在百分比组件", entityId)
}
curRate := components.PercentageDeviceComponent.Get(deviceEntry).Rate
if curRate == toRate {
return nil
// 触发比率设备变动到目标比率
// lhDistance: 从L到H的总耗时单位ms
// targetRateValue: 变动的最终目标比率值,[0,100000]
func FirePercentageDevice(world ecs.World, deviceEntry *ecs.Entry, lhDistance int64, targetRateValue int64) error {
if targetRateValue < system.PercentageRateValueMin || targetRateValue > system.PercentageRateValueMax {
return fmt.Errorf("targetRateValue须在[%d,%d]范围内", system.PercentageRateValueMin, system.PercentageRateValueMax)
}
//
if !deviceEntry.HasComponent(components.PercentageDeviceOperatingComponent) {
deviceEntry.AddComponent(components.PercentageDeviceOperatingComponent)
id := components.DeviceIdentityComponent.Get(deviceEntry).Id
if !deviceEntry.HasComponent(components.PercentageDeviceStateComponent) {
return fmt.Errorf("比率设备[%s]实体中没有百分比组件", id)
}
operation := components.PercentageDeviceOperatingComponent.Get(deviceEntry)
//
toHigh := toRate > curRate
var initDistance, sumDistance int64
if toHigh {
initDistance = int64(float64(lhDistance) * (float64(curRate) / float64(100)))
sumDistance = int64(float64(lhDistance) * (float64(toRate-curRate) / float64(100)))
} else {
initDistance = int64(float64(lhDistance) * (float64(100-curRate) / float64(100)))
sumDistance = int64(float64(lhDistance) * (float64(curRate-toRate) / float64(100)))
if !deviceEntry.HasComponent(components.MovableDeviceStateComponent) {
return fmt.Errorf("比率设备[%s]实体中没有按速度移动组件", id)
}
//
*operation = cstate.PercentageDeviceOperating{
ToH: toHigh,
LhDistance: lhDistance,
InitDistance: initDistance,
SumDistance: sumDistance,
RemainingDistance: sumDistance,
}
speed := int32(float64(world.Tick()) * (float64(system.PercentageRateValueMax) / float64(lhDistance)))
//
percent := components.PercentageDeviceStateComponent.Get(deviceEntry)
movable := components.MovableDeviceStateComponent.Get(deviceEntry)
//
percent.Target = targetRateValue
movable.Speed = speed
movable.ToH = targetRateValue > percent.Rate
//
return nil
}

View File

@ -10,6 +10,13 @@ import (
"joylink.club/rtsssimulation/umi"
)
const (
//屏蔽门完全关闭,百分比
PsdCellWholeCloseRate int8 = system.PercentageRateMax
//屏蔽门完全打开,百分比
PsdCellWholeOpenRate int8 = system.PercentageRateMin
)
// 车站单侧屏蔽门互锁解除操作
func FirePsdInterlockRelease(world ecs.World, psdId string, lockRelease bool) error {
psdEntry, err := findPsdEntry(world, psdId)
@ -31,20 +38,23 @@ func FirePsdOperation(world ecs.World, psdId string, closeOpt bool) error {
//屏蔽门标签
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
var errPercent error = nil
psdCellQuery.Each(world, func(psdCellEntry *ecs.Entry) {
if closeOpt {
FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(world, psdId), system.PsdCellWholeCloseRate)
} else {
FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(world, psdId), system.PsdCellWholeOpenRate)
if errPercent == nil {
if closeOpt {
errPercent = FirePercentageDevice(world, psdCellEntry, findPsdWholeMoveTime(world, psdId), system.GetRateValue(PsdCellWholeCloseRate))
} else {
errPercent = FirePercentageDevice(world, psdCellEntry, findPsdWholeMoveTime(world, psdId), system.GetRateValue(PsdCellWholeOpenRate))
}
}
})
//
return nil
return errPercent
}
// 车站单侧屏蔽门单元cell操作
// closeRate cell最终关上的百分比100-完全关上0-完全未关即完全打开,(0,100)内即半关闭
func FirePsdCellOperation(world ecs.World, psdId string, psdCellId string, closeRate int32) error {
func FirePsdCellOperation(world ecs.World, psdId string, psdCellId string, closeRate int8) error {
if closeRate < 0 || closeRate > 100 {
return fmt.Errorf("屏蔽门单元操作closeRate(%d)不在[0,100]内", closeRate)
}
@ -61,7 +71,7 @@ func FirePsdCellOperation(world ecs.World, psdId string, psdCellId string, close
return fmt.Errorf("屏蔽门[%s]的单元门[%s]的实体不存在", psdId, psdCellId)
}
//
return FirePercentageDeviceOperation(world, psdCellEntry, findPsdWholeMoveTime(world, psdId), closeRate)
return FirePercentageDevice(world, psdCellEntry, findPsdWholeMoveTime(world, psdId), system.GetRateValue(closeRate))
}
// 获取屏蔽门实体

View File

@ -9,31 +9,43 @@ import (
"joylink.club/rtsssimulation/umi"
)
const (
//道岔定位
SwitchNormalRate int8 = system.PercentageRateMin
//道岔反位
SwitchReverseRate int8 = system.PercentageRateMax
)
// 触发道岔正常转动
// w: 当前世界
// switchId: 道岔id
// terminalRate: 道岔转动到百分比规定定位百分比为0反位百分比为100
func FireSwitchTurn(w ecs.World, switchId string, terminalRate int32) error {
if terminalRate < 0 || terminalRate > 100 {
return fmt.Errorf("道岔转动终点百分比[%d]不在范围[0,100]内", terminalRate)
// turnRate: 道岔转动到目标百分比[0,100]
func FireSwitchTurn(w ecs.World, switchId string, turnRate int8) error {
if turnRate < 0 || turnRate > 100 {
return fmt.Errorf("道岔操作turnRate(%d)不在[0,100]内", turnRate)
}
var switchEntry *ecs.Entry = system.QueryEntityById(w, system.SwitchQuery, switchId)
if switchEntry == nil {
return fmt.Errorf("道岔[%s]的实体不存在", switchId)
}
//
switchRelay := components.SwitchRelayStateComponent.Get(switchEntry)
switchRate := components.PercentageDeviceComponent.Get(switchEntry)
if terminalRate == switchRate.Rate {
return nil
}
switchRelay.DcJ = terminalRate < switchRate.Rate
switchRelay.FcJ = terminalRate > switchRate.Rate
switchRelay.DbJ = false
switchRelay.FbJ = false
switchPercent := components.PercentageDeviceStateComponent.Get(switchEntry)
turnRateValue := system.GetRateValue(turnRate)
//
lhDistance := getSwitchTurnTime(w, switchId)
return FirePercentageDeviceOperation(w, switchEntry, lhDistance, terminalRate)
switchRelay := components.SwitchRelayStateComponent.Get(switchEntry)
if turnRateValue == switchPercent.Rate {
return nil
} else {
lhDistance := getSwitchTurnTime(w, switchId)
if turnRateValue > switchPercent.Rate { //反操
switchRelay.DcJ = false
switchRelay.FcJ = true
} else { //定操
switchRelay.DcJ = true
switchRelay.FcJ = false
}
return FirePercentageDevice(w, switchEntry, lhDistance, turnRateValue)
}
}
// 获取道岔转动耗时ms

View File

@ -102,24 +102,24 @@ message PsdState{
////////////////////////////////////////////////////////
//
//
message PercentageDeviceState{
//[0,100],L=0,H=100
int32 rate =1;
}
//
message PercentageDeviceOperating{
//
bool toH = 1;
//0-100ms
int64 lhDistance = 2;
//ms
int64 initDistance = 3;
//ms
int64 sumDistance = 4;
//ms
int64 remainingDistance = 5;
//,[0,100000]
int64 rate = 1;
//
int64 target = 2;
}
//
message MovableDeviceState{
//
//true-false-
bool toH = 1;
//world tick的位置变动率
int32 speed = 2;
//
int64 position = 3;
}
////////////////////////////////////////////////////////
//

View File

@ -18,12 +18,27 @@ func NewDebugSystem() *DebugSystem {
// world 执行
func (me *DebugSystem) Update(w ecs.World) {
//debugMovableDevice(w)
debugPsd(w)
//debugSwitch(w)
//debugSignal(w)
//debugTowPosButton(w)
}
// 可按速度移动组件
func debugMovableDevice(w ecs.World) {
query := ecs.NewQuery(filter.Contains(components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent))
query.Each(w, func(e *ecs.Entry) {
id := components.DeviceIdentityComponent.Get(e).Id
if "psd1Cell1" == id {
percent := components.PercentageDeviceStateComponent.Get(e)
movable := components.MovableDeviceStateComponent.Get(e)
fmt.Printf("==>>屏蔽门cell [%s],curRateValue = %d ,targetRateValue = %d , speed = %d position = %d\n", id, percent.Rate, percent.Target, movable.Speed, movable.Position)
}
})
}
// 两档位按钮旋钮
func debugTowPosButton(w ecs.World) {
towPosButtonsQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.TowPositionButtonStateComponent))
@ -60,20 +75,21 @@ func debugPsd(w ecs.World) {
psdTag := components.EntityTagHandlerComponent.Get(e).Tag
fmt.Printf("屏蔽门[%s] ,全关=%t ,全开=%t ,互锁解除=%t > ", psdId, psdState.AllClosed, psdState.AllOpened, psdState.InterlockReleased)
//
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag, components.PercentageDeviceComponent))
psdCellQuery := ecs.NewQuery(filter.Contains(psdTag))
psdCellQuery.Each(w, func(e *ecs.Entry) {
psdCellId := components.DeviceIdentityComponent.Get(e).Id
psdCellState := components.PercentageDeviceComponent.Get(e)
psdCellPercent := components.PercentageDeviceStateComponent.Get(e)
psdCellMovable := components.MovableDeviceStateComponent.Get(e)
//
fmt.Printf("|| cell[%s] ,closeRate=%d ", psdCellId, psdCellState.Rate)
if e.HasComponent(components.PercentageDeviceOperatingComponent) {
psdCellOpt := components.PercentageDeviceOperatingComponent.Get(e)
if psdCellOpt.ToH {
fmt.Printf("== 关门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance)
fmt.Printf("|| cell[%s] ,closeRate=%d ", psdCellId, GetRate(psdCellPercent.Rate))
if psdCellMovable.Speed > 0 {
if psdCellMovable.ToH {
fmt.Printf("== 关门操作中,移动速率=%d", psdCellMovable.Speed)
} else {
fmt.Printf("== 开门操作中,剩余移动距离=%d", psdCellOpt.RemainingDistance)
fmt.Printf("== 开门操作中,移动速率=%d", psdCellMovable.Speed)
}
}
})
//
fmt.Println()
@ -92,15 +108,16 @@ func debugSignal(w ecs.World) {
// 显示道岔状态
func debugSwitch(w ecs.World) {
switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
switchesQuery := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent))
switchesQuery.Each(w, func(e *ecs.Entry) {
percent := components.PercentageDeviceStateComponent.Get(e)
movable := components.MovableDeviceStateComponent.Get(e)
id := components.DeviceIdentityComponent.Get(e).Id
curRate := components.PercentageDeviceComponent.Get(e).Rate
curRate := GetRate(percent.Rate)
j := components.SwitchRelayStateComponent.Get(e)
fmt.Printf("道岔 [%s],当前位置百分比 [%d] ,Dcj = %t, Fcj = %t, Dbj = %t ,Fbj = %t ,", id, curRate, j.DcJ, j.FcJ, j.DbJ, j.FbJ)
if e.HasComponent(components.PercentageDeviceOperatingComponent) {
opt := components.PercentageDeviceOperatingComponent.Get(e)
fmt.Printf(" ==> 正在转动,剩余距离[%d]ms", opt.RemainingDistance)
if movable.Speed > 0 {
fmt.Printf(" ==> 正在转动,移动速率[%d]", movable.Speed)
}
fmt.Println()
})

31
system/movable_system.go Normal file
View File

@ -0,0 +1,31 @@
package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
)
// 按速度移动的设备系统
// 只负责按速度移动位置,由该组件的观察者负责解释位置
type MovableDeviceSystem struct {
query *ecs.Query
}
func NewMovableDeviceSystem() *MovableDeviceSystem {
return &MovableDeviceSystem{query: ecs.NewQuery(filter.Contains(components.MovableDeviceStateComponent))}
}
// world 执行
func (me *MovableDeviceSystem) Update(world ecs.World) {
me.query.Each(world, func(e *ecs.Entry) {
md := components.MovableDeviceStateComponent.Get(e)
if md.Speed > 0 {
if md.ToH {
md.Position += int64(md.Speed)
} else {
md.Position -= int64(md.Speed)
}
}
})
}

View File

@ -6,34 +6,53 @@ import (
"joylink.club/rtsssimulation/components"
)
// 百分比设备系统
type PercentageSystem struct {
type PercentageDeviceSystem struct {
query *ecs.Query
}
func NewPercentageSystem() *PercentageSystem {
return &PercentageSystem{query: ecs.NewQuery(filter.Contains(components.PercentageDeviceComponent, components.PercentageDeviceOperatingComponent))}
func NewPercentageDeviceSystem() *PercentageDeviceSystem {
return &PercentageDeviceSystem{query: ecs.NewQuery(filter.Contains(components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent))}
}
const (
PercentageRateValueMax int64 = 100000
PercentageRateValueMin int64 = 0
)
const (
PercentageRateMax int8 = 100
PercentageRateMin int8 = 0
)
// world 执行
func (me *PercentageSystem) Update(world ecs.World) {
func (me *PercentageDeviceSystem) Update(world ecs.World) {
me.query.Each(world, func(e *ecs.Entry) {
operation := components.PercentageDeviceOperatingComponent.Get(e)
if operation.RemainingDistance <= 0 {
operation.RemainingDistance = 0
e.RemoveComponent(components.PercentageDeviceOperatingComponent)
} else {
operation.RemainingDistance -= int64(world.Tick())
if operation.RemainingDistance < 0 {
operation.RemainingDistance = 0
percentage := components.PercentageDeviceStateComponent.Get(e)
if percentage.Rate != percentage.Target {
movable := components.MovableDeviceStateComponent.Get(e)
if movable.ToH {
if movable.Position >= percentage.Target {
movable.Speed = 0
movable.Position = percentage.Target
}
} else {
if movable.Position <= percentage.Target {
movable.Speed = 0
movable.Position = percentage.Target
}
}
//
percentage.Rate = movable.Position
}
//
rateDevice := components.PercentageDeviceComponent.Get(e)
if operation.ToH { //百分比变大
rateDevice.Rate = int32(float64(100) * (float64(operation.InitDistance+operation.SumDistance-operation.RemainingDistance) / float64(operation.LhDistance)))
} else {
rateDevice.Rate = 100 - int32(float64(100)*(float64(operation.InitDistance+operation.SumDistance-operation.RemainingDistance)/float64(operation.LhDistance)))
}
})
}
// 映射百分比到大数值
func GetRateValue(rate int8) int64 {
return int64(float64(float32(rate)/float32(100)) * float64(PercentageRateValueMax))
}
// 大数值映射到百分比
func GetRate(rateValue int64) int8 {
return int8((float64(rateValue) / float64(PercentageRateValueMax)) * float64(100))
}

View File

@ -11,9 +11,9 @@ var PsdQuery = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent,
const (
//屏蔽门完全关闭
PsdCellWholeCloseRate = 100
PsdCellWholeCloseValue = PercentageRateValueMax
//屏蔽门完全打开
PsdCellWholeOpenRate = 0
PsdCellWholeOpenValue = PercentageRateValueMin
)
type PsdSystem struct {
@ -30,18 +30,18 @@ func (me *PsdSystem) Update(world ecs.World) {
psdTag := components.EntityTagHandlerComponent.Get(psdEntry).Tag
psdCellQuery, ok := me.cellsQuery[psdTag]
if !ok {
psdCellQuery = ecs.NewQuery(filter.Contains(psdTag, components.PercentageDeviceComponent))
psdCellQuery = ecs.NewQuery(filter.Contains(psdTag, components.PercentageDeviceStateComponent, components.MovableDeviceStateComponent))
me.cellsQuery[psdTag] = psdCellQuery
}
//
var allCellClosed, allCellOpened bool = true, true
psdCellQuery.Each(world, func(psdCellEntry *ecs.Entry) {
psdCellRate := components.PercentageDeviceComponent.Get(psdCellEntry).Rate
psdCellRate := components.PercentageDeviceStateComponent.Get(psdCellEntry).Rate
if allCellClosed {
allCellClosed = psdCellRate == PsdCellWholeCloseRate
allCellClosed = psdCellRate == PsdCellWholeCloseValue
}
if allCellOpened {
allCellOpened = psdCellRate == PsdCellWholeOpenRate
allCellOpened = psdCellRate == PsdCellWholeOpenValue
}
})
//

View File

@ -6,13 +6,13 @@ import (
"joylink.club/rtsssimulation/components"
)
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent))
var SwitchQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceStateComponent))
const (
//道岔定位
SwitchNormalRate int32 = 0
SwitchNormalVaule int64 = PercentageRateValueMin
//道岔反位
SwitchReverseRate int32 = 100
SwitchReverseValue int64 = PercentageRateValueMax
)
// 道岔系统操作
@ -26,20 +26,13 @@ func NewSwitchSystem() *SwitchSystem {
// world 执行
func (me *SwitchSystem) Update(w ecs.World) {
SwitchQuery.Each(w, func(e *ecs.Entry) {
switchRate := components.PercentageDeviceComponent.Get(e)
switchPercent := components.PercentageDeviceStateComponent.Get(e)
switchRelay := components.SwitchRelayStateComponent.Get(e)
if switchRate.Rate <= 0 {
switchRelay.DcJ = false
switchRelay.DbJ = true
}
if switchRate.Rate >= 100 {
switchRelay.FcJ = false
switchRelay.FbJ = true
}
//过了操作时限,定操反操继电器自动复位
if !e.HasComponent(components.PercentageDeviceOperatingComponent) {
if switchPercent.Rate == switchPercent.Target {
switchRelay.DcJ = false
switchRelay.FcJ = false
switchRelay.DbJ = switchPercent.Rate <= SwitchNormalVaule
switchRelay.FbJ = switchPercent.Rate >= SwitchReverseValue
} else {
switchRelay.DbJ = false
switchRelay.FbJ = false