Documentation
¶
Overview ¶
Package charger simulates one charger: a single charge point ID with its own connection to the CSMS.
Index ¶
- Constants
- Variables
- type CSMS
- type Charger
- func (c *Charger) ClearFault(connectorID int) (string, error)
- func (c *Charger) Fail(what string) (string, error)
- func (c *Charger) Fault(connectorID int, fault Fault) (string, error)
- func (c *Charger) ID() string
- func (c *Charger) Kill()
- func (c *Charger) Offline(d time.Duration) (string, error)
- func (c *Charger) Online() (string, error)
- func (c *Charger) Plug(ctx context.Context, connectorID int, params ev.Params) (string, error)
- func (c *Charger) Reboot() (string, error)
- func (c *Charger) Run(ctx context.Context) error
- func (c *Charger) Snapshot() Snapshot
- func (c *Charger) State() State
- func (c *Charger) Tap(ctx context.Context, connectorID int, tag string) (string, error)
- func (c *Charger) URL() string
- func (c *Charger) Unplug(connectorID int) (string, error)
- type Config
- type ConfigKey
- type ConnectorSnapshot
- type ConnectorState
- type Declared
- type DeclaredConnector
- type DeclaredEV
- type Entry
- type EntryKind
- type Fault
- type InstalledProfile
- type QueuedMessage
- type Snapshot
- type State
- type Timing
- type TxState
Constants ¶
const ( Connecting = "connecting" Online = "online" Offline = "offline" )
Connection states, as shown by "plugyard ps".
const ( FailDownload = "download" FailInstall = "install" FailUpload = "upload" )
What Fail can make fail.
const Stopped = "stopped"
Stopped is the connection state shown for a charger that is powered off.
Variables ¶
var Failures = []string{FailDownload, FailInstall, FailUpload}
Failures lists what Fail accepts.
Functions ¶
This section is empty.
Types ¶
type CSMS ¶
type CSMS struct {
// URL is the CSMS endpoint, ws:// or wss://. The charge point ID is
// appended to its path.
URL string
// Password, if set, is sent with HTTP Basic authentication, with the
// charge point ID as the user name.
Password string
// InsecureSkipVerify disables TLS certificate verification.
InsecureSkipVerify bool
}
CSMS says how to reach the CSMS.
type Charger ¶
type Charger struct {
// contains filtered or unexported fields
}
Charger is one simulated charger. It is powered on once, with Run; a charger that has been powered off is replaced by a new one made from its saved state.
func (*Charger) ClearFault ¶
ClearFault recovers a connector, or the charger as a whole, from its fault.
func (*Charger) Fail ¶ added in v0.1.2
Fail makes the next firmware download, firmware installation or diagnostics upload fail, as a broken link or a bad file would. It stays set until that step has failed, or the charger is powered off.
func (*Charger) Fault ¶
Fault makes a connector, or with connector 0 the charger as a whole, report a fault. A transaction running there ends.
func (*Charger) Kill ¶
func (c *Charger) Kill()
Kill cuts the charger's power: Run returns at once, the connection drops with no message, and nothing that happened since the last save is kept.
func (*Charger) Offline ¶
Offline takes the charger's network connection down. The charger keeps running and queues what it has to tell the CSMS. It stays away until Online, or for the given time when that is not zero.
func (*Charger) Plug ¶
Plug plugs an EV into a connector. It returns a description of what happened, or an error if the action could not be carried out.
func (*Charger) Reboot ¶
Reboot reboots the charger as a person at the charger would: transactions end, and the charger boots again.
func (*Charger) Run ¶
Run powers the charger on and keeps it running until ctx is cancelled, which shuts it down in an orderly way, or until Kill cuts its power. While running, the charger reconnects by itself whenever the connection is lost. A charger can be powered on only once.
func (*Charger) Tap ¶
Tap presents a tag at a connector: it stops the connector's transaction if the tag is entitled to, and otherwise asks the CSMS to authorize the tag and starts a transaction. A tag the CSMS rejects is an outcome, not an error.
type Config ¶
type Config struct {
// ID is the charge point ID.
ID string
Model *model.Model
CSMS CSMS
// Speed multiplies the rate of EV charging and energy accumulation.
// Zero means 1. Protocol timers are not affected.
Speed float64
Timing Timing
// BeforeDial, if set, is called before every connection attempt and
// may wait. A site uses it to pace the connections of its chargers.
BeforeDial func(ctx context.Context) error
// Log, if set, receives the charger's events and OCPP messages. It is
// called from several goroutines and must not block.
Log func(Entry)
// Restore, if set, is the state saved when the charger last had power.
Restore *State
// Declared, if set, is the state the charger's site file says it is in
// each time it powers on. Where it speaks, it takes the place of
// Restore.
Declared *Declared
// Diagnostics, if set, returns the charger's log between two moments, as
// the file GetDiagnostics asks for. A zero time leaves that end open.
Diagnostics func(from, to time.Time) ([]byte, error)
// AllowUploads lists the hosts diagnostics may be uploaded to besides
// the machine the CSMS is on.
AllowUploads []string
// UploadsInsecureSkipVerify turns off the check of the certificate of
// an https or ftps server diagnostics are uploaded to.
UploadsInsecureSkipVerify bool
// Save, if set, is given the charger's state whenever something worth
// keeping has changed: at once for transactions and queued messages, and
// every MeterSaveInterval seconds for meter readings.
Save func(State) error
}
Config describes one charger.
type ConfigKey ¶
type ConfigKey struct {
Key string `json:"key"`
Value string `json:"value"`
Readonly bool `json:"readonly"`
}
ConfigKey is one configuration key of a charger.
type ConnectorSnapshot ¶
type ConnectorSnapshot struct {
ID int `json:"id"`
Status string `json:"status"`
// TransactionID is zero when there is no transaction, or when the CSMS
// has not confirmed it yet.
TransactionID int `json:"transactionId,omitempty"`
// ErrorCode is the fault the connector reports, or empty.
ErrorCode string `json:"errorCode,omitempty"`
PowerW float64 `json:"powerW"`
MeterWh float64 `json:"meterWh"`
// SoC is the EV's state of charge from 0 to 1, or nil with no EV.
SoC *float64 `json:"soc,omitempty"`
}
ConnectorSnapshot is the state of a connector at one moment.
type ConnectorState ¶
type ConnectorState struct {
ID int `json:"id"`
MeterWh float64 `json:"meterWh"`
// EV is the EV plugged in, or nil.
EV *ev.State `json:"ev,omitempty"`
Finishing bool `json:"finishing,omitempty"`
// Fault is the fault the connector has, or nil.
Fault *Fault `json:"fault,omitempty"`
// Inoperative says the CSMS has made the connector unavailable.
Inoperative bool `json:"inoperative,omitempty"`
// Tx is the open transaction, or nil. A charger that starts with one was
// not shut down in an orderly way.
Tx *TxState `json:"tx,omitempty"`
}
ConnectorState is the saved state of one connector.
type Declared ¶ added in v0.3.0
type Declared struct {
// Connection is Offline for a charger that powers on with its network
// connection taken down, Stopped for one its site leaves powered off,
// and empty otherwise.
Connection string `json:"connection,omitempty"`
// Connectors holds the connectors the site file lists, in the order of
// their numbers. A connector that is not listed follows the saved
// state.
Connectors []DeclaredConnector `json:"connectors,omitempty"`
}
Declared is the declared state of a charger: the state its site file says it is in each time it powers on. Where it speaks, it takes the place of the saved state (ADR 0009).
func (*Declared) Check ¶ added in v0.3.0
Check lists what is wrong with a declared state for a charger of the given model.
func (*Declared) Over ¶ added in v0.3.0
Over returns the saved state of a charger that is powered off as it will stand once the declared state has taken its place: what the charger starts in. A transaction left open on a declared connector is left out, since it ends when the charger starts. Neither argument is changed, and s may be nil for a charger that has never run.
type DeclaredConnector ¶ added in v0.3.0
type DeclaredConnector struct {
// ID is the connector's number, or 0 for the charger as a whole.
ID int `json:"id"`
EV *DeclaredEV `json:"ev,omitempty"`
Fault *Fault `json:"fault,omitempty"`
}
DeclaredConnector is the declared state of one connector. It is declared whole: without an EV nothing is plugged in, and without a fault there is none.
type DeclaredEV ¶ added in v0.3.0
type DeclaredEV struct {
// Preset names the EV preset the EV is made from.
Preset string `json:"preset"`
// Params is that EV in full, as the presets stood when the site file
// was read.
Params ev.Params `json:"params"`
// Renew, when above zero, has the EV renewed once it is done: it leaves
// that long after it is full with no transaction, and a fresh one
// arrives that long after it left. It is real time, whatever the speed.
Renew time.Duration `json:"renew,omitempty"`
}
DeclaredEV is an EV a site file declares to be plugged in.
type Fault ¶
type Fault struct {
// Code is one of the OCPP 1.6 error codes, such as GroundFailure.
Code string `json:"code"`
// Info is free text about the fault.
Info string `json:"info,omitempty"`
// VendorCode is the vendor's own code for the fault.
VendorCode string `json:"vendorCode,omitempty"`
}
Fault is something wrong with a connector, or with the charger as a whole.
type InstalledProfile ¶
type InstalledProfile struct {
// ConnectorID is the connector the profile is on, where 0 stands for the
// charger as a whole.
ConnectorID int `json:"connectorId"`
// Installed is when the profile arrived. A schedule that names no start
// of its own starts then.
Installed time.Time `json:"installed"`
Profile v16.ChargingProfile `json:"profile"`
}
InstalledProfile is a charging profile the CSMS installed on a connector.
type QueuedMessage ¶
type QueuedMessage struct {
Action string `json:"action"`
Payload json.RawMessage `json:"payload"`
// TxRef, when not zero, names the transaction whose ID the message needs
// and the CSMS has not given yet.
TxRef int `json:"txRef,omitempty"`
}
QueuedMessage is a message still owed to the CSMS.
type Snapshot ¶
type Snapshot struct {
ChargePointID string `json:"chargePointId"`
Connection string `json:"connection"`
Connectors []ConnectorSnapshot `json:"connectors"`
// MessagesSent and MessagesReceived count the OCPP messages since the
// charger was powered on.
MessagesSent int64 `json:"messagesSent"`
MessagesReceived int64 `json:"messagesReceived"`
}
Snapshot is the state of a charger at one moment.
type State ¶
type State struct {
// SavedAt is the moment the state was taken. After a power cut it is the
// last moment the charger is known to have been delivering energy.
SavedAt time.Time `json:"savedAt"`
// Config holds the configuration keys the CSMS changed. Keys it did not
// change follow the model.
Config map[string]string `json:"config,omitempty"`
Connectors []ConnectorState `json:"connectors"`
// Outbox holds the messages still owed to the CSMS, in order.
Outbox []QueuedMessage `json:"outbox,omitempty"`
NextTxRef int `json:"nextTxRef,omitempty"`
// Fault and Inoperative describe the charger as a whole, which OCPP
// addresses as connector 0.
Fault *Fault `json:"fault,omitempty"`
Inoperative bool `json:"inoperative,omitempty"`
// AuthCache holds what the CSMS said about tags, when the authorization
// cache is on.
AuthCache map[string]v16.IDTagInfo `json:"authCache,omitempty"`
// Profiles holds the charging profiles the CSMS installed.
Profiles []InstalledProfile `json:"profiles,omitempty"`
// Firmware is the firmware a firmware update installed. It is empty
// while the charger runs the firmware of its model.
Firmware string `json:"firmware,omitempty"`
}
State is what a charger remembers while it is powered off: everything needed to come back as the same charger.
type Timing ¶
type Timing struct {
// CallTimeout is how long to wait for the CSMS to answer a message.
CallTimeout time.Duration
// ReconnectMin and ReconnectMax bound the wait between connection
// attempts, which doubles after each failure.
ReconnectMin time.Duration
ReconnectMax time.Duration
// Tick is how often the EVs on the connectors are advanced.
Tick time.Duration
// Reboot is how long the charger is away when it reboots.
Reboot time.Duration
// Download and Install are how long a firmware download and a firmware
// installation take at speed 1.
Download time.Duration
Install time.Duration
// UploadTimeout is how long one attempt to upload diagnostics may take.
UploadTimeout time.Duration
}
Timing holds the charger's own timeouts. Zero values select the defaults.
type TxState ¶
type TxState struct {
// Ref identifies the transaction inside the charger until the CSMS has
// given it an ID.
Ref int `json:"ref"`
ID int `json:"id,omitempty"`
IDTag string `json:"idTag"`
ParentIDTag string `json:"parentIdTag,omitempty"`
Begin *v16.MeterValue `json:"begin,omitempty"`
EVFull bool `json:"evFull,omitempty"`
// StartedAt is when the transaction started.
StartedAt time.Time `json:"startedAt,omitzero"`
}
TxState is the saved state of an open transaction.