Skip to content

Commit

Permalink
output rssi in all FSK examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Jul 25, 2024
1 parent bdc173a commit eaa7313
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
25 changes: 17 additions & 8 deletions examples/receive_fsk/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ TaskHandle_t handle_interrupt;
int total_packets_received = 0;
static const char *TAG = "sx127x";

void IRAM_ATTR handle_interrupt_fromisr(void *arg) {
void IRAM_ATTR

handle_interrupt_fromisr(void *arg) {
xTaskResumeFromISR(handle_interrupt);
}

void handle_interrupt_task(void *arg) {
while (1) {
vTaskSuspend(NULL);
sx127x_handle_interrupt((sx127x *)arg);
sx127x_handle_interrupt((sx127x *) arg);
}
}

Expand All @@ -50,7 +52,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) {

int32_t frequency_error;
ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error));
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
int16_t rssi;
int code = sx127x_rx_get_packet_rssi(device, &rssi);
if (code == SX127X_ERR_NOT_FOUND) {
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
} else {
ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error);
}
total_packets_received++;
}

Expand All @@ -59,7 +67,7 @@ void setup_gpio_interrupts(gpio_num_t gpio, sx127x *device) {
gpio_pulldown_en(gpio);
gpio_pullup_dis(gpio);
gpio_set_intr_type(gpio, GPIO_INTR_POSEDGE);
gpio_isr_handler_add(gpio, handle_interrupt_fromisr, (void *)device);
gpio_isr_handler_add(gpio, handle_interrupt_fromisr, (void *) device);
}

void app_main() {
Expand Down Expand Up @@ -89,7 +97,7 @@ void app_main() {
.address_bits = 8,
.dummy_bits = 0,
.mode = 0};
spi_device_handle_t spi_device;
spi_device_handle_t spi_device;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_device));
ESP_ERROR_CHECK(sx127x_create(spi_device, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device));
Expand All @@ -110,6 +118,7 @@ void app_main() {
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device));

sx127x_rx_set_callback(rx_callback, device);

Expand All @@ -121,9 +130,9 @@ void app_main() {
}

gpio_install_isr_service(0);
setup_gpio_interrupts((gpio_num_t)DIO0, device);
setup_gpio_interrupts((gpio_num_t)DIO1, device);
setup_gpio_interrupts((gpio_num_t)DIO2, device);
setup_gpio_interrupts((gpio_num_t) DIO0, device);
setup_gpio_interrupts((gpio_num_t) DIO1, device);
setup_gpio_interrupts((gpio_num_t) DIO2, device);

ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));
}
8 changes: 7 additions & 1 deletion examples/receive_fsk_beacon/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) {

int32_t frequency_error;
ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error));
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
int16_t rssi;
int code = sx127x_rx_get_packet_rssi(device, &rssi);
if (code == SX127X_ERR_NOT_FOUND) {
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
} else {
ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error);
}
total_packets_received++;
}

Expand Down
8 changes: 7 additions & 1 deletion examples/receive_fsk_filtered/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) {

int32_t frequency_error;
ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error));
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
int16_t rssi;
int code = sx127x_rx_get_packet_rssi(device, &rssi);
if (code == SX127X_ERR_NOT_FOUND) {
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
} else {
ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error);
}
total_packets_received++;
}

Expand Down
8 changes: 7 additions & 1 deletion examples/receive_fsk_fixed/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) {

int32_t frequency_error;
ESP_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error));
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
int16_t rssi;
int code = sx127x_rx_get_packet_rssi(device, &rssi);
if (code == SX127X_ERR_NOT_FOUND) {
ESP_LOGI(TAG, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
} else {
ESP_LOGI(TAG, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error);
}
total_packets_received++;
}

Expand Down
16 changes: 11 additions & 5 deletions examples/receive_fsk_raspberrypi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define GPIO_DIO1_PIN 13
#define GPIO_DIO2_PIN 19
#define GPIO_DIO3_PIN 26
#define GPIO_DIO4_PIN 5
#define GPIO_DIO0_PIN 27
#define GPIO_RESET_PIN 6
#define GPIO_POLL_TIMEOUT (-1)
Expand Down Expand Up @@ -50,11 +51,15 @@ void rx_callback(sx127x *device, uint8_t *data, uint16_t data_length) {
}
payload[data_length * 2] = '\0';

int16_t rssi;
LINUX_NO_CODE_ERROR_CHECK(sx127x_rx_get_packet_rssi(device, &rssi));
int32_t frequency_error;
LINUX_NO_CODE_ERROR_CHECK(sx127x_rx_get_frequency_error(device, &frequency_error));
fprintf(stdout, "received: %d %s rssi: %d freq_error: %" PRId32 "\n", data_length, payload, rssi, frequency_error);
int16_t rssi;
int code = sx127x_rx_get_packet_rssi(device, &rssi);
if (code == SX127X_ERR_NOT_FOUND) {
fprintf(stdout, "received: %d %s freq_error: %" PRId32, data_length, payload, frequency_error);
} else {
fprintf(stdout, "received: %d %s rssi: %d freq_error: %" PRId32, data_length, payload, rssi, frequency_error);
}
}

int msleep(long msec) {
Expand Down Expand Up @@ -120,9 +125,9 @@ int setup_and_wait_for_interrupt(sx127x *device) {
perror("unable to open device");
return EXIT_FAILURE;
}
uint8_t gpios[] = {GPIO_DIO0_PIN, GPIO_DIO1_PIN, GPIO_DIO2_PIN, GPIO_DIO3_PIN};
uint8_t gpios[] = {GPIO_DIO0_PIN, GPIO_DIO1_PIN, GPIO_DIO2_PIN, GPIO_DIO3_PIN, GPIO_DIO4_PIN};
int gpios_length = sizeof(gpios);
struct pollfd pfd[4];
struct pollfd pfd[5];
for (int i = 0; i < gpios_length; i++) {
struct gpioevent_request rq;
rq.lineoffset = gpios[i];
Expand Down Expand Up @@ -200,6 +205,7 @@ int main() {
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device));

sx127x_rx_set_callback(rx_callback, device);
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));
Expand Down
8 changes: 4 additions & 4 deletions examples/receive_ook/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#define RST 23
#define DIO0 26
// older versions of TTGO require manual wiring of pins below
//#define DIO1 33
//#define DIO2 32
#define DIO1 33
#define DIO2 32

// Heltec lora32 v2
#define DIO1 35
#define DIO2 34
//#define DIO1 35
//#define DIO2 34

sx127x *device = NULL;
TaskHandle_t handle_interrupt;
Expand Down

0 comments on commit eaa7313

Please sign in to comment.