【新增】车库门PSL模型构建及相关ecs逻辑;

【改动】车库门ecs逻辑
This commit is contained in:
thesai 2024-03-26 13:12:16 +08:00
parent f0a6c534ec
commit d63be32ad5
19 changed files with 1371 additions and 1128 deletions

View File

@ -10,6 +10,7 @@ var (
CkmMgzTag = ecs.NewTag() //门故障tag
CkmCircuitType = ecs.NewComponentType[CkmCircuit]()
CkmStateType = ecs.NewComponentType[component_data.CkmState]()
CkmPslType = ecs.NewComponentType[CkmPsl]()
)
type CkmCircuit struct {
@ -23,3 +24,10 @@ type CkmCircuit struct {
KMJ *ecs.Entry //开门继电器
GMJ *ecs.Entry //关门继电器
}
type CkmPsl struct {
KMA *ecs.Entry //开门按钮
GMA *ecs.Entry //关门按钮
MPLA *ecs.Entry //门旁路按钮
MMSA *ecs.Entry //门模式按钮
}

View File

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

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.32.0
// protoc-gen-go v1.33.0
// protoc v4.23.1
// source: component/ckm.proto
@ -26,7 +26,7 @@ type CkmState struct {
unknownFields protoimpl.UnknownFields
Close bool `protobuf:"varint,1,opt,name=close,proto3" json:"close,omitempty"`
Mms bool `protobuf:"varint,2,opt,name=mms,proto3" json:"mms,omitempty"` //门模式(true远程false本地
Mms bool `protobuf:"varint,2,opt,name=mms,proto3" json:"mms,omitempty"` //门模式(false远程true本地
Mgz bool `protobuf:"varint,3,opt,name=mgz,proto3" json:"mgz,omitempty"` //门故障
// 驱动状态(没有继电器时直接操作以下状态)
Km bool `protobuf:"varint,4,opt,name=km,proto3" json:"km,omitempty"` //开门

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.32.0
// protoc-gen-go v1.33.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.32.0
// protoc-gen-go v1.33.0
// protoc v4.23.1
// source: component/equipment.proto

View File

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

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.32.0
// protoc-gen-go v1.33.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.32.0
// protoc-gen-go v1.33.0
// protoc v4.23.1
// source: component/signal.proto

View File

@ -1,6 +1,7 @@
package entity
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
@ -12,14 +13,31 @@ var CkmBaseComponentTypes = []ecs.IComponentType{component.UidType, component.Ck
func LoadCkm(w ecs.World) error {
data := GetWorldData(w)
for _, ckm := range data.Repo.CkmList() {
ckmEntry := buildBaseEntry(w, ckm, data)
addCkmCircuit(w, ckm, ckmEntry, data)
}
for _, psl := range data.Repo.CkmPslList() {
ckmEntry := data.EntityMap[psl.Ckm().Id()]
addCkmPsl(w, psl, ckmEntry, data)
}
return nil
}
// 构建基础镜像
func buildBaseEntry(w ecs.World, ckm *repository.Ckm, data *component.WorldData) *donburi.Entry {
//创建基础entry
entry := w.Entry(w.Create(CkmBaseComponentTypes...))
component.UidType.SetValue(entry, component.Uid{Id: ckm.Id()})
data.EntityMap[ckm.Id()] = entry
return entry
}
// 添加车库门电路
func addCkmCircuit(w ecs.World, ckm *repository.Ckm, ckmEntry *donburi.Entry, data *component.WorldData) {
//加载电路
if len(ckm.ComponentGroups()) != 0 {
circuit := &component.CkmCircuit{}
entry.AddComponent(component.CkmCircuitType, unsafe.Pointer(circuit))
ckmEntry.AddComponent(component.CkmCircuitType, unsafe.Pointer(circuit))
for _, group := range ckm.ComponentGroups() {
for _, ec := range group.Components() {
relay := ec.(*repository.Relay)
@ -43,5 +61,14 @@ func LoadCkm(w ecs.World) error {
}
}
}
return nil
// 添加车库门PSL
func addCkmPsl(w ecs.World, psl *repository.CkmPsl, ckmEntry *ecs.Entry, data *component.WorldData) {
ckmPsl := component.CkmPsl{
KMA: NewButtonEntity(w, psl.Kma(), data.EntityMap),
GMA: NewButtonEntity(w, psl.Gma(), data.EntityMap),
MPLA: NewButtonEntity(w, psl.Mpla(), data.EntityMap),
MMSA: NewButtonEntity(w, psl.Mmsa(), data.EntityMap),
}
ckmEntry.AddComponent(component.CkmPslType, unsafe.Pointer(&ckmPsl))
}

View File

@ -29,7 +29,7 @@ func LoadPsd(w ecs.World) error {
}
func loadPlatformMkxCircuit(world ecs.World, entryMap map[string]*ecs.Entry, pmcMap map[string]*ecs.Entry,
mkx *repository.Mkx, mkxEntry *ecs.Entry, psdEntry *ecs.Entry) {
mkx *repository.PsdPsl, mkxEntry *ecs.Entry, psdEntry *ecs.Entry) {
platformMkx, ok := pmcMap[mkx.Psd().Id()]
if !ok {
platformMkx = NewPlatformMkxEntry(world, entryMap, mkx)
@ -103,7 +103,7 @@ func NewAsdEntry(world ecs.World, worldData *component.WorldData, psdId string,
return entry
}
func NewMkxEntry(world ecs.World, worldData *component.WorldData, mkx *repository.Mkx) *ecs.Entry {
func NewMkxEntry(world ecs.World, worldData *component.WorldData, mkx *repository.PsdPsl) *ecs.Entry {
entry := world.Entry(world.Create(component.UidType, component.MkxType))
worldData.EntityMap[mkx.Id()] = entry
component.UidType.SetValue(entry, component.Uid{Id: mkx.Id()})
@ -149,7 +149,7 @@ func NewMkxEntry(world ecs.World, worldData *component.WorldData, mkx *repositor
return entry
}
func NewPlatformMkxEntry(world ecs.World, entryMap map[string]*ecs.Entry, mkx *repository.Mkx) *ecs.Entry {
func NewPlatformMkxEntry(world ecs.World, entryMap map[string]*ecs.Entry, mkx *repository.PsdPsl) *ecs.Entry {
entry := world.Entry(world.Create(component.PlatformMkxCircuitType))
circuit := &component.PlatformMkxCircuit{}
if pcbj := mkx.Pcbj(); pcbj != nil {

View File

@ -6,7 +6,7 @@ option go_package = "./component/component_data";
message CkmState {
bool close = 1;
bool mms = 2; //true远程false本地
bool mms = 2; //false远程true本地
bool mgz = 3; //
//

View File

@ -30,6 +30,7 @@ message Repository {
repeated Route routes = 23;
repeated Ckm ckms = 24;
repeated Xcj xcjs = 25;
repeated CkmPsl ckmPsls = 26;
//ISCS [300,500]
//ISCS管线
repeated Pipe pipes = 300;
@ -221,8 +222,9 @@ enum DeviceType {
DeviceType_PowerScreen = 22;
//
DeviceType_Route = 23;
DeviceType_Ckm = 24;
DeviceType_Xcj = 25;
DeviceType_Ckm = 24; //
DeviceType_Xcj = 25; //
DeviceType_CkmPsl = 26; //PSL
//--------ISCS [300,500]------
//ISCS门磁
@ -518,6 +520,16 @@ message Mkx {
string mplaId = 18; //
string jxtcplaId = 19; //
}
//PSL
message CkmPsl {
string id= 1;
string ckmId = 2;
string gmaId = 3; //
string kmaId = 4; //
string mplaId = 5; //
string mmsaId = 6; //
}
//
message Platform {
enum PlatformDirection {

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.32.0
// protoc-gen-go v1.33.0
// protoc v4.23.1
// source: cg_repo.proto

34
repository/ckm_psl.go Normal file
View File

@ -0,0 +1,34 @@
package repository
import "joylink.club/rtsssimulation/repository/model/proto"
type CkmPsl struct {
Identity
ckm *Ckm
kma *Button
gma *Button
mpla *Button
mmsa *Button
}
func NewCkmPsl(id string) *CkmPsl {
return &CkmPsl{
Identity: identity{id, proto.DeviceType_DeviceType_CkmPsl},
}
}
func (psl *CkmPsl) Ckm() *Ckm {
return psl.ckm
}
func (psl *CkmPsl) Kma() *Button {
return psl.kma
}
func (psl *CkmPsl) Gma() *Button {
return psl.gma
}
func (psl *CkmPsl) Mpla() *Button {
return psl.mpla
}
func (psl *CkmPsl) Mmsa() *Button {
return psl.mmsa
}

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ package repository
import "joylink.club/rtsssimulation/repository/model/proto"
type Mkx struct {
type PsdPsl struct {
Identity
psd *Psd
@ -25,8 +25,8 @@ type Mkx struct {
jxtcpl *Button
}
func NewMkx(id string) *Mkx {
return &Mkx{
func NewPsdPsl(id string) *PsdPsl {
return &PsdPsl{
Identity: identity{
id: id,
deviceType: proto.DeviceType_DeviceType_Mkx,
@ -34,74 +34,74 @@ func NewMkx(id string) *Mkx {
}
}
func (m *Mkx) Psd() *Psd {
func (m *PsdPsl) Psd() *Psd {
return m.psd
}
func (m *Mkx) Pcb() *Button {
func (m *PsdPsl) Pcb() *Button {
return m.pcb
}
func (m *Mkx) Pcbpl() *Button {
func (m *PsdPsl) Pcbpl() *Button {
return m.pcbpl
}
func (m *Mkx) Pcbj() *Relay {
func (m *PsdPsl) Pcbj() *Relay {
return m.pcbj
}
func (m *Mkx) Pob() *Button {
func (m *PsdPsl) Pob() *Button {
return m.pob
}
func (m *Mkx) Pobpl() *Button {
func (m *PsdPsl) Pobpl() *Button {
return m.pobpl
}
func (m *Mkx) Pobj() *Relay {
func (m *PsdPsl) Pobj() *Relay {
return m.pobj
}
func (m *Mkx) Pab() *Button {
func (m *PsdPsl) Pab() *Button {
return m.pab
}
func (m *Mkx) Pabpl() *Button {
func (m *PsdPsl) Pabpl() *Button {
return m.pabpl
}
func (m *Mkx) Pabj() *Relay {
func (m *PsdPsl) Pabj() *Relay {
return m.pabj
}
func (m *Mkx) Wrzf() *Button {
func (m *PsdPsl) Wrzf() *Button {
return m.wrzf
}
func (m *Mkx) Wrzfpl() *Button {
func (m *PsdPsl) Wrzfpl() *Button {
return m.wrzfpl
}
func (m *Mkx) Wrzfj() *Relay {
func (m *PsdPsl) Wrzfj() *Relay {
return m.wrzfj
}
func (m *Mkx) Qkqr() *Button {
func (m *PsdPsl) Qkqr() *Button {
return m.qkqr
}
func (m *Mkx) Qkqrpl() *Button {
func (m *PsdPsl) Qkqrpl() *Button {
return m.qkqrpl
}
func (m *Mkx) Qkqrj() *Relay {
func (m *PsdPsl) Qkqrj() *Relay {
return m.qkqrj
}
func (m *Mkx) Mpl() *Button {
func (m *PsdPsl) Mpl() *Button {
return m.mpl
}
func (m *Mkx) Jxtcpl() *Button {
func (m *PsdPsl) Jxtcpl() *Button {
return m.jxtcpl
}

View File

@ -26,13 +26,15 @@ type Repository struct {
lightMap map[string]*Light
alarmMap map[string]*Alarm
stationMap map[string]*Station
mkxMap map[string]*Mkx
psdPslMap map[string]*PsdPsl
keyMap map[string]*Key
linkMap map[string]*Link
platformMap map[string]*Platform
centralizedMap map[string]*proto.CentralizedStationRef
ckmMap map[string]*Ckm
ckmPslMap map[string]*CkmPsl
xcjMap map[string]*Xcj
PipeMap map[string]*Pipe //ISCS 管线
PipeFittingMap map[string]*PipeFitting //ISCS 管件
CircuitBreakerMap map[string]*CircuitBreaker //ISCS 断路器
@ -76,7 +78,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),
psdPslMap: make(map[string]*PsdPsl),
keyMap: make(map[string]*Key),
platformMap: make(map[string]*Platform),
centralizedMap: make(map[string]*proto.CentralizedStationRef),
@ -293,9 +295,9 @@ func (repo *Repository) PsdList() []*Psd {
}
return list
}
func (repo *Repository) MkxList() []*Mkx {
var list []*Mkx
for _, model := range repo.mkxMap {
func (repo *Repository) MkxList() []*PsdPsl {
var list []*PsdPsl
for _, model := range repo.psdPslMap {
list = append(list, model)
}
return list
@ -340,6 +342,14 @@ func (repo *Repository) XcjList() []*Xcj {
return list
}
func (repo *Repository) CkmPslList() []*CkmPsl {
var list []*CkmPsl
for _, model := range repo.ckmPslMap {
list = append(list, model)
}
return list
}
func (repo *Repository) GetCentralizedStationRef(centralizedStationId string) *proto.CentralizedStationRef {
return repo.centralizedMap[centralizedStationId]
}

View File

@ -123,8 +123,8 @@ func buildModels(source *proto.Repository, repository *Repository) error {
repository.alarmMap[m.Id()] = m
}
for _, protoData := range source.Mkxs {
m := NewMkx(protoData.Id)
repository.mkxMap[m.Id()] = m
m := NewPsdPsl(protoData.Id)
repository.psdPslMap[m.Id()] = m
}
for _, protoData := range source.Keys {
m := NewKey(protoData.Id, protoData.Code, protoData.Gear)
@ -142,6 +142,10 @@ func buildModels(source *proto.Repository, repository *Repository) error {
m := NewXcj(protoData.Id)
repository.xcjMap[m.Id()] = m
}
for _, protoData := range source.CkmPsls {
m := NewCkmPsl(protoData.Id)
repository.ckmPslMap[m.Id()] = m
}
err := repository.generateCoordinateInfo(source.MainCoordinateSystem)
if err != nil {
return err
@ -208,9 +212,22 @@ func buildModelRelationship(source *proto.Repository, repository *Repository) er
if err != nil {
return err
}
err = buildCkmPslRelationShip(source, repository)
return err
}
func buildCkmPslRelationShip(source *proto.Repository, repository *Repository) error {
for _, protoData := range source.CkmPsls {
psl := repository.ckmPslMap[protoData.Id]
psl.ckm = repository.ckmMap[protoData.CkmId]
psl.gma = repository.buttonMap[protoData.GmaId]
psl.kma = repository.buttonMap[protoData.KmaId]
psl.mpla = repository.buttonMap[protoData.MplaId]
psl.mmsa = repository.buttonMap[protoData.MmsaId]
}
return nil
}
func buildXcjRelationShip(source *proto.Repository, repo *Repository) error {
for _, protoData := range source.Ckms {
ckm := repo.ckmMap[protoData.Id]
@ -270,7 +287,7 @@ func buildCentralizedStationRelationShip(source *proto.Repository, repo *Reposit
}
func buildMkxRelationShip(source *proto.Repository, repo *Repository) error {
for _, protoData := range source.Mkxs {
mkx := repo.mkxMap[protoData.Id]
mkx := repo.psdPslMap[protoData.Id]
mkx.psd = repo.psdMap[protoData.PsdId]
mkx.pcb = repo.buttonMap[protoData.PcbaId]
mkx.pcbpl = repo.buttonMap[protoData.PcbplaId]

View File

@ -22,10 +22,20 @@ func NewCkmSys() *CkmSys {
func (p *CkmSys) Update(world ecs.World) {
worldData := entity.GetWorldData(world)
p.query.Each(world, func(entry *ecs.Entry) {
//车库门故障(状态丢失)
if entry.HasComponent(component.CkmMgzTag) {
return
}
posCom := component.FixedPositionTransformType.Get(entry)
state := component.CkmStateType.Get(entry)
if entry.HasComponent(component.CkmCircuitType) {
circuit := component.CkmCircuitType.Get(entry)
remote := true //是否远程模式
circuit := component.CkmCircuitType.Get(entry) //目前不考虑没有车库门电路的情况
//车库门PSL
if entry.HasComponent(component.CkmPslType) {
ckmPsl := component.CkmPslType.Get(entry)
component.RelayDriveType.Get(circuit.MPLJ).Td = component.BitStateType.Get(ckmPsl.MPLA).Val
remote = component.BitStateType.Get(ckmPsl.MMSA).Val
}
//门开/关继电器及状态
if posCom.Pos == consts.TwoPosMin {
component.RelayDriveType.Get(circuit.MGJ).Td = true
@ -40,6 +50,7 @@ func (p *CkmSys) Update(world ecs.World) {
component.RelayDriveType.Get(circuit.MGZJ).Td = entry.HasComponent(component.CkmMgzTag)
state.Mgz = entry.HasComponent(component.CkmMgzTag)
//开/关门继电器驱动状态
if remote {
kmBit, err := worldData.QueryQdBit(component.UidType.Get(circuit.KMJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.KMJ).Td = kmBit
@ -52,17 +63,15 @@ func (p *CkmSys) Update(world ecs.World) {
} else {
slog.Error(err.Error())
}
} else {
ckmPsl := component.CkmPslType.Get(entry)
component.RelayDriveType.Get(circuit.KMJ).Td = component.BitStateType.Get(ckmPsl.KMA).Val
component.RelayDriveType.Get(circuit.GMJ).Td = component.BitStateType.Get(ckmPsl.GMA).Val
}
//车库门状态
state.Km = component.BitStateType.Get(circuit.KMJ).Val
state.Gm = component.BitStateType.Get(circuit.GMJ).Val
} else {
if posCom.Pos == consts.TwoPosMin {
state.Close = true
} else {
state.Close = false
}
state.Mgz = entry.HasComponent(component.CkmMgzTag)
}
//驱动
if state.Gm {
posCom.Speed = -component.CalculateTwoPositionAvgSpeed(3*1000, world.Tick())