Class Sx126x
The Semtech SX1261, SX1262, SX1268, and LLCC68 LoRa transceivers.
public static class Sx126x
- Inheritance
-
Sx126x
- Inherited Members
Remarks
Every command returns the bytes of one SPI transaction, which the caller sends once the chip's BUSY line is low, and every decoder turns the bytes the chip answered with into values. Nothing here touches a bus, so the same code plans a transmission on a host with no radio attached and checks a capture taken from one that has.
Fields
RegisterLoraSyncWord
The register the two bytes of the LoRa sync word are written to.
public const ushort RegisterLoraSyncWord = 1856
Field Value
RxContinuous
The SetRx timeout that keeps the receiver listening until told otherwise.
public const uint RxContinuous = 16777215
Field Value
SyncWordPrivate
The LoRa sync word private networks use.
public const ushort SyncWordPrivate = 5156
Field Value
SyncWordPublic
The LoRa sync word public LoRaWAN networks use.
public const ushort SyncWordPublic = 13380
Field Value
Methods
CalibrateImage(uint, uint)
Builds CalibrateImage for the band a radio operates in.
public static byte[] CalibrateImage(uint lowHz, uint highHz)
Parameters
lowHzuintThe lowest frequency the radio uses, in hertz.
highHzuintThe highest frequency the radio uses, in hertz.
Returns
- byte[]
The command bytes.
ClearIrqStatus(Sx126xIrq)
Builds ClearIrqStatus.
public static byte[] ClearIrqStatus(Sx126xIrq irq)
Parameters
irqSx126xIrqThe interrupts to clear.
Returns
- byte[]
The command bytes.
DeviceErrors(ReadOnlySpan<byte>)
Decodes a GetDeviceErrors answer.
public static Sx126xDeviceErrors DeviceErrors(ReadOnlySpan<byte> answer)
Parameters
answerReadOnlySpan<byte>The two answer bytes.
Returns
- Sx126xDeviceErrors
The faults reported.
Exceptions
- ArgumentException
The answer is not two bytes.
FrequencyWord(uint)
Returns the RF frequency word SetRfFrequency carries.
public static uint FrequencyWord(uint frequencyHz)
Parameters
frequencyHzuintThe carrier frequency in hertz.
Returns
- uint
The frequency in steps of 32 MHz over 2^25.
GetDeviceErrors()
Builds GetDeviceErrors.
public static Sx126xQuery GetDeviceErrors()
Returns
- Sx126xQuery
The query, whose answer DeviceErrors(ReadOnlySpan<byte>) decodes.
GetIrqStatus()
Builds GetIrqStatus.
public static Sx126xQuery GetIrqStatus()
Returns
- Sx126xQuery
The query, whose answer Irq(ReadOnlySpan<byte>) decodes.
GetPacketStatus()
Builds GetPacketStatus.
public static Sx126xQuery GetPacketStatus()
Returns
- Sx126xQuery
The query, whose answer PacketStatus(ReadOnlySpan<byte>) decodes.
GetRssiInst()
Builds GetRssiInst.
public static Sx126xQuery GetRssiInst()
Returns
- Sx126xQuery
The query, whose answer RssiInstDbm(byte) decodes.
GetRxBufferStatus()
Builds GetRxBufferStatus.
public static Sx126xQuery GetRxBufferStatus()
Returns
- Sx126xQuery
The query, whose answer RxBufferStatus(ReadOnlySpan<byte>) decodes.
GetStatus()
Builds GetStatus.
public static Sx126xQuery GetStatus()
Returns
- Sx126xQuery
The query.
ImageCalibration(uint, uint)
Returns the CalibrateImage codes for the band a radio operates in.
public static byte[] ImageCalibration(uint lowHz, uint highHz)
Parameters
lowHzuintThe lowest frequency the radio uses, in hertz.
highHzuintThe highest frequency the radio uses, in hertz.
Returns
- byte[]
The two calibration codes.
Irq(ReadOnlySpan<byte>)
Decodes a GetIrqStatus answer.
public static Sx126xIrq Irq(ReadOnlySpan<byte> answer)
Parameters
answerReadOnlySpan<byte>The two answer bytes.
Returns
- Sx126xIrq
The interrupts raised.
Exceptions
- ArgumentException
The answer is not two bytes.
Llcc68Supports(LoraLink)
Reports whether an LLCC68 supports a link's spreading factor at its bandwidth.
public static bool Llcc68Supports(LoraLink link)
Parameters
linkLoraLinkThe link settings.
Returns
- bool
truewhen an LLCC68 can use the link: up to SF9 at 125 kHz, SF10 at 250 kHz, and SF11 at 500 kHz, and no bandwidth below 125 kHz.
PacketStatus(ReadOnlySpan<byte>)
Decodes a GetPacketStatus answer.
public static Sx126xPacketStatus PacketStatus(ReadOnlySpan<byte> answer)
Parameters
answerReadOnlySpan<byte>The three answer bytes.
Returns
- Sx126xPacketStatus
The signal levels the frame was received at.
Exceptions
- ArgumentException
The answer is not three bytes.
RampTimeMicros(uint)
Returns the shortest ramp time the chip offers that lasts at least a duration.
public static uint RampTimeMicros(uint atLeastMicros)
Parameters
atLeastMicrosuintThe least ramp time wanted, in microseconds; past 3400, the longest ramp there is.
Returns
- uint
The ramp time in microseconds.
ReadBuffer(byte, byte)
Builds ReadBuffer for a run of buffer bytes.
public static Sx126xQuery ReadBuffer(byte offset, byte length)
Parameters
Returns
- Sx126xQuery
The query.
ReadRegister(ushort, byte)
Builds ReadRegister for a run of registers.
public static Sx126xQuery ReadRegister(ushort address, byte length)
Parameters
Returns
- Sx126xQuery
The query.
RssiInstDbm(byte)
Decodes a GetRssiInst answer.
public static double RssiInstDbm(byte value)
Parameters
valuebyteThe answer byte.
Returns
- double
The signal level the receiver hears right now, in dBm.
RxBufferStatus(ReadOnlySpan<byte>)
Decodes a GetRxBufferStatus answer.
public static Sx126xRxBufferStatus RxBufferStatus(ReadOnlySpan<byte> answer)
Parameters
answerReadOnlySpan<byte>The two answer bytes.
Returns
- Sx126xRxBufferStatus
The payload length and where it starts.
Exceptions
- ArgumentException
The answer is not two bytes.
SetDioIrqParams(Sx126xIrq, Sx126xIrq, Sx126xIrq, Sx126xIrq)
Builds SetDioIrqParams.
public static byte[] SetDioIrqParams(Sx126xIrq irq, Sx126xIrq dio1, Sx126xIrq dio2 = Sx126xIrq.None, Sx126xIrq dio3 = Sx126xIrq.None)
Parameters
irqSx126xIrqThe interrupts the chip raises at all.
dio1Sx126xIrqThe interrupts that drive DIO1.
dio2Sx126xIrqThe interrupts that drive DIO2.
dio3Sx126xIrqThe interrupts that drive DIO3.
Returns
- byte[]
The command bytes.
SetLoraModulationParams(LoraLink)
Builds SetModulationParams for a LoRa link.
public static byte[] SetLoraModulationParams(LoraLink link)
Parameters
linkLoraLinkThe link settings.
Returns
- byte[]
The command bytes, with low data-rate optimization on where the datasheet asks for it.
Exceptions
- PamojaException
The chip has no such bandwidth.
SetLoraPacketParams(LoraLink, byte, bool)
Builds SetPacketParams for a LoRa link.
public static byte[] SetLoraPacketParams(LoraLink link, byte payloadLength, bool invertIq)
Parameters
linkLoraLinkThe link settings.
payloadLengthbyteThe payload length in bytes.
invertIqboolWhether to invert the IQ signals, as a LoRaWAN downlink does.
Returns
- byte[]
The command bytes.
SetPaConfig(Sx126xTxPower)
Builds SetPaConfig.
public static byte[] SetPaConfig(Sx126xTxPower power)
Parameters
powerSx126xTxPowerThe amplifier setting.
Returns
- byte[]
The command bytes.
SetPacketTypeLora()
Builds SetPacketType for LoRa.
public static byte[] SetPacketTypeLora()
Returns
- byte[]
The command bytes.
SetRfFrequency(uint)
Builds SetRfFrequency.
public static byte[] SetRfFrequency(uint frequencyHz)
Parameters
frequencyHzuintThe carrier frequency in hertz.
Returns
- byte[]
The command bytes.
SetRx(ulong)
Builds SetRx.
public static byte[] SetRx(ulong timeoutMicros)
Parameters
timeoutMicrosulongHow long to listen for a frame, in microseconds;
0listens for one frame however long it takes.
Returns
- byte[]
The command bytes.
SetRxContinuous()
Builds SetRx that keeps listening, frame after frame, until told otherwise.
public static byte[] SetRxContinuous()
Returns
- byte[]
The command bytes.
SetSleep(bool)
Builds SetSleep.
public static byte[] SetSleep(bool warmStart)
Parameters
warmStartboolWhether to keep the configuration through sleep.
Returns
- byte[]
The command bytes.
SetStandby()
Builds SetStandby into the RC oscillator standby.
public static byte[] SetStandby()
Returns
- byte[]
The command bytes.
SetTx(ulong)
Builds SetTx.
public static byte[] SetTx(ulong timeoutMicros)
Parameters
timeoutMicrosulongHow long the chip may take to send the frame before it gives up, in microseconds;
0waits for the frame however long it takes.
Returns
- byte[]
The command bytes.
SetTxParams(Sx126xTxPower, uint)
Builds SetTxParams.
public static byte[] SetTxParams(Sx126xTxPower power, uint rampMicros)
Parameters
powerSx126xTxPowerThe amplifier setting.
rampMicrosuintThe least ramp time wanted, in microseconds.
Returns
- byte[]
The command bytes.
Status(byte)
Decodes a status byte.
public static Sx126xStatus Status(byte value)
Parameters
valuebyteThe byte the chip returned.
Returns
- Sx126xStatus
The operating mode and the outcome of the last command.
TimeoutSteps(ulong)
Returns a timeout in the chip's steps.
public static uint TimeoutSteps(ulong timeoutMicros)
Parameters
timeoutMicrosulongThe timeout in microseconds.
Returns
- uint
The timeout in 15.625 microsecond steps, rounded up.
TxPower(Sx126xAmplifier, sbyte)
Returns the amplifier setting that delivers an output power.
public static Sx126xTxPower TxPower(Sx126xAmplifier amplifier, sbyte outputDbm)
Parameters
amplifierSx126xAmplifierThe amplifier the chip carries.
outputDbmsbyteThe power wanted at the antenna port, in dBm.
Returns
- Sx126xTxPower
The setting, clamped to what the amplifier can deliver.
TxPowerUnderCeiling(Sx126xAmplifier, LoraLinkBudget, double)
Returns the strongest amplifier setting that keeps a link under an EIRP ceiling.
public static Sx126xTxPower TxPowerUnderCeiling(Sx126xAmplifier amplifier, LoraLinkBudget budget, double eirpCeilingDbm)
Parameters
amplifierSx126xAmplifierThe amplifier the chip carries.
budgetLoraLinkBudgetThe antenna gain and cable loss between the chip and the air.
eirpCeilingDbmdoubleThe most EIRP allowed, such as a plan's limit for the channel.
Returns
- Sx126xTxPower
The setting, in whole decibels rounded down so the ceiling holds.
WriteBuffer(byte, ReadOnlySpan<byte>)
Builds WriteBuffer for a payload.
public static byte[] WriteBuffer(byte offset, ReadOnlySpan<byte> payload)
Parameters
offsetbyteThe buffer offset the payload starts at.
payloadReadOnlySpan<byte>The payload.
Returns
- byte[]
The whole transaction: the header followed by the payload.
WriteRegister(ushort, ReadOnlySpan<byte>)
Builds WriteRegister for a run of registers.
public static byte[] WriteRegister(ushort address, ReadOnlySpan<byte> values)
Parameters
addressushortThe first register.
valuesReadOnlySpan<byte>The values, one per register.
Returns
- byte[]
The whole transaction: the header followed by the values.