lorawan: make unconfirmed message type explicit

The enum did not contain an entry for unconfirmed messages. Instead, it
was only mentioned in the comment that 0 is the default for
unconfirmed messages.

This commit adds LORAWAN_MSG_UNCONFIRMED to the enum and changes the
parameter in the lorawan_send function to enum lorawan_message_type.

Signed-off-by: Martin Jäger <martin@libre.solar>
This commit is contained in:
Martin Jäger 2022-03-01 12:52:09 +01:00 committed by Carles Cufí
parent 2a4e47a912
commit b6a907dd89
2 changed files with 16 additions and 20 deletions

View file

@ -60,11 +60,10 @@ enum lorawan_datarate {
/** /**
* @brief LoRaWAN message types. * @brief LoRaWAN message types.
*
* Note: The default message type is unconfirmed.
*/ */
enum lorawan_message_type { enum lorawan_message_type {
LORAWAN_MSG_CONFIRMED = BIT(0), LORAWAN_MSG_UNCONFIRMED = 0,
LORAWAN_MSG_CONFIRMED,
}; };
/** /**
@ -202,13 +201,12 @@ int lorawan_start(void);
* @param len Length of the buffer to be sent. Maximum length of this * @param len Length of the buffer to be sent. Maximum length of this
* buffer is 255 bytes but the actual payload size varies with * buffer is 255 bytes but the actual payload size varies with
* region and datarate. * region and datarate.
* @param flags Flag used to determine the type of message being sent. It * @param type Specifies if the message shall be confirmed or unconfirmed.
* could be one of the lorawan_message_type. The default * Must be one of @ref lorawan_message_type.
* behaviour is unconfirmed message.
* *
* @return 0 if successful, negative errno code if failure * @return 0 if successful, negative errno code if failure
*/ */
int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, uint8_t flags); int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, enum lorawan_message_type type);
/** /**
* @brief Set the current device class * @brief Set the current device class

View file

@ -448,7 +448,7 @@ int lorawan_set_conf_msg_tries(uint8_t tries)
return 0; return 0;
} }
int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, uint8_t flags) int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, enum lorawan_message_type type)
{ {
LoRaMacStatus_t status; LoRaMacStatus_t status;
McpsReq_t mcpsReq; McpsReq_t mcpsReq;
@ -480,21 +480,19 @@ int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, uint8_t flags)
mcpsReq.Req.Unconfirmed.fBufferSize = 0; mcpsReq.Req.Unconfirmed.fBufferSize = 0;
mcpsReq.Req.Unconfirmed.Datarate = DR_0; mcpsReq.Req.Unconfirmed.Datarate = DR_0;
} else { } else {
if (flags & LORAWAN_MSG_CONFIRMED) { switch (type) {
mcpsReq.Type = MCPS_CONFIRMED; case LORAWAN_MSG_UNCONFIRMED:
mcpsReq.Req.Confirmed.fPort = port;
mcpsReq.Req.Confirmed.fBuffer = data;
mcpsReq.Req.Confirmed.fBufferSize = len;
mcpsReq.Req.Confirmed.Datarate = current_datarate;
} else {
/* default message type */
mcpsReq.Type = MCPS_UNCONFIRMED; mcpsReq.Type = MCPS_UNCONFIRMED;
break;
case LORAWAN_MSG_CONFIRMED:
mcpsReq.Type = MCPS_CONFIRMED;
break;
}
mcpsReq.Req.Unconfirmed.fPort = port; mcpsReq.Req.Unconfirmed.fPort = port;
mcpsReq.Req.Unconfirmed.fBuffer = data; mcpsReq.Req.Unconfirmed.fBuffer = data;
mcpsReq.Req.Unconfirmed.fBufferSize = len; mcpsReq.Req.Unconfirmed.fBufferSize = len;
mcpsReq.Req.Unconfirmed.Datarate = current_datarate; mcpsReq.Req.Unconfirmed.Datarate = current_datarate;
} }
}
status = LoRaMacMcpsRequest(&mcpsReq); status = LoRaMacMcpsRequest(&mcpsReq);
if (status != LORAMAC_STATUS_OK) { if (status != LORAMAC_STATUS_OK) {