rts-sim-module/repository/iscs_pscada_yc.go
2023-12-29 17:00:26 +08:00

465 lines
11 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 repository
import (
"fmt"
"joylink.club/rtsssimulation/repository/model/proto"
)
//电力监控系统车站一次图中相关设备模型
// Pipe 管线模型
type Pipe struct {
Identity
Code string
PipeType proto.Pipe_Type
PortA DevicePort //管线的A端连接的设备
PortB DevicePort //管线的B端连接的设备
}
func NewPipe(id string, code string, pipeType proto.Pipe_Type) *Pipe {
return &Pipe{Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_Pipe}, Code: code, PipeType: pipeType}
}
func (p *Pipe) PortNum() int {
return 2
}
// PortDevice 获取管线对应端口连接的设备
func (p *Pipe) PortDevice(port proto.Port) DevicePort {
switch port {
case proto.Port_A:
return p.PortA
case proto.Port_B:
return p.PortB
default:
panic("管线端口只有A或B")
}
}
// PipePort 管线端口
//
// implement DevicePort
type PipePort struct {
port proto.Port
pipe *Pipe
}
func (p *PipePort) Port() proto.Port {
return p.port
}
func (p *PipePort) Device() PortedDevice {
return p.pipe
}
func (p *PipePort) PipePortId() string {
return fmt.Sprintf("%s-%d", p.pipe.Id(), p.port)
}
// ToOtherPort 获取当前管线端口所在管线的另一端
func (p *PipePort) ToOtherPort() PipePort {
switch p.port {
case proto.Port_A:
return PipePort{port: proto.Port_B, pipe: p.pipe}
case proto.Port_B:
return PipePort{port: proto.Port_A, pipe: p.pipe}
default:
panic("管线的端口只能为A或B")
}
}
///////////////////////////////////////////////////
// PipeFitting 管件模型
type PipeFitting struct {
Identity
Code string
portsSum int8 //管件端口数
PortA *PipePort //管件A端口连接的管线
PortB *PipePort //管件B端口连接的管线
PortC *PipePort //管件C端口连接的管线
PortD *PipePort //管件D端口连接的管线
}
func NewPipeFitting(id string, code string, portsSum int8) *PipeFitting {
return &PipeFitting{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_PipeFitting},
Code: code,
portsSum: portsSum,
}
}
func (p *PipeFitting) PortNum() int {
return int(p.portsSum)
}
func (p *PipeFitting) Ports() []*PipePort {
var ports []*PipePort
if p.PortA != nil {
ports = append(ports, p.PortA)
}
if p.PortB != nil {
ports = append(ports, p.PortB)
}
if p.PortC != nil {
ports = append(ports, p.PortC)
}
if p.PortD != nil {
ports = append(ports, p.PortD)
}
return ports
}
// IsEle true-管件为电力管件
func (p *PipeFitting) IsEle() bool {
for _, port := range p.Ports() {
if port.pipe.PipeType != proto.Pipe_ElectricPower {
return false
}
}
return true
}
// PipeFittingPort 管件端口
//
// implement DevicePort
type PipeFittingPort struct {
port proto.Port
pipeFitting *PipeFitting
}
func (p *PipeFittingPort) Port() proto.Port {
return p.port
}
func (p *PipeFittingPort) Device() PortedDevice {
return p.pipeFitting
}
/////////////////////////////////////////////////////////////////////////////
// CircuitBreaker 断路器模型
type CircuitBreaker struct {
Identity
Code string
PortA *PipePort //断路器A端口连接的管线
PortB *PipePort //断路器B端口连接的管线
}
func NewCircuitBreaker(id string, code string) *CircuitBreaker {
return &CircuitBreaker{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_CircuitBreaker},
Code: code,
}
}
func (p *CircuitBreaker) PortNum() int {
return 2
}
// CircuitBreakerPort 断路器端口
//
// implement DevicePort
type CircuitBreakerPort struct {
port proto.Port
breaker *CircuitBreaker
}
func (p *CircuitBreakerPort) Port() proto.Port {
return p.port
}
func (p *CircuitBreakerPort) Device() PortedDevice {
return p.breaker
}
//////////////////////////////////////////////////////////
// ThreePositionSwitch 三工位开关模型
// 有三个连接端口公共连接点A,隔离开关连接点B,接地开关连接点C
type ThreePositionSwitch struct {
Identity
Code string
PortA *PipePort //三工位开关A端口连接的管线
PortB *PipePort //三工位开关B端口连接的管线
PortC *PipePort //三工位开关C端口连接的管线
}
func NewThreePositionSwitch(id string, code string) *ThreePositionSwitch {
return &ThreePositionSwitch{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_ThreePositionSwitch},
Code: code,
}
}
func (p *ThreePositionSwitch) PortNum() int {
return 3
}
// ThreePositionSwitchPort 三工位开关端口
//
// implement DevicePort
type ThreePositionSwitchPort struct {
port proto.Port
breaker *ThreePositionSwitch
}
func (p *ThreePositionSwitchPort) Port() proto.Port {
return p.port
}
func (p *ThreePositionSwitchPort) Device() PortedDevice {
return p.breaker
}
////////////////////////////////////////////////////////
// HandcartSwitch 手车模型
type HandcartSwitch struct {
Identity
Code string
PortA *PipePort //手车A端口连接的管线
PortB *PipePort //手车B端口连接的管线
}
func NewHandcartSwitch(id string, code string) *HandcartSwitch {
return &HandcartSwitch{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_HandcartSwitch},
Code: code,
}
}
func (p *HandcartSwitch) PortNum() int {
return 2
}
// HandcartSwitchPort 手车端口
//
// implement DevicePort
type HandcartSwitchPort struct {
port proto.Port
breaker *HandcartSwitch
}
func (p *HandcartSwitchPort) Port() proto.Port {
return p.port
}
func (p *HandcartSwitchPort) Device() PortedDevice {
return p.breaker
}
////////////////////////////////////////////
// Rectifier 整流器模型
//
// PSCADA中整流器有两个交流输入端分别为A(火线L)和B(零线N);直流输出端口有两个分别为直流正极端口C(+正极)和直流负极端口D(-负极)
type Rectifier struct {
Identity
Code string
PortA *PipePort //整流器A端口连接的管线,交流L(火线)
PortB *PipePort //整流器B端口连接的管线,交流N(零线)
PortC *PipePort //整流器C端口连接的管线,直流+
PortD *PipePort //整流器D端口连接的管线,直流-
}
func NewRectifier(id string, code string) *Rectifier {
return &Rectifier{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_Rectifier},
Code: code,
}
}
func (p *Rectifier) PortNum() int {
return 4
}
// RectifierPort 整流器端口
//
// implement DevicePort
type RectifierPort struct {
port proto.Port
rectifier *Rectifier
}
func (p *RectifierPort) Port() proto.Port {
return p.port
}
func (p *RectifierPort) Device() PortedDevice {
return p.rectifier
}
///////////////////////////////////////////////////////
// Disconnector 隔离开关模型
type Disconnector struct {
Identity
Code string
PortA *PipePort //隔离开关A端口连接的管线
PortB *PipePort //隔离开关B端口连接的管线
}
func NewDisconnector(id string, code string) *Disconnector {
return &Disconnector{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_Disconnector},
Code: code,
}
}
func (p *Disconnector) PortNum() int {
return 2
}
// DisconnectorPort 隔离开关端口
//
// implement DevicePort
type DisconnectorPort struct {
port proto.Port
breaker *Disconnector
}
func (p *DisconnectorPort) Port() proto.Port {
return p.port
}
func (p *DisconnectorPort) Device() PortedDevice {
return p.breaker
}
//////////////////////////////////////////////////////
// VoltageTransformer 变压器模型
// 一次侧端口A,二次侧端口B为L火线端口二次侧端口C如果存在则为N零线端口
// 通过标定电动势计算变压比
type VoltageTransformer struct {
Identity
Code string
E1 uint32 //一次侧标定电动势,单位V
E2 uint32 //二次侧标定电动势,单位V
PortA *PipePort //变压器A端口连接的管线
PortB *PipePort //变压器B端口连接的管线
PortC *PipePort //变压器C端口连接的管线
}
func NewVoltageTransformer(id string, code string, e1 uint32, e2 uint32) *VoltageTransformer {
return &VoltageTransformer{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_VoltageTransformer},
Code: code,
E1: e1,
E2: e2,
}
}
func (p *VoltageTransformer) PortNum() int {
if p.PortC == nil {
return 2
} else {
return 3
}
}
// VoltageTransformerPort 变压器端口
//
// implement DevicePort
type VoltageTransformerPort struct {
port proto.Port
vt *VoltageTransformer
}
func (p *VoltageTransformerPort) Port() proto.Port {
return p.port
}
func (p *VoltageTransformerPort) Device() PortedDevice {
return p.vt
}
//////////////////////////////////////////////////////////
// PowerSource 电源模型
// 只有一个输出端口A
type PowerSource struct {
Identity
Code string
PortA *PipePort //电源A端口连接的管线
Ac bool //true-交流false-直流
Voltage uint32 //电压单位V
}
func NewPowerSource(id string, code string, ac bool, voltage uint32) *PowerSource {
return &PowerSource{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_PowerSource},
Code: code,
Ac: ac,
Voltage: voltage,
}
}
func (p *PowerSource) PortNum() int {
return 1
}
// PowerSourcePort 电源端口
//
// implement DevicePort
type PowerSourcePort struct {
ps *PowerSource
}
func (p *PowerSourcePort) Port() proto.Port {
return proto.Port_A
}
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
}
/////////////////////////////////////////////////
// EarthingDevice 接地装置
type EarthingDevice struct {
Identity
Code string
PortA *PipePort //接地输入端口
}
func NewEarthingDevice(id string, code string) *EarthingDevice {
return &EarthingDevice{
Identity: &identity{id: id, deviceType: proto.DeviceType_DeviceType_EarthingDevice},
Code: code,
}
}
func (p *EarthingDevice) PortNum() int {
return 1
}
// EarthingDevicePort 避雷器端口
//
// implement DevicePort
type EarthingDevicePort struct {
ed *EarthingDevice
}
func (p *EarthingDevicePort) Port() proto.Port {
return proto.Port_A
}
func (p *EarthingDevicePort) Device() PortedDevice {
return p.ed
}