Bluetooth: Mesh: Fix encoding/decoding Publish Retransmit value

The Model Publish Retransmit Interval is in units of 50ms and not 10ms
like the other transmit/retransmit states. Create dedicated macros for
the Publish Retransmit State and use them where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-18 10:01:43 +02:00 committed by Johan Hedberg
commit f9fad553ac
3 changed files with 46 additions and 11 deletions

View file

@ -219,6 +219,40 @@ struct bt_mesh_model_op {
*/
#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
/** @def BT_MESH_PUB_TRANSMIT
*
* @brief Encode Publish Retransmit count & interval steps.
*
* @param count Number of retransmissions (first transmission is excluded).
* @param int_ms Interval steps in milliseconds. Must be greater than 0
* and a multiple of 50.
*
* @return Mesh transmit value that can be used e.g. for the default
* values of the configuration model data.
*/
#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
(int_ms) / 5)
/** @def BT_MESH_PUB_TRANSMIT_COUNT
*
* @brief Decode Pubhlish Retransmit count from a given value.
*
* @param transmit Encoded Publish Retransmit count & interval value.
*
* @return Retransmission count (actual transmissions is N + 1).
*/
#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
/** @def BT_MESH_PUB_TRANSMIT_INT
*
* @brief Decode Publish Retransmit interval from a given value.
*
* @param transmit Encoded Publish Retransmit count & interval value.
*
* @return Transmission interval in milliseconds.
*/
#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
struct bt_mesh_model_pub {
/* Self-reference for easy lookup */
struct bt_mesh_model *mod;

View file

@ -1023,8 +1023,8 @@ static void mod_pub_set(struct bt_mesh_model *model,
BT_DBG("pub_app_idx 0x%03x, pub_ttl %u pub_period 0x%02x",
pub_app_idx, pub_ttl, pub_period);
BT_DBG("retransmit 0x%02x (count %u interval %ums)", retransmit,
BT_MESH_TRANSMIT_COUNT(retransmit),
BT_MESH_TRANSMIT_INT(retransmit));
BT_MESH_PUB_TRANSMIT_COUNT(retransmit),
BT_MESH_PUB_TRANSMIT_INT(retransmit));
elem = bt_mesh_elem_find(elem_addr);
if (!elem) {
@ -1130,8 +1130,8 @@ static void mod_pub_va_set(struct bt_mesh_model *model,
BT_DBG("pub_app_idx 0x%03x, pub_ttl %u pub_period 0x%02x",
pub_app_idx, pub_ttl, pub_period);
BT_DBG("retransmit 0x%02x (count %u interval %ums)", retransmit,
BT_MESH_TRANSMIT_COUNT(retransmit),
BT_MESH_TRANSMIT_INT(retransmit));
BT_MESH_PUB_TRANSMIT_COUNT(retransmit),
BT_MESH_PUB_TRANSMIT_INT(retransmit));
elem = bt_mesh_elem_find(elem_addr);
if (!elem) {

View file

@ -708,10 +708,10 @@ static int mod_pub_get(u16_t addr, u16_t mod_id, u16_t cid)
"\tPublishTTL: %u\n"
"\tPublishPeriod: 0x%02x\n"
"\tPublishRetransmitCount: %u\n"
"\tPublishRetransmitIntervalSteps: %u\n",
"\tPublishRetransmitInterval: %ums\n",
addr, mod_id, pub.addr, pub.app_idx, pub.cred_flag, pub.ttl,
pub.period, BT_MESH_TRANSMIT_COUNT(pub.transmit),
BT_MESH_TRANSMIT_INT(pub.transmit));
pub.period, BT_MESH_PUB_TRANSMIT_COUNT(pub.transmit),
BT_MESH_PUB_TRANSMIT_INT(pub.transmit));
return 0;
}
@ -719,7 +719,8 @@ static int mod_pub_get(u16_t addr, u16_t mod_id, u16_t cid)
static int mod_pub_set(u16_t addr, u16_t mod_id, u16_t cid, char *argv[])
{
struct bt_mesh_cfg_mod_pub pub;
u8_t status, count, interval;
u8_t status, count;
u16_t interval;
int err;
pub.addr = strtoul(argv[0], NULL, 0);
@ -735,12 +736,12 @@ static int mod_pub_set(u16_t addr, u16_t mod_id, u16_t cid, char *argv[])
}
interval = strtoul(argv[6], NULL, 0);
if (interval > 31) {
printk("Invalid retransmit interval\n");
if (interval > (31 * 50) || (interval % 50)) {
printk("Invalid retransmit interval %u\n", interval);
return -EINVAL;
}
pub.transmit = BT_MESH_TRANSMIT(count, interval);
pub.transmit = BT_MESH_PUB_TRANSMIT(count, interval);
if (cid == CID_NVAL) {
err = bt_mesh_cfg_mod_pub_set(net.net_idx, net.dst, addr,