mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-23 13:42:55 +08:00
fix: When the equipment is in poor contact, it is forbidden to empty the data
This commit is contained in:
parent
e3efc5ff76
commit
d2131b1d2a
@ -387,6 +387,11 @@ void ProtocolDock::on_add_protocol()
|
||||
|
||||
bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list<pv::data::decode::Decoder*> &sub_decoders)
|
||||
{
|
||||
if (_session->is_device_re_attach() == true){
|
||||
qDebug()<<"Keep current decoders, cancel add new.";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_session->get_device()->dev_inst()->mode != LOGIC) {
|
||||
qDebug()<<"Protocol Analyzer\nProtocol Analyzer is only valid in Digital Mode!";
|
||||
return false;
|
||||
@ -452,7 +457,7 @@ bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list<pv::dat
|
||||
|
||||
void ProtocolDock::del_all_protocol()
|
||||
{
|
||||
if (_protocol_lay_items.size() > 0)
|
||||
if (_protocol_lay_items.size() > 0 && _session->is_device_re_attach() == false)
|
||||
{
|
||||
_session->clear_all_decoder();
|
||||
|
||||
|
@ -60,6 +60,7 @@
|
||||
|
||||
#include "data/decode/decoderstatus.h"
|
||||
#include "dsvdef.h"
|
||||
|
||||
|
||||
namespace pv {
|
||||
|
||||
@ -100,6 +101,9 @@ SigSession::SigSession(DeviceManager *device_manager)
|
||||
_bClose = false;
|
||||
_callback = NULL;
|
||||
_dev_inst = NULL;
|
||||
_is_wait_reattch = false;
|
||||
_wait_reattch_times = 0;
|
||||
_is_device_reattach = false;
|
||||
|
||||
// Create snapshots & data containers
|
||||
_logic_data = new data::Logic(new data::LogicSnapshot());
|
||||
@ -134,7 +138,12 @@ void SigSession::set_device(DevInst *dev_inst)
|
||||
|
||||
assert(dev_inst);
|
||||
|
||||
clear_all_decoder(false);
|
||||
if (is_device_re_attach() == false){
|
||||
clear_all_decoder(false);
|
||||
}
|
||||
else{
|
||||
qDebug()<<"Keep current decoders";
|
||||
}
|
||||
|
||||
RELEASE_ARRAY(_group_traces);
|
||||
|
||||
@ -148,7 +157,18 @@ void SigSession::set_device(DevInst *dev_inst)
|
||||
|
||||
if (_dev_inst) {
|
||||
|
||||
qDebug()<<"Switch to device:"<<_dev_inst->format_device_title();
|
||||
QString dev_name = _dev_inst->format_device_title();
|
||||
|
||||
if (_last_device_name != dev_name){
|
||||
_last_device_name = dev_name;
|
||||
_is_device_reattach = false;
|
||||
clear_all_decoder(false);
|
||||
}
|
||||
else if (is_device_re_attach() == false){
|
||||
clear_all_decoder(false);
|
||||
}
|
||||
|
||||
qDebug()<<"Switch to device:"<<dev_name;
|
||||
|
||||
try {
|
||||
_dev_inst->use(this);
|
||||
@ -677,18 +697,18 @@ void SigSession::init_signals()
|
||||
unsigned int dso_probe_count = 0;
|
||||
unsigned int analog_probe_count = 0;
|
||||
|
||||
if (_logic_data)
|
||||
if (is_device_re_attach() == false){
|
||||
_logic_data->clear();
|
||||
if (_dso_data)
|
||||
_dso_data->clear();
|
||||
if (_analog_data)
|
||||
_analog_data->clear();
|
||||
if (_group_data)
|
||||
_group_data->clear();
|
||||
|
||||
|
||||
// Clear the decode traces
|
||||
clear_all_decoder();
|
||||
// Clear the decode traces
|
||||
clear_all_decoder();
|
||||
}
|
||||
else{
|
||||
qDebug()<<"Device loose contact";
|
||||
}
|
||||
|
||||
// Detect what data types we will receive
|
||||
if(_dev_inst) {
|
||||
@ -1207,17 +1227,33 @@ void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi,
|
||||
*/
|
||||
void SigSession::hotplug_callback(void *ctx, void *dev, int event, void *user_data)
|
||||
{
|
||||
if (_session != NULL){
|
||||
_session->on_hotplug_event(ctx, dev, event, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
void SigSession::on_hotplug_event(void *ctx, void *dev, int event, void *user_data)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)dev;
|
||||
(void)user_data;
|
||||
|
||||
if (USB_EV_HOTPLUG_ATTACH == event) {
|
||||
_session->_hot_attach = true;
|
||||
}else if (USB_EV_HOTPLUG_DETTACH == event) {
|
||||
_session->_hot_detach = true;
|
||||
}else{
|
||||
if (USB_EV_HOTPLUG_ATTACH != event && USB_EV_HOTPLUG_DETTACH != event){
|
||||
qDebug("Unhandled event %d\n", event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (USB_EV_HOTPLUG_ATTACH == event)
|
||||
{
|
||||
_hot_attach = true;
|
||||
_is_device_reattach = _is_wait_reattch;
|
||||
_is_wait_reattch = false; //cancel detach event
|
||||
}
|
||||
else if (USB_EV_HOTPLUG_DETTACH == event)
|
||||
{
|
||||
_wait_reattch_times = 0;
|
||||
_is_wait_reattch = true;
|
||||
_is_device_reattach = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1229,7 +1265,7 @@ void SigSession::hotplug_proc()
|
||||
qDebug("Hotplug thread start!");
|
||||
|
||||
try {
|
||||
while(_session && !_bHotplugStop) {
|
||||
while(_session && !_bHotplugStop) {
|
||||
|
||||
sr_hotplug_wait_timout(_sr_ctx);
|
||||
|
||||
@ -1244,6 +1280,17 @@ void SigSession::hotplug_proc()
|
||||
_hot_detach = false;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
if (_is_wait_reattch){
|
||||
_wait_reattch_times++;
|
||||
|
||||
// 500ms
|
||||
if (_wait_reattch_times == 5)
|
||||
{
|
||||
_hot_detach = true;
|
||||
_is_wait_reattch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(...) {
|
||||
qDebug("Interrupt exception for hotplug thread was thrown.");
|
||||
@ -1955,5 +2002,4 @@ void SigSession::set_stop_scale(float scale)
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace pv
|
||||
|
@ -36,13 +36,11 @@
|
||||
#include "data/mathstack.h"
|
||||
#include "interface/icallbacks.h"
|
||||
#include "dstimer.h"
|
||||
|
||||
#include "libsigrok.h"
|
||||
|
||||
|
||||
struct srd_decoder;
|
||||
struct srd_channel;
|
||||
|
||||
|
||||
class DecoderStatus;
|
||||
|
||||
typedef std::lock_guard<std::mutex> ds_lock_guard;
|
||||
@ -328,7 +326,9 @@ private:
|
||||
// thread for hotplug
|
||||
void hotplug_proc();
|
||||
|
||||
static void hotplug_callback(void *ctx, void *dev, int event, void *user_data);
|
||||
static void hotplug_callback(void *ctx, void *dev, int event, void *user_data);
|
||||
|
||||
void on_hotplug_event(void *ctx, void *dev, int event, void *user_data);
|
||||
|
||||
public:
|
||||
void reload();
|
||||
@ -338,8 +338,12 @@ public:
|
||||
void check_update();
|
||||
void set_repeating(bool repeat);
|
||||
void set_map_zoom(int index);
|
||||
void auto_end();
|
||||
|
||||
void auto_end();
|
||||
|
||||
inline bool is_device_re_attach(){
|
||||
return _is_device_reattach;
|
||||
}
|
||||
|
||||
private:
|
||||
DeviceManager *_device_manager;
|
||||
|
||||
@ -414,6 +418,10 @@ private:
|
||||
float _stop_scale;
|
||||
bool _bClose;
|
||||
struct sr_context *_sr_ctx;
|
||||
volatile bool _is_wait_reattch;
|
||||
volatile int _wait_reattch_times;
|
||||
bool _is_device_reattach;
|
||||
QString _last_device_name;
|
||||
|
||||
ISessionCallback *_callback;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user