transport

package
v0.0.0-...-55c65bb Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package transport provides the interfaces that are used to communicate between the manager and the gateway and subsequently to the charge station.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	// Disconnect drops the previously established connection to the broker.
	Disconnect(ctx context.Context) error
}

type Emitter

type Emitter interface {
	// Emit sends a message, destined for a specific charge station which is identified by its
	// chargeStationId using a specific ocppVersion, to the gateway.
	Emit(ctx context.Context, ocppVersion OcppVersion, chargeStationId string, message *Message) error
}

Emitter defines the contract for sending messages to the gateway.

type EmitterFunc

type EmitterFunc func(ctx context.Context, ocppVersion OcppVersion, chargeStationId string, message *Message) error

EmitterFunc allows a plain function to be used as an Emitter

func (EmitterFunc) Emit

func (e EmitterFunc) Emit(ctx context.Context, ocppVersion OcppVersion, chargeStationId string, message *Message) error

type Error

type Error struct {
	ErrorCode    ErrorCode
	WrappedError error
}

An Error allows a function to return an error that includes an OCPP ErrorCode.

func NewError

func NewError(code ErrorCode, err error) *Error

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type ErrorCode

type ErrorCode string

ErrorCode represents an OCPP error code.

const (
	ErrorFormatViolation               ErrorCode = "FormatViolation"
	ErrorGenericError                  ErrorCode = "GenericError"
	ErrorInternalError                 ErrorCode = "InternalError"
	ErrorMessageTypeNotSupported       ErrorCode = "MessageTypeNotSupported"
	ErrorNotImplemented                ErrorCode = "NotImplemented"
	ErrorNotSupported                  ErrorCode = "NotSupported"
	ErrorOccurrenceConstraintViolation ErrorCode = "OccurrenceConstraintViolation"
	ErrorPropertyConstraintViolation   ErrorCode = "PropertyConstraintViolation"
	ErrorProtocolError                 ErrorCode = "ProtocolError"
	ErrorRpcFrameworkError             ErrorCode = "RpcFrameworkError"
	ErrorSecurityError                 ErrorCode = "SecurityError"
	ErrorTypeConstraintViolation       ErrorCode = "TypeConstraintViolation"
)

type Listener

type Listener interface {
	// Connect establishes a connection to the broker and subscribes to receive messages for
	// either a specific charge station or all charge stations (for a specific OcppVersion). The messages
	// are delivered to the provided MessageHandler.
	//
	// Returns either a Connection on success or an error.
	Connect(ctx context.Context, ocppVersion OcppVersion, chargeStationId *string, handler MessageHandler) (Connection, error)
}

type Message

type Message struct {
	MessageType      MessageType     `json:"type"`
	Action           string          `json:"action"`
	MessageId        string          `json:"id"`
	RequestPayload   json.RawMessage `json:"request,omitempty"`
	ResponsePayload  json.RawMessage `json:"response,omitempty"`
	ErrorCode        ErrorCode       `json:"error_code,omitempty"`
	ErrorDescription string          `json:"error_description,omitempty"`
	State            json.RawMessage `json:"state,omitempty"`
}

func NewErrorMessage

func NewErrorMessage(action, messageId string, code ErrorCode, err error) *Message

type MessageHandler

type MessageHandler interface {
	// Handle a Message produced by the broker. The message will be for a specific OcppVersion
	// and come from the charge station identified by the chargeStationId.
	Handle(ctx context.Context, chargeStationId string, message *Message)
}

type MessageHandlerFunc

type MessageHandlerFunc func(ctx context.Context, chargeStationId string, message *Message)

func (MessageHandlerFunc) Handle

func (h MessageHandlerFunc) Handle(ctx context.Context, chargeStationId string, message *Message)

type MessageType

type MessageType int
const (
	MessageTypeCall MessageType = iota + 2
	MessageTypeCallResult
	MessageTypeCallError
)

func (MessageType) String

func (m MessageType) String() string

type OcppVersion

type OcppVersion string

OcppVersion represents the version of OCPP that is being used.

const (
	OcppVersion16  OcppVersion = "ocpp1.6"   // OCPP 1.6
	OcppVersion201 OcppVersion = "ocpp2.0.1" // OCPP 2.0.1
)

type Receiver

type Receiver interface {
	Connect(errCh chan error)
}

Receiver is the interface implemented in order to receive messages from the gateway (and thus from the charge station). The Receiver must establish a connection to the gateway and then use a Router to process any messages that are received.

Directories

Path Synopsis
Package mqtt provides support for handling messages from the gateway and emitting messages to the gateway using MQTT
Package mqtt provides support for handling messages from the gateway and emitting messages to the gateway using MQTT

Jump to

Keyboard shortcuts

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