X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fserial_bt.c;h=23b4dd6ce159aac263071ad3db6ce65689e5b52d;hb=dca972f8ba1eca12fd462bd97788b18c8953ce64;hp=a851dad8c6fff16a1e2874b7fb165a08b41c11b3;hpb=0e4a85a9254cf684c3a30ef0d0eb370b90c68541;p=libsigrok.git diff --git a/src/serial_bt.c b/src/serial_bt.c index a851dad8..23b4dd6c 100644 --- a/src/serial_bt.c +++ b/src/serial_bt.c @@ -54,17 +54,54 @@ /* {{{ support for serial-over-BT channels */ +/* + * This builtin database of known devices (keyed by their names as + * provided during BT/BLE scans) can help improve the presentation of + * scan results. Ideally users could take the output and pass it to + * subsequent program invocations, not having to "come up with" the + * conn= spec, or only having to touch it up minimally. GUI dialogs + * could present scan results such that users just need to pick an + * item to open a connection. + * + * The current implementation guesses connection types from device + * names, and optionally amends them with additional parameters if + * experience shows that individual devices need these extra specs. + * + * This database may have to move to a separate source file should + * its size grow to amounts that are considered inappropriate here + * in the serial transport's BT dispatcher. For now the item count + * is small. + */ + static const struct scan_supported_item { const char *name; enum ser_bt_conn_t type; + const char *add_params; } scan_supported_items[] = { - /* Guess connection types from device names (useful for scans). */ - { "121GW", SER_BT_CONN_BLE122, }, - { "Adafruit Bluefruit LE 8134", SER_BT_CONN_NRF51, }, - { "HC-05", SER_BT_CONN_RFCOMM, }, - { NULL, SER_BT_CONN_UNKNOWN, }, + { "121GW", SER_BT_CONN_BLE122, NULL, }, + { "Adafruit Bluefruit LE 8134", SER_BT_CONN_NRF51, NULL, }, + { "HC-05", SER_BT_CONN_RFCOMM, NULL, }, + { "UM25C", SER_BT_CONN_RFCOMM, NULL, }, + { NULL, SER_BT_CONN_UNKNOWN, NULL, }, }; +static const struct scan_supported_item *scan_is_supported(const char *name) +{ + size_t idx; + const struct scan_supported_item *item; + + for (idx = 0; idx < ARRAY_SIZE(scan_supported_items); idx++) { + item = &scan_supported_items[idx]; + if (!item->name) + break; + if (strcmp(name, item->name) != 0) + continue; + return item; + } + + return NULL; +} + static const char *ser_bt_conn_names[SER_BT_CONN_MAX] = { [SER_BT_CONN_UNKNOWN] = "", [SER_BT_CONN_RFCOMM] = "rfcomm", @@ -125,14 +162,16 @@ static const char *conn_name_text(enum ser_bt_conn_t type) * - The next field is the remote device's address, either separated * by colons or dashes or spaces, or not separated at all. * - Other parameters (RFCOMM channel, notify handles and write values) - * get derived from the connection type. A future implementation may - * accept more fields, but the syntax is yet to get developed. + * get derived from the connection type. + * - More fields after the remote address are options which override + * builtin defaults (RFCOMM channels, BLE handles, etc). * * Supported formats resulting from these rules: - * bt// + * bt//[/]... * * Examples: * bt/rfcomm/11-22-33-44-55-66 + * bt/rfcomm/11-22-33-44-55-66/channel=2 * bt/ble122/88:6b:12:34:56:78 * bt/cc254x/0123456789ab * @@ -777,23 +816,6 @@ static int ser_bt_setup_source_remove(struct sr_session *session, return SR_OK; } -static enum ser_bt_conn_t scan_is_supported(const char *name) -{ - size_t idx; - const struct scan_supported_item *item; - - for (idx = 0; idx < ARRAY_SIZE(scan_supported_items); idx++) { - item = &scan_supported_items[idx]; - if (!item->name) - break; - if (strcmp(name, item->name) != 0) - continue; - return item->type; - } - - return SER_BT_CONN_UNKNOWN; -} - struct bt_scan_args_t { GSList *port_list; sr_ser_list_append_t append; @@ -806,6 +828,7 @@ static void scan_cb(void *cb_args, const char *addr, const char *name) struct bt_scan_args_t *scan_args; GSList *l; char addr_text[20]; + const struct scan_supported_item *item; enum ser_bt_conn_t type; char *port_name, *port_desc; char *addr_copy; @@ -828,9 +851,11 @@ static void scan_cb(void *cb_args, const char *addr, const char *name) g_strcanon(addr_text, "0123456789abcdefABCDEF", '-'); /* Create a port name, and a description. */ - type = scan_is_supported(name); - port_name = g_strdup_printf("%s/%s/%s", - SER_BT_CONN_PREFIX, conn_name_text(type), addr_text); + item = scan_is_supported(name); + type = item ? item->type : SER_BT_CONN_UNKNOWN; + port_name = g_strdup_printf("%s/%s/%s%s", + SER_BT_CONN_PREFIX, conn_name_text(type), addr_text, + (item && item->add_params) ? item->add_params : ""); port_desc = g_strdup_printf("%s (%s)", name, scan_args->bt_type); scan_args->port_list = scan_args->append(scan_args->port_list, port_name, port_desc); @@ -844,7 +869,7 @@ static void scan_cb(void *cb_args, const char *addr, const char *name) static GSList *ser_bt_list(GSList *list, sr_ser_list_append_t append) { - static const int scan_duration = 2; + static const int scan_duration = 3; struct bt_scan_args_t scan_args; struct sr_bt_desc *desc;