iscs pscada 一次图 电力传递实现

This commit is contained in:
xzb 2023-12-22 10:57:43 +08:00
parent 04be5d1bb1
commit 3ba7610c61
7 changed files with 103 additions and 0 deletions

View File

@ -43,6 +43,10 @@ func LoadIscs(w ecs.World) error {
for _, ps := range data.Repo.PowerSourceMap {
NewPowerSourceEntity(w, ps.Id(), ps.Ac, ps.Voltage)
}
//避雷器
for _, la := range data.Repo.LightningArresterMap {
NewLightningArresterEntity(w, la.Id())
}
//
return nil
}

View File

@ -88,6 +88,7 @@ func NewLightningArresterEntity(w ecs.World, id string) *ecs.Entry {
if !ok {
e := w.Entry(w.Create(component.UidType, component.LightningArresterType))
component.UidType.SetValue(e, component.Uid{Id: id})
component.LightningArresterType.Set(e, &component.LightningArrester{Normal: true})
wd.EntityMap[id] = e
}
return e

View File

@ -364,3 +364,38 @@ func (p *PowerSourcePort) Port() proto.Port {
func (p *PowerSourcePort) Device() PortedDevice {
return p.ps
}
///////////////////////////////////////////
// LightningArrester 避雷器模型
type LightningArrester struct {
Identity
Code string
PortA *PipePort //电流从A端口进入
PortB *PipePort //电流从B端口流出然后进入大地
}
func NewLightningArrester(id string, code string) *LightningArrester {
return &LightningArrester{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_LightningArrester},
Code: code,
}
}
func (p *LightningArrester) PortNum() int {
return 2
}
// LightningArresterPort 避雷器端口
//
// implement DevicePort
type LightningArresterPort struct {
port proto.Port
arrester *LightningArrester
}
func (p *LightningArresterPort) Port() proto.Port {
return p.port
}
func (p *LightningArresterPort) Device() PortedDevice {
return p.arrester
}

View File

@ -40,6 +40,7 @@ type Repository struct {
DisconnectorMap map[string]*Disconnector //ISCS 隔离开关
VoltageTransformerMap map[string]*VoltageTransformer //ISCS 变压器
PowerSourceMap map[string]*PowerSource //ISCS 电源
LightningArresterMap map[string]*LightningArrester //ISCS 避雷器
}
func newRepository(id string, version string) *Repository {
@ -75,6 +76,7 @@ func newRepository(id string, version string) *Repository {
DisconnectorMap: make(map[string]*Disconnector), //ISCS 隔离开关
VoltageTransformerMap: make(map[string]*VoltageTransformer), //ISCS 变压器
PowerSourceMap: make(map[string]*PowerSource), //ISCS 电源
LightningArresterMap: make(map[string]*LightningArrester), //ISCS 避雷器
}
}
@ -132,6 +134,9 @@ func (repo *Repository) FindById(id string) Identity {
if md, ok := repo.PowerSourceMap[id]; ok {
return md
}
if md, ok := repo.LightningArresterMap[id]; ok {
return md
}
//ISCS-end
return nil
@ -303,6 +308,8 @@ func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType)
return repo.VoltageTransformerMap[deviceId], nil
case proto.DeviceType_DeviceType_PowerSource:
return repo.PowerSourceMap[deviceId], nil
case proto.DeviceType_DeviceType_LightningArrester:
return repo.LightningArresterMap[deviceId], nil
default:
return nil, fmt.Errorf("仓库中不存在[%s]类型的模型", deviceType)
}

View File

@ -49,6 +49,11 @@ func buildIscsModels(source *proto.Repository, repository *Repository) error {
m := NewPowerSource(protoData.Id, protoData.Code, protoData.Ac, protoData.Voltage)
repository.PowerSourceMap[m.Id()] = m
}
//ISCS避雷器
for _, protoData := range source.LightningArresters {
m := NewLightningArrester(protoData.Id, protoData.Code)
repository.LightningArresterMap[m.Id()] = m
}
//
return nil
}
@ -104,6 +109,17 @@ func buildIscsPipeModelRelationship(source *proto.Repository, repository *Reposi
circuitBreaker.PortB = &PipePort{port: pipePort, pipe: pipeModel}
}
}
case proto.DeviceType_DeviceType_LightningArrester:
{
lightningArrester := relatedDevice.(*LightningArrester)
pipePortRelatedDevice = &LightningArresterPort{port: portRelatedDevice.Port, arrester: lightningArrester}
switch portRelatedDevice.Port {
case proto.Port_A:
lightningArrester.PortA = &PipePort{port: pipePort, pipe: pipeModel}
case proto.Port_B:
lightningArrester.PortB = &PipePort{port: pipePort, pipe: pipeModel}
}
}
case proto.DeviceType_DeviceType_ThreePositionSwitch:
{
tps := relatedDevice.(*ThreePositionSwitch)

View File

@ -55,5 +55,6 @@ func bindIscsSystem(w ecs.World) {
iscs_sys.NewPipeFittingSystem(),
iscs_sys.NewRectifierSystem(),
iscs_sys.NewVoltageTransformerSystem(),
iscs_sys.NewLightningArresterSystem(),
iscs_sys.NewPowerPipeSystem())
}

View File

@ -0,0 +1,39 @@
package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
)
type LightningArresterSystem struct {
query *ecs.Query
}
func NewLightningArresterSystem() *LightningArresterSystem {
return &LightningArresterSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.LightningArresterType)),
}
}
func (s *LightningArresterSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
s.lightningArresterTransPower(wd, entry)
})
}
// 避雷器传递电能
func (s *LightningArresterSystem) lightningArresterTransPower(wd *component.WorldData, entry *ecs.Entry) {
arresterId := component.UidType.Get(entry).Id
closed := true
arresterModel := (wd.Repo.FindById(arresterId)).(*repository.LightningArrester)
//避雷器A端连接的管线
arresterPortA := arresterModel.PortA
//避雷器B端连接的管线
arresterPortB := arresterModel.PortB
//传递电能
towPipePortsTransPower(wd, closed, arresterPortA, arresterPortB)
}