adif

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package adif defines basic types (Field, Record, Logfile) for working with amateur radio logs in ADIF format. It also defines I/O types which can read and write ADIF data in several formats, including the ADIF-specified ADI and ADX formats as well as CSV and JSON. The adif package does not have any code dealing with specific fields or enumerations defined by specification; see the adif/spec package for such code.

Index

Constants

View Source
const CabrilloFieldExample = "header:field_a/field_b?=default"

Variables

View Source
var (

	// Allowed values for Cabrillo categories.
	// See https://wwrof.org/cabrillo/cabrillo-v3-header/
	CabrilloCategoryValues = map[string][]string{
		"ASSISTED": {"ASSISTED", "NON-ASSISTED"},
		"BAND": {
			"ALL",
			"160M",
			"80M",
			"40M",
			"20M",
			"15M",
			"10M",
			"6M",
			"4M",
			"2M",
			"222",
			"432",
			"902",
			"1.2G",
			"2.3G",
			"3.4G",
			"5.7G",
			"10G",
			"24G",
			"47G",
			"75G",
			"122G",
			"134G",
			"241G",
			"LIGHT",
			"VHF-3-BAND",
			"VHF-FM-ONLY",
		},
		"MODE":     {"CW", "DIGI", "FM", "RTTY", "SSB", "MIXED"},
		"OPERATOR": {"SINGLE-OP", "MULTI-OP", "CHECKLOG"},
		"OVERLAY":  {"CLASSIC", "ROOKIE", "TB-WIRES", "YOUTH", "NOVICE-TECH", "YL"},
		"POWER":    {"HIGH", "LOW", "QRP"},
		"STATION": {
			"DISTRIBUTED",
			"FIXED",
			"MOBILE",
			"PORTABLE",
			"ROVER",
			"ROVER-LIMITED",
			"ROVER-UNLIMITED",
			"EXPEDITION",
			"HQ",
			"SCHOOL",
			"EXPLORER",
		},
		"TIME":        {"6-HOURS", "8-HOURS", "12-HOURS", "24-HOURS"},
		"TRANSMITTER": {"ONE", "TWO", "LIMITED", "UNLIMITED", "SWL"},
	}
)
View Source
var ErrInvalidFormat = fmt.Errorf("not a valid Format, try [%s]", strings.Join(_FormatNames, ", "))
View Source
var ErrInvalidSeparator = fmt.Errorf("not a valid Separator, try [%s]", strings.Join(_SeparatorNames, ", "))

Functions

func FormatNames

func FormatNames() []string

FormatNames returns a list of possible string values of Format.

func SeparatorNames

func SeparatorNames() []string

SeparatorNames returns a list of possible string values of Separator.

Types

type ADIIO

type ADIIO struct {
	LowerCase           bool // TODO consider a case enum: keep, upper, lower, or just get rid of this option
	ASCIIOnly           bool
	FieldSep, RecordSep Separator
}

func NewADIIO

func NewADIIO() *ADIIO

func (*ADIIO) Read

func (o *ADIIO) Read(in io.Reader) (*Logfile, error)

func (*ADIIO) String

func (_ *ADIIO) String() string

func (*ADIIO) Write

func (o *ADIIO) Write(l *Logfile, out io.Writer) error

type ADXIO

type ADXIO struct {
	Indent int
}

func NewADXIO

func NewADXIO() *ADXIO

func (*ADXIO) Read

func (o *ADXIO) Read(in io.Reader) (*Logfile, error)

func (*ADXIO) String

func (_ *ADXIO) String() string

func (*ADXIO) Write

func (o *ADXIO) Write(l *Logfile, out io.Writer) error

type CSVIO

type CSVIO struct {
	Comma             rune
	Comment           rune
	CRLF              bool
	LazyQuotes        bool
	RequireFullRecord bool
	TrimLeadingSpace  bool
	OmitHeader        bool
}

func NewCSVIO

func NewCSVIO() *CSVIO

func (*CSVIO) Read

func (o *CSVIO) Read(in io.Reader) (*Logfile, error)

func (*CSVIO) String

func (o *CSVIO) String() string

func (*CSVIO) Write

func (o *CSVIO) Write(l *Logfile, out io.Writer) error

type CabrilloField added in v0.1.16

type CabrilloField struct {
	TryFields  []string
	Default    string
	Header     string
	AllowEmpty bool
}
CabrilloField represents a field in a Cabrillo file which will appear in a column.

The data in a CabrilloField can come from one field, a series of ADIF fields, or be set to a default value, e.g. an exchange used throughout a contest. A field optionally has a header, shown only for informational purposes. Fields are required by default, but may be made optional, in which case one or more hyphens will be used in the output if the ADIF fields are all empty.

func (*CabrilloField) String added in v0.1.16

func (c *CabrilloField) String() string

type CabrilloFieldList added in v0.1.16

type CabrilloFieldList []CabrilloField

CabrilloFieldList is a slice of CabrilloFields. Repeated appearances of a flag append to the list, or a single flag value can have multiple fields separated by whitespace. The syntax is:

  • header:field_a=default (single labeled field, default value)
  • field_a/field_b? (two possible fields, allow empty, no header)
  • header:=default (no lookup, same value for all QSOs)
  • header:field_a/field_b?=default (the works)

Examples: "rst:rst_sent=59" "srx_string/state?" "exch:=CT"

func (*CabrilloFieldList) Get added in v0.1.16

func (l *CabrilloFieldList) Get() any

func (*CabrilloFieldList) Set added in v0.1.16

func (l *CabrilloFieldList) Set(v string) error

func (*CabrilloFieldList) String added in v0.1.16

func (l *CabrilloFieldList) String() string

type CabrilloIO added in v0.1.9

type CabrilloIO struct {
	Callsign, Contest, Club, CreatedBy, Email,
	GridLocator, Location, Name, Address, Soapbox string
	Operators                              []string
	LowPowerMax, QRPPowerMax, ClaimedScore int
	MinReportedOfftime                     time.Duration
	Categories                             map[string]string
	MyExchange, TheirExchange, ExtraFields CabrilloFieldList
	TabDelimiter                           bool
}

CabrilloIO configures the headers and QSO inference for conversion to and from the Cabrillo format. Most fields configure the value of a header with the same name. Categories maps CATEGORY header names to value, e.g. "TIME" to "6-HOURS". See https://wwrof.org/cabrillo/cabrillo-v3-header/ for details about header values.

func NewCabrilloIO added in v0.1.9

func NewCabrilloIO() *CabrilloIO

func (*CabrilloIO) Read added in v0.1.9

func (o *CabrilloIO) Read(in io.Reader) (*Logfile, error)

func (*CabrilloIO) String added in v0.1.9

func (_ *CabrilloIO) String() string

func (*CabrilloIO) Write added in v0.1.9

func (o *CabrilloIO) Write(l *Logfile, out io.Writer) error

type DataType

type DataType int
const (
	TypeUnspecified DataType = iota
	TypeMultilineString
	TypeIntlMultilineString
	TypeString
	TypeIntlString
	TypeEnumeration
	TypeBoolean
	TypeNumber
	TypeDate
	TypeTime
	TypeLocation
)

func DataTypeFromIndicator

func DataTypeFromIndicator(id string) (DataType, error)

func (DataType) Indicator

func (t DataType) Indicator() string

func (DataType) String

func (t DataType) String() string

type Field

type Field struct {
	Name  string
	Value string
	Type  DataType
}

func (Field) IsAppDefined

func (f Field) IsAppDefined() bool

func (Field) String

func (f Field) String() string

type Format

type Format string

ENUM(ADI, ADX, Cabrillo, CSV, JSON, TSV)

const (
	// FormatADI is a Format of type ADI.
	FormatADI Format = "ADI"
	// FormatADX is a Format of type ADX.
	FormatADX Format = "ADX"
	// FormatCabrillo is a Format of type Cabrillo.
	FormatCabrillo Format = "Cabrillo"
	// FormatCSV is a Format of type CSV.
	FormatCSV Format = "CSV"
	// FormatJSON is a Format of type JSON.
	FormatJSON Format = "JSON"
	// FormatTSV is a Format of type TSV.
	FormatTSV Format = "TSV"
)

func GuessFormatFromContent

func GuessFormatFromContent(r *bufio.Reader) (Format, error)

GuessFormatFromContent inspects the beginning bytes of r to guess which Format the data is in. Returns Format("") and an error if no heuristic matched the content.

func GuessFormatFromName

func GuessFormatFromName(filename string) (Format, error)

GuessFormatFromName guesses a file's Format based on its extension. If filename doesn't match any known format, Format("") and an error are returned.

func ParseFormat

func ParseFormat(name string) (Format, error)

ParseFormat attempts to convert a string to a Format.

func (*Format) Get

func (x *Format) Get() interface{}

Get implements the Golang flag.Getter interface func.

func (Format) IsValid

func (x Format) IsValid() bool

String implements the Stringer interface.

func (*Format) Set

func (x *Format) Set(val string) error

Set implements the Golang flag.Value interface func.

func (Format) String

func (x Format) String() string

String implements the Stringer interface.

func (*Format) Type

func (x *Format) Type() string

Type implements the github.com/spf13/pFlag Value interface.

type JSONIO

type JSONIO struct {
	HTMLSafe    bool
	Indent      int
	TypedOutput bool
}

func NewJSONIO

func NewJSONIO() *JSONIO

func (*JSONIO) Read

func (o *JSONIO) Read(in io.Reader) (*Logfile, error)

func (*JSONIO) String

func (_ *JSONIO) String() string

func (*JSONIO) Write

func (o *JSONIO) Write(l *Logfile, out io.Writer) error

type Logfile

type Logfile struct {
	Records    []*Record
	Header     *Record
	Userdef    []UserdefField
	Comment    string
	Filename   string
	FieldOrder []string
}

func NewLogfile

func NewLogfile() *Logfile

func (*Logfile) AddRecord

func (f *Logfile) AddRecord(r *Record) *Logfile

func (*Logfile) AddUserdef

func (f *Logfile) AddUserdef(u UserdefField) error

func (*Logfile) GetUserdef

func (f *Logfile) GetUserdef(name string) (UserdefField, bool)

func (*Logfile) String

func (f *Logfile) String() string

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
	fmt.Stringer
}

type Reader

type Reader interface {
	Read(io.Reader) (*Logfile, error)
}

type Record

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

func NewRecord

func NewRecord(fs ...Field) *Record

func (*Record) Empty

func (r *Record) Empty() bool

func (*Record) Equal

func (r *Record) Equal(o *Record) bool

Equal compares two records for equality of fields, ignoring order and comments. Records are considered equal even if one has assigned empty fields while the other does not have a field of that name set.

func (*Record) Fields

func (r *Record) Fields() []Field

func (*Record) Get

func (r *Record) Get(name string) (f Field, ok bool)

func (*Record) GetComment

func (r *Record) GetComment() string

func (*Record) ParseBool added in v0.1.9

func (r *Record) ParseBool(name string) (bool, error)

func (*Record) ParseDate added in v0.1.9

func (r *Record) ParseDate(name string) (time.Time, error)

func (*Record) ParseFloat added in v0.1.9

func (r *Record) ParseFloat(name string) (float64, error)

func (*Record) ParseInt added in v0.1.9

func (r *Record) ParseInt(name string) (int, error)

func (*Record) ParseTime added in v0.1.9

func (r *Record) ParseTime(name string) (time.Time, error)

func (*Record) Set

func (r *Record) Set(f Field) error

func (*Record) SetComment

func (r *Record) SetComment(c string)

func (*Record) String

func (r *Record) String() string

type Separator

type Separator int

ENUM(empty, space, tab, newline, 2newline, crlf, 2crlf)

const (
	// SeparatorEmpty is a Separator of type Empty.
	SeparatorEmpty Separator = iota
	// SeparatorSpace is a Separator of type Space.
	SeparatorSpace
	// SeparatorTab is a Separator of type Tab.
	SeparatorTab
	// SeparatorNewline is a Separator of type Newline.
	SeparatorNewline
	// Separator2Newline is a Separator of type 2Newline.
	Separator2Newline
	// SeparatorCrlf is a Separator of type Crlf.
	SeparatorCrlf
	// Separator2Crlf is a Separator of type 2Crlf.
	Separator2Crlf
)

func ParseSeparator

func ParseSeparator(name string) (Separator, error)

ParseSeparator attempts to convert a string to a Separator.

func (*Separator) Get

func (x *Separator) Get() interface{}

Get implements the Golang flag.Getter interface func.

func (*Separator) Set

func (x *Separator) Set(val string) error

Set implements the Golang flag.Value interface func.

func (Separator) String

func (x Separator) String() string

String implements the Stringer interface.

func (*Separator) Type

func (x *Separator) Type() string

Type implements the github.com/spf13/pFlag Value interface.

func (Separator) Val

func (d Separator) Val() string

type TSVIO added in v0.1.5

type TSVIO struct {
	CRLF               bool
	EscapeSpecial      bool
	IgnoreEmptyHeaders bool
	OmitHeader         bool
}

func NewTSVIO added in v0.1.5

func NewTSVIO() *TSVIO

func (*TSVIO) Read added in v0.1.5

func (o *TSVIO) Read(r io.Reader) (*Logfile, error)

func (*TSVIO) String added in v0.1.13

func (_ *TSVIO) String() string

func (*TSVIO) Write added in v0.1.5

func (o *TSVIO) Write(l *Logfile, w io.Writer) error

type UserdefField

type UserdefField struct {
	Name       string
	Type       DataType
	Min, Max   float64
	EnumValues []string
}

func (UserdefField) String

func (u UserdefField) String() string

func (UserdefField) Validate

func (u UserdefField) Validate(f Field) error

func (UserdefField) ValidateSelf

func (u UserdefField) ValidateSelf() error

type Writer

type Writer interface {
	Write(*Logfile, io.Writer) error
}

Directories

Path Synopsis
Package spec contains data types, field definitions, and enumerations defined by the ADIF specification from https://adif.org.uk/ Most structures in this package are automatically generated.
Package spec contains data types, field definitions, and enumerations defined by the ADIF specification from https://adif.org.uk/ Most structures in this package are automatically generated.
countrystats
countrystats prints miscellaneous information about DXCC entities and ISO 3166-1 codes, particularly highlighting potential problems.
countrystats prints miscellaneous information about DXCC entities and ISO 3166-1 codes, particularly highlighting potential problems.

Jump to

Keyboard shortcuts

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