Documentation
¶
Overview ¶
Package gateway bridges two field devices: it polls a source device into a shared core.TagDB and forwards every tag change on to a sink device, turning silk into a protocol gateway (数据转发 / FameView 数据转发). Source and sink points are matched by tag name, so a value read from one device's address is written to the other device's address for the same tag.
This is deliberately NOT driver.Poller's read-write echo case. The Poller suppresses a poll's own tag update so a read never bounces back as a write to the SAME device; the gateway instead forwards every source change on to a DIFFERENT device. Forwarding is one-directional: source -> sink only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway forwards tags read from a source device to a sink device. It composes a driver.Poller (source device -> shared TagDB) with a set of tag subscriptions that write each change out to the sink device.
func NewGateway ¶
func NewGateway(source, sink driver.Driver, srcPoints, sinkPoints []driver.TagPoint, tags *core.TagDB, period time.Duration) *Gateway
NewGateway builds a gateway. The source Poller reads srcPoints from source into tags every period; sinkPoints are indexed by tag name so each source tag is forwarded to the sink point that shares its name (same tag name = a match; the device addresses differ). period is the source read interval.
func (*Gateway) ForwardOnce ¶
func (g *Gateway) ForwardOnce()
ForwardOnce reads every source point once and forwards the changes to the sink synchronously (subscribers fire on the calling goroutine). It wires the forwards on first use, giving tests a deterministic source -> sink path with no poll goroutine and no sleeps.
func (*Gateway) SetOnError ¶
SetOnError registers a hook fired with the tag name and error whenever a forward write to the sink fails. Passing nil disables it. Set it before Start or ForwardOnce; without it a failed forward is only logged.
func (*Gateway) SetOnForward ¶
SetOnForward registers a hook fired with the tag name after each value is written to the sink. Passing nil disables it. Set it before Start or ForwardOnce.