config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 10 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 config holds hamstack's own settings and paths.

Index

Constants

View Source
const (
	RigCtld  = "rigctld"  // rig control (hamlib): one per rig
	Mercury  = "mercury"  // HF modem: one per rig that uses it
	Direwolf = "direwolf" // VHF/UHF packet soundcard TNC: one per rig that uses it
	Pat      = "pat"      // Winlink client: one, shared by all rigs
	GPSD     = "gpsd"     // GPS daemon: one, shared by every program that wants a position
)

The kinds of service hamstack runs.

View Source
const (
	RigPortBase = 4532
	ArqPortBase = 8300
	ArqPortStep = 10
)

Ports. Each rig gets its own so several can run at once: rig control counts up from 4532, and a rig's Mercury modem uses a block of ten from 8300 (ARQ control, data, broadcast and web UI are derived from it, see MercuryPorts).

View Source
const GPSPort = 2948

GPSPort is the port of the gpsd hamstack runs. It is not gpsd's standard 2947, so a system-wide gpsd (often already running on a machine that has a GPS) cannot clash with it.

Variables

View Source
var Bauds = []int{300, 1200, 2400, 4800, 9600}

Bauds are the modem speeds hamstack offers.

Functions

func Dir

func Dir() (string, error)

Dir is hamstack's config directory (~/.config/hamstack).

func DirewolfPorts

func DirewolfPorts(r Rig) (agw, kiss int)

DirewolfPorts returns the AGW and KISS ports of a rig's Direwolf, derived like Mercury's so rigs never collide. The first rig gets Direwolf's own defaults, 8000 and 8001.

func MercuryPorts

func MercuryPorts(r Rig) (arq, data, broadcast, ui int)

MercuryPorts returns the ports of a rig's Mercury modem, all derived from ArqPort so they never collide between rigs: ARQ control, ARQ data, broadcast and the web UI.

func NormalizeBands

func NormalizeBands(in []string) ([]string, error)

NormalizeBands lower-cases, de-duplicates and validates a band list.

func NormalizeCallsign

func NormalizeCallsign(s string) string

NormalizeCallsign upper-cases and trims s.

func NormalizeGrid

func NormalizeGrid(s string) string

NormalizeGrid writes a locator in the conventional case: the first pair upper case and the sub-square lower case (EM10dg).

func Save

func Save(c Config) error

Save writes the config.

func ValidCallsign

func ValidCallsign(s string) bool

ValidCallsign reports whether s looks like an amateur callsign (optionally with -SSID).

func ValidGrid

func ValidGrid(s string) bool

ValidGrid reports whether s is a 4, 6 or 8 character Maidenhead grid locator.

func ValidID

func ValidID(s string) bool

ValidID reports whether s is usable as a station id.

Types

type AX25

type AX25 struct {
	Rig  string `json:"rig"`  // the rig whose Direwolf is attached
	Port string `json:"port"` // the name in /etc/ax25/axports
	// The port's settings; zero means the default (the station's callsign, the rig's Direwolf speed, 255, 2).
	Call   string `json:"call,omitempty"`
	Speed  int    `json:"speed,omitempty"`
	Paclen int    `json:"paclen,omitempty"`
	Window int    `json:"window,omitempty"`
}

AX25 says which rig offers its Direwolf to the Linux kernel's AX.25 stack, and under which axports name. That Direwolf is started with -p, which makes it offer a KISS pseudo-terminal that kissattach attaches to.

type Config

type Config struct {
	Rigs        []Rig     `json:"rigs,omitempty"`   // the radios; see Rig
	NoPat       bool      `json:"no_pat,omitempty"` // Pat is part of the setup unless this is set
	UI          bool      `json:"ui"`               // Mercury web UI (listens on all interfaces, no auth)
	Active      string    `json:"active"`           // id of the active station
	Grid        string    `json:"grid"`             // operator's Maidenhead grid square, reused by every program that wants a locator
	Stations    []Station `json:"stations"`
	Sites       []Site    `json:"sites,omitempty"` // named places; see Site
	GPS         *GPS      `json:"gps,omitempty"`   // the position source (gpsd); see GPS
	AX25        *AX25     `json:"ax25,omitempty"`  // Direwolf offered to the kernel's AX.25 stack; see AX25
	CurrentSite string    `json:"site,omitempty"`  // the site in use
	// Read only to upgrade configs from before rigs existed (see migrate); never written back.
	LegacyProfile string   `json:"profile,omitempty"`
	Chosen        []string `json:"components,omitempty"`
}

Config is the user's hamstack configuration.

func Load

func Load() (Config, error)

Load reads the config; a missing file gives an empty Config.

func (Config) ActiveRigs

func (c Config) ActiveRigs() []Rig

ActiveRigs are the rigs that are not switched off.

func (Config) ActiveStation

func (c Config) ActiveStation() (Station, bool)

ActiveStation returns the active station, if any.

func (*Config) AddRig

func (c *Config) AddRig(r Rig) error

AddRig validates and adds a rig, giving it free ports if it has none.

func (*Config) AddSite

func (c *Config) AddSite(s Site) error

AddSite validates and adds a site. The first one added becomes the current site.

func (*Config) AddStation

func (c *Config) AddStation(s Station) error

AddStation validates and adds a station. The first one added becomes active.

func (Config) Components

func (c Config) Components() []string

Components lists the kinds of service in use, in start order.

func (Config) EffectiveGrid

func (c Config) EffectiveGrid() string

EffectiveGrid is the grid square that applies now: the current site's, else the default.

func (Config) Find

func (c Config) Find(id string) (Station, bool)

Find returns the station with the given id.

func (Config) GPSAddr

func (c Config) GPSAddr() string

GPSAddr is where programs reach gpsd: the configured external gpsd, or hamstack's own on this machine. It is empty when no GPS is set up.

func (Config) Has

func (c Config) Has(kind string) bool

Has reports whether a kind of service is part of the setup.

func (Config) Here

func (c Config) Here() (Site, bool)

Here is the current site, if one is selected.

func (Config) NeedsRadio

func (c Config) NeedsRadio() bool

NeedsRadio reports whether any rig is in use.

func (Config) NeedsStation

func (c Config) NeedsStation() bool

NeedsStation reports whether the setup needs a callsign (Pat, or a modem that identifies itself).

func (Config) NextAddr

func (c Config) NextAddr() string

NextAddr returns a localhost address on the lowest port from 8080 that no station uses.

func (Config) PatEnabled

func (c Config) PatEnabled() bool

PatEnabled reports whether Pat is part of the setup.

func (Config) PatHFRig

func (c Config) PatHFRig() (Rig, bool)

PatHFRig is the rig Pat's HF modem connection uses: the first active rig with Mercury. Pat has a single HF modem setting, so with several Mercury rigs this one is wired to Pat.

func (Config) PatPacketRig

func (c Config) PatPacketRig() (Rig, bool)

PatPacketRig is the rig Pat's packet (AX.25) connections use: the first active rig with Direwolf. Pat has a single AX.25 setting, so with several Direwolf rigs this one is wired to Pat.

func (*Config) RemoveGPS

func (c *Config) RemoveGPS()

RemoveGPS forgets the GPS settings.

func (*Config) RemoveRig

func (c *Config) RemoveRig(id string) error

RemoveRig deletes a rig from the config.

func (*Config) RemoveSite

func (c *Config) RemoveSite(id string) error

RemoveSite deletes a site. Rigs, stations and the grid are left as they are.

func (*Config) RemoveStation

func (c *Config) RemoveStation(id string) error

RemoveStation removes a station; if it was active, the first remaining one becomes active.

func (*Config) RigByID

func (c *Config) RigByID(id string) (*Rig, bool)

RigByID finds a rig (including a switched-off one).

func (Config) RigByIDValue

func (c Config) RigByIDValue(id string) (Rig, bool)

RigByIDValue is RigByID returning a copy.

func (Config) RunsGPSD

func (c Config) RunsGPSD() bool

RunsGPSD reports whether hamstack runs a gpsd service: a receiver is set up, not switched off, and not provided by a gpsd elsewhere.

func (Config) ScoreSites

func (c Config) ScoreSites(identify func(Rig) (known, present bool)) []SiteScore

ScoreSites compares each site's rigs with what is plugged in. identify reports, for a rig, whether its hardware can be recognised at all and whether it is present; rigs that cannot be recognised (the dummy rig) take no part, so they never make a site look absent.

func (*Config) Set

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

Set changes one key from the command line.

func (*Config) SetGPS

func (c *Config) SetGPS(g GPS) error

SetGPS validates and saves the GPS settings.

func (*Config) SetGrid

func (c *Config) SetGrid(g string) (where string)

SetGrid sets the grid square for where you are: the current site's, or the default when there is no current site. It says which it changed.

func (*Config) SetSiteField

func (c *Config) SetSiteField(id, key, value string) error

SetSiteField changes one field of a site: name, rigs, station or grid.

func (Config) SiteByID

func (c Config) SiteByID(id string) (Site, bool)

SiteByID finds a site.

func (*Config) SyncSite

func (c *Config) SyncSite()

SyncSite records the current setup in the current site, so the site always describes what is running now: after you enable, disable or add a rig, or switch station, the site follows.

func (*Config) Use

func (c *Config) Use(id string) error

Use makes id the active station.

func (*Config) UseSite

func (c *Config) UseSite(id string) error

UseSite makes a site current and applies it: its rigs are switched on and every other rig off, and its station (if it names one) becomes the active station.

type GPS

type GPS struct {
	Device string `json:"device,omitempty"` // exact receiver device (a /dev/serial/by-id path)
	USB    string `json:"usb,omitempty"`    // USB identity (vid:pid:serial) of the receiver, to find it again after a replug
	Addr   string `json:"addr,omitempty"`   // "host:port" of an existing gpsd; hamstack then runs none
	Port   int    `json:"port,omitempty"`   // port of the gpsd hamstack runs (default GPSPort)
	Off    bool   `json:"off,omitempty"`    // kept in the config but not run
}

GPS is the position source: a gpsd daemon. Either hamstack runs gpsd itself for a receiver plugged into this machine (Device and USB say which one), or it uses a gpsd that already runs somewhere (Addr).

func (GPS) ListenPort

func (g GPS) ListenPort() int

ListenPort is the port hamstack's gpsd listens on.

type PacketOpts

type PacketOpts struct {
	Baud     int    `json:"baud,omitempty"`     // modem speed: 300 (HF), 1200 (VHF packet and APRS, the default), 2400, 4800, 9600
	Call     string `json:"call,omitempty"`     // the callsign (with SSID) to use instead of the station's
	TxDelay  int    `json:"txdelay,omitempty"`  // key-up delay in 10 ms units (Direwolf's default is 30)
	TxTail   int    `json:"txtail,omitempty"`   // hold-after delay in 10 ms units (default 10)
	Persist  int    `json:"persist,omitempty"`  // CSMA persistence 0-255 (default 63)
	SlotTime int    `json:"slottime,omitempty"` // CSMA slot time in 10 ms units (default 10)
	Digipeat bool   `json:"digipeat,omitempty"` // repeat other stations' WIDEn-N packets (a transmitting service: see the notice)
}

PacketOpts are the settings of a rig's Direwolf that people change. Zero means "leave it to Direwolf's default", so a rig that never touched them gets exactly the configuration it always had.

func (PacketOpts) ModemBaud

func (o PacketOpts) ModemBaud() int

ModemBaud is the speed to run: 1200 unless set.

func (PacketOpts) Validate

func (o PacketOpts) Validate() error

Validate checks the values.

type Rig

type Rig struct {
	ID       string     `json:"id"` // short name used on the command line and in unit names
	Name     string     `json:"name,omitempty"`
	Profile  string     `json:"profile"`             // radio model: hamlib model, baud, USB ids
	CAT      string     `json:"cat,omitempty"`       // exact CAT device (a /dev/serial/by-id path); empty = find it via the profile
	CATID    string     `json:"cat_id,omitempty"`    // USB identity (vid:pid:serial) of the CAT device
	Audio    string     `json:"audio,omitempty"`     // ALSA card id of its sound card
	AudioUSB string     `json:"audio_usb,omitempty"` // USB identity of the sound card, to find it again if card numbers change
	Modem    string     `json:"modem,omitempty"`     // "", "mercury" (HF) or "direwolf" (VHF/UHF packet)
	NoCAT    bool       `json:"no_cat,omitempty"`    // the radio has no CAT control (its profile has no hamlib model): no rigctld
	Bands    []string   `json:"bands,omitempty"`     // hf, vhf, uhf
	RigPort  int        `json:"rig_port"`            // its rigctld port
	ArqPort  int        `json:"arq_port,omitempty"`  // base of its Mercury ports
	Off      bool       `json:"off,omitempty"`       // kept in the config but not run (not at this site, or unplugged)
	Packet   PacketOpts `json:"packet,omitzero"`     // Direwolf's settings for this rig; zero values mean Direwolf's own defaults
}

Rig is one physical radio and how it is wired up. A rig is identified by its own name, not by the model, so two radios of the same model are two rigs.

type Site

type Site struct {
	ID      string   `json:"id"`
	Name    string   `json:"name,omitempty"`
	Rigs    []string `json:"rigs"`              // ids of the rigs that are on at this site; the rest are switched off
	Station string   `json:"station,omitempty"` // the active station here ("" leaves it as it is)
	Grid    string   `json:"grid,omitempty"`    // the grid square here ("" uses the default grid)
}

Site is a named place you operate from (home, the EOC, the club). It records which of your rigs are there, which station is active, and the grid square, so moving between places is one command.

type SiteScore

type SiteScore struct {
	Site    Site
	Known   int      // rigs whose hardware can be recognised (a saved USB device, or a profile with a pattern)
	Present int      // of those, how many are plugged in now
	Missing []string // ids of the ones that are not
}

SiteScore says how many of a site's identifiable radios are plugged in.

func (SiteScore) Complete

func (s SiteScore) Complete() bool

Complete reports whether the site has radios to recognise and all of them are present.

type Station

type Station struct {
	ID        string `json:"id"`         // short name used on the command line
	Name      string `json:"name"`       // optional label, e.g. "Club"
	Callsign  string `json:"callsign"`   // may include an -SSID
	PatConfig string `json:"pat_config"` // path of this station's Pat config file
	HTTPAddr  string `json:"http_addr"`  // Pat web UI listen address, e.g. localhost:8081
}

Station is one operating identity: a callsign with its own Pat config and web UI address. Examples: a personal call, a club call, an emergency-communications call.

Jump to

Keyboard shortcuts

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