process

package
v0.0.0-...-89c8f47 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHeaters                         = errors.New("can't execute process without heaters")
	ErrNoTSensors                        = errors.New("can't execute process without temperature sensors")
	ErrNoSuchPhase                       = errors.New("requested phase number doesn't exist")
	ErrWrongHeaterID                     = errors.New("requested heater ID doesn't exist")
	ErrWrongSensorID                     = errors.New("requested sensor ID doesn't exist")
	ErrWrongGpioID                       = errors.New("requested gpio ID doesn't exist")
	ErrWrongHeaterPower                  = errors.New("power must be in range <0, 100>")
	ErrDifferentGPIOSConfig              = errors.New("different number of gpio configs and gpios")
	ErrHeaterConfigDiffersFromHeatersLen = errors.New("different number of heaters configs and heaters")
	ErrByTimeWrongTime                   = errors.New("timeleft must be greater than 0")
	ErrByTemperatureWrongID              = errors.New("chosen ByTemperature, but id doesn't exist")
	ErrUnknownType                       = errors.New("MoveToNextType unknown")
	ErrNotRunning                        = errors.New("not running")
	ErrTooManyErrorOnTemperature         = errors.New("too many consecutive errors on Temperature")
	ErrSetPower                          = errors.New("on heater SetPower")
	ErrSetValue                          = errors.New("on output Set")
	ErrDuplicatedID                      = errors.New("duplicated ID in config")
)

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Unix() int64 // Unix returns seconds since 01.01.1970 UTC
}

type Config

type Config struct {
	PhaseNumber uint          `json:"phase_number"`
	Phases      []PhaseConfig `json:"phases"`
	GlobalGPIO  []GPIOConfig  `json:"global_gpio"`
	Sensors     []string      `json:"sensors"`
}

type GPIOConfig

type GPIOConfig struct {
	Enabled    bool    `json:"enabled"`
	ID         string  `json:"id"`
	SensorID   string  `json:"sensor_id"`
	TLow       float64 `json:"t_low"`
	THigh      float64 `json:"t_high"`
	Hysteresis float64 `json:"hysteresis"`
	Inverted   bool    `json:"inverted"`
}

type GPIOPhaseStatus

type GPIOPhaseStatus struct {
	ID    string `json:"id"`
	State bool   `json:"state"`
}

type Heater

type Heater interface {
	ID() string             // ID returns unique ID of interface
	SetPower(pwr int) error // SetPower set power (in %) for that Heater. 0% means Heater should be disabled
}

type HeaterPhaseConfig

type HeaterPhaseConfig struct {
	ID    string `json:"ID"`
	Power int    `json:"power"`
}

type HeaterPhaseStatus

type HeaterPhaseStatus struct {
	HeaterPhaseConfig
}

type MoveToNextConfig

type MoveToNextConfig struct {
	Type            MoveToNextType `json:"type"`
	Sensors         []string       `json:"sensors"`
	SensorID        string         `json:"sensor_id"`
	SensorThreshold float64        `json:"sensor_threshold"`
	TimeLeft        int64          `json:"time_left"`
}

type MoveToNextStatus

type MoveToNextStatus struct {
	Type        MoveToNextType              `json:"type"`
	TimeLeft    int64                       `json:"time_left"`
	Temperature MoveToNextStatusTemperature `json:"temperature,omitempty"`
}

type MoveToNextStatusTemperature

type MoveToNextStatusTemperature struct {
	SensorID        string  `json:"sensor_id"`
	SensorThreshold float64 `json:"sensor_threshold"`
}

type MoveToNextType

type MoveToNextType int
const (
	ByTime MoveToNextType = iota
	ByTemperature
)

type Option

type Option func(p *Process)

func WithClock

func WithClock(c Clock) Option

type Output

type Output interface {
	ID() string           // ID returns unique ID of interface
	Set(value bool) error // Set applies value to output
}

type PhaseConfig

type PhaseConfig struct {
	Next    MoveToNextConfig    `json:"next"`
	Heaters []HeaterPhaseConfig `json:"heaters"`
	GPIO    []GPIOConfig        `json:"gpio"`
}

type Process

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

func New

func New(opts ...Option) *Process

func (*Process) Finish

func (p *Process) Finish() (Status, error)

func (Process) GetConfig

func (c Process) GetConfig() Config

func (*Process) MoveToNext

func (p *Process) MoveToNext() (Status, error)

func (*Process) Process

func (p *Process) Process() (Status, error)

func (*Process) Run

func (p *Process) Run() (Status, error)

func (*Process) Running

func (p *Process) Running() bool

func (Process) SetGPIOGlobalConfig

func (c Process) SetGPIOGlobalConfig(conf []GPIOConfig) error

func (*Process) SetPhaseConfig

func (p *Process) SetPhaseConfig(nb uint, conf PhaseConfig) error

func (Process) SetPhaseNumber

func (c Process) SetPhaseNumber(number uint)

func (Process) UpdateHeaters

func (c Process) UpdateHeaters(heaters []Heater)

func (Process) UpdateOutputs

func (c Process) UpdateOutputs(outputs []Output)

func (Process) UpdateSensors

func (c Process) UpdateSensors(sensors []Sensor)

func (Process) Validate

func (c Process) Validate() error

type Sensor

type Sensor interface {
	ID() string                    // ID returns unique ID of interface
	Temperature() (float64, error) // Temperature returns latest temperature read from sensor
}

type Status

type Status struct {
	Running     bool                     `json:"running"`
	Done        bool                     `json:"done"`
	PhaseNumber uint                     `json:"phase_number"`
	StartTime   time.Time                `json:"start_time"`
	EndTime     time.Time                `json:"end_time"`
	Next        MoveToNextStatus         `json:"next"`
	Heaters     []HeaterPhaseStatus      `json:"heaters"`
	Temperature []TemperaturePhaseStatus `json:"temperature"`
	GPIO        []GPIOPhaseStatus        `json:"gpio"`
	Errors      []string                 `json:"errors"`
}

type TemperaturePhaseStatus

type TemperaturePhaseStatus struct {
	ID          string  `json:"ID"`
	Temperature float64 `json:"temperature"`
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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