rts-sim-testing-service/ts/simulation/wayside/memory/relay_collect.go

56 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package memory
import (
"fmt"
appcomponent "joylink.club/bj-rtsts-server/ts/simulation/app_component"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"log/slog"
)
var ( //保存状态丢失的继电器的最后一次状态
xqStateMap = make(map[string]*bool)
lxStateMap = make(map[string]*bool)
)
// 采集继电器吸起电路状态
func CollectXQCircuitState(w ecs.World, id string) bool {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := component.BitStateType.Get(entry).Val
if entry.HasComponent(appcomponent.RelayStateLossTag) {
if xqStateMap[id] == nil {
xqStateMap[id] = &state
} else {
state = *xqStateMap[id]
}
}
return state
} else {
slog.Error(fmt.Sprintf("采集继电器状态时未找到id=%s的继电器\n", id))
}
return false
}
// 采集继电器落下电路状态
func CollectLXCircuitState(w ecs.World, id string) bool {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
state := !component.BitStateType.Get(entry).Val
if entry.HasComponent(appcomponent.RelayStateLossTag) {
if lxStateMap[id] == nil {
lxStateMap[id] = &state
} else {
state = *lxStateMap[id]
}
}
return state
} else {
slog.Error(fmt.Sprintf("采集继电器状态时未找到id=%s的继电器\n", id))
}
return false
}