rf

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 4 Imported by: 17

README

hz.tools/rf

Package rf contains go fundemental types and helpers to allow Go code to easily manupulate RF related types.

Documentation

Overview

Package rf contains go fundemental types and helpers to allow Go code to easily manupulate RF related types.

Additional types and helpers can be found in `hz.tools/sdr` for dealing with software defined radios.

Index

Constants

View Source
const (
	// SpeedOfLight is set to the speed of light in Meters per second
	SpeedOfLight float64 = 299792458
)

Variables

View Source
var (
	// KHz represents one kilohertz, or 1,000 Hz
	KHz Hz = Hz(1e+3)

	// MHz represents one megahertz, or 1,000,000 Hz
	MHz Hz = Hz(1e+6)

	// GHz represents one gigahertz, or 1,000,000,000 Hz
	GHz Hz = Hz(1e+9)

	// THz represents one terrahertz, or 1,000,000,000,000 Hz
	THz Hz = Hz(1e+12)

	// KHzBand represents the Kilohertz band, from 1KHz up to 1MHz.
	KHzBand Allocation = Allocation{Name: "KHz", Range: Range{KHz, MHz - 1}}

	// MHzBand represents the Megahertz band, from 1MHz up to 1GHz.
	MHzBand Allocation = Allocation{Name: "MHz", Range: Range{MHz, GHz - 1}}

	// GHzBand represents the Gigahertz band, from 1GHz up to 1THz.
	GHzBand Allocation = Allocation{Name: "GHz", Range: Range{GHz, THz - 1}}

	// SIBands represents the Hz-based allocations (KHz, MHz, GHz)
	SIBands Allocations = Allocations{KHzBand, MHzBand, GHzBand}
)
View Source
var (
	// ELFBand or Extremely Low Frequency, is a slice of RF space defined by the ITU
	// as being between 3Hz and 30Hz
	ELFBand Allocation = Allocation{Name: "ELF", Range: Range{ituELF, ituSLF - 1}}

	// SLFBand or Super Low Frequency, is a slice of RF space defined by the ITU
	// as being between 30Hz and 300Hz
	SLFBand Allocation = Allocation{Name: "SLF", Range: Range{ituSLF, ituULF - 1}}

	// ULFBand or Ultra Low Frequency, is a slice of RF space defined by the ITU
	// as being between 300Hz and 3KHz
	ULFBand Allocation = Allocation{Name: "ULF", Range: Range{ituULF, ituVLF - 1}}

	// VLFBand or Very Low Frequency, is a slice of RF space defined by the ITU
	// as being between 3KHz and 30KHz
	VLFBand Allocation = Allocation{Name: "VLF", Range: Range{ituVLF, ituLF - 1}}

	// LFBand or Low Frequency, is a slice of RF space defined by the ITU
	// as being between 30KHz and 300KHz
	LFBand Allocation = Allocation{Name: "LF", Range: Range{ituLF, ituMF - 1}}

	// MFBand or Medium Frequency, is a slice of RF space defined by the ITU
	// as being between 300KHz and 3MHz
	MFBand Allocation = Allocation{Name: "MF", Range: Range{ituMF, ituHF - 1}}

	// HFBand or High Frequency, is a slice of RF space defined by the ITU
	// as being between 3MHz and 30MHz
	HFBand Allocation = Allocation{Name: "HF", Range: Range{ituHF, ituVHF - 1}}

	// VHFBand or Very High Frequency, is a slice of RF space defined by the ITU
	// as being between 30MHz and 300MHz
	VHFBand Allocation = Allocation{Name: "VHF", Range: Range{ituVHF, ituUHF - 1}}

	// UHFBand or Ultra High Frequency, is a slice of RF space defined by the ITU
	// as being between 300MHz and 3GHz
	UHFBand Allocation = Allocation{Name: "UHF", Range: Range{ituUHF, ituSHF - 1}}

	// SHFBand or Super High Frequency, is a slice of RF space defined by the ITU
	// as being between 3GHz and 30GHz
	SHFBand Allocation = Allocation{Name: "SHF", Range: Range{ituSHF, ituEHF - 1}}

	// EHFBand or Extremely High Frequency, is a slice of RF space defined by the ITU
	// as being between 30GHz and 300GHz
	EHFBand Allocation = Allocation{Name: "EHF", Range: Range{ituEHF, ituTHF - 1}}

	// ITUBands represents all the ITU allocated RF bands.
	//
	// This is likely most useful to amateur radio applications, where specific
	// individuals are using the ITU names frequently.
	ITUBands Allocations = []Allocation{
		ELFBand, SLFBand, ULFBand, VLFBand,
		LFBand, MFBand, HFBand,
		VHFBand, UHFBand, SHFBand, EHFBand,
	}
)

Functions

This section is empty.

Types

type Allocation

type Allocation struct {
	// Name describing the band
	Name string

	// Range of frequency that this Allocation covers
	Range Range
}

Allocation is a range of Frequency, allocated a name, and perhaps a purpose. Some examples of this would be the 'KU' radar band, 'VHF' range or 'WiFi Channel 11'.

func (Allocation) String

func (r Allocation) String() string

String will output a human readable string representing the Allocation of frequency.

type Allocations

type Allocations []Allocation

Allocations is a slice that represents grouped frequency allocations, which allow for easy querying.

func (Allocations) ContainingFrequency

func (a Allocations) ContainingFrequency(freq Hz) Allocations

ContainingFrequency will return all Allocations that contain this Frequency.

func (Allocations) First

func (a Allocations) First() Allocation

First will return the first Allocation in the Allocations slice.

type Hz

type Hz float64

Hz represents a specific frequency, in cycles per second.

func MustParseHz

func MustParseHz(freq string) Hz

MustParseHz will run the string through ParseHz, and on error, panic. This is very useful for hardcoded const strings, or places where invalid input is actually fatal.

func ParseHz

func ParseHz(freq string) (Hz, error)

ParseHz will take a frequency as a string, and return it as an rf.Hz.

Examples of valid frequencies:

-10MHz 2GHz 2000Hz

Valid Hz units are 'Hz', 'KHz', 'MHz', 'GHz', 'THz'

func (Hz) ITUBandName

func (h Hz) ITUBandName() string

ITUBandName will return the string verify of the ITU band name the frequency is contained in.

func (Hz) MarshalJSON

func (h Hz) MarshalJSON() ([]byte, error)

MarshalJSON will convert the frequency in Hz to a string. This can be used to transmit frequency data via JSON.

func (Hz) MarshalYAML added in v0.0.4

func (h Hz) MarshalYAML() (interface{}, error)

MarshalYAML will convert the frequency in Hz to a string. This can be used to transmit frequency data via YAML.

func (Hz) SIBandName

func (h Hz) SIBandName() string

SIBandName will return the name of the SI frequency range (KHz, MHz, GHz)

func (Hz) String

func (h Hz) String() string

String will convert the frequency into a string, able to be re-parsed as a frequency, or displayed to a user.

func (*Hz) UnmarshalJSON

func (h *Hz) UnmarshalJSON(data []byte) error

UnmarshalJSON will parse a string as a frequency, and convert it into Hz. This can be used to transmit frequency data via JSON.

func (*Hz) UnmarshalYAML added in v0.0.4

func (h *Hz) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML will parse a string as a frequency, and convert it into Hz. This can be used to transmit frequency data via YAML.

func (Hz) Wavelength

func (h Hz) Wavelength() float64

Wavelength will return the Wavelength, in meters.

type Range

type Range [2]Hz

Range is a tuple of Hz values, Range[0] is the lowest value of the range, and Range[1] is the highest value of the range.

func (Range) Add

func (r Range) Add(freq Hz) Range

Add the provided frequency in Hz to both the lower and upper side of the Range, shifting the Range by the provided Hz.

func (Range) Center

func (r Range) Center() Hz

Center will return the center of a range (perhaps to get the center of a channel to tune to).

func (Range) ContainsFrequency

func (r Range) ContainsFrequency(freq Hz) bool

ContainsFrequency will check to see if a given Frequency is contained inside this Range.

func (Range) ContainsRange

func (r Range) ContainsRange(r1 Range) bool

ContainsRange will return true if r1 a subset of the range defined by the Range.

func (Range) Equal

func (r Range) Equal(r1 Range) bool

Equal will check to see if the Range is specifically the same as another Range.

func (Range) Intersection added in v0.0.5

func (r Range) Intersection(r1 Range) Range

Intersection will return the intersection of the range this method is bound to and the provided range.

func (Range) Overlaps

func (r Range) Overlaps(r1 Range) bool

Overlaps will return true if r1 overlaps with the Range.

func (Range) String

func (r Range) String() string

String will turn the range into a string.

Jump to

Keyboard shortcuts

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