From 26f52ddafc6422086552298a60cf1a4e3a547d9d Mon Sep 17 00:00:00 2001 From: Jan Janak Date: Tue, 5 Apr 2022 19:47:12 -0400 Subject: [PATCH] Fix AT+FRMCNT The counters are uint32_t and thus need to be printed as %lu. Furthermore, we need to select either AFCntDown or FCntDown depending on the LoRaWAN protocol version negotiated between the device and the network server. Note: UINT32_MAX is a special value that indicates that the counter is set to the initial value, i.e., no uplink or downlink has taken place so far. --- src/cmd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cmd.c b/src/cmd.c index 5f87fc5..2bad236 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -962,8 +962,18 @@ static void pctx(atci_param_t *param) static void get_frmcnt(void) { + uint32_t down; LoRaMacNvmData_t *state = lrw_get_state(); - OK("%ld,%ld", state->Crypto.FCntList.FCntUp ,state->Crypto.FCntList.FCntDown); + + MibRequestConfirm_t r = { .Type = MIB_LORAWAN_VERSION }; + LoRaMacMibGetRequestConfirm(&r); + + if (r.Param.LrWanVersion.LoRaWan.Fields.Minor == 0) + down = state->Crypto.FCntList.FCntDown; + else + down = state->Crypto.FCntList.AFCntDown; + + OK("%lu,%lu", state->Crypto.FCntList.FCntUp, down); }