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

Merge pull request #17824 from geonnave/set_channels_mask

pkg/semtech-loramac: enable setting channels mask
This commit is contained in:
Alexandre Abadie 2022-04-02 18:56:11 +02:00 committed by GitHub
commit 3a83c380f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 2 deletions

View File

@ -407,3 +407,25 @@ uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac)
mutex_unlock(&mac->lock);
return counter;
}
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 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

@ -512,6 +512,22 @@ void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter
*/
uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac);
/**
* @brief Sets the Channels Mask
*
* @param[in] mac Pointer to the mac
* @param[in] mask Mask array, e.g., {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000}
*/
void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask);
/**
* @brief Gets the Channels Mask
*
* @param[in] mac Pointer to the mac
* @param[in] mask Mask array pointer
*/
void semtech_loramac_get_channels_mask(semtech_loramac_t *mac, uint16_t *mask);
#ifdef MODULE_PERIPH_EEPROM
/**
* @brief The magic number used to identify the LoRaWAN configuration

View File

@ -547,6 +547,17 @@ extern "C" {
*/
#define LORAMAC_NETWORK_ID_LEN (3U)
/**
* @brief Channel mask length
*
* Must match CHANNELS_MASK_SIZE in src/mac/region/RegionXXYYY.c
*/
#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

@ -58,13 +58,13 @@ static void _loramac_tx_usage(void)
static void _loramac_set_usage(void)
{
puts("Usage: loramac set <deveui|appeui|appkey|appskey|nwkskey|devaddr|"
"class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt> <value>");
"class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt|ch_mask> <value>");
}
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;
@ -347,6 +356,22 @@ int _loramac_handler(int argc, char **argv)
uint32_t counter = atoi(argv[3]);
semtech_loramac_set_uplink_counter(&loramac, counter);
}
else if (strcmp("ch_mask", argv[2]) == 0) {
if (argc < 4) {
puts("Usage: loramac set ch_mask <value>");
puts("Example (sets channels 0-3): loramac set ch_mask 000F00000000000000000000");
return 1;
}
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_LEN; i++, j+=2) {
/* copy over to span a 16-bit -wide unsigned integer */
mask[i] |= tmp[j] << 8;
mask[i] |= tmp[j+1];
}
semtech_loramac_set_channels_mask(&loramac, mask);
}
else {
_loramac_set_usage();
return 1;