diff --git a/sys/include/net/loramac.h b/sys/include/net/loramac.h index 48b432a802..c602718c49 100644 --- a/sys/include/net/loramac.h +++ b/sys/include/net/loramac.h @@ -547,6 +547,15 @@ extern "C" { */ #define LORAMAC_NETWORK_ID_LEN (3U) +/** + * @brief Maximum length for channel mask + * + * The actual length is set by each region-specific LoRaMac + * implementation (see CHANNELS_MASK_SIZE), which + * automatically slices down the channel array mask. + */ +#define LORAMAC_CHANNELS_MASK_MAX_LEN (6U) + /** @} */ /** diff --git a/sys/shell/commands/sc_loramac.c b/sys/shell/commands/sc_loramac.c index 72cd487f41..540be6620a 100644 --- a/sys/shell/commands/sc_loramac.c +++ b/sys/shell/commands/sc_loramac.c @@ -58,7 +58,7 @@ static void _loramac_tx_usage(void) static void _loramac_set_usage(void) { puts("Usage: loramac set "); + "class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt|ch_mask> "); } static void _loramac_get_usage(void) @@ -347,6 +347,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 "); + 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]; + fmt_hex_bytes(tmp, argv[3]); + for (size_t i = 0, j = 0; i < LORAMAC_CHANNELS_MASK_MAX_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;