mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #11917 from fjmolinas/pr_loramac_uplink_setget
pkg/semtech-loramac: add uplink_counter get/set functions
This commit is contained in:
commit
9ca842c226
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -57,13 +57,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> <value>");
|
||||
"class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt> <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>");
|
||||
"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 <value>");
|
||||
return 1;
|
||||
}
|
||||
uint32_t counter = atoi(argv[3]);
|
||||
semtech_loramac_set_uplink_counter(&loramac, counter);
|
||||
}
|
||||
else {
|
||||
_loramac_set_usage();
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user