ble qos

SETTINGS_STATIC_HANDLER_DEFINE(ble_qos, MODULE_NAME, NULL, settings_set, NULL,NULL); so how i have to call it ?

Parents
  • Hi ,

    You can implement the following code to call it.

    #include <zephyr/settings/settings.h>
    
    static uint32_t ble_interval;
    
    static int ble_qos_set(const char *key, size_t len,
    settings_read_cb read_cb, void *cb_arg)
    {
    const char *next;
    int rc;
    
    if (settings_name_steq(key, "interval", &next) && !next) {
    if (len != sizeof(ble_interval)) {
    return -EINVAL;
    }
    rc = read_cb(cb_arg, &ble_interval, sizeof(ble_interval));
    if (rc >= 0) {
    return 0;
    }
    return rc;
    }
    
    return -ENOENT;
    }
    
    SETTINGS_STATIC_HANDLER_DEFINE(ble_qos, "ble_qos", NULL, ble_qos_set, NULL, NULL);
    
    int main(void)
    {
    settings_subsys_init();
    settings_load();
    // ble_interval is now restored from storage
    
    // Update the value and save it
    ble_interval = 100;
    settings_save_one("ble_qos/interval", &ble_interval, sizeof(ble_interval));
    }

    Call it after settings_subsys_init() and whenever the value changes and needs to be persisted.

    Please let me know if you have any issues while implementing.

    Regards

    Pallavi

Reply
  • Hi ,

    You can implement the following code to call it.

    #include <zephyr/settings/settings.h>
    
    static uint32_t ble_interval;
    
    static int ble_qos_set(const char *key, size_t len,
    settings_read_cb read_cb, void *cb_arg)
    {
    const char *next;
    int rc;
    
    if (settings_name_steq(key, "interval", &next) && !next) {
    if (len != sizeof(ble_interval)) {
    return -EINVAL;
    }
    rc = read_cb(cb_arg, &ble_interval, sizeof(ble_interval));
    if (rc >= 0) {
    return 0;
    }
    return rc;
    }
    
    return -ENOENT;
    }
    
    SETTINGS_STATIC_HANDLER_DEFINE(ble_qos, "ble_qos", NULL, ble_qos_set, NULL, NULL);
    
    int main(void)
    {
    settings_subsys_init();
    settings_load();
    // ble_interval is now restored from storage
    
    // Update the value and save it
    ble_interval = 100;
    settings_save_one("ble_qos/interval", &ble_interval, sizeof(ble_interval));
    }

    Call it after settings_subsys_init() and whenever the value changes and needs to be persisted.

    Please let me know if you have any issues while implementing.

    Regards

    Pallavi

Children
No Data
Related