config

package module
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: GPL-3.0 Imports: 15 Imported by: 20

README

go-config

Documentation

Index

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 (
	BatteryKey = "battery"
)
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 WindowsKey = "windows"

Variables

View Source
var LeadAcid12V = BatteryType{
	Name:       "lead-acid-12v",
	MinVoltage: 9.0,
	MaxVoltage: 14.0,
	Voltages:   []float32{11.3, 11.5, 11.66, 11.81, 11.96, 12.1, 12.24, 12.37, 12.50, 12.62, 12.73},
	Percent:    []float32{0.00, 10.0, 20.00, 30.00, 40.00, 50.0, 60.00, 70.00, 80.00, 90.00, 100.0},
}
View Source
var LiIonBattery = BatteryType{
	Name:       "li-ion",
	MinVoltage: 2.9,
	MaxVoltage: 4.3,
	Voltages:   []float32{3.4, 3.46, 3.51, 3.56, 3.58, 3.61, 3.62, 3.64, 3.67, 3.71, 3.76, 3.81, 3.86, 3.90, 3.93, 3.97, 4.00, 4.04, 4.07, 4.11, 4.170},
	Percent:    []float32{0.0, 5.00, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0},
}
View Source
var LimeBattery = BatteryType{
	Name:       "lime",
	MinVoltage: 29,
	MaxVoltage: 42.5,
	Voltages:   []float32{30.0, 30.1, 30.2, 30.4, 30.5, 30.6, 30.7, 30.8, 31.0, 31.1, 31.2, 31.3, 31.4, 31.6, 31.7, 31.8, 31.9, 32.0, 32.2, 32.3, 32.4, 32.5, 32.6, 32.8, 32.9, 33.0, 33.1, 33.2, 33.4, 33.5, 33.6, 33.7, 33.8, 34.0, 34.1, 34.2, 34.3, 34.4, 34.6, 34.7, 34.8, 34.9, 35.0, 35.2, 35.3, 35.4, 35.5, 35.6, 35.8, 35.9, 36.0, 36.1, 36.2, 36.4, 36.5, 36.6, 36.7, 36.8, 37.0, 37.1, 37.2, 37.3, 37.4, 37.6, 37.7, 37.8, 37.9, 38.0, 38.2, 38.3, 38.4, 38.5, 38.6, 38.8, 38.9, 39.0, 39.1, 39.2, 39.4, 39.5, 39.6, 39.7, 39.8, 40.0, 40.1, 40.2, 40.3, 40.4, 40.6, 40.7, 40.8, 40.9, 41.0, 41.2, 41.3, 41.4, 41.5, 41.6, 41.8, 41.9, 42.0},
	Percent:    []float32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100},
}
View Source
var PresetBatteryTypes = []BatteryType{
	LimeBattery,
	LiIonBattery,
	LeadAcid12V,
}

PresetBatteryTypes is a list of battery chemistries for the camera to choose from. Have the more preferred battery chemistries first (when auto detecting battery type from voltage multiple might be valid so it will choose the first one that is valid from hte list).

Functions

func GetAllSections added in v1.22.0

func GetAllSections() map[string]interface{}

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 {
	EnableVoltageReadings   bool         `mapstructure:"enable-voltage-readings"`
	CustomBatteryType       *BatteryType `mapstructure:"custom-battery-type"`       // When wanting to specify a custom battery type
	PresetBatteryType       string       `mapstructure:"preset-battery-type"`       // When wanting to use one from the default list.
	MinimumVoltageDetection float32      `mapstructure:"minimum-voltage-detection"` // Voltages below this will be considered 0V
}

Battery struct. Only CustomBatteryYype or PresetBatteryType should be set. Not both.

func DefaultBattery added in v1.2.0

func DefaultBattery() Battery

type BatteryType added in v1.24.0

type BatteryType struct {
	Name       string
	MinVoltage float32 // This is the minimum voltage that this battery type will be, this is used to guess what battery type is in use if not specified.
	MaxVoltage float32 // This is the maximum voltage that this battery type will be (including when charging), this is used to guess what battery type is in use if not specified.
	Voltages   []float32
	Percent    []float32
}

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) 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) 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"`
}

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"`
	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 Windows

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

func DefaultWindows

func DefaultWindows() Windows

Directories

Path Synopsis
cmd
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
JackTT - Gopher 🇻🇳