Documentation
¶
Overview ¶
Package chargepoint is the charging station side of OCPP-J as a library role: it dials a central system as <url>/<identity> with the versions it offers, authenticates (security profiles 1 to 3), routes the central system's CALLs to handlers by action, checks every request and answer against the OCA schemas and, run with Run, reconnects with the randomised, doubling back-off of the 2.x OCPPCommCtrlr variables.
It holds no charger behaviour (connectors, transactions, meter values); handlers and the application's own calls supply it. ocpp-sim's simulated charge point is built on Dial.
Index ¶
- Variables
- func EndpointURL(base, id string) string
- type Backoff
- type Client
- func (c *Client) Call(ctx context.Context, action string, req any) (json.RawMessage, error)
- func (c *Client) CallInto(ctx context.Context, action string, req, out any) error
- func (c *Client) Close(reason string)
- func (c *Client) Conn() *ocpp.Conn
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) Handle(action string, h HandlerFunc)
- func (c *Client) HandleVersion(version, action string, h HandlerFunc)
- func (c *Client) ID() string
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) Send(ctx context.Context, action string, payload any) error
- func (c *Client) Version() string
- func (c *Client) WaitConnected(ctx context.Context) error
- type Config
- type Dialled
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ErrNotConnected = errors.New("not connected to the central system")
ErrNotConnected is returned by Call while there is no connection.
Functions ¶
func EndpointURL ¶
EndpointURL is base with the identity appended as an escaped path segment.
Types ¶
type Backoff ¶
type Backoff struct {
Minimum time.Duration // default 1 s
RandomRange time.Duration // default 1 s
RepeatTimes int // default 5
}
Backoff is the reconnection back-off, read the way the OCPP 2.x OCPPCommCtrlr variables RetryBackOffWaitMinimum, RetryBackOffRandomRange and RetryBackOffRepeatTimes are: the first wait is Minimum plus a random part of RandomRange, and each later wait doubles the previous one, for at most RepeatTimes doublings; then it stays there.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a charging station's connection to its central system.
func (*Client) Call ¶
Call sends a CALL and returns the central system's answer, checked as csms.Station.Call checks it: a request outside the schema is returned as an *ocpp.RPCError unsent, an answer outside it with an *ocpp.ResultError, a CALLERROR as an *ocpp.CallError.
func (*Client) Connect ¶
Connect dials once and serves the connection in the background until it ends or ctx is done.
func (*Client) Handle ¶
func (c *Client) Handle(action string, h HandlerFunc)
Handle routes the central system's action, in every version, to h.
func (*Client) HandleVersion ¶
func (c *Client) HandleVersion(version, action string, h HandlerFunc)
HandleVersion routes action in version to h, ahead of Handle.
func (*Client) Send ¶
Send sends a 2.1 SEND message (never answered), checked against its schema first.
type Config ¶
type Config struct {
// URL is the central system's endpoint without the identity, e.g.
// wss://csms.example/ocpp; the identity is appended as a path segment.
URL string
// ID is the charging station identity (1 to 48 characters).
ID string
// Versions offered, in order of preference (default 2.1, 2.0.1, 1.6).
Versions []string
// Password for HTTP basic authentication (security profiles 1 and 2).
Password string
// TLS for wss (profiles 2 and 3; a client certificate for 3).
TLS *tls.Config
// Header holds further upgrade request headers.
Header http.Header
// Timeout of our CALLs and of each handler (default 30 s).
Timeout time.Duration
// Ping is the WebSocket ping interval (0: none).
Ping time.Duration
// SkipValidation turns off the schema checks.
SkipValidation bool
// OnInvalid, when set, decides about a central system request that
// fails the schema check: nil hands it to the handler anyway, an error
// (normally verr) refuses it. Unset, such requests are refused.
OnInvalid func(c *Client, action string, payload json.RawMessage, verr *ocpp.RPCError) error
// Backoff between reconnection attempts in Run.
Backoff Backoff
// OnConnect runs, on its own goroutine, after every connection (send
// BootNotification there); OnDisconnect after it ends.
OnConnect func(ctx context.Context, c *Client)
OnDisconnect func(c *Client, err error)
// OnResultError is told about a 2.1 CALLRESULTERROR the central system
// sent about one of our answers.
OnResultError func(id, code, desc string)
}
Config describes a charging station's connection.
type HandlerFunc ¶
HandlerFunc answers a CALL of the central system. Return an *ocpp.RPCError to choose the CALLERROR, any other error for an InternalError.