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

37 lines
1.1 KiB
Go
Raw Normal View History

package memory
import (
2024-01-10 11:13:13 +08:00
"fmt"
"joylink.club/bj-rtsts-server/dto/request_proto"
2023-10-26 17:16:07 +08:00
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
2023-10-08 10:35:40 +08:00
"joylink.club/rtsssimulation/fi"
)
2023-10-07 17:48:39 +08:00
// 继电器操作方法
2023-12-14 13:04:48 +08:00
func ChangeRelayState(sim *VerifySimulation, mapId int32, id uint32, td bool) error {
2023-10-07 17:48:39 +08:00
uid := QueryUidByMidAndComId(mapId, id, &graphicData.Relay{})
2023-10-08 10:35:40 +08:00
if td {
return fi.DriveRelayUp(sim.World, uid)
2023-10-08 10:35:40 +08:00
} else {
return fi.DriveRelayDown(sim.World, uid)
2023-10-07 17:48:39 +08:00
}
}
2024-01-10 11:13:13 +08:00
// 处理继电器操作
func HandleRelayOperation(simulation *VerifySimulation, req *request_proto.RelayOperationReq) error {
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Relay{})
var err error
switch req.Operation {
case request_proto.Relay_ForceQw:
err = fi.SetRelayFaultForce(simulation.World, uid, true)
case request_proto.Relay_ForceHw:
err = fi.SetRelayFaultForce(simulation.World, uid, false)
case request_proto.Relay_CancelForce:
err = fi.CancelRelayFaultForce(simulation.World, uid)
default:
panic(fmt.Sprintf("未知的继电器操作:%s", req.Operation))
}
return err
}