2 posts / 0 new
Last post
scnash
Offline
Last seen:5 years 8 months ago
加入:2014-12-09 22:07
Reading device name

Greetings,

I am using the SPS profile between two DA14580 devices. When they connect I want the remote device to look at the name of the device that initiated the connection. It seems like a simple enough thing but I just cant figure out where to start. From what I can see the device name UUID is always 0x2A00 and at least for these devices the attribute handle seems to always be 3 for the device name. What would be the simplest way to read a specific characteristic just after a connection is made?

Device:
MHv_Dialog
Offline
Last seen:2周6天前
年代taff
加入:2013-12-06 15:10
Hi,

Hi,

In this case, where you are in control of both ends of the link, using the GATT handle for read/write is a good solution, and the device name is as you state "filed" under handle 0x0003 in the DSPS implementation (and pretty much any other Dialog sample application).

This function will result in a read command being issued to the peer device:

void app_read_device_name_by_handle() { struct gattc_read_cmd *cmd = KE_MSG_ALLOC(GATTC_READ_CMD, TASK_GATTC,TASK_APP,gattc_read_cmd); cmd->req_type = GATTC_READ; cmd->nb =1; cmd->req.simple.handle = 0x0003; // Device name on a DSPS device is always 3 cmd->req.simple.offset = 0; cmd->req.simple.length = 0; // Read all ke_msg_send(cmd); }

The peer will respond, and you need to have a taskhandler defined in order to react when the response arrives (in app_task_handlers.h)

{GATTC_READ_IND, (ke_msg_func_t)app_read_ind_handler},

An then in your application, receive the response and parse the data (I am simply printing it to the debug port in this example):

void app_read_ind_handler(ke_msg_id_t const msgid, struct gattc_read_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { uint8_t c[param->length]; memcpy(&c,param->value,param->length); arch_printf("Data Received: %s\n\r>",c); }

I hope this helps you move forward.