update: Auto scan connected hardware device first time

This commit is contained in:
dreamsourcelabTAI 2022-11-10 19:18:10 +08:00
parent 195e20fd05
commit 94a8e924f4
7 changed files with 109 additions and 47 deletions

View File

@ -417,7 +417,7 @@ SR_PRIV int sr_listen_hotplug(struct sr_context *ctx, hotplug_event_callback cal
ret = libusb_hotplug_register_callback(ctx->libusb_ctx, ret = libusb_hotplug_register_callback(ctx->libusb_ctx,
(libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), (libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT),
(libusb_hotplug_flag)LIBUSB_HOTPLUG_ENUMERATE, (libusb_hotplug_flag)LIBUSB_HOTPLUG_ENUMERATE,
0x2A0E, DS_VENDOR_ID,
LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY,
LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY,
(libusb_hotplug_callback_fn)sr_hotplug_callback, (libusb_hotplug_callback_fn)sr_hotplug_callback,

View File

@ -190,8 +190,11 @@ static GSList *scan(GSList *options)
struct sr_usb_dev_inst *usb_dev_info; struct sr_usb_dev_inst *usb_dev_info;
uint8_t bus; uint8_t bus;
uint8_t address; uint8_t address;
int isProduct;
int num;
drvc = di->priv; drvc = di->priv;
num = 0;
if (options != NULL) if (options != NULL)
sr_info("%s", "Scan DSCope device with options."); sr_info("%s", "Scan DSCope device with options.");
@ -242,11 +245,16 @@ static GSList *scan(GSList *options)
continue; continue;
} }
usb_speed = libusb_get_device_speed(device_handle); // The vendor id is not right.
if ((usb_speed != LIBUSB_SPEED_HIGH) && if (des.idVendor != DS_VENDOR_ID)
(usb_speed != LIBUSB_SPEED_SUPER))
continue; continue;
usb_speed = libusb_get_device_speed(device_handle);
if ((usb_speed != LIBUSB_SPEED_HIGH) && (usb_speed != LIBUSB_SPEED_SUPER)){
sr_info("scan(): The idVendor is right, but the usb speed is too low, speed type:%d", usb_speed);
continue;
}
prof = NULL; prof = NULL;
for (j = 0; supported_DSCope[j].vid; j++) { for (j = 0; supported_DSCope[j].vid; j++) {
if (des.idVendor == supported_DSCope[j].vid && if (des.idVendor == supported_DSCope[j].vid &&
@ -258,8 +266,28 @@ static GSList *scan(GSList *options)
} }
/* Skip if the device was not found. */ /* Skip if the device was not found. */
if (!prof) if (prof == NULL){
isProduct = 0;
//Mybe is a dslogic device.
for (j = 0; supported_DSLogic[j].vid; j++)
{
if (des.idVendor == supported_DSLogic[j].vid &&
des.idProduct == supported_DSLogic[j].pid &&
usb_speed == supported_DSLogic[j].usb_speed) {
isProduct = 1;
break;
}
}
if (isProduct == 0){
sr_info("scan(): The profile is not matched, idVendor:%02X, idProduct:%02X",
des.idVendor,
des.idProduct);
}
continue; continue;
}
if (sr_usb_device_is_exists(device_handle)){ if (sr_usb_device_is_exists(device_handle)){
sr_detail("Device is exists, handle: %p", device_handle); sr_detail("Device is exists, handle: %p", device_handle);
@ -294,6 +322,7 @@ static GSList *scan(GSList *options)
return NULL; return NULL;
} }
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
num++;
if (dsl_check_conf_profile(device_handle)) { if (dsl_check_conf_profile(device_handle)) {
/* Already has the firmware, so fix the new address. */ /* Already has the firmware, so fix the new address. */
@ -337,6 +366,8 @@ static GSList *scan(GSList *options)
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
} }
sr_info("Fond new DSCope device count: %d", num);
return devices; return devices;
} }

View File

@ -444,7 +444,7 @@ static const struct DSL_profile supported_DSLogic[] = {
/* /*
* DSLogic * DSLogic
*/ */
{0x2A0E, 0x0001, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic", NULL, {DS_VENDOR_ID, 0x0001, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic", NULL,
"DSLogic.fw", "DSLogic.fw",
"DSLogic33.bin", "DSLogic33.bin",
"DSLogic50.bin", "DSLogic50.bin",
@ -473,7 +473,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_MHZ(400)} SR_MHZ(400)}
}, },
{0x2A0E, 0x0003, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic Pro", NULL, {DS_VENDOR_ID, 0x0003, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic Pro", NULL,
"DSLogicPro.fw", "DSLogicPro.fw",
"DSLogicPro.bin", "DSLogicPro.bin",
"DSLogicPro.bin", "DSLogicPro.bin",
@ -500,7 +500,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_MHZ(400)} SR_MHZ(400)}
}, },
{0x2A0E, 0x0020, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic PLus", NULL, {DS_VENDOR_ID, 0x0020, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic PLus", NULL,
"DSLogicPlus.fw", "DSLogicPlus.fw",
"DSLogicPlus.bin", "DSLogicPlus.bin",
"DSLogicPlus.bin", "DSLogicPlus.bin",
@ -527,7 +527,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_MHZ(400)} SR_MHZ(400)}
}, },
{0x2A0E, 0x0021, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic Basic", NULL, {DS_VENDOR_ID, 0x0021, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic Basic", NULL,
"DSLogicBasic.fw", "DSLogicBasic.fw",
"DSLogicBasic.bin", "DSLogicBasic.bin",
"DSLogicBasic.bin", "DSLogicBasic.bin",
@ -554,7 +554,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_MHZ(400)} SR_MHZ(400)}
}, },
{0x2A0E, 0x0029, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U2Basic", NULL, {DS_VENDOR_ID, 0x0029, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U2Basic", NULL,
"DSLogicU2Basic.fw", "DSLogicU2Basic.fw",
"DSLogicU2Basic.bin", "DSLogicU2Basic.bin",
"DSLogicU2Basic.bin", "DSLogicU2Basic.bin",
@ -581,7 +581,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_MHZ(400)} SR_MHZ(400)}
}, },
{0x2A0E, 0x002A, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U3Pro16", NULL, {DS_VENDOR_ID, 0x002A, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U3Pro16", NULL,
"DSLogicU3Pro16.fw", "DSLogicU3Pro16.fw",
"DSLogicU3Pro16.bin", "DSLogicU3Pro16.bin",
"DSLogicU3Pro16.bin", "DSLogicU3Pro16.bin",
@ -608,7 +608,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_GHZ(1)} SR_GHZ(1)}
}, },
{0x2A0E, 0x002A, LIBUSB_SPEED_SUPER, "DreamSourceLab", "DSLogic U3Pro16", NULL, {DS_VENDOR_ID, 0x002A, LIBUSB_SPEED_SUPER, "DreamSourceLab", "DSLogic U3Pro16", NULL,
"DSLogicU3Pro16.fw", "DSLogicU3Pro16.fw",
"DSLogicU3Pro16.bin", "DSLogicU3Pro16.bin",
"DSLogicU3Pro16.bin", "DSLogicU3Pro16.bin",
@ -635,7 +635,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_GHZ(1)} SR_GHZ(1)}
}, },
{0x2A0E, 0x002C, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U3Pro32", NULL, {DS_VENDOR_ID, 0x002C, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSLogic U3Pro32", NULL,
"DSLogicU3Pro32.fw", "DSLogicU3Pro32.fw",
"DSLogicU3Pro32.bin", "DSLogicU3Pro32.bin",
"DSLogicU3Pro32.bin", "DSLogicU3Pro32.bin",
@ -662,7 +662,7 @@ static const struct DSL_profile supported_DSLogic[] = {
SR_GHZ(1)} SR_GHZ(1)}
}, },
{0x2A0E, 0x002C, LIBUSB_SPEED_SUPER, "DreamSourceLab", "DSLogic U3Pro32", NULL, {DS_VENDOR_ID, 0x002C, LIBUSB_SPEED_SUPER, "DreamSourceLab", "DSLogic U3Pro32", NULL,
"DSLogicU3Pro32.fw", "DSLogicU3Pro32.fw",
"DSLogicU3Pro32.bin", "DSLogicU3Pro32.bin",
"DSLogicU3Pro32.bin", "DSLogicU3Pro32.bin",
@ -696,7 +696,7 @@ static const struct DSL_profile supported_DSCope[] = {
/* /*
* DSCope * DSCope
*/ */
{0x2A0E, 0x0002, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope", NULL, {DS_VENDOR_ID, 0x0002, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope", NULL,
"DSCope.fw", "DSCope.fw",
"DSCope.bin", "DSCope.bin",
"DSCope.bin", "DSCope.bin",
@ -723,7 +723,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0004, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope20", NULL, {DS_VENDOR_ID, 0x0004, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope20", NULL,
"DSCope20.fw", "DSCope20.fw",
"DSCope20.bin", "DSCope20.bin",
"DSCope20.bin", "DSCope20.bin",
@ -750,7 +750,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0022, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope B20", NULL, {DS_VENDOR_ID, 0x0022, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope B20", NULL,
"DSCopeB20.fw", "DSCopeB20.fw",
"DSCope20.bin", "DSCope20.bin",
"DSCope20.bin", "DSCope20.bin",
@ -777,7 +777,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0023, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope C20", NULL, {DS_VENDOR_ID, 0x0023, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope C20", NULL,
"DSCopeC20.fw", "DSCopeC20.fw",
"DSCopeC20P.bin", "DSCopeC20P.bin",
"DSCopeC20P.bin", "DSCopeC20P.bin",
@ -805,7 +805,7 @@ static const struct DSL_profile supported_DSCope[] = {
}, },
{0x2A0E, 0x0024, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope C20P", NULL, {DS_VENDOR_ID, 0x0024, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope C20P", NULL,
"DSCopeC20P.fw", "DSCopeC20P.fw",
"DSCopeC20P.bin", "DSCopeC20P.bin",
"DSCopeC20P.bin", "DSCopeC20P.bin",
@ -832,7 +832,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0025, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope C20", NULL, {DS_VENDOR_ID, 0x0025, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope C20", NULL,
"DSCopeC20B.fw", "DSCopeC20B.fw",
"DSCopeC20B.bin", "DSCopeC20B.bin",
"DSCopeC20B.bin", "DSCopeC20B.bin",
@ -859,7 +859,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0026, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U2B20", NULL, {DS_VENDOR_ID, 0x0026, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U2B20", NULL,
"DSCopeU2B20.fw", "DSCopeU2B20.fw",
"DSCopeU2B20.bin", "DSCopeU2B20.bin",
"DSCopeU2B20.bin", "DSCopeU2B20.bin",
@ -886,7 +886,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0027, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U2P20", NULL, {DS_VENDOR_ID, 0x0027, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U2P20", NULL,
"DSCopeU2P20.fw", "DSCopeU2P20.fw",
"DSCopeU2P20.bin", "DSCopeU2P20.bin",
"DSCopeU2P20.bin", "DSCopeU2P20.bin",
@ -913,7 +913,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x0028, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U2B100", NULL, {DS_VENDOR_ID, 0x0028, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U2B100", NULL,
"DSCopeU2B100.fw", "DSCopeU2B100.fw",
"DSCopeU2B100.bin", "DSCopeU2B100.bin",
"DSCopeU2B100.bin", "DSCopeU2B100.bin",
@ -940,7 +940,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x002B, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U3P100", NULL, {DS_VENDOR_ID, 0x002B, LIBUSB_SPEED_HIGH, "DreamSourceLab", "DSCope U3P100", NULL,
"DSCopeU3P100.fw", "DSCopeU3P100.fw",
"DSCopeU3P100.bin", "DSCopeU3P100.bin",
"DSCopeU3P100.bin", "DSCopeU3P100.bin",
@ -967,7 +967,7 @@ static const struct DSL_profile supported_DSCope[] = {
SR_HZ(0)} SR_HZ(0)}
}, },
{0x2A0E, 0x002B, LIBUSB_SPEED_SUPER, "DreamSourceLab", "DSCope U3P100", NULL, {DS_VENDOR_ID, 0x002B, LIBUSB_SPEED_SUPER, "DreamSourceLab", "DSCope U3P100", NULL,
"DSCopeU3P100.fw", "DSCopeU3P100.fw",
"DSCopeU3P100.bin", "DSCopeU3P100.bin",
"DSCopeU3P100.bin", "DSCopeU3P100.bin",

View File

@ -292,8 +292,11 @@ static GSList *scan(GSList *options)
struct sr_usb_dev_inst *usb_dev_info; struct sr_usb_dev_inst *usb_dev_info;
uint8_t bus; uint8_t bus;
uint8_t address; uint8_t address;
int isProduct;
int num;
drvc = di->priv; drvc = di->priv;
num = 0;
if (options != NULL) if (options != NULL)
sr_info("%s", "Scan DSLogic device with options."); sr_info("%s", "Scan DSLogic device with options.");
@ -344,8 +347,13 @@ static GSList *scan(GSList *options)
continue; continue;
} }
// The vendor id is not right.
if (des.idVendor != DS_VENDOR_ID)
continue;
usb_speed = libusb_get_device_speed(device_handle); usb_speed = libusb_get_device_speed(device_handle);
if ((usb_speed != LIBUSB_SPEED_HIGH) && (usb_speed != LIBUSB_SPEED_SUPER)){ if ((usb_speed != LIBUSB_SPEED_HIGH) && (usb_speed != LIBUSB_SPEED_SUPER)){
sr_info("scan(): The idVendor is right, but the usb speed is too low, speed type:%d", usb_speed);
continue; continue;
} }
@ -361,8 +369,28 @@ static GSList *scan(GSList *options)
} }
/* Skip if the device was not found. */ /* Skip if the device was not found. */
if (!prof) if (prof == NULL){
isProduct = 0;
//Mybe is a dscope device.
for (j = 0; supported_DSCope[j].vid; j++)
{
if (des.idVendor == supported_DSCope[j].vid &&
des.idProduct == supported_DSCope[j].pid &&
usb_speed == supported_DSCope[j].usb_speed) {
isProduct = 1;
break;
}
}
if (isProduct == 0){
sr_info("scan(): The profile is not matched, idVendor:%02X, idProduct:%02X",
des.idVendor,
des.idProduct);
}
continue; continue;
}
if (sr_usb_device_is_exists(device_handle)){ if (sr_usb_device_is_exists(device_handle)){
sr_detail("Device is exists, handle: %p", device_handle); sr_detail("Device is exists, handle: %p", device_handle);
@ -395,6 +423,7 @@ static GSList *scan(GSList *options)
return NULL; return NULL;
} }
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
num++;
if (dsl_check_conf_profile(device_handle)) { if (dsl_check_conf_profile(device_handle)) {
/* Already has the firmware, so fix the new address. */ /* Already has the firmware, so fix the new address. */
@ -439,6 +468,8 @@ static GSList *scan(GSList *options)
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
} }
sr_info("Fond new DSLogic device count: %d", num);
return devices; return devices;
} }

View File

@ -396,7 +396,7 @@ SR_PRIV int ds_scan_all_device_list(libusb_context *usb_ctx,struct libusb_device
continue; continue;
} }
if (des.idVendor == 0x2A0E){ if (des.idVendor == DS_VENDOR_ID){
if (wr >= size){ if (wr >= size){
sr_err("%s", "ds_scan_all_device_list(), buffer length is too short."); sr_err("%s", "ds_scan_all_device_list(), buffer length is too short.");
assert(0); assert(0);

View File

@ -72,6 +72,7 @@ static void collect_run_proc();
static void post_event_async(int event); static void post_event_async(int event);
static void send_event(int event); static void send_event(int event);
static void make_demo_device_to_list(); static void make_demo_device_to_list();
static void process_attach_event(int isEvent);
static struct libusb_device* get_new_attached_usb_device(); static struct libusb_device* get_new_attached_usb_device();
static struct libusb_device* get_new_detached_usb_device(); static struct libusb_device* get_new_detached_usb_device();
@ -153,6 +154,10 @@ SR_API int ds_lib_init()
#endif #endif
#endif #endif
// Scan the all hardware device.
sr_info("%s", "Scan all connected hardware device.");
process_attach_event(0);
sr_listen_hotplug(lib_ctx.sr_ctx, hotplug_event_listen_callback); sr_listen_hotplug(lib_ctx.sr_ctx, hotplug_event_listen_callback);
/** Start usb hotplug thread */ /** Start usb hotplug thread */
@ -1160,7 +1165,7 @@ static void hotplug_event_listen_callback(struct libusb_context *ctx, struct lib
} }
if (dev == NULL){ if (dev == NULL){
sr_err("%s", "hotplug_event_listen_callback(), @dev is null."); sr_err("%s", "hotplug_event_listen_callback(), no devices to process");
return; return;
} }
@ -1233,7 +1238,7 @@ static void hotplug_event_listen_callback(struct libusb_context *ctx, struct lib
} }
} }
static void process_attach_event() static void process_attach_event(int isEvent)
{ {
struct sr_dev_driver **drivers; struct sr_dev_driver **drivers;
GList *dev_list; GList *dev_list;
@ -1241,12 +1246,8 @@ static void process_attach_event()
struct sr_dev_driver *dr; struct sr_dev_driver *dr;
int num = 0; int num = 0;
if (isEvent){
sr_info("%s", "Process device attach event."); sr_info("%s", "Process device attach event.");
if (lib_ctx.attach_device_handle == NULL)
{
sr_err("%s", "The attached device handle is null.");
return;
} }
drivers = sr_driver_list(); drivers = sr_driver_list();
@ -1278,9 +1279,7 @@ static void process_attach_event()
} }
// Tell user one new device attched, and the list is updated. // Tell user one new device attched, and the list is updated.
if (num > 0 && isEvent){
if (num > 0)
{
post_event_async(DS_EV_NEW_DEVICE_ATTACH); post_event_async(DS_EV_NEW_DEVICE_ATTACH);
} }
@ -1346,13 +1345,12 @@ static void usb_hotplug_process_proc()
{ {
sr_hotplug_wait_timout(lib_ctx.sr_ctx); sr_hotplug_wait_timout(lib_ctx.sr_ctx);
if (lib_ctx.attach_event_flag) if (lib_ctx.attach_event_flag){
{ process_attach_event(1);
process_attach_event();
lib_ctx.attach_event_flag = 0; lib_ctx.attach_event_flag = 0;
} }
if (lib_ctx.detach_event_flag)
{ if (lib_ctx.detach_event_flag){
process_detach_event(); process_detach_event();
lib_ctx.detach_event_flag = 0; lib_ctx.detach_event_flag = 0;
} }

View File

@ -54,6 +54,8 @@
#define g_safe_free(p) if((p)) g_free((p)); ((p)) = NULL; #define g_safe_free(p) if((p)) g_free((p)); ((p)) = NULL;
#define g_safe_free_list(p) if((p)) g_slist_free((p)); ((p)) = NULL; #define g_safe_free_list(p) if((p)) g_slist_free((p)); ((p)) = NULL;
#define DS_VENDOR_ID 0x2A0E
/** global variable */ /** global variable */
extern char DS_RES_PATH[500]; extern char DS_RES_PATH[500];
extern struct ds_trigger *trigger; extern struct ds_trigger *trigger;