dsmr

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 6 Imported by: 0

README

DSMR

A package for parsing Dutch Smart Meter Requirements (DSMR) telegram data.

Latest Release Build Status MIT license PkgGoDev

Usage

import "github.com/mijnverbruik/dsmr"

raw := "" +
    "/ISk5\\2MT382-1000\r\n" +
    "\r\n" +
    "1-3:0.2.8(50)\r\n" +
    "0-0:1.0.0(170102192002W)\r\n" +
    "0-0:96.1.1(4B384547303034303436333935353037)\r\n" +
    "1-0:1.8.1(000004.426*kWh)\r\n" +
    "1-0:1.8.2(000002.399*kWh)\r\n" +
    "1-0:2.8.1(000002.444*kWh)\r\n" +
    "1-0:2.8.2(000000.000*kWh)\r\n" +
    "0-0:96.14.0(0002)\r\n" +
    "1-0:1.7.0(00.244*kW)\r\n" +
    "1-0:2.7.0(00.000*kW)\r\n" +
    "0-0:96.7.21(00013)\r\n" +
    "0-0:96.7.9(00000)\r\n" +
    "1-0:99.97.0(0)(0-0:96.7.19)\r\n" +
    "1-0:32.32.0(00000)\r\n" +
    "1-0:52.32.0(00000)\r\n" +
    "1-0:72.32.0(00000)\r\n" +
    "1-0:32.36.0(00000)\r\n" +
    "1-0:52.36.0(00000)\r\n" +
    "1-0:72.36.0(00000)\r\n" +
    "0-0:96.13.0()\r\n" +
    "1-0:32.7.0(0230.0*V)\r\n" +
    "1-0:52.7.0(0230.0*V)\r\n" +
    "1-0:72.7.0(0229.0*V)\r\n" +
    "1-0:31.7.0(0.48*A)\r\n" +
    "1-0:51.7.0(0.44*A)\r\n" +
    "1-0:71.7.0(0.86*A)\r\n" +
    "1-0:21.7.0(00.070*kW)\r\n" +
    "1-0:41.7.0(00.032*kW)\r\n" +
    "1-0:61.7.0(00.142*kW)\r\n" +
    "1-0:22.7.0(00.000*kW)\r\n" +
    "1-0:42.7.0(00.000*kW)\r\n" +
    "1-0:62.7.0(00.000*kW)\r\n" +
    "0-1:24.1.0(003)\r\n" +
    "0-1:96.1.0(3232323241424344313233343536373839)\r\n" +
    "0-1:24.2.1(170102161005W)(00000.107*m3)\r\n" +
    "0-2:24.1.0(003)\r\n" +
    "0-2:96.1.0()\r\n" +
    "!6EEE\r\n"

telegram, err := dsmr.ParseString(raw)

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/mijnverbruik/dsmr.git
cd dsmr
go test ./...

Feel free to open an issue to get feedback on your idea before spending too much time on it.

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyChecksum added in v0.4.0

func VerifyChecksum(t *Telegram, raw string) error

Types

type ChecksumError

type ChecksumError struct {
	Unexpected string
	Expect     string
}

func (*ChecksumError) Error

func (e *ChecksumError) Error() string

type Data added in v0.3.0

type Data []*Object

Data Objects in the root of the AST.

type Entry added in v0.3.0

type Entry interface {
	Key() string
	Node
}

type Error

type Error interface {
	error
}

type Event added in v0.3.0

type Event struct {
	Pos lexer.Position `parser:""`

	Timestamp *Timestamp   `parser:"'(' @@ ')'"`
	Value     *Measurement `parser:"'(' @@ ( ')' (?='(') )?"`
}

Event represents a timestamp+duration.

func (*Event) Position added in v0.3.0

func (e *Event) Position() lexer.Position

type EventLog added in v0.3.0

type EventLog struct {
	Pos lexer.Position `parser:""`

	Count *Number  `parser:"@@ ')'"`
	OBIS  *OBIS    `parser:"'(' @@ ( ')' (?='(') )?"`
	Value []*Event `parser:"@@*"`
}

EventLog represents a log of events.

func (*EventLog) Position added in v0.3.0

func (e *EventLog) Position() lexer.Position
type Footer struct {
	Pos lexer.Position `parser:""`

	Value string `parser:"'!' @(~EOL)? (?=EOL)"`
}

func (*Footer) Key added in v0.3.0

func (f *Footer) Key() string

func (*Footer) Position added in v0.3.0

func (f *Footer) Position() lexer.Position
type Header struct {
	Pos lexer.Position `parser:""`

	Value string `parser:"'/' @(~EOL)+ (?=EOL)"`
}

func (*Header) Key added in v0.3.0

func (h *Header) Key() string

func (*Header) Position added in v0.3.0

func (h *Header) Position() lexer.Position

type List added in v0.3.0

type List struct {
	Pos lexer.Position `parser:""`

	Value []ListValue `parser:"( @@ ')' '(' )+ @@"`
}

List represents a list of values.

func (*List) Position added in v0.3.0

func (l *List) Position() lexer.Position

type ListValue added in v0.3.0

type ListValue interface {
	Node
}

...

type Measurement

type Measurement struct {
	Pos lexer.Position `parser:""`

	Value *Number `parser:"@@"`
	Unit  *String `parser:"'*' @@"`
}

Measurement represents a number+unit.

func (*Measurement) Position added in v0.3.0

func (m *Measurement) Position() lexer.Position

type Node added in v0.3.0

type Node interface {
	Position() lexer.Position
	// contains filtered or unexported methods
}

type Number added in v0.3.0

type Number struct {
	Pos lexer.Position `parser:""`

	Value *big.Float `parser:"@Number"`
}

...

func (*Number) Position added in v0.3.0

func (n *Number) Position() lexer.Position

type OBIS

type OBIS struct {
	Pos lexer.Position `parser:""`

	Value string `parser:"@OBIS"`
}

...

func (*OBIS) Position added in v0.3.0

func (o *OBIS) Position() lexer.Position

type Object added in v0.3.0

type Object struct {
	Pos lexer.Position `parser:""`

	OBIS  *OBIS `parser:"@@"`
	Value Value `parser:"'(' @@* ')' (?=EOL)"`
}

Object is a COSEM object in the Telegram represented by the OBIS (Object Identification System) and one or more attributes.

func (*Object) Key added in v0.3.0

func (o *Object) Key() string

func (*Object) Position added in v0.3.0

func (o *Object) Position() lexer.Position

type String added in v0.3.0

type String struct {
	Pos lexer.Position `parser:""`

	// Also check for `EOL` token so both Header and Footer
	// can use this Value struct as well.
	Value string `parser:"@(~(')' | EOL)+)"`
}

String literal.

func (*String) Position added in v0.3.0

func (s *String) Position() lexer.Position

type Telegram

type Telegram struct {
	Pos lexer.Position `parser:""`

	Header *Header `parser:"@@"`
	Data   Data    `parser:"@@*"`
	Footer *Footer `parser:"@@"`
}

Struct for telegram data.

func Parse

func Parse(str string) (*Telegram, error)

Parse parses telegram from a string.

func (*Telegram) Position added in v0.4.0

func (t *Telegram) Position() lexer.Position

type Timestamp

type Timestamp struct {
	Pos lexer.Position `parser:""`

	Value string `parser:"@Timestamp"`
	DST   bool   `parser:"(@'S' | 'W')"`
}

Timestamp represents a timestamp of a date.

func (*Timestamp) Position added in v0.3.0

func (t *Timestamp) Position() lexer.Position

type Value added in v0.3.0

type Value interface {
	Node
	// contains filtered or unexported methods
}

Value represents an object value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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