linguini1 opened a new pull request, #15828:
URL: https://github.com/apache/nuttx/pull/15828
## Summary
Add support for the RN903 and RN2483 family of LoRa radio transceivers. This
initial support includes transmit and receive functionality and configuration
and reading of radio parameters like frequency and bandwidth.
## Impact
NuttX users can now use these radio transceivers!
This changes touches the build system, wireless drivers and documentation.
The documentation includes examples of how to use the driver and its available
commands.
## Testing
Testing was performed from an RP2040 based custom flight computer. The chip
this code was tested again was the RN2903, but commands for both modules are
the same. The only difference is the values allowed for each command, but the
radio module does its own error checking so the driver code will not need to
change between modules.
The test script that was used to test the commands was:
```c
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <syslog.h>
#include <unistd.h>
#include <nuttx/wireless/lpwan/rn2xx3.h>
#define handle_errno(msg, err)
\
if ((err) < 0)
\
{
\
fprintf(stderr, msg ": %d\n", errno);
\
return EXIT_FAILURE;
\
}
int main(int argc, FAR char *argv[])
{
int err;
int radio;
int fd;
int cnt;
unsigned int num = 0;
char ch;
char line[MINMEA_MAX_LENGTH];
char *port = "/dev/ttyS0";
radio = open("/dev/rn2903", O_RDWR);
if (radio < 0)
{
fprintf(stderr, "Couldn't open RN2903: %d\n", errno);
return EXIT_FAILURE;
}
/* Set frequency */
err = ioctl(radio, WLIOC_SETRADIOFREQ, 902400000);
handle_errno("Couldn't set freq", err);
/* Get frequency */
uint32_t freq;
err = ioctl(radio, WLIOC_GETRADIOFREQ, &freq);
handle_errno("Couldn't get freq", err);
printf("Frequency: %lu Hz\n", freq);
/* Set TX power */
float txpower = 12.0;
err = ioctl(radio, WLIOC_SETTXPOWER, &txpower);
handle_errno("Couldn't set txpwr", err);
printf("Transmit power set to %.2f dBm\n", txpower);
/* Get TX power */
int8_t txpwr;
err = ioctl(radio, WLIOC_GETTXPOWER, &txpwr);
handle_errno("Couldn't get txpwr", err);
printf("Tx power level: %d\n", txpwr);
/* Get SNR */
int8_t snr;
err = ioctl(radio, WLIOC_GETSNR, &snr);
handle_errno("Couldn't get snr", err);
printf("SNR: %d\n", snr);
/* Set preamble length */
err = ioctl(radio, WLIOC_SETPRLEN, 8);
handle_errno("Couldn't set prlen", err);
/* Get preamble length */
uint16_t prlen;
err = ioctl(radio, WLIOC_GETPRLEN, &prlen);
handle_errno("Couldn't get prlen", err);
printf("Preamble length: %u\n", prlen);
/* Set spread */
err = ioctl(radio, WLIOC_SETSPREAD, 8);
handle_errno("Couldn't set spread factor", err);
/* Get spread */
uint8_t spread;
err = ioctl(radio, WLIOC_GETSPREAD, &spread);
handle_errno("Couldn't get spread factor", err);
printf("Spread factor: sf%u\n", spread);
usleep(10000);
/* Set modulation */
err = ioctl(radio, WLIOC_SETMOD, RN2XX3_MOD_FSK);
handle_errno("Couldn't set modulation", err);
/* Get modulation */
char modulation[10];
err = ioctl(radio, WLIOC_GETMOD, modulation);
handle_errno("Couldn't get modulation", err);
printf("Modulation: %s\n", modulation);
usleep(10000);
/* Set bandwidth */
uint32_t bandwidth = 250;
err = ioctl(radio, WLIOC_SETBANDWIDTH, bandwidth);
handle_errno("Couldn't set bw", err);
/* Get bandwidth */
err = ioctl(radio, WLIOC_GETBANDWIDTH, &bandwidth);
handle_errno("Couldn't get bw", err);
printf("Bandwidth: %lu kHz\n", bandwidth);
return 0;
}
```
The output is:
```console
nsh> hello
Frequency: 902400000 Hz
Transmit power set to 12.00 dBm
Tx power level: 11
SNR: -128
Preamble length: 8
Spread factor: sf8
Modulation: fsk
Bandwidth: 250 kHz
nsh>
```
I also performed transmit/receive testing using a second RN2903 which I used
to transmit/receive from a Python script. I was able to successfully receive
messages sent from the NuttX driver, and I was also able to successfully
receive messages with the NuttX driver sent from the Python script controlled
transceiver.
The code works with `read/write` functions, so it can be `echo`ed into or
`cat`ted from to transmit and receive in the shell.
Documentation was built locally and verified for correct render in the
browser.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]