Hello,
I am struggling to figure out how to use the "bt_gatt_attr_read()" function in a gatt read callback. I can successfully use it to read strings of type "char *" and "uint8_t *". However, the data I need to send is two large hex numbers (192 bits, too large for even a "long long" type to hold). I can send the numbers as ASCII, but I need them to come as a Byte array, so that the hex number is represented in the "byte array" format in the nRF-connect app. For example, I have the following numbers:
0x1122334455667788 (64 bits)
0x11223344556677881122334455667788 (128 bits)
I need to concatenate them and then send them in bytes.
The way I need to send them is using the "read characteristic" functionality. Ex: pressing the down-arrow on the nRF-connect phone app to read a characteristic. When I do that in the app, it should show (in byte array fomat):
0x112233445566778811223344556677881122334455667788 (192 bits)
However, I figured I would start small and try to just send the 64 bit number before trying to concatenate and send the larger number. But even that has proven too difficult for me.
I have tried to put the number in an array, like this:
{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}
and then passing the array into "bt_gatt_attr_read()" during the read callback. This also doesn't work. However, when I do this I can see the first element come through in the nRF-connect app (in this example, 0x11) but no others.
I'm not sure how to handle large numbers like this and the only way I can think to do so is to put them into an array.. but when I do so, the "bt_gatt_attr_read()" function only seems to read the first element or garbage! I've tried everything I can think of and I think I've reached the limit of my ability.
Thanks for any help you can provide. I have attached the relevant parts of my code.
BT_GATT_SERVICE_DEFINE(remote_srv, BT_GATT_PRIMARY_SERVICE(BT_UUID_REMOTE_SERVICE), BT_GATT_CHARACTERISTIC(BT_UUID_READER_TRANSACTION_CHRC, BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, BT_transaction_read_cb, BT_transaction_write_cb, NULL), ); // this is my gatt read callback static ssize_t BT_transaction_read_cb(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { mainboard_uart_send("bt_read!\r\n", 10); //debugging int test = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; int *p_test = test; //memcpy(buf, &p_test, 8*sizeof(test)); //I tried doing this too, didn't work either. return bt_gatt_attr_read(conn, attr, buf, len, offset, p_test, 8 * sizeof(test)); //returns TOTAL garbage! //return bt_gatt_attr_read(conn, attr, buf, len, offset, p_test, 8 * sizeof(test)); //returns first element followed by lots of garbage! //return bt_gatt_attr_read(conn, attr, buf, len, offset, p_test, 8 * sizeof(test)); //returns first element followed by 6 zeros! }