cs104

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2022 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APCICtlFiledSize = 4 // control filed(4)

	APDUSizeMax      = 255                                 // start(1) + length(1) + control field(4) + ASDU
	APDUFieldSizeMax = APCICtlFiledSize + asdu.ASDUSizeMax // control field(4) + ASDU
)

APDU form Max size 255

|              APCI                   |       ASDU         |
| start | APDU length | control field |       ASDU         |
                 |          APDU field size(253)           |

bytes| 1 | 1 | 4 | |

View Source
const (
	// Port is the IANA registered port number for unsecure connection.
	Port = 2404

	// PortSecure is the IANA registered port number for secure connection.
	PortSecure = 19998
)
View Source
const (
	// "t₀" 范围[1, 255]s 默认 30s
	ConnectTimeout0Min = 1 * time.Second
	ConnectTimeout0Max = 255 * time.Second

	// "t₁" 范围[1, 255]s 默认 15s. See IEC 60870-5-104, figure 18.
	SendUnAckTimeout1Min = 1 * time.Second
	SendUnAckTimeout1Max = 255 * time.Second

	// "t₂" 范围[1, 255]s 默认 10s, See IEC 60870-5-104, figure 10.
	RecvUnAckTimeout2Min = 1 * time.Second
	RecvUnAckTimeout2Max = 255 * time.Second

	// "t₃" 范围[1 second, 48 hours] 默认 20 s, See IEC 60870-5-104, subclass 5.2.
	IdleTimeout3Min = 1 * time.Second
	IdleTimeout3Max = 48 * time.Hour

	// "k" 范围[1, 32767] 默认 12. See IEC 60870-5-104, subclass 5.5.
	SendUnAckLimitKMin = 1
	SendUnAckLimitKMax = 32767

	// "w" 范围 [1, 32767] 默认 8. See IEC 60870-5-104, subclass 5.5.
	RecvUnAckLimitWMin = 1
	RecvUnAckLimitWMax = 32767
)

defines an IEC 60870-5-104 configuration range

View Source
const DefaultReconnectInterval = 1 * time.Minute

DefaultReconnectInterval defined default value

Variables

View Source
var (
	ErrUseClosedConnection = errors.New("use of closed connection")
	ErrBufferFulled        = errors.New("buffer is full")
	ErrNotActive           = errors.New("server is not active")
)

error defined

Functions

This section is empty.

Types

type APCI

type APCI struct {
	// contains filtered or unexported fields
}

APCI apci 应用规约控制信息

type Client

type Client struct {

	// 其他
	clog.Clog
	// contains filtered or unexported fields
}

Client is an IEC104 master

func NewClient

func NewClient(handler ClientHandlerInterface, o *ClientOption) *Client

NewClient returns an IEC104 master,default config and default asdu.ParamsWide params

func (*Client) ClockSynchronizationCmd

func (sf *Client) ClockSynchronizationCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, t time.Time) error

ClockSynchronizationCmd wrap asdu.ClockSynchronizationCmd

func (*Client) Close

func (sf *Client) Close() error

Close close all

func (*Client) CounterInterrogationCmd

func (sf *Client) CounterInterrogationCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, qcc asdu.QualifierCountCall) error

CounterInterrogationCmd wrap asdu.CounterInterrogationCmd

func (*Client) DelayAcquireCommand

func (sf *Client) DelayAcquireCommand(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, msec uint16) error

DelayAcquireCommand wrap asdu.DelayAcquireCommand

func (*Client) InterrogationCmd

func (sf *Client) InterrogationCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, qoi asdu.QualifierOfInterrogation) error

InterrogationCmd wrap asdu.InterrogationCmd

func (*Client) IsConnected

func (sf *Client) IsConnected() bool

IsConnected get server session connected state

func (*Client) Params

func (sf *Client) Params() *asdu.Params

Params returns params of client

func (*Client) ReadCmd

func (sf *Client) ReadCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, ioa asdu.InfoObjAddr) error

ReadCmd wrap asdu.ReadCmd

func (*Client) ResetProcessCmd

ResetProcessCmd wrap asdu.ResetProcessCmd

func (*Client) Send

func (sf *Client) Send(a *asdu.ASDU) error

Send send asdu

func (*Client) SendStartDt

func (sf *Client) SendStartDt()

SendStartDt start data transmission on this connection

func (*Client) SendStopDt

func (sf *Client) SendStopDt()

SendStopDt stop data transmission on this connection

func (*Client) SetConnectionLostHandler

func (sf *Client) SetConnectionLostHandler(f func(c *Client)) *Client

SetConnectionLostHandler set connection lost handler

func (*Client) SetOnConnectHandler

func (sf *Client) SetOnConnectHandler(f func(c *Client)) *Client

SetOnConnectHandler set on connect handler

func (*Client) Start

func (sf *Client) Start() error

Start start the server,and return quickly,if it nil,the server will disconnected background,other failed

func (*Client) TestCommand

func (sf *Client) TestCommand(coa asdu.CauseOfTransmission, ca asdu.CommonAddr) error

TestCommand wrap asdu.TestCommand

func (*Client) UnderlyingConn

func (sf *Client) UnderlyingConn() net.Conn

UnderlyingConn returns underlying conn of client

type ClientHandlerInterface

type ClientHandlerInterface interface {
	InterrogationHandler(asdu.Connect, *asdu.ASDU) error
	CounterInterrogationHandler(asdu.Connect, *asdu.ASDU) error
	ReadHandler(asdu.Connect, *asdu.ASDU) error
	TestCommandHandler(asdu.Connect, *asdu.ASDU) error
	ClockSyncHandler(asdu.Connect, *asdu.ASDU) error
	ResetProcessHandler(asdu.Connect, *asdu.ASDU) error
	DelayAcquisitionHandler(asdu.Connect, *asdu.ASDU) error
	ASDUHandler(asdu.Connect, *asdu.ASDU) error
}

ClientHandlerInterface is the interface of client handler

type ClientOption

type ClientOption struct {
	TLSConfig *tls.Config // tls配置
	// contains filtered or unexported fields
}

ClientOption 客户端配置

func NewOption

func NewOption() *ClientOption

NewOption with default config and default asdu.ParamsWide params

func (*ClientOption) AddRemoteServer

func (sf *ClientOption) AddRemoteServer(server string) error

AddRemoteServer adds a broker URI to the list of brokers to be used. The format should be scheme://host:port Default values for hostname is "127.0.0.1", for schema is "tcp://". An example broker URI would look like: tcp://foobar.com:1204

func (*ClientOption) SetAutoReconnect

func (sf *ClientOption) SetAutoReconnect(b bool) *ClientOption

SetAutoReconnect enable auto reconnect

func (*ClientOption) SetConfig

func (sf *ClientOption) SetConfig(cfg Config) *ClientOption

SetConfig set config if config is valid it will use DefaultConfig()

func (*ClientOption) SetParams

func (sf *ClientOption) SetParams(p *asdu.Params) *ClientOption

SetParams set asdu params if params is valid it will use asdu.ParamsWide

func (*ClientOption) SetReconnectInterval

func (sf *ClientOption) SetReconnectInterval(t time.Duration) *ClientOption

SetReconnectInterval set tcp reconnect the host interval when connect failed after try

func (*ClientOption) SetTLSConfig

func (sf *ClientOption) SetTLSConfig(t *tls.Config) *ClientOption

SetTLSConfig set tls config

type Config

type Config struct {
	// tcp连接建立的最大超时时间
	// "t₀" 范围[1, 255]s,默认 30s.
	ConnectTimeout0 time.Duration

	// I-frames 发送未收到确认的帧数上限, 一旦达到这个数,将停止传输
	// "k" 范围[1, 32767] 默认 12.
	// See IEC 60870-5-104, subclass 5.5.
	SendUnAckLimitK uint16

	// 帧接收确认最长超时时间,超过此时间立即关闭连接。
	// "t₁" 范围[1, 255]s 默认 15s.
	// See IEC 60870-5-104, figure 18.
	SendUnAckTimeout1 time.Duration

	// 接收端最迟在接收了w次I-frames应用规约数据单元以后发出认可。 w不超过2/3k(2/3 SendUnAckLimitK)
	// "w" 范围 [1, 32767] 默认 8.
	// See IEC 60870-5-104, subclass 5.5.
	RecvUnAckLimitW uint16

	// 发送一个接收确认的最大时间,实际上这个框架1秒内发送回复
	// "t₂" 范围[1, 255]s 默认 10s
	// See IEC 60870-5-104, figure 10.
	RecvUnAckTimeout2 time.Duration

	// 触发 "TESTFR" 保活的空闲时间值,
	// "t₃" 范围[1 second, 48 hours] 默认 20 s
	// See IEC 60870-5-104, subclass 5.2.
	IdleTimeout3 time.Duration
}

Config defines an IEC 60870-5-104 configuration. The default is applied for each unspecified value.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig default config

func (*Config) Valid

func (sf *Config) Valid() error

Valid applies the default (defined by IEC) for each unspecified value.

type Server

type Server struct {
	TLSConfig *tls.Config

	clog.Clog
	// contains filtered or unexported fields
}

Server the common server

func NewServer

func NewServer(handler ServerHandlerInterface) *Server

NewServer new a server, default config and default asdu.ParamsWide params

func (*Server) Close

func (sf *Server) Close() error

Close close the server

func (*Server) ListenAndServer

func (sf *Server) ListenAndServer(addr string)

ListenAndServer run the server

func (*Server) Params

func (sf *Server) Params() *asdu.Params

Params imp interface Connect

func (*Server) Send

func (sf *Server) Send(a *asdu.ASDU) error

Send imp interface Connect

func (*Server) SetConfig

func (sf *Server) SetConfig(cfg Config) *Server

SetConfig set config if config is valid it will use DefaultConfig()

func (*Server) SetConnectionLostHandler

func (sf *Server) SetConnectionLostHandler(f func(asdu.Connect))

SetConnectionLostHandler set connect lost handler

func (*Server) SetInfoObjTimeZone

func (sf *Server) SetInfoObjTimeZone(zone *time.Location)

SetInfoObjTimeZone set info object time zone

func (*Server) SetOnConnectionHandler

func (sf *Server) SetOnConnectionHandler(f func(asdu.Connect))

SetOnConnectionHandler set on connect handler

func (*Server) SetParams

func (sf *Server) SetParams(p *asdu.Params) *Server

SetParams set asdu params if params is valid it will use asdu.ParamsWide

func (*Server) UnderlyingConn

func (sf *Server) UnderlyingConn() net.Conn

UnderlyingConn imp interface Connect

type ServerHandlerInterface

type ServerHandlerInterface interface {
	InterrogationHandler(asdu.Connect, *asdu.ASDU, asdu.QualifierOfInterrogation) error
	CounterInterrogationHandler(asdu.Connect, *asdu.ASDU, asdu.QualifierCountCall) error
	ReadHandler(asdu.Connect, *asdu.ASDU, asdu.InfoObjAddr) error
	ClockSyncHandler(asdu.Connect, *asdu.ASDU, time.Time) error
	ResetProcessHandler(asdu.Connect, *asdu.ASDU, asdu.QualifierOfResetProcessCmd) error
	DelayAcquisitionHandler(asdu.Connect, *asdu.ASDU, uint16) error
	ASDUHandler(asdu.Connect, *asdu.ASDU) error
}

ServerHandlerInterface is the interface of server handler

type ServerSpecial

type ServerSpecial interface {
	asdu.Connect

	IsConnected() bool
	IsClosed() bool
	Start() error
	Close() error

	SetOnConnectHandler(f func(c asdu.Connect))
	SetConnectionLostHandler(f func(c asdu.Connect))

	LogMode(enable bool)
	SetLogProvider(p clog.LogProvider)
}

ServerSpecial server special interface

func NewServerSpecial

func NewServerSpecial(handler ServerHandlerInterface, o *ClientOption) ServerSpecial

NewServerSpecial new special server

type SrvSession

type SrvSession struct {
	clog.Clog
	// contains filtered or unexported fields
}

SrvSession the cs104 server session

func (*SrvSession) IsConnected

func (sf *SrvSession) IsConnected() bool

IsConnected get server session connected state

func (*SrvSession) Params

func (sf *SrvSession) Params() *asdu.Params

Params get params

func (*SrvSession) Send

func (sf *SrvSession) Send(u *asdu.ASDU) error

Send asdu frame

func (*SrvSession) UnderlyingConn

func (sf *SrvSession) UnderlyingConn() net.Conn

UnderlyingConn got under net.conn

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL