This commit is contained in:
xzb 2023-11-23 16:30:39 +08:00
parent 1d016f6fab
commit 64ef4069be
2 changed files with 55 additions and 8 deletions

View File

@ -56,6 +56,51 @@ func UpdateTrainPositionFromDynamics(w ecs.World, tpi TrainPositionInfo) error {
return result.Err
}
// TrainBalisePowerAmplifierSwitch 车载应答器天线功率放大器开关控制
func TrainBalisePowerAmplifierSwitch(w ecs.World, trainId string, turnOn bool) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
te, find := wd.EntityMap[trainId]
if find {
train := component.TrainBtmType.Get(te)
train.PowerAmplifierSwitch = turnOn
return ecs.NewOkEmptyResult()
} else {
return ecs.NewErrResult(fmt.Errorf("列车[%s]实体不存在", trainId))
}
})
return result.Err
}
// FindTrainBaliseBtmStatus 获取车载BTM的相关状态信息
func FindTrainBaliseBtmStatus(w ecs.World, trainId string) ecs.Result[*TrainBaliseBtmStatus] {
result := <-ecs.Request[*TrainBaliseBtmStatus](w, func() ecs.Result[*TrainBaliseBtmStatus] {
wd := entity.GetWorldData(w)
te, find := wd.EntityMap[trainId]
if find {
btm := component.TrainBtmType.Get(te)
btmStatus := &TrainBaliseBtmStatus{
PowerAmplifierOn: btm.PowerAmplifierSwitch,
PowerAmplifierFault: false,
AboveBalise: btm.AboveBalise,
AntennaFault: false,
}
return ecs.NewOkResult(btmStatus)
} else {
return ecs.NewResult[*TrainBaliseBtmStatus](nil, fmt.Errorf("列车[%s]实体不存在", trainId))
}
})
return result
}
// /////////////////////////////////////////////////////////////////////////////////////////
type TrainBaliseBtmStatus struct {
PowerAmplifierOn bool //BTM功率放大器是否开启
PowerAmplifierFault bool //BTM功率放大器是否有故障
AntennaFault bool //BTM应答器天线是否有故障
AboveBalise bool //BTM当前是否在应答器上方
}
type TrainPositionInfo struct {
//列车id
TrainId string

View File

@ -28,16 +28,18 @@ func (s *BaliseDetectSystem) Update(w ecs.World) {
//所有列车
//列车速度80KM/H时222mm/10ms
s.trainQuery.Each(w, func(entry *ecs.Entry) {
tp := component.TrainPositionInfoType.Get(entry)
btm := component.TrainBtmType.Get(entry)
detectedBalise := s.detect(wd, tp, balises)
//列车应答器天线扫描到应答器,获取应答器报文发送给BTM
tbt := s.findBaliseTelegram(wd, detectedBalise)
var detectedBaliseId string
if detectedBalise != nil {
detectedBaliseId = detectedBalise.Id()
if btm.PowerAmplifierSwitch { //车载应答器天线功率放大器开启
tp := component.TrainPositionInfoType.Get(entry)
detectedBalise := s.detect(wd, tp, balises)
//列车应答器天线扫描到应答器,获取应答器报文发送给BTM
tbt := s.findBaliseTelegram(wd, detectedBalise)
var detectedBaliseId string
if detectedBalise != nil {
detectedBaliseId = detectedBalise.Id()
}
btm.Scanning(detectedBalise != nil, detectedBaliseId, tbt)
}
btm.Scanning(detectedBalise != nil, detectedBaliseId, tbt)
})
}