Merge branch 'master' of https://git.code.tencent.com/jl-framework/rtss_simulation
This commit is contained in:
commit
964f697409
@ -9,7 +9,7 @@ import (
|
|||||||
"joylink.club/rtsssimulation/repository/model/proto"
|
"joylink.club/rtsssimulation/repository/model/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 创建继电器实体(有uid)
|
// 创建继电器实体
|
||||||
func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
||||||
uid := relay.Id()
|
uid := relay.Id()
|
||||||
model := proto.Relay_Model_name[int32(relay.Model())]
|
model := proto.Relay_Model_name[int32(relay.Model())]
|
||||||
@ -17,15 +17,15 @@ func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]*
|
|||||||
if !ok {
|
if !ok {
|
||||||
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType)
|
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType)
|
||||||
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||||||
if strings.Contains(model, "Y") {
|
if strings.Contains(model, "Y") { // 有极继电器
|
||||||
entry.AddComponent(component.YjRelayTag)
|
entry.AddComponent(component.YjRelayTag)
|
||||||
} else if strings.Contains(model, "W") {
|
} else if strings.Contains(model, "W") { // 无极继电器
|
||||||
entry.AddComponent(component.WjRelayTag)
|
entry.AddComponent(component.WjRelayTag)
|
||||||
} else if strings.Contains(model, "P") {
|
} else if strings.Contains(model, "P") { // 偏极继电器
|
||||||
entry.AddComponent(component.WjRelayTag)
|
entry.AddComponent(component.WjRelayTag)
|
||||||
entry.AddComponent(component.PjRelayTag)
|
entry.AddComponent(component.PjRelayTag)
|
||||||
}
|
}
|
||||||
if strings.Contains(model, "H") {
|
if strings.Contains(model, "H") { // 缓放继电器
|
||||||
entry.AddComponent(component.HfRelayTag)
|
entry.AddComponent(component.HfRelayTag)
|
||||||
}
|
}
|
||||||
entityMap[uid] = entry
|
entityMap[uid] = entry
|
||||||
|
64
fi/relay.go
Normal file
64
fi/relay.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package fi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 继电器功能接口
|
||||||
|
|
||||||
|
// 控制有极继电器励磁
|
||||||
|
// id - 继电器uid
|
||||||
|
// td - 是否通电励磁
|
||||||
|
// xq - 是否到吸起位置(有极继电器)
|
||||||
|
func driveYjRelay(w ecs.World, entry *ecs.Entry, td bool, xq bool) {
|
||||||
|
rd := component.RelayDriveType.Get(entry)
|
||||||
|
rd.Td = td
|
||||||
|
rd.Xq = xq
|
||||||
|
}
|
||||||
|
|
||||||
|
// 控制无极继电器励磁
|
||||||
|
// id - 继电器uid
|
||||||
|
// td - 是否通电励磁
|
||||||
|
// xq - 是否到吸起位置(有极继电器)
|
||||||
|
func driveWjRelay(w ecs.World, entry *ecs.Entry, td bool) {
|
||||||
|
rd := component.RelayDriveType.Get(entry)
|
||||||
|
rd.Td = td
|
||||||
|
}
|
||||||
|
|
||||||
|
// 驱动继电器到吸起位置
|
||||||
|
func DriveRelayUp(w ecs.World, id string) {
|
||||||
|
w.Execute(func() {
|
||||||
|
wd := entity.GetWorldData(w)
|
||||||
|
entry, ok := wd.EntityMap[id]
|
||||||
|
if ok {
|
||||||
|
if entry.HasComponent(component.YjRelayTag) {
|
||||||
|
driveYjRelay(w, entry, true, true)
|
||||||
|
} else {
|
||||||
|
driveWjRelay(w, entry, true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("未找到id=%s的继电器\n", id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 驱动继电器到落下位置
|
||||||
|
func DriveRelayDown(w ecs.World, id string) {
|
||||||
|
w.Execute(func() {
|
||||||
|
wd := entity.GetWorldData(w)
|
||||||
|
entry, ok := wd.EntityMap[id]
|
||||||
|
if ok {
|
||||||
|
if entry.HasComponent(component.YjRelayTag) {
|
||||||
|
driveYjRelay(w, entry, true, false)
|
||||||
|
} else {
|
||||||
|
driveWjRelay(w, entry, false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("未找到id=%s的继电器\n", id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -10,6 +10,10 @@ import (
|
|||||||
|
|
||||||
// 道岔功能接口
|
// 道岔功能接口
|
||||||
|
|
||||||
|
// 驱动道岔转辙机
|
||||||
|
// id - 道岔uid
|
||||||
|
// dc - 定操/反操
|
||||||
|
// on - 设置/取消
|
||||||
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
|
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
|
||||||
w.Execute(func() {
|
w.Execute(func() {
|
||||||
wd := entity.GetWorldData(w)
|
wd := entity.GetWorldData(w)
|
||||||
@ -46,22 +50,22 @@ func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 驱动道岔转辙机定操启动
|
// 设置道岔转辙机定操
|
||||||
func DriveTurnoutDCOn(w ecs.World, id string) {
|
func DriveTurnoutDCOn(w ecs.World, id string) {
|
||||||
driveTurnoutZzj(w, id, true /* dc */, true /* on */)
|
driveTurnoutZzj(w, id, true /* dc */, true /* on */)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 驱动道岔转辙机定操停止
|
// 取消道岔转辙机定操
|
||||||
func DriveTurnoutDCOff(w ecs.World, id string) {
|
func DriveTurnoutDCOff(w ecs.World, id string) {
|
||||||
driveTurnoutZzj(w, id, true /* dc */, false /* on */)
|
driveTurnoutZzj(w, id, true /* dc */, false /* on */)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 驱动道岔转辙机反操启动
|
// 设置道岔转辙机反操
|
||||||
func DriveTurnoutFCOn(w ecs.World, id string) {
|
func DriveTurnoutFCOn(w ecs.World, id string) {
|
||||||
driveTurnoutZzj(w, id, false /* dc */, true /* on */)
|
driveTurnoutZzj(w, id, false /* dc */, true /* on */)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 驱动道岔转辙机反操停止
|
// 取消道岔转辙机反操
|
||||||
func DriveTurnoutFCOff(w ecs.World, id string) {
|
func DriveTurnoutFCOff(w ecs.World, id string) {
|
||||||
driveTurnoutZzj(w, id, false /* dc */, false /* on */)
|
driveTurnoutZzj(w, id, false /* dc */, false /* on */)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user