rts-sim-module/sys/iscs_sys/iscs_fas_smoke_detector.go
2023-12-15 13:34:22 +08:00

61 lines
1.6 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 iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
// SmokeDetectorSystem 烟感
type SmokeDetectorSystem struct {
query *ecs.Query
}
const (
SmokeDensityFireAlarm uint16 = 15
SmokeDensityEarlyWarn uint16 = 10
)
func NewSmokeDetectorSystem() *SmokeDetectorSystem {
return &SmokeDetectorSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.SmokeDetectorType)),
}
}
func (s *SmokeDetectorSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
detector := component.SmokeDetectorType.Get(entry)
detectorId := component.UidType.Get(entry).Id
//例外处理
exception := consts.DeviceExceptionNon
if entry.HasComponent(component.DeviceFaultTag) {
exception = consts.DeviceFault
}
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
exception = consts.DeviceCommunicationInterrupt
}
detector.Exception = exception
//烟感探测所在环境
detector.Density = s.detectSmoke(w, detectorId)
if detector.State != component.StaIsolate {
state := component.StaNormal
//产生烟雾预警信号
if detector.Density >= SmokeDensityEarlyWarn {
state = component.StaEarlyWarn
}
//产生烟雾报警即火警信号
if detector.Density >= SmokeDensityFireAlarm {
state = component.StaFireAlarm
}
//
detector.State = state
}
})
}
// 烟感探测环境烟雾浓度1=0.01%
func (s *SmokeDetectorSystem) detectSmoke(w ecs.World, detectorId string) uint16 {
//todo
return 0
}