From 7053af0a8f384006ce03e6b554af962601465b13 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 20 Jun 2023 15:29:34 +0800 Subject: [PATCH] The store confirm times, and surport the old version hardware --- DSView/pv/mainwindow.cpp | 2 + DSView/pv/sigsession.h | 4 ++ libsigrok4DSL/hardware/DSL/dscope.c | 78 +++++++++++++--------------- libsigrok4DSL/hardware/DSL/dsl.c | 17 +++--- libsigrok4DSL/hardware/DSL/dslogic.c | 76 +++++++++++++-------------- libsigrok4DSL/lib_main.c | 7 ++- 6 files changed, 95 insertions(+), 89 deletions(-) diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 429341bc..a126c550 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -2007,6 +2007,8 @@ namespace pv break; case DSV_MSG_SAVE_COMPLETE: + _session->clear_store_confirm_flag(); + if (_is_auto_switch_device) { _is_auto_switch_device = false; diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index bcb31a7d..82c68df2 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -199,6 +199,10 @@ public: bool is_first_store_confirm(); bool get_capture_status(bool &triggered, int &progress); + inline void clear_store_confirm_flag(){ + _confirm_store_time_id = _work_time_id; + } + std::vector& get_signals(); bool add_decoder(srd_decoder *const dec, bool silent, DecoderStatus *dstatus, diff --git a/libsigrok4DSL/hardware/DSL/dscope.c b/libsigrok4DSL/hardware/DSL/dscope.c index 45ec0fd7..5f1e6732 100644 --- a/libsigrok4DSL/hardware/DSL/dscope.c +++ b/libsigrok4DSL/hardware/DSL/dscope.c @@ -190,7 +190,7 @@ static GSList *scan(GSList *options) struct libusb_device_descriptor des; libusb_device **devlist; libusb_device *device_handle = NULL; - int devcnt, ret, i, j; + int ret, i, j; const char *conn; enum libusb_speed usb_speed; struct sr_usb_dev_inst *usb_dev_info; @@ -316,67 +316,63 @@ static GSList *scan(GSList *options) address = libusb_get_device_address(device_handle); sr_info("Found a new device,handle:%p", device_handle); - devc = DSCope_dev_new(prof); - if (!devc) - return NULL; - - sdi = sr_dev_inst_new(channel_modes[devc->ch_mode].mode, SR_ST_INITIALIZING, - prof->vendor, prof->model, prof->model_version); - - if (!sdi) { - g_free(devc); - return NULL; - } - - sdi->priv = devc; - sdi->driver = di; - sdi->dev_type = DEV_TYPE_USB; - sdi->handle = (ds_device_handle)device_handle; - - /* Fill in probelist according to this device's profile. */ - if (dsl_setup_probes(sdi, channel_modes[devc->ch_mode].num) != SR_OK){ - sr_err("dsl_setup_probes() error"); - dev_destroy(sdi); - return NULL; - } - devices = g_slist_append(devices, sdi); - num++; - if (dsl_check_conf_profile(device_handle)) { /* Already has the firmware, so fix the new address. */ sr_info("Found a DSCope device,name:\"%s\",handle:%p", prof->model, device_handle); + devc = DSCope_dev_new(prof); + if (devc == NULL){ + break; + } + + sdi = sr_dev_inst_new(channel_modes[devc->ch_mode].mode, SR_ST_INITIALIZING, + prof->vendor, prof->model, prof->model_version); + + if (sdi == NULL) { + free(devc); + break; + } + + sdi->priv = devc; + sdi->driver = di; + sdi->dev_type = DEV_TYPE_USB; + sdi->handle = (ds_device_handle)device_handle; + + /* Fill in probelist according to this device's profile. */ + if (dsl_setup_probes(sdi, channel_modes[devc->ch_mode].num) != SR_OK){ + sr_err("dsl_setup_probes() error"); + dev_destroy(sdi); + break; + } + usb_dev_info = sr_usb_dev_inst_new(bus, address); usb_dev_info->usb_dev = device_handle; sdi->conn = usb_dev_info; - sdi->status = SR_ST_INACTIVE; + sdi->status = SR_ST_INACTIVE; + + devices = g_slist_append(devices, sdi); + num++; } else { char *firmware; char *res_path = DS_RES_PATH; if (!(firmware = malloc(strlen(res_path)+strlen(prof->firmware) + 5))) { sr_err("Firmware path malloc error!"); - return NULL; + break; } - strcpy(firmware, res_path); strcat(firmware, "/"); strcat(firmware, prof->firmware); sr_info("Install firmware bin file, device:\"%s\", file:\"%s\"", prof->model, firmware); - if (ezusb_upload_firmware(device_handle, USB_CONFIGURATION, - firmware) == SR_OK) - /* Store when this device's FW was updated. */ - devc->fw_updated = g_get_monotonic_time(); - else - sr_err("Firmware upload failed for " - "device %d.", devcnt); + if (ezusb_upload_firmware(device_handle, USB_CONFIGURATION, firmware) != SR_OK){ + sr_err("Firmware upload failed for device %s", prof->model); + } + g_free(firmware); - - usb_dev_info = sr_usb_dev_inst_new(bus, 0xff); - usb_dev_info->usb_dev = device_handle; - sdi->conn = usb_dev_info; + + sr_info("Waitting for device reconnect, name:\"%s\"", prof->model); } } diff --git a/libsigrok4DSL/hardware/DSL/dsl.c b/libsigrok4DSL/hardware/DSL/dsl.c index f64e82be..4916f85f 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.c +++ b/libsigrok4DSL/hardware/DSL/dsl.c @@ -1824,14 +1824,7 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo * Just wait for renumerate -> detach -> attach */ ret = SR_ERR; - if (devc->fw_updated > 0) { - sr_info("%s: Firmware upload have done.", __func__); - return SR_ERR; - } - else { - sr_info("%s: Firmware upload was not needed.", __func__); - ret = hw_dev_open(di, sdi); - } + ret = hw_dev_open(di, sdi); if (ret != SR_OK) { sr_err("%s: Unable to open device.", __func__); @@ -1963,7 +1956,15 @@ SR_PRIV int dsl_dev_close(struct sr_dev_inst *sdi) { struct sr_usb_dev_inst *usb; + assert(sdi); + usb = sdi->conn; + + if (usb == NULL){ + sdi->status = SR_ST_INACTIVE; + return SR_OK; + } + if (usb->devhdl == NULL){ sr_detail("dsl_dev_close(),libusb_device_handle is null."); return SR_ERR; diff --git a/libsigrok4DSL/hardware/DSL/dslogic.c b/libsigrok4DSL/hardware/DSL/dslogic.c index 7e0ee431..de53bb94 100644 --- a/libsigrok4DSL/hardware/DSL/dslogic.c +++ b/libsigrok4DSL/hardware/DSL/dslogic.c @@ -276,7 +276,7 @@ static GSList *scan(GSList *options) struct libusb_device_descriptor des; libusb_device **devlist; libusb_device *device_handle = NULL; - int devcnt, ret, i, j; + int ret, i, j; const char *conn; enum libusb_speed usb_speed; struct sr_usb_dev_inst *usb_dev_info; @@ -403,46 +403,49 @@ static GSList *scan(GSList *options) bus = libusb_get_bus_number(device_handle); address = libusb_get_device_address(device_handle); sr_info("Found a new device,handle:%p", device_handle); - - devc = DSLogic_dev_new(prof); - if (!devc) - return NULL; - - sdi = sr_dev_inst_new(channel_modes[devc->ch_mode].mode, SR_ST_INITIALIZING, - prof->vendor, prof->model, prof->model_version); - if (!sdi) { - g_free(devc); - return NULL; - } - sdi->priv = devc; - sdi->driver = di; - sdi->dev_type = DEV_TYPE_USB; - sdi->handle = (ds_device_handle)device_handle; - /* Fill in probelist according to this device's profile. */ - if (dsl_setup_probes(sdi, channel_modes[devc->ch_mode].num) != SR_OK){ - sr_err("dsl_setup_probes() error"); - dev_destroy(sdi); - return NULL; - } - devices = g_slist_append(devices, sdi); - num++; - if (dsl_check_conf_profile(device_handle)) { /* Already has the firmware, so fix the new address. */ sr_info("Found a DSLogic device,name:\"%s\",handle:%p", prof->model,device_handle); + + devc = DSLogic_dev_new(prof); + if (devc == NULL){ + break; + } + + sdi = sr_dev_inst_new(channel_modes[devc->ch_mode].mode, SR_ST_INITIALIZING, + prof->vendor, prof->model, prof->model_version); + if (sdi == NULL) { + free(devc); + break; + } + + sdi->priv = devc; + sdi->driver = di; + sdi->dev_type = DEV_TYPE_USB; + sdi->handle = (ds_device_handle)device_handle; + + /* Fill in probelist according to this device's profile. */ + if (dsl_setup_probes(sdi, channel_modes[devc->ch_mode].num) != SR_OK){ + sr_err("dsl_setup_probes() error"); + dev_destroy(sdi); + break; + } usb_dev_info = sr_usb_dev_inst_new(bus, address); usb_dev_info->usb_dev = device_handle; sdi->conn = usb_dev_info; - sdi->status = SR_ST_INACTIVE; + sdi->status = SR_ST_INACTIVE; + + devices = g_slist_append(devices, sdi); + num++; } else { char *firmware; char *res_path = DS_RES_PATH; if (!(firmware = malloc(strlen(res_path)+strlen(prof->firmware) + 5))) { sr_err("Firmware path malloc error!"); - return NULL; + break; } strcpy(firmware, res_path); strcat(firmware, "/"); @@ -450,18 +453,13 @@ static GSList *scan(GSList *options) sr_info("Install firmware bin file, device:\"%s\", file:\"%s\"", prof->model, firmware); - if (ezusb_upload_firmware(device_handle, USB_CONFIGURATION, - firmware) == SR_OK) - /* Store when this device's FW was updated. */ - devc->fw_updated = g_get_monotonic_time(); - else - sr_err("Firmware upload failed for " - "device %d.", devcnt); - g_free(firmware); - - usb_dev_info = sr_usb_dev_inst_new(bus, 0xff); - usb_dev_info->usb_dev = device_handle; - sdi->conn = usb_dev_info; + if (ezusb_upload_firmware(device_handle, USB_CONFIGURATION, firmware) != SR_OK){ + sr_err("Firmware upload failed for device %s.", prof->model); + } + + free(firmware); + + sr_info("Waitting for device reconnect, name:\"%s\"", prof->model); } } diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index 2fc1864a..52e0b302 100644 --- a/libsigrok4DSL/lib_main.c +++ b/libsigrok4DSL/lib_main.c @@ -1362,6 +1362,7 @@ static void process_detach_event() struct sr_dev_driver *driver_ins; libusb_device *ev_dev; int ev; + int bFind; sr_info("Process device detach event."); @@ -1375,6 +1376,7 @@ static void process_detach_event() } lib_ctx.detach_device_handle = NULL; + bFind = 0; pthread_mutex_lock(&lib_ctx.mutext); for (l = lib_ctx.device_list; l; l = l->next) @@ -1397,13 +1399,16 @@ static void process_detach_event() destroy_device_instance(dev); } + bFind = 1; break; } } pthread_mutex_unlock(&lib_ctx.mutext); // Tell user a new device detached, and the list is updated. - post_event_async(ev); + if (bFind){ + post_event_async(ev); + } } static void usb_hotplug_process_proc()