ocpp

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Open Charge Point Protocol (OCPP) is a standard open protocol for communication between Charge Points and a Central System and is designed to accommodate any type of charging technique. This package contains the base interfaces used for the OCPP 1.6 and OCPP 2.0 implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code        ErrorCode
	Description string
	MessageId   string
}

Error wraps an OCPP error, containing an ErrorCode, a Description and the ID of the message.

func NewError

func NewError(errorCode ErrorCode, description string, messageId string) *Error

Creates a new OCPP Error.

func (*Error) Error

func (err *Error) Error() string

type ErrorCode

type ErrorCode string

ErrorCode defines a common code name for an error.

type Feature

type Feature interface {
	// Returns the unique name of the feature.
	GetFeatureName() string
	// Returns the type of the request message.
	GetRequestType() reflect.Type
	// Returns the type of the response message.
	GetResponseType() reflect.Type
}

Feature represents a single functionality, associated to a unique name. Every feature describes a Request and a Response message, specified in the OCPP protocol.

type Profile

type Profile struct {
	Name     string
	Features map[string]Feature
}

Profile defines a specific set of features, grouped by functionality.

Some vendor may want to keep the protocol as slim as possible, and only support some feature profiles. This can easily be achieved by only registering certain profiles, while remaining compliant with the specifications.

func NewProfile

func NewProfile(name string, features ...Feature) *Profile

Creates a new profile, identified by a name and a set of features.

func (*Profile) AddFeature

func (p *Profile) AddFeature(feature Feature)

Adds a feature to the profile.

func (*Profile) GetFeature

func (p *Profile) GetFeature(name string) Feature

Retrieves a feature, identified by a unique name. Returns nil in case the feature is not registered with this profile.

func (*Profile) ParseRequest

func (p *Profile) ParseRequest(featureName string, rawRequest interface{}, requestParser func(raw interface{}, requestType reflect.Type) (Request, error)) (Request, error)

ParseRequest checks whether a feature is supported and passes the rawRequest message to the requestParser function. The type of the request message is passed to the requestParser function, which has to perform type assertion.

func (*Profile) ParseResponse

func (p *Profile) ParseResponse(featureName string, rawResponse interface{}, responseParser func(raw interface{}, responseType reflect.Type) (Response, error)) (Response, error)

ParseRequest checks whether a feature is supported and passes the rawResponse message to the responseParser function. The type of the response message is passed to the responseParser function, which has to perform type assertion.

func (*Profile) SupportsFeature

func (p *Profile) SupportsFeature(name string) bool

SupportsFeature returns true if a feature matching the the passed name is registered with this profile, false otherwise.

type Request

type Request interface {
	// Returns the unique name of the feature, to which this request belongs to.
	GetFeatureName() string
}

Request message

type Response

type Response interface {
	// Returns the unique name of the feature, to which this request belongs to.
	GetFeatureName() string
}

Response message

Jump to

Keyboard shortcuts

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