2024-03-20 14:35:35 +08:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
|
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
|
|
|
appcomponent "joylink.club/bj-rtsts-server/ts/simulation/app_component"
|
|
|
|
"joylink.club/ecs"
|
2024-03-29 16:46:31 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
2024-03-20 14:35:35 +08:00
|
|
|
"joylink.club/rtsssimulation/entity"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CkmOperation(simulation *VerifySimulation, req *request_proto.CkmOperationReq) *sys_error.BusinessError {
|
|
|
|
switch req.Operation {
|
|
|
|
case request_proto.Ckm_SetParams:
|
|
|
|
return setParam(simulation, req)
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("未知的屏蔽门操作:%s", req.Operation))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setParam(simulation *VerifySimulation, req *request_proto.CkmOperationReq) *sys_error.BusinessError {
|
|
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.GarageDoor{})
|
|
|
|
result := <-ecs.Request[ecs.EmptyType](simulation.World, func() ecs.Result[ecs.EmptyType] {
|
|
|
|
wd := entity.GetWorldData(simulation.World)
|
|
|
|
entry, ok := wd.EntityMap[uid]
|
|
|
|
if ok {
|
|
|
|
entry.AddComponent(appcomponent.CkmParamType, unsafe.Pointer(req.Param))
|
2024-04-07 13:38:30 +08:00
|
|
|
//故障
|
2024-03-29 16:46:31 +08:00
|
|
|
if req.Param.Fault == request_proto.Ckm_FA_State_Loss {
|
|
|
|
setRelayStateLoss(entry)
|
|
|
|
} else {
|
|
|
|
clearRelayStateLoss(entry)
|
|
|
|
}
|
2024-04-07 13:38:30 +08:00
|
|
|
//强制
|
|
|
|
switch req.Param.Force {
|
|
|
|
case request_proto.Ckm_F_NONE:
|
|
|
|
entry.RemoveComponent(component.CkmForceCloseTag)
|
|
|
|
entry.RemoveComponent(component.CkmForceOpenTag)
|
|
|
|
case request_proto.Ckm_F_KM:
|
|
|
|
entry.AddComponent(component.CkmForceOpenTag)
|
|
|
|
entry.RemoveComponent(component.CkmForceCloseTag)
|
|
|
|
case request_proto.Ckm_F_GM:
|
|
|
|
entry.AddComponent(component.CkmForceCloseTag)
|
|
|
|
entry.RemoveComponent(component.CkmForceOpenTag)
|
|
|
|
}
|
2024-03-20 14:35:35 +08:00
|
|
|
} else {
|
|
|
|
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的实体", uid))
|
|
|
|
}
|
|
|
|
return ecs.NewOkEmptyResult()
|
|
|
|
})
|
|
|
|
if result.Err != nil {
|
|
|
|
return sys_error.New("车库门设置参数失败", result.Err)
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2024-03-29 16:46:31 +08:00
|
|
|
|
|
|
|
func setRelayStateLoss(entry *ecs.Entry) {
|
|
|
|
if entry.HasComponent(component.CkmCircuitType) {
|
|
|
|
ckmCircuit := component.CkmCircuitType.Get(entry)
|
|
|
|
for _, relayEntry := range ckmCircuit.RelayList() {
|
|
|
|
if relayEntry != nil {
|
|
|
|
relayEntry.AddComponent(appcomponent.RelayStateLossTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func clearRelayStateLoss(entry *ecs.Entry) {
|
|
|
|
if entry.HasComponent(component.CkmCircuitType) {
|
|
|
|
ckmCircuit := component.CkmCircuitType.Get(entry)
|
|
|
|
for _, relayEntry := range ckmCircuit.RelayList() {
|
|
|
|
if relayEntry != nil {
|
|
|
|
relayEntry.RemoveComponent(appcomponent.RelayStateLossTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|