调整道岔功能接口使用ecs请求接口实现

This commit is contained in:
walker 2023-10-12 14:05:09 +08:00
parent c5cef5eb4e
commit 758d396ad1
2 changed files with 26 additions and 22 deletions

View File

@ -14,23 +14,25 @@ import (
// id - 道岔uid
// dc - 定操/反操
// on - 设置/取消
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
w.Execute(func() {
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.Zdj9TwoElectronicType) { // 有电路,驱动继电器
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
dcj := component.RelayDriveType.Get(zdj9.TDC_DCJ)
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
ycj.Td = on
if entry.HasComponent(component.Zdj9TwoDriveType) { // 有电路,驱动继电器
drive := component.Zdj9TwoDriveType.Get(entry)
if dc {
dcj.Td = on
fcj.Td = !on
drive.YCJ = on
drive.DCJ = on
if on {
drive.FCJ = !on
}
} else {
dcj.Td = !on
fcj.Td = on
drive.YCJ = on
drive.FCJ = on
if on {
drive.DCJ = !on
}
}
} else { // 无电路,直接驱动转辙机
tz := component.TurnoutZzjType.Get(entry)
@ -45,27 +47,29 @@ func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
}
}
} else {
fmt.Println("未找到id=", id, "的道岔")
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的道岔", id))
}
return ecs.NewOkEmptyResult()
})
return result.Err
}
// 设置道岔转辙机定操
func DriveTurnoutDCOn(w ecs.World, id string) {
driveTurnoutZzj(w, id, true /* dc */, true /* on */)
func DriveTurnoutDCOn(w ecs.World, id string) error {
return driveTurnoutZzj(w, id, true /* dc */, true /* on */)
}
// 取消道岔转辙机定操
func DriveTurnoutDCOff(w ecs.World, id string) {
driveTurnoutZzj(w, id, true /* dc */, false /* on */)
func DriveTurnoutDCOff(w ecs.World, id string) error {
return driveTurnoutZzj(w, id, true /* dc */, false /* on */)
}
// 设置道岔转辙机反操
func DriveTurnoutFCOn(w ecs.World, id string) {
driveTurnoutZzj(w, id, false /* dc */, true /* on */)
func DriveTurnoutFCOn(w ecs.World, id string) error {
return driveTurnoutZzj(w, id, false /* dc */, true /* on */)
}
// 取消道岔转辙机反操
func DriveTurnoutFCOff(w ecs.World, id string) {
driveTurnoutZzj(w, id, false /* dc */, false /* on */)
func DriveTurnoutFCOff(w ecs.World, id string) error {
return driveTurnoutZzj(w, id, false /* dc */, false /* on */)
}

@ -1 +1 @@
Subproject commit 74c02116147b7b4e86b56c790c9075e039e6fe82
Subproject commit 37e06d2aaf64828da677131dfb790bd0de7cef56