Skip to content

Commit 31ab5b0

Browse files
jefdriesenmikeller
authored andcommitted
Update the filter function
Halcyon changed the bluetooth device name to the full serial number without a prefix. The serial number uses the format YYMMPCNNNN (e.g. 2412070123) with: - YY = Production year - MM = Production month - PC = Product code (01 = HUD, 07 = handset) - NNNN = Continuous number The existing filter with the prefix is kept for backwards compatibility.
1 parent a696627 commit 31ab5b0

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/descriptor.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,35 @@ dc_match_cressi (const void *key, const void *value)
619619
return dc_match_hex_with_prefix (key, &p);
620620
}
621621

622+
static int
623+
dc_match_halcyon (const void *key, const void *value)
624+
{
625+
const char *str = (const char *) key;
626+
unsigned int model = *(const unsigned int *) value;
627+
628+
char prefix[16] = {0};
629+
dc_platform_snprintf(prefix, sizeof(prefix), "H%02u", model);
630+
631+
if (strncasecmp (str, prefix, 3) == 0) {
632+
return 1;
633+
}
634+
635+
size_t n = 0;
636+
while (str[n] != 0) {
637+
const char c = str[n];
638+
if (c < '0' || c > '9') {
639+
return 0;
640+
}
641+
n++;
642+
}
643+
644+
if (n < 10) {
645+
return 0;
646+
}
647+
648+
return strncasecmp (str + 4, prefix + 1, 2) == 0;
649+
}
650+
622651
static int
623652
dc_filter_internal (const void *key, const void *values, size_t count, size_t size, dc_match_t match)
624653
{
@@ -930,13 +959,13 @@ dc_filter_cressi (const dc_descriptor_t *descriptor, dc_transport_t transport, c
930959
static int
931960
dc_filter_halcyon (const dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata)
932961
{
933-
static const char * const bluetooth[] = {
934-
"H01", // Symbios HUD
935-
"H07", // Symbios Handset
962+
static const unsigned int model[] = {
963+
1, // Symbios HUD
964+
7, // Symbios Handset
936965
};
937966

938967
if (transport == DC_TRANSPORT_BLE) {
939-
return DC_FILTER_INTERNAL (userdata, bluetooth, 0, dc_match_prefix);
968+
return DC_FILTER_INTERNAL (userdata, model, 0, dc_match_halcyon);
940969
}
941970

942971
return 1;

0 commit comments

Comments
 (0)