, ,

nordic settings module

load multiple values at once with settings_load_subtree_direct:

add :

uint64_t length_val = 100;
uint16_t length_1_val = 40;
uint32_t length_2_val = 60;

struct direct_length_data {
	uint64_t length;
	uint16_t length_1;
	uint32_t length_2;
};

static int direct_loader(const char *name, size_t len, settings_read_cb read_cb,
			  void *cb_arg, void *param)
{
	const char *next;
	size_t name_len;
	int rc;
	struct direct_length_data *dest = (struct direct_length_data *)param;

	printk("direct load: ");

	name_len = settings_name_next(name, &next);

	if (name_len == 0) {
		rc = read_cb(cb_arg, &(dest->length), sizeof(dest->length));
		printk("<alpha/length>\n");
		return 0;
	}

	name_len = settings_name_next(name, &next);
	if (next) {
		printk("nothing\n");
		return -ENOENT;
	}

	if (!strncmp(name, "1", name_len)) {
		rc = read_cb(cb_arg, &(dest->length_1), sizeof(dest->length_1));
		printk("<alpha/length/1>\n");
		return 0;
	}

	if (!strncmp(name, "2", name_len)) {
		rc = read_cb(cb_arg, &(dest->length_2), sizeof(dest->length_2));
		printk("<alpha/length/2>\n");
		return 0;
	}

	printk("nothing\n");
	return -ENOENT;
}

use it with:

    int rc;
	struct direct_length_data dld;
	rc = settings_load_subtree_direct("alpha/length", direct_loader,
					  (void *)&dld);
					  	if (rc == 0) {
		printk("  direct.length = %" PRId64 "\n", dld.length);
		printk("  direct.length_1 = %d\n", dld.length_1);
		printk("  direct.length_2 = %d\n", dld.length_2);
	} else {
		printk("  direct load fails unexpectedly\n");
	}
Loïc Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *