gateway

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 4 Imported by: 0

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

func (g *Gateway) SetOnError(fn func(tag string, err error))

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

func (g *Gateway) SetOnForward(fn func(tag string))

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.

func (*Gateway) Start

func (g *Gateway) Start() error

Start connects the sink, wires the forwards and starts the source Poller. It returns any sink-connect or source-start error; on a source failure the sink is closed again so Start never leaves the gateway half-open.

func (*Gateway) Stop

func (g *Gateway) Stop()

Stop halts the source Poller (which closes the source device), cancels the forward subscriptions and closes the sink device. Safe to call once.

Jump to

Keyboard shortcuts

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