Documentation
¶
Overview ¶
The sl module has been writen as a lightweight replacement for the C libslink library. It is aimed at clients that need to connect and decode data from a seedlink server.
The seedlink code is not a direct replacement for libslink. It can run in two modes, either as a raw connection to the client connection (Conn) which allows mechanisms to monitor or have a finer control of the SeedLink connection, or in the collection mode (SLink) where a connection is established and received miniseed blocks can be processed with a call back function. A context can be passed into the collection loop to allow interuption or as a shutdown mechanism. It is not passed to the underlying seedlink connection messaging which is managed via a deadline mechanism, e.g. the `SetTimeout` option.
An example Seedlink application can be as simple as:
if err := sl.NewSLink().Collect(func(seq string, data []byte) (bool, error) { //... process miniseed data return false, nil }); err != nil { log.Fatal(err) }
A state mechanism is available for the initial connection, although it is the clients responsibility to periodically maintain its content.
Index ¶
- Constants
- type CollectFunc
- type Conn
- func (c *Conn) Collect() (*Packet, error)
- func (c *Conn) CommandCat() ([]byte, error)
- func (c *Conn) CommandClose() ([]byte, error)
- func (c *Conn) CommandData(sequence string, starttime time.Time) error
- func (c *Conn) CommandEnd() error
- func (c *Conn) CommandHello() ([]byte, error)
- func (c *Conn) CommandId() ([]byte, error)
- func (c *Conn) CommandSelect(selection string) error
- func (c *Conn) CommandStation(station, network string) error
- func (c *Conn) CommandTime(starttime, endtime time.Time) error
- func (c *Conn) GetInfo(level string) (*Info, error)
- func (c *Conn) GetInfoLevel(level string) ([]byte, error)
- type Info
- type Packet
- type PacketError
- type SLink
- func (s *SLink) AddState(stations ...Station)
- func (s *SLink) Collect(fn CollectFunc) error
- func (s *SLink) CollectWithContext(ctx context.Context, fn CollectFunc) error
- func (s *SLink) SetEnd(t time.Time)
- func (s *SLink) SetKeepAlive(d time.Duration)
- func (s *SLink) SetNetTo(d time.Duration)
- func (s *SLink) SetSelectors(selectors string)
- func (s *SLink) SetSequence(sequence int)
- func (s *SLink) SetStart(t time.Time)
- func (s *SLink) SetState(stations ...Station)
- func (s *SLink) SetStreams(streams string)
- func (s *SLink) SetTimeout(d time.Duration)
- type SLinkOpt
- func SetEnd(t time.Time) SLinkOpt
- func SetKeepAlive(d time.Duration) SLinkOpt
- func SetNetTo(d time.Duration) SLinkOpt
- func SetSelectors(selectors string) SLinkOpt
- func SetSequence(sequence int) SLinkOpt
- func SetServer(v string) SLinkOpt
- func SetStart(t time.Time) SLinkOpt
- func SetState(stations ...Station) SLinkOpt
- func SetStreams(streams string) SLinkOpt
- func SetStrict(strict bool) SLinkOpt
- func SetTimeout(d time.Duration) SLinkOpt
- type State
- type Station
Constants ¶
const (
PacketSize = 8 + 512
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CollectFunc ¶
CollectFunc is a function run on each returned seedlink packet. It should return a true value to stop collecting data without an error message. A non-nil returned error will also stop collection but with an assumed errored state.
type Conn ¶
func NewConn ¶
NewConn returns a new connection to the named seedlink server with a given command timeout. It is expected that the Close function be called when the connection is no longer required.
func (*Conn) Collect ¶
Collect returns a seedlink packet if available within the optional timout. Any error returned should be checked that it isn't a timeout, this should be handled as appropriate for the request.
func (*Conn) CommandCat ¶
CommandStationList sends a CAT command to the seedlink server.
func (*Conn) CommandClose ¶
CommandClose sends a BYE command to the seedlink server.
func (*Conn) CommandData ¶
CommandData sends a DATA command to the seedlink server.
func (*Conn) CommandEnd ¶
CommandEnd sends an END command to the seedlink server.
func (*Conn) CommandHello ¶
CommandHello sends a HELLO command to the seedlink server.
func (*Conn) CommandSelect ¶
CommandSelect sends a SELECT command to the seedlink server.
func (*Conn) CommandStation ¶
CommandStation sends a STATION command to the seedlink server.
func (*Conn) CommandTime ¶
CommandTime sends a TIME command to the seedlink server.
type Info ¶
type Info struct { XMLName xml.Name `xml:"seedlink"` Software string `xml:"software,attr"` Organization string `xml:"organization,attr"` Started string `xml:"started,attr"` Capability []struct { Name string `xml:"name,attr"` } `xml:"capability"` Station []struct { Name string `xml:"name,attr"` Network string `xml:"network,attr"` Description string `xml:"description,attr"` BeginSeq string `xml:"begin_seq,attr"` EndSeq string `xml:"end_seq,attr"` StreamCheck string `xml:"stream_check,attr"` Stream []struct { Location string `xml:"location,attr"` Seedname string `xml:"seedname,attr"` Type string `xml:"type,attr"` BeginTime string `xml:"begin_time,attr"` EndTime string `xml:"end_time,attr"` } `xml:"stream"` } `xml:"station"` }
type Packet ¶
type PacketError ¶
type PacketError struct {
// contains filtered or unexported fields
}
func NewPacketError ¶
func NewPacketError(message string) *PacketError
func (*PacketError) Error ¶
func (e *PacketError) Error() string
type SLink ¶
type SLink struct { Server string Timeout time.Duration NetTo time.Duration KeepAlive time.Duration Strict bool Start time.Time End time.Time Sequence int Streams string Selectors string State []Station }
SLink is a wrapper around an SLConn to provide handling of timeouts and keep alive messages.
func NewSLink ¶
NewSlink returns a SLink pointer for the given server, optional settings can be passed as SLinkOpt functions.
func (*SLink) Collect ¶
func (s *SLink) Collect(fn CollectFunc) error
Collect calls CollectWithContext with a background Context and a handler function.
func (*SLink) CollectWithContext ¶
func (s *SLink) CollectWithContext(ctx context.Context, fn CollectFunc) error
CollectWithContext makes a connection to the seedlink server, recovers initial client information and the sets the connection into streaming mode. Recovered packets are passed to a given function to process, if this function returns a true value or a non-nil error value the collection will stop and the function will return. If a call returns with a timeout error a check is made whether a keepalive is needed or whether the function should return as no data has been received for an extended period of time. It is assumed the calling function will attempt a reconnection with an updated set of options, specifically any start or end time parameters. The Context parameter can be used to to cancel the data collection independent of the function as this may never be called if no appropriate has been received.
func (*SLink) SetKeepAlive ¶
SetKeepAlive sets the time interval needed without any packets for a check message is sent.
func (*SLink) SetSelectors ¶
SetSelectors sets the channel selectors used for seedlink connections.
func (*SLink) SetSequence ¶
SetSequence sets the start sequence for the initial request.
func (*SLink) SetStreams ¶
SetStreams sets the channel streams used for seedlink connections.
func (*SLink) SetTimeout ¶
SetTimeout sets the timeout value used for connection requests.
type SLinkOpt ¶
type SLinkOpt func(*SLink)
SLinkOpt is a function for setting SLink internal parameters.
func SetKeepAlive ¶
SetKeepAlive sets the time to send an ID message to server if no packets have been received.
func SetNetTo ¶
SetNetTo sets the time to after which the connection is closed after no packets have been received.
func SetSelectors ¶
SetSelectors sets the default list of selectors to use for seedlink stream requests.
func SetSequence ¶
SetSequence sets the start sequence for the initial request.
func SetState ¶
SetState sets the default list of station state information, only used during the initial connection.
func SetStreams ¶
SetStreams sets the list of stations and streams to from the seedlink server.
func SetStrict ¶
SetStrict sets whether a package error should restart the collection system, rather than be skipped.
func SetTimeout ¶
SetTimeout sets the timeout for seedlink server commands and packet requests.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State maintains the current state information for a seedlink connection.
func (*State) Add ¶
Add inserts or updates the station collection details into the connection state.