Notifications working for ATT characteristic

This commit is contained in:
Adam Greenwood-Byrne 2020-08-11 17:48:00 +01:00
parent 8d1a7750f1
commit b2ae702c48
3 changed files with 12 additions and 11 deletions

View file

@ -194,18 +194,18 @@ void bt_getbdaddr(unsigned char *bdaddr) {
for (int c=0;c<6;c++) bdaddr[c] = bt_waitReadByte();
}
void sendACLreadreq(unsigned int handle)
void sendACLsubscribe(unsigned int handle)
{
bt_writeByte(HCI_ACL_PKT);
bt_writeByte(lo(handle));
bt_writeByte(hi(handle));
unsigned int length = 0x0007;
unsigned int length = 0x0009;
bt_writeByte(lo(length));
bt_writeByte(hi(length));
unsigned int data_length = 0x0003;
unsigned int data_length = 0x0005;
bt_writeByte(lo(data_length));
bt_writeByte(hi(data_length));
@ -213,7 +213,7 @@ void sendACLreadreq(unsigned int handle)
bt_writeByte(lo(channel));
bt_writeByte(hi(channel));
unsigned char params[] = { 0x0a, 0x2a, 0x00 };
unsigned char params[] = { 0x12, 0x2b, 0x00, 0x01, 0x00 };
unsigned int c=0;
while (c++<data_length) bt_writeByte(params[c-1]);

View file

@ -13,4 +13,4 @@ void stopScanning();
void startActiveAdvertising();
void connect(unsigned char *addr);
void bt_flushrx();
void sendACLreadreq(unsigned int handle);
void sendACLsubscribe(unsigned int handle);

View file

@ -1,6 +1,5 @@
#include "io.h"
#include "bt.h"
#include "fb.h"
#define memcmp __builtin_memcmp
@ -177,10 +176,12 @@ void acl_poll()
length = data[0] | (data[1] << 8);
unsigned int channel = data[2] | (data[3] << 8);
unsigned char opcode = data[4];
if (opcode == 0x0b) {
for (int c=0;c<length-1;c++) uart_byte(data[5+c]);
if (opcode == 0x1b) {
unsigned int from_handle = data[5] | (data[6] << 8);
for (int c=0;c<length-3;c++) uart_byte(data[7+c]);
uart_writeText("\n");
}
}
@ -222,7 +223,7 @@ void main()
// Get the characteristic value
uart_writeText("Sending read request: ");
uart_hex(connection_handle); uart_writeText("\n");
sendACLreadreq(connection_handle);
sendACLsubscribe(connection_handle);
// Into the main infinite loop
uart_writeText("Waiting for input...\n");