Re: [web-bluetooth] Accept filters on manufacturer and service data.

At the beginning - thanks for decision that this feature will be 
included in specification. My only suggestion is that 'mask/prefix' is
 not so intuitive to use and something like 'pattern/ignore' would be 
little better and more flexible. I'm not javascript expert, so allowed
 myself to write small example in C to illustrate this:

```C
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>

char service_data_1[] = {0xAA, 0xB3, 0xCC}; //10101010 10110011 
11001100
char service_data_2[] = {0xAE, 0x8B, 0xCD}; //10101110 10001011 
11001101

char pattern[]        = {0xA0, 0x00, 0xCC}; //10100000 00000000 
11001100
char ignore[]         = {0x0F, 0xFF, 0x00}; //00001111 11111111 
00000000

bool service_data_check(char * p_service_data, size_t 
service_data_size, char * p_pattern, char * p_ignore)
{
    for(char i=0; i<service_data_size; i++)
    {
        if( (p_service_data[i] & (~ignore[i])) == (p_pattern[i] & 
(~ignore[i])) )
        {
            //byte matches - go ahead
        }
        else
        {
            //byte not matches - stop checking
            printf("Service data don't matches pattern!\n");
            return false;
        }
    }
    
    printf("Service data matches pattern!\n");
    return true;
}

int main()
{
    service_data_check(service_data_1, sizeof(service_data_1), 
pattern, ignore);
    service_data_check(service_data_2, sizeof(service_data_2), 
pattern, ignore);
}
```

-- 
GitHub Notification of comment by irgu
Please view or discuss this issue at 
https://github.com/WebBluetoothCG/web-bluetooth/pull/297#issuecomment-250141589
 using your GitHub account

Received on Wednesday, 28 September 2016 11:31:05 UTC