2
0
forked from Ivasoft/DSView

Code refactoring 15

This commit is contained in:
dreamsourcelabTAI
2022-08-26 13:41:57 +08:00
parent cb08ca65ef
commit 6f14f1fd53
14 changed files with 467 additions and 472 deletions

View File

@@ -92,6 +92,7 @@ void AnalogSnapshot::clear()
free_data();
free_envelop();
init_all();
_have_data = false;
}
void AnalogSnapshot::first_payload(const sr_datafeed_analog &analog, uint64_t total_sample_count, GSList *channels)
@@ -173,6 +174,8 @@ void AnalogSnapshot::append_payload(
// Generate the first mip-map from the data
if (analog.num_samples != 0) // guarantee new samples to compute
append_payload_to_envelope_levels();
_have_data = true;
}
void AnalogSnapshot::append_data(void *data, uint64_t samples, uint16_t pitch)

View File

@@ -95,6 +95,7 @@ void DsoSnapshot::clear()
free_data();
free_envelop();
init_all();
_have_data = false;
}
void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sample_count,
@@ -166,6 +167,8 @@ void DsoSnapshot::append_payload(const sr_datafeed_dso &dso)
// Generate the first mip-map from the data
if (_envelope_en)
append_payload_to_envelope_levels(dso.samplerate_tog);
_have_data = true;
}
}

View File

@@ -99,6 +99,7 @@ void LogicSnapshot::clear()
std::lock_guard<std::mutex> lock(_mutex);
free_data();
init_all();
_have_data = false;
}
void LogicSnapshot::capture_ended()
@@ -228,6 +229,8 @@ void LogicSnapshot::append_payload(const sr_datafeed_logic &logic)
append_cross_payload(logic);
else if (logic.format == LA_SPLIT_DATA)
append_split_payload(logic);
_have_data = true;
}
void LogicSnapshot::append_cross_payload(const sr_datafeed_logic &logic)

View File

@@ -43,6 +43,7 @@ Snapshot::Snapshot(int unit_size, uint64_t total_sample_count, unsigned int chan
assert(_unit_size > 0);
_unit_bytes = 1;
_unit_pitch = 0;
_have_data = false;
}
Snapshot::~Snapshot()

View File

@@ -73,11 +73,15 @@ public:
return _channel_num;
}
inline bool have_data(){
return _have_data;
}
virtual void capture_ended();
virtual bool has_data(int index) = 0;
virtual int get_block_num() = 0;
virtual uint64_t get_block_size(int block_index) = 0;
virtual uint64_t get_real_sample_count() = 0;
protected:
virtual void free_data();
@@ -106,6 +110,7 @@ protected:
uint16_t _unit_pitch;
bool _memory_failed;
bool _last_ended;
bool _have_data;
};
} // namespace data

View File

@@ -167,7 +167,7 @@ double DeviceAgent::get_sample_time()
return sample_time;
}
const GSList* DeviceAgent::get_dev_mode_list()
const GSList* DeviceAgent::get_device_mode_list()
{
assert(_dev_handle);
return ds_get_actived_device_mode_list();
@@ -202,3 +202,108 @@ bool DeviceAgent::stop()
return false;
}
bool DeviceAgent::have_enabled_channel()
{
assert(_dev_handle);
return ds_channel_is_enabled() > 0;
}
bool DeviceAgent::get_status(struct sr_status &status, gboolean prg)
{
assert(_dev_handle);
if (ds_get_actived_device_status(&status, prg) == SR_OK){
return true;
}
return false;
}
//---------------device config-----------/
int DeviceAgent::get_work_mode()
{
return ds_get_actived_device_mode();
}
bool DeviceAgent::get_device_info(struct ds_device_info &info)
{
if (ds_get_actived_device_info(&info) == SR_OK){
return info.handle != NULL;
}
return false;
}
bool DeviceAgent::get_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant **data)
{
if (ds_get_actived_device_config(ch, cg, key, data) == SR_OK){
return true;
}
return false;
}
bool DeviceAgent::set_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant *data)
{
if (ds_set_actived_device_config(ch, cg, key, data) == SR_OK){
return true;
}
return false;
}
bool DeviceAgent::get_device_config_list(const struct sr_channel_group *cg,
int key, GVariant **data)
{
if (ds_get_actived_device_config_list(cg, key, data) == SR_OK){
return true;
}
return false;
}
const struct sr_config_info* DeviceAgent::get_device_config_info(int key)
{
return ds_get_actived_device_config_info(key);
}
const struct sr_config_info* DeviceAgent::get_device_config_info_by_name(const char *optname)
{
return ds_get_actived_device_config_info_by_name(optname);
}
bool DeviceAgent::get_device_status(struct sr_status &status, gboolean prg)
{
if (ds_get_actived_device_status(&status, prg) == SR_OK){
return true;
}
return false;
}
struct sr_config* DeviceAgent::new_config(int key, GVariant *data)
{
return ds_new_config(key, data);
}
void DeviceAgent::free_config(struct sr_config *src)
{
ds_free_config(src);
}
bool DeviceAgent::is_collecting()
{
return ds_is_collecting() > 0;
}
GSList* DeviceAgent::get_channels()
{
assert(_dev_handle);
return ds_get_actived_device_channels();
}
//---------------device config end -----------/

View File

@@ -42,7 +42,7 @@ public:
void update();
inline bool have_instance(){
return _dev_handle != NULL;
return _dev_handle != NULL_HANDLE;
}
inline QString name(){
@@ -107,7 +107,7 @@ public:
* @return The returned device mode list from the driver, or NULL if the
* mode list could not be read.
*/
const GSList *get_dev_mode_list();
const GSList *get_device_mode_list();
/**
* Check whether the trigger exists
@@ -124,6 +124,41 @@ public:
*/
bool stop();
bool have_enabled_channel();
bool get_status(struct sr_status &status, gboolean prg);
bool is_collecting();
GSList* get_channels();
//---------------device config-----------/
public:
int get_work_mode();
bool get_device_info(struct ds_device_info &info);
bool get_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant **data);
bool set_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant *data);
bool get_device_config_list(const struct sr_channel_group *cg,
int key, GVariant **data);
const struct sr_config_info* get_device_config_info(int key);
const struct sr_config_info* get_device_config_info_by_name(const char *optname);
bool get_device_status(struct sr_status &status, gboolean prg);
struct sr_config* new_config(int key, GVariant *data);
void free_config(struct sr_config *src);
private:
ds_device_handle _dev_handle;

View File

@@ -54,7 +54,7 @@ public:
virtual void receive_header()=0;
virtual void data_received()=0;
virtual void update_device_list(struct ds_device_info *array, int count, int select_index)=0;
virtual void device_list_changed();
};

View File

@@ -1602,9 +1602,9 @@ void MainWindow::data_received(){
}
void MainWindow::update_device_list(struct ds_device_info *array, int count, int select_index)
void MainWindow::device_list_changed()
{
_sampling_bar->update_device_list(array, count, select_index);
}
} // namespace pv

View File

@@ -173,7 +173,7 @@ private:
void receive_data_len(quint64 len);
void receive_header();
void data_received();
void update_device_list(struct ds_device_info *array, int count, int select_index);
void device_list_changed();
//------private
bool gen_session_json(QJsonObject &sessionVar);

View File

@@ -125,157 +125,7 @@ SigSession::SigSession(SigSession &o)
SigSession::~SigSession()
{
}
DevInst* SigSession::get_device()
{
return _dev_inst;
}
/*
when be called, it will call 4DSL lib sr_session_new, and create a session struct in the lib
*/
void SigSession::set_device(DevInst *dev_inst)
{
// Ensure we are not capturing before setting the device
assert(dev_inst);
if (is_device_re_attach() == false){
clear_all_decoder(false);
}
else{
dsv_dbg("%s", "Keep current decoders");
}
RELEASE_ARRAY(_group_traces);
if (_dev_inst) {
_dev_inst->release();
_dev_inst = NULL;
}
_dev_inst = dev_inst;
if (_dev_inst) {
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);
}
if (_dev_inst->is_file())
dsv_info("%s\"%s\"", "Switch to file: ", dev_name.toUtf8().data());
else
dsv_info("%s\"%s\"", "Switch to device: ", dev_name.toUtf8().data());
try {
_dev_inst->use(this);
_cur_snap_samplerate = _dev_inst->get_sample_rate();
_cur_samplelimits = _dev_inst->get_sample_limit();
if (_dev_inst->dev_inst()->mode == DSO)
set_run_mode(Repetitive);
else
set_run_mode(Single);
} catch(const QString e) {
throw(e);
return;
}
sr_session_datafeed_callback_add(data_feed_callback, NULL);
_callback->device_setted();
}
}
void SigSession::set_file(QString name)
{
// Deslect the old device, because file type detection in File::create
// destorys the old session inside libsigrok.
clear_all_decoder(false);
RELEASE_ARRAY(_group_traces);
//File::create(name) will get resource, so try to release old file before
if (_dev_inst) {
sr_session_datafeed_callback_remove_all();
_dev_inst->release();
_dev_inst = NULL;
}
try {
set_device(device::File::create(name));
} catch(const QString e) {
throw(e);
return;
}
}
void SigSession::close_file(DevInst *dev_inst)
{
assert(dev_inst);
assert(_device_manager);
try {
clear_all_decoder();
dev_inst->device_updated();
set_repeating(false);
stop_capture();
capture_state_changed(SigSession::Stopped);
_device_manager->del_device(dev_inst);
} catch(const QString e) {
throw(e);
return;
}
}
void SigSession::set_default_device()
{
assert(_device_manager);
DevInst *default_device = NULL;
const std::list<DevInst*> &devices = _device_manager->devices();
if (!devices.empty()) {
// Fall back to the first device in the list.
default_device = devices.front();
// Try and find the DreamSourceLab device and select that by default
for (DevInst *dev : devices)
if (dev->dev_inst() && !dev->name().contains("virtual")) {
default_device = dev;
break;
}
}
if (default_device != NULL){
try {
set_device(default_device);
} catch(const QString e) {
_callback->show_error(e);
return;
}
}
}
void SigSession::release_device(DevInst *dev_inst)
{
if (_dev_inst == NULL)
return;
assert(dev_inst);
assert(get_capture_state() != Running);
_dev_inst = NULL;
}
SigSession::capture_state SigSession::get_capture_state()
{
std::lock_guard<std::mutex> lock(_sampling_mutex);
@@ -290,8 +140,8 @@ uint64_t SigSession::cur_samplelimits()
uint64_t SigSession::cur_samplerate()
{
// samplerate for current viewport
if (_dev_inst->dev_inst()->mode == DSO)
return _dev_inst->get_sample_rate();
if (_device_agent.get_work_mode() == DSO)
return _device_agent.get_sample_rate();
else
return cur_snap_samplerate();
}
@@ -336,7 +186,9 @@ void SigSession::set_cur_snap_samplerate(uint64_t samplerate)
// DecoderStack
for(auto &d : _decode_traces)
{
d->decoder()->set_samplerate(_cur_snap_samplerate);
}
// Math
if (_math_trace && _math_trace->enabled())
@@ -354,11 +206,11 @@ void SigSession::set_cur_samplelimits(uint64_t samplelimits)
_cur_samplelimits = samplelimits;
}
void SigSession::capture_init()
{
if (!_instant)
set_repeating(get_run_mode() == Repetitive);
// update instant setting
_dev_inst->set_config(NULL, NULL, SR_CONF_INSTANT, g_variant_new_boolean(_instant));
_callback->update_capture();
@@ -371,7 +223,7 @@ void SigSession::capture_init()
_trigger_ch = 0;
_hw_replied = false;
if (_dev_inst->dev_inst()->mode != LOGIC)
if (_device_agent.get_work_mode() != LOGIC)
_feed_timer.Start(FeedInterval);
else
_feed_timer.Stop();
@@ -440,19 +292,11 @@ void SigSession::container_init()
void SigSession::start_capture(bool instant)
{
// Check that a device instance has been selected.
if (!_dev_inst) {
if (_device_agent.have_instance() == false) {
dsv_err("%s", "No device selected");
capture_state_changed(SigSession::Stopped);
return;
}
assert(_dev_inst->dev_inst());
if (!_dev_inst->is_usable()) {
_error = Hw_err;
_callback->session_error();
capture_state_changed(SigSession::Stopped);
return;
}
// stop all decode tasks
int run_dex = 0;
@@ -469,85 +313,43 @@ void SigSession::start_capture(bool instant)
dsoSig->set_mValid(false);
}
// update setting
if (_dev_inst->name() != "virtual-session")
// update setting
if (_device_agent.isFile() == false)
_instant = instant;
else
_instant = true;
capture_init();
// Check that at least one probe is enabled
const GSList *l;
for (l = _dev_inst->dev_inst()->channels; l; l = l->next) {
sr_channel *const probe = (sr_channel*)l->data;
assert(probe);
if (probe->enabled)
break;
}
if (!l) {
if (_device_agent.have_enabled_channel() == false){
_callback->show_error("No probes enabled.");
data_updated();
set_repeating(false);
capture_state_changed(SigSession::Stopped);
return;
}
if (_sampling_thread.joinable()){
_sampling_thread.join();
}
if (sr_check_session_start_before() != 0){
assert(false);
if (_device_agent.start() == false)
{
dsv_err("%s", "Start collect error!");
}
_sampling_thread = std::thread(&SigSession::sample_thread_proc, this, _dev_inst);
}
void SigSession::sample_thread_proc(DevInst *dev_inst)
{
assert(dev_inst);
assert(dev_inst->dev_inst());
try {
dev_inst->start();
} catch(const QString e) {
_callback->show_error(e);
return;
}
receive_data(0);
set_capture_state(Running);
//session loop
dev_inst->run();
set_capture_state(Stopped);
// Confirm that SR_DF_END was received
assert(_logic_data->snapshot()->last_ended());
assert(_dso_data->snapshot()->last_ended());
assert(_analog_data->snapshot()->last_ended());
}
void SigSession::stop_capture()
{
data_unlock();
data_unlock();
if (_dev_inst){
_dev_inst->stop();
}
// Check that sampling stopped
if (_sampling_thread.joinable()){
_sampling_thread.join();
}
if (_device_agent.is_collecting()){
_device_agent.stop();
// update_collect_status_view();
}
}
bool SigSession::get_capture_status(bool &triggered, int &progress)
{
uint64_t sample_limits = cur_samplelimits();
sr_status status;
if (sr_status_get(_dev_inst->dev_inst(), &status, true) == SR_OK){
if (_device_agent.get_status(status, true)){
triggered = status.trig_hit & 0x01;
uint64_t captured_cnt = status.trig_hit >> 2;
captured_cnt = ((uint64_t)status.captured_cnt0 +
@@ -555,7 +357,7 @@ bool SigSession::get_capture_status(bool &triggered, int &progress)
((uint64_t)status.captured_cnt2 << 16) +
((uint64_t)status.captured_cnt3 << 24) +
(captured_cnt << 32));
if (_dev_inst->dev_inst()->mode == DSO)
if (_device_agent.get_work_mode() == DSO)
captured_cnt = captured_cnt * _signals.size() / get_ch_num(SR_CHANNEL_DSO);
if (triggered)
progress = (sample_limits - captured_cnt) * 100.0 / sample_limits;
@@ -701,24 +503,19 @@ void SigSession::init_signals()
unsigned int dso_probe_count = 0;
unsigned int analog_probe_count = 0;
if (is_device_re_attach() == false){
_logic_data->clear();
_dso_data->clear();
_analog_data->clear();
_group_data->clear();
_logic_data->clear();
_dso_data->clear();
_analog_data->clear();
_group_data->clear();
// Clear the decode traces
clear_all_decoder();
}
else{
dsv_info("%s", "Device loose contact, and it reconnect success.");
}
// Clear the decode traces
clear_all_decoder();
// Detect what data types we will receive
if(_dev_inst) {
assert(_dev_inst->dev_inst());
for (const GSList *l = _dev_inst->dev_inst()->channels;
l; l = l->next) {
if(_device_agent.have_instance()) {
for (const GSList *l = _device_agent.get_channels(); l; l = l->next)
{
const sr_channel *const probe = (const sr_channel *)l->data;
switch(probe->type) {
@@ -1718,14 +1515,6 @@ void SigSession::set_stop_scale(float scale)
_stop_scale = scale;
}
sr_dev_inst* SigSession::get_dev_inst_c()
{
if (_dev_inst != NULL){
return _dev_inst->dev_inst();
}
return NULL;
}
void SigSession::Open()
{
@@ -1909,65 +1698,143 @@ void SigSession::set_stop_scale(float scale)
}
_session->on_device_lib_event(event);
}
void SigSession::on_device_lib_event(int event)
{
struct ds_device_info *array = NULL;
int count = 0;
int index = -1;
if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH){
Snapshot *data = get_signal_snapshot();
if (data->get_real_sample_count() > 0)
{
if (ds_is_collecting()){
ds_stop_collect();
}
update_collect_status_view();
// Try to save current device data, and auto select the lastest device later.
_active_last_device_flag = true;
store_session_data();
return;
}
}
if (ds_get_device_list(&array, &count) != SR_OK){
dsv_err("%s", "Get device list error!");
return;
}
if (count < 1 || array == NULL){
dsv_err("%s", "Device list is empty!");
void SigSession::on_device_lib_event(int event)
{
if (event == DS_EV_COLLECT_TASK_START){
set_capture_state(Running);
return;
}
}
if (event == DS_EV_COLLECT_TASK_END){
set_capture_state(Stopped);
if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH){
index = count -1;
if (_logic_data->snapshot()->last_ended() == false){
dsv_err("%s", "The collected data is error!");
}
if (_dso_data->snapshot()->last_ended() == false){
dsv_err("%s", "The collected data is error!");
}
if (_analog_data->snapshot()->last_ended() == false){
dsv_err("%s", "The collected data is error!");
}
return;
}
if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH)
{
if (_device_agent.is_collecting())
_device_agent.stop();
update_collect_status_view();
if (have_hardware_data())
{
// Try to save current device data, and auto select the lastest device later.
_active_last_device_flag = true;
store_session_data();
return;
}
}
if (_device_agent.is_collecting())
_device_agent.stop();
if (ds_is_collecting()){
ds_stop_collect();
}
update_collect_status_view();
update_collect_status_view();
if (ds_active_device_by_index(index) != SR_OK){
dsv_err("%s", "Active device error!");
free(array);
return;
}
if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH)
{
set_default_device();
}
else if (_callback != NULL)
{
_callback->device_list_changed(); // Update list only.
}
}
init_device_view();
}
else{
index = ds_get_actived_device_index();
}
bool SigSession::set_default_device()
{
struct ds_device_info *array = NULL;
int count = 0;
_callback->update_device_list(array, count, index);
if (ds_get_device_list(&array, &count) != SR_OK)
{
dsv_err("%s", "Get device list error!");
return false;
}
if (count < 1 || array == NULL)
{
dsv_err("%s", "Device list is empty!");
return false;
}
struct ds_device_info *dev = (array + count - 1);
ds_device_handle dev_handle = dev->handle;
free(array);
bool ret = set_device(dev_handle);
if (ret && _callback != NULL){
_callback->device_list_changed();
init_device_view();
}
return ret;
}
bool SigSession::set_device(ds_device_handle dev_handle)
{
if (ds_active_device(dev_handle) != SR_OK){
dsv_err("%s", "Switch device error!");
return false;
}
_device_agent.update();
RELEASE_ARRAY(_group_traces);
clear_all_decoder();
if (_device_agent.isFile())
dsv_info("%s\"%s\"", "Switch to file: ", _device_agent.name().toUtf8().data());
else
dsv_info("%s\"%s\"", "Switch to device: ", _device_agent.name().toUtf8().data());
free(array);
}
_cur_snap_samplerate = _device_agent.get_sample_rate();
_cur_samplelimits = _device_agent.get_sample_limit();
bool SigSession::init()
if (_device_agent.get_work_mode() == DSO)
set_run_mode(Repetitive);
else
set_run_mode(Single);
_callback->device_setted();
}
bool SigSession::set_file(QString name)
{
dsv_info("Load file:\"%s\"", name.toUtf8().data());
std::string path = path::ToUnicodePath(name);
if (ds_device_from_file(path.c_str()) != SR_OK)
{
dsv_err("%s", "Load file error!");
return false;
}
return set_default_device();
}
void SigSession::close_file(ds_device_handle dev_handle)
{
ds_remove_device(dev_handle);
set_repeating(false);
stop_capture();
capture_state_changed(SigSession::Stopped);
set_default_device();
}
bool SigSession::init()
{
ds_log_set_context(dsv_log_context());
@@ -2009,85 +1876,33 @@ void SigSession::set_stop_scale(float scale)
void SigSession::store_session_data()
{
}
//---------------device api-----------/
int SigSession::get_device_work_mode()
{
return ds_get_actived_device_mode();
}
bool SigSession::get_device_info(struct ds_device_info &info)
bool SigSession::have_hardware_data()
{
if (ds_get_actived_device_info(&info) == SR_OK){
return info.handle != NULL;
if (_device_agent.have_instance() && _device_agent.isHardware()){
Snapshot *data = get_signal_snapshot();
return data->have_data();
}
return false;
}
bool SigSession::get_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant **data)
void SigSession::update_graph_view()
{
if (ds_get_actived_device_config(ch, cg, key, data) == SR_OK){
return true;
}
return false;
}
bool SigSession::set_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant *data)
{
bool SigSession::get_device_list(struct ds_device_info **out_list, int &out_count, int &actived_index)
{
out_count = 0;
actived_index = -1;
if (ds_set_actived_device_config(ch, cg, key, data) == SR_OK){
return true;
}
if (ds_get_device_list(out_list, &out_count) == SR_OK){
actived_index = ds_get_actived_device_index();
return true;
}
return false;
}
return false;
}
bool SigSession::get_device_config_list(const struct sr_channel_group *cg,
int key, GVariant **data)
{
if (ds_get_actived_device_config_list(cg, key, data) == SR_OK){
return true;
}
return false;
}
const struct sr_config_info* SigSession::get_device_config_info(int key)
{
return ds_get_actived_device_config_info(key);
}
const struct sr_config_info* SigSession::get_device_config_info_by_name(const char *optname)
{
return ds_get_actived_device_config_info_by_name(optname);
}
bool SigSession::get_device_status(struct sr_status &status, gboolean prg)
{
if (ds_get_actived_device_status(&status, prg) == SR_OK){
return true;
}
return false;
}
struct sr_config* new_config(int key, GVariant *data)
{
return ds_new_config(key, data);
}
void free_config(struct sr_config *src)
{
ds_free_config(src);
}
//---------------device api end-----------/
} // namespace pv

View File

@@ -131,17 +131,16 @@ public:
inline DeviceAgent* get_device(){
return &_device_agent;
}
bool set_device(ds_device_handle dev_handle);
bool set_file(QString name);
void close_file(ds_device_handle dev_handle);
/**
* Sets device instance that will be used in the next capture session.
*/
void set_device(DevInst *dev_inst);
void set_file(QString name);
void close_file(DevInst *dev_inst);
void set_default_device();
void release_device(DevInst *dev_inst);
/**
* Set the last one device.
*/
bool set_default_device();
capture_state get_capture_state();
uint64_t cur_samplerate();
uint64_t cur_snap_samplerate();
@@ -184,8 +183,7 @@ public:
void add_group();
void del_group();
uint16_t get_ch_num(int type);
uint16_t get_ch_num(int type);
bool get_instant();
bool get_data_lock();
void data_auto_lock(int lock);
@@ -230,7 +228,7 @@ public:
float stop_scale();
void exit_capture();
sr_dev_inst* get_dev_inst_c();
void Open();
void Close();
void clear_all_decoder(bool bUpdateView = true);
@@ -282,33 +280,7 @@ public:
}
void store_session_data();
//---------------device api-----------/
public:
int get_device_work_mode();
bool get_device_info(struct ds_device_info &info);
bool get_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant **data);
bool set_device_config(const struct sr_channel *ch,
const struct sr_channel_group *cg,
int key, GVariant *data);
bool get_device_config_list(const struct sr_channel_group *cg,
int key, GVariant **data);
const struct sr_config_info* get_device_config_info(int key);
const struct sr_config_info* get_device_config_info_by_name(const char *optname);
bool get_device_status(struct sr_status &status, gboolean prg);
struct sr_config* new_config(int key, GVariant *data);
void free_config(struct sr_config *src);
bool have_hardware_data();
private:
inline void data_updated(){
@@ -350,7 +322,7 @@ private:
* auto-detected.
*/
static sr_input_format* determine_input_file_format(const std::string &filename);
void sample_thread_proc(DevInst *dev_inst);
// data feed
void feed_in_header(const sr_dev_inst *sdi);
@@ -373,6 +345,9 @@ private:
void update_collect_status_view();
void init_device_view();
void update_graph_view();
bool get_device_list(struct ds_device_info **out_list, int &out_count, int &actived_index);
private:
@@ -383,8 +358,7 @@ private:
mutable std::mutex _sampling_mutex;
mutable std::mutex _data_mutex;
mutable std::mutex _decode_task_mutex;
std::thread _sampling_thread;
std::thread _decode_thread;
volatile bool _bHotplugStop;

View File

@@ -67,6 +67,7 @@ static void close_device_instance(struct sr_dev_inst *dev);
static int open_device_instance(struct sr_dev_inst *dev);
static void collect_run_proc();
static void post_event_async(int event);
static void send_event(int event);
static struct sr_lib_context lib_ctx = {
.event_callback = NULL,
@@ -300,7 +301,7 @@ SR_API int ds_active_device(ds_device_handle handle)
int bFind = 0;
int ret;
if (handle == NULL)
if (handle == NULL_HANDLE)
{
return SR_ERR_ARG;
}
@@ -318,12 +319,11 @@ SR_API int ds_active_device(ds_device_handle handle)
if (lib_ctx.actived_device_instance != NULL)
{
sr_info("Close the previous device \"%s\"", lib_ctx.actived_device_instance->name);
close_device_instance(lib_ctx.actived_device_instance);
lib_ctx.actived_device_instance = NULL;
lib_ctx.actived_device_info.handle = NULL;
lib_ctx.actived_device_info.handle = NULL_HANDLE;
lib_ctx.actived_device_info.name[0] = '\0';
}
@@ -439,12 +439,22 @@ SR_API int ds_get_actived_device_index()
}
i++;
}
pthread_mutex_unlock(&lib_ctx.mutext);
return dex;
}
/**
* Detect whether the active device exists
*/
SR_API int ds_have_actived_device()
{
if (lib_ctx.actived_device_instance != NULL){
return 1;
}
return 0;
}
/**
* Get the decive supports work mode, mode list: LOGIC、ANALOG、DSO
* return type see struct sr_dev_mode.
@@ -480,7 +490,7 @@ SR_API int ds_remove_device(ds_device_handle handle)
di = lib_ctx.actived_device_instance;
if (handle == NULL)
if (handle == NULL_HANDLE)
{
return SR_ERR_ARG;
}
@@ -506,7 +516,7 @@ SR_API int ds_remove_device(ds_device_handle handle)
}
if (lib_ctx.actived_device_info.handle == dev->handle)
{
lib_ctx.actived_device_info.handle = 0;
lib_ctx.actived_device_info.handle = NULL_HANDLE;
lib_ctx.actived_device_info.name[0] = '\0';
}
@@ -535,11 +545,11 @@ SR_API int ds_get_actived_device_info(struct ds_device_info *fill_info)
return SR_ERR_ARG;
}
fill_info->handle = NULL;
fill_info->handle = NULL_HANDLE;
fill_info->name[0] = '\0';
fill_info->dev_type = DEV_TYPE_UNKOWN;
if (lib_ctx.actived_device_info.handle != NULL)
if (lib_ctx.actived_device_info.handle != NULL_HANDLE)
{
fill_info->handle = lib_ctx.actived_device_info.handle;
strncpy(fill_info->name, lib_ctx.actived_device_info.name, sizeof(fill_info->name));
@@ -627,6 +637,8 @@ static void collect_run_proc()
struct sr_dev_inst *di;
di = lib_ctx.actived_device_instance;
send_event(DS_EV_COLLECT_TASK_START);
sr_info("%s", "Collect thread start.");
if (di == NULL || di->driver == NULL || di->driver->dev_acquisition_start == NULL)
@@ -645,17 +657,16 @@ static void collect_run_proc()
}
ret = sr_session_run();
if (ret != SR_OK)
{
if (ret != SR_OK){
sr_err("%s", "Run session error!");
lib_ctx.collect_thread = NULL;
goto END;
}
}
END:
sr_info("%s", "Collect thread end.");
lib_ctx.collect_thread = NULL;
send_event(DS_EV_COLLECT_TASK_END);
}
/**
@@ -694,37 +705,25 @@ int ds_trigger_is_enabled()
{
GSList *l;
struct sr_channel *p;
int ret;
ret = 0;
pthread_mutex_lock(&lib_ctx.mutext);
if (lib_ctx.actived_device_instance != NULL)
{
for (l = lib_ctx.actived_device_instance->channels; l; l = l->next)
{
p = (struct sr_channel *)l->data;
if (p->trigger && p->trigger[0] != '\0')
return 1;
if (p->trigger && p->trigger[0] != '\0'){
ret = 1;
break;
}
}
}
return 0;
}
pthread_mutex_unlock(&lib_ctx.mutext);
/**
* heck that at least one probe is enabled
*/
int ds_channel_is_enabled()
{
GSList *l;
struct sr_channel *p;
if (lib_ctx.actived_device_instance != NULL)
{
for (l = lib_ctx.actived_device_instance->channels; l; l = l->next)
{
p = (struct sr_channel *)l->data;
if (p->enabled)
return 1;
}
}
return 0;
return ret;
}
/**-------------------public end ---------------*/
@@ -827,6 +826,41 @@ SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable
return sr_enable_device_channel(lib_ctx.actived_device_instance, ch, enable);
}
/**
* check that at least one probe is enabled
*/
int ds_channel_is_enabled()
{
GSList *l;
struct sr_channel *p;
int ret;
ret = 0;
pthread_mutex_lock(&lib_ctx.mutext);
if (lib_ctx.actived_device_instance != NULL)
{
for (l = lib_ctx.actived_device_instance->channels; l; l = l->next)
{
p = (struct sr_channel *)l->data;
if (p->enabled){
ret = 1;
break;
}
}
}
pthread_mutex_unlock(&lib_ctx.mutext);
return ret;
}
GSList* ds_get_actived_device_channels()
{
if (lib_ctx.actived_device_instance != NULL){
return lib_ctx.actived_device_instance->channels;
}
return NULL;
}
/**-------------------config end-------------------*/
/**-------------------internal function ---------------*/
@@ -1250,7 +1284,6 @@ static void post_event_proc(int event)
pthread_mutex_lock(&lib_ctx.mutext);
lib_ctx.callback_thread_count--;
;
pthread_mutex_unlock(&lib_ctx.mutext);
}
@@ -1263,4 +1296,11 @@ static void post_event_async(int event)
g_thread_new("callback_thread", post_event_proc, event);
}
static void send_event(int event)
{
if (lib_ctx.event_callback != NULL){
lib_ctx.event_callback(event);
}
}
/**-------------------private function end---------------*/

View File

@@ -1242,24 +1242,29 @@ SR_API void ds_log_set_context(xlog_context *ctx);
SR_API void ds_log_level(int level);
/*---event define ---------------------------------------------*/
enum dslib_event_type
{
// A new device attached, user need to call ds_get_device_list to get the list,
// the last one is new.
// User can call ds_active_device() to switch to the current device.
DS_EV_NEW_DEVICE_ATTACH = 0,
// A new device attached, user need to call ds_get_device_list to get the list,
// the last one is new.
// User can call ds_active_device() to switch to the current device.
#define DS_EV_NEW_DEVICE_ATTACH 0
// The current device detached, user need to call ds_get_device_list to get the list,
// and call ds_active_device() to switch to the current device.
DS_EV_CURRENT_DEVICE_DETACH = 1,
// The current device detached, user need to call ds_get_device_list to get the list,
// and call ds_active_device() to switch to the current device.
#define DS_EV_CURRENT_DEVICE_DETACH 1
// A inactive device detached.
// User can call ds_get_device_list() to get the new list, and update the list view.
DS_EV_INACTIVE_DEVICE_DETACH = 2,
};
// A inactive device detached.
// User can call ds_get_device_list() to get the new list, and update the list view.
#define DS_EV_INACTIVE_DEVICE_DETACH 2
typedef void* ds_device_handle;
// The collect task is ends.
#define DS_EV_COLLECT_TASK_START 100
// The collect task is ends.
#define DS_EV_COLLECT_TASK_END 101
typedef unsigned long long ds_device_handle;
#define NULL_HANDLE 0
/**
* Device base info
@@ -1284,16 +1289,6 @@ struct ds_store_extra_data
int data_length;
};
/*-----------------trigger---------------*/
int ds_trigger_is_enabled();
/*-----------------channel---------------*/
/**
* heck that at least one probe is enabled
*/
int ds_channel_is_enabled();
/*---lib_main.c -----------------------------------------------*/
/**
@@ -1355,6 +1350,11 @@ SR_API int ds_active_device_by_index(int index);
*/
SR_API int ds_get_actived_device_index();
/**
* Detect whether the active device exists
*/
SR_API int ds_have_actived_device();
/**
* Create a device from session file, and will auto load the data.
*/
@@ -1423,6 +1423,17 @@ SR_API void ds_free_config(struct sr_config *src);
/*----------channel----------*/
SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable);
/**
* heck that at least one probe is enabled
*/
int ds_channel_is_enabled();
GSList* ds_get_actived_device_channels();
/*-----------------trigger---------------*/
int ds_trigger_is_enabled();
#ifdef __cplusplus
}
#endif