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.
*
* Note: The default message type is unconfirmed.
*/
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
* buffer is 255 bytes but the actual payload size varies with
* region and datarate.
* @param flags Flag used to determine the type of message being sent. It
* could be one of the lorawan_message_type. The default
* behaviour is unconfirmed message.
* @param type Specifies if the message shall be confirmed or unconfirmed.
* Must be one of @ref lorawan_message_type.
*
* @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

View file

@ -448,7 +448,7 @@ int lorawan_set_conf_msg_tries(uint8_t tries)
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;
McpsReq_t mcpsReq;
@ -480,20 +480,18 @@ int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, uint8_t flags)
mcpsReq.Req.Unconfirmed.fBufferSize = 0;
mcpsReq.Req.Unconfirmed.Datarate = DR_0;
} else {
if (flags & LORAWAN_MSG_CONFIRMED) {
mcpsReq.Type = MCPS_CONFIRMED;
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 */
switch (type) {
case LORAWAN_MSG_UNCONFIRMED:
mcpsReq.Type = MCPS_UNCONFIRMED;
mcpsReq.Req.Unconfirmed.fPort = port;
mcpsReq.Req.Unconfirmed.fBuffer = data;
mcpsReq.Req.Unconfirmed.fBufferSize = len;
mcpsReq.Req.Unconfirmed.Datarate = current_datarate;
break;
case LORAWAN_MSG_CONFIRMED:
mcpsReq.Type = MCPS_CONFIRMED;
break;
}
mcpsReq.Req.Unconfirmed.fPort = port;
mcpsReq.Req.Unconfirmed.fBuffer = data;
mcpsReq.Req.Unconfirmed.fBufferSize = len;
mcpsReq.Req.Unconfirmed.Datarate = current_datarate;
}
status = LoRaMacMcpsRequest(&mcpsReq);