Documentation
¶
Overview ¶
Package csms is the central system side of OCPP-J as a library role: an http.Handler that accepts charging stations of 1.6, 2.0.1 and 2.1 at <path>/<identity>, authenticates them (security profiles 1 to 3 through a hook), routes their CALLs and 2.1 SENDs to handlers by action, checks every request and every answer against the OCA schemas, keeps a registry of connected stations and calls them.
It holds no charging business logic (authorization lists, tariffs, smart charging); handlers supply it.
Index ¶
- func Identity(r *http.Request) (string, error)
- type Config
- type HandlerFunc
- type Server
- type Station
- func (st *Station) Call(ctx context.Context, action string, req any) (json.RawMessage, error)
- func (st *Station) CallInto(ctx context.Context, action string, req, out any) error
- func (st *Station) Close(reason string)
- func (st *Station) Conn() *ocpp.Conn
- func (st *Station) Done() <-chan struct{}
- func (st *Station) Get(key any) any
- func (st *Station) Header() http.Header
- func (st *Station) ID() string
- func (st *Station) Send(ctx context.Context, action string, payload any) error
- func (st *Station) Set(key, value any)
- func (st *Station) String() string
- func (st *Station) TLS() *tls.ConnectionState
- func (st *Station) Version() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Versions offered, in order of preference (default 2.1, 2.0.1, 1.6).
// Variant spellings of each (ocpp.Subprotocols) are accepted too.
Versions []string
// NoSubprotocol is the version assumed for a station that offers no
// subprotocol; empty refuses such a station.
NoSubprotocol string
// Authenticate admits a station before the WebSocket upgrade: check the
// basic authentication password (profiles 1 and 2; ocpp.BasicAuthPassword,
// ocpp.PasswordOK) or r.TLS (profile 3; ocpp.ClientCertNames). A
// non-nil error refuses the station with HTTP 401. Nil admits everyone.
Authenticate func(r *http.Request, identity string) error
// 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 of requests and answers
// (for a station whose deviations the application handles itself).
SkipValidation bool
// OnInvalid, when set, decides about a station's request that fails
// the schema check: return nil to hand it to the handler anyway (a
// deviation the application tolerates; see ocpp.Deviations) or an
// error to refuse it, normally verr. Unset, such requests are refused.
OnInvalid func(st *Station, action string, payload json.RawMessage, verr *ocpp.RPCError) error
// CheckSerial closes the connection of a 2.x station using a TLS client
// certificate whose BootNotification serial number differs from the
// certificate's common name (security profile 3).
CheckSerial bool
// OnConnect and OnDisconnect follow the registry.
OnConnect func(st *Station)
OnDisconnect func(st *Station, err error)
// AcceptOptions are passed to websocket.Accept (Subprotocols is set by
// the Server); for example compression or origin checks.
AcceptOptions websocket.AcceptOptions
}
Config sets up a Server. The zero value accepts 2.1, 2.0.1 and 1.6 from anyone, which suits tests only: set Authenticate in production.
type HandlerFunc ¶
HandlerFunc answers a CALL (or takes a 2.1 SEND, whose answer is dropped; ocpp.IsSend(ctx) tells them apart) from station st. Return an *ocpp.RPCError to choose the CALLERROR, any other error for an InternalError.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a central system. Register handlers before serving.
func (*Server) Handle ¶
func (s *Server) Handle(action string, h HandlerFunc)
Handle routes action, in every version, to h.
func (*Server) HandleVersion ¶
func (s *Server) HandleVersion(version, action string, h HandlerFunc)
HandleVersion routes action in version to h, ahead of a Handle for every version.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP accepts one charging station and serves it until it leaves.
type Station ¶
type Station struct {
// contains filtered or unexported fields
}
Station is one connected charging station.
func (*Station) Call ¶
Call sends a CALL and returns the station's answer. Unless validation is off, the request is checked before it is sent (a failure is returned as an *ocpp.RPCError and nothing is sent) and the answer after: an answer outside the schema is returned with an *ocpp.ResultError (on 2.1 the station is also told with a CALLRESULTERROR). A CALLERROR comes back as an *ocpp.CallError.
func (*Station) Done ¶
func (st *Station) Done() <-chan struct{}
Done is closed when the station disconnects.
func (*Station) TLS ¶
func (st *Station) TLS() *tls.ConnectionState
TLS is the TLS state of the connection (nil over plain WebSocket).