Skip to content

Commit

Permalink
subsys/settings: Update client modules
Browse files Browse the repository at this point in the history
This updates all client modules to const char processing of
setting names.

Update of peripheral_dis sample

Signed-off-by: Laczen JMS <[email protected]>
  • Loading branch information
Laczen authored and carlescufi committed Jun 18, 2019
1 parent 36edf92 commit 8ca8708
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 95 deletions.
6 changes: 4 additions & 2 deletions samples/bluetooth/peripheral_dis/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ static struct bt_conn_cb conn_callbacks = {
.disconnected = disconnected,
};

static int zephyr_settings_fw_load(struct settings_store *cs);
static int zephyr_settings_fw_load(struct settings_store *cs,
const char *subtree);

static const struct settings_store_itf zephyr_settings_fw_itf = {
.csi_load = zephyr_settings_fw_load,
Expand All @@ -55,7 +56,8 @@ static struct settings_store zephyr_settings_fw_store = {
.cs_itf = &zephyr_settings_fw_itf
};

static int zephyr_settings_fw_load(struct settings_store *cs)
static int zephyr_settings_fw_load(struct settings_store *cs,
const char *subtree)
{

#if defined(CONFIG_BT_GATT_DIS_SETTINGS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,48 +114,52 @@ void save_on_flash(u8_t id)
k_work_submit(&storage_work);
}

static int ps_set(int argc, char **argv, size_t len_rd,
static int ps_set(const char *key, size_t len_rd,
settings_read_cb read_cb, void *cb_arg)
{
ssize_t len = 0;
int key_len;
const char *next;

if (argc == 1) {
if (!strcmp(argv[0], "rc")) {
key_len = settings_name_next(key, &next);

if (!next) {
if (!strncmp(key, "rc", key_len)) {
len = read_cb(cb_arg, &reset_counter,
sizeof(reset_counter));
}

if (!strcmp(argv[0], "gdtt")) {
if (!strncmp(key, "gdtt", key_len)) {
len = read_cb(cb_arg,
&gen_def_trans_time_srv_user_data.tt,
sizeof(gen_def_trans_time_srv_user_data.tt));
}

if (!strcmp(argv[0], "gpo")) {
if (!strncmp(key, "gpo", key_len)) {
len = read_cb(cb_arg,
&gen_power_onoff_srv_user_data.onpowerup,
sizeof(gen_power_onoff_srv_user_data.onpowerup));
}

if (!strcmp(argv[0], "ltd")) {
if (!strncmp(key, "ltd", key_len)) {
len = read_cb(cb_arg,
&light_ctl_srv_user_data.lightness_temp_def,
sizeof(light_ctl_srv_user_data.lightness_temp_def));
}

if (!strcmp(argv[0], "ltl")) {
if (!strncmp(key, "ltl", key_len)) {
len = read_cb(cb_arg,
&light_ctl_srv_user_data.lightness_temp_last,
sizeof(light_ctl_srv_user_data.lightness_temp_last));
}

if (!strcmp(argv[0], "lr")) {
if (!strncmp(key, "lr", key_len)) {
len = read_cb(cb_arg,
&light_lightness_srv_user_data.lightness_range,
sizeof(light_lightness_srv_user_data.lightness_range));
}

if (!strcmp(argv[0], "tr")) {
if (!strncmp(key, "tr", key_len)) {
len = read_cb(cb_arg,
&light_ctl_srv_user_data.temperature_range,
sizeof(light_ctl_srv_user_data.temperature_range));
Expand Down
29 changes: 16 additions & 13 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3550,26 +3550,29 @@ static u8_t ccc_load(const struct bt_gatt_attr *attr, void *user_data)
return load->count ? BT_GATT_ITER_CONTINUE : BT_GATT_ITER_STOP;
}

static int ccc_set(int argc, char **argv, size_t len_rd,
settings_read_cb read_cb, void *cb_arg)
static int ccc_set(const char *name, size_t len_rd, settings_read_cb read_cb,
void *cb_arg)
{
struct ccc_store ccc_store[CCC_STORE_MAX];
struct ccc_load load;
bt_addr_le_t addr;
int len, err;
const char *next;

if (argc < 1) {
settings_name_next(name, &next);

if (!name) {
BT_ERR("Insufficient number of arguments");
return -EINVAL;
} else if (argc == 1) {
} else if (!next) {
load.addr_with_id.id = BT_ID_DEFAULT;
} else {
load.addr_with_id.id = strtol(argv[1], NULL, 10);
load.addr_with_id.id = strtol(next, NULL, 10);
}

err = bt_settings_decode_key(argv[0], &addr);
err = bt_settings_decode_key(name, &addr);
if (err) {
BT_ERR("Unable to decode address %s", argv[0]);
BT_ERR("Unable to decode address %s", name);
return -EINVAL;
}

Expand Down Expand Up @@ -3606,21 +3609,21 @@ static int ccc_set(int argc, char **argv, size_t len_rd,
BT_SETTINGS_DEFINE(ccc, ccc_set, NULL, NULL);

#if defined(CONFIG_BT_GATT_CACHING)
static int cf_set(int argc, char **argv, size_t len_rd,
settings_read_cb read_cb, void *cb_arg)
static int cf_set(const char *name, size_t len_rd, settings_read_cb read_cb,
void *cb_arg)
{
struct gatt_cf_cfg *cfg;
bt_addr_le_t addr;
int len, err;

if (argc < 1) {
if (!name) {
BT_ERR("Insufficient number of arguments");
return -EINVAL;
}

err = bt_settings_decode_key(argv[0], &addr);
err = bt_settings_decode_key(name, &addr);
if (err) {
BT_ERR("Unable to decode address %s", argv[0]);
BT_ERR("Unable to decode address %s", name);
return -EINVAL;
}

Expand Down Expand Up @@ -3654,7 +3657,7 @@ BT_SETTINGS_DEFINE(cf, cf_set, NULL, NULL);

static u8_t stored_hash[16];

static int db_hash_set(int argc, char **argv, size_t len_rd,
static int db_hash_set(const char *name, size_t len_rd,
settings_read_cb read_cb, void *cb_arg)
{
int len;
Expand Down
19 changes: 11 additions & 8 deletions subsys/bluetooth/host/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,18 @@ int bt_keys_store(struct bt_keys *keys)
return 0;
}

static int keys_set(int argc, char **argv, size_t len_rd,
settings_read_cb read_cb, void *cb_arg)
static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
void *cb_arg)
{
struct bt_keys *keys;
bt_addr_le_t addr;
u8_t id;
size_t len;
int err;
char val[BT_KEYS_STORAGE_LEN];
const char *next;

if (argc < 1) {
if (!name) {
BT_ERR("Insufficient number of arguments");
return -EINVAL;
}
Expand All @@ -298,18 +299,20 @@ static int keys_set(int argc, char **argv, size_t len_rd,
return -EINVAL;
}

BT_DBG("argv[0] %s val %s", argv[0], (len) ? val : "(null)");
BT_DBG("name %s val %s", name, (len) ? val : "(null)");

err = bt_settings_decode_key(argv[0], &addr);
err = bt_settings_decode_key(name, &addr);
if (err) {
BT_ERR("Unable to decode address %s", argv[0]);
BT_ERR("Unable to decode address %s", name);
return -EINVAL;
}

if (argc == 1) {
settings_name_next(name, &next);

if (!next) {
id = BT_ID_DEFAULT;
} else {
id = strtol(argv[1], NULL, 10);
id = strtol(next, NULL, 10);
}

if (!len) {
Expand Down
Loading

0 comments on commit 8ca8708

Please sign in to comment.