This commit is contained in:
xzb 2023-10-11 16:58:43 +08:00
commit 1d3d8e0150
7 changed files with 186 additions and 220 deletions

View File

@ -1,28 +0,0 @@
package component
import "joylink.club/ecs"
// 标签
var (
// 非自复式按下接通式按钮
NoResetPressBtn = ecs.NewTag()
// 非自复式拉起接通式按钮
NoResetUpBtn = ecs.NewTag()
// 自复式按下接通式按钮
ResetPressBtn = ecs.NewTag()
// 自复式拉起接通式按钮
ResetUpBtn = ecs.NewTag()
)
// 按钮的实际转台
type ButtonState struct {
Tq bool // 是否抬起(位置信息)
Jt bool // 是否接通(状态信息)
Remain int // 接通保持时间
}
// 实际按钮的实际位置组件类型
var ButtonStateType = ecs.NewComponentType[ButtonState]()

View File

@ -2,6 +2,26 @@ package component
import "joylink.club/ecs"
// 按钮标签
var (
// 非自复式按下接通式按钮
NoResetPressBtn = ecs.NewTag()
// 非自复式拉起接通式按钮
NoResetUpBtn = ecs.NewTag()
// 自复式按下接通式按钮
ResetPressBtn = ecs.NewTag()
// 自复式拉起接通式按钮
ResetUpBtn = ecs.NewTag()
)
// 蜂鸣器驱动
type FMQDrive struct {
Td bool
}
// 蜂鸣器驱动组件
var FMQDriveType = ecs.NewComponentType[FMQDrive]()
// SPK继电器控制电路
type SpkControlElectronic struct {
SPKSXPLA_BTN *ecs.Entry
@ -30,12 +50,12 @@ type SpksStateElectronic struct {
SPKSXPLAJ *ecs.Entry
SPKSSPLAJ *ecs.Entry
SPKSX1D bool
SPKSX3D bool
SPKSS2D bool
SPKSS4D bool
SPKSXPLAD bool
SPKSSPLAD bool
SPKSX1D *ecs.Entry
SPKSX3D *ecs.Entry
SPKSS2D *ecs.Entry
SPKSS4D *ecs.Entry
SPKSXPLAD *ecs.Entry
SPKSSPLAD *ecs.Entry
SDA *ecs.Entry
}
@ -64,16 +84,15 @@ var EmpControlElectronicType = ecs.NewComponentType[EmpControlElectronic]()
// EMP 标识状态电路
type EmpStateElectronic struct {
XEMPJ *ecs.Entry // 继电器
XEMPD bool
XEMPD_SDA *ecs.Entry // 按钮
XEMPJ *ecs.Entry // 继电器
XEMPD *ecs.Entry
SEMPJ *ecs.Entry // 继电器
SEMPD bool
SEMPD_SDA *ecs.Entry // 按钮
SEMPJ *ecs.Entry // 继电器
SEMPD *ecs.Entry
SDA *ecs.Entry // 按钮
QBA *ecs.Entry // 非自复位按钮
FMQ bool // 蜂鸣器
FMQ *ecs.Entry // 蜂鸣器
}
var EmpStateElectronicType = ecs.NewComponentType[EmpStateElectronic]()

@ -1 +1 @@
Subproject commit af605020f1bccf1f1b2ab5a4ae4966d1c6c9776c
Subproject commit e7797346722a572814539d9a453789b89ffe6bf4

View File

@ -1,80 +0,0 @@
package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// emp 继电器控制电路
type EmpControlSys struct {
query *ecs.Query
}
func NewEmpControl() *EmpControlSys {
return &EmpControlSys{
query: ecs.NewQuery(filter.Contains(component.EmpControlElectronicType)),
}
}
// 控制电路更新
func (emp *EmpControlSys) Update(w ecs.World) {
emp.query.Each(w, func(entry *ecs.Entry) {
s := component.EmpControlElectronicType.Get(entry)
xempfab := component.ButtonStateType.Get(s.XEMPFA_BTN)
xempj := component.RelayDriveType.Get(s.XEMPJ)
if xempfab.Jt {
xempj.Td = true
} else {
emp1 := component.ButtonStateType.Get(s.EMP1_BTN)
emp3 := component.ButtonStateType.Get(s.EMP3_BTN)
emp5 := component.ButtonStateType.Get(s.EMP5_BTN)
empx := component.ButtonStateType.Get(s.EMPX_BTN)
xempj.Td = xempj.Td && (emp1.Jt && emp3.Jt && emp5.Jt && empx.Jt)
}
sempfab := component.ButtonStateType.Get(s.SEMPFA_BTN)
sempj := component.RelayDriveType.Get(s.SEMPJ)
if sempfab.Jt {
sempj.Td = true
} else {
emp2 := component.ButtonStateType.Get(s.EMP2_BTN)
emp4 := component.ButtonStateType.Get(s.EMP4_BTN)
emp6 := component.ButtonStateType.Get(s.EMP6_BTN)
emps := component.ButtonStateType.Get(s.EMPS_BTN)
sempj.Td = sempj.Td && (emp2.Jt && emp4.Jt && emp6.Jt && emps.Jt)
}
})
}
// emp 继电器状态电路
type EmpStateSys struct {
query *ecs.Query
}
func NewEmpState() *EmpStateSys {
return &EmpStateSys{
query: ecs.NewQuery(filter.Contains(component.EmpStateElectronicType)),
}
}
// 控制电路更新
func (emp *EmpStateSys) Update(w ecs.World) {
emp.query.Each(w, func(entry *ecs.Entry) {
s := component.EmpStateElectronicType.Get(entry)
xempSda := component.ButtonStateType.Get(s.XEMPD_SDA)
xempj := component.RelayDriveType.Get(s.XEMPJ)
s.XEMPD = xempSda.Jt || !xempj.Xq
sempSda := component.ButtonStateType.Get(s.SEMPD_SDA)
sempj := component.RelayDriveType.Get(s.SEMPJ)
s.SEMPD = sempSda.Jt || !sempj.Xq
qba := component.ButtonStateType.Get(s.QBA)
if qba.Jt {
s.FMQ = xempj.Xq && sempj.Xq
} else {
s.FMQ = (!xempj.Xq) || (!sempj.Xq)
}
})
}

127
sys/circuit_sys/ibp.go Normal file
View File

@ -0,0 +1,127 @@
package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// ibp 系统
type IBPSys struct {
query *ecs.Query
}
// ibp盘系统
func NewIBPSys() *IBPSys {
return &IBPSys{
query: ecs.NewQuery(filter.Contains(
component.SpkControlElectronicType,
component.SpksStateElectronicType,
component.EmpControlElectronicType,
component.EmpStateElectronicType,
)),
}
}
// 控制电路更新
func (ibp *IBPSys) Update(w ecs.World) {
ibp.query.Each(w, func(entry *ecs.Entry) {
ibp.spkControl(entry)
ibp.spksState(entry)
ibp.empControl(entry)
ibp.empState(entry)
})
}
// 人员防护继电器控制电路逻辑
func (ibp *IBPSys) spkControl(entry *ecs.Entry) {
spkState := component.SpkControlElectronicType.Get(entry)
spksxplaBtn := getBtnVal(spkState.SPKSXPLA_BTN)
// spksx1j 通电状态
setRelayTdVal(spkState.SPKSX1J, spksxplaBtn || getBtnVal(spkState.SPKSX1J_BTN))
// spksx3j 通电状态
setRelayTdVal(spkState.SPKSX3J, spksxplaBtn || getBtnVal(spkState.SPKSX3J_BTN))
spkssplaBtn := getBtnVal(spkState.SPKSSPLA_BTN)
// spkss2j 通电状态
setRelayTdVal(spkState.SPKSS2J, spkssplaBtn || getBtnVal(spkState.SPKSS2J_BTN))
// spkss4j 通电状态
setRelayTdVal(spkState.SPKSS4J, spkssplaBtn || getBtnVal(spkState.SPKSS4J_BTN))
}
// 人员防护表示状态电路逻辑
func (ibp *IBPSys) spksState(entry *ecs.Entry) {
spkState := component.SpksStateElectronicType.Get(entry)
sda := getBtnVal(spkState.SDA)
// SPKSXPLAJ
spksxplaj := component.RelayDriveType.Get(spkState.SPKSXPLAJ)
setLightTdVal(spkState.SPKSXPLAD, sda || spksxplaj.Xq)
// SPKSSPLAJ
spkssplaj := component.RelayDriveType.Get(spkState.SPKSSPLAJ)
setLightTdVal(spkState.SPKSSPLAD, sda || spkssplaj.Xq)
// SPKSX1J
spksx1j := component.RelayDriveType.Get(spkState.SPKSX1J)
setLightTdVal(spkState.SPKSX1D, sda || !spksx1j.Xq)
// SPKSX3J
spksx3j := component.RelayDriveType.Get(spkState.SPKSX3J)
setLightTdVal(spkState.SPKSX3D, sda || !spksx3j.Xq)
// SPKSS2J
spkss2j := component.RelayDriveType.Get(spkState.SPKSS2J)
setLightTdVal(spkState.SPKSS2D, sda || !spkss2j.Xq)
// SPKSS4J
spkss4j := component.RelayDriveType.Get(spkState.SPKSS4J)
setLightTdVal(spkState.SPKSS4D, sda || !spkss4j.Xq)
}
// 紧急关闭控制电路
func (ibp *IBPSys) empControl(entry *ecs.Entry) {
s := component.EmpControlElectronicType.Get(entry)
xempfab := getBtnVal(s.XEMPFA_BTN)
xempj := component.RelayDriveType.Get(s.XEMPJ)
// xempfab接通或者按钮组接通并且xempj继电器吸起状态
xempj.Td = xempfab || (xempj.Xq && getBtnVal(s.EMP1_BTN) && getBtnVal(s.EMP3_BTN) && getBtnVal(s.EMP5_BTN) && getBtnVal(s.EMPX_BTN))
sempfab := getBtnVal(s.SEMPFA_BTN)
sempj := component.RelayDriveType.Get(s.SEMPJ)
// sempfab接通或者按钮组接通并且sempj继电器吸起状态
sempj.Td = sempfab || (sempj.Xq && getBtnVal(s.EMP2_BTN) && getBtnVal(s.EMP4_BTN) && getBtnVal(s.EMP6_BTN) && getBtnVal(s.EMPS_BTN))
}
// 紧急关闭表示电路
func (ibp *IBPSys) empState(entry *ecs.Entry) {
s := component.EmpStateElectronicType.Get(entry)
sda := getBtnVal(s.SDA)
xempj := component.RelayDriveType.Get(s.XEMPJ)
setLightTdVal(s.XEMPD, sda || !xempj.Xq)
sempj := component.RelayDriveType.Get(s.SEMPJ)
setLightTdVal(s.SEMPD, sda || !sempj.Xq)
qba := getBtnVal(s.QBA)
if qba {
setFMQTdVal(s.FMQ, xempj.Xq && sempj.Xq)
} else {
setFMQTdVal(s.FMQ, (!xempj.Xq) || (!sempj.Xq))
}
}
// 获取按钮状态
func getBtnVal(entry *ecs.Entry) bool {
btn := component.BitStateType.Get(entry)
return btn.Val
}
// 设置继电器通电状态
func setRelayTdVal(entry *ecs.Entry, val bool) {
relay := component.RelayDriveType.Get(entry)
relay.Td = val
}
// 设置信号灯通电状态
func setLightTdVal(entry *ecs.Entry, val bool) {
light := component.LightDriveType.Get(entry)
light.Td = val
}
// 设置蜂鸣器通电状态
func setFMQTdVal(entry *ecs.Entry, val bool) {
fmq := component.FMQDriveType.Get(entry)
fmq.Td = val
}

View File

@ -1,98 +0,0 @@
package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type SpkControlSys struct {
query *ecs.Query
}
func NewSpkControl() *SpkControlSys {
return &SpkControlSys{
query: ecs.NewQuery(filter.Contains(component.SpkControlElectronicType)),
}
}
// 控制电路更新
func (spk *SpkControlSys) Update(w ecs.World) {
spk.query.Each(w, func(entry *ecs.Entry) {
spkState := component.SpkControlElectronicType.Get(entry)
spksxplaBtn := component.ButtonStateType.Get(spkState.SPKSXPLA_BTN)
spksx1j := component.RelayDriveType.Get(spkState.SPKSX1J)
spksx3j := component.RelayDriveType.Get(spkState.SPKSX3J)
if spksxplaBtn.Jt {
spksx1j.Td = true
spksx3j.Td = true
} else {
spksx1jBtn := component.ButtonStateType.Get(spkState.SPKSX1J_BTN)
spksx3jBtn := component.ButtonStateType.Get(spkState.SPKSX3J_BTN)
spksx1j.Td = spksx1jBtn.Jt
spksx3j.Td = spksx3jBtn.Jt
}
spkssplaBtn := component.ButtonStateType.Get(spkState.SPKSSPLA_BTN)
spkss2j := component.RelayDriveType.Get(spkState.SPKSS2J)
spkss4j := component.RelayDriveType.Get(spkState.SPKSS4J)
if spkssplaBtn.Jt {
spkss2j.Td = true
spkss4j.Td = true
} else {
spkss2jBtn := component.ButtonStateType.Get(spkState.SPKSS2J_BTN)
spkss4jBtn := component.ButtonStateType.Get(spkState.SPKSS4J_BTN)
spkss2j.Td = spkss2jBtn.Jt
spkss4j.Td = spkss4jBtn.Jt
}
})
}
// 人员防护状态系统
type SpksStateSys struct {
query *ecs.Query
}
func NewSpksStateSys() *SpksStateSys {
return &SpksStateSys{
query: ecs.NewQuery(filter.Contains(component.SpksStateElectronicType)),
}
}
// 状态电路更新
func (spk *SpksStateSys) Update(w ecs.World) {
spk.query.Each(w, func(entry *ecs.Entry) {
spkState := component.SpksStateElectronicType.Get(entry)
sda := component.ButtonStateType.Get(spkState.SDA)
// SPKSXPLAJ
spksxplaj := component.RelayDriveType.Get(spkState.SPKSXPLAJ)
spksxplaj.Xq = spksxplaj.Td
spkState.SPKSXPLAD = sda.Jt || spksxplaj.Xq
// SPKSSPLAJ
spkssplaj := component.RelayDriveType.Get(spkState.SPKSSPLAJ)
spkssplaj.Xq = spkssplaj.Td
spkState.SPKSSPLAD = sda.Jt || spkssplaj.Xq
// SPKSX1J
spksx1j := component.RelayDriveType.Get(spkState.SPKSX1J)
spksx1j.Xq = spksx1j.Td || spksxplaj.Xq
spkState.SPKSX1D = sda.Jt || !spksx1j.Xq
// SPKSX3J
spksx3j := component.RelayDriveType.Get(spkState.SPKSX3J)
spksx3j.Xq = spksx3j.Td || spksxplaj.Xq
spkState.SPKSX3D = sda.Jt || spksx3j.Xq
// SPKSS2J
spkss2j := component.RelayDriveType.Get(spkState.SPKSS2J)
spkss2j.Xq = spkss2j.Td || spkssplaj.Xq
spkState.SPKSS2D = sda.Jt || !spkss2j.Xq
// SPKSS4J
spkss4j := component.RelayDriveType.Get(spkState.SPKSS4J)
spkss4j.Xq = spkss4j.Td || spkssplaj.Xq
spkState.SPKSS4D = sda.Jt || !spkss4j.Xq
})
}

26
sys/device_sys/fmq.go Normal file
View File

@ -0,0 +1,26 @@
package device_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// FMQSys 蜂鸣系统
type FMQSys struct {
query *ecs.Query
}
func NewFMQSys() *FMQSys {
return &FMQSys{query: ecs.NewQuery(filter.Contains(component.FMQDriveType, component.BitStateType))}
}
func (fmq *FMQSys) Update(w ecs.World) {
fmq.query.Each(w, func(entry *ecs.Entry) {
drive := component.FMQDriveType.Get(entry)
state := component.BitStateType.Get(entry)
if drive.Td != state.Val {
state.Val = drive.Td
}
})
}