【IBP操作】

This commit is contained in:
weizhihong 2023-10-12 15:03:11 +08:00
parent ae3495ce62
commit dbb5eaa417
7 changed files with 96 additions and 32 deletions

View File

@ -17,7 +17,7 @@ var (
// 自复式拉起接通式按钮
ResetUpBtn = ecs.NewTag()
// 钥匙旋钮
KeyKnobBtn = ecs.NewTag()
KeyKnob = ecs.NewTag()
)
// 蜂鸣器驱动
@ -32,11 +32,11 @@ var FMQDriveType = ecs.NewComponentType[FMQDrive]()
type SpkElectronic struct {
// 控制区
SPKSXPLA_BTN *ecs.Entry
SPKSX1J_BTN *ecs.Entry
SPKSX3J_BTN *ecs.Entry
SPKSX1J_KEY *ecs.Entry
SPKSX3J_KEY *ecs.Entry
SPKSSPLA_BTN *ecs.Entry
SPKSS2J_BTN *ecs.Entry
SPKSS4J_BTN *ecs.Entry
SPKSS2J_KEY *ecs.Entry
SPKSS4J_KEY *ecs.Entry
// 表示区
SPKSX1J *ecs.Entry

View File

@ -32,7 +32,7 @@ func NewButtonEntity(w ecs.World, data *repository.Button, entityMap map[string]
case proto.Button_Reset_Up:
btnType = component.ResetUpBtn
case proto.Button_Key_Knob:
btnType = component.KeyKnobBtn
btnType = component.KeyKnob
default:
btnType = component.UnknowBtn
}
@ -43,8 +43,7 @@ func NewButtonEntity(w ecs.World, data *repository.Button, entityMap map[string]
}
// 创建蜂鸣器实体
func NewFMQEntity(w ecs.World, data *repository.Fmq, entityMap map[string]*ecs.Entry) *ecs.Entry {
uid := data.Id()
func NewFMQEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
entry, ok := entityMap[uid]
if !ok {
entry = w.Entry(w.Create(component.FMQDriveType, component.BitStateType))
@ -59,11 +58,12 @@ func loadSPKEntity(w ecs.World, entry *ecs.Entry, entityMap map[string]*ecs.Entr
// 按钮组
spk.SPKSXPLA_BTN = NewButtonEntity(w, nil, entityMap)
spk.SPKSSPLA_BTN = NewButtonEntity(w, nil, entityMap)
spk.SPKSX1J_BTN = NewButtonEntity(w, nil, entityMap)
spk.SPKSX3J_BTN = NewButtonEntity(w, nil, entityMap)
spk.SPKSS2J_BTN = NewButtonEntity(w, nil, entityMap)
spk.SPKSS4J_BTN = NewButtonEntity(w, nil, entityMap)
spk.SDA = NewButtonEntity(w, nil, entityMap)
// 钥匙
spk.SPKSX1J_KEY = NewButtonEntity(w, nil, entityMap)
spk.SPKSX3J_KEY = NewButtonEntity(w, nil, entityMap)
spk.SPKSS2J_KEY = NewButtonEntity(w, nil, entityMap)
spk.SPKSS4J_KEY = NewButtonEntity(w, nil, entityMap)
// 继电器组
spk.SPKSX1J = NewRelayEntity(w, nil, entityMap)
spk.SPKSX3J = NewRelayEntity(w, nil, entityMap)
@ -106,7 +106,7 @@ func loadEMPEntity(w ecs.World, entry *ecs.Entry, entityMap map[string]*ecs.Entr
emp.XEMPD = NewLightHEntity(w)
emp.SEMPD = NewLightHEntity(w)
// 蜂鸣器
emp.FMQ = NewFMQEntity(w, nil, entityMap)
emp.FMQ = NewFMQEntity(w, "", entityMap)
entry.AddComponent(component.EmpElectronicType, unsafe.Pointer(emp))
entry.AddComponent(component.EmpCollectStateType, unsafe.Pointer(&component.EmpCollectState{}))
return nil

77
fi/ibp.go Normal file
View File

@ -0,0 +1,77 @@
package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// 按下按钮
func PressDownButton(w ecs.World, id string) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry)
if entry.HasComponent(component.NoResetUpBtn) {
state.Val = false
} else if entry.HasComponent(component.ResetUpBtn) {
state.Val = false
} else {
state.Val = true
}
} else {
fmt.Printf("未找到id=%s的按钮\n", id)
}
})
}
// 抬起拉起按钮
func PressUpButton(w ecs.World, id string) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry)
if entry.HasComponent(component.NoResetUpBtn) {
state.Val = true
} else if entry.HasComponent(component.ResetUpBtn) {
state.Val = true
} else {
state.Val = false
}
} else {
fmt.Printf("未找到id=%s的按钮\n", id)
}
})
}
// 修改钥匙旋钮关闭状态
func PutKeyOff(w ecs.World, id string) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry)
state.Val = false
} else {
fmt.Printf("未找到id=%s的钥匙开关\n", id)
}
})
}
// 修改钥匙旋钮开启状态
func PutKeyOn(w ecs.World, id string) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry)
state.Val = true
} else {
fmt.Printf("未找到id=%s的钥匙开关\n", id)
}
})
}

@ -1 +1 @@
Subproject commit af605020f1bccf1f1b2ab5a4ae4966d1c6c9776c
Subproject commit 37e06d2aaf64828da677131dfb790bd0de7cef56

View File

@ -172,7 +172,7 @@ message ElectronicComponentGroup {
repeated string componentIds = 2; //id
}
//
//
message Button {
enum ButtonType {
Unknown = 0;

View File

@ -1,13 +0,0 @@
package repository
import "joylink.club/rtsssimulation/repository/model/proto"
type Fmq struct {
Identity
}
func NewFmq(id string) *Fmq {
return &Fmq{
Identity: identity{id, proto.DeviceType_DeviceType_FMQ},
}
}

View File

@ -39,14 +39,14 @@ func (ibp *IBPSys) Update(w ecs.World) {
func (ibp *IBPSys) spkControl(entry *ecs.Entry, spkState *component.SpkElectronic) {
spksxplaBtn := getBtnVal(spkState.SPKSXPLA_BTN)
// spksx1j 通电状态
setRelayTdVal(spkState.SPKSX1J, spksxplaBtn || getBtnVal(spkState.SPKSX1J_BTN))
setRelayTdVal(spkState.SPKSX1J, spksxplaBtn || getBtnVal(spkState.SPKSX1J_KEY))
// spksx3j 通电状态
setRelayTdVal(spkState.SPKSX3J, spksxplaBtn || getBtnVal(spkState.SPKSX3J_BTN))
setRelayTdVal(spkState.SPKSX3J, spksxplaBtn || getBtnVal(spkState.SPKSX3J_KEY))
spkssplaBtn := getBtnVal(spkState.SPKSSPLA_BTN)
// spkss2j 通电状态
setRelayTdVal(spkState.SPKSS2J, spkssplaBtn || getBtnVal(spkState.SPKSS2J_BTN))
setRelayTdVal(spkState.SPKSS2J, spkssplaBtn || getBtnVal(spkState.SPKSS2J_KEY))
// spkss4j 通电状态
setRelayTdVal(spkState.SPKSS4J, spkssplaBtn || getBtnVal(spkState.SPKSS4J_BTN))
setRelayTdVal(spkState.SPKSS4J, spkssplaBtn || getBtnVal(spkState.SPKSS4J_KEY))
}
// 人员防护表示状态电路逻辑