Documentation
¶
Overview ¶
Package cp implements the OCPP Charge Point (client) side.
Index ¶
- func Call[Req, Resp any](ctx context.Context, c *Client, m ocppj.Message[Req, Resp], req Req) (Resp, error)
- func CallAsync[Req, Resp any](ctx context.Context, c *Client, m ocppj.Message[Req, Resp], req Req, ...) error
- func CallRaw(ctx context.Context, c *Client, action string, payload []byte) ([]byte, error)
- func CallRawAsync(ctx context.Context, c *Client, action string, payload []byte, ...) error
- func On[Req, Resp any](c *Client, m ocppj.Message[Req, Resp], ...) error
- func OnSend[Req any](c *Client, m ocppj.SendMessage[Req], ...) error
- func Send[Req any](ctx context.Context, c *Client, m ocppj.SendMessage[Req], req Req) error
- type Client
- type Option
- func WithAsyncQueueSize(n int) Option
- func WithBasicAuth(username, password string) Option
- func WithCallTimeout(d time.Duration) Option
- func WithCompression(m transport.CompressionMode) Option
- func WithHTTPHeader(key, value string) Option
- func WithHeartbeatInterval(d time.Duration) Option
- func WithLenientSchema() Option
- func WithLogger(l *slog.Logger) Option
- func WithOfflineQueue(capacity int) Option
- func WithOnConnect(fn func()) Option
- func WithOnDisconnect(fn func(error)) Option
- func WithOnReconnect(fn func()) Option
- func WithRequireSignature(require bool) Option
- func WithRetryInFlightCalls() Option
- func WithSchemaRegistry(r *schema.Registry) Option
- func WithSerializedCalls() Option
- func WithSigner(s *signing.Signer) Option
- func WithStrictSchema(strict bool) Option
- func WithSubProtocols(p ...string) Option
- func WithTLSConfig(cfg *tls.Config) Option
- func WithTolerantSchema() Option
- func WithVerifier(v *signing.Verifier) Option
- func WithWebSocketPingInterval(d time.Duration) Option
- func WithWebSocketPongWait(d time.Duration) Option
- func WithWebSocketReadTimeout(d time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call[Req, Resp any](ctx context.Context, c *Client, m ocppj.Message[Req, Resp], req Req) (Resp, error)
Call sends a typed message from this charge point to the CSMS.
func CallAsync ¶ added in v0.1.3
func CallAsync[Req, Resp any](ctx context.Context, c *Client, m ocppj.Message[Req, Resp], req Req, cb func(Resp, error)) error
CallAsync sends a typed message to the CSMS without blocking and delivers the typed response (or error) to cb. With WithSerializedCalls the calls are queued FIFO and sent one outstanding at a time; otherwise they run concurrently. It returns synchronously only if the call could not be accepted (e.g. not connected, ocppj.ErrQueueFull). Unlike Call, this does not use the offline queue — it requires a live connection. See dispatcher.DoCallAsync.
func CallRaw ¶
CallRaw sends an action with a raw JSON payload and returns the raw response. Used by tools like the simulator that operate on untyped messages.
func CallRawAsync ¶ added in v0.1.3
func CallRawAsync(ctx context.Context, c *Client, action string, payload []byte, cb func([]byte, error)) error
CallRawAsync is the untyped form of CallAsync.
func On ¶
func On[Req, Resp any](c *Client, m ocppj.Message[Req, Resp], h func(ctx context.Context, req Req) (Resp, error)) error
On registers a typed handler for a message the CSMS sends to this charge point.
func OnSend ¶ added in v0.1.7
func OnSend[Req any](c *Client, m ocppj.SendMessage[Req], h func(ctx context.Context, req Req) error) error
OnSend registers a typed handler for an OCPP 2.1 SEND this charge point receives. SEND messages are unconfirmed: the handler returns only an error (logged, never sent back).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an OCPP charge point.
func (*Client) IsConnected ¶
IsConnected reports whether a live connection exists.
func (*Client) NegotiatedProtocol ¶
NegotiatedProtocol returns the subprotocol chosen during the handshake.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a Client.
func WithAsyncQueueSize ¶ added in v0.1.3
WithAsyncQueueSize bounds the per-connection FIFO queue used by CallAsync when WithSerializedCalls is set (default 64). Enqueuing beyond it returns ocppj.ErrQueueFull.
func WithBasicAuth ¶ added in v0.1.2
WithBasicAuth sets HTTP Basic authentication for the WebSocket dial.
func WithCallTimeout ¶
WithCallTimeout sets the per-call timeout.
func WithCompression ¶ added in v0.1.7
func WithCompression(m transport.CompressionMode) Option
WithCompression sets the RFC 7692 permessage-deflate mode for the dial. Defaults to transport.CompressionNoContextTakeover; pass transport.CompressionDisabled to opt out.
func WithHTTPHeader ¶ added in v0.1.2
WithHTTPHeader appends an HTTP header to the WebSocket dial request.
func WithHeartbeatInterval ¶
WithHeartbeatInterval sets the OCPP Heartbeat interval.
func WithLenientSchema ¶ added in v0.1.4
func WithLenientSchema() Option
WithLenientSchema enables lenient JSON-Schema validation: structurally broken messages are rejected, while benign violations are logged and passed, and enum case mismatches are normalized to canonical values. Last-wins with WithStrictSchema / WithTolerantSchema.
func WithOfflineQueue ¶ added in v0.1.2
WithOfflineQueue enables a bounded FIFO queue for CP-originated calls while disconnected.
func WithOnConnect ¶ added in v0.1.2
func WithOnConnect(fn func()) Option
WithOnConnect registers a callback fired after a successful connection.
func WithOnDisconnect ¶ added in v0.1.2
WithOnDisconnect registers a callback fired after the active connection drops.
func WithOnReconnect ¶ added in v0.1.2
func WithOnReconnect(fn func()) Option
WithOnReconnect registers a callback fired after Run re-establishes a dropped connection.
func WithRequireSignature ¶ added in v0.1.7
WithRequireSignature rejects inbound signed messages that fail verification instead of unwrapping and processing them.
func WithRetryInFlightCalls ¶ added in v0.1.2
func WithRetryInFlightCalls() Option
WithRetryInFlightCalls makes the offline queue re-send a CALL that was already in-flight when the connection dropped, instead of failing it. Off by default: OCPP gives no idempotency guarantee, so an in-flight CALL the peer may already have received fails with ocppj.ErrConnClosed rather than risk double execution. Only affects connections using WithOfflineQueue.
func WithSchemaRegistry ¶
WithSchemaRegistry sets the schema registry used for first-layer validation.
func WithSerializedCalls ¶ added in v0.1.2
func WithSerializedCalls() Option
WithSerializedCalls limits outbound OCPP Calls to one outstanding request.
func WithSigner ¶ added in v0.1.7
WithSigner signs outbound CALL/SEND messages (OCPP 2.1 Signed Messages).
func WithStrictSchema ¶
WithStrictSchema controls whether schema validation failures reject the message. Passing false turns schema validation off. If WithStrictSchema and WithTolerantSchema are both used, the last option in the list wins.
func WithSubProtocols ¶
WithSubProtocols sets offered subprotocols.
func WithTLSConfig ¶ added in v0.1.2
WithTLSConfig sets the TLS configuration used by the WebSocket dial.
func WithTolerantSchema ¶
func WithTolerantSchema() Option
WithTolerantSchema enables schema validation that logs validation failures but continues processing messages. If WithStrictSchema and WithTolerantSchema are both used, the last option in the list wins.
func WithVerifier ¶ added in v0.1.7
WithVerifier verifies inbound signed CALL/SEND messages.
func WithWebSocketPingInterval ¶ added in v0.1.2
WithWebSocketPingInterval sets the transport ping interval.
func WithWebSocketPongWait ¶ added in v0.1.2
WithWebSocketPongWait sets the transport pong timeout.
func WithWebSocketReadTimeout ¶ added in v0.1.6
WithWebSocketReadTimeout sets the read idle timeout: the connection is closed if no inbound frame (data, ping, or pong) arrives within d. 0 disables it.