config

package module
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: GPL-3.0 Imports: 19 Imported by: 21

README

go-config

Documentation

Index

Constants

View Source
const (
	BatteryKey = "battery"

	// Voltage rails
	RailHV   = "hv"
	RailLV   = "lv"
	RailAuto = "auto"

	ChemistryLeadAcid = "lead-acid"
	ChemistryLiFePO4  = "lifepo4"
	ChemistryLiIon    = "li-ion"
	ChemistryLiPo     = "lipo"
	ChemistryCustom   = "custom"
)

Battery configuration constants

View Source
const (
	DefaultConfigDir = "/etc/cacophony"
	ConfigFileName   = "config.toml"

	TimeFormat = time.RFC3339
)
View Source
const AudioBaitKey = "audio-bait"
View Source
const AudioRecordingKey = "audio-recording"
View Source
const CommsKey = "comms"
View Source
const DeviceKey = "device"
View Source
const DeviceSetupKey = "device-setup"
View Source
const GPIOKey = "gpio"
View Source
const LeptonKey = "lepton"
View Source
const LocationKey = "location"
View Source
const ModemdKey = "modemd"
View Source
const PortsKey = "ports"
View Source
const SaltKey = "salt"
View Source
const SecretsKey = "secrets"
View Source
const TestHostsKey = "test-hosts"
View Source
const ThermalMotionKey = "thermal-motion"
View Source
const ThermalRecorderKey = "thermal-recorder"
View Source
const ThermalThrottlerKey = "thermal-throttler"
View Source
const TrapKey = "trap"
View Source
const WindowsKey = "windows"

Variables

ChemistryProfiles defines single-cell characteristics for each chemistry type

View Source
var LeadAcidChemistry = BatteryType{
	Chemistry:  ChemistryLeadAcid,
	MinVoltage: 1.94,
	MaxVoltage: 2.15,
	Voltages:   []float32{1.94, 1.95, 1.97, 1.99, 2.02, 2.04, 2.07, 2.09, 2.11, 2.13, 2.15},
	Percent:    []float32{0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100},
}
View Source
var LiFePO4Chemistry = BatteryType{
	Chemistry:  ChemistryLiFePO4,
	MinVoltage: 2.5,
	MaxVoltage: 3.4,
	Voltages:   []float32{2.5, 3.0, 3.2, 3.22, 3.25, 3.26, 3.27, 3.3, 3.32, 3.35, 3.4},
	Percent:    []float32{0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100},
}

Single-cell chemistry profiles

View Source
var LiIonChemistry = BatteryType{
	Chemistry:  ChemistryLiIon,
	MinVoltage: 2.8,
	MaxVoltage: 4.2,
	Voltages:   []float32{2.5, 3.0, 3.2, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.2},
	Percent:    []float32{0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100},
}

Based on NMC cells

View Source
var LiPoChemistry = BatteryType{
	Chemistry:  ChemistryLiPo,
	MinVoltage: 3.27,
	MaxVoltage: 4.2,
	Voltages:   []float32{3.27, 3.69, 3.73, 3.77, 3.8, 3.84, 3.87, 3.95, 4.02, 4.11, 4.2},
	Percent:    []float32{0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100},
}

Functions

func ConvertToStruct added in v1.26.0

func ConvertToStruct[T any](input interface{}) (T, error)

ConvertToStruct converts an interface{} to the target struct type T. Can input the struct itself, a pointer to the struct, or a map[string]interface{}

func GetAllSections added in v1.22.0

func GetAllSections() map[string]interface{}

func GetAvailableChemistries added in v1.25.3

func GetAvailableChemistries() []map[string]interface{}

GetAvailableChemistries returns list of available battery chemistries for manual selection

func GetDefaults added in v1.22.0

func GetDefaults() map[string]interface{}

func SetFs

func SetFs(f afero.Fs)

func SetLockFilePath

func SetLockFilePath(f func(string) string)

Types

type AudioBait added in v1.10.0

type AudioBait struct {
	Dir           string `mapstructure:"directory"`
	Card          int    `mapstructure:"card"`
	VolumeControl string `mapstructure:"volume-control"`
}

func DefaultAudioBait added in v1.10.0

func DefaultAudioBait() AudioBait

type AudioRecording added in v1.10.0

type AudioRecording struct {
	AudioMode string    `mapstructure:"audio-mode"`
	AudioSeed uint32    `mapstructure:"random-seed"`
	Updated   time.Time `mapstructure:"updated"`
}

func DefaultAudioRecording added in v1.10.0

func DefaultAudioRecording() AudioRecording

type Battery

type Battery struct {
	Chemistry               string  `mapstructure:"chemistry"`
	ManualCellCount         int     `mapstructure:"manual-cell-count"`
	ManuallyConfigured      bool    `mapstructure:"manually-configured"`
	MinimumVoltageDetection float32 `mapstructure:"minimum-voltage-detection"`
	DepletionHistoryHours   int     `mapstructure:"depletion-history-hours"`
	DepletionWarningHours   float32 `mapstructure:"depletion-warning-hours"`
	Updated                 any     `mapstructure:"updated,omitempty"`
}

Battery represents the main battery configuration

func DefaultBattery added in v1.2.0

func DefaultBattery() Battery

DefaultBattery returns default battery configuration

func (*Battery) ClearManualConfiguration added in v1.25.2

func (b *Battery) ClearManualConfiguration()

ClearManualConfiguration clears manual battery configuration and returns to auto-detection

func (*Battery) DetectCellCount added in v1.25.3

func (b *Battery) DetectCellCount(chemistry string, voltage float32) int

DetectCellCount estimates cell count for a given chemistry and voltage

func (*Battery) GetBatteryPack added in v1.25.3

func (b *Battery) GetBatteryPack(voltage float32) (*BatteryPack, error)

GetBatteryPack creates a BatteryPack from config and voltage reading

func (*Battery) GetBatteryType added in v1.25.0

func (b *Battery) GetBatteryType() *BatteryType

GetBatteryType returns the configured battery chemistry profile Deprecated: Use GetChemistryProfile or GetBatteryPack instead

func (*Battery) GetChemistryProfile added in v1.25.3

func (b *Battery) GetChemistryProfile() (*BatteryType, error)

GetChemistryProfile returns the chemistry profile for the configured chemistry

func (*Battery) IsManuallyConfigured added in v1.25.2

func (b *Battery) IsManuallyConfigured() bool

IsManuallyConfigured returns true if battery type is manually set by user

func (*Battery) NewBatteryPack added in v1.25.3

func (b *Battery) NewBatteryPack(chemistry string, cellCount int) (*BatteryPack, error)

NewBatteryPack creates a new battery pack with the specified chemistry and cell count

func (*Battery) SetManualChemistry added in v1.25.3

func (b *Battery) SetManualChemistry(chemistry string) error

SetManualChemistry sets a manual battery chemistry override

func (*Battery) SetManualConfiguration added in v1.25.3

func (b *Battery) SetManualConfiguration(chemistry string, cellCount int) error

SetManualConfiguration sets manual battery chemistry and cell count

type BatteryPack added in v1.25.3

type BatteryPack struct {
	Type      *BatteryType
	CellCount int
}

BatteryPack represents a complete battery pack with chemistry and cell count

func AutoDetectBatteryPack added in v1.26.1

func AutoDetectBatteryPack(voltage float32, minVoltage float32, maxVoltage float32) (*BatteryPack, error)

AutoDetectBatteryPack detects battery chemistry and cell count based on voltage It first checks against the authoritative voltage table, then falls back to range matching

func (*BatteryPack) DetectCellCount added in v1.25.3

func (bp *BatteryPack) DetectCellCount(voltage float32) int

DetectCellCount estimates the number of cells based on voltage reading and chemistry

func (*BatteryPack) GetScaledMaxVoltage added in v1.25.3

func (bp *BatteryPack) GetScaledMaxVoltage() float32

GetScaledMaxVoltage returns the maximum voltage for the entire pack

func (*BatteryPack) GetScaledMinVoltage added in v1.25.3

func (bp *BatteryPack) GetScaledMinVoltage() float32

GetScaledMinVoltage returns the minimum voltage for the entire pack

func (*BatteryPack) VoltageToPercent added in v1.25.3

func (bp *BatteryPack) VoltageToPercent(voltage float32) (float32, error)

VoltageToPercent converts pack voltage to percentage using scaled single-cell curve

type BatteryType added in v1.24.0

type BatteryType struct {
	Chemistry  string  `mapstructure:"chemistry"`
	MinVoltage float32 `mapstructure:"min-voltage"` // Per-cell minimum voltage
	MaxVoltage float32 `mapstructure:"max-voltage"` // Per-cell maximum voltage

	// Single-cell discharge curve
	Voltages []float32 `mapstructure:"voltages"`
	Percent  []float32 `mapstructure:"percent"`
}

BatteryType defines a single-cell battery chemistry characteristics

func (*BatteryType) NormalizeCurves added in v1.25.0

func (bt *BatteryType) NormalizeCurves()

NormalizeCurves ensures voltage curves are properly set with backward compatibility

type Comms added in v1.22.0

type Comms struct {
	Enable               bool   `mapstructure:"enable"`
	TrapEnabledByDefault bool   `mapstructure:"trap-enabled-by-default"` // If no animals are seen should the trap be enabled or not.
	CommsOut             string `mapstructure:"comms-out"`               // "uart" or "high-low"
	Bluetooth            bool   `mapstructure:"bluetooth"`               // Bluetooth can only be enabled if UART is not in use.

	PowerOutput     string        `mapstructure:"power-output"`      // "on", "off", "comms-only"
	PowerUpDuration time.Duration `mapstructure:"power-up-duration"` // When PowerOutput is set to "comms-only" how long should it be powered up before sending data.

	TrapSpecies  map[string]int32 `mapstructure:"trap-species"`  // Species with set confidence to trap
	TrapDuration time.Duration    `mapstructure:"trap-duration"` // How long to keep a trap active for after seeing a trapped species

	ProtectSpecies  map[string]int32 `mapstructure:"protect-species"`  // Species with set confidence to protect
	ProtectDuration time.Duration    `mapstructure:"protect-duration"` // How long to keep a trap inactive for after seeing a protected species

}

func DefaultComms added in v1.22.0

func DefaultComms() Comms

type Config

type Config struct {
	AutoWrite bool
	// contains filtered or unexported fields
}

func New

func New(dir string) (*Config, error)

New created a new config and loads files from the given directory

func (*Config) Get

func (c *Config) Get(key string) interface{}

func (*Config) GetAllValues added in v1.22.0

func (c *Config) GetAllValues() (map[string]interface{}, error)

func (*Config) ReadInConfig added in v1.27.0

func (c *Config) ReadInConfig() error

func (*Config) Reload added in v1.6.1

func (c *Config) Reload() error

func (*Config) Set

func (c *Config) Set(key string, value interface{}) error

Set can only update one section at a time.

func (*Config) SetField

func (c *Config) SetField(sectionKey, valueKey, value string, force bool) error

func (*Config) SetFromMap

func (c *Config) SetFromMap(sectionKey string, newConfig map[string]interface{}, force bool) error

SetFromMap can only update one section at a time.

func (*Config) SetMultipleSections added in v1.27.0

func (c *Config) SetMultipleSections(newConfig map[string]interface{}) error

func (*Config) Unmarshal

func (c *Config) Unmarshal(key string, raw interface{}) error

func (*Config) Unset

func (c *Config) Unset(key string) error

func (*Config) Update

func (c *Config) Update() error

func (*Config) Write

func (c *Config) Write() error

type ConfigArgs added in v1.22.0

type ConfigArgs struct {
	ConfigDir string `arg:"--config-dir" default:"/etc/cacophony/" help:"path to configuration directory"`
}

type Device

type Device struct {
	Group  string
	ID     int
	Name   string
	Server string
}

type DeviceSetup added in v1.9.0

type DeviceSetup struct {
	IR bool `mapstructure:"ir"`

	// S or L ( for small trap or large trap)
	TrapSize string `mapstructure:"trap-size"`
}

func DefaultDeviceSetup added in v1.11.0

func DefaultDeviceSetup() DeviceSetup

type GPIO

type GPIO struct {
	ThermalCameraPower string `mapstructure:"thermal-camera-power"`
	ModemPower         string `mapstructure:"modem-power"`
	UartTx             string `mapstructure:"uart-tx"`
}

func DefaultGPIO

func DefaultGPIO() GPIO

type Lepton

type Lepton struct {
	SPISpeed    int64  `mapstructure:"spi-speed"`
	FrameOutput string `mapstructure:"frame-output"`
}

func DefaultLepton

func DefaultLepton() Lepton

type Location

type Location struct {
	Timestamp time.Time
	Accuracy  float32
	Altitude  float32
	Latitude  float32
	Longitude float32
}

func DefaultWindowLocation

func DefaultWindowLocation() Location

Default location used when setting windows relative to sunset/sunrise

type Modem

type Modem struct {
	Name            string `mapstructure:"name"`
	NetDev          string `mapstructure:"net-dev"`
	VendorProductID string `mapstructure:"vendor-product-id"`
}

type Modemd

type Modemd struct {
	TestInterval           time.Duration `mapstructure:"test-interval"`
	InitialOnDuration      time.Duration `mapstructure:"initial-on-duration"`
	FindModemTimeout       time.Duration `mapstructure:"find-modem-timeout"`
	ConnectionTimeout      time.Duration `mapstructure:"connection-timeout"`
	RequestOnDuration      time.Duration `mapstructure:"request-on-duration"`
	RetryInterval          time.Duration `mapstructure:"retry-interval"`
	RetryFindModemInterval time.Duration `mapstructure:"retry-find-modem-interval"`
	MinConnDuration        time.Duration `mapstructure:"min-connection-duration"`
	MaxOffDuration         time.Duration `mapstructure:"max-off-duration"`
	Modems                 []Modem       `mapstructure:"modems"`
}

func DefaultModemd

func DefaultModemd() Modemd

type Ports

type Ports struct {
	Managementd int
}

func DefaultPorts

func DefaultPorts() Ports

type Salt added in v1.11.0

type Salt struct {
	AutoUpdate bool `mapstructure:"auto-update"`
}

func DefaultSalt added in v1.11.0

func DefaultSalt() Salt

type Secrets

type Secrets struct {
	DevicePassword string `mapstructure:"device-password"`
}

type TestHosts

type TestHosts struct {
	URLs         []string
	PingWaitTime time.Duration `mapstructure:"ping-wait-time"`
	PingRetries  int           `mapstructure:"ping-retries"`
}

func DefaultTestHosts

func DefaultTestHosts() TestHosts

type ThermalMotion

type ThermalMotion struct {
	DynamicThreshold  bool   `mapstructure:"dynamic-threshold"`
	TempThreshMin     uint16 `mapstructure:"temp-thresh-min"`
	TempThreshMax     uint16 `mapstructure:"temp-thresh-max"`
	TempThresh        uint16 `mapstructure:"temp-thresh"`
	DeltaThresh       uint16 `mapstructure:"delta-thresh"`
	CountThresh       int    `mapstructure:"count-thresh"`
	FrameCompareGap   int    `mapstructure:"frame-compare-gap"`
	UseOneDiffOnly    bool   `mapstructure:"use-one-diff-only"`
	TriggerFrames     int    `mapstructure:"trigger-frames"`
	WarmerOnly        bool   `mapstructure:"warmer-only"`
	EdgePixels        int    `mapstructure:"edge-pixels"`
	Verbose           bool   `mapstructure:"verbose"`
	RunClassifier     bool   `mapstructure:"run-classifier"`
	TrackingEvents    bool   `mapstructure:"tracking-events"`
	DoTracking        bool   `mapstructure:"do-tracking"`
	BluetoothBeacons  bool   `mapstructure:"bluetooth-beacons"`
	PostProcessEvents bool   `mapstructure:"postprocess-events"`
	PostProcess       bool   `mapstructure:"postprocess"`
}

func DefaultLepton35Motion added in v1.5.0

func DefaultLepton35Motion() ThermalMotion

func DefaultLeptonMotion added in v1.5.0

func DefaultLeptonMotion() ThermalMotion

func DefaultThermalMotion

func DefaultThermalMotion(cameraModel string) ThermalMotion

type ThermalRecorder

type ThermalRecorder struct {
	OutputDir        string    `mapstructure:"output-dir"`
	MinDiskSpaceMB   uint64    `mapstructure:"min-disk-space-mb"`
	MinSecs          int       `mapstructure:"min-secs"`
	MaxSecs          int       `mapstructure:"max-secs"`
	PreviewSecs      int       `mapstructure:"preview-secs"`
	ConstantRecorder bool      `mapstructure:"constant-recorder"`
	UseLowPowerMode  bool      `mapstructure:"use-low-power-mode"`
	InstantClassify  bool      `mapstructure:"instant-classify"`
	Updated          time.Time `mapstructure:"updated"`
}

func DefaultThermalRecorder

func DefaultThermalRecorder() ThermalRecorder

type ThermalThrottler

type ThermalThrottler struct {
	Activate   bool
	BucketSize time.Duration `mapstructure:"bucket-size"`
	MinRefill  time.Duration `mapstructure:"min-refill"`
}

func DefaultThermalThrottler

func DefaultThermalThrottler() ThermalThrottler

type Trap added in v1.33.0

type Trap struct {
	Config map[string]any `mapstructure:"config"`
}

func DefaultTrap added in v1.33.0

func DefaultTrap() Trap

type Windows

type Windows struct {
	StartRecording string    `mapstructure:"start-recording"`
	StopRecording  string    `mapstructure:"stop-recording"`
	Updated        time.Time `mapstructure:"updated"`
}

func DefaultWindows

func DefaultWindows() Windows

Directories

Path Synopsis
cmd
internal
cacophony-config-sync
cacophony-config-sync - sync device settings with Cacophony Project API.
cacophony-config-sync - sync device settings with Cacophony Project API.

Jump to

Keyboard shortcuts

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