Documentation
¶
Overview ¶
Package ocppj implements OCPP-J: OCPP messages framed as JSON arrays over a WebSocket connection. It knows nothing about individual OCPP actions, so every OCPP version that uses this framing can sit on top of it.
Index ¶
Constants ¶
const ( ErrNotImplemented = "NotImplemented" ErrNotSupported = "NotSupported" ErrInternalError = "InternalError" ErrProtocolError = "ProtocolError" ErrSecurityError = "SecurityError" ErrFormationViolation = "FormationViolation" ErrPropertyConstraintViolation = "PropertyConstraintViolation" ErrOccurrenceConstraintViolation = "OccurrenceConstraintViolation" ErrTypeConstraintViolation = "TypeConstraintViolation" ErrGenericError = "GenericError" )
Error codes defined by OCPP-J 1.6.
Variables ¶
var ErrClosed = errors.New("ocppj: connection closed")
ErrClosed is returned by Call when the connection is closed before the answer arrives.
Functions ¶
This section is empty.
Types ¶
type CallError ¶
type CallError struct {
Code string
Description string
Details json.RawMessage
}
CallError is an error answer to a call. It is returned by Conn.Call when the other side answers with an error, and returned by a Handler to answer with one.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is one OCPP-J connection. Both ends of a connection use the same type: each may call the other and must answer the other's calls.
func (*Conn) Call ¶
Call sends a call and waits for its answer, which is decoded into result unless result is nil. If the other side answers with an error, Call returns a *CallError.
func (*Conn) Done ¶
func (c *Conn) Done() <-chan struct{}
Done is closed when the connection has ended, for any reason.
func (*Conn) Drop ¶
func (c *Conn) Drop()
Drop ends the connection abruptly, without a close handshake, as a power cut or a network failure would.
func (*Conn) Err ¶
Err reports why the connection ended. It is only meaningful after Done is closed.
func (*Conn) Subprotocol ¶
Subprotocol returns the WebSocket subprotocol both sides agreed on, or "" if none was agreed.
type DialOptions ¶
type DialOptions struct {
Options
// Subprotocol is the WebSocket subprotocol to request, such as "ocpp1.6".
Subprotocol string
// Username and Password, when Password is set, are sent as HTTP Basic
// authentication.
Username string
Password string
// InsecureSkipVerify disables TLS certificate verification.
InsecureSkipVerify bool
}
DialOptions configure Dial.
type Handler ¶
Handler answers a call from the other side. It returns the result payload, or a CallError to answer with an error. A nil payload is sent as {}.
type Message ¶
type Message struct {
Type MessageType
ID string
Action string // Call
Payload json.RawMessage // Call and CallResult
ErrorCode string // CallError
ErrorDescription string // CallError
ErrorDetails json.RawMessage // CallError
}
Message is one decoded OCPP-J frame.
Call: [2, "<id>", "<action>", {payload}]
CallResult: [3, "<id>", {payload}]
CallError: [4, "<id>", "<code>", "<description>", {details}]
type MessageType ¶
type MessageType int
MessageType is the first element of an OCPP-J frame.
const ( TypeCall MessageType = 2 TypeCallResult MessageType = 3 TypeCallError MessageType = 4 )
type Options ¶
type Options struct {
// Handler answers incoming calls. Without one, every call is answered
// with NotImplemented.
Handler Handler
// OnFrame, if set, is given every frame sent and received, for logging.
// It must not block.
OnFrame func(dir Direction, frame []byte)
}
Options configure a Conn.