cp

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cp implements the OCPP Charge Point (client) side.

Index

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 CallRaw

func CallRaw(ctx context.Context, c *Client, action string, payload []byte) ([]byte, error)

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 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.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an OCPP charge point.

func NewClient

func NewClient(cpID, csmsURL string, opts ...Option) *Client

NewClient creates a charge point client. Call Connect or Run to establish.

func (*Client) Close

func (c *Client) Close()

Close tears down the current connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes a single connection (no auto-reconnect).

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected reports whether a live connection exists.

func (*Client) NegotiatedProtocol

func (c *Client) NegotiatedProtocol() string

NegotiatedProtocol returns the subprotocol chosen during the handshake.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run connects and maintains the connection with exponential backoff until ctx is cancelled. In-flight calls fail on disconnect (OCPP has no idempotency guarantee).

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a Client.

func WithCallTimeout

func WithCallTimeout(d time.Duration) Option

WithCallTimeout sets the per-call timeout.

func WithHeartbeatInterval

func WithHeartbeatInterval(d time.Duration) Option

WithHeartbeatInterval sets the OCPP Heartbeat interval.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the structured logger.

func WithSchemaRegistry

func WithSchemaRegistry(r *schema.Registry) Option

WithSchemaRegistry sets the schema registry used for first-layer validation.

func WithStrictSchema

func WithStrictSchema(strict bool) Option

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

func WithSubProtocols(p ...string) Option

WithSubProtocols sets offered subprotocols.

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.

Jump to

Keyboard shortcuts

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