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 ¶
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.
const MaxAddress = 255
MaxAddress is the longest physical device address: its length is one octet (C.2).
Variables ¶
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 ¶
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 ¶
FormatAddress writes an address in upper-case hex.
func ParseAddress ¶
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.