1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #8639 from aabadie/pr/pkg/loramac_link_check

pkg/semtech-loramac: add link check support
This commit is contained in:
jia200x 2018-05-08 11:11:33 +02:00 committed by GitHub
commit 736c757b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 1 deletions

View File

@ -241,6 +241,15 @@ static void mlme_confirm(MlmeConfirm_t *confirm)
}
break;
case MLME_LINK_CHECK:
if (confirm->Status == LORAMAC_EVENT_INFO_STATUS_OK) {
DEBUG("[semtech-loramac] link check received\n");
msg_t msg;
msg.type = MSG_TYPE_LORAMAC_LINK_CHECK;
msg.content.ptr = confirm;
msg_send(&msg, semtech_loramac_pid);
}
default:
break;
}
@ -313,6 +322,7 @@ void _init_loramac(semtech_loramac_t *mac,
semtech_loramac_set_class(mac, LORAMAC_DEFAULT_DEVICE_CLASS);
semtech_loramac_set_tx_port(mac, LORAMAC_DEFAULT_TX_PORT);
semtech_loramac_set_tx_mode(mac, LORAMAC_DEFAULT_TX_MODE);
mac->link_chk.available = false;
}
static void _join_otaa(semtech_loramac_t *mac)
@ -522,6 +532,19 @@ void *_semtech_loramac_event_loop(void *arg)
mac->state = SEMTECH_LORAMAC_STATE_IDLE;
break;
}
case MSG_TYPE_LORAMAC_LINK_CHECK:
{
MlmeConfirm_t *confirm = (MlmeConfirm_t *)msg.content.ptr;
mac->link_chk.demod_margin = confirm->DemodMargin;
mac->link_chk.nb_gateways = confirm->NbGateways;
mac->link_chk.available = true;
DEBUG("[semtech-loramac] link check info received:\n"
" - Demodulation marging: %d\n"
" - Number of gateways: %d\n",
mac->link_chk.demod_margin,
mac->link_chk.nb_gateways);
break;
}
case MSG_TYPE_LORAMAC_TX_DONE:
{
DEBUG("[semtech-loramac] loramac TX done\n");
@ -609,6 +632,16 @@ uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type)
return SEMTECH_LORAMAC_JOIN_SUCCEEDED;
}
void semtech_loramac_request_link_check(semtech_loramac_t *mac)
{
mutex_lock(&mac->lock);
mac->link_chk.available = false;
MlmeReq_t mlmeReq;
mlmeReq.Type = MLME_LINK_CHECK;
LoRaMacMlmeRequest(&mlmeReq);
mutex_unlock(&mac->lock);
}
uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
{
mutex_lock(&mac->lock);
@ -616,6 +649,7 @@ uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
mibReq.Type = MIB_NETWORK_JOINED;
LoRaMacMibGetRequestConfirm(&mibReq);
bool is_joined = mibReq.Param.IsNetworkJoined;
mac->link_chk.available = false;
mutex_unlock(&mac->lock);
if (!is_joined) {

View File

@ -44,6 +44,7 @@ extern "C" {
#define MSG_TYPE_LORAMAC_JOIN (0x3461) /**< MAC join event */
#define MSG_TYPE_LORAMAC_TX_DONE (0x3462) /**< MAC TX completes */
#define MSG_TYPE_LORAMAC_RX (0x3463) /**< Some data received */
#define MSG_TYPE_LORAMAC_LINK_CHECK (0x3464) /**< Link check info received */
/** @} */
/**
@ -89,6 +90,15 @@ typedef struct {
uint8_t port; /**< RX port */
} semtech_loramac_rx_data_t;
/**
* @brief LoRaMAC link check information
*/
typedef struct {
uint8_t demod_margin; /**< Demodulation margin */
uint8_t nb_gateways; /**< number of LoRa gateways found */
bool available; /**< new link check information avalable */
} semtech_loramac_link_check_info_t;
/**
* @brief Semtech LoRaMAC descriptor
*/
@ -105,6 +115,7 @@ typedef struct {
uint8_t nwkskey[LORAMAC_NWKSKEY_LEN]; /**< network session key */
uint8_t devaddr[LORAMAC_DEVADDR_LEN]; /**< device address */
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_t;
/**
@ -166,6 +177,13 @@ uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
*/
uint8_t semtech_loramac_recv(semtech_loramac_t *mac);
/**
* @brief Requests a LoRaWAN link check
*
* @param[in] mac Pointer to the mac
*/
void semtech_loramac_request_link_check(semtech_loramac_t *mac);
/**
* @brief Sets the device EUI
*

View File

@ -34,7 +34,7 @@ static char print_buf[LORAMAC_APPKEY_LEN * 2 + 1];
static void _loramac_usage(void)
{
puts("Usage: loramac <get|set|join|tx>");
puts("Usage: loramac <get|set|join|tx|link_check>");
}
static void _loramac_join_usage(void)
@ -416,8 +416,25 @@ static int _cmd_loramac(int argc, char **argv)
break;
}
if (loramac.link_chk.available) {
printf("Link check information:\n"
" - Demodulation margin: %d\n"
" - Number of gateways: %d\n",
loramac.link_chk.demod_margin,
loramac.link_chk.nb_gateways);
}
return 0;
}
else if (strcmp(argv[1], "link_check") == 0) {
if (argc > 2) {
_loramac_usage();
return 1;
}
semtech_loramac_request_link_check(&loramac);
puts("Link check request scheduled");
}
else {
_loramac_usage();
return 1;