Bluetooth: Audio: VOCS use bt_vocs instead of bt_vocs_server
Modify vocs.c to use the bt_vocs struct instead of the bt_vocs_server struct. This is done so that there is less difference between the internal struct usage and the struct type used in the API. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
eff957b764
commit
301cedbad5
1 changed files with 48 additions and 48 deletions
|
@ -34,10 +34,10 @@ static void offset_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t v
|
||||||
static ssize_t read_offset_state(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t read_offset_state(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
void *buf, uint16_t len, uint16_t offset)
|
void *buf, uint16_t len, uint16_t offset)
|
||||||
{
|
{
|
||||||
struct bt_vocs_server *inst = attr->user_data;
|
struct bt_vocs *inst = attr->user_data;
|
||||||
|
|
||||||
BT_DBG("offset %d, counter %u", inst->state.offset, inst->state.change_counter);
|
BT_DBG("offset %d, counter %u", inst->srv.state.offset, inst->srv.state.change_counter);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->state, sizeof(inst->state));
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state, sizeof(inst->srv.state));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void location_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
static void location_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||||
|
@ -50,28 +50,28 @@ static void location_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value
|
||||||
static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
||||||
{
|
{
|
||||||
struct bt_vocs_server *inst = attr->user_data;
|
struct bt_vocs *inst = attr->user_data;
|
||||||
uint32_t old_location = inst->location;
|
uint32_t old_location = inst->srv.location;
|
||||||
|
|
||||||
if (offset) {
|
if (offset) {
|
||||||
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
|
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != sizeof(inst->location)) {
|
if (len != sizeof(inst->srv.location)) {
|
||||||
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
|
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&inst->location, buf, len);
|
memcpy(&inst->srv.location, buf, len);
|
||||||
BT_DBG("%02x", inst->location);
|
BT_DBG("%02x", inst->srv.location);
|
||||||
|
|
||||||
if (old_location != inst->location) {
|
if (old_location != inst->srv.location) {
|
||||||
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_LOCATION,
|
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_LOCATION,
|
||||||
inst->service_p->attrs,
|
inst->srv.service_p->attrs,
|
||||||
&inst->location,
|
&inst->srv.location,
|
||||||
sizeof(inst->location));
|
sizeof(inst->srv.location));
|
||||||
|
|
||||||
if (inst->cb && inst->cb->location) {
|
if (inst->srv.cb && inst->srv.cb->location) {
|
||||||
inst->cb->location(NULL, (struct bt_vocs *)inst, 0, inst->location);
|
inst->srv.cb->location(NULL, inst, 0, inst->srv.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,18 +82,18 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
|
||||||
static ssize_t read_location(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t read_location(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
void *buf, uint16_t len, uint16_t offset)
|
void *buf, uint16_t len, uint16_t offset)
|
||||||
{
|
{
|
||||||
struct bt_vocs_server *inst = attr->user_data;
|
struct bt_vocs *inst = attr->user_data;
|
||||||
|
|
||||||
BT_DBG("0x%02x", inst->location);
|
BT_DBG("0x%02x", inst->srv.location);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->location,
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.location,
|
||||||
sizeof(inst->location));
|
sizeof(inst->srv.location));
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_VOCS */
|
#endif /* CONFIG_BT_VOCS */
|
||||||
|
|
||||||
static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
||||||
{
|
{
|
||||||
struct bt_vocs_server *inst = attr->user_data;
|
struct bt_vocs *inst = attr->user_data;
|
||||||
const struct bt_vocs_control *cp = buf;
|
const struct bt_vocs_control *cp = buf;
|
||||||
bool notify = false;
|
bool notify = false;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
|
||||||
BT_DBG("Opcode %u, counter %u", cp->opcode, cp->counter);
|
BT_DBG("Opcode %u, counter %u", cp->opcode, cp->counter);
|
||||||
|
|
||||||
|
|
||||||
if (cp->counter != inst->state.change_counter) {
|
if (cp->counter != inst->srv.state.change_counter) {
|
||||||
return BT_GATT_ERR(BT_VOCS_ERR_INVALID_COUNTER);
|
return BT_GATT_ERR(BT_VOCS_ERR_INVALID_COUNTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,8 +129,8 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
|
||||||
return BT_GATT_ERR(BT_VOCS_ERR_OUT_OF_RANGE);
|
return BT_GATT_ERR(BT_VOCS_ERR_OUT_OF_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inst->state.offset != sys_le16_to_cpu(cp->offset)) {
|
if (inst->srv.state.offset != sys_le16_to_cpu(cp->offset)) {
|
||||||
inst->state.offset = sys_le16_to_cpu(cp->offset);
|
inst->srv.state.offset = sys_le16_to_cpu(cp->offset);
|
||||||
notify = true;
|
notify = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -139,15 +139,15 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notify) {
|
if (notify) {
|
||||||
inst->state.change_counter++;
|
inst->srv.state.change_counter++;
|
||||||
BT_DBG("New state: offset %d, counter %u",
|
BT_DBG("New state: offset %d, counter %u",
|
||||||
inst->state.offset, inst->state.change_counter);
|
inst->srv.state.offset, inst->srv.state.change_counter);
|
||||||
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_STATE,
|
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_STATE,
|
||||||
inst->service_p->attrs,
|
inst->srv.service_p->attrs,
|
||||||
&inst->state, sizeof(inst->state));
|
&inst->srv.state, sizeof(inst->srv.state));
|
||||||
|
|
||||||
if (inst->cb && inst->cb->state) {
|
if (inst->srv.cb && inst->srv.cb->state) {
|
||||||
inst->cb->state(NULL, (struct bt_vocs *)inst, 0, inst->state.offset);
|
inst->srv.cb->state(NULL, inst, 0, inst->srv.state.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -165,34 +165,34 @@ static void output_desc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t va
|
||||||
static ssize_t write_output_desc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t write_output_desc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
|
||||||
{
|
{
|
||||||
struct bt_vocs_server *inst = attr->user_data;
|
struct bt_vocs *inst = attr->user_data;
|
||||||
|
|
||||||
if (offset) {
|
if (offset) {
|
||||||
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
|
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len >= sizeof(inst->output_desc)) {
|
if (len >= sizeof(inst->srv.output_desc)) {
|
||||||
BT_DBG("Output desc was clipped from length %u to %zu",
|
BT_DBG("Output desc was clipped from length %u to %zu",
|
||||||
len, sizeof(inst->output_desc) - 1);
|
len, sizeof(inst->srv.output_desc) - 1);
|
||||||
/* We just clip the string value if it's too long */
|
/* We just clip the string value if it's too long */
|
||||||
len = (uint16_t)sizeof(inst->output_desc) - 1;
|
len = (uint16_t)sizeof(inst->srv.output_desc) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != strlen(inst->output_desc) || memcmp(buf, inst->output_desc, len)) {
|
if (len != strlen(inst->srv.output_desc) || memcmp(buf, inst->srv.output_desc, len)) {
|
||||||
memcpy(inst->output_desc, buf, len);
|
memcpy(inst->srv.output_desc, buf, len);
|
||||||
inst->output_desc[len] = '\0';
|
inst->srv.output_desc[len] = '\0';
|
||||||
|
|
||||||
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_DESCRIPTION,
|
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_DESCRIPTION,
|
||||||
inst->service_p->attrs,
|
inst->srv.service_p->attrs,
|
||||||
&inst->output_desc,
|
&inst->srv.output_desc,
|
||||||
strlen(inst->output_desc));
|
strlen(inst->srv.output_desc));
|
||||||
|
|
||||||
if (inst->cb && inst->cb->description) {
|
if (inst->srv.cb && inst->srv.cb->description) {
|
||||||
inst->cb->description(NULL, (struct bt_vocs *)inst, 0, inst->output_desc);
|
inst->srv.cb->description(NULL, inst, 0, inst->srv.output_desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_DBG("%s", log_strdup(inst->output_desc));
|
BT_DBG("%s", log_strdup(inst->srv.output_desc));
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
@ -201,11 +201,11 @@ static ssize_t write_output_desc(struct bt_conn *conn, const struct bt_gatt_attr
|
||||||
static ssize_t read_output_desc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t read_output_desc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
void *buf, uint16_t len, uint16_t offset)
|
void *buf, uint16_t len, uint16_t offset)
|
||||||
{
|
{
|
||||||
struct bt_vocs_server *inst = attr->user_data;
|
struct bt_vocs *inst = attr->user_data;
|
||||||
|
|
||||||
BT_DBG("%s", log_strdup(inst->output_desc));
|
BT_DBG("%s", log_strdup(inst->srv.output_desc));
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->output_desc,
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.output_desc,
|
||||||
strlen(inst->output_desc));
|
strlen(inst->srv.output_desc));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BT_VOCS_SERVICE_DEFINITION(_vocs) { \
|
#define BT_VOCS_SERVICE_DEFINITION(_vocs) { \
|
||||||
|
@ -234,7 +234,7 @@ static ssize_t read_output_desc(struct bt_conn *conn, const struct bt_gatt_attr
|
||||||
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT) \
|
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT) \
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_vocs_server vocs_insts[CONFIG_BT_VOCS_MAX_INSTANCE_COUNT];
|
static struct bt_vocs vocs_insts[CONFIG_BT_VOCS_MAX_INSTANCE_COUNT];
|
||||||
BT_GATT_SERVICE_INSTANCE_DEFINE(vocs_service_list, vocs_insts, CONFIG_BT_VOCS_MAX_INSTANCE_COUNT,
|
BT_GATT_SERVICE_INSTANCE_DEFINE(vocs_service_list, vocs_insts, CONFIG_BT_VOCS_MAX_INSTANCE_COUNT,
|
||||||
BT_VOCS_SERVICE_DEFINITION);
|
BT_VOCS_SERVICE_DEFINITION);
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ struct bt_vocs *bt_vocs_free_instance_get(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (struct bt_vocs *)&vocs_insts[instance_cnt++];
|
return &vocs_insts[instance_cnt++];
|
||||||
}
|
}
|
||||||
|
|
||||||
void *bt_vocs_svc_decl_get(struct bt_vocs *vocs)
|
void *bt_vocs_svc_decl_get(struct bt_vocs *vocs)
|
||||||
|
@ -262,7 +262,7 @@ void *bt_vocs_svc_decl_get(struct bt_vocs *vocs)
|
||||||
static void prepare_vocs_instances(void)
|
static void prepare_vocs_instances(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ARRAY_SIZE(vocs_insts); i++) {
|
for (int i = 0; i < ARRAY_SIZE(vocs_insts); i++) {
|
||||||
vocs_insts[i].service_p = &vocs_service_list[i];
|
vocs_insts[i].srv.service_p = &vocs_service_list[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue