37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
"joylink.club/rtsssimulation/fi"
|
|
)
|
|
|
|
// 继电器操作方法
|
|
func ChangeRelayState(sim *VerifySimulation, mapId int32, id uint32, td bool) error {
|
|
uid := QueryUidByMidAndComId(mapId, id, &data_proto.Relay{})
|
|
if td {
|
|
return fi.DriveRelayUp(sim.World, uid)
|
|
} else {
|
|
return fi.DriveRelayDown(sim.World, uid)
|
|
}
|
|
}
|
|
|
|
// 处理继电器操作
|
|
func HandleRelayOperation(simulation *VerifySimulation, req *request_proto.RelayOperationReq) error {
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.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
|
|
}
|