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

sys/shell+pkg/semtech-loramac: add get ch_mask

Also, set LORAMAC_CHANNELS_MASK_LEN based on the
selected LORA_REGION configuration.
This commit is contained in:
Geovane Fedrecheski 2022-03-18 14:26:01 -03:00
parent 26c55a91bd
commit eabeee0ebe
4 changed files with 46 additions and 16 deletions

View File

@ -412,9 +412,20 @@ void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask)
{
mutex_lock(&mac->lock);
DEBUG("[semtech-loramac] setting channels mask\n");
MibRequestConfirm_t mibReqChannel;
mibReqChannel.Type = MIB_CHANNELS_MASK;
mibReqChannel.Param.ChannelsMask = mask;
LoRaMacMibSetRequestConfirm(&mibReqChannel);
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_CHANNELS_MASK;
mibReq.Param.ChannelsMask = mask;
LoRaMacMibSetRequestConfirm(&mibReq);
mutex_unlock(&mac->lock);
}
void semtech_loramac_get_channels_mask(semtech_loramac_t *mac, uint16_t *mask)
{
mutex_lock(&mac->lock);
DEBUG("[semtech-loramac] getting channels mask\n");
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_CHANNELS_MASK;
LoRaMacMibGetRequestConfirm(&mibReq);
memcpy(mask, mibReq.Param.ChannelsMask, LORAMAC_CHANNELS_MASK_LEN);
mutex_unlock(&mac->lock);
}

View File

@ -504,6 +504,14 @@ uint8_t semtech_loramac_get_rx2_dr(semtech_loramac_t *mac);
*/
void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter);
/**
* @brief Gets the Uplink Frame Counter
*
* @param[in] mac Pointer to the mac
* @return Uplink frame counter
*/
uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac);
/**
* @brief Sets the Channels Mask
*
@ -513,12 +521,12 @@ void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter
void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask);
/**
* @brief Gets the Uplink Frame Counter
* @brief Gets the Channels Mask
*
* @param[in] mac Pointer to the mac
* @return Uplink frame counter
* @param[in] mask Mask array pointer
*/
uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac);
void semtech_loramac_get_channels_mask(semtech_loramac_t *mac, uint16_t *mask);
#ifdef MODULE_PERIPH_EEPROM
/**

View File

@ -548,13 +548,15 @@ extern "C" {
#define LORAMAC_NETWORK_ID_LEN (3U)
/**
* @brief Maximum length for channel mask
* @brief Channel mask length
*
* The actual length is set by each region-specific LoRaMac
* implementation (see CHANNELS_MASK_SIZE), which
* automatically slices down the channel array mask.
* Must match CHANNELS_MASK_SIZE in src/mac/region/RegionXXYYY.c
*/
#define LORAMAC_CHANNELS_MASK_MAX_LEN (6U)
#if defined(REGION_AU915) || defined(REGION_CN470) || defined(REGION_US915) || defined(REGION_US915_HYBRID) || defined(REGION_AS923)
#define LORAMAC_CHANNELS_MASK_LEN (6U)
#else
#define LORAMAC_CHANNELS_MASK_LEN (1U)
#endif
/** @} */

View File

@ -64,7 +64,7 @@ static void _loramac_set_usage(void)
static void _loramac_get_usage(void)
{
puts("Usage: loramac get <deveui|appeui|appkey|appskey|nwkskey|devaddr|"
"class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt>");
"class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt|ch_mask>");
}
int _loramac_handler(int argc, char **argv)
@ -166,6 +166,15 @@ int _loramac_handler(int argc, char **argv)
else if (strcmp("ul_cnt", argv[2]) == 0) {
printf("Uplink Counter: %"PRIu32"\n", semtech_loramac_get_uplink_counter(&loramac));
}
else if (strcmp("ch_mask", argv[2]) == 0) {
uint16_t mask[LORAMAC_CHANNELS_MASK_LEN] = { 0 };
semtech_loramac_get_channels_mask(&loramac, mask);
printf("Channels mask: ");
for (size_t i = 0; i < LORAMAC_CHANNELS_MASK_LEN; i++) {
printf("%04x", mask[i]);
}
printf("\n");
}
else {
_loramac_get_usage();
return 1;
@ -353,10 +362,10 @@ int _loramac_handler(int argc, char **argv)
puts("Example (sets channels 0-3): loramac set ch_mask 000F00000000000000000000");
return 1;
}
uint16_t mask[LORAMAC_CHANNELS_MASK_MAX_LEN] = { 0 };
uint8_t tmp[LORAMAC_CHANNELS_MASK_MAX_LEN*2];
uint16_t mask[LORAMAC_CHANNELS_MASK_LEN] = { 0 };
uint8_t tmp[LORAMAC_CHANNELS_MASK_LEN*2];
fmt_hex_bytes(tmp, argv[3]);
for (size_t i = 0, j = 0; i < LORAMAC_CHANNELS_MASK_MAX_LEN; i++, j+=2) {
for (size_t i = 0, j = 0; i < LORAMAC_CHANNELS_MASK_LEN; i++, j+=2) {
/* copy over to span a 16-bit -wide unsigned integer */
mask[i] |= tmp[j] << 8;
mask[i] |= tmp[j+1];