diff options
Diffstat (limited to 'DSLogic-gui/pv/sigsession.cpp')
-rw-r--r-- | DSLogic-gui/pv/sigsession.cpp | 731 |
1 files changed, 558 insertions, 173 deletions
diff --git a/DSLogic-gui/pv/sigsession.cpp b/DSLogic-gui/pv/sigsession.cpp index 684f346..27d7946 100644 --- a/DSLogic-gui/pv/sigsession.cpp +++ b/DSLogic-gui/pv/sigsession.cpp @@ -26,11 +26,14 @@ #include "devicemanager.h" #include "data/analog.h" #include "data/analogsnapshot.h" +#include "data/dso.h" +#include "data/dsosnapshot.h" #include "data/logic.h" #include "data/logicsnapshot.h" #include "data/group.h" #include "data/groupsnapshot.h" #include "view/analogsignal.h" +#include "view/dsosignal.h" #include "view/logicsignal.h" #include "view/groupsignal.h" #include "view/protocolsignal.h" @@ -59,8 +62,7 @@ SigSession::SigSession(DeviceManager &device_manager) : _sdi(NULL), _capture_state(Init), _last_sample_rate(1), - _total_sample_len(1), - _hot_plug_handle(NULL) + _total_sample_len(1) { // TODO: This should not be necessary _session = this; @@ -71,20 +73,28 @@ SigSession::SigSession(DeviceManager &device_manager) : _protocol_cnt = 0; _decoderFactory = new decoder::DecoderFactory(); ds_trigger_init(); + + _vDial_changed = false; + _hDial_changed = false; + _dso_ctrl_channel = 0; + register_hotplug_callback(); } SigSession::~SigSession() { - stop_capture(); + stop_capture(); - if (_sampling_thread.get()) - _sampling_thread->join(); - _sampling_thread.reset(); + if (_sampling_thread.get()) + _sampling_thread->join(); + _sampling_thread.reset(); - if (_hot_plug_handle) - stop_hot_plug_proc(); + if (_hotplug_handle) { + stop_hotplug_proc(); + deregister_hotplug_callback(); + } ds_trigger_destroy(); + stop_dso_ctrl_proc(); // TODO: This should not be necessary _session = NULL; @@ -114,15 +124,18 @@ int SigSession::set_device(struct sr_dev_inst *sdi) { int ret = SR_ERR; - if (sdi) + if (_sdi == NULL) { ret = _device_manager.use_device(sdi, this); - if (ret == SR_OK && (sdi != _sdi) && _sdi) { - _device_manager.release_device(_sdi); - } - if (ret == SR_OK) _sdi = sdi; - - set_capture_state(Init); + set_capture_state(Init); + } else if (sdi != _sdi) { + ret = _device_manager.use_device(sdi, this); + _device_manager.release_device(_sdi); + _sdi = sdi; + set_capture_state(Init); + } else { + ret = SR_OK; + } return ret; } @@ -137,12 +150,25 @@ void SigSession::release_device(struct sr_dev_inst *sdi) void SigSession::save_file(const std::string &name){ if (_sdi->mode == LOGIC) { - const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots = + const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots = _logic_data->get_snapshots(); if (snapshots.empty()) return; - const shared_ptr<pv::data::LogicSnapshot> &snapshot = + const boost::shared_ptr<pv::data::LogicSnapshot> &snapshot = + snapshots.front(); + + sr_session_save(name.c_str(), _sdi, + (unsigned char*)snapshot->get_data(), + snapshot->get_unit_size(), + snapshot->get_sample_count()); + } else if (_sdi->mode == DSO){ + const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots = + _dso_data->get_snapshots(); + if (snapshots.empty()) + return; + + const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot = snapshots.front(); sr_session_save(name.c_str(), _sdi, @@ -150,12 +176,12 @@ void SigSession::save_file(const std::string &name){ snapshot->get_unit_size(), snapshot->get_sample_count()); } else { - const deque< shared_ptr<pv::data::AnalogSnapshot> > &snapshots = + const deque< boost::shared_ptr<pv::data::AnalogSnapshot> > &snapshots = _analog_data->get_snapshots(); if (snapshots.empty()) return; - const shared_ptr<pv::data::AnalogSnapshot> &snapshot = + const boost::shared_ptr<pv::data::AnalogSnapshot> &snapshot = snapshots.front(); sr_session_save(name.c_str(), _sdi, @@ -166,7 +192,7 @@ void SigSession::save_file(const std::string &name){ } void SigSession::load_file(const string &name, - function<void (const QString)> error_handler) + boost::function<void (const QString)> error_handler) { stop_capture(); _sampling_thread.reset(new boost::thread( @@ -176,12 +202,12 @@ void SigSession::load_file(const string &name, SigSession::capture_state SigSession::get_capture_state() const { - lock_guard<mutex> lock(_sampling_mutex); + boost::lock_guard<boost::mutex> lock(_sampling_mutex); return _capture_state; } void SigSession::start_capture(uint64_t record_length, - function<void (const QString)> error_handler) + boost::function<void (const QString)> error_handler) { stop_capture(); @@ -199,12 +225,28 @@ void SigSession::start_capture(uint64_t record_length, if (probe->enabled) break; } - if (!l) { error_handler(tr("No probes enabled.")); return; } + // Check that at least one signal channel is active under DSO mode + if (_sdi->mode == DSO) { + bool active = false; + BOOST_FOREACH(const shared_ptr<view::Signal> s, _signals) + { + assert(s); + if (s->get_active()) { + active = true; + break; + } + } + if (!active) { + error_handler(tr("No channels enabled.")); + return; + } + } + // Begin the session _sampling_thread.reset(new boost::thread( &SigSession::sample_thread_proc, this, _sdi, @@ -215,7 +257,6 @@ void SigSession::stop_capture() { if (get_capture_state() == Stopped) return; - sr_session_stop(); // Check that sampling stopped @@ -224,15 +265,15 @@ void SigSession::stop_capture() _sampling_thread.reset(); } -vector< shared_ptr<view::Signal> > SigSession::get_signals() +vector< boost::shared_ptr<view::Signal> > SigSession::get_signals() { - lock_guard<mutex> lock(_signals_mutex); + boost::lock_guard<boost::mutex> lock(_signals_mutex); return _signals; } -vector< shared_ptr<view::Signal> > SigSession::get_pro_signals() +vector< boost::shared_ptr<view::Signal> > SigSession::get_pro_signals() { - lock_guard<mutex> lock(_signals_mutex); + boost::lock_guard<boost::mutex> lock(_signals_mutex); return _protocol_signals; } @@ -255,6 +296,24 @@ int SigSession::get_logic_probe_cnt(const sr_dev_inst *sdi) return logic_probe_cnt; } +int SigSession::get_dso_probe_cnt(const sr_dev_inst *sdi) +{ + unsigned int dso_probe_cnt = 0; + for (const GSList *l = sdi->probes; l; l = l->next) { + const sr_probe *const probe = (const sr_probe *)l->data; + if (!probe->enabled) + continue; + + switch(probe->type) { + case SR_PROBE_DSO: + dso_probe_cnt++; + break; + } + } + + return dso_probe_cnt; +} + int SigSession::get_analog_probe_cnt(const sr_dev_inst *sdi) { unsigned int analog_probe_cnt = 0; @@ -281,24 +340,36 @@ boost::shared_ptr<data::Logic> SigSession::get_data() void* SigSession::get_buf(int& unit_size, uint64_t &length) { if (_sdi->mode == LOGIC) { - const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots = + const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots = _logic_data->get_snapshots(); if (snapshots.empty()) return NULL; - const shared_ptr<pv::data::LogicSnapshot> &snapshot = + const boost::shared_ptr<pv::data::LogicSnapshot> &snapshot = + snapshots.front(); + + unit_size = snapshot->get_unit_size(); + length = snapshot->get_sample_count(); + return snapshot->get_data(); + } else if (_sdi->mode == DSO) { + const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots = + _dso_data->get_snapshots(); + if (snapshots.empty()) + return NULL; + + const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot = snapshots.front(); unit_size = snapshot->get_unit_size(); length = snapshot->get_sample_count(); return snapshot->get_data(); } else { - const deque< shared_ptr<pv::data::AnalogSnapshot> > &snapshots = + const deque< boost::shared_ptr<pv::data::AnalogSnapshot> > &snapshots = _analog_data->get_snapshots(); if (snapshots.empty()) return NULL; - const shared_ptr<pv::data::AnalogSnapshot> &snapshot = + const boost::shared_ptr<pv::data::AnalogSnapshot> &snapshot = snapshots.front(); unit_size = snapshot->get_unit_size(); @@ -309,14 +380,14 @@ void* SigSession::get_buf(int& unit_size, uint64_t &length) void SigSession::set_capture_state(capture_state state) { - lock_guard<mutex> lock(_sampling_mutex); + boost::lock_guard<boost::mutex> lock(_sampling_mutex); _capture_state = state; data_updated(); capture_state_changed(state); } void SigSession::load_thread_proc(const string name, - function<void (const QString)> error_handler) + boost::function<void (const QString)> error_handler) { if (sr_session_load(name.c_str()) != SR_OK) { error_handler(tr("Failed to load file.")); @@ -339,79 +410,79 @@ void SigSession::load_thread_proc(const string name, // Confirm that SR_DF_END was received assert(!_cur_logic_snapshot); + assert(!_cur_dso_snapshot); assert(!_cur_analog_snapshot); } void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, uint64_t record_length, - function<void (const QString)> error_handler) + boost::function<void (const QString)> error_handler) { -// while(1) { - assert(sdi); - assert(error_handler); - - if (!_adv_trigger) { - /* simple trigger check trigger_enable */ - ds_trigger_set_en(false); - BOOST_FOREACH(const shared_ptr<view::Signal> s, _signals) - { - assert(s); - if (s->get_trig() != 0) { - ds_trigger_set_en(true); - s->set_trig(s->get_trig()); - } - } - } else { - /* advanced trigger check trigger_enable */ - ds_trigger_set_en(true); - } + assert(sdi); + assert(error_handler); - sr_session_new(); - sr_session_datafeed_callback_add(data_feed_in_proc, NULL); - - if (sr_session_dev_add(sdi) != SR_OK) { - error_handler(tr("Failed to use device.")); - sr_session_destroy(); - return; - } - - // Set the sample limit - if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(record_length)) != SR_OK) { - error_handler(tr("Failed to configure " - "time-based sample limit.")); - sr_session_destroy(); - return; + if (!_adv_trigger) { + /* simple trigger check trigger_enable */ + ds_trigger_set_en(false); + BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals) + { + assert(s); + if (s->get_trig() != 0) { + ds_trigger_set_en(true); + s->set_trig(s->get_trig()); + } } + } else { + /* advanced trigger check trigger_enable */ + ds_trigger_set_en(true); + } - receive_data(0); - set_capture_state(Running); + sr_session_new(); + sr_session_datafeed_callback_add(data_feed_in_proc, NULL); - if (sr_session_start() != SR_OK) { - error_handler(tr("Failed to start session.")); - set_capture_state(Stopped); - return; - } + if (sr_session_dev_add(sdi) != SR_OK) { + error_handler(tr("Failed to use device.")); + sr_session_destroy(); + return; + } - sr_session_run(); + // Set the sample limit + if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, + g_variant_new_uint64(record_length)) != SR_OK) { + error_handler(tr("Failed to configure " + "time-based sample limit.")); sr_session_destroy(); + return; + } + + receive_data(0); + set_capture_state(Running); + if (sr_session_start() != SR_OK) { + error_handler(tr("Failed to start session.")); set_capture_state(Stopped); + return; + } - // Confirm that SR_DF_END was received - assert(!_cur_logic_snapshot); - assert(!_cur_analog_snapshot); + sr_session_run(); + sr_session_destroy(); -// g_usleep(3000*1000); -// } + set_capture_state(Stopped); + + // Confirm that SR_DF_END was received + assert(!_cur_logic_snapshot); + assert(!_cur_dso_snapshot); + assert(!_cur_analog_snapshot); } void SigSession::feed_in_header(const sr_dev_inst *sdi) { - shared_ptr<view::Signal> signal; + boost::shared_ptr<view::Signal> signal; GVariant *gvar; uint64_t sample_rate = 0; unsigned int logic_probe_count = 0; + unsigned int dso_probe_count = 0; + unsigned int dso_channel_count = 0; unsigned int analog_probe_count = 0; // Detect what data types we will receive @@ -425,6 +496,10 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) logic_probe_count++; break; + case SR_PROBE_DSO: + dso_probe_count++; + break; + case SR_PROBE_ANALOG: analog_probe_count++; break; @@ -443,24 +518,39 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) sample_rate = g_variant_get_uint64(gvar); g_variant_unref(gvar); - ret = sr_config_get(sdi->driver, SR_CONF_LIMIT_SAMPLES, - &gvar, sdi); - if (ret != SR_OK) { - qDebug("Failed to get total samples"); - return; - } - if (g_variant_get_uint64(gvar) != 0) - _total_sample_len = g_variant_get_uint64(gvar); - g_variant_unref(gvar); +// ret = sr_config_get(sdi->driver, SR_CONF_LIMIT_SAMPLES, +// &gvar, sdi); +// if (ret != SR_OK) { +// qDebug("Failed to get total samples"); +// return; +// } +// if (g_variant_get_uint64(gvar) != 0) +// _total_sample_len = g_variant_get_uint64(gvar); +// g_variant_unref(gvar); if (sample_rate != _last_sample_rate) { _last_sample_rate = sample_rate; sample_rate_changed(sample_rate); } + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of DSO channel 0\n"); + return; + } + dso_channel_count += g_variant_get_boolean(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of DSO channel 1\n"); + return; + } + dso_channel_count += g_variant_get_boolean(gvar); + // Create data containers for the coming data snapshots { - lock_guard<mutex> data_lock(_data_mutex); + boost::lock_guard<boost::mutex> data_lock(_data_mutex); if (logic_probe_count != 0) { _logic_data.reset(new data::Logic( @@ -471,6 +561,11 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) assert(_group_data); } + if (dso_probe_count != 0) { + _dso_data.reset(new data::Dso(dso_channel_count, sample_rate)); + assert(_dso_data); + } + if (analog_probe_count != 0) { _analog_data.reset(new data::Analog(analog_probe_count, sample_rate)); assert(_analog_data); @@ -479,10 +574,10 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) // Set Signal data { - BOOST_FOREACH(const shared_ptr<view::Signal> s, _signals) + BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals) { assert(s); - s->set_data(_logic_data, _analog_data, _group_data); + s->set_data(_logic_data, _dso_data, _analog_data, _group_data); } receive_data(0); @@ -503,7 +598,7 @@ void SigSession::add_group() if (probe_index_list.size() > 1) { //_group_data.reset(new data::Group(_last_sample_rate)); - const shared_ptr<view::Signal> signal = shared_ptr<view::Signal>( + const boost::shared_ptr<view::Signal> signal = boost::shared_ptr<view::Signal>( new view::GroupSignal("New Group", _group_data, probe_index_list, _signals.size(), _group_cnt)); _signals.push_back(signal); @@ -513,7 +608,7 @@ void SigSession::add_group() if (!_cur_group_snapshot) { // Create a new data snapshot - _cur_group_snapshot = shared_ptr<data::GroupSnapshot>( + _cur_group_snapshot = boost::shared_ptr<data::GroupSnapshot>( new data::GroupSnapshot(_logic_data->get_snapshots().front(), signal->get_index_list())); //_cur_group_snapshot->append_payload(); _group_data->push_snapshot(_cur_group_snapshot); @@ -572,7 +667,7 @@ void SigSession::add_protocol(std::list<int> probe_index_list, decoder::Decoder if (probe_index_list.size() > 0) { //_group_data.reset(new data::Group(_last_sample_rate)); - const shared_ptr<view::Signal> signal = shared_ptr<view::Signal>( + const boost::shared_ptr<view::Signal> signal = boost::shared_ptr<view::Signal>( new view::ProtocolSignal(decoder->get_decode_name(), _logic_data, decoder, probe_index_list, 0, _protocol_cnt)); _signals.push_back(signal); @@ -627,11 +722,18 @@ void SigSession::del_signal(std::vector< boost::shared_ptr<view::Signal> >::iter void SigSession::init_signals(const sr_dev_inst *sdi) { - shared_ptr<view::Signal> signal; + boost::shared_ptr<view::Signal> signal; GVariant *gvar; uint64_t sample_rate = 0; unsigned int logic_probe_count = 0; + unsigned int dso_probe_count = 0; + unsigned int dso_channel_count = 0; unsigned int analog_probe_count = 0; + uint64_t vdiv; + uint64_t timebase; + bool coupling; + bool active; + int ret; // Detect what data types we will receive for (const GSList *l = sdi->probes; l; l = l->next) { @@ -644,6 +746,10 @@ void SigSession::init_signals(const sr_dev_inst *sdi) logic_probe_count++; break; + case SR_PROBE_DSO: + dso_probe_count++; + break; + case SR_PROBE_ANALOG: analog_probe_count++; break; @@ -653,21 +759,34 @@ void SigSession::init_signals(const sr_dev_inst *sdi) // Read out the sample rate assert(sdi->driver); - const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, + ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, &gvar, sdi); if (ret != SR_OK) { qDebug("Failed to get samplerate\n"); return; } - sample_rate = g_variant_get_uint64(gvar); - g_variant_unref(gvar); if (sample_rate != _last_sample_rate) { _last_sample_rate = sample_rate; sample_rate_changed(sample_rate); } + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of DSO channel 0\n"); + return; + } + dso_channel_count += g_variant_get_boolean(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of DSO channel 1\n"); + return; + } + dso_channel_count += g_variant_get_boolean(gvar); + // Create data containers for the coming data snapshots { if (logic_probe_count != 0) { @@ -680,6 +799,11 @@ void SigSession::init_signals(const sr_dev_inst *sdi) _group_cnt = 0; } + if (dso_probe_count != 0) { + _dso_data.reset(new data::Dso(dso_channel_count, sample_rate)); + assert(_dso_data); + } + if (analog_probe_count != 0) { _analog_data.reset(new data::Analog(analog_probe_count, sample_rate)); assert(_analog_data); @@ -699,13 +823,78 @@ void SigSession::init_signals(const sr_dev_inst *sdi) switch(probe->type) { case SR_PROBE_LOGIC: - signal = shared_ptr<view::Signal>( + signal = boost::shared_ptr<view::Signal>( new view::LogicSignal(probe->name, _logic_data, probe->index, _signals.size())); break; + case SR_PROBE_DSO: + if (probe->index == 0) { + ret = sr_config_get(sdi->driver, SR_CONF_VDIV0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get VDIV of channel 0\n"); + return; + } + vdiv = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_TIMEBASE, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get TIMEBASE\n"); + return; + } + timebase = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_COUPLING0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get AC COUPLING of channel 0\n"); + return; + } + coupling = g_variant_get_boolean(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of channel 0\n"); + return; + } + active = g_variant_get_boolean(gvar); + } else if (probe->index == 1) { + ret = sr_config_get(sdi->driver, SR_CONF_VDIV1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get VDIV of channel 1\n"); + return; + } + vdiv = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_TIMEBASE, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get TIMEBASE\n"); + return; + } + timebase = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_COUPLING1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get AC COUPLING of channel 1\n"); + return; + } + coupling = g_variant_get_boolean(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of channel 1\n"); + return; + } + active = g_variant_get_boolean(gvar); + } + signal = boost::shared_ptr<view::Signal>( + new view::DsoSignal(probe->name, + _dso_data, probe->index, _signals.size(), vdiv, timebase, coupling, active)); + break; + case SR_PROBE_ANALOG: - signal = shared_ptr<view::Signal>( + signal = boost::shared_ptr<view::Signal>( new view::AnalogSignal(probe->name, _analog_data, probe->index, _signals.size())); break; @@ -716,19 +905,27 @@ void SigSession::init_signals(const sr_dev_inst *sdi) signals_changed(); data_updated(); } + g_variant_unref(gvar); } void SigSession::update_signals(const sr_dev_inst *sdi) { - shared_ptr<view::Signal> signal; + boost::shared_ptr<view::Signal> signal; QMap<int, bool> probes_en_table; QMap<int, bool> signals_en_table; int index = 0; + GVariant *gvar; + uint64_t vdiv; + uint64_t timebase; + bool coupling; + bool active; + int ret; std::vector< boost::shared_ptr<view::Signal> >::iterator i = _signals.begin(); while (i != _signals.end()) { if (((*i)->get_type() == view::Signal::DS_LOGIC || - (*i)->get_type() == view::Signal::DS_ANALOG)) + (*i)->get_type() == view::Signal::DS_DSO || + (*i)->get_type() == view::Signal::DS_ANALOG)) signals_en_table.insert((*i)->get_index(), 1); i++; } @@ -748,13 +945,78 @@ void SigSession::update_signals(const sr_dev_inst *sdi) switch(probe->type) { case SR_PROBE_LOGIC: - signal = shared_ptr<view::Signal>( + signal = boost::shared_ptr<view::Signal>( new view::LogicSignal(probe->name, _logic_data, probe->index, 0)); break; + case SR_PROBE_DSO: + if (probe->index == 0) { + ret = sr_config_get(sdi->driver, SR_CONF_VDIV0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get VDIV of channel 0\n"); + return; + } + vdiv = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_TIMEBASE, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get TIMEBASE\n"); + return; + } + timebase = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_COUPLING0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get AC COUPLING of channel 0\n"); + return; + } + coupling = g_variant_get_boolean(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH0, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of channel 0\n"); + return; + } + active = g_variant_get_boolean(gvar); + } else if (probe->index == 1) { + ret = sr_config_get(sdi->driver, SR_CONF_VDIV1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get VDIV of channel 1\n"); + return; + } + vdiv = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_TIMEBASE, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get TIMEBASE\n"); + return; + } + timebase = g_variant_get_uint64(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_COUPLING1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get AC COUPLING of channel 1\n"); + return; + } + coupling = g_variant_get_boolean(gvar); + ret = sr_config_get(sdi->driver, SR_CONF_EN_CH1, + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get ENABLE of channel 1\n"); + return; + } + active = g_variant_get_boolean(gvar); + } + signal = boost::shared_ptr<view::Signal>( + new view::DsoSignal(probe->name, + _dso_data, probe->index, _signals.size(), vdiv, timebase, coupling, active)); + break; + case SR_PROBE_ANALOG: - signal = shared_ptr<view::Signal>( + signal = boost::shared_ptr<view::Signal>( new view::AnalogSignal(probe->name, _analog_data, probe->index, 0)); break; @@ -767,7 +1029,8 @@ void SigSession::update_signals(const sr_dev_inst *sdi) i = _signals.begin(); while (i != _signals.end()) { if (((*i)->get_type() == view::Signal::DS_LOGIC || - (*i)->get_type() == view::Signal::DS_ANALOG) && + (*i)->get_type() == view::Signal::DS_DSO || + (*i)->get_type() == view::Signal::DS_ANALOG) && probes_en_table.value((*i)->get_index()) == false) { std::vector< boost::shared_ptr<view::Signal> >::iterator j = _signals.begin(); while(j != _signals.end()) { @@ -813,7 +1076,7 @@ void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) void SigSession::feed_in_logic(const sr_datafeed_logic &logic) { - lock_guard<mutex> lock(_data_mutex); + boost::lock_guard<boost::mutex> lock(_data_mutex); if (!_logic_data) { @@ -828,7 +1091,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) if (!_cur_logic_snapshot) { // Create a new data snapshot - _cur_logic_snapshot = shared_ptr<data::LogicSnapshot>( + _cur_logic_snapshot = boost::shared_ptr<data::LogicSnapshot>( new data::LogicSnapshot(logic, _total_sample_len, 1)); if (_cur_logic_snapshot->buf_null()) stop_capture(); @@ -845,9 +1108,39 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) //data_updated(); } +void SigSession::feed_in_dso(const sr_datafeed_dso &dso) +{ + boost::lock_guard<boost::mutex> lock(_data_mutex); + + if(!_dso_data) + { + qDebug() << "Unexpected dso packet"; + return; // This dso packet was not expected. + } + + if (!_cur_dso_snapshot) + { + // Create a new data snapshot + _cur_dso_snapshot = boost::shared_ptr<data::DsoSnapshot>( + new data::DsoSnapshot(dso, _total_sample_len, _dso_data->get_num_probes())); + if (_cur_dso_snapshot->buf_null()) + stop_capture(); + else + _dso_data->push_snapshot(_cur_dso_snapshot); + } + else + { + // Append to the existing data snapshot + _cur_dso_snapshot->append_payload(dso); + } + + receive_data(dso.num_samples); + data_updated(); +} + void SigSession::feed_in_analog(const sr_datafeed_analog &analog) { - lock_guard<mutex> lock(_data_mutex); + boost::lock_guard<boost::mutex> lock(_data_mutex); if(!_analog_data) { @@ -858,7 +1151,7 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) if (!_cur_analog_snapshot) { // Create a new data snapshot - _cur_analog_snapshot = shared_ptr<data::AnalogSnapshot>( + _cur_analog_snapshot = boost::shared_ptr<data::AnalogSnapshot>( new data::AnalogSnapshot(analog, _total_sample_len, _analog_data->get_num_probes())); if (_cur_analog_snapshot->buf_null()) stop_capture(); @@ -902,6 +1195,11 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, feed_in_logic(*(const sr_datafeed_logic*)packet->payload); break; + case SR_DF_DSO: + assert(packet->payload); + feed_in_dso(*(const sr_datafeed_dso*)packet->payload); + break; + case SR_DF_ANALOG: assert(packet->payload); feed_in_analog(*(const sr_datafeed_analog*)packet->payload); @@ -910,12 +1208,12 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, case SR_DF_END: { { - lock_guard<mutex> lock(_data_mutex); - BOOST_FOREACH(const shared_ptr<view::Signal> s, _signals) + boost::lock_guard<boost::mutex> lock(_data_mutex); + BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals) { assert(s); if (s->get_type() == view::Signal::DS_GROUP) { - _cur_group_snapshot = shared_ptr<data::GroupSnapshot>( + _cur_group_snapshot = boost::shared_ptr<data::GroupSnapshot>( new data::GroupSnapshot(_logic_data->get_snapshots().front(), s->get_index_list())); //_cur_group_snapshot->append_payload(); _group_data->push_snapshot(_cur_group_snapshot); @@ -926,6 +1224,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, } } _cur_logic_snapshot.reset(); + _cur_dso_snapshot.reset(); _cur_analog_snapshot.reset(); } break; @@ -975,7 +1274,7 @@ void SigSession::rst_protocol_analyzer(int rst_index, std::list <int > _sel_prob if (_logic_data) _decoders.at(rst_index).first->recode(_sel_probes, _options, _options_index); - BOOST_FOREACH(const shared_ptr<view::Signal> s, _signals) + BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals) { assert(s); if (s->get_decoder() == _decoders.at(rst_index).first) { @@ -992,7 +1291,7 @@ void SigSession::rst_protocol_analyzer(int rst_index, std::list <int > _sel_prob void SigSession::del_protocol_analyzer(int protocol_index) { assert(protocol_index < _decoders.size()); - delete (_decoders.at(protocol_index)).first; + //delete (_decoders.at(protocol_index)).first; // BOOST_FOREACH(const int _index, (_decoders.at(protocol_index)).second) { // _signals.at(_index)->del_decoder(); @@ -1019,64 +1318,50 @@ QMap<QString, int> SigSession::get_decode_options_index(int decode_index) /* * hotplug function */ -void SigSession::start_hot_plug_proc(boost::function<void (const QString)> error_handler) -{ -#ifdef HAVE_LA_DSLOGIC - if (_hot_plug_handle) { - error_handler("Hotplug proc have started!"); - return; - } +int SigSession::hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev, + libusb_hotplug_event event, void *user_data) { - int ret = libusbhp_init(&_hot_plug_handle); - if(ret != 0) { - error_handler("Could not initialize hotplug handle."); - return; - } + (void)ctx; + (void)dev; + (void)user_data; - libusbhp_register_hotplug_listeners(_hot_plug_handle, - dev_attach_callback, - dev_detach_callback, - NULL); + if (LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED == event) { + _session->_hot_attach = true; + qDebug("DSLogic attaced!\n"); + }else if (LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT == event) { + _session->_hot_detach = true; + qDebug("DSLogic dettaced!\n"); + }else{ + qDebug("Unhandled event %d\n", event); + } - // Begin the session - _hot_plug.reset(new boost::thread( - &SigSession::hot_plug_proc, this, error_handler)); -#else - error_handler("No hotplug device."); -#endif + return 0; } -void SigSession::stop_hot_plug_proc() +void SigSession::hotplug_proc(boost::function<void (const QString)> error_handler) { -#ifdef HAVE_LA_DSLOGIC - if (_hot_plug.get()) { - _hot_plug->interrupt(); - _hot_plug->join(); - } - _hot_plug.reset(); + struct timeval tv; - if(_hot_plug_handle) { - libusbhp_exit(_hot_plug_handle); - _hot_plug_handle = NULL; - } -#endif -} + (void)error_handler; -void SigSession::hot_plug_proc(boost::function<void (const QString)> error_handler) -{ if (!_sdi) return; + tv.tv_sec = tv.tv_usec = 0; try { while(_session) { + libusb_handle_events_timeout(NULL, &tv); if (_hot_attach) { + qDebug("DSLogic hardware attached!"); device_attach(); _hot_attach = false; break; } if (_hot_detach) { + qDebug("DSLogic hardware detached!"); device_detach(); _logic_data.reset(); + _dso_data.reset(); _analog_data.reset(); _hot_detach = false; break; @@ -1085,39 +1370,51 @@ void SigSession::hot_plug_proc(boost::function<void (const QString)> error_handl } } catch(...) { qDebug("Interrupt exception for hotplug thread was thrown."); - error_handler("Interrupt exception for hotplug thread was thrown."); } qDebug("Hotplug thread exit!"); } -void SigSession::dev_attach_callback(struct libusbhp_device_t *device, void *user_data) +void SigSession::register_hotplug_callback() { - (void)user_data; - - if (device) - qDebug("Attach: (%04x/%04x)", device->idVendor, device->idProduct); + int ret; + + ret = libusb_hotplug_register_callback(NULL, (libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), + (libusb_hotplug_flag)LIBUSB_HOTPLUG_ENUMERATE, 0x2A0E, 0x0001, + LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, NULL, + &_hotplug_handle); + if (LIBUSB_SUCCESS != ret){ + qDebug() << "Error creating a hotplug callback\n"; + } +} - _session->_hot_attach = true; +void SigSession::deregister_hotplug_callback() +{ + libusb_hotplug_deregister_callback(NULL, _hotplug_handle); } -void SigSession::dev_detach_callback(struct libusbhp_device_t *device, void *user_data) +void SigSession::start_hotplug_proc(boost::function<void (const QString)> error_handler) { - (void)user_data; - if (device) - qDebug("Detach: (%04x/%04x)", device->idVendor, device->idProduct); + // Begin the session + qDebug() << "Starting a hotplug thread...\n"; + _hot_attach = false; + _hot_detach = false; + _hotplug.reset(new boost::thread( + &SigSession::hotplug_proc, this, error_handler)); - _session->_hot_detach = true; } -int SigSession::hot_plug_active() +void SigSession::stop_hotplug_proc() { - if (_hot_plug_handle) - return 1; - else - return 0; + if (_hotplug.get()) { + _hotplug->interrupt(); + _hotplug->join(); + } + _hotplug.reset(); } + /* * Tigger */ @@ -1126,4 +1423,92 @@ void SigSession::set_adv_trigger(bool adv_trigger) _adv_trigger = adv_trigger; } + +/* + * oscilloscope control + */ +void SigSession::start_dso_ctrl_proc(boost::function<void (const QString)> error_handler) +{ + + // Begin the dso control thread + _dso_ctrl_thread.reset(new boost::thread( + &SigSession::dso_ctrl_proc, this, error_handler)); + +} + +void SigSession::stop_dso_ctrl_proc() +{ + + if (_dso_ctrl_thread.get()) { + _dso_ctrl_thread->interrupt(); + _dso_ctrl_thread->join(); + } + _dso_ctrl_thread.reset(); +} + +int SigSession::set_dso_ctrl(int key) +{ + int ret; + + if (key== SR_CONF_TIMEBASE) { + uint64_t timebase = _signals.at(0)->get_hDialValue(); + ret = sr_config_set(_sdi, key, g_variant_new_uint64(timebase)); + } else if (key == SR_CONF_VDIV0) { + uint64_t vdiv = _signals.at(0)->get_vDialValue(); + ret = sr_config_set(_sdi, key, g_variant_new_uint64(vdiv)); + } else if (key == SR_CONF_VDIV1) { + uint64_t vdiv = _signals.at(1)->get_vDialValue(); + ret = sr_config_set(_sdi, key, g_variant_new_uint64(vdiv)); + } else if (key == SR_CONF_COUPLING0) { + bool acdc = _signals.at(0)->get_acCoupling(); + ret = sr_config_set(_sdi, key, g_variant_new_boolean(acdc)); + } else if (key == SR_CONF_COUPLING1) { + bool acdc = _signals.at(1)->get_acCoupling(); + ret = sr_config_set(_sdi, key, g_variant_new_boolean(acdc)); + } else if (key == SR_CONF_EN_CH0) { + bool enable = _signals.at(0)->get_active(); + ret = sr_config_set(_sdi, key, g_variant_new_boolean(enable)); + dso_ch_changed(get_dso_ch_num()); + } else if (key == SR_CONF_EN_CH1) { + bool enable = _signals.at(1)->get_active(); + ret = sr_config_set(_sdi, key, g_variant_new_boolean(enable)); + dso_ch_changed(get_dso_ch_num()); + } + + return ret; +} + +uint16_t SigSession::get_dso_ch_num() +{ + uint16_t num_channels = 0; + BOOST_FOREACH(const shared_ptr<view::Signal> s, _signals) + { + assert(s); + if (s->get_active()) { + num_channels++; + } + } + return num_channels; +} + +void SigSession::dso_ctrl_proc(boost::function<void (const QString)> error_handler) +{ + (void)error_handler; + try { + while(_session) { + if (!_sdi) { + // do nothing + } else if (strcmp(_sdi->driver->name, "Demo") == 0) { + + } else if (strcmp(_sdi->driver->name, "DSLogic") == 0) { + + } + boost::this_thread::sleep(boost::posix_time::millisec(100)); + } + } catch(...) { + qDebug("Interrupt exception for oscilloscope control thread was thrown."); + } + qDebug("Oscilloscope control thread exit!"); +} + } // namespace pv |