gosml

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 8 Imported by: 2

README

gosml

This repository is a fork of github.com/andig/gosml, which is a Go port of github.com/volkszaehler/libsml.

I adapted it to my needs and to make it more usable in my eyes.

Usage

To include in your code use:

import (
	"github.com/mfmayer/gosml"
)

Example

For an example see examples/emmon and the libsml documentation.

Status

The implementation of this port and fork is not complete and has not been extensively tested. It's main intension is to use it for decoding list entries with well known obis codes like for electricity meter readings.

Test binaries and SML files from real world meters can be found here: https://github.com/devZer0/libsml-testing

Documentation

Index

Constants

View Source
const (
	OCTET_MESSAGE_END       = 0x00
	OCTET_TYPE_FIELD        = 0x70
	OCTET_LENGTH_FIELD      = 0x0F
	OCTET_ANOTHER_TL        = 0x80
	OCTET_TYPE_OCTET_STRING = 0x00
	OCTET_TYPE_BOOLEAN      = 0x40
	OCTET_TYPE_INTEGER      = 0x50
	OCTET_TYPE_UNSIGNED     = 0x60
	OCTET_TYPE_LIST         = 0x70
	OCTET_OPTIONAL_SKIPPED  = 0x01
)
View Source
const (
	TYPE_NUMBER_8  = 1
	TYPE_NUMBER_16 = 2
	TYPE_NUMBER_32 = 4
	TYPE_NUMBER_64 = 8
)
View Source
const (
	MESSAGE_OPEN_REQUEST                = 0x00000100
	MESSAGE_OPEN_RESPONSE               = 0x00000101
	MESSAGE_CLOSE_REQUEST               = 0x00000200
	MESSAGE_CLOSE_RESPONSE              = 0x00000201
	MESSAGE_GET_PROFILE_PACK_REQUEST    = 0x00000300
	MESSAGE_GET_PROFILE_PACK_RESPONSE   = 0x00000301
	MESSAGE_GET_PROFILE_LIST_REQUEST    = 0x00000400
	MESSAGE_GET_PROFILE_LIST_RESPONSE   = 0x00000401
	MESSAGE_GET_PROC_PARAMETER_REQUEST  = 0x00000500
	MESSAGE_GET_PROC_PARAMETER_RESPONSE = 0x00000501
	MESSAGE_SET_PROC_PARAMETER_REQUEST  = 0x00000600
	MESSAGE_SET_PROC_PARAMETER_RESPONSE = 0x00000601 // This doesn't exist in the spec
	MESSAGE_GET_LIST_REQUEST            = 0x00000700
	MESSAGE_GET_LIST_RESPONSE           = 0x00000701
	MESSAGE_ATTENTION_RESPONSE          = 0x0000FF01
)

Variables

View Source
var ErrSequenceTooLong = errors.New("max sequence length exceeded")

ErrSequenceTooLong means that the max length of a sequence has been reached before end of sequence has been detected.

View Source
var ErrUnrecognizedSequence = errors.New("unrecognized sequence")

ErrUnrecognizedSequence means that a sequence was found but its end was not found. E.g. a new sequence started before the end of current sequence was found.

Functions

func Read

func Read(r *bufio.Reader, opts ...ReadOption) error

Read reads and parses sml file from given buffered reader. If sml file is not recognized ErrUnrecognizedSequence is returned. If sml file is too long ErrSequenceTooLong is returned. If file is successfully read and parsed slice of found messages is returned

Types

type Buffer

type Buffer struct {
	Bytes  []byte
	Cursor int
}

func (*Buffer) BooleanParse

func (buf *Buffer) BooleanParse() (bool, error)

func (*Buffer) Debug

func (buf *Buffer) Debug()

func (*Buffer) Expect

func (buf *Buffer) Expect(expectedType uint8, expectedLength int) error

func (*Buffer) ExpectType

func (buf *Buffer) ExpectType(expectedType uint8) error

func (*Buffer) GetCurrentByte

func (buf *Buffer) GetCurrentByte() byte

func (*Buffer) GetNextLength

func (buf *Buffer) GetNextLength() int

func (*Buffer) GetNextType

func (buf *Buffer) GetNextType() uint8

func (*Buffer) I8Parse

func (buf *Buffer) I8Parse() (int8, error)

func (*Buffer) I16Parse

func (buf *Buffer) I16Parse() (int16, error)

func (*Buffer) I32Parse

func (buf *Buffer) I32Parse() (int32, error)

func (*Buffer) I64Parse

func (buf *Buffer) I64Parse() (int64, error)

func (*Buffer) NumberParse

func (buf *Buffer) NumberParse(numType uint8, maxSize int) (int64, error)

func (*Buffer) OctetStringParse

func (buf *Buffer) OctetStringParse() (OctetString, error)

func (*Buffer) OptionalIsSkipped

func (buf *Buffer) OptionalIsSkipped() bool

func (*Buffer) StatusParse

func (buf *Buffer) StatusParse() (int64, error)

func (*Buffer) TimeParse

func (buf *Buffer) TimeParse() (Time, error)

func (*Buffer) U8Parse

func (buf *Buffer) U8Parse() (uint8, error)

func (*Buffer) U16Parse

func (buf *Buffer) U16Parse() (uint16, error)

func (*Buffer) U32Parse

func (buf *Buffer) U32Parse() (uint32, error)

func (*Buffer) U64Parse

func (buf *Buffer) U64Parse() (uint64, error)

func (*Buffer) UpdateBytesRead

func (buf *Buffer) UpdateBytesRead(delta int)

func (*Buffer) ValueParse

func (buf *Buffer) ValueParse() (Value, error)

type CloseRequest

type CloseRequest struct {
	GlobalSignature OctetString
}

func CloseRequestParse

func CloseRequestParse(buf *Buffer) (CloseRequest, error)

type CloseResponse

type CloseResponse CloseRequest

func CloseResponseParse

func CloseResponseParse(buf *Buffer) (CloseResponse, error)

type GetListRequest

type GetListRequest struct {
	ClientID OctetString
	ServerID OctetString // optional
	Username OctetString // optional
	Password OctetString // optional
	ListName OctetString // optional
}

func GetListRequestParse

func GetListRequestParse(buf *Buffer) (GetListRequest, error)

type GetListResponse

type GetListResponse struct {
	ClientID       OctetString
	ServerID       OctetString
	ListName       OctetString
	ActSensorTime  Time
	ValList        []*ListEntry
	ListSignature  OctetString
	ActGatewayTime Time
}

func GetListResponseParse

func GetListResponseParse(buf *Buffer) (GetListResponse, error)

type ListEntry

type ListEntry struct {
	ObjName OctetString

	Unit uint8

	Value          Value
	ValueSignature OctetString
	// contains filtered or unexported fields
}

func ListEntryParse

func ListEntryParse(buf *Buffer) (*ListEntry, error)

func ListParse

func ListParse(buf *Buffer) ([]*ListEntry, error)

func (*ListEntry) Float

func (le *ListEntry) Float() float64

func (*ListEntry) ObjectName

func (le *ListEntry) ObjectName() string

func (*ListEntry) Scaler

func (le *ListEntry) Scaler() float64

func (*ListEntry) String

func (le *ListEntry) String() string

func (*ListEntry) ValueString

func (le *ListEntry) ValueString() string

type Message

type Message struct {
	TransactionID OctetString
	GroupID       uint8
	AbortOnError  uint8
	MessageBody   MessageBody
	Crc           uint16
}

func MessageParse

func MessageParse(buf *Buffer, validate ...bool) (*Message, error)

type MessageBody

type MessageBody struct {
	Tag  uint32
	Data MessageBodyData
}

func MessageBodyParse

func MessageBodyParse(buf *Buffer) (MessageBody, error)

type MessageBodyData

type MessageBodyData interface{}

type OctetString

type OctetString []byte

type OpenRequest

type OpenRequest struct {
	Codepage  OctetString // optional
	ClientID  OctetString
	ReqFileID OctetString
	ServerID  OctetString // optional
	Username  OctetString // optional
	Password  OctetString // optional
	Version   uint8       // optional
}

func OpenRequestParse

func OpenRequestParse(buf *Buffer) (OpenRequest, error)

type OpenResponse

type OpenResponse struct {
	Codepage  OctetString
	ClientID  OctetString
	ReqFileID OctetString
	ServerID  OctetString
	RefTime   Time
	Version   uint8
}

func OpenResponseParse

func OpenResponseParse(buf *Buffer) (OpenResponse, error)

type ReadOption

type ReadOption func(*options)

func WithObisCallback

func WithObisCallback(obisCode OctetString, callback func(message *ListEntry)) ReadOption

type Time

type Time uint32

type Value

type Value struct {
	Typ         uint8
	DataBytes   OctetString
	DataBoolean bool
	DataInt     int64
}

Directories

Path Synopsis
examples
emmon command

Jump to

Keyboard shortcuts

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