Merge pull request #609 from yunyaobaihong/demo

Demo
This commit is contained in:
dreamsourcelabTAI 2023-05-05 10:16:25 +08:00 committed by GitHub
commit f17bbc8461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 2481 additions and 838 deletions

View File

@ -116,6 +116,8 @@ namespace pv
_is_auto_switch_device = false;
_is_save_confirm_msg = false;
_pattern_mode = "RANDOM";
setup_ui();
setContextMenuPolicy(Qt::NoContextMenu);
@ -1712,7 +1714,10 @@ namespace pv
_session->device_event_object()->device_updated();
if (_device_agent->is_hardware())
{
_session->on_load_config_end();
}
if (_device_agent->get_work_mode() == LOGIC && _device_agent->is_file() == false)
_view->auto_set_max_scale();
@ -1731,7 +1736,33 @@ namespace pv
}
_session->start_capture(true);
}
}
if (_device_agent->is_demo())
{
if(_device_agent->get_work_mode() == LOGIC)
{
GVariant *gvar = _device_agent->get_config(NULL,NULL,SR_CONF_PATTERN_MODE);
if(gvar != NULL)
{
_pattern_mode = g_variant_get_string(gvar,NULL);
g_variant_unref(gvar);
}
_protocol_widget->del_all_protocol();
if(_device_agent->get_work_mode() == LOGIC)
{
_view->auto_set_max_scale();
if(_pattern_mode != "RANDOM")
{
StoreSession ss(_session);
QJsonArray deArray = get_decoder_json_from_file(_device_agent->path());
ss.load_decoders(_protocol_widget, deArray);
}
}
}
}
}
break;
@ -1746,10 +1777,11 @@ namespace pv
_view->timebase_changed();
break;
case DSV_MSG_DEVICE_MODE_CHANGED:
case DSV_MSG_DEVICE_MODE_CHANGED:
_view->mode_changed();
reset_all_view();
load_device_config();
load_device_config();
update_toolbar_view_status();
_sampling_bar->update_sample_rate_list();
@ -1758,6 +1790,27 @@ namespace pv
if (_device_agent->get_work_mode() == LOGIC)
_view->auto_set_max_scale();
if(_device_agent->is_demo())
{
GVariant *gvar = _device_agent->get_config(NULL,NULL,SR_CONF_PATTERN_MODE);
if(gvar != NULL)
{
_pattern_mode = g_variant_get_string(gvar,NULL);
g_variant_unref(gvar);
}
_protocol_widget->del_all_protocol();
if(_device_agent->get_work_mode() == LOGIC)
{
if(_pattern_mode != "RANDOM")
{
StoreSession ss(_session);
QJsonArray deArray = get_decoder_json_from_file(_device_agent->path());
ss.load_decoders(_protocol_widget, deArray);
}
}
}
break;
case DSV_MSG_NEW_USB_DEVICE:
@ -1838,9 +1891,47 @@ namespace pv
}
break;
case DSV_MSG_END_DEVICE_OPTIONS:
break;
case DSV_MSG_END_DEVICE_OPTIONS:
if(_device_agent->is_demo() &&_device_agent->get_work_mode() == LOGIC)
{
GVariant *gvar = _device_agent->get_config(NULL,NULL,SR_CONF_PATTERN_MODE);
if(gvar != NULL)
{
std::string pattern_mode = g_variant_get_string(gvar,NULL);
g_variant_unref(gvar);
if(pattern_mode != _pattern_mode)
{
_pattern_mode = pattern_mode;
_device_agent->set_config(NULL,NULL,SR_CONF_DEMO_INIT,g_variant_new_boolean(TRUE));
_device_agent->update();
_session->init_signals();
update_toolbar_view_status();
_sampling_bar->update_sample_rate_list();
_protocol_widget->del_all_protocol();
if(_pattern_mode != "RANDOM")
{
StoreSession ss(_session);
QJsonArray deArray = get_decoder_json_from_file(_device_agent->path());
ss.load_decoders(_protocol_widget, deArray);
_session->start_capture(false);
}
}
}
}
break;
case DSV_MSG_BEGIN_DEVICE_OPTIONS:
if(_device_agent->is_demo())
{
GVariant *gvar = _device_agent->get_config(NULL,NULL,SR_CONF_PATTERN_MODE);
if(gvar != NULL)
{
_pattern_mode = g_variant_get_string(gvar,NULL);
g_variant_unref(gvar);
}
}
}
}

View File

@ -214,6 +214,7 @@ private:
bool _is_auto_switch_device;
high_resolution_clock::time_point _last_key_press_time;
bool _is_save_confirm_msg;
std::string _pattern_mode;
int _key_value;
bool _key_vaild;

View File

@ -758,7 +758,10 @@ namespace pv
std::vector<view::Signal *> sigs;
unsigned int logic_probe_count = 0;
unsigned int dso_probe_count = 0;
unsigned int analog_probe_count = 0;
unsigned int analog_probe_count = 0;
set_cur_snap_samplerate(_device_agent.get_sample_rate());
set_cur_samplelimits(_device_agent.get_sample_limit());
// Detect what data types we will receive
if (_device_agent.have_instance())
@ -841,6 +844,9 @@ namespace pv
int dso_chan_num = 0;
int all_chann_num = 0;
set_cur_snap_samplerate(_device_agent.get_sample_rate());
set_cur_samplelimits(_device_agent.get_sample_limit());
// Make the logic probe list
for (GSList *l = _device_agent.get_channels(); l; l = l->next)
{
@ -2104,7 +2110,9 @@ namespace pv
set_cur_samplelimits(_device_agent.get_sample_limit());
dsv_info("Switch work mode to:%d", mode);
broadcast_msg(DSV_MSG_DEVICE_MODE_CHANGED);
return true;
}
return false;

View File

@ -410,6 +410,7 @@ public:
}
void on_load_config_end();
void init_signals();
private:
void set_cur_samplelimits(uint64_t samplelimits);
@ -446,7 +447,7 @@ private:
void capture_init();
void nodata_timeout();
void feed_timeout();
void init_signals();
void clear_decode_result();
void attach_data_to_signal(SessionData *data);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -23,22 +23,103 @@
#include <glib.h>
#include "../../libsigrok-internal.h"
/* Supported patterns which we can generate */
#include <minizip/unzip.h>
enum DEMO_PATTERN {
PATTERN_SINE = 0,
PATTERN_SQUARE = 1,
PATTERN_TRIANGLE = 2,
PATTERN_SAWTOOTH = 3,
PATTERN_RANDOM = 4,
PATTERN_INVALID = -1,
PATTERN_RANDOM = 0,
PATTERN_DEFAULT = 1,
};
static const char *pattern_strings[] = {
"Sine",
"Square",
"Triangle",
"Sawtooth",
"Random",
static char *pattern_strings_logic[100] = {"RANDOM"};
static char *pattern_strings_dso[100] = {"RANDOM"};
static char *pattern_strings_analog[100] = {"RANDOM"};
static int pattern_logic_count = 1;
static int pattern_dso_count= 1;
static int pattern_analog_count= 1;
static uint64_t samplerates_file[1];
static uint64_t samplecounts_file[1];
static GTimer *packet_interval = NULL;
static GTimer *run_time = NULL;
static gboolean is_first = TRUE;
static gboolean is_change = FALSE;
static int enabled_probe_num;
static uint64_t packet_len;
static gdouble packet_time;
static uint64_t post_data_len;
extern char DS_RES_PATH[500];
static gboolean vdiv_change;
static gboolean instant = FALSE;
static int max_probe_num = 0;
extern char DS_RES_PATH[500];
uint8_t cur_sample_generator;
uint8_t pre_sample_generator;
struct session_packet_buffer;
static const uint64_t vdivs10to2000[] = {
SR_mV(10),
SR_mV(20),
SR_mV(50),
SR_mV(100),
SR_mV(200),
SR_mV(500),
SR_V(1),
SR_V(2),
0,
};
struct session_vdev
{
int version;
unzFile archive; // zip document
int capfile; // current inner file open status
uint16_t samplerates_min_index;
uint16_t samplerates_max_index;
void *logic_buf;
uint64_t logic_buf_len;
void *analog_buf;
uint64_t analog_buf_len;
uint64_t analog_read_pos;
int cur_channel;
int cur_block;
int num_blocks;
uint64_t samplerate;
uint64_t total_samples;
int64_t trig_time;
uint64_t trig_pos;
int cur_probes;
int num_probes;
int enabled_probes;
uint64_t timebase;
uint64_t max_timebase;
uint64_t min_timebase;
uint8_t unit_bits;
uint32_t ref_min;
uint32_t ref_max;
uint8_t max_height;
struct sr_status mstatus;
struct session_packet_buffer *packet_buffer;
};
#define SESSION_MAX_CHANNEL_COUNT 512
struct session_packet_buffer
{
void *post_buf;
uint64_t post_buf_len;
uint64_t post_len;
uint64_t block_buf_len;
uint64_t block_chan_read_pos;
uint64_t block_data_len;
void *block_bufs[SESSION_MAX_CHANNEL_COUNT];
uint64_t block_read_positions[SESSION_MAX_CHANNEL_COUNT];
};
struct DEMO_caps {
@ -63,22 +144,10 @@ struct DEMO_profile {
struct DEMO_caps dev_caps;
};
static const uint64_t vdivs10to2000[] = {
SR_mV(10),
SR_mV(20),
SR_mV(50),
SR_mV(100),
SR_mV(200),
SR_mV(500),
SR_V(1),
SR_V(2),
0,
};
enum DEMO_CHANNEL_ID {
DEMO_LOGIC100x16 = 0,
DEMO_ANALOG10x2,
DEMO_DSO200x2,
DEMO_ANALOG10x2 = 1 ,
DEMO_DSO200x2 = 2,
};
struct DEMO_channels {
@ -227,6 +296,15 @@ static const int32_t probeOptions[] = {
SR_CONF_PROBE_MAP_MAX,
};
static const int32_t probeSessions[] = {
SR_CONF_PROBE_COUPLING,
SR_CONF_PROBE_VDIV,
SR_CONF_PROBE_MAP_DEFAULT,
SR_CONF_PROBE_MAP_UNIT,
SR_CONF_PROBE_MAP_MIN,
SR_CONF_PROBE_MAP_MAX,
};
static const uint8_t probeCoupling[] = {
SR_DC_COUPLING,
SR_AC_COUPLING,
@ -258,8 +336,8 @@ static const struct DEMO_profile supported_Demo[] = {
0,
vdivs10to2000,
0,
DEMO_LOGIC100x16,
PATTERN_SINE,
DEMO_LOGIC100x16,
PATTERN_RANDOM,
SR_NS(500)}
},
@ -332,4 +410,62 @@ static const int ranx[] = {
-41, 36, -8, 46, 47, -34, 28, -39, 7, -32, 38, -27, 28, -3, -8, 43, -37, -24, 6, 3,
};
static int init_pattern_mode_list();
static int get_pattern_mode_index_by_string(uint8_t device_mode , const char* str);
static int scan_dsl_file(struct sr_dev_inst *sdi);
static char* get_dsl_path_by_pattern_mode(uint8_t device_mode ,uint8_t pattern_mode);
static void adjust_samplerate(struct sr_dev_inst *sdi);
static int init_random_data(struct session_vdev * vdev);
static int hw_init(struct sr_context *sr_ctx);
static GSList *hw_scan(GSList *options);
static const GSList *hw_dev_mode_list(const struct sr_dev_inst *sdi);
static int hw_dev_open(struct sr_dev_inst *sdi);
static int hw_dev_close(struct sr_dev_inst *sdi);
static int dev_destroy(struct sr_dev_inst *sdi);
static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel *ch,
const struct sr_channel_group *cg);
static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
struct sr_channel *ch,
struct sr_channel_group *cg);
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg);
static int hw_dev_acquisition_start(struct sr_dev_inst *sdi,
void *cb_data);
static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data);
static int hw_dev_status_get(const struct sr_dev_inst *sdi, struct sr_status *status, gboolean prg);
static int load_virtual_device_session(struct sr_dev_inst *sdi);
static int receive_data_logic(int fd, int revents, const struct sr_dev_inst *sdi);
static int receive_data_logic_decoder(int fd, int revents, const struct sr_dev_inst *sdi);
static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi);
static int receive_data_analog(int fd, int revents, const struct sr_dev_inst *sdi);
static void send_error_packet(const struct sr_dev_inst *cb_sdi, struct session_vdev *vdev, struct sr_datafeed_packet *packet);
static int close_archive(struct session_vdev *vdev);
#endif

View File

@ -647,7 +647,7 @@ SR_API int ds_get_actived_device_info(struct ds_device_full_info *fill_info)
strncpy(p->driver_name, dev->driver->name, sizeof(p->driver_name) - 1);
}
if (dev->dev_type == DEV_TYPE_FILELOG && dev->path != NULL){
if ((dev->dev_type == DEV_TYPE_FILELOG || dev->dev_type == DEV_TYPE_DEMO) && dev->path != NULL){
strncpy(p->path, dev->path, sizeof(p->path) - 1);
}
ret = SR_OK;

View File

@ -1033,6 +1033,12 @@ enum sr_config_option_id
/** The device supports setting the number of data blocks. */
SR_CONF_NUM_BLOCKS = 30104,
SR_CONF_LOAD_DECODER = 30105,
SR_CONF_DEMO_INIT = 30106,
SR_CONF_DEMO_CHANGE = 30107,
/*--- Acquisition modes ---------------------------------------------*/
/**