Documentation ¶
Index ¶
- Constants
- Variables
- func ByteToHex(b byte) string
- func BytesToHex(b []byte) string
- func CheckCommandResponse(line string, allowUnknown bool) error
- func HexToByte(h string) (byte, error)
- func HexToBytes(h string) ([]byte, error)
- func HexToUInt16(h string) (uint16, error)
- func PadHex(h string, digits int) string
- func PadHexToEvenLength(h string) string
- func ReadNVM(d *Device, start, amount uint16) ([]byte, error)
- func UInt16ToHex(v uint16) string
- func WriteNVM(d *Device, address uint16, data []byte) error
- type Config
- type DebugSerial
- type Device
- func (d *Device) Close() error
- func (d *Device) ExecuteCommand(format string, a ...interface{}) (string, error)
- func (d *Device) ExecuteCommandChecked(format string, a ...interface{}) (string, error)
- func (d *Device) ExecuteCommandCheckedStrict(format string, a ...interface{}) error
- func (d *Device) FactoryReset() (*FirmwareVersion, error)
- func (d *Device) GetHWEUI() (string, error)
- func (d *Device) GetRadioParameter(name string) (string, error)
- func (d *Device) GetRadioPower() (int, error)
- func (d *Device) GetVDD() (Voltage, error)
- func (d *Device) GetVersion() (*FirmwareVersion, error)
- func (d *Device) PauseMAC() (time.Duration, error)
- func (d *Device) RadioRx(windowSize uint16) ([]byte, error)
- func (d *Device) RadioTx(data []byte) error
- func (d *Device) ReadNVM(address uint16) (byte, error)
- func (d *Device) ReadResponse() (string, error)
- func (d *Device) Reset() (*FirmwareVersion, error)
- func (d *Device) Sendf(format string, a ...interface{}) error
- func (d *Device) SetDigitalGPIO(gpio PinName, value bool) error
- func (d *Device) SetRadioParameter(name string, value interface{}) error
- func (d *Device) SetRadioPower(power int) error
- func (d *Device) Sleep(duration time.Duration) error
- func (d *Device) WriteNVM(address uint16, value byte) error
- type DeviceSKU
- type FirmwareVersion
- type PinName
- type Voltage
Constants ¶
const ( // UserNVMStart is the address of the first byte in user NVM that can be addressed UserNVMStart uint16 = 0x300 // UserNVMEnd is the last address in user NVM that can be addressed UserNVMEnd uint16 = 0x3FF )
Variables ¶
var ( ErrInvalidParam = errors.New("invalid parameter") ErrUnknown = errors.New("unknown error") ErrTransceiverBusy = errors.New("the transceiver is currently busy") )
var ( ErrReceiveTimeout = errors.New("reception unsuccessful, timeout occurred") ContinuousReceiveMode uint16 = 0 )
var AllPins = []PinName{ PinGPIO00, PinGPIO01, PinGPIO02, PinGPIO03, PinGPIO04, PinGPIO05, PinGPIO06, PinGPIO07, PinGPIO08, PinGPIO09, PinGPIO10, PinGPIO11, PinGPIO12, PinGPIO13, PinGPIO14, PinUARTCTS, PinUARTRTS, PinTEST0, PinTEST1, }
AllPins lists all the GPIO pins that can be asserted
var (
ErrTransmitTimeout = errors.New("transmission unsuccessful, interrupted by radio WDT")
)
var ( // FirmwareVersionRegex is a regex for breaking down a version string reported by the device FirmwareVersionRegex = regexp.MustCompile("^(.+)\\s+([0-9]+\\.[0-9]+\\.[0-9]+)\\s+(.+)$") )
var KnownDeviceSKUs = []DeviceSKU{DeviceRN2483, DeviceRN2903}
KnownDeviceSKUs is a list of all known device SKUs
var KnownRadioParameters = []string{
"bt", "mod", "freq", "pwr", "sf", "afcbw", "rxbw", "bitrate",
"fdev", "prlen", "crc", "iqi", "cr", "wdt", "bw", "snr",
}
KnownRadioParameters lists the known parameters that can be get/set with radio commands
var ( // UserNVMLength is the number of bytes of user NVM that can be addressed UserNVMLength = (UserNVMEnd + 1) - UserNVMStart )
Functions ¶
func BytesToHex ¶
BytesToHex returns the hex representation of a byte array
func CheckCommandResponse ¶
CheckCommandResponse validates a command response against known error codes, optionally failing unknown responses
func HexToBytes ¶
HexToBytes decodes a hex string into a byte array
func HexToUInt16 ¶
HexToUInt16 decodes a hex string of a big-endian uint16
func PadHex ¶
PadHex pads a hexadecimal string with leading 0s until it satisfied the desired number of digits
func PadHexToEvenLength ¶
PadHexToEvenLength pads a hex string with a single leading 0 only if the input hex string is an odd length
func UInt16ToHex ¶
UInt16ToHex returns the big-endian hex representation of a uint16
Types ¶
type Config ¶
type Config struct {
Serial io.ReadWriteCloser
}
Config allows for configuring a new Device
type DebugSerial ¶
type DebugSerial struct { Serial io.ReadWriteCloser Logger logr.Logger // AssumeText controls whether data flowing through this device is likely printable text, if true then // logged data will be printed as text, otherwise it is treated as unprintable binary and is displayed // however the logging library chooses to render []byte (often base64) AssumeText bool }
DebugSerial wraps a serial device and logs data flowing to/from that device
func (*DebugSerial) Close ¶
func (d *DebugSerial) Close() error
Close implements the io.ReadWriteCloser interface by calling the underlying Serial implementation
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents a single RN2483 (or 2903) device, providing methods for configuring and querying its state and invoking the various features of the device (primarily transmitting & receiving packets)
func (*Device) ExecuteCommand ¶
ExecuteCommand sends the provided command, then reads and returns the response
func (*Device) ExecuteCommandChecked ¶
ExecuteCommandChecked sends the provided command, reads the response, checks it for common error codes, then returns the response
func (*Device) ExecuteCommandCheckedStrict ¶
ExecuteCommandCheckedStrict sends the provided command, reads the response and then checks it is one of a set of known command responses, failing any unrecognised responses
func (*Device) FactoryReset ¶
func (d *Device) FactoryReset() (*FirmwareVersion, error)
FactoryReset resets the device to its factory configuration
func (*Device) GetRadioParameter ¶
GetRadioParameter gets the specified radio parameter as a raw string value (direct from the response message)
func (*Device) GetRadioPower ¶
GetRadioPower gets the radio's current configured transmit power
func (*Device) GetVersion ¶
func (d *Device) GetVersion() (*FirmwareVersion, error)
GetVersion retrieves the device's version information
func (*Device) RadioRx ¶
RadioRx causes the device to listen for, and return, a single packet. The window size determines how long it will listen for, behaving differently depending on the current radio configuration (particularly modulation mode).
func (*Device) RadioTx ¶
RadioTx attempts to transmit a packet of data using the radio's current configuration
func (*Device) ReadResponse ¶
ReadResponse allows for easily reading a line of text from the device in response to a command
func (*Device) Reset ¶
func (d *Device) Reset() (*FirmwareVersion, error)
Reset resets the device, reverting to its stored configuration
func (*Device) SetDigitalGPIO ¶
SetDigitalGPIO sets the specified GPIO pin to on or off
func (*Device) SetRadioParameter ¶
SetRadioParameter sets the specified radio parameter to the given value
func (*Device) SetRadioPower ¶
SetRadioPower sets the radio's transmit power
type FirmwareVersion ¶
type FirmwareVersion struct { // Raw contains the original version string Raw string // SKU indicates the device model SKU DeviceSKU // Major is the first component of the firmware version number Major int // Minor is the second component of the firmware version number Minor int // Revision is the third component of the firmware version number Revision int // ReleaseTime is the time at which this firmware version was released ReleaseTime time.Time }
FirmwareVersion contains the result of parsing a version string returned by several sys commands
func ParseFirmwareVersion ¶
func ParseFirmwareVersion(s string) (*FirmwareVersion, error)
ParseFirmwareVersion attempts to parse a version string reported by the device
func (*FirmwareVersion) IsKnownSKU ¶
func (fw *FirmwareVersion) IsKnownSKU() bool
IsKnownSKU compares this firmware version's reported SKU to the list of known SKUs
func (*FirmwareVersion) VersionString ¶
func (fw *FirmwareVersion) VersionString() string
VersionString combines the major, minor and revision components into a single string for easier printing
type PinName ¶
type PinName string
PinName identifies the GPIO pin that may be asserted
const ( PinGPIO00 PinName = "GPIO00" PinGPIO01 PinName = "GPIO01" PinGPIO02 PinName = "GPIO02" PinGPIO03 PinName = "GPIO03" PinGPIO04 PinName = "GPIO04" PinGPIO05 PinName = "GPIO05" PinGPIO06 PinName = "GPIO06" PinGPIO07 PinName = "GPIO07" PinGPIO08 PinName = "GPIO08" PinGPIO09 PinName = "GPIO09" PinGPIO10 PinName = "GPIO10" PinGPIO11 PinName = "GPIO11" PinGPIO12 PinName = "GPIO12" PinGPIO13 PinName = "GPIO13" PinGPIO14 PinName = "GPIO14" PinUARTCTS PinName = "UART_CTS" PinUARTRTS PinName = "UART_RTS" PinTEST0 PinName = "TEST0" PinTEST1 PinName = "TEST1" )
type Voltage ¶
type Voltage uint16
Voltage represents a voltage measured by the device
func (Voltage) Millivolts ¶
Millivolts is the measured voltage in Millivolts (mV) as an integer