136 lines
3.5 KiB
Go
136 lines
3.5 KiB
Go
package component
|
||
|
||
import "joylink.club/ecs"
|
||
|
||
///////////////////////////////////////////
|
||
//组合空调柜AHU-A01 二通阀MOV-A01
|
||
//回排风机RAF-A01 风阀MDD-A03
|
||
//排烟风机SEF-A01 风阀MDD-A04
|
||
//排风阀MDA-A02
|
||
//回风阀MDA-A03
|
||
//小新风阀MDA-A01
|
||
//空调柜MDD-A02
|
||
//防烟防火SFD-A01
|
||
|
||
// PipeMatter 管线中传输的物质类型
|
||
type PipeMatter uint8
|
||
|
||
const (
|
||
PmtNon PipeMatter = iota //未知或没有
|
||
PmtWater
|
||
PmtElectricity //电
|
||
PmtAir //正常空气
|
||
PmtSmoke //含有有害烟的空气(如火灾时的烟气)
|
||
PmtOil //油
|
||
)
|
||
|
||
func (m *PipeMatter) IsNon() bool {
|
||
return *m == PmtNon
|
||
}
|
||
func (m *PipeMatter) IsEle() bool {
|
||
return *m == PmtElectricity
|
||
}
|
||
|
||
// PipeDirection 管线中物质传输方向定义
|
||
type PipeDirection uint8
|
||
|
||
const (
|
||
PdNon PipeDirection = iota //无方向
|
||
PdAb //方向A=>B
|
||
PdBa //方向B=>A
|
||
)
|
||
|
||
func (d *PipeDirection) IsAb() bool {
|
||
return *d == PdAb
|
||
}
|
||
func (d *PipeDirection) IsBa() bool {
|
||
return *d == PdBa
|
||
}
|
||
func (d *PipeDirection) IsNon() bool {
|
||
return *d == PdNon
|
||
}
|
||
|
||
// Pipe 管线一般状态定义
|
||
type Pipe struct {
|
||
Matter PipeMatter //管线中物质类型
|
||
Direction PipeDirection //管线中物质运动方向
|
||
}
|
||
|
||
// PipeElectricity 电线(三相交流,一般单相交流,直流)
|
||
// 如果是三相电,则简化认为每相电压电流一样
|
||
type PipeElectricity struct {
|
||
U uint32 //电压
|
||
I uint32 //电流
|
||
Sx bool //true-三相交流电,此时Ac无效;false-一般单相电,此时Ua Ia Ac有效
|
||
Ac bool //true-交流;false-直流
|
||
Sources map[string]*ElectricitySource //key-电源实体id,value-电源投影
|
||
}
|
||
|
||
func NewPipeElectricity() *PipeElectricity {
|
||
return &PipeElectricity{Sources: make(map[string]*ElectricitySource)}
|
||
}
|
||
func (p *PipeElectricity) FromElectricitySource(es *ElectricitySource) {
|
||
p.U = es.U
|
||
p.Sx = es.Sx
|
||
p.Ac = es.Ac
|
||
}
|
||
func (p *PipeElectricity) TransPower(powerSourceId string, power *ElectricitySource) {
|
||
ep, ok := p.Sources[powerSourceId]
|
||
if ok {
|
||
*ep = *power
|
||
ep.Fresh -= 1
|
||
} else {
|
||
p.Sources[powerSourceId] = &ElectricitySource{}
|
||
*p.Sources[powerSourceId] = *power
|
||
p.Sources[powerSourceId].Fresh -= 1
|
||
}
|
||
}
|
||
|
||
// ElectricitySource 电源(三相交流,一般单相交流,直流)
|
||
type ElectricitySource struct {
|
||
Fresh int64 //该电力值更新的时间戳
|
||
U uint32 //电压
|
||
I uint32 //电流
|
||
Sx bool //true-三相交流电,此时Ac无效;false-一般单相电,此时Ua Ia Ac有效
|
||
Ac bool //true-交流;false-直流
|
||
}
|
||
|
||
func NewElectricitySource() *ElectricitySource {
|
||
return &ElectricitySource{}
|
||
}
|
||
|
||
// SetOut0 设置0输出
|
||
func (s *ElectricitySource) SetOut0() {
|
||
s.U = 0
|
||
s.I = 0
|
||
}
|
||
|
||
// PipeFluid 流体(液体气体)管线
|
||
type PipeFluid struct {
|
||
T float32 //温度
|
||
}
|
||
|
||
func NewPipeFluid() *PipeFluid {
|
||
return &PipeFluid{}
|
||
}
|
||
|
||
var (
|
||
PipeType = ecs.NewComponentType[Pipe]() //电线
|
||
PipeElectricityType = ecs.NewComponentType[PipeElectricity]() //电线电力
|
||
PipeFluidType = ecs.NewComponentType[PipeFluid]() //管线流体
|
||
|
||
ElectricitySourceType = ecs.NewComponentType[ElectricitySource]() //电源
|
||
|
||
)
|
||
|
||
/////////////////////////////////////////////////////////////////////////
|
||
|
||
// FluidDriver 流体驱动器
|
||
type FluidDriver struct {
|
||
On bool //true-输出流体驱动力;false-未输出流体驱动力
|
||
}
|
||
|
||
var (
|
||
FluidDriverType = ecs.NewComponentType[FluidDriver]() //流体驱动器
|
||
)
|