concentrator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package concentrator is a DLMS/COSEM data concentrator (DCU): the head end reaches it over the wrapper on TCP, and it serves two modes at once.

Gateway mode (IEC 62056-5-3:2023 annex C): a request carrying the gateway prefix (header E6, network ID, physical device address) goes to the end device at that network and address, and its answer comes back with the prefix (header E7). The prefix is outside the application layer's protection, so associations and security stay end to end between the head end and each meter. Meters' pushes are forwarded to the head end with the prefix.

Logical-device mode: a request without the prefix goes to the logical device at the server SAP (wPort) the head end addressed, as with a concentrator that presents its meters, or its own management device, as logical devices of one physical device (IEC 62056-6-2 logical devices).

End devices and logical devices are Downstream: a server of package server in the same process (Local), any gosem transport to a meter on the concentrator's local network (Transport: HDLC on a serial bus or through a converter, the wrapper to IP meters, NB-IoT), or anything else that answers APDUs. Each head-end connection keeps a session per meter, client SAP and server SAP, and every session runs on its own, so a slow meter does not hold the others up.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnreachable = errors.New("the end device is not reachable")

ErrUnreachable is returned by a Downstream the local network cannot reach now.

Functions

This section is empty.

Types

type Concentrator

type Concentrator struct {
	// Meters are the end devices behind the gateway (Add and Remove change
	// them while serving).
	Meters []Meter
	// Logical are the logical devices by server SAP, served to requests
	// without the prefix.
	Logical map[uint16]Downstream
	// ResponsePrefix, when set, gives the prefix of an answer from the
	// request's (default: header E7 with the request's network and
	// address). Some concentrators put their own address there.
	ResponsePrefix func(request gateway.Prefix) gateway.Prefix
	// PushHeader is the header of forwarded pushes: gateway.Request (E6,
	// the default, as annex C has it for data-notifications) or
	// gateway.Response (E7, which some concentrators send).
	PushHeader byte
	// Strict drops requests without the prefix for a server SAP that has
	// no logical device. By default such a request goes to the meter the
	// same client and server SAPs last reached with the prefix on that
	// connection: some clients prefix the AARQ but not the ciphered APDUs
	// after it.
	Strict bool
	// Logf, when set, receives events.
	Logf func(format string, args ...any)
	// contains filtered or unexported fields
}

Concentrator is a data concentrator. Set the fields, then Listen or Serve.

func (*Concentrator) Add

func (c *Concentrator) Add(m Meter)

Add puts a meter behind the gateway (one at the same network and address is replaced).

func (*Concentrator) Close

func (c *Concentrator) Close() error

Close stops listening, drops the head end's connections and closes the sessions with downstream devices.

func (*Concentrator) Forward

func (c *Concentrator) Forward(network byte, address []byte, client uint16, apdu []byte) error

Forward sends a meter's push (a data-notification APDU, protected as the meter protected it) to the head end on every open connection, with the prefix of the meter's network and address, from the management device SAP to the client SAP the push setup names.

func (*Concentrator) ForwardTo

func (c *Concentrator) ForwardTo(addr string, network byte, address []byte, client uint16, apdu []byte) error

ForwardTo sends a meter's push to the head end's push listener at addr over TCP, for a concentrator that knows where the head end listens.

func (*Concentrator) Listen

func (c *Concentrator) Listen(addr string) (string, error)

Listen serves the head end over the wrapper on TCP at addr until Close, and returns the address listened on.

func (*Concentrator) Remove

func (c *Concentrator) Remove(network byte, address []byte)

Remove takes a meter away.

func (*Concentrator) Serve

func (c *Concentrator) Serve(rw io.ReadWriter) error

Serve answers the head end on one connection (TCP, or a stream someone else opened) until it ends.

func (*Concentrator) Stats

func (c *Concentrator) Stats() Stats

Stats returns the counters so far.

type Downstream

type Downstream interface {
	// Open starts a session for a client SAP and the server SAP the head
	// end addressed. An error drops the requests (the head end times out),
	// as for a meter the local network cannot reach.
	Open(client, server uint16) (Session, error)
}

Downstream is a meter (or a logical device) the concentrator serves.

func Local

func Local(s *server.Server) Downstream

Local serves a server of package server in the same process: a meter the concentrator emulates, or the concentrator's own management logical device. Requests for another server SAP than the server's Address (default 1) are dropped, except in logical-device mode, where the SAP already chose the device.

func LogicalDevice

func LogicalDevice(s *server.Server) Downstream

LogicalDevice serves a server of package server as a logical device: the server SAP the head end addressed is taken as the server's.

type Func

type Func func(client, server uint16) (Session, error)

Func is a Downstream from a function that opens sessions.

func (Func) Open

func (f Func) Open(client, server uint16) (Session, error)

Open calls f.

type Meter

type Meter struct {
	// Network is the network ID (0 when the concentrator has one local
	// network); Address the physical device address as that network
	// writes it.
	Network byte
	Address []byte
	Device  Downstream
}

Meter is an end device behind the gateway.

type Session

type Session interface {
	// Exchange sends one APDU and returns the answer (nil: none, as for an
	// unconfirmed service).
	Exchange(apdu []byte) ([]byte, error)
	Close() error
}

Session carries one client's APDUs to a downstream device.

type SessionFunc

type SessionFunc func(apdu []byte) ([]byte, error)

SessionFunc is a Session from a function that answers APDUs (Close does nothing).

func (SessionFunc) Close

func (f SessionFunc) Close() error

Close does nothing.

func (SessionFunc) Exchange

func (f SessionFunc) Exchange(apdu []byte) ([]byte, error)

Exchange calls f.

type Stats

type Stats struct {
	Accepts     int            // head-end connections
	Routed      map[string]int // requests passed on, by address (hex)
	Logical     int            // requests to logical devices
	Unknown     int            // prefixed requests for an address no meter has
	Unreachable int            // requests a downstream device did not take
	Pushes      int            // pushes forwarded to the head end
}

Stats counts what the concentrator did.

type Transport

type Transport struct {
	// Dial opens a transport for a client SAP and the meter's server SAP
	// (not yet connected).
	Dial func(client, server int) (gdlms.Transport, error)
	// Timeout bounds the wait for an answer (default 30 s). Unconfirmed
	// requests are not waited for.
	Timeout time.Duration
	// Push, when set, receives APDUs the meter sends unasked
	// (data-notifications); a concentrator forwards them with Forward.
	Push func(client uint16, apdu []byte)
}

Transport reaches a meter over a gosem transport on the concentrator's local network: HDLC (package hdlc) on a serial bus or a converter, the wrapper (package wrapper) to an IP meter, DLMS over NB-IoT (package lpwan), or any other.

func (*Transport) Open

func (t *Transport) Open(client, server uint16) (Session, error)

Open dials the meter for one client.

Jump to

Keyboard shortcuts

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