Skip to content

Commit

Permalink
Merge pull request #11144 from jia200x/pr/netdev_lora_rx_info
Browse files Browse the repository at this point in the history
netdev/lora: add netdev_lora_rx_info structure for RX info
  • Loading branch information
aabadie authored Mar 8, 2019
2 parents 65fd51c + d3de1d7 commit d562af4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
46 changes: 46 additions & 0 deletions drivers/include/net/netdev/lora.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2019 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for
* more details.
*/

/**
* @defgroup drivers_netdev_lora LoRa drivers
* @ingroup drivers_netdev_api
* @{
*
* @file
* @brief Definitions for netdev common LoRa code
*
* @author José Ignacio Alamos <jose.alamos@haw-hamburg.de>
*/


#ifndef NET_NETDEV_LORA_H
#define NET_NETDEV_LORA_H

#include <stdint.h>

#include "net/netdev.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Received LoRa packet status information
*/
typedef struct {
uint8_t rssi; /**< RSSI of a received packet */
int8_t snr; /**< S/N ratio */
} netdev_lora_rx_info_t;


#ifdef __cplusplus
}
#endif

#endif /* NET_NETDEV_LORA_H */
/** @} */
9 changes: 0 additions & 9 deletions drivers/sx127x/include/sx127x_netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ extern "C" {
*/
extern const netdev_driver_t sx127x_driver;

/**
* @brief Received LoRa packet status information
*/
typedef struct netdev_radio_lora_packet_info {
uint8_t rssi; /**< RSSI of a received packet */
uint8_t lqi; /**< LQI of a received packet */
int8_t snr; /**< S/N ratio */
} netdev_sx127x_lora_packet_info_t;

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions drivers/sx127x/sx127x_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "net/netopt.h"
#include "net/netdev.h"
#include "net/netdev/lora.h"
#include "net/lora.h"

#include "sx127x_registers.h"
Expand Down Expand Up @@ -119,10 +120,8 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
return -EBADMSG;
}

netdev_sx127x_lora_packet_info_t *packet_info = info;
netdev_lora_rx_info_t *packet_info = info;
if (packet_info) {
/* there is no LQI for LoRa */
packet_info->lqi = 0;
uint8_t snr_value = sx127x_reg_read(dev, SX127X_REG_LR_PKTSNRVALUE);
if (snr_value & 0x80) { /* The SNR is negative */
/* Invert and divide by 4 */
Expand Down
3 changes: 2 additions & 1 deletion pkg/semtech-loramac/contrib/semtech_loramac.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "mutex.h"

#include "net/netdev.h"
#include "net/netdev/lora.h"
#include "net/loramac.h"

#include "sx127x.h"
Expand Down Expand Up @@ -579,7 +580,7 @@ static void _semtech_loramac_call(semtech_loramac_func_t func, void *arg)

static void _semtech_loramac_event_cb(netdev_t *dev, netdev_event_t event)
{
netdev_sx127x_lora_packet_info_t packet_info;
netdev_lora_rx_info_t packet_info;

msg_t msg;
msg.content.ptr = dev;
Expand Down
3 changes: 2 additions & 1 deletion tests/driver_sx127x/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "shell_commands.h"

#include "net/netdev.h"
#include "net/netdev/lora.h"
#include "net/lora.h"

#include "board.h"
Expand Down Expand Up @@ -324,7 +325,7 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
}
else {
size_t len;
netdev_sx127x_lora_packet_info_t packet_info;
netdev_lora_rx_info_t packet_info;
switch (event) {
case NETDEV_EVENT_RX_STARTED:
puts("Data reception started");
Expand Down

0 comments on commit d562af4

Please # to comment.