diff --git a/src/lrw.c b/src/lrw.c index b96cf54..4a279cb 100644 --- a/src/lrw.c +++ b/src/lrw.c @@ -821,24 +821,16 @@ int lrw_send(uint8_t port, void *buffer, uint8_t length, bool confirmed) // Sertting the port to 0, the payload buffer to NULL, and buffer size // to 0 will send an uplink message with FOpts but no port or payload. - // Disable retransmissions for the internally generated flush uplink - // message. - r.Type = MIB_CHANNELS_NB_TRANS; - r.Param.ChannelsNbTrans = 1; - LoRaMacStatus_t rv = LoRaMacMibSetRequestConfirm(&r); - if (rv != LORAMAC_STATUS_OK) { - log_debug("Could not configure retransmissions: %d", rv); - return rv; - } - mr.Type = MCPS_UNCONFIRMED; mr.Req.Unconfirmed.fPort = 0; mr.Req.Unconfirmed.fBuffer = NULL; mr.Req.Unconfirmed.fBufferSize = 0; mr.Req.Unconfirmed.Datarate = r.Param.ChannelsDatarate; - // Intentionally ignore any errors generated by the flush command - lrw_mcps_request(&mr); + // Intentionally ignore any errors generated by the flush command. + // Disable retransmissions for the internally generated flush uplink + // message. + lrw_mcps_request(&mr, 1); } // Return the original status to the caller to indicate that we haven't @@ -869,17 +861,9 @@ int lrw_send(uint8_t port, void *buffer, uint8_t length, bool confirmed) mr.Req.Confirmed.Datarate = r.Param.ChannelsDatarate; } - r.Type = MIB_CHANNELS_NB_TRANS; - r.Param.ChannelsNbTrans = confirmed + rc = lrw_mcps_request(&mr, confirmed ? sysconf.confirmed_retransmissions - : sysconf.unconfirmed_retransmissions; - rc = LoRaMacMibSetRequestConfirm(&r); - if (rc != LORAMAC_STATUS_OK) { - log_debug("Could not configure retransmissions: %d", rc); - return rc; - } - - rc = lrw_mcps_request(&mr); + : sysconf.unconfirmed_retransmissions); if (rc != LORAMAC_STATUS_OK) log_debug("Transmission failed: %d", rc); @@ -1113,7 +1097,12 @@ int lrw_check_link(bool piggyback) // the value from MIB mcr.Req.Unconfirmed.Datarate = mbr.Param.ChannelsDatarate; - rc = lrw_mcps_request(&mcr); + // Disable retransmissions. Standalone (non-piggybacked) link check + // requests are sent as unconfirmed uplinks with an empty payload. + // Retransmitting such requests is not useful. If desired, the + // application could simply issue the corresponding AT command multiple + // times. + rc = lrw_mcps_request(&mcr, 1); if (rc != LORAMAC_STATUS_OK) log_debug("Empty frame TX failed: %d", rc); } @@ -1199,11 +1188,20 @@ LoRaMacStatus_t lrw_mlme_request(MlmeReq_t* req) } -// This function is a simple wrapper over LoRaMacMcpsRequest that keeps track of -// the duty cycle wait time returned by the function for the benefit of AT+BACKOFF -LoRaMacStatus_t lrw_mcps_request(McpsReq_t* req) +LoRaMacStatus_t lrw_mcps_request(McpsReq_t* req, int transmissions) { - LoRaMacStatus_t rc = LoRaMacMcpsRequest(req); + LoRaMacStatus_t rc; + MibRequestConfirm_t r = { + .Type = MIB_CHANNELS_NB_TRANS, + .Param = { .ChannelsNbTrans = transmissions } + }; + rc = LoRaMacMibSetRequestConfirm(&r); + if (rc != LORAMAC_STATUS_OK) { + log_debug("Could not configure retransmissions: %d", rc); + return rc; + } + + rc = LoRaMacMcpsRequest(req); update_duty_cycle_deadline(rc, req->ReqReturn.DutyCycleWaitTime); return rc; } diff --git a/src/lrw.h b/src/lrw.h index d4ed8f4..66fc244 100644 --- a/src/lrw.h +++ b/src/lrw.h @@ -162,9 +162,10 @@ int lrw_get_max_channels(void); LoRaMacStatus_t lrw_mlme_request(MlmeReq_t* req); - -LoRaMacStatus_t lrw_mcps_request(McpsReq_t* req); - +// Aa simple wrapper over LoRaMacMcpsRequest that properly configures uplink +// retransmissions and keeps track of the duty cycle wait time returned by the +// function for the benefit of AT+BACKOFF +LoRaMacStatus_t lrw_mcps_request(McpsReq_t* req, int transmissions); void lrw_factory_reset(bool reset_devnonce, bool reset_deveui);