Changing a value on the database dinamically

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
3 posts / 0 new
Last post
TMiranda
Offline
Last seen:2 years 5 months ago
对未来ned:2017-11-16 18:00
Changing a value on the database dinamically

Hi guys,

I'm following up a question I've posted here (https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bl...–-software/reading-dummy-value) and it's not fully answered to my needs.

I'm trying to set a dummy value in my Bluetooth services, which I've already done this way:

On file @user_custs1_impl.c

void updating_device_id()
{
struct custs1_val_set_req *req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_SET_REQ,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_val_set_req,
DEF_SVC1_DEVICE_ID_CHAR_LEN);

// ADC value to be sampled
static uint16_t sample;
sample = 1234;

//req->conhdl = app_env->conhdl;
req->handle = SVC1_IDX_DEVICE_ID_VAL;
req->length = DEF_SVC1_DEVICE_ID_CHAR_LEN;
//req->notification = true;
memcpy(req->value, &sample, DEF_SVC1_DEVICE_ID_CHAR_LEN);

ke_msg_send(req);
}

void updating_major()
{
struct custs1_val_set_req *req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_SET_REQ,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_val_set_req,
DEF_SVC1_MAJOR_CHAR_LEN);

// ADC value to be sampled
static uint16_t sample;
sample = 4536;

//req->conhdl = app_env->conhdl;
req->handle = SVC1_IDX_MAJOR_VAL;
req->length = DEF_SVC1_MAJOR_CHAR_LEN;
//req->notification = true;
memcpy(req->value, &sample, DEF_SVC1_MAJOR_CHAR_LEN);

ke_msg_send(req);
}

void updating_minor()
{
struct custs1_val_set_req *req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_SET_REQ,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_val_set_req,
DEF_SVC1_MINOR_CHAR_LEN);

static uint16_t sample;
sample = 0xA0AA;
//req->conhdl = app_env->conhdl;
申请- >处理= SVC1_IDX_MINOR_VAL;
req->length = DEF_SVC1_MINOR_CHAR_LEN;
//req->notification = true;
memcpy(req->value, &sample, DEF_SVC1_MINOR_CHAR_LEN);

ke_msg_send(req);
}

void updating_location()
{
struct custs1_val_set_req *req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_SET_REQ,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_val_set_req,
DEF_SVC1_LOCATION__CHAR_LEN);

// ADC value to be sampled
static uint16_t sample;
sample = 6435;

//req->conhdl = app_env->conhdl;
req->handle = SVC1_IDX_LOCATION_VAL;
req->length = DEF_SVC1_LOCATION__CHAR_LEN;
//req->notification = true;
memcpy(req->value, &sample, DEF_SVC1_LOCATION__CHAR_LEN);

ke_msg_send(req);
}

file @user_peripheral.c
void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param)
{
if (app_env[connection_idx].conidx != GAP_INVALID_CONIDX)
{
app_connection_idx = connection_idx;

// Stop the advertising data update timer
app_easy_timer_cancel(app_adv_data_update_timer_used);
updating_device_id();
updating_major();
updating_minor();
updating_location();

...
}

Basically, I'm setting the values on my database on connection between the board and the app. My question is: how can I change dinamically those values?
As an example, if I read the value once, I would like to add 0x0001 to the stored value on my database and show the new value on my next Read command.

I was trying to do it on the user_catch_rest_hndl function, specifically on the case CUSTS1_ATT_INFO_REQ. But that's not working at all. Any tips?
I'm using the ble_pheriperal example of the SDK 6.0.6 to build my code.

Keywords:
Device:
TMiranda
Offline
Last seen:2 years 5 months ago
对未来ned:2017-11-16 18:00
I've already read both
MT_dialog
Offline
Last seen:1 month 3 weeks ago
Staff
对未来ned:2015-06-08 11:34
嗨TMiranda,

嗨TMiranda,

I am not sure if understand exactly what you are trying to do, in the code that you have pasted you are just sending a message in order to update the value of the characteristics, as far as i can understand you would like to read those values from the phone and as soon as those values are read you would like to update the values on that characteristic, if that is the case then on the 580 you could use theATTS_READ_REQ_IND in order to get that kind of indication in application level and as soon as a characteristic was read and when receiving that you could update again the values of the characteristics. In the 585/586 things are a bit different, the custs1 profile doesn't send a message towards the application level in order to indicate that, but if you apply the RI option in the database definition in the user_custs1_def.c file, for example use the below line as a reference in order to activate this feature for the custom characteristics that you would like to get an indication when read:

// ADC Value 1 Characteristic Value
[SVC1_IDX_ADC_VAL_1_VAL] = {SVC1_ADC_VAL_1_UUID_128, ATT_UUID_128_LEN, PERM(RD, ENABLE) | PERM(NTF, ENABLE),
PERM(RI, ENABLE)|DEF_SVC1_ADC_VAL_1_CHAR_LEN, 0, NULL},

By doing that you will get the gattc_read_req_ind_handler() function to execute as soon as a central tries to read a specific characteristic, that way you could implement what you would like to, please also check the implementation of the DISS profile which is using a similar option.

Thanks MT_dialog