Documentation ¶
Index ¶
- Constants
- Variables
- type APCI
- type Client
- func (sf *Client) ClockSynchronizationCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, t time.Time) error
- func (sf *Client) Close() error
- func (sf *Client) CounterInterrogationCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, qcc asdu.QualifierCountCall) error
- func (sf *Client) DelayAcquireCommand(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, msec uint16) error
- func (sf *Client) InterrogationCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, ...) error
- func (sf *Client) IsConnected() bool
- func (sf *Client) Params() *asdu.Params
- func (sf *Client) ReadCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, ioa asdu.InfoObjAddr) error
- func (sf *Client) ResetProcessCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, ...) error
- func (sf *Client) Send(a *asdu.ASDU) error
- func (sf *Client) SendStartDt()
- func (sf *Client) SendStopDt()
- func (sf *Client) SetConnectionLostHandler(f func(c *Client)) *Client
- func (sf *Client) SetOnConnectHandler(f func(c *Client)) *Client
- func (sf *Client) Start() error
- func (sf *Client) TestCommand(coa asdu.CauseOfTransmission, ca asdu.CommonAddr) error
- func (sf *Client) UnderlyingConn() net.Conn
- type ClientHandlerInterface
- type ClientOption
- func (sf *ClientOption) AddRemoteServer(server string) error
- func (sf *ClientOption) SetAutoReconnect(b bool) *ClientOption
- func (sf *ClientOption) SetConfig(cfg Config) *ClientOption
- func (sf *ClientOption) SetParams(p *asdu.Params) *ClientOption
- func (sf *ClientOption) SetReconnectInterval(t time.Duration) *ClientOption
- func (sf *ClientOption) SetTLSConfig(t *tls.Config) *ClientOption
- type Config
- type Server
- func (sf *Server) Close() error
- func (sf *Server) ListenAndServer(addr string)
- func (sf *Server) Params() *asdu.Params
- func (sf *Server) Send(a *asdu.ASDU) error
- func (sf *Server) SetConfig(cfg Config) *Server
- func (sf *Server) SetConnectionLostHandler(f func(asdu.Connect))
- func (sf *Server) SetInfoObjTimeZone(zone *time.Location)
- func (sf *Server) SetOnConnectionHandler(f func(asdu.Connect))
- func (sf *Server) SetParams(p *asdu.Params) *Server
- func (sf *Server) UnderlyingConn() net.Conn
- type ServerHandlerInterface
- type ServerSpecial
- type SrvSession
Constants ¶
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 | |
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 )
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
const DefaultReconnectInterval = 1 * time.Minute
DefaultReconnectInterval defined default value
Variables ¶
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 Client ¶
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) 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 ¶
IsConnected get server session connected state
func (*Client) ReadCmd ¶
func (sf *Client) ReadCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, ioa asdu.InfoObjAddr) error
ReadCmd wrap asdu.ReadCmd
func (*Client) ResetProcessCmd ¶
func (sf *Client) ResetProcessCmd(coa asdu.CauseOfTransmission, ca asdu.CommonAddr, qrp asdu.QualifierOfResetProcessCmd) error
ResetProcessCmd wrap asdu.ResetProcessCmd
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 ¶
SetConnectionLostHandler set connection lost handler
func (*Client) SetOnConnectHandler ¶
SetOnConnectHandler set on connect handler
func (*Client) Start ¶
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 ¶
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.
type Server ¶
Server the common server
func NewServer ¶
func NewServer(handler ServerHandlerInterface) *Server
NewServer new a server, default config and default asdu.ParamsWide params
func (*Server) ListenAndServer ¶
ListenAndServer run the server
func (*Server) SetConnectionLostHandler ¶
SetConnectionLostHandler set connect lost handler
func (*Server) SetInfoObjTimeZone ¶
SetInfoObjTimeZone set info object time zone
func (*Server) SetOnConnectionHandler ¶
SetOnConnectionHandler set on connect handler
func (*Server) UnderlyingConn ¶
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 ¶
SrvSession the cs104 server session
func (*SrvSession) IsConnected ¶
func (sf *SrvSession) IsConnected() bool
IsConnected get server session connected state
func (*SrvSession) UnderlyingConn ¶
func (sf *SrvSession) UnderlyingConn() net.Conn
UnderlyingConn got under net.conn