ble_mesh: Allow empty sensor series column value

This commit is contained in:
lly 2020-04-07 11:11:13 +08:00 committed by bot
parent df96c73471
commit 6f7acf6a21

View file

@ -424,14 +424,22 @@ static void send_sensor_column_status(struct bt_mesh_model *model,
state = &srv->states[i]; state = &srv->states[i];
if (state->sensor_property_id != INVALID_SENSOR_PROPERTY_ID && if (state->sensor_property_id != INVALID_SENSOR_PROPERTY_ID &&
state->sensor_property_id == prop_id) { state->sensor_property_id == prop_id) {
length = SENSOR_PROPERTY_ID_LEN + state->series_column.raw_value_x->len; length = SENSOR_PROPERTY_ID_LEN;
if (state->series_column.raw_value_x) {
length += state->series_column.raw_value_x->len;
}
/** /**
* TODO: column width & raw value y in Sensor Column Status are optional, * TODO: column width & raw value y in Sensor Column Status are optional,
* here we need to add some conditions to decide whether put these two * here we need to add some conditions to decide whether put these two
* in the status message. * in the status message.
*/ */
if (optional) { if (optional) {
length += state->series_column.column_width->len + state->series_column.raw_value_y->len; if (state->series_column.column_width) {
length += state->series_column.column_width->len;
}
if (state->series_column.raw_value_y) {
length += state->series_column.raw_value_y->len;
}
} }
break; break;
} }
@ -455,15 +463,21 @@ static void send_sensor_column_status(struct bt_mesh_model *model,
bt_mesh_model_msg_init(msg, BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS); bt_mesh_model_msg_init(msg, BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS);
net_buf_simple_add_le16(msg, prop_id); net_buf_simple_add_le16(msg, prop_id);
if (i != srv->state_count) { if (i != srv->state_count) {
if (state->series_column.raw_value_x) {
net_buf_simple_add_mem(msg, state->series_column.raw_value_x->data, net_buf_simple_add_mem(msg, state->series_column.raw_value_x->data,
state->series_column.raw_value_x->len); state->series_column.raw_value_x->len);
}
if (optional) { if (optional) {
if (state->series_column.column_width) {
net_buf_simple_add_mem(msg, state->series_column.column_width->data, net_buf_simple_add_mem(msg, state->series_column.column_width->data,
state->series_column.column_width->len); state->series_column.column_width->len);
}
if (state->series_column.raw_value_y) {
net_buf_simple_add_mem(msg, state->series_column.raw_value_y->data, net_buf_simple_add_mem(msg, state->series_column.raw_value_y->data,
state->series_column.raw_value_y->len); state->series_column.raw_value_y->len);
} }
} }
}
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL)); BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg); bt_mesh_free_buf(msg);
@ -491,9 +505,15 @@ static void send_sensor_series_status(struct bt_mesh_model *model,
* decide whether put these three in the status message. * decide whether put these three in the status message.
*/ */
if (optional) { if (optional) {
length += state->series_column.raw_value_x->len + if (state->series_column.raw_value_x) {
state->series_column.column_width->len + length += state->series_column.raw_value_x->len;
state->series_column.raw_value_y->len; }
if (state->series_column.column_width) {
length += state->series_column.column_width->len;
}
if (state->series_column.raw_value_y) {
length += state->series_column.raw_value_y->len;
}
} }
break; break;
} }
@ -519,14 +539,20 @@ static void send_sensor_series_status(struct bt_mesh_model *model,
net_buf_simple_add_le16(msg, prop_id); net_buf_simple_add_le16(msg, prop_id);
if (i != srv->state_count) { if (i != srv->state_count) {
if (optional) { if (optional) {
if (state->series_column.raw_value_x) {
net_buf_simple_add_mem(msg, state->series_column.raw_value_x->data, net_buf_simple_add_mem(msg, state->series_column.raw_value_x->data,
state->series_column.raw_value_x->len); state->series_column.raw_value_x->len);
}
if (state->series_column.column_width) {
net_buf_simple_add_mem(msg, state->series_column.column_width->data, net_buf_simple_add_mem(msg, state->series_column.column_width->data,
state->series_column.column_width->len); state->series_column.column_width->len);
}
if (state->series_column.raw_value_y) {
net_buf_simple_add_mem(msg, state->series_column.raw_value_y->data, net_buf_simple_add_mem(msg, state->series_column.raw_value_y->data,
state->series_column.raw_value_y->len); state->series_column.raw_value_y->len);
} }
} }
}
BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL)); BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL));
bt_mesh_free_buf(msg); bt_mesh_free_buf(msg);
@ -1010,12 +1036,6 @@ static int check_sensor_server_init(struct bt_mesh_sensor_state *state_start,
BT_ERR("%s, Invalid Sensor Data state", __func__); BT_ERR("%s, Invalid Sensor Data state", __func__);
return -EINVAL; return -EINVAL;
} }
if (state->series_column.raw_value_x == NULL ||
state->series_column.column_width == NULL ||
state->series_column.raw_value_y == NULL) {
BT_ERR("%s, Invalid Sensor Series column state", __func__);
return -EINVAL;
}
} }
return 0; return 0;