Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation into HEAD
This commit is contained in:
commit
365f5a50d9
@ -7,7 +7,7 @@ var MkxTag = ecs.NewTag()
|
||||
var MkxInfoType = ecs.NewComponentType[MkxInfo]()
|
||||
|
||||
type MkxInfo struct {
|
||||
PlatformId string
|
||||
PsdId string
|
||||
}
|
||||
|
||||
var MkxCircuitType = ecs.NewComponentType[MkxCircuit]()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
@ -19,6 +20,9 @@ func LoadMkx(w ecs.World) error {
|
||||
}
|
||||
|
||||
func loadMkxCircuit(world ecs.World, entry *ecs.Entry, mkx *repository.Mkx, entryMap map[string]*ecs.Entry) {
|
||||
if len(mkx.ComponentGroups()) == 0 {
|
||||
return
|
||||
}
|
||||
circuit := &component.MkxCircuit{}
|
||||
for _, group := range mkx.ComponentGroups() {
|
||||
for _, ec := range group.Components() {
|
||||
@ -29,6 +33,8 @@ func loadMkxCircuit(world ecs.World, entry *ecs.Entry, mkx *repository.Mkx, entr
|
||||
circuit.Pobj = NewRelayEntity(world, relay, entryMap)
|
||||
} else if strings.Contains(ec.Code(), "PABJ") {
|
||||
circuit.Pabj = NewRelayEntity(world, relay, entryMap)
|
||||
} else {
|
||||
println(fmt.Sprintf("未知的门控箱继电器[%s]", ec.Id()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,21 +56,23 @@ func loadMkxCircuit(world ecs.World, entry *ecs.Entry, mkx *repository.Mkx, entr
|
||||
func NewMkxEntry(world ecs.World, mkx *repository.Mkx, worldData *component.WorldData) *ecs.Entry {
|
||||
entry, ok := worldData.EntityMap[mkx.Id()]
|
||||
if !ok {
|
||||
entry = world.Entry(world.Create(component.MkxTag, component.UidType, component.MkxInfoType, component.MkxCircuitType))
|
||||
entry = world.Entry(world.Create(component.MkxTag, component.UidType, component.MkxInfoType, component.MkxCircuitType,
|
||||
component.MkxCollectionCircuitType))
|
||||
component.UidType.SetValue(entry, component.Uid{Id: mkx.Id()})
|
||||
component.MkxInfoType.SetValue(entry, component.MkxInfo{PlatformId: mkx.PlatformId()})
|
||||
component.MkxInfoType.SetValue(entry, component.MkxInfo{PsdId: mkx.PsdId()})
|
||||
worldData.EntityMap[mkx.Id()] = entry
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
func NewMkxBox(world ecs.World, btn *repository.Button, entryMap map[string]*ecs.Entry) *ecs.Entry {
|
||||
mplButton := repository.NewButton(btn.Id()+"mpl", "mpl", proto.Button_NO_Reset_Up)
|
||||
mplButton := repository.NewButton(btn.Id()+"mpl", "mpl", proto.Button_NO_Reset_Press)
|
||||
box := &component.MkxBox{
|
||||
Btn: NewButtonEntity(world, btn, entryMap),
|
||||
MkxplBtn: NewButtonEntity(world, mplButton, entryMap),
|
||||
}
|
||||
entry := world.Entry(world.Create(component.MkxBoxType))
|
||||
component.MkxBoxType.Set(entry, box)
|
||||
component.BitStateType.SetValue(box.MkxplBtn, component.BitState{Val: true})
|
||||
return entry
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ func LoadPsd(w ecs.World) error {
|
||||
}
|
||||
|
||||
func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entryMap map[string]*ecs.Entry) {
|
||||
if len(psd.ComponentGroups()) == 0 {
|
||||
return
|
||||
}
|
||||
circuit := &component.PsdCircuit{}
|
||||
for _, group := range psd.ComponentGroups() {
|
||||
for _, ec := range group.Components() {
|
||||
@ -42,7 +45,7 @@ func NewPsdEntry(world ecs.World, psd *repository.Psd, worldData *component.Worl
|
||||
entry, ok := worldData.EntityMap[psd.Id()]
|
||||
if !ok {
|
||||
entry = world.Entry(world.Create(component.PsdTag, component.UidType, component.PsdInfoType, component.PsdStateType,
|
||||
component.PsdCircuitType, component.PsdDriveCircuitType, component.PsdCollectionCircuitType, component.PsdMotorType))
|
||||
component.PsdDriveCircuitType, component.PsdCollectionCircuitType, component.PsdMotorType))
|
||||
component.UidType.SetValue(entry, component.Uid{Id: psd.Id()})
|
||||
component.PsdInfoType.SetValue(entry, component.PsdInfo{PlatformId: psd.PlatformId()})
|
||||
psdMotor := world.Entry(world.Create(component.PsdMotorStateType))
|
||||
|
@ -4,25 +4,25 @@ import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Mkx struct {
|
||||
Identity
|
||||
platformId string
|
||||
psdId string
|
||||
pcbButtons []*Button
|
||||
pobButtons []*Button
|
||||
pabButtons []*Button
|
||||
componentGroups []*ElectronicComponentGroup
|
||||
}
|
||||
|
||||
func NewMkx(id string) *Mkx {
|
||||
func NewMkx(id string, psdId string) *Mkx {
|
||||
return &Mkx{
|
||||
Identity: identity{
|
||||
id: id,
|
||||
deviceType: proto.DeviceType_DeviceType_Mkx,
|
||||
},
|
||||
componentGroups: nil,
|
||||
psdId: psdId,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mkx) PlatformId() string {
|
||||
return m.platformId
|
||||
func (m *Mkx) PsdId() string {
|
||||
return m.psdId
|
||||
}
|
||||
|
||||
func (m *Mkx) PcbButtons() []*Button {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
"joylink.club/rtsssimulation/util/number"
|
||||
)
|
||||
@ -28,14 +27,14 @@ func BuildRepository(source *proto.Repository) (*Repository, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zap.S().Debug("基础模型构建完毕")
|
||||
slog.Info("基础模型构建完毕")
|
||||
err = buildModelRelationship(source, repository)
|
||||
zap.S().Debug("模型关系构建完毕")
|
||||
slog.Info("模型关系构建完毕")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = buildLinksAndRelate(repository)
|
||||
zap.S().Debug("构建Link并与模型关联完毕")
|
||||
slog.Info("构建Link并与模型关联完毕")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -115,7 +114,7 @@ func buildModels(source *proto.Repository, repository *Repository) error {
|
||||
repository.stationMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Mkxs {
|
||||
m := NewMkx(protoData.Id)
|
||||
m := NewMkx(protoData.Id, protoData.PsdId)
|
||||
repository.mkxMap[m.Id()] = m
|
||||
}
|
||||
for _, protoData := range source.Keys {
|
||||
|
@ -27,5 +27,12 @@ func BindSystem(w ecs.World) {
|
||||
circuit_sys.NewSignalJCKXHSystem(),
|
||||
circuit_sys.NewSignalJDXHSystem(),
|
||||
device_sys.NewLightSys(),
|
||||
//屏蔽门
|
||||
circuit_sys.NewPsdSys(),
|
||||
device_sys.NewPsdMotorSys(),
|
||||
//门控箱
|
||||
circuit_sys.NewMkxSys(),
|
||||
//联锁机
|
||||
device_sys.NewInterlockSys(),
|
||||
)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ type MkxSys struct {
|
||||
|
||||
func NewMkxSys() *MkxSys {
|
||||
return &MkxSys{
|
||||
query: ecs.NewQuery(filter.Contains(component.PsdCircuitType, component.PsdDriveCircuitType)),
|
||||
query: ecs.NewQuery(filter.Contains(component.MkxCircuitType, component.MkxCollectionCircuitType)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,25 +21,38 @@ func (p *MkxSys) Update(world ecs.World) {
|
||||
circuit := component.MkxCircuitType.Get(entry)
|
||||
p.exciteRelay(circuit.PcbList, circuit.Pcbj)
|
||||
p.exciteRelay(circuit.PobList, circuit.Pobj)
|
||||
if circuit.Pabj != nil { //北岗子没有PABJ,而是PDBJ,原因未知
|
||||
p.exciteRelay(circuit.PabList, circuit.Pabj)
|
||||
}
|
||||
//联锁采集
|
||||
collectionCircuit := component.MkxCollectionCircuitType.Get(entry)
|
||||
pcb := component.BitStateType.Get(circuit.Pcbj).Val
|
||||
collectionCircuit.Pcb = pcb
|
||||
pob := component.BitStateType.Get(circuit.Pobj).Val
|
||||
collectionCircuit.Pob = pob
|
||||
if circuit.Pabj != nil { //北岗子没有PABJ,而是PDBJ,原因未知
|
||||
pab := component.BitStateType.Get(circuit.Pabj).Val
|
||||
collectionCircuit.Pab = pab
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
for _, entry := range entries {
|
||||
box := component.MkxBoxType.Get(entry)
|
||||
btn := component.BitStateType.Get(box.Btn)
|
||||
mkxplBtn := component.BitStateType.Get(box.MkxplBtn)
|
||||
if btn.Val && mkxplBtn.Val {
|
||||
on = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if on {
|
||||
component.RelayDriveType.Get(relay).Td = true
|
||||
component.BitStateType.Get(relay).Val = true
|
||||
//component.BitStateType.Get(relay).Val = true
|
||||
} else {
|
||||
component.RelayDriveType.Get(relay).Td = false
|
||||
component.BitStateType.Get(relay).Val = false
|
||||
//component.BitStateType.Get(relay).Val = false
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ type PsdSys struct {
|
||||
|
||||
func NewPsdSys() *PsdSys {
|
||||
return &PsdSys{
|
||||
query: ecs.NewQuery(filter.Contains(component.PsdCircuitType, component.PsdDriveCircuitType)),
|
||||
query: ecs.NewQuery(filter.Contains(component.PsdDriveCircuitType, component.PsdMotorType)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,13 +20,17 @@ func (p *PsdSys) Update(world ecs.World) {
|
||||
p.query.Each(world, func(entry *ecs.Entry) {
|
||||
psdMotor := component.PsdMotorType.Get(entry)
|
||||
psdMotorState := component.PsdMotorStateType.Get(psdMotor)
|
||||
psd := component.PsdCircuitType.Get(entry)
|
||||
psdDrive := component.PsdDriveCircuitType.Get(entry)
|
||||
p.exciteByDrive(psd, psdDrive)
|
||||
p.exciteGMJ(psdMotorState, psd, psdDrive)
|
||||
p.exciteKMJ4(psdMotorState, psd, psdDrive)
|
||||
p.exciteKMJ8(psdMotorState, psd, psdDrive)
|
||||
p.exciteMGJ(entry, psdMotorState)
|
||||
if entry.HasComponent(component.PsdCircuitType) { //有屏蔽门电路
|
||||
psdCircuit := component.PsdCircuitType.Get(entry)
|
||||
p.exciteByDrive(psdCircuit, psdDrive)
|
||||
p.exciteGMJ(psdMotorState, psdCircuit, psdDrive)
|
||||
p.exciteKMJ4(psdMotorState, psdCircuit, psdDrive)
|
||||
p.exciteKMJ8(psdMotorState, psdCircuit, psdDrive)
|
||||
p.exciteMGJ(psdCircuit, psdMotorState)
|
||||
} else { //无屏蔽门电路,直接驱动电机
|
||||
p.driveMotor(psdMotorState, psdDrive.GMJ, psdDrive.KMJ4, psdDrive.KMJ8)
|
||||
}
|
||||
p.updatePsdState(entry, psdMotorState)
|
||||
})
|
||||
}
|
||||
@ -46,6 +50,23 @@ func (p *PsdSys) exciteByDrive(psd *component.PsdCircuit, drive *component.PsdDr
|
||||
}
|
||||
}
|
||||
|
||||
// 驱动电机
|
||||
func (p *PsdSys) driveMotor(psdMotorState *component.PsdMotorState, gm, km4, km8 bool) {
|
||||
if gm {
|
||||
psdMotorState.Gm_Td = true
|
||||
psdMotorState.Km4_Td = false
|
||||
psdMotorState.Km8_Td = false
|
||||
} else if km4 {
|
||||
psdMotorState.Gm_Td = false
|
||||
psdMotorState.Km4_Td = true
|
||||
psdMotorState.Km8_Td = false
|
||||
} else if km8 {
|
||||
psdMotorState.Gm_Td = false
|
||||
psdMotorState.Km4_Td = false
|
||||
psdMotorState.Km8_Td = true
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PsdSys) exciteGMJ(state *component.PsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) {
|
||||
gmj := component.BitStateType.Get(psd.GMJ)
|
||||
kmj4 := component.BitStateType.Get(psd.KMJ4)
|
||||
@ -106,8 +127,7 @@ func (p *PsdSys) exciteKMJ8(state *component.PsdMotorState, psd *component.PsdCi
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PsdSys) exciteMGJ(entry *ecs.Entry, state *component.PsdMotorState) {
|
||||
psdCircuit := component.PsdCircuitType.Get(entry)
|
||||
func (p *PsdSys) exciteMGJ(psdCircuit *component.PsdCircuit, state *component.PsdMotorState) {
|
||||
if state.Is4Km() || state.Is8Km() {
|
||||
component.RelayDriveType.Get(psdCircuit.MGJ).Td = false
|
||||
component.BitStateType.Get(psdCircuit.MGJ).Val = false
|
||||
|
@ -13,7 +13,7 @@ type InterlockSys struct {
|
||||
|
||||
func NewInterlockSys() *InterlockSys {
|
||||
return &InterlockSys{
|
||||
psdQuery: ecs.NewQuery(filter.Contains(component.PsdInfoType, component.PsdDriveCircuitType)),
|
||||
psdQuery: ecs.NewQuery(filter.Contains(component.PsdTag, component.UidType, component.PsdDriveCircuitType)),
|
||||
mkxQuery: ecs.NewQuery(filter.Contains(component.MkxInfoType, component.MkxCollectionCircuitType)),
|
||||
}
|
||||
}
|
||||
@ -21,19 +21,18 @@ func NewInterlockSys() *InterlockSys {
|
||||
func (s *InterlockSys) Update(world ecs.World) {
|
||||
psdEntryMap := make(map[string]*ecs.Entry)
|
||||
s.psdQuery.Each(world, func(entry *ecs.Entry) {
|
||||
psdEntryMap[component.PsdInfoType.Get(entry).PlatformId] = entry
|
||||
psdEntryMap[component.UidType.Get(entry).Id] = entry
|
||||
})
|
||||
s.mkxQuery.Each(world, func(entry *ecs.Entry) {
|
||||
mkxState := component.MkxCollectionCircuitType.Get(entry)
|
||||
if mkxState.Pcb {
|
||||
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PlatformId]
|
||||
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PsdId]
|
||||
psdDriveCircuit := component.PsdDriveCircuitType.Get(psdEntry)
|
||||
psdDriveCircuit.GMJ = true
|
||||
psdDriveCircuit.KMJ4 = false
|
||||
psdDriveCircuit.KMJ8 = false
|
||||
}
|
||||
if mkxState.Pob {
|
||||
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PlatformId]
|
||||
} else if mkxState.Pob {
|
||||
psdEntry := psdEntryMap[component.MkxInfoType.Get(entry).PsdId]
|
||||
psdDriveCircuit := component.PsdDriveCircuitType.Get(psdEntry)
|
||||
psdDriveCircuit.GMJ = false
|
||||
psdDriveCircuit.KMJ4 = false
|
||||
|
@ -48,6 +48,9 @@ func gm(psdMotorState *component.PsdMotorState, rate int32) {
|
||||
psdMotorState.Km8_4 = newRate
|
||||
}
|
||||
}
|
||||
if !psdMotorState.Is8Km() && !psdMotorState.Is4Km() {
|
||||
psdMotorState.Gm_Td = false
|
||||
}
|
||||
}
|
||||
|
||||
func km4(psdMotorState *component.PsdMotorState, rate int32) {
|
||||
@ -59,6 +62,9 @@ func km4(psdMotorState *component.PsdMotorState, rate int32) {
|
||||
psdMotorState.Km4 = newRate
|
||||
}
|
||||
}
|
||||
if psdMotorState.Is4Km() || psdMotorState.Is8Km() {
|
||||
psdMotorState.Km4_Td = false
|
||||
}
|
||||
}
|
||||
|
||||
func km8(psdMotorState *component.PsdMotorState, rate int32) {
|
||||
@ -78,4 +84,7 @@ func km8(psdMotorState *component.PsdMotorState, rate int32) {
|
||||
psdMotorState.Km8_4 = newRate
|
||||
}
|
||||
}
|
||||
if psdMotorState.Is8Km() {
|
||||
psdMotorState.Km8_Td = false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user