diff --git a/pkg/semtech-loramac/contrib/semtech_loramac.c b/pkg/semtech-loramac/contrib/semtech_loramac.c index 0a2381dbc2..5d7a5e1ed3 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac.c @@ -203,17 +203,7 @@ static size_t _write_uint32(size_t pos, uint32_t value) return eeprom_write(pos, array, sizeof(uint32_t)); } -static inline void _set_uplink_counter(semtech_loramac_t *mac, uint32_t counter) -{ - DEBUG("[semtech-loramac] reading uplink counter: %" PRIu32 " \n", counter); - mutex_lock(&mac->lock); - MibRequestConfirm_t mibReq; - mibReq.Type = MIB_UPLINK_COUNTER; - mibReq.Param.UpLinkCounter = counter; - LoRaMacMibSetRequestConfirm(&mibReq); - mutex_unlock(&mac->lock); -} static inline void _set_join_state(semtech_loramac_t *mac, bool joined) { @@ -260,7 +250,7 @@ static inline void _read_loramac_config(semtech_loramac_t *mac) /* Read uplink counter */ uint32_t ul_counter; pos += _read_uint32(pos, &ul_counter); - _set_uplink_counter(mac, ul_counter); + semtech_loramac_set_uplink_counter(mac, ul_counter); /* Read RX2 freq */ uint32_t rx2_freq; diff --git a/pkg/semtech-loramac/contrib/semtech_loramac_getset.c b/pkg/semtech-loramac/contrib/semtech_loramac_getset.c index ee5b662326..237a48ada4 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac_getset.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac_getset.c @@ -385,3 +385,27 @@ uint8_t semtech_loramac_get_rx2_dr(semtech_loramac_t *mac) mutex_unlock(&mac->lock); return datarate; } + +void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter) +{ + DEBUG("[semtech-loramac] reading uplink counter: %" PRIu32 " \n", counter); + mutex_lock(&mac->lock); + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_UPLINK_COUNTER; + mibReq.Param.UpLinkCounter = counter; + LoRaMacMibSetRequestConfirm(&mibReq); + mutex_unlock(&mac->lock); +} + +uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac) +{ + mutex_lock(&mac->lock); + uint32_t counter; + DEBUG("[semtech-loramac] getting uplink counter\n"); + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_UPLINK_COUNTER; + LoRaMacMibGetRequestConfirm(&mibReq); + counter = mibReq.Param.UpLinkCounter; + mutex_unlock(&mac->lock); + return counter; +} diff --git a/pkg/semtech-loramac/include/semtech_loramac.h b/pkg/semtech-loramac/include/semtech_loramac.h index 4b77c961e7..752c507798 100644 --- a/pkg/semtech-loramac/include/semtech_loramac.h +++ b/pkg/semtech-loramac/include/semtech_loramac.h @@ -497,6 +497,22 @@ void semtech_loramac_set_rx2_dr(semtech_loramac_t *mac, uint8_t dr); */ uint8_t semtech_loramac_get_rx2_dr(semtech_loramac_t *mac); +/** + * @brief Sets the Uplink Frame Counter + * + * @param[in] mac Pointer to the mac + * @param[in] counter Frame counter to set + */ +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); + #ifdef MODULE_PERIPH_EEPROM /** * @brief The magic number used to identify the LoRaWAN configuration diff --git a/sys/shell/commands/sc_loramac.c b/sys/shell/commands/sc_loramac.c index bc280a4cf2..6f7cb00dbe 100644 --- a/sys/shell/commands/sc_loramac.c +++ b/sys/shell/commands/sc_loramac.c @@ -57,13 +57,13 @@ 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> "); } static void _loramac_get_usage(void) { puts("Usage: loramac get "); + "class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt>"); } int _loramac_handler(int argc, char **argv) @@ -162,6 +162,9 @@ int _loramac_handler(int argc, char **argv) else if (strcmp("rx2_dr", argv[2]) == 0) { printf("RX2 dr: %d\n", semtech_loramac_get_rx2_dr(&loramac)); } + else if (strcmp("ul_cnt", argv[2]) == 0) { + printf("Uplink Counter: %"PRIu32"\n", semtech_loramac_get_uplink_counter(&loramac)); + } else { _loramac_get_usage(); return 1; @@ -335,6 +338,14 @@ int _loramac_handler(int argc, char **argv) } semtech_loramac_set_rx2_dr(&loramac, dr); } + else if (strcmp("ul_cnt", argv[2]) == 0) { + if (argc < 4) { + puts("Usage: loramac set ul_cnt "); + return 1; + } + uint32_t counter = atoi(argv[3]); + semtech_loramac_set_uplink_counter(&loramac, counter); + } else { _loramac_set_usage(); return 1;