【修改IBP实体、电路逻辑】

This commit is contained in:
weizhihong 2023-12-06 16:43:29 +08:00
parent 4861c8c248
commit bf9d0ab624
8 changed files with 182 additions and 306 deletions

View File

@ -77,47 +77,20 @@ type SpkElectronic struct {
// SPK继电器元器件组件 // SPK继电器元器件组件
var SpkElectronicType = ecs.NewComponentType[SpkElectronic]() var SpkElectronicType = ecs.NewComponentType[SpkElectronic]()
// SPK采集电路吸起、落下接通状态 // EMP 电路设备
type SpkCollectState struct { type EmpDeviceElectronic struct {
SPKSX1J_XQ bool EMP_BTNS []*ecs.Entry // 紧急关闭按钮
SPKSX3J_XQ bool EMPFA_BTN *ecs.Entry // 复原按钮
SPKSS2J_XQ bool EMPD *ecs.Entry // 指示灯
SPKSS4J_XQ bool EMPJ *ecs.Entry // 继电器
SPKSXPLA_XQ bool
SPKSSPLA_XQ bool
} }
var SpkCollectStateType = ecs.NewComponentType[SpkCollectState]()
// EMP 电路 // EMP 电路
type EmpElectronic struct { type EmpElectronic struct {
// 控制区 EMPJMap map[string]*EmpDeviceElectronic
EMP1_BTN *ecs.Entry SDA *ecs.Entry // 按钮
EMP3_BTN *ecs.Entry QBA *ecs.Entry // 非自复位按钮
EMP5_BTN *ecs.Entry Alarm *ecs.Entry // 蜂鸣器
EMPX_BTN *ecs.Entry
XEMPFA_BTN *ecs.Entry
EMP2_BTN *ecs.Entry
EMP4_BTN *ecs.Entry
EMP6_BTN *ecs.Entry
EMPS_BTN *ecs.Entry
SEMPFA_BTN *ecs.Entry
// 表示区
XEMPJ *ecs.Entry // 继电器
XEMPD *ecs.Entry
SEMPJ *ecs.Entry // 继电器
SEMPD *ecs.Entry
SDA *ecs.Entry // 按钮
QBA *ecs.Entry // 非自复位按钮
Alarm *ecs.Entry // 蜂鸣器
} }
var EmpElectronicType = ecs.NewComponentType[EmpElectronic]() var EmpElectronicType = ecs.NewComponentType[EmpElectronic]()
// EMP 采集电路吸起、落下接通状态
type EmpCollectState struct {
XEMPJ_XQ bool
SEMPJ_XQ bool
}
var EmpCollectStateType = ecs.NewComponentType[EmpCollectState]()

View File

@ -1,6 +1,9 @@
package entity package entity
import ( import (
"fmt"
"log/slog"
"strings"
"unsafe" "unsafe"
"joylink.club/ecs" "joylink.club/ecs"
@ -75,135 +78,132 @@ func NewIBPKeyEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *
} }
// 构建人员防护实体 // 构建人员防护实体
func LoadSPKEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, worldData *component.WorldData) error { func LoadSPKEntity(w ecs.World, entry *ecs.Entry, datas []repository.IGroupedElectronicComponent, worldData *component.WorldData) error {
if len(datas) == 0 {
return nil
}
entityMap := worldData.EntityMap entityMap := worldData.EntityMap
spk := &component.SpkElectronic{} spk := &component.SpkElectronic{}
// 按钮组 for _, c := range datas {
for _, btn := range spkData.Buttons() { switch c.Code() {
e := NewButtonEntity(w, btn, entityMap) // 按钮组
switch btn.Code() {
case "SPKSXPLA": case "SPKSXPLA":
spk.SPKSXPLA_BTN = e spk.SPKSXPLA_BTN = NewButtonEntity(w, c.(*repository.Button), entityMap)
case "SPKSSPLA": case "SPKSSPLA":
spk.SPKSSPLA_BTN = e spk.SPKSSPLA_BTN = NewButtonEntity(w, c.(*repository.Button), entityMap)
case "SDA": case "SDA":
spk.SDA = e spk.SDA = NewButtonEntity(w, c.(*repository.Button), entityMap)
} // 钥匙组、继电器
}
// 钥匙组
for _, key := range spkData.Keys() {
e := NewIBPKeyEntity(w, key.Id(), entityMap)
switch key.Code() {
case "SPKSX1J": case "SPKSX1J":
spk.SPKSX1J_KEY = e r, ok := c.(*repository.Relay)
if ok {
spk.SPKSX1J = NewRelayEntity(w, r, entityMap)
} else {
spk.SPKSX1J_KEY = NewIBPKeyEntity(w, c.Id(), entityMap)
}
case "SPKSX3J": case "SPKSX3J":
spk.SPKSX3J_KEY = e r, ok := c.(*repository.Relay)
if ok {
spk.SPKSX3J = NewRelayEntity(w, r, entityMap)
} else {
spk.SPKSX3J_KEY = NewIBPKeyEntity(w, c.Id(), entityMap)
}
case "SPKSS2J": case "SPKSS2J":
spk.SPKSS2J_KEY = e r, ok := c.(*repository.Relay)
if ok {
spk.SPKSS2J = NewRelayEntity(w, r, entityMap)
} else {
spk.SPKSS2J_KEY = NewIBPKeyEntity(w, c.Id(), entityMap)
}
case "SPKSS4J": case "SPKSS4J":
spk.SPKSS4J_KEY = e r, ok := c.(*repository.Relay)
} if ok {
} spk.SPKSS4J = NewRelayEntity(w, r, entityMap)
// 继电器组 } else {
for _, relay := range spkData.Relays() { spk.SPKSS4J_KEY = NewIBPKeyEntity(w, c.Id(), entityMap)
e := NewRelayEntity(w, relay, entityMap) }
switch relay.Code() {
case "SPKSX1J":
spk.SPKSX1J = e
case "SPKSX3J":
spk.SPKSX3J = e
case "SPKSS2J":
spk.SPKSS2J = e
case "SPKSS4J":
spk.SPKSS4J = e
case "SPKSXPLAJ": case "SPKSXPLAJ":
spk.SPKSXPLAJ = e spk.SPKSXPLAJ = NewRelayEntity(w, c.(*repository.Relay), entityMap)
case "SPKSSPLAJ": case "SPKSSPLAJ":
spk.SPKSSPLAJ = e spk.SPKSSPLAJ = NewRelayEntity(w, c.(*repository.Relay), entityMap)
} // 灯组
}
// 灯组
for _, light := range spkData.Lights() {
e := NewIBPLightEntity(w, light.Id(), entityMap)
switch light.Code() {
case "SPKSX1D": case "SPKSX1D":
spk.SPKSX1D = e spk.SPKSX1D = NewIBPLightEntity(w, c.Id(), entityMap)
case "SPKSX3D": case "SPKSX3D":
spk.SPKSX3D = e spk.SPKSX3D = NewIBPLightEntity(w, c.Id(), entityMap)
case "SPKSS2D": case "SPKSS2D":
spk.SPKSS2D = e spk.SPKSS2D = NewIBPLightEntity(w, c.Id(), entityMap)
case "SPKSS4D": case "SPKSS4D":
spk.SPKSS4D = e spk.SPKSS4D = NewIBPLightEntity(w, c.Id(), entityMap)
} }
} }
// 绑定组件 // 绑定组件
entry.AddComponent(component.SpkElectronicType, unsafe.Pointer(spk)) entry.AddComponent(component.SpkElectronicType, unsafe.Pointer(spk))
entry.AddComponent(component.SpkCollectStateType, unsafe.Pointer(&component.SpkCollectState{}))
return nil return nil
} }
// 构建紧急关闭实体 // 构建紧急关闭实体
func LoadEMPEntity(w ecs.World, entry *ecs.Entry, spkData *repository.IBPRefMap, worldData *component.WorldData) error { func LoadEMPEntity(w ecs.World, entry *ecs.Entry, datas []*repository.ElectronicComponentGroup, worldData *component.WorldData) error {
if len(datas) == 0 {
return nil
}
entityMap := worldData.EntityMap entityMap := worldData.EntityMap
emp := &component.EmpElectronic{} emp := &component.EmpElectronic{EMPJMap: make(map[string]*component.EmpDeviceElectronic)}
// 按钮组 for _, g := range datas {
for _, btn := range spkData.Buttons() { if g.Code() == "EMP" { // 独立设备
e := NewButtonEntity(w, btn, entityMap) for _, c := range g.Components() {
switch btn.Code() { switch c.Code() {
case "EMP1": case "QBA":
emp.EMP1_BTN = e emp.QBA = NewButtonEntity(w, c.(*repository.Button), entityMap)
case "EMP3": case "SDA":
emp.EMP3_BTN = e emp.SDA = NewButtonEntity(w, c.(*repository.Button), entityMap)
case "EMP5": case "蜂鸣器":
emp.EMP5_BTN = e emp.Alarm = NewAlarmEntity(w, c.(*repository.Alarm), entityMap)
case "EMP2": default:
emp.EMP2_BTN = e r, ok := c.(*repository.Relay)
case "EMP4": if ok { // 如果是继电器
emp.EMP4_BTN = e d := emp.EMPJMap[r.Code()]
case "EMP6": if d == nil {
emp.EMP6_BTN = e d = &component.EmpDeviceElectronic{}
case "EMP-X": }
emp.EMPX_BTN = e d.EMPJ = NewRelayEntity(w, r, entityMap)
case "EMP-S": emp.EMPJMap[r.Code()] = d
emp.EMPS_BTN = e } else {
case "XEMPFA": slog.Warn("车站未实现设备[id:%s]逻辑", c.Id())
emp.XEMPFA_BTN = e }
case "SEMPFA": }
emp.SEMPFA_BTN = e }
case "QBA": } else { // 组合设备
emp.QBA = e d := emp.EMPJMap[g.Code()]
case "SDA": if d == nil {
emp.SDA = e d = &component.EmpDeviceElectronic{}
}
for _, c := range g.Components() {
b, ok := c.(*repository.Button)
if strings.HasSuffix(c.Code(), "EMPD") {
d.EMPD = NewIBPLightEntity(w, c.Id(), entityMap)
} else if ok && strings.HasSuffix(c.Code(), "EMPFA") {
d.EMPFA_BTN = NewButtonEntity(w, b, entityMap)
} else if ok && strings.HasPrefix(c.Code(), "EMP") {
d.EMP_BTNS = append(d.EMP_BTNS, NewButtonEntity(w, b, entityMap))
} else {
slog.Warn("车站未实现设备[id:%s]逻辑", c.Id())
}
}
emp.EMPJMap[g.Code()] = d
} }
} }
// 继电器组 if emp.Alarm == nil || emp.QBA == nil || emp.SDA == nil {
for _, relay := range spkData.Relays() { return fmt.Errorf("车站EMP组合初始化出错,请检查IBP地图组合数据")
e := NewRelayEntity(w, relay, entityMap)
switch relay.Code() {
case "XEMPJ":
emp.XEMPJ = e
case "SEMPJ":
emp.SEMPJ = e
}
} }
// 灯组 for code, e := range emp.EMPJMap {
for _, light := range spkData.Lights() { if e.EMPFA_BTN == nil || e.EMPD == nil || len(e.EMP_BTNS) == 0 {
e := NewIBPLightEntity(w, light.Id(), entityMap) return fmt.Errorf("车站组合[%s]还原按钮未关联,请检查IBP地图组合数据", code)
switch light.Code() { } else if e.EMPJ == nil {
case "XEMPD": return fmt.Errorf("车站组合[%s]还原按钮未关联,请检查继电器地图组合数据", code)
emp.XEMPD = e
case "SEMPD":
emp.SEMPD = e
}
}
// 蜂鸣器
for _, alarm := range spkData.Alarms() {
switch alarm.Code() {
case "蜂鸣器":
emp.Alarm = NewAlarmEntity(w, alarm, entityMap)
} }
} }
entry.AddComponent(component.EmpElectronicType, unsafe.Pointer(emp)) entry.AddComponent(component.EmpElectronicType, unsafe.Pointer(emp))
entry.AddComponent(component.EmpCollectStateType, unsafe.Pointer(&component.EmpCollectState{}))
return nil return nil
} }

View File

@ -22,13 +22,14 @@ func LoadStations(w ecs.World) error {
if err != nil { if err != nil {
return err return err
} }
entry := NewStationEntity(w, station.Id(), data) entry := NewStationEntity(w, station.Id(), data)
if station.GetIbpSpk() != nil { // 人员防护 err = LoadSPKEntity(w, entry, station.SpksComponents(), data) // 人员防护
LoadSPKEntity(w, entry, station.GetIbpSpk(), data) if err != nil {
return err
} }
if station.GetIbpEmp() != nil { // 紧急停车 err = LoadEMPEntity(w, entry, station.EmpGroups(), data) // 紧急停车
LoadEMPEntity(w, entry, station.GetIbpEmp(), data) if err != nil {
return err
} }
} }
return nil return nil

View File

@ -1,91 +0,0 @@
package repository
type IBP struct {
Spk *IBPRefMap
Emp *IBPRefMap
}
func NewIBP() *IBP {
return &IBP{
Spk: newIBPRefMap(),
Emp: newIBPRefMap(),
}
}
type IBPRefMap struct {
buttonMap map[string]*Button
relayMap map[string]*Relay
alarmMap map[string]*Alarm
lightMap map[string]*Light
keyMap map[string]*Key
}
func newIBPRefMap() *IBPRefMap {
return &IBPRefMap{
buttonMap: make(map[string]*Button),
relayMap: make(map[string]*Relay),
alarmMap: make(map[string]*Alarm),
lightMap: make(map[string]*Light),
keyMap: make(map[string]*Key),
}
}
func (ibp *IBPRefMap) AddButton(btn *Button) {
ibp.buttonMap[btn.Id()] = btn
}
func (ibp *IBPRefMap) AddRelay(relay *Relay) {
ibp.relayMap[relay.Id()] = relay
}
func (ibp *IBPRefMap) AddLight(light *Light) {
ibp.lightMap[light.Id()] = light
}
func (ibp *IBPRefMap) AddAlarm(fmq *Alarm) {
ibp.alarmMap[fmq.Id()] = fmq
}
func (ibp *IBPRefMap) AddKey(key *Key) {
ibp.keyMap[key.Id()] = key
}
func (ibp *IBPRefMap) Buttons() []*Button {
var buttons []*Button
for _, b := range ibp.buttonMap {
buttons = append(buttons, b)
}
return buttons
}
func (ibp *IBPRefMap) Relays() []*Relay {
var relays []*Relay
for _, b := range ibp.relayMap {
relays = append(relays, b)
}
return relays
}
func (ibp *IBPRefMap) Alarms() []*Alarm {
var alarms []*Alarm
for _, b := range ibp.alarmMap {
alarms = append(alarms, b)
}
return alarms
}
func (ibp *IBPRefMap) Lights() []*Light {
var lights []*Light
for _, b := range ibp.lightMap {
lights = append(lights, b)
}
return lights
}
func (ibp *IBPRefMap) Keys() []*Key {
var keys []*Key
for _, b := range ibp.keyMap {
keys = append(keys, b)
}
return keys
}

View File

@ -6,6 +6,7 @@ import (
"log/slog" "log/slog"
"math" "math"
"strconv" "strconv"
"strings"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/util/number" "joylink.club/rtsssimulation/util/number"
@ -913,17 +914,18 @@ func buildStationRelationShip(source *proto.Repository, repo *Repository) error
if !ok { if !ok {
return fmt.Errorf("缺失车站[%s]", protoData.Id) return fmt.Errorf("缺失车站[%s]", protoData.Id)
} }
if len(protoData.ElectronicGroup) > 0 { for _, group := range protoData.ElectronicGroup {
for _, ref := range protoData.ElectronicGroup { if group.Code == "SPKS" {
switch ref.Code { station.spksComponents = buildRelComponent(repo, group.Components)
case "EMP": } else if group.Code == "EMP" || strings.HasSuffix(group.Code, "EMPJ") {
bindIbpDevice(repo, ref.Components, station.GetIbpEmp()) station.empGroups = append(station.empGroups, &ElectronicComponentGroup{
case "SPKS": code: group.Code,
bindIbpDevice(repo, ref.Components, station.GetIbpSpk()) components: buildRelComponent(repo, group.Components),
default: })
slog.Warn("未知的车站组合", "组合code", ref.Code) } else {
} slog.Warn("未知的车站组合code", group.Code)
} }
} }
if len(protoData.Deccs) > 0 { // 暂时让逻辑运行起来,后需重构 if len(protoData.Deccs) > 0 { // 暂时让逻辑运行起来,后需重构
station.deviceEcc = protoData.Deccs station.deviceEcc = protoData.Deccs
@ -932,22 +934,23 @@ func buildStationRelationShip(source *proto.Repository, repo *Repository) error
return nil return nil
} }
// 将设备绑入IBP func buildRelComponent(repo *Repository, comps []*proto.ElectronicComponent) []IGroupedElectronicComponent {
func bindIbpDevice(repo *Repository, comps []*proto.ElectronicComponent, refMap *IBPRefMap) { var components []IGroupedElectronicComponent
for _, data := range comps { for _, data := range comps {
switch data.DeviceType { switch data.DeviceType {
case proto.DeviceType_DeviceType_Alarm: case proto.DeviceType_DeviceType_Alarm:
refMap.AddAlarm(repo.alarmMap[data.Id]) components = append(components, repo.alarmMap[data.Id])
case proto.DeviceType_DeviceType_Button: case proto.DeviceType_DeviceType_Button:
refMap.AddButton(repo.buttonMap[data.Id]) components = append(components, repo.buttonMap[data.Id])
case proto.DeviceType_DeviceType_Relay: case proto.DeviceType_DeviceType_Relay:
refMap.AddRelay(repo.relayMap[data.Id]) components = append(components, repo.relayMap[data.Id])
case proto.DeviceType_DeviceType_Light: case proto.DeviceType_DeviceType_Light:
refMap.AddLight(repo.lightMap[data.Id]) components = append(components, repo.lightMap[data.Id])
case proto.DeviceType_DeviceType_Key: case proto.DeviceType_DeviceType_Key:
refMap.AddKey(repo.keyMap[data.Id]) components = append(components, repo.keyMap[data.Id])
default: default:
slog.Warn("IBP未绑定【%s】类型设备", data.DeviceType.String()) slog.Warn("IBP未绑定【%s】类型设备", data.DeviceType.String())
} }
} }
return components
} }

View File

@ -1,20 +1,21 @@
package repository package repository
import "joylink.club/rtsssimulation/repository/model/proto" import (
"joylink.club/rtsssimulation/repository/model/proto"
)
type Station struct { type Station struct {
Identity Identity
code string code string
ibp *IBP empGroups []*ElectronicComponentGroup
componentGroups []*ElectronicComponentGroup spksComponents []IGroupedElectronicComponent
deviceEcc []*proto.DeviceEcc deviceEcc []*proto.DeviceEcc
} }
func NewStation(id, code string) *Station { func NewStation(id, code string) *Station {
return &Station{ return &Station{
Identity: identity{id, proto.DeviceType_DeviceType_Station}, Identity: identity{id, proto.DeviceType_DeviceType_Station},
code: code, code: code,
ibp: NewIBP(),
} }
} }
@ -22,16 +23,23 @@ func (s *Station) GetCode() string {
return s.code return s.code
} }
func (s *Station) GetIbpEmp() *IBPRefMap { func (s *Station) EmpGroups() []*ElectronicComponentGroup {
return s.ibp.Emp return s.empGroups
} }
func (s *Station) GetIbpSpk() *IBPRefMap { func (s *Station) SpksComponents() []IGroupedElectronicComponent {
return s.ibp.Spk return s.spksComponents
} }
func (s *Station) ComponentGroups() []*ElectronicComponentGroup { func (s *Station) SpksButtons() []*Button {
return s.componentGroups var buttons []*Button
for _, c := range s.spksComponents {
b, ok := c.(*Button)
if ok {
buttons = append(buttons, b)
}
}
return buttons
} }
func (s *Station) DeviceEcc() []*proto.DeviceEcc { func (s *Station) DeviceEcc() []*proto.DeviceEcc {

View File

@ -14,10 +14,7 @@ type IBPSys struct {
// ibp盘系统 // ibp盘系统
func NewIBPSys() *IBPSys { func NewIBPSys() *IBPSys {
return &IBPSys{ return &IBPSys{
query: ecs.NewQuery(filter.Contains( query: ecs.NewQuery(filter.Contains(component.SpkElectronicType, component.EmpElectronicType)),
component.SpkElectronicType, component.SpkCollectStateType,
component.EmpElectronicType, component.EmpCollectStateType,
)),
} }
} }
@ -27,11 +24,9 @@ func (ibp *IBPSys) Update(w ecs.World) {
spkState := component.SpkElectronicType.Get(entry) spkState := component.SpkElectronicType.Get(entry)
ibp.spkControl(entry, spkState) ibp.spkControl(entry, spkState)
ibp.spksState(entry, spkState) ibp.spksState(entry, spkState)
ibp.spkCollect(entry, spkState)
empState := component.EmpElectronicType.Get(entry) empState := component.EmpElectronicType.Get(entry)
ibp.empControl(entry, empState) ibp.empControl(entry, empState)
ibp.empState(entry, empState) ibp.empState(entry, empState)
ibp.empCollect(entry, empState)
}) })
} }
@ -76,55 +71,41 @@ func (ibp *IBPSys) spksState(entry *ecs.Entry, spkState *component.SpkElectronic
setLightTdVal(spkState.SPKSS4D, sda || !getRelayXqVal(spkState.SPKSS4J)) setLightTdVal(spkState.SPKSS4D, sda || !getRelayXqVal(spkState.SPKSS4J))
} }
// 人员防护继电器采集电路状态逻辑
func (ibp *IBPSys) spkCollect(entry *ecs.Entry, spkState *component.SpkElectronic) {
collectState := component.SpkCollectStateType.Get(entry)
collectState.SPKSX1J_XQ = getRelayXqVal(spkState.SPKSX1J)
collectState.SPKSX3J_XQ = getRelayXqVal(spkState.SPKSX3J)
collectState.SPKSS2J_XQ = getRelayXqVal(spkState.SPKSS2J)
collectState.SPKSS4J_XQ = getRelayXqVal(spkState.SPKSS4J)
collectState.SPKSXPLA_XQ = getRelayXqVal(spkState.SPKSXPLAJ)
collectState.SPKSSPLA_XQ = getRelayXqVal(spkState.SPKSSPLAJ)
}
// 紧急关闭控制电路 // 紧急关闭控制电路
func (ibp *IBPSys) empControl(entry *ecs.Entry, s *component.EmpElectronic) { func (ibp *IBPSys) empControl(entry *ecs.Entry, s *component.EmpElectronic) {
xempfab := getIbpBtnVal(s.XEMPFA_BTN) for _, e := range s.EMPJMap {
xempj := component.RelayDriveType.Get(s.XEMPJ) empfab := getIbpBtnVal(e.EMPFA_BTN)
// xempfab接通或者按钮组接通并且xempj继电器吸起状态 empj := component.RelayDriveType.Get(e.EMPJ)
xempj.Td = xempfab || (getRelayXqVal(s.XEMPJ) && // empfab接通或者按钮组接通并且empj继电器吸起状态
(!getIbpBtnVal(s.EMP1_BTN)) && (!getIbpBtnVal(s.EMP3_BTN)) && empBtnStatus := true
(!getIbpBtnVal(s.EMP5_BTN)) && (!getIbpBtnVal(s.EMPX_BTN))) for _, b := range e.EMP_BTNS {
sempfab := getIbpBtnVal(s.SEMPFA_BTN) if !empBtnStatus {
sempj := component.RelayDriveType.Get(s.SEMPJ) break
// sempfab接通或者按钮组接通并且sempj继电器吸起状态 }
sempj.Td = sempfab || (getRelayXqVal(s.SEMPJ) && empBtnStatus = !getIbpBtnVal(b)
(!getIbpBtnVal(s.EMP2_BTN)) && (!getIbpBtnVal(s.EMP4_BTN)) && }
(!getIbpBtnVal(s.EMP6_BTN)) && (!getIbpBtnVal(s.EMPS_BTN))) empj.Td = empfab || (getRelayXqVal(e.EMPJ) && empBtnStatus)
}
} }
// 紧急关闭表示电路 // 紧急关闭表示电路
func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) { func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) {
sda := getIbpBtnVal(s.SDA) sda := getIbpBtnVal(s.SDA)
xempj := getRelayXqVal(s.XEMPJ) xq, lx := true, false
setLightTdVal(s.XEMPD, sda || !xempj) for _, e := range s.EMPJMap {
sempj := getRelayXqVal(s.SEMPJ) empj := getRelayXqVal(e.EMPJ)
setLightTdVal(s.SEMPD, sda || !sempj) setLightTdVal(e.EMPD, sda || !empj)
xq = xq && empj
lx = lx || !empj
}
qba := getIbpBtnVal(s.QBA) qba := getIbpBtnVal(s.QBA)
if qba { if qba {
setAlarmTdVal(s.Alarm, xempj && sempj) setAlarmTdVal(s.Alarm, xq)
} else { } else {
setAlarmTdVal(s.Alarm, (!xempj) || (!sempj)) setAlarmTdVal(s.Alarm, lx)
} }
} }
// 紧急关闭继电器采集电路状态逻辑
func (ibp *IBPSys) empCollect(entry *ecs.Entry, s *component.EmpElectronic) {
collectState := component.EmpCollectStateType.Get(entry)
collectState.XEMPJ_XQ = getRelayXqVal(s.XEMPJ)
collectState.SEMPJ_XQ = getRelayXqVal(s.SEMPJ)
}
// 获取按钮状态 // 获取按钮状态
func getIbpBtnVal(entry *ecs.Entry) bool { func getIbpBtnVal(entry *ecs.Entry) bool {
btn := component.BitStateType.Get(entry) btn := component.BitStateType.Get(entry)

View File

@ -1,11 +1,12 @@
package circuit_sys package circuit_sys
import ( import (
"strings"
"joylink.club/ecs" "joylink.club/ecs"
"joylink.club/ecs/filter" "joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/entity"
"strings"
) )
type PsdSys struct { type PsdSys struct {
@ -205,7 +206,7 @@ func (p *PsdSys) exciteMPLJ(world ecs.World, circuit *component.PsdCircuit, uid
} else { } else {
return return
} }
for _, button := range station.GetIbpSpk().Buttons() { for _, button := range station.SpksButtons() {
if button.Code() != buttonCode { if button.Code() != buttonCode {
return return
} }