Documentation
¶
Overview ¶
Package wrapper is our DLMS/COSEM transport layer for IP networks (IEC 62056-4-7:2015, profile IEC 62056-9-7:2013): the wrapper protocol data unit (version, source and destination wPort, length) over TCP, where a WPDU may arrive in any number of TCP packets, and over UDP, where it fills one datagram. Transport is a gosem transport for the DLMS client; ReadWPDU and ParseDatagram serve the push listener and the meter simulator. Clause numbers are those of IEC 62056-4-7 unless stated.
Index ¶
- Constants
- Variables
- func CheckClient(p int) error
- func CheckServer(p int) error
- func Encode(src, dst uint16, apdu []byte) ([]byte, error)
- type Header
- type Transport
- func (t *Transport) Close()
- func (t *Transport) Connect() error
- func (t *Transport) Discarded() int
- func (t *Transport) Disconnect() error
- func (t *Transport) IsConnected() bool
- func (t *Transport) Send(apdu []byte) error
- func (t *Transport) SendBroadcast(apdu []byte) error
- func (t *Transport) SetAddress(client, server int)
- func (t *Transport) SetLogger(l *log.Logger)
- func (t *Transport) SetReception(dc gdlms.DataChannel)
Examples ¶
Constants ¶
const ( NoStation = 0x0000 // client and server ClientManagement = 0x0001 // client management process PublicClient = 0x0010 // public client ManagementDevice = 0x0001 // management logical device AllStation = 0x007F // server all-station (broadcast) )
Reserved wPorts (Table 1).
const HeaderLen = 8
HeaderLen is the wrapper header: four 16-bit fields (5.3.2, Figure 4).
const MaxAPDU = 0xFFFF
MaxAPDU is the most the 16-bit length field can carry (TCP).
const MaxUDPAPDU = 65507 - HeaderLen
MaxUDPAPDU is the longest APDU in one UDP datagram over IPv4 (65 507 octets of UDP data less the wrapper header; 5.2.1, Figure 4 NOTE).
const Port = 4059
Port is the IANA port of DLMS/COSEM, TCP and UDP (IEC 62056-9-7 clause 6 NOTE 1).
const Version = 0x0001
Version is the wrapper version (5.3.2).
Variables ¶
var ErrVersion = errors.New("not a wrapper version 1 header")
ErrVersion is returned for a WPDU of another wrapper version, whose header may have another layout (5.3.2).
Functions ¶
func CheckClient ¶
CheckClient reports a client wPort Table 1 does not open: 1 (client management), 0x10 (public) and 0x02 to 0xFF.
func CheckServer ¶
CheckServer reports a server wPort that does not name one logical device: 1 (management logical device) or 0x10 to 0x7E (Table 1).
func Encode ¶
Encode prefixes an APDU with the wrapper header.
Example ¶
A GET of the clock (class 8, 0.0.1.0.0.255, attribute 2) from client wPort 16 to the meter's management logical device (wPort 1), framed and read back.
package main
import (
"bytes"
"fmt"
"github.com/cB-Sigma/dlms/wrapper"
)
func main() {
get := []byte{0xC0, 0x01, 0xC1, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF, 0x02, 0x00}
wpdu, err := wrapper.Encode(16, 1, get)
if err != nil {
panic(err)
}
fmt.Printf("header % X\n", wpdu[:wrapper.HeaderLen])
h, apdu, err := wrapper.ReadWPDU(bytes.NewReader(wpdu))
fmt.Println(h.Src, h.Dst, len(apdu), err)
}
Output: header 00 01 00 10 00 01 00 0D 16 1 13 <nil>
Types ¶
type Header ¶
type Header struct {
Version, Src, Dst, Length uint16
}
Header is a wrapper header.
func ParseDatagram ¶
ParseDatagram reads the WPDU a UDP datagram carries; the APDU fills the rest of the datagram exactly (5.2.1, 5.3.3).
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the client side of the wrapper over TCP or UDP, a gosem transport: each Send is one WPDU; each WPDU received from the server's wPort to ours is delivered whole. WPDUs of another version or for another wPort are discarded (5.3.5, 6.2.5.2).
func (*Transport) Close ¶
func (t *Transport) Close()
Close disconnects and closes the reception channel.
func (*Transport) Disconnect ¶
Disconnect closes the connection and waits for the reader.
func (*Transport) IsConnected ¶
IsConnected reports an open connection.
func (*Transport) Send ¶
Send sends one APDU in one WPDU. Over TCP the whole WPDU is written however many writes it takes (6.3.5.4); over UDP it must fit one datagram (5.2.1).
func (*Transport) SendBroadcast ¶
SendBroadcast sends an unconfirmed APDU; over IP it is an ordinary WPDU (IEC 62056-9-7 9.1, the invoke-id's service class bit says it).
func (*Transport) SetAddress ¶
SetAddress sets our (client) and the server's wPort.
func (*Transport) SetReception ¶
func (t *Transport) SetReception(dc gdlms.DataChannel)
SetReception sets where APDUs go.