pkg/semtech-loramac: make RX optional

This commit is contained in:
Alexandre Abadie 2019-05-29 10:10:16 +02:00
parent f2c63c86fd
commit b5c48ef04e
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
4 changed files with 31 additions and 1 deletions

View File

@ -68,6 +68,7 @@ PSEUDOMODULES += saul_gpio
PSEUDOMODULES += saul_nrf_temperature PSEUDOMODULES += saul_nrf_temperature
PSEUDOMODULES += scanf_float PSEUDOMODULES += scanf_float
PSEUDOMODULES += schedstatistics PSEUDOMODULES += schedstatistics
PSEUDOMODULES += semtech_loramac_rx
PSEUDOMODULES += sock PSEUDOMODULES += sock
PSEUDOMODULES += sock_ip PSEUDOMODULES += sock_ip
PSEUDOMODULES += sock_tcp PSEUDOMODULES += sock_tcp

View File

@ -606,6 +606,7 @@ void *_semtech_loramac_event_loop(void *arg)
msg_send(&msg_ret, mac->tx_pid); msg_send(&msg_ret, mac->tx_pid);
break; break;
} }
#ifdef MODULE_SEMTECH_LORAMAC_RX
case MLME_LINK_CHECK: case MLME_LINK_CHECK:
if (confirm->Status == LORAMAC_EVENT_INFO_STATUS_OK) { if (confirm->Status == LORAMAC_EVENT_INFO_STATUS_OK) {
mac->link_chk.demod_margin = confirm->DemodMargin; mac->link_chk.demod_margin = confirm->DemodMargin;
@ -619,6 +620,7 @@ void *_semtech_loramac_event_loop(void *arg)
msg_ret.content.value = SEMTECH_LORAMAC_RX_LINK_CHECK; msg_ret.content.value = SEMTECH_LORAMAC_RX_LINK_CHECK;
msg_send(&msg_ret, mac->rx_pid); msg_send(&msg_ret, mac->rx_pid);
} }
#endif
default: default:
break; break;
} }
@ -732,6 +734,7 @@ void *_semtech_loramac_event_loop(void *arg)
_semtech_loramac_send(mac, NULL, 0); _semtech_loramac_send(mac, NULL, 0);
mac->port = prev_port; mac->port = prev_port;
} }
#ifdef MODULE_SEMTECH_LORAMAC_RX
if (indication->RxData) { if (indication->RxData) {
DEBUG("[semtech-loramac] MCPS indication: data received\n"); DEBUG("[semtech-loramac] MCPS indication: data received\n");
memcpy(mac->rx_data.payload, memcpy(mac->rx_data.payload,
@ -755,6 +758,7 @@ void *_semtech_loramac_event_loop(void *arg)
msg_ret.content.value = SEMTECH_LORAMAC_RX_CONFIRMED; msg_ret.content.value = SEMTECH_LORAMAC_RX_CONFIRMED;
msg_send(&msg_ret, mac->rx_pid); msg_send(&msg_ret, mac->rx_pid);
} }
#endif
break; break;
} }
@ -825,6 +829,7 @@ uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type)
return SEMTECH_LORAMAC_JOIN_SUCCEEDED; return SEMTECH_LORAMAC_JOIN_SUCCEEDED;
} }
#ifdef MODULE_SEMTECH_LORAMAC_RX
void semtech_loramac_request_link_check(semtech_loramac_t *mac) void semtech_loramac_request_link_check(semtech_loramac_t *mac)
{ {
mutex_lock(&mac->lock); mutex_lock(&mac->lock);
@ -833,6 +838,7 @@ void semtech_loramac_request_link_check(semtech_loramac_t *mac)
LoRaMacMlmeRequest(&mlmeReq); LoRaMacMlmeRequest(&mlmeReq);
mutex_unlock(&mac->lock); mutex_unlock(&mac->lock);
} }
#endif
uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len) uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
{ {
@ -856,6 +862,7 @@ uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
return (uint8_t)msg.content.value; return (uint8_t)msg.content.value;
} }
#ifdef MODULE_SEMTECH_LORAMAC_RX
uint8_t semtech_loramac_recv(semtech_loramac_t *mac) uint8_t semtech_loramac_recv(semtech_loramac_t *mac)
{ {
/* Correctly set the receiver thread pid */ /* Correctly set the receiver thread pid */
@ -868,3 +875,4 @@ uint8_t semtech_loramac_recv(semtech_loramac_t *mac)
return (uint8_t)msg.content.value; return (uint8_t)msg.content.value;
} }
#endif

View File

@ -96,7 +96,12 @@
* } * }
* ``` * ```
* *
* To receive downlink messages, use a dedicated receiving thread. * To receive downlink messages, enable the `semtech_loramac_rx` and use a
* dedicated receiving thread.
* - In the application Makefile, add
* ```mk
* USEMODULE += semtech_loramac_rx
* ```
* - At the beginning of the application source file, add the necessary * - At the beginning of the application source file, add the necessary
* includes and declare the message queue and stack arrays: * includes and declare the message queue and stack arrays:
* ```c * ```c

View File

@ -99,6 +99,7 @@ typedef struct {
uint8_t port; /**< RX port */ uint8_t port; /**< RX port */
} semtech_loramac_rx_data_t; } semtech_loramac_rx_data_t;
#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
/** /**
* @brief LoRaMAC link check information * @brief LoRaMAC link check information
*/ */
@ -106,6 +107,7 @@ typedef struct {
uint8_t demod_margin; /**< Demodulation margin */ uint8_t demod_margin; /**< Demodulation margin */
uint8_t nb_gateways; /**< number of LoRa gateways found */ uint8_t nb_gateways; /**< number of LoRa gateways found */
} semtech_loramac_link_check_info_t; } semtech_loramac_link_check_info_t;
#endif
/** /**
* @brief Semtech LoRaMAC descriptor * @brief Semtech LoRaMAC descriptor
@ -113,7 +115,9 @@ typedef struct {
typedef struct { typedef struct {
mutex_t lock; /**< loramac access lock */ mutex_t lock; /**< loramac access lock */
uint8_t tx_pid; /**< pid of sender thread */ uint8_t tx_pid; /**< pid of sender thread */
#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
uint8_t rx_pid; /**< pid of receiver thread */ uint8_t rx_pid; /**< pid of receiver thread */
#endif
uint8_t port; /**< application TX port */ uint8_t port; /**< application TX port */
uint8_t cnf; /**< enable/disable confirmable messages */ uint8_t cnf; /**< enable/disable confirmable messages */
uint8_t deveui[LORAMAC_DEVEUI_LEN]; /**< device EUI */ uint8_t deveui[LORAMAC_DEVEUI_LEN]; /**< device EUI */
@ -122,8 +126,10 @@ typedef struct {
uint8_t appskey[LORAMAC_APPSKEY_LEN]; /**< application session key */ uint8_t appskey[LORAMAC_APPSKEY_LEN]; /**< application session key */
uint8_t nwkskey[LORAMAC_NWKSKEY_LEN]; /**< network session key */ uint8_t nwkskey[LORAMAC_NWKSKEY_LEN]; /**< network session key */
uint8_t devaddr[LORAMAC_DEVADDR_LEN]; /**< device address */ uint8_t devaddr[LORAMAC_DEVADDR_LEN]; /**< device address */
#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
semtech_loramac_rx_data_t rx_data; /**< struct handling the RX data */ semtech_loramac_rx_data_t rx_data; /**< struct handling the RX data */
semtech_loramac_link_check_info_t link_chk; /**< link check information */ semtech_loramac_link_check_info_t link_chk; /**< link check information */
#endif
} semtech_loramac_t; } semtech_loramac_t;
/** /**
@ -172,6 +178,7 @@ uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type);
*/ */
uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len); uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len);
#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
/** /**
* @brief Wait for a message sent by the LoRaWAN network * @brief Wait for a message sent by the LoRaWAN network
* *
@ -184,6 +191,9 @@ uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
* Be sure to call this function before the end of the RX windows otherwise it * Be sure to call this function before the end of the RX windows otherwise it
* may block the calling thread. * may block the calling thread.
* *
* By default this feature is not available to the user application, enable it
* by adding `USEMODULE += semtech_loramac_rx` to the application Makefile.
*
* @see semtech_loramac_send * @see semtech_loramac_send
* *
* @param[in] mac Pointer to the mac * @param[in] mac Pointer to the mac
@ -193,13 +203,19 @@ uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
* @return SEMTECH_LORAMAC_RX_CONFIRMED when an ACK is received from the network * @return SEMTECH_LORAMAC_RX_CONFIRMED when an ACK is received from the network
*/ */
uint8_t semtech_loramac_recv(semtech_loramac_t *mac); uint8_t semtech_loramac_recv(semtech_loramac_t *mac);
#endif
#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
/** /**
* @brief Requests a LoRaWAN link check * @brief Requests a LoRaWAN link check
* *
* By default this feature is not available to the user application, enable it
* by adding `USEMODULE += semtech_loramac_rx` to the application Makefile.
*
* @param[in] mac Pointer to the mac * @param[in] mac Pointer to the mac
*/ */
void semtech_loramac_request_link_check(semtech_loramac_t *mac); void semtech_loramac_request_link_check(semtech_loramac_t *mac);
#endif
/** /**
* @brief Sets the device EUI * @brief Sets the device EUI