gateway

package
v0.2.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: 4 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 gateway is the DLMS/COSEM gateway protocol of IEC 62056-5-3:2023 annex C: a COSEM APDU exchanged with an end device behind a gateway (a data concentrator unit, DCU) is prefixed with a header octet, the network ID of the gateway's local network, the length of the physical device address and that address (C.2, Figure C.2). The client and server SAPs are not in the prefix; they travel in the supporting layer (the wrapper wPorts) as for a directly connected meter (C.3). The prefix is outside the application layer's protection: security stays end to end (C.5).

Index

Examples

Constants

View Source
const (
	// Request is a client's request to an end device, or an end device's
	// request to a client (a data-notification pushed through the gateway).
	Request = 0xE6
	// Response is an end device's response to a client.
	Response = 0xE7
)

Header octets (C.2). The ASN.1 of clause 8 reserves tags 230 and 231 for the gateway without defining an APDU there.

View Source
const MaxAddress = 255

MaxAddress is the longest physical device address: its length is one octet (C.2).

Variables

View Source
var ErrShort = errors.New("gateway prefix: the APDU ends inside the prefix")

ErrShort is a prefixed APDU that ends inside its prefix.

Functions

func Encode

func Encode(p Prefix, apdu []byte) ([]byte, error)

Encode puts the prefix in front of an APDU.

Example

A request to the meter at physical address 0A:01 behind a data concentrator, and the concentrator's answer taken apart again.

package main

import (
	"fmt"

	"github.com/cB-Sigma/dlms/gateway"
)

func main() {
	addr, _ := gateway.ParseAddress("0A01")
	req, err := gateway.Encode(gateway.Prefix{Header: gateway.Request, Address: addr}, []byte{0xC0, 0x01, 0xC1})
	if err != nil {
		panic(err)
	}
	fmt.Printf("% X\n", req)
	p, apdu, ok, err := gateway.Parse(req)
	fmt.Println(p, ok, err)
	fmt.Printf("% X\n", apdu)
}
Output:
E6 00 02 0A 01 C0 01 C1
network 0 address 0A01 true <nil>
C0 01 C1

func FormatAddress

func FormatAddress(a []byte) string

FormatAddress writes an address in upper-case hex.

func ParseAddress

func ParseAddress(s string) ([]byte, error)

ParseAddress reads a physical device address written in hex, with or without separators (":", "-", "." or spaces) and an optional 0x.

Types

type Prefix

type Prefix struct {
	Header  byte   // Request or Response
	Network byte   // network ID; 0 when the gateway has one network
	Address []byte // physical device address, as the local network's protocol writes it
}

Prefix is the gateway prefix of one APDU.

func Parse

func Parse(b []byte) (p Prefix, apdu []byte, ok bool, err error)

Parse splits a prefixed APDU. ok is false for an APDU without a prefix (a plain COSEM APDU); err is set when the header says prefix but the octets do not hold one.

func (Prefix) String

func (p Prefix) String() string

String names the prefix for messages: network and address in hex.

Jump to

Keyboard shortcuts

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