control

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package control is the channel between plugyard commands and the process that owns a running site: HTTP with JSON over a Unix domain socket in the data directory (see docs/adr/0004). The channel is internal and may change between versions.

Index

Constants

View Source
const (
	OpStart   = "start"
	OpStop    = "stop"
	OpRestart = "restart"
	OpKill    = "kill"
	OpRemove  = "rm"
)

Power operations that PowerRequest can carry.

View Source
const (
	ActionPlug    = "plug"
	ActionUnplug  = "unplug"
	ActionTap     = "tap"
	ActionFault   = "fault"
	ActionClear   = "clear"
	ActionOffline = "offline"
	ActionOnline  = "online"
	ActionReboot  = "reboot"
)

Actions that ExecRequest can carry.

View Source
const ProtocolVersion = 6

ProtocolVersion changes whenever requests or answers change shape. A command only talks to a site that speaks the same version.

Variables

View Source
var ErrAlreadyRunning = errors.New("the site is already running")

ErrAlreadyRunning is returned by Serve when a live process already serves a site of the same name.

Functions

func SocketPath

func SocketPath(dataDir, siteName string) string

SocketPath returns the socket file of the site with the given name.

func WholeCharger

func WholeCharger(action string) bool

WholeCharger reports whether an action is about a charger as a whole and not one of its connectors.

Types

type ChargerState

type ChargerState struct {
	Site string `json:"site"`
	// Name is the charger's name, unique on the machine.
	Name string `json:"name"`
	// Powered says whether the charger is powered on. It is not part of the
	// JSON output: a charger that is off shows "stopped" as its connection.
	Powered bool `json:"-"`
	charger.Snapshot
}

ChargerState is a charger's state together with the site it runs in.

type Client

type Client struct {
	// Info describes the site behind the socket.
	Info Info
	// contains filtered or unexported fields
}

Client talks to one running site.

func Discover

func Discover(ctx context.Context, dataDir string) ([]*Client, error)

Discover returns a client for every site running under dataDir, sorted by site name. Sockets left behind by processes that died are removed.

func Probe

func Probe(ctx context.Context, dataDir, siteName string) (*Client, error)

Probe returns a client for the site with the given name if it is running under dataDir.

func (*Client) Chargers

func (c *Client) Chargers(ctx context.Context) ([]ChargerState, error)

Chargers returns the state of every charger in the site.

func (*Client) Close

func (c *Client) Close()

Close releases the client's connection.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, req ExecRequest) ([]ExecResult, error)

Exec runs an action on chargers of the site and returns one result per charge point ID, in the order given.

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, chargePointID string) (Inspection, error)

Inspect returns everything the site knows about one of its chargers.

func (*Client) Power

func (c *Client) Power(ctx context.Context, req PowerRequest) ([]ExecResult, error)

Power powers chargers of the site on or off, or removes them, and returns one result per charge point ID, in the order given.

func (*Client) Shutdown

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

Shutdown asks the site to shut down in an orderly way and waits until its process has stopped answering.

type ExecRequest

type ExecRequest struct {
	ChargePointIDs []string `json:"chargePointIds"`
	Action         string   `json:"action"`
	// Connector is the connector the action is about. For a fault it may be
	// 0, meaning the charger as a whole.
	Connector int `json:"connector"`
	// Fault is the fault a fault action reports.
	Fault charger.Fault `json:"fault"`
	// For is how long an offline action lasts; zero means until online.
	For time.Duration `json:"for,omitempty"`
	// Tag is the tag presented by a tap.
	Tag string `json:"tag,omitempty"`
	// EVPreset names an EV preset of the site to plug in.
	EVPreset string `json:"evPreset,omitempty"`
	// EV holds the EV parameters given with a plug. They take precedence
	// over the preset.
	EV ev.Overrides `json:"ev"`
}

ExecRequest asks a site to run one action on some of its chargers.

type ExecResult

type ExecResult struct {
	ChargePointID string `json:"chargePointId"`
	// Connector is zero for an operation on the whole charger.
	Connector int  `json:"connector,omitempty"`
	OK        bool `json:"ok"`
	// Message is the outcome when OK, and the reason when not.
	Message string `json:"message"`
}

ExecResult says what an action did on one charger.

type Info

type Info struct {
	Protocol int    `json:"protocol"`
	Site     string `json:"site"`
	PID      int    `json:"pid"`
	// Chargers is the number of chargers in the site, powered on or not.
	Chargers int `json:"chargers"`
	// Powered is the number of chargers that are powered on.
	Powered int `json:"powered"`
	// CSMS lists the distinct CSMS URLs the site connects to.
	CSMS []string `json:"csms"`
	// Speed is how many times faster than real time EVs charge.
	Speed float64 `json:"speed"`
}

Info identifies the process behind a socket.

type Inspection

type Inspection struct {
	Model   *model.Model `json:"model"`
	CSMSURL string       `json:"csmsUrl"`
	// State is nil for a charger that has never run.
	State *charger.State `json:"state"`
}

Inspection is everything a site knows about one of its chargers.

type PowerRequest

type PowerRequest struct {
	ChargePointIDs []string `json:"chargePointIds"`
	Op             string   `json:"op"`
	// Force lets OpRemove stop a running charger first.
	Force bool `json:"force,omitempty"`
}

PowerRequest asks a site to power some of its chargers on or off, or to remove them.

type Server

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

Server answers commands for one running site.

func Serve

func Serve(dataDir string, s *site.Site, shutdown func()) (*Server, error)

Serve starts answering commands for s on its socket in dataDir. shutdown is called when a command asks the site to shut down.

func (*Server) Close

func (srv *Server) Close()

Close stops answering commands and removes the socket.

Jump to

Keyboard shortcuts

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