rn2483

package module
v0.0.0-...-6de8608 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: MIT Imports: 9 Imported by: 0

README

RN2483

Build Status GoDoc

This library gives users the ability to use the RN2483 module in their application. For more info about the RN2483 module commands, see http://ww1.microchip.com/downloads/en/DeviceDoc/40001784F.pdf.

As this is a work in progress, not all commands are supported yet. For more info about what is supported, check the go docs reference.

Usage

package main

import (
  "fmt"
  "time"

  "github.com/bullettime/rn2483"
)

func main() {
  // Setup the serial information
  rn2483.SetName("/dev/cu.usbmodem14111")
  rn2483.setBaud(57600)
  rn2483.SetTimeout(time.Millisecond * 500)

  // Connect the RN2483 via serial
  rn2483.Connect()
  // Make sure the app closes the connection at the end the free the resource
  defer rn2483.Disconnect()

  // Do you stuff
  fmt.Println(rn2483.Version())
}

Documentation

Index

Constants

View Source
const (
	LoRa = "lora"
	FSK  = "fsk"
)

The possible modulations

View Source
const (
	SF7  = "sf7"
	SF8  = "sf8"
	SF9  = "sf9"
	SF10 = "sf10"
	SF11 = "sf11"
	SF12 = "sf12"
)

The possible spreading factors

View Source
const (
	CR5 = "4/5"
	CR6 = "4/6"
	CR7 = "4/7"
	CR8 = "4/8"
)

The possible coding rates

View Source
const (
	BW1 = "125"
	BW2 = "250"
	BW3 = "500"
)

The possible bandwidths

View Source
const (
	OTAA = "otaa"
	ABP  = "abp"
)

The possible join modes

View Source
const (
	CONFIRMED   = "cnf"
	UNCONFIRMED = "uncnf"
)

The possible uplink types

View Source
const (
	SF7BW125  = uint8(5)
	SF8BW125  = uint8(4)
	SF9BW125  = uint8(3)
	SF10BW125 = uint8(2)
	SF11BW125 = uint8(1)
	SF12BW125 = uint8(0)
)

The possible data rates

View Source
const (
	DBm20 = 0
	DBm14 = 1
	DBm11 = 2
	DBm8  = 3
	DBm5  = 4
	DBm2  = 5
)

The possible TXPowers

Variables

View Source
var BWs = map[uint16]string{
	125: BW1,
	250: BW2,
	500: BW3,
}

BWs is the mapping of the bandwidths

View Source
var CodingRates = map[uint8]string{
	5: CR5,
	6: CR6,
	7: CR7,
	8: CR8,
}

CodingRates is the mapping of the coding rates

View Source
var SFs = map[uint8]string{
	7:  SF7,
	8:  SF8,
	9:  SF9,
	10: SF10,
	11: SF11,
	12: SF12,
}

SFs is the mapping of the spreading factors

Functions

func Connect

func Connect()

Connect will connect to the serial device currently configured.

func Disconnect

func Disconnect()

Disconnect will disconnect the serial device that is currently connected. If no device is connected, it will recover from the panic.

func HardwareID

func HardwareID() string

HardwareID will return the HWEUI of the RN2483 module as a string. The HWEUI is actually an 8 bit hex string.

func MacGetADR

func MacGetADR() bool

MacGetADR will return the state of the adpative data rate mechanism.

func MacGetApplicationEUI

func MacGetApplicationEUI() string

MacGetApplicationEUI will return the current configured application EUI. The EUI is represented as a 8-byte hexadecimal number and returned as a string. The default value of 0000000000000000 will be returned in case of an error.

func MacGetChannelDutyCycle

func MacGetChannelDutyCycle(channelID uint8) float32

MacGetChannelDutyCycle will return the duty cycle on the requested channelID. The duty cycle will be returned as a percentage. The channelID has to be in the range of [0-15].

func MacGetChannelFrequency

func MacGetChannelFrequency(channelID uint8) uint32

MacGetChannelFrequency will return the frequency on the requested channelID. This frequency is returned in Hz. The channelID has to be in the range of [0-15].

func MacGetChannelStatus

func MacGetChannelStatus(channelID uint8) bool

MacGetChannelStatus will return if the given channelID is currently enabled for use. The channelID has to be in the range of [0-15].

func MacGetDataRate

func MacGetDataRate() uint8

MacGetDataRate will return the current data rate. The data rate is a number in the range of [0-5], with 0 = SF12BW125 and 5 = SF7BW125.

func MacGetDeviceAddress

func MacGetDeviceAddress() string

MacGetDeviceAddress will return the current end device address of the module. The address is represented as a 4-byte hexadecimal number and returned as a string. The default value of 00000000 will be returned in case of an error.

func MacGetDeviceEUI

func MacGetDeviceEUI() string

MacGetDeviceEUI will return the current end device EUI of the module. The EUI is represented as a 8-byte hexadecimal number and returned as a string. The default value of 0000000000000000 will be returned in case of an error.

func MacGetPowerIndex

func MacGetPowerIndex() uint8

MacGetPowerIndex will return the current power index. The power index is a number in the range of [0-5], with 0 = 20 dBm (if available), 1 = 14 dBm, 2 = 11 dBm, 3 = 8 dBm, 4 = 5dBm and 5 = 2 dBm.

func MacJoin

func MacJoin(mode string) bool

MacJoin will join the configured network with the given mode.

func MacPause

func MacPause() uint32

MacPause will pause the LoRaWAN stack functionality to allow transceiver (radio) configuration. The length is the time in milliseconds the stack will be paused, with a maximum of 4294967295 (max of uint32), is returned as an uint32.

func MacReset

func MacReset(band uint16) bool

MacReset will automatically reset the software LoRaWAN stack and initilize it with the parameters for the selected band.

func MacResume

func MacResume() bool

MacResume will resume the LoRaWAN stack functionality, in order to continue normal functionality after being paused.

func MacSetADR

func MacSetADR(adr bool) error

MacSetADR will set the adaptive data rate.

func MacSetApplicationEUI

func MacSetApplicationEUI(eui string) error

MacSetApplicationEUI will configure the module with a network application EUI. The EUI is a 8-byte hexadecimal value given as a string.

func MacSetApplicationKey

func MacSetApplicationKey(key string) error

MacSetApplicationKey will configure the module with an application key. The key is a 16-byte hexadecimal value given as a string.

func MacSetApplicationSessionKey

func MacSetApplicationSessionKey(key string) error

MacSetApplicationSessionKey will configure the module with an application session key. The key is a 16-byte hexadecimal value given as a string.

func MacSetChannelDutyCycle

func MacSetChannelDutyCycle(channelID uint8, dcycle float32) error

MacSetChannelDutyCycle will set the duty cycle used on the given channel id. The applicable range for the channel id is [0-15]. The duty cycle can be given as a percentage.

func MacSetChannelFrequency

func MacSetChannelFrequency(channelID uint8, frequency uint32) error

MacSetChannelFrequency will set the frequency on the given channel id. The default channels (0-2) cannot be modified. The applicable range for the channel id is [3-15]. The frequency has to be given in Hz.

func MacSetChannelStatus

func MacSetChannelStatus(channelID uint8, status bool) error

MacSetChannelStatus will set the operation on the given channel id. The applicable range for the channel id is [0-15].

func MacSetDataRate

func MacSetDataRate(dr uint8) error

MacSetDataRate will configure the data rate for the next transmission. The data rate has to be in the range of [0-5], with 0 = SF12BW125 and 5 = SF7BW125.

func MacSetDeviceAddress

func MacSetDeviceAddress(address string) error

MacSetDeviceAddress will configure the module with a network device address. The address is a 4-byte hexadecimal value given as a string.

func MacSetDeviceEUI

func MacSetDeviceEUI(eui string) error

MacSetDeviceEUI will configure the module with a network device EUI. The EUI is a 8-byte hexadecimal value given as a string.

func MacSetLinkCheck

func MacSetLinkCheck(interval uint16) error

MacSetLinkCheck will set the time interval for the link check process to be triggered.

func MacSetNetworkSessionKey

func MacSetNetworkSessionKey(key string) error

MacSetNetworkSessionKey will configure the module with a network session key. The key is a 16-byte hexadecimal value given as a string.

func MacSetPowerIndex

func MacSetPowerIndex(index uint8) error

MacSetPowerIndex will configure the power index for the next transmission. The index has to be in the range of [1-5] for 868 MHz and [0-5] for 433 MHz.

func MacTx

func MacTx(confirmed bool, port uint8, data []byte, callback receiveCallback) bool

MacTX will transmit the given data on the given port. The transmission can either be confirmed (if the boolean is set), meaning that the server will response with an acknowledgement. If no acknowledgement is received, the message will be retransmitted by the number indicated by the MacSetRetx command. The port number has to be a value in the range of [1,223]. The receiveCallback function passed is responsible to handle the received answer from the server. If no answers are expected, nil can be passed as the callback argument.

func RadioGetBandWidth

func RadioGetBandWidth() uint16

RadioGetBandWidth reads back the current bandwidth being used by the transceiver. It will return an uint16 with one of the values [125, 250, 500]. If an error occured, it will return 0.

func RadioGetCodingRate

func RadioGetCodingRate() uint8

RadioGetCodingRate reads back the current coding rate being used by the transceiver. It will return an uint8 between [5, 8]. If an error occured, it will return 0.

func RadioGetCrc

func RadioGetCrc() bool

RadioGetCrc reads back the status of the CRC header, to determine if it is to be included during operation. The function will return false as well if something went wrong.

func RadioGetFrequency

func RadioGetFrequency() uint32

RadioGetFrequency returns the current operation frequency of the module. If there was an error, the function will return 0.

func RadioGetIqi

func RadioGetIqi() bool

RadioGetIqi reads back the status of the Invert IQ functionality. The function will return false as well if something went wrong.

func RadioGetModulation

func RadioGetModulation() string

RadioGetModulation reads back the current mode of operation of the module. It returns an empty string if something went wrong.

func RadioGetPower

func RadioGetPower() int8

RadioGetPower reads back the current power level setting used in operation. The function will return an int8 value, which will be between [-3, 15]. If an error occured, it will return -15.

func RadioGetSNR

func RadioGetSNR() int8

RadioGetSNR reads back the Signal Noise Ratio (SNR) for the last received packet. The default is -128.

func RadioGetSpreadingFactor

func RadioGetSpreadingFactor() uint8

RadioGetSpreadingFactor reads back the current spreading factor being used by the transceiver. It will return an uint8 between [7, 12]. If an error occured, it will return 0.

func RadioGetSyncWord

func RadioGetSyncWord() bool

RadioGetSyncWord returns true if the sync word is set to public, and false when it is set to private. The function will return false as well if something went wrong.

func RadioGetWatchDogTimer

func RadioGetWatchDogTimer() uint32

RadioGetWatchDogTimer reads back, in milliseconds, the length used for the watchdog time-out. It will return an uint32. If an error occured, it will return 0 (this also means it is disabled).

func RadioRxBlocking

func RadioRxBlocking(window uint16) []byte

RadioRxBlocking will open the receiver. The window size is the number of symbols for LoRa modulation and the time in milliseconds for FSK modulation. In order to enable continuous reception, the window size should be 0. Don't forget to set the radio watchdog timer time-out! This function will return a valid packet that has been received, or an empty array of bytes when the receiver was busy or it timed out without receiving a valid packet. This function is blocking, which means if you enabled continous reception, it will block the program until a valid packet has been received or until a time out occured.

func RadioSetBandWidth

func RadioSetBandWidth(bw uint16) bool

RadioSetBandWidth sets the bandwidth used during transmission. The bandwidth has to be passed as an uint16 and has to be one of [125, 250, 500]. The function will return true if the command succeeded. If an error occured, it will return false.

func RadioSetCodingRate

func RadioSetCodingRate(cr uint8) bool

RadioSetCodingRate sets the coding rate used during transmission. The coding rate has to be passed as an uint8 between [5, 8]. The function will return true if the command succeeded. If an error occured, it will return false.

func RadioSetCrc

func RadioSetCrc(on bool) bool

RadioSetCrc enables or disables the CRC header for communications. The function will return true if the command succeeded, or false when it didn't.

func RadioSetFrequency

func RadioSetFrequency(freq uint32) bool

RadioSetFrequency changes the communication frequency of the radio transceiver. It will only accept frequencies between [433050000, 434790000] and [863000000, 870000000]. The function will return true when the frequency changed and false when an error occured.

func RadioSetIqi

func RadioSetIqi(on bool) bool

RadioSetIqi enables or disables the Invert IQ for communications. The function will return true if the command succeeded, or false when it didn't.

func RadioSetModulation

func RadioSetModulation(mod string) bool

RadioSetModulation changes the modulation method being used by the module. The modulations are available as constants in the package. The function will return true when the change is accepted by the module. When the change isn't accepted or the modulation is wrong, it will return false.

func RadioSetPower

func RadioSetPower(pwr int8) bool

RadioSetPower changes the transceiver output power. The output power has to be passed as an int8 value between [-3, 15]. The function will return true if the change succeeeded, or false when an error occured.

func RadioSetSpreadingFactor

func RadioSetSpreadingFactor(sf uint8) bool

RadioSetSpreadingFactor sets the spreading factor used during transmission. The spreading factor has to be passed as an uint8 between [7, 12]. The function will return true if the command succeeded. If an error occured, it will return false.

func RadioSetSyncWord

func RadioSetSyncWord(public bool) bool

RadioSetSyncWord sets the sync word to either public or private. This is done by passing a boolean (public) which is true for public and false for private. The function will return true if the command succeeded, or false when it didn't.

func RadioSetWatchDogTimer

func RadioSetWatchDogTimer(length uint32) bool

RadioSetWatchDogTimer updates the time-out length, in milliseconds, applied to the radio Watchdog Timer. If this functionality is enabled, then the Watchdog Timer is started for every transceiver reception or transmission. The Watchdog Timer is stopped when the operation in progress in finished. The function will return true if the command succeeded. If an error occured, it will return false.

func RadioTx

func RadioTx(data []byte) bool

RadioTx will transmit the given data. The data has to have a length > 0 but has to be smaller than 255 if LoRa modulation is active or smaller than 64 if FSK modulation is active. It will return a boolean, true if the transmit was succesful, false is there was an error. For more info about the error, the user can check the log file.

func ReadByte

func ReadByte(address uint16) (byte, error)

ReadByte returns the data stored in the EEPROM at the specified address.

func Reset

func Reset() bool

Reset will reset and restart the RN2483 module.

func SaveByte

func SaveByte(address uint16, data uint8) bool

SaveByte allows the user to modify the EEPROM at the specified address with the specified data (one byte).

func SetBaud

func SetBaud(baud int)

SetBaud sets a new baud rate for the serial connection. Reconnect to the serial device required!

func SetName

func SetName(name string)

SetName sets a new device name for the serial connection. Reconnect to the serial device required!

func SetTimeout

func SetTimeout(timeout time.Duration)

SetTimeout sets a new read timeout for the serial connection. Reconnect to the serial device required!

func Sleep

func Sleep(length uint32) bool

Sleep puts the RN2483 chip to sleep for the specified number of milliseconds.

func Version

func Version() string

Version returns the information related to the hardware platform, firmware version, release date and time stamp on firmware creation.

func Voltage

func Voltage() (uint16, error)

Voltage will return the voltage measured on Vdd in millivolts

Types

type Logger

type Logger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}
var (
	ERROR Logger = NOOPLogger{}
	WARN  Logger = NOOPLogger{}
	DEBUG Logger = NOOPLogger{}
)

type NOOPLogger

type NOOPLogger struct{}

func (NOOPLogger) Printf

func (NOOPLogger) Printf(format string, v ...interface{})

func (NOOPLogger) Println

func (NOOPLogger) Println(v ...interface{})

Jump to

Keyboard shortcuts

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