Skip to content

Commit

Permalink
tests: bluetooth: tester: migrate mesh tester to new Sensor API
Browse files Browse the repository at this point in the history
Disable the legacy sensor value usage
Update tester to be able to use new Sensor API

Signed-off-by: Alperen Şener <[email protected]>
  • Loading branch information
m-alperen-sener authored and rlubos committed Feb 12, 2024
1 parent 9f4a516 commit 13775f5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
2 changes: 2 additions & 0 deletions tests/bluetooth/tester/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ CONFIG_BT_MESH_LIGHT_CTRL_SRV_TIME_FADE_STANDBY_AUTO=0
CONFIG_BT_MESH_LIGHT_CTRL_SRV_TIME_FADE_STANDBY_MANUAL=0
CONFIG_BT_MESH_LIGHT_CTRL_SRV_TIME_PROLONG=0

CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE=n

CONFIG_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
Expand Down
68 changes: 56 additions & 12 deletions tests/bluetooth/tester/src/mmdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ static void sensor_get(uint8_t *data, uint16_t len)
struct mesh_sensor_get *cmd = (void *)data;
const struct bt_mesh_sensor_type *sensor;
struct net_buf_simple *buf = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX);
struct sensor_value value[CONFIG_BT_MESH_SENSOR_CHANNELS_MAX];
sensor_value_type value[CONFIG_BT_MESH_SENSOR_CHANNELS_MAX];
struct bt_mesh_sensor_data values[5];
uint32_t count = ARRAY_SIZE(values);
struct model_data *model_bound;
Expand Down Expand Up @@ -1886,7 +1886,7 @@ static void sensor_setting_set(uint8_t *data, uint16_t len)
struct mesh_sensor_setting_set *cmd = (void *)data;
const struct bt_mesh_sensor_type *sensor;
const struct bt_mesh_sensor_type *setting;
struct sensor_value value[CONFIG_BT_MESH_SENSOR_CHANNELS_MAX];
sensor_value_type value[CONFIG_BT_MESH_SENSOR_CHANNELS_MAX];
struct bt_mesh_sensor_setting_status rsp;
struct model_data *model_bound;
struct bt_mesh_msg_ctx ctx = {
Expand Down Expand Up @@ -1930,7 +1930,12 @@ static void sensor_setting_set(uint8_t *data, uint16_t len)
}

memset(value, 0, sizeof(value));
#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
memcpy(&value[0].raw, cmd->data, cmd->len);
value[0].format = setting->channels[0].format;
#else
memcpy(value, cmd->data, cmd->len);
#endif

if (cmd->ack) {
err = bt_mesh_sensor_cli_setting_set(&sensor_cli, &ctx, sensor,
Expand Down Expand Up @@ -1968,10 +1973,14 @@ static void sensor_column_get(uint8_t *data, uint16_t len)
struct net_buf_simple *buf_rsp =
NET_BUF_SIMPLE(BT_MESH_SENSOR_MSG_MAXLEN_COLUMN_STATUS);
const struct bt_mesh_sensor_type *sensor;
#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
union bt_mesh_sensor_column_key column;
#else
struct bt_mesh_sensor_column column = { 0 };
#endif
struct bt_mesh_sensor_series_entry rsp;
const struct bt_mesh_sensor_format *col_format;
struct sensor_value width;
sensor_value_type width;
struct model_data *model_bound;
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
Expand Down Expand Up @@ -2000,11 +2009,19 @@ static void sensor_column_get(uint8_t *data, uint16_t len)
net_buf_simple_init_with_data(buf, (void *)&cmd->data, cmd->len);

col_format = bt_mesh_sensor_column_format_get(sensor);

if (col_format == NULL) {
#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
column.index = cmd->data[0];
#else
column.start = val_to_sensorval(cmd->data[0]);
#endif
} else {
#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
err = sensor_ch_decode(buf, col_format, &column.sensor_value);
#else
err = sensor_ch_decode(buf, col_format, &column.start);

#endif
if (err) {
LOG_ERR("err=%d", err);
goto fail;
Expand Down Expand Up @@ -2032,8 +2049,12 @@ static void sensor_column_get(uint8_t *data, uint16_t len)
goto fail;
}

#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
width = rsp.column.width;
#else
width.val1 = rsp.column.end.val1 - rsp.column.start.val1;
width.val2 = rsp.column.end.val2 - rsp.column.start.val2;
#endif

err = sensor_ch_encode(buf_rsp, col_format, &width);
if (err) {
Expand Down Expand Up @@ -2062,9 +2083,8 @@ static void sensor_series_get(uint8_t *data, uint16_t len)
struct net_buf_simple *buf = NET_BUF_SIMPLE(0);
struct net_buf_simple *buf_rsp = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX);
const struct bt_mesh_sensor_type *sensor;
struct bt_mesh_sensor_column range;
struct bt_mesh_sensor_series_entry rsp[10];
struct sensor_value width;
sensor_value_type width;
uint32_t count = ARRAY_SIZE(rsp);
const struct bt_mesh_sensor_format *col_format;
struct model_data *model_bound;
Expand Down Expand Up @@ -2097,6 +2117,27 @@ static void sensor_series_get(uint8_t *data, uint16_t len)
net_buf_simple_init_with_data(buf, (void *)&cmd->data, cmd->len);

col_format = bt_mesh_sensor_column_format_get(sensor);
#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
union bt_mesh_sensor_column_key range_start, range_end;

if (col_format != NULL) {
err = sensor_ch_decode(buf, col_format, &range_start.sensor_value);
if (err) {
goto fail;
}
err = sensor_ch_decode(buf, col_format, &range_end.sensor_value);
if (err) {
goto fail;
}
} else {
range_start.index = net_buf_simple_pull_u8(buf);
range_end.index = net_buf_simple_pull_u8(buf);
}

err = bt_mesh_sensor_cli_series_entries_get(&sensor_cli, &ctx, sensor, &range_start,
&range_end, rsp, &count);
#else
struct bt_mesh_sensor_column range;

if (col_format != NULL) {
err = sensor_ch_decode(buf, col_format, &range.end);
Expand All @@ -2108,9 +2149,10 @@ static void sensor_series_get(uint8_t *data, uint16_t len)
range.end.val1 = net_buf_simple_pull_u8(buf);
}


err = bt_mesh_sensor_cli_series_entries_get(&sensor_cli, &ctx, sensor,
&range, rsp, &count);
#endif

if (err) {
LOG_ERR("err=%d", err);
goto fail;
Expand All @@ -2132,10 +2174,12 @@ static void sensor_series_get(uint8_t *data, uint16_t len)
LOG_ERR("err=%d", err);
goto fail;
}

#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
width = rsp[i].column.width;
#else
width.val1 = rsp[i].column.end.val1 - rsp[i].column.start.val1;
width.val2 = rsp[i].column.end.val2 - rsp[i].column.start.val2;

#endif
err = sensor_ch_encode(buf_rsp, col_format, &width);
if (err) {
LOG_ERR("err=%d", err);
Expand Down Expand Up @@ -3251,7 +3295,7 @@ static void light_lc_property_get(uint8_t *data, uint16_t len)
{
struct mesh_light_lc_property_get *cmd = (void *)data;
struct net_buf_simple *rsp_buf = NET_BUF_SIMPLE(4);
struct sensor_value status;
sensor_value_type status;
const struct bt_mesh_sensor_format *format;
enum bt_mesh_light_ctrl_prop id;
struct model_data *model_bound;
Expand Down Expand Up @@ -3311,8 +3355,8 @@ static void light_lc_property_set(uint8_t *data, uint16_t len)
struct net_buf_simple *rsp_buf = NET_BUF_SIMPLE(4);
const struct bt_mesh_sensor_format *format;
enum bt_mesh_light_ctrl_prop id;
struct sensor_value val;
struct sensor_value status;
sensor_value_type val;
sensor_value_type status;
struct model_data *model_bound;
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
Expand Down
15 changes: 12 additions & 3 deletions tests/bluetooth/tester/src/model_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <zephyr/bluetooth/bluetooth.h>
#include <bluetooth/mesh/models.h>
#include <sensor.h>

#include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bttester_model_handler
Expand Down Expand Up @@ -283,7 +284,7 @@ static void prop_mfr_get(struct bt_mesh_prop_srv *srv,
static int sensor_data_get(struct bt_mesh_sensor_srv *srv,
struct bt_mesh_sensor *sensor,
struct bt_mesh_msg_ctx *ctx,
struct sensor_value *rsp);
sensor_value_type *rsp);

static struct bt_mesh_sensor time_since_presence_detected = {
.type = &bt_mesh_sensor_time_since_presence_detected,
Expand All @@ -302,16 +303,24 @@ static struct bt_mesh_sensor_srv sensor_srv =
static int sensor_data_get(struct bt_mesh_sensor_srv *srv,
struct bt_mesh_sensor *sensor,
struct bt_mesh_msg_ctx *ctx,
struct sensor_value *rsp)
sensor_value_type *rsp)
{
int i;

for (i = 0; i < ARRAY_SIZE(sensors); ++i) {
if (sensor->type->id != sensors[i]->type->id) {
continue;
}

#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE)
int err = bt_mesh_sensor_value_from_sensor_value(sensor->type->channels[0].format,
&values[i], rsp);
if (err) {
LOG_ERR("Failed to convert sensor value (err: %d)", err);
return err;
}
#else
memcpy(rsp, &values[i], sizeof(*rsp));
#endif
break;
}

Expand Down

0 comments on commit 13775f5

Please sign in to comment.