forked from Ivasoft/DSView
Code refactoring 9
This commit is contained in:
@@ -186,7 +186,7 @@ void SigSession::set_device(DevInst *dev_inst)
|
||||
throw(e);
|
||||
return;
|
||||
}
|
||||
sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
|
||||
sr_session_datafeed_callback_add(data_feed_callback, NULL);
|
||||
_callback->device_setted();
|
||||
}
|
||||
}
|
||||
@@ -1216,7 +1216,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
|
||||
}
|
||||
}
|
||||
|
||||
void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi,
|
||||
void SigSession::data_feed_callback(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet, void *cb_data)
|
||||
{
|
||||
(void) cb_data;
|
||||
|
||||
@@ -318,9 +318,9 @@ private:
|
||||
void feed_in_dso(const sr_datafeed_dso &dso);
|
||||
void feed_in_analog(const sr_datafeed_analog &analog);
|
||||
void data_feed_in(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet);
|
||||
const struct sr_datafeed_packet *packet);
|
||||
|
||||
static void data_feed_in_proc(const struct sr_dev_inst *sdi,
|
||||
static void data_feed_callback(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet, void *cb_data);
|
||||
|
||||
// thread for hotplug
|
||||
|
||||
@@ -197,7 +197,7 @@ SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int mode, int index, int status,
|
||||
sdi->channels = NULL;
|
||||
sdi->conn = NULL;
|
||||
sdi->priv = NULL;
|
||||
sdi->handle = (sr_device_handle)sdi;
|
||||
sdi->handle = (ds_device_handle)sdi;
|
||||
sdi->dev_type = DEV_TYPE_UNKOWN;
|
||||
|
||||
if (model && *model){
|
||||
|
||||
@@ -299,7 +299,7 @@ static GSList *scan(GSList *options)
|
||||
sdi->priv = devc;
|
||||
sdi->driver = di;
|
||||
sdi->dev_type = DEV_TYPE_USB;
|
||||
sdi->handle = (sr_device_handle)device_handle;
|
||||
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){
|
||||
|
||||
@@ -1036,6 +1036,12 @@ SR_PRIV int dsl_fpga_arm(const struct sr_dev_inst *sdi)
|
||||
setting_ext32.align_bytes = 0xffff;
|
||||
setting_ext32.end_sync = 0xfa5afa5a;
|
||||
|
||||
if (trigger == NULL)
|
||||
{
|
||||
sr_err("%s", "Trigger have'nt inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
// basic configuration
|
||||
setting.mode = (trigger->trigger_en << TRIG_EN_BIT) +
|
||||
(devc->clock_type << CLK_TYPE_BIT) +
|
||||
@@ -2089,7 +2095,7 @@ static void finish_acquisition(struct DSL_context *devc)
|
||||
/* Terminate session. */
|
||||
packet.type = SR_DF_END;
|
||||
packet.status = SR_PKT_OK;
|
||||
sr_session_send(devc->cb_data, &packet);
|
||||
ds_data_forward(devc->cb_data, &packet);
|
||||
|
||||
if (devc->num_transfers != 0) {
|
||||
devc->num_transfers = 0;
|
||||
@@ -2242,7 +2248,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||
if (devc->abort)
|
||||
devc->status = DSL_STOP;
|
||||
|
||||
sr_info("%llu: receive_transfer(): status %d; timeout %d; received %d bytes.",
|
||||
sr_detail("%llu: receive_transfer(): status %d; timeout %d; received %d bytes.",
|
||||
g_get_monotonic_time(), transfer->status, transfer->timeout, transfer->actual_length);
|
||||
|
||||
switch (transfer->status) {
|
||||
@@ -2317,7 +2323,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||
|
||||
/* send data to session bus */
|
||||
if (packet.status == SR_PKT_OK)
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
}
|
||||
|
||||
devc->num_samples += cur_sample_count;
|
||||
@@ -2381,7 +2387,7 @@ static void receive_header(struct libusb_transfer *transfer)
|
||||
|
||||
packet.type = SR_DF_TRIGGER;
|
||||
packet.payload = trigger_pos;
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
|
||||
devc->status = DSL_DATA;
|
||||
}
|
||||
@@ -2391,7 +2397,7 @@ static void receive_header(struct libusb_transfer *transfer)
|
||||
packet.type = SR_DF_TRIGGER;
|
||||
packet.payload = trigger_pos;
|
||||
packet.status = SR_PKT_DATA_ERROR;
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
}
|
||||
|
||||
free_transfer(transfer);
|
||||
|
||||
@@ -366,7 +366,7 @@ static GSList *scan(GSList *options)
|
||||
sdi->priv = devc;
|
||||
sdi->driver = di;
|
||||
sdi->dev_type = DEV_TYPE_USB;
|
||||
sdi->handle = (sr_device_handle)device_handle;
|
||||
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){
|
||||
@@ -1247,7 +1247,7 @@ static void report_overflow(struct DSL_context *devc)
|
||||
packet.status = SR_PKT_OK;
|
||||
packet.type = SR_DF_OVERFLOW;
|
||||
packet.payload = NULL;
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
}
|
||||
|
||||
static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
|
||||
|
||||
@@ -913,7 +913,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
|
||||
demo_trigger_pos.real_pos = i;
|
||||
packet.type = SR_DF_TRIGGER;
|
||||
packet.payload = &demo_trigger_pos;
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -960,7 +960,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
|
||||
devc->pre_index += sending_now;
|
||||
}
|
||||
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
|
||||
devc->mstatus.trig_hit = (devc->trigger_stage == 0);
|
||||
devc->mstatus.captured_cnt0 = devc->samples_counter;
|
||||
@@ -1062,7 +1062,7 @@ static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data)
|
||||
/* Send last packet. */
|
||||
packet.type = SR_DF_END;
|
||||
packet.status = SR_PKT_OK;
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||
src = sr_config_new(SR_CONF_SAMPLERATE,
|
||||
g_variant_new_uint64(ctx->samplerate));
|
||||
meta.config = g_slist_append(NULL, src);
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
sr_config_free(src);
|
||||
}
|
||||
|
||||
@@ -132,13 +132,13 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||
logic.data = buffer;
|
||||
while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
|
||||
logic.length = size;
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
|
||||
g_free(ctx);
|
||||
in->internal = NULL;
|
||||
|
||||
@@ -418,7 +418,7 @@ static void send_samples(const struct sr_dev_inst *sdi, uint64_t sample, uint64_
|
||||
|
||||
logic.length = sizeof(uint64_t) * chunksize;
|
||||
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
count -= chunksize;
|
||||
}
|
||||
}
|
||||
@@ -582,7 +582,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||
samplerate = ctx->samplerate / ctx->downsample;
|
||||
src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
|
||||
meta.config = g_slist_append(NULL, src);
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
sr_config_free(src);
|
||||
|
||||
/* Parse the contents of the VCD file */
|
||||
@@ -590,7 +590,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||
|
||||
/* Send end packet to the session bus. */
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
|
||||
fclose(file);
|
||||
release_context(ctx);
|
||||
|
||||
@@ -147,7 +147,7 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||
src = sr_config_new(SR_CONF_SAMPLERATE,
|
||||
g_variant_new_uint64(ctx->samplerate));
|
||||
meta.config = g_slist_append(NULL, src);
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
sr_config_free(src);
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) == -1)
|
||||
@@ -186,12 +186,12 @@ static int loadfile(struct sr_input *in, const char *filename)
|
||||
analog.mq = 0;
|
||||
analog.unit = 0;
|
||||
analog.data = fdata;
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(in->sdi, &packet);
|
||||
ds_data_forward(in->sdi, &packet);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ char DS_RES_PATH[500] = {0};
|
||||
|
||||
struct sr_lib_context
|
||||
{
|
||||
libsigrok_event_callback_t event_callback;
|
||||
dslib_event_callback_t event_callback;
|
||||
struct sr_context *sr_ctx;
|
||||
GList* device_list; // All device instance, sr_dev_inst* type
|
||||
pthread_mutex_t mutext;
|
||||
@@ -52,8 +52,11 @@ struct sr_lib_context
|
||||
int check_reconnect_times;
|
||||
struct libusb_device *attach_device_handle;
|
||||
struct libusb_device *detach_device_handle;
|
||||
struct sr_device_info current_device_info;
|
||||
struct ds_device_info current_device_info;
|
||||
struct sr_dev_inst *current_device_instance;
|
||||
int collect_stop_flag;
|
||||
GThread *collect_thread;
|
||||
ds_datafeed_callback_t data_forward_callback;
|
||||
};
|
||||
|
||||
static void hotplug_event_listen_callback(struct libusb_context *ctx, struct libusb_device *dev, int event);
|
||||
@@ -61,6 +64,7 @@ static void usb_hotplug_process_proc();
|
||||
static void destroy_device_instance(struct sr_dev_inst *dev);
|
||||
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 struct sr_lib_context lib_ctx = {
|
||||
.event_callback = NULL,
|
||||
@@ -81,12 +85,15 @@ static struct sr_lib_context lib_ctx = {
|
||||
.dev_type = DEV_TYPE_UNKOWN,
|
||||
},
|
||||
.current_device_instance = NULL,
|
||||
.collect_stop_flag = 0,
|
||||
.data_forward_callback = NULL,
|
||||
.collect_thread = NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* Must call first
|
||||
*/
|
||||
SR_API int sr_lib_init()
|
||||
SR_API int ds_lib_init()
|
||||
{
|
||||
int ret = 0;
|
||||
struct sr_dev_driver **drivers = NULL;
|
||||
@@ -106,6 +113,9 @@ SR_API int sr_lib_init()
|
||||
}
|
||||
lib_ctx.lib_exit_flag = 0;
|
||||
|
||||
//init trigger
|
||||
ds_trigger_init();
|
||||
|
||||
// Initialise all libsigrok drivers
|
||||
drivers = sr_driver_list();
|
||||
for (dr = drivers; *dr; dr++) {
|
||||
@@ -130,7 +140,7 @@ SR_API int sr_lib_init()
|
||||
/**
|
||||
* Free all resource before program exits
|
||||
*/
|
||||
SR_API int sr_lib_exit()
|
||||
SR_API int ds_lib_exit()
|
||||
{
|
||||
GSList *l;
|
||||
|
||||
@@ -140,6 +150,10 @@ SR_API int sr_lib_exit()
|
||||
|
||||
sr_info("Uninit %s.", SR_LIB_NAME);
|
||||
|
||||
if (lib_ctx.collect_thread != NULL){
|
||||
ds_device_stop_collect(); //stop collect.
|
||||
}
|
||||
|
||||
sr_close_hotplug(lib_ctx.sr_ctx);
|
||||
|
||||
lib_ctx.lib_exit_flag = 1; //all thread to exit
|
||||
@@ -157,6 +171,9 @@ SR_API int sr_lib_exit()
|
||||
|
||||
pthread_mutex_destroy(&lib_ctx.mutext); //uninit locker
|
||||
|
||||
//uninit trigger
|
||||
ds_trigger_destroy();
|
||||
|
||||
if (sr_exit(lib_ctx.sr_ctx) != SR_OK){
|
||||
sr_err("%s", "call sr_exit error");
|
||||
}
|
||||
@@ -170,7 +187,7 @@ SR_API int sr_lib_exit()
|
||||
/**
|
||||
* Set the firmware binary file directory
|
||||
*/
|
||||
SR_API void sr_set_firmware_resource_dir(const char *dir)
|
||||
SR_API void ds_set_firmware_resource_dir(const char *dir)
|
||||
{
|
||||
if (dir){
|
||||
strcpy(DS_RES_PATH, dir);
|
||||
@@ -188,20 +205,28 @@ SR_API void sr_set_firmware_resource_dir(const char *dir)
|
||||
/**
|
||||
* Set event callback, event type see enum libsigrok_event_type
|
||||
*/
|
||||
SR_API void sr_set_event_callback(libsigrok_event_callback_t cb)
|
||||
SR_API void ds_set_event_callback(dslib_event_callback_t cb)
|
||||
{
|
||||
lib_ctx.event_callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data receive callback.
|
||||
*/
|
||||
SR_API int ds_set_datafeed_callback(ds_datafeed_callback_t cb)
|
||||
{
|
||||
lib_ctx.data_forward_callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the device list, if the field _handle is 0, the list visited to end.
|
||||
* User need call free() to release the buffer. If the list is empty, the out_list is null.
|
||||
*/
|
||||
SR_API int sr_device_get_list(struct sr_device_info** out_list, int *out_count)
|
||||
SR_API int ds_device_get_list(struct ds_device_info** out_list, int *out_count)
|
||||
{
|
||||
int num;
|
||||
struct sr_device_info *array = NULL;
|
||||
struct sr_device_info *p = NULL;
|
||||
struct ds_device_info *array = NULL;
|
||||
struct ds_device_info *p = NULL;
|
||||
GList *l;
|
||||
struct sr_dev_inst *dev;
|
||||
|
||||
@@ -218,7 +243,7 @@ SR_API int sr_device_get_list(struct sr_device_info** out_list, int *out_count)
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
array = (struct sr_device_info*)malloc(sizeof(struct sr_device_info) * (num+1));
|
||||
array = (struct ds_device_info*)malloc(sizeof(struct ds_device_info) * (num+1));
|
||||
if (array == NULL){
|
||||
pthread_mutex_unlock(&lib_ctx.mutext);
|
||||
return SR_ERR_MALLOC;
|
||||
@@ -251,7 +276,7 @@ SR_API int sr_device_get_list(struct sr_device_info** out_list, int *out_count)
|
||||
/**
|
||||
* Active a device, if success, it will trigs the event of SR_EV_CURRENT_DEVICE_CHANGED.
|
||||
*/
|
||||
SR_API int sr_device_select(sr_device_handle handle)
|
||||
SR_API int ds_device_select(ds_device_handle handle)
|
||||
{
|
||||
GList *l;
|
||||
struct sr_dev_inst *dev;
|
||||
@@ -265,6 +290,11 @@ SR_API int sr_device_select(sr_device_handle handle)
|
||||
|
||||
sr_info("%s", "Begin set current device.");
|
||||
|
||||
if (lib_ctx.collect_thread != NULL){
|
||||
sr_err("%s", "One device is collecting, switch device error.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&lib_ctx.mutext);
|
||||
|
||||
if (lib_ctx.current_device_instance != NULL) {
|
||||
@@ -284,7 +314,7 @@ SR_API int sr_device_select(sr_device_handle handle)
|
||||
bFind = 1;
|
||||
|
||||
if (dev->dev_type == DEV_TYPE_USB && DS_RES_PATH[0] == '\0'){
|
||||
sr_err("%s", "Please call sr_set_firmware_resource_dir() to set the firmware resource path.");
|
||||
sr_err("%s", "Please call ds_set_firmware_resource_dir() to set the firmware resource path.");
|
||||
}
|
||||
|
||||
sr_info("Switch \"%s\" to current device.", dev->name);
|
||||
@@ -310,7 +340,7 @@ SR_API int sr_device_select(sr_device_handle handle)
|
||||
sr_info("%s", "End of setting current device.");
|
||||
|
||||
if (!bFind){
|
||||
sr_err("sr_device_select() error, can't find the device.");
|
||||
sr_err("ds_device_select() error, can't find the device.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
@@ -321,12 +351,12 @@ SR_API int sr_device_select(sr_device_handle handle)
|
||||
* Active a device, if success, it will trigs the event of SR_EV_CURRENT_DEVICE_CHANGED.
|
||||
* @index is -1, will select the last one.
|
||||
*/
|
||||
SR_API int sr_device_select_by_index(int index)
|
||||
SR_API int ds_device_select_by_index(int index)
|
||||
{
|
||||
GList *l;
|
||||
struct sr_dev_inst *dev;
|
||||
sr_device_handle handle = NULL;
|
||||
sr_device_handle lst_handle = NULL;
|
||||
ds_device_handle handle = NULL;
|
||||
ds_device_handle lst_handle = NULL;
|
||||
int i=0;
|
||||
|
||||
pthread_mutex_lock(&lib_ctx.mutext);
|
||||
@@ -349,11 +379,209 @@ SR_API int sr_device_select_by_index(int index)
|
||||
}
|
||||
|
||||
if (handle == NULL){
|
||||
sr_err("%s", "sr_device_select_by_index(), index is error!");
|
||||
sr_err("%s", "ds_device_select_by_index(), index is error!");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
return sr_device_select(handle);
|
||||
return ds_device_select(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove one device from the list, and destory it.
|
||||
* User need to call ds_device_get_list() to get the new list.
|
||||
*/
|
||||
SR_API int ds_remove_device(ds_device_handle handle)
|
||||
{
|
||||
GList *l;
|
||||
struct sr_dev_inst *dev;
|
||||
int bFind = 0;
|
||||
|
||||
if (handle == NULL){
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&lib_ctx.mutext);
|
||||
|
||||
for (l = lib_ctx.device_list; l; l = l->next){
|
||||
dev = l->data;
|
||||
if (dev->handle == handle){
|
||||
lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data);
|
||||
destroy_device_instance(dev);
|
||||
bFind = 1;
|
||||
if (dev == lib_ctx.current_device_instance){
|
||||
lib_ctx.current_device_instance = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&lib_ctx.mutext);
|
||||
|
||||
if (bFind == 0){
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current device info.
|
||||
* If the current device is not exists, the handle filed will be set null.
|
||||
*/
|
||||
SR_API int ds_get_current_device_info(struct ds_device_info *info)
|
||||
{
|
||||
if (info == NULL){
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
info->handle = NULL;
|
||||
info->name[0] = '\0';
|
||||
info->is_current = 0;
|
||||
info->dev_type = DEV_TYPE_UNKOWN;
|
||||
|
||||
if (lib_ctx.current_device_info.handle != NULL){
|
||||
info->handle = lib_ctx.current_device_info.handle;
|
||||
strncpy(info->name, lib_ctx.current_device_info.name, sizeof(info->name));
|
||||
info->is_current = 1;
|
||||
info->dev_type = lib_ctx.current_device_info.dev_type;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start collect data
|
||||
*/
|
||||
SR_API int ds_device_start_collect()
|
||||
{
|
||||
int ret;
|
||||
struct sr_dev_inst *di;
|
||||
di = lib_ctx.current_device_instance;
|
||||
|
||||
if (lib_ctx.collect_thread != NULL)
|
||||
{
|
||||
sr_err("%s", "Is collecting.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
if (lib_ctx.current_device_instance == NULL){
|
||||
sr_err("%s", "Please set a current device first.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
if (lib_ctx.current_device_instance->status != SR_ST_ACTIVE){
|
||||
sr_err("The device cannot be used, status:%d", SR_ST_ACTIVE);
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
if (ds_channel_is_enabled() == 0){
|
||||
sr_err("%s", "There have no useable channel, unable to collect.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
if (lib_ctx.data_forward_callback == NULL){
|
||||
sr_err("%s", "Error! Data forwarding callback is not set, see \"ds_set_datafeed_callback()\".");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
lib_ctx.collect_stop_flag = 0;
|
||||
|
||||
sr_session_new(); //create new session
|
||||
|
||||
ret = open_device_instance(lib_ctx.current_device_instance); //open device
|
||||
if (ret != SR_OK){
|
||||
sr_err("%s", "Open device error!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
lib_ctx.collect_thread = g_thread_new("collect_run_proc", collect_run_proc, NULL);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static void collect_run_proc()
|
||||
{
|
||||
int ret;
|
||||
struct sr_dev_inst *di;
|
||||
di = lib_ctx.current_device_instance;
|
||||
|
||||
sr_info("%s", "Collect thread start.");
|
||||
|
||||
if (di == NULL || di->driver == NULL || di->driver->dev_acquisition_start == NULL){
|
||||
sr_err("%s", "The device cannot be used.");
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = di->driver->dev_acquisition_start(di, (void*)di);
|
||||
if (ret != SR_OK){
|
||||
sr_err("Failed to start acquisition of device in "
|
||||
"running session: %d", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = sr_session_run();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop collect data
|
||||
*/
|
||||
SR_API int ds_device_stop_collect()
|
||||
{
|
||||
if (lib_ctx.collect_thread != NULL){
|
||||
sr_session_destroy();
|
||||
|
||||
lib_ctx.collect_stop_flag = 1;
|
||||
|
||||
g_thread_join(lib_ctx.collect_thread); //Wait the collect thread ends.
|
||||
lib_ctx.collect_thread = NULL;
|
||||
|
||||
if (lib_ctx.current_device_instance != NULL){
|
||||
close_device_instance(lib_ctx.current_device_instance);
|
||||
}
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
int ds_trigger_is_enabled()
|
||||
{
|
||||
GSList *l;
|
||||
struct sr_channel *p;
|
||||
|
||||
if (lib_ctx.current_device_instance != NULL)
|
||||
{
|
||||
for (l = lib_ctx.current_device_instance->channels; l; l = l->next)
|
||||
{
|
||||
p = (struct sr_channel *)l->data;
|
||||
if (p->trigger && p->trigger[0] != '\0')
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* heck that at least one probe is enabled
|
||||
*/
|
||||
int ds_channel_is_enabled()
|
||||
{
|
||||
GSList *l;
|
||||
struct sr_channel *p;
|
||||
|
||||
if (lib_ctx.current_device_instance != NULL)
|
||||
{
|
||||
for (l = lib_ctx.current_device_instance->channels; l; l = l->next)
|
||||
{
|
||||
p = (struct sr_channel *)l->data;
|
||||
if (p->enabled)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**-------------------internal function ---------------*/
|
||||
@@ -390,66 +618,40 @@ SR_PRIV int sr_usb_device_is_exists(libusb_device *usb_dev)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove one device from the list, and destory it.
|
||||
* User need to call sr_device_get_list() to get the new list.
|
||||
* Forward the data.
|
||||
*/
|
||||
SR_API int sr_remove_device(sr_device_handle handle)
|
||||
SR_PRIV int ds_data_forward(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet)
|
||||
{
|
||||
GList *l;
|
||||
struct sr_dev_inst *dev;
|
||||
int bFind = 0;
|
||||
|
||||
if (handle == NULL){
|
||||
if (!sdi) {
|
||||
sr_err("%s: sdi was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&lib_ctx.mutext);
|
||||
|
||||
for (l = lib_ctx.device_list; l; l = l->next){
|
||||
dev = l->data;
|
||||
if (dev->handle == handle){
|
||||
lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data);
|
||||
destroy_device_instance(dev);
|
||||
bFind = 1;
|
||||
if (dev == lib_ctx.current_device_instance){
|
||||
lib_ctx.current_device_instance = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&lib_ctx.mutext);
|
||||
|
||||
if (bFind == 0){
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current device info.
|
||||
* If the current device is not exists, the handle filed will be set null.
|
||||
*/
|
||||
SR_API int sr_get_current_device_info(struct sr_device_info *info)
|
||||
{
|
||||
if (info == NULL){
|
||||
if (!packet) {
|
||||
sr_err("%s: packet was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
info->handle = NULL;
|
||||
info->name[0] = '\0';
|
||||
info->is_current = 0;
|
||||
info->dev_type = DEV_TYPE_UNKOWN;
|
||||
|
||||
if (lib_ctx.current_device_info.handle != NULL){
|
||||
info->handle = lib_ctx.current_device_info.handle;
|
||||
strncpy(info->name, lib_ctx.current_device_info.name, sizeof(info->name));
|
||||
info->is_current = 1;
|
||||
info->dev_type = lib_ctx.current_device_info.dev_type;
|
||||
if (lib_ctx.data_forward_callback != NULL && lib_ctx.collect_stop_flag == 0){
|
||||
lib_ctx.data_forward_callback(sdi, packet);
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
SR_PRIV int current_device_acquisition_stop()
|
||||
{
|
||||
struct sr_dev_inst *di;
|
||||
di = lib_ctx.current_device_instance;
|
||||
if (di != NULL && di->driver && di->driver->dev_acquisition_stop){
|
||||
return di->driver->dev_acquisition_stop(di, (void*)di);
|
||||
}
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
/**--------------------internal function end------------------*/
|
||||
|
||||
/**-------------------private function ---------------*/
|
||||
|
||||
static int update_device_handle(struct libusb_device *old_dev, struct libusb_device *new_dev)
|
||||
@@ -610,7 +812,7 @@ static void process_attach_event()
|
||||
|
||||
if (lib_ctx.event_callback != NULL && num > 0){
|
||||
// Tell user one new device attched, and the list is updated.
|
||||
lib_ctx.event_callback(SR_EV_NEW_DEVICE_ATTACH);
|
||||
lib_ctx.event_callback(DS_EV_NEW_DEVICE_ATTACH);
|
||||
}
|
||||
|
||||
lib_ctx.attach_device_handle = NULL;
|
||||
@@ -619,7 +821,7 @@ static void process_attach_event()
|
||||
static void process_detach_event()
|
||||
{
|
||||
libusb_device *ev_dev;
|
||||
int ev = SR_EV_INACTIVE_DEVICE_DETACH;
|
||||
int ev = DS_EV_INACTIVE_DEVICE_DETACH;
|
||||
GList *l;
|
||||
struct sr_dev_inst *dev;
|
||||
struct sr_usb_dev_inst *usb_dev_info;
|
||||
@@ -652,7 +854,7 @@ static void process_detach_event()
|
||||
pthread_mutex_unlock(&lib_ctx.mutext);
|
||||
|
||||
if (ev_dev == lib_ctx.current_device_info.handle)
|
||||
ev = SR_EV_CURRENT_DEVICE_DETACH;
|
||||
ev = DS_EV_CURRENT_DEVICE_DETACH;
|
||||
|
||||
if (lib_ctx.event_callback != NULL){
|
||||
//Tell user one new device detached, and the list is updated.
|
||||
@@ -694,7 +896,6 @@ static void usb_hotplug_process_proc()
|
||||
sr_info("%s", "Hotplug thread end!");
|
||||
}
|
||||
|
||||
|
||||
static void destroy_device_instance(struct sr_dev_inst *dev)
|
||||
{
|
||||
if (dev == NULL || dev->driver == NULL){
|
||||
@@ -739,3 +940,5 @@ static int open_device_instance(struct sr_dev_inst *dev)
|
||||
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
/**-------------------private function end---------------*/
|
||||
@@ -124,7 +124,7 @@ struct sr_dev_inst {
|
||||
/** Device driver. */
|
||||
struct sr_dev_driver *driver;
|
||||
/**Identity. */
|
||||
sr_device_handle handle;
|
||||
ds_device_handle handle;
|
||||
/** device name. */
|
||||
char name[50];
|
||||
/** Device type:(demo,filelog,hardware). The type see enum sr_device_type. */
|
||||
@@ -150,11 +150,8 @@ struct sr_dev_inst {
|
||||
void *priv;
|
||||
};
|
||||
|
||||
struct sr_session {
|
||||
/** List of struct sr_dev pointers. */
|
||||
GSList *devs;
|
||||
/** List of struct datafeed_callback pointers. */
|
||||
GSList *datafeed_callbacks;
|
||||
struct sr_session
|
||||
{
|
||||
gboolean running;
|
||||
|
||||
unsigned int num_sources;
|
||||
@@ -255,11 +252,7 @@ SR_PRIV int sr_source_add(int fd, int events, int timeout,
|
||||
sr_receive_data_callback_t cb, void *cb_data);
|
||||
|
||||
/*--- session.c -------------------------------------------------------------*/
|
||||
|
||||
SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet);
|
||||
SR_PRIV int sr_session_stop_sync(void);
|
||||
|
||||
|
||||
SR_PRIV int usb_hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev,
|
||||
libusb_hotplug_event event, void *user_data);
|
||||
|
||||
@@ -271,8 +264,7 @@ SR_PRIV int sr_session_source_add_channel(GIOChannel *channel, int events,
|
||||
int timeout, sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
|
||||
SR_PRIV int sr_session_source_remove(int fd);
|
||||
SR_PRIV int sr_session_source_remove_pollfd(GPollFD *pollfd);
|
||||
SR_PRIV int sr_session_source_remove_channel(GIOChannel *channel);
|
||||
SR_PRIV int sr_session_datafeed_callback_add(sr_datafeed_callback_t cb,void *cb_data);
|
||||
SR_PRIV int sr_session_source_remove_channel(GIOChannel *channel);
|
||||
|
||||
/*--- std.c -----------------------------------------------------------------*/
|
||||
|
||||
@@ -301,6 +293,9 @@ SR_PRIV uint16_t ds_trigger_get_mask1(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
SR_PRIV uint16_t ds_trigger_get_value1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
SR_PRIV uint16_t ds_trigger_get_edge1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
|
||||
SR_PRIV int ds_trigger_init(void);
|
||||
SR_PRIV int ds_trigger_destroy(void);
|
||||
|
||||
/*--- hardware/common/serial.c ----------------------------------------------*/
|
||||
|
||||
enum {
|
||||
@@ -355,5 +350,13 @@ SR_PRIV void sr_hotplug_wait_timout(struct sr_context *ctx);
|
||||
* Check whether the USB device is in the device list.
|
||||
*/
|
||||
SR_PRIV int sr_usb_device_is_exists(libusb_device *usb_dev);
|
||||
|
||||
/**
|
||||
* Forward the data.
|
||||
*/
|
||||
SR_PRIV int ds_data_forward(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet);
|
||||
|
||||
SR_PRIV int current_device_acquisition_stop();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -183,7 +183,7 @@ enum {
|
||||
};
|
||||
|
||||
/** Value for sr_datafeed_packet.type. */
|
||||
enum {
|
||||
enum sr_datafeed_packet_type {
|
||||
SR_DF_HEADER = 10000,
|
||||
SR_DF_END,
|
||||
SR_DF_META,
|
||||
@@ -339,7 +339,7 @@ struct sr_dev_inst;
|
||||
struct sr_dev_driver;
|
||||
|
||||
struct sr_datafeed_packet {
|
||||
uint16_t type;
|
||||
uint16_t type; //see enum sr_datafeed_packet_type
|
||||
uint16_t status;
|
||||
const void *payload;
|
||||
int bExportOriginalData;
|
||||
@@ -1228,22 +1228,12 @@ typedef void (*sr_datafeed_callback_t)(const struct sr_dev_inst *sdi,
|
||||
/* Session setup */
|
||||
SR_API int sr_session_load(const char *filename);
|
||||
SR_API struct sr_session *sr_session_new(void);
|
||||
SR_API int sr_session_destroy(void);
|
||||
SR_API int sr_session_dev_remove_all(void);
|
||||
SR_API int sr_session_dev_add(struct sr_dev_inst *sdi);
|
||||
SR_API int sr_session_dev_list(GSList **devlist);
|
||||
SR_API int sr_session_destroy(void);
|
||||
|
||||
/* Datafeed setup */
|
||||
SR_API int sr_session_datafeed_callback_remove_all(void);
|
||||
|
||||
|
||||
/* Session control */
|
||||
SR_API int sr_session_start(void);
|
||||
/* Session control */
|
||||
SR_API int sr_session_run(void);
|
||||
SR_API int sr_session_stop(void);
|
||||
|
||||
//0:ok, 1:error
|
||||
SR_API int sr_check_session_start_before();
|
||||
|
||||
|
||||
/*--- input/input.c ---------------------------------------------------------*/
|
||||
|
||||
@@ -1278,9 +1268,6 @@ SR_API const char *sr_error_str(int error_code);
|
||||
SR_API const char *sr_error_name(int error_code);
|
||||
|
||||
/*--- trigger.c ------------------------------------------------------------*/
|
||||
SR_API int ds_trigger_init(void);
|
||||
SR_API int ds_trigger_destroy(void);
|
||||
SR_API struct ds_trigger *ds_trigger_get(void);
|
||||
SR_API int ds_trigger_stage_set_value(uint16_t stage, uint16_t probes, char *trigger0, char *trigger1);
|
||||
SR_API int ds_trigger_stage_set_logic(uint16_t stage, uint16_t probes, unsigned char trigger_logic);
|
||||
SR_API int ds_trigger_stage_set_inv(uint16_t stage, uint16_t probes, unsigned char trigger0_inv, unsigned char trigger1_inv);
|
||||
@@ -1298,139 +1285,153 @@ SR_API int ds_trigger_set_mode(uint16_t mode);
|
||||
/**
|
||||
* Use a shared context, and drop the private log context
|
||||
*/
|
||||
SR_API void sr_log_set_context(xlog_context *ctx);
|
||||
SR_API void ds_log_set_context(xlog_context *ctx);
|
||||
|
||||
/**
|
||||
* Set the private log context level
|
||||
*/
|
||||
SR_API void sr_log_level(int level);
|
||||
SR_API void ds_log_level(int level);
|
||||
|
||||
|
||||
/*---event define ---------------------------------------------*/
|
||||
enum libsigrok_event_type
|
||||
enum dslib_event_type
|
||||
{
|
||||
// A new device attached, user need to call sr_device_get_list to get the list,
|
||||
// A new device attached, user need to call ds_device_get_list to get the list,
|
||||
// the last one is new.
|
||||
// User can call sr_device_select() to switch to the current device.
|
||||
SR_EV_NEW_DEVICE_ATTACH = 0,
|
||||
// User can call ds_device_select() to switch to the current device.
|
||||
DS_EV_NEW_DEVICE_ATTACH = 0,
|
||||
|
||||
// The current device detached, user need to call sr_device_get_list to get the list,
|
||||
// and call sr_device_select() to switch to the current device.
|
||||
SR_EV_CURRENT_DEVICE_DETACH = 1,
|
||||
// The current device detached, user need to call ds_device_get_list to get the list,
|
||||
// and call ds_device_select() to switch to the current device.
|
||||
DS_EV_CURRENT_DEVICE_DETACH = 1,
|
||||
|
||||
// A inactive device detached.
|
||||
// User can call sr_device_get_list() to get the new list, and update the list view.
|
||||
SR_EV_INACTIVE_DEVICE_DETACH = 2,
|
||||
// User can call ds_device_get_list() to get the new list, and update the list view.
|
||||
DS_EV_INACTIVE_DEVICE_DETACH = 2,
|
||||
|
||||
// The current device switch success.
|
||||
// User can call sr_device_get_list() to get new list, and update the data view.
|
||||
SR_EV_CURRENT_DEVICE_CHANGED = 3,
|
||||
// User can call ds_device_get_list() to get new list, and update the data view.
|
||||
DS_EV_CURRENT_DEVICE_CHANGED = 3,
|
||||
};
|
||||
|
||||
typedef unsigned long long sr_device_handle;
|
||||
typedef unsigned long long ds_device_handle;
|
||||
|
||||
/**
|
||||
* Device base info
|
||||
*/
|
||||
struct sr_device_info
|
||||
struct ds_device_info
|
||||
{
|
||||
sr_device_handle handle;
|
||||
ds_device_handle handle;
|
||||
char name[50];
|
||||
int dev_type; // enum sr_device_type
|
||||
int is_current; //is actived
|
||||
};
|
||||
|
||||
struct sr_task_progress
|
||||
struct ds_task_progress
|
||||
{
|
||||
int progress;
|
||||
int is_end;
|
||||
};
|
||||
|
||||
struct sr_store_extra_data
|
||||
struct ds_store_extra_data
|
||||
{
|
||||
char name[50];
|
||||
char *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 -----------------------------------------------*/
|
||||
|
||||
/**
|
||||
* event see enum libsigrok_event_type
|
||||
*/
|
||||
typedef void (*libsigrok_event_callback_t)(int event);
|
||||
typedef void (*dslib_event_callback_t)(int event);
|
||||
|
||||
/**
|
||||
* Data forwarding callback collected by the device.
|
||||
*/
|
||||
typedef void (*ds_datafeed_callback_t)(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet);
|
||||
|
||||
/**
|
||||
* Must call first
|
||||
*/
|
||||
SR_API int sr_lib_init();
|
||||
SR_API int ds_lib_init();
|
||||
|
||||
/**
|
||||
* Free all resource before program exits
|
||||
*/
|
||||
SR_API int sr_lib_exit();
|
||||
SR_API int ds_lib_exit();
|
||||
|
||||
/**
|
||||
* Set event callback, event type see enum libsigrok_event_type
|
||||
*/
|
||||
SR_API void sr_set_event_callback(libsigrok_event_callback_t cb);
|
||||
SR_API void ds_set_event_callback(dslib_event_callback_t cb);
|
||||
|
||||
/**
|
||||
* By default, the library can manage data by itself. If set the callback,
|
||||
* the library will no longer manage data, it just forwards data.
|
||||
* Set the data receive callback.
|
||||
*/
|
||||
SR_API int sr_set_datafeed_callback(sr_datafeed_callback_t cb, void *cb_data);
|
||||
SR_API int ds_set_datafeed_callback(ds_datafeed_callback_t cb);
|
||||
|
||||
/**
|
||||
* Set the firmware binary file directory,
|
||||
* User must call it to set the firmware resource directory
|
||||
*/
|
||||
SR_API void sr_set_firmware_resource_dir(const char *dir);
|
||||
SR_API void ds_set_firmware_resource_dir(const char *dir);
|
||||
|
||||
/**
|
||||
* Get the device list, if the field _handle is 0, the list visited to end.
|
||||
* User need call free() to release the buffer. If the list is empty, the out_list is null.
|
||||
*/
|
||||
SR_API int sr_device_get_list(struct sr_device_info** out_list, int *out_count);
|
||||
SR_API int ds_device_get_list(struct ds_device_info** out_list, int *out_count);
|
||||
|
||||
/**
|
||||
* Active a device, if success, it will trigs the event of SR_EV_CURRENT_DEVICE_CHANGED.
|
||||
*/
|
||||
SR_API int sr_device_select(sr_device_handle handle);
|
||||
SR_API int ds_device_select(ds_device_handle handle);
|
||||
|
||||
/**
|
||||
* Active a device, if success, it will trigs the event of SR_EV_CURRENT_DEVICE_CHANGED.
|
||||
* @index is -1, will select the last one.
|
||||
*/
|
||||
SR_API int sr_device_select_by_index(int index);
|
||||
SR_API int ds_device_select_by_index(int index);
|
||||
|
||||
/**
|
||||
* Create a device from session file, it auto load the data.
|
||||
*/
|
||||
SR_API int sr_device_from_file(const char *file_path);
|
||||
SR_API int ds_device_from_file(const char *file_path);
|
||||
|
||||
/**
|
||||
* Remove one device from the list, and destory it.
|
||||
* User need to call sr_device_get_list() to get the new list.
|
||||
* User need to call ds_device_get_list() to get the new list.
|
||||
*/
|
||||
SR_API int sr_remove_device(sr_device_handle handle);
|
||||
SR_API int ds_remove_device(ds_device_handle handle);
|
||||
|
||||
/**
|
||||
* Get the current device info.
|
||||
* If the current device is not exists, the handle filed will be set null.
|
||||
*/
|
||||
SR_API int sr_get_current_device_info(struct sr_device_info *info);
|
||||
SR_API int ds_get_current_device_info(struct ds_device_info *info);
|
||||
|
||||
/**
|
||||
* Start collect data
|
||||
*/
|
||||
SR_API int sr_device_start_collect();
|
||||
SR_API int ds_device_start_collect();
|
||||
|
||||
/**
|
||||
* Stop collect data
|
||||
*/
|
||||
SR_API int sr_device_stop_collect();
|
||||
SR_API int ds_device_stop_collect();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -61,7 +61,7 @@ SR_PRIV void sr_log_uninit()
|
||||
/**
|
||||
* Use a shared context, and drop the private log context
|
||||
*/
|
||||
SR_API void sr_log_set_context(xlog_context *ctx)
|
||||
SR_API void ds_log_set_context(xlog_context *ctx)
|
||||
{
|
||||
if (ctx){
|
||||
sr_log_uninit();
|
||||
@@ -76,7 +76,7 @@ SR_API void sr_log_set_context(xlog_context *ctx)
|
||||
/**
|
||||
* Set the private log context level
|
||||
*/
|
||||
SR_API void sr_log_level(int level)
|
||||
SR_API void ds_log_level(int level)
|
||||
{
|
||||
log_level_value = level;
|
||||
if (log_ctx)
|
||||
|
||||
@@ -40,12 +40,12 @@ SR_PRIV void sr_log_uninit();
|
||||
/**
|
||||
* Use a shared context, and drop the private log context
|
||||
*/
|
||||
SR_API void sr_log_set_context(xlog_context *ctx);
|
||||
SR_API void ds_log_set_context(xlog_context *ctx);
|
||||
|
||||
/**
|
||||
* Set the private log context level
|
||||
*/
|
||||
SR_API void sr_log_level(int level);
|
||||
SR_API void ds_log_level(int level);
|
||||
|
||||
#define LOG_PREFIX ""
|
||||
#define sr_err(fmt, args...) xlog_err(sr_log, LOG_PREFIX fmt, ## args)
|
||||
|
||||
@@ -97,13 +97,9 @@ SR_API struct sr_session *sr_session_new(void)
|
||||
SR_API int sr_session_destroy(void)
|
||||
{
|
||||
if (!session) {
|
||||
sr_dbg("%s: session was NULL", __func__);
|
||||
sr_detail("%s: session was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_session_dev_remove_all();
|
||||
|
||||
sr_session_datafeed_callback_remove_all();
|
||||
}
|
||||
|
||||
if (session->sources) {
|
||||
g_free(session->sources);
|
||||
@@ -125,159 +121,6 @@ SR_API int sr_session_destroy(void)
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* List all device instances attached to the current session.
|
||||
*
|
||||
* @param devlist A pointer where the device instance list will be
|
||||
* stored on return. If no devices are in the session,
|
||||
* this will be NULL. Each element in the list points
|
||||
* to a struct sr_dev_inst *.
|
||||
* The list must be freed by the caller, but not the
|
||||
* elements pointed to.
|
||||
*
|
||||
* @retval SR_OK Success.
|
||||
* @retval SR_ERR Invalid argument.
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
SR_API int sr_session_dev_list(GSList **devlist)
|
||||
{
|
||||
|
||||
*devlist = NULL;
|
||||
|
||||
if (!session)
|
||||
return SR_ERR;
|
||||
|
||||
*devlist = g_slist_copy(session->devs);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the devices from the current session.
|
||||
*
|
||||
* The session itself (i.e., the struct sr_session) is not free'd and still
|
||||
* exists after this function returns.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
|
||||
*/
|
||||
SR_API int sr_session_dev_remove_all(void)
|
||||
{
|
||||
if (!session) {
|
||||
sr_err("%s: session was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
g_slist_free(session->devs);
|
||||
session->devs = NULL;
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a device instance to the current session.
|
||||
*
|
||||
* @param sdi The device instance to add to the current session. Must not
|
||||
* be NULL. Also, sdi->driver and sdi->driver->dev_open must
|
||||
* not be NULL.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
|
||||
*/
|
||||
SR_API int sr_session_dev_add(struct sr_dev_inst *sdi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!sdi) {
|
||||
sr_err("%s: sdi was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
sr_err("%s: session was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
/* If sdi->driver is NULL, this is a virtual device. */
|
||||
if (!sdi->driver) {
|
||||
sr_dbg("%s: sdi->driver was NULL, this seems to be "
|
||||
"a virtual device; continuing", __func__);
|
||||
/* Just add the device, don't run dev_open(). */
|
||||
session->devs = g_slist_append(session->devs, (gpointer)sdi);
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/* sdi->driver is non-NULL (i.e. we have a real device). */
|
||||
if (!sdi->driver->dev_open) {
|
||||
sr_err("%s: sdi->driver->dev_open was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
session->devs = g_slist_append(session->devs, (gpointer)sdi);
|
||||
|
||||
if (session->running) {
|
||||
/* Adding a device to a running session. Start acquisition
|
||||
* on that device now. */
|
||||
if ((ret = sdi->driver->dev_acquisition_start(sdi,
|
||||
(void *)sdi)) != SR_OK)
|
||||
sr_err("Failed to start acquisition of device in "
|
||||
"running session: %d", ret);
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all datafeed callbacks in the current session.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
|
||||
*/
|
||||
SR_API int sr_session_datafeed_callback_remove_all(void)
|
||||
{
|
||||
if (!session) {
|
||||
sr_err("%s: session was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
g_slist_free_full(session->datafeed_callbacks, g_free);
|
||||
session->datafeed_callbacks = NULL;
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a datafeed callback to the current session.
|
||||
*
|
||||
* @param cb Function to call when a chunk of data is received.
|
||||
* Must not be NULL.
|
||||
* @param cb_data Opaque pointer passed in by the caller.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
|
||||
*/
|
||||
SR_PRIV int sr_session_datafeed_callback_add(sr_datafeed_callback_t cb, void *cb_data)
|
||||
{
|
||||
struct datafeed_callback *cb_struct;
|
||||
|
||||
if (!session) {
|
||||
sr_err("%s: session was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
if (!cb) {
|
||||
sr_err("%s: cb was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
if (!(cb_struct = g_try_malloc0(sizeof(struct datafeed_callback))))
|
||||
return SR_ERR_MALLOC;
|
||||
|
||||
cb_struct->cb = cb;
|
||||
cb_struct->cb_data = cb_data;
|
||||
|
||||
session->datafeed_callbacks =
|
||||
g_slist_append(session->datafeed_callbacks, cb_struct);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call every device in the session's callback.
|
||||
@@ -323,7 +166,7 @@ static int sr_session_iteration(gboolean block)
|
||||
*/
|
||||
g_mutex_lock(&session->stop_mutex);
|
||||
if (session->abort_session) {
|
||||
sr_session_stop_sync();
|
||||
current_device_acquisition_stop();
|
||||
/* But once is enough. */
|
||||
session->abort_session = FALSE;
|
||||
}
|
||||
@@ -333,59 +176,6 @@ static int sr_session_iteration(gboolean block)
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a session.
|
||||
*
|
||||
* There can only be one session at a time.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR upon errors.
|
||||
*/
|
||||
SR_API int sr_session_start(void)
|
||||
{
|
||||
struct sr_dev_inst *sdi;
|
||||
GSList *l;
|
||||
int ret;
|
||||
|
||||
if (!session) {
|
||||
sr_err("%s: session was NULL; a session must be "
|
||||
"created before starting it.", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
if (!session->devs) {
|
||||
sr_err("%s: session->devs was NULL; a session "
|
||||
"cannot be started without devices.", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_info("Starting...");
|
||||
|
||||
ret = SR_OK;
|
||||
for (l = session->devs; l; l = l->next) {
|
||||
sdi = l->data;
|
||||
if ((ret = sdi->driver->dev_acquisition_start(sdi, sdi)) != SR_OK) {
|
||||
sr_err("%s: could not start an acquisition "
|
||||
"(%d)", __func__, sr_error_str(ret));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: What if there are multiple devices? Which return code? */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* check session if be created
|
||||
*/
|
||||
int sr_check_session_start_before(){
|
||||
|
||||
if (!session || !session->devs) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the session.
|
||||
*
|
||||
@@ -398,14 +188,11 @@ SR_API int sr_session_run(void)
|
||||
"created first, before running it.", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
if (!session->devs) {
|
||||
/* TODO: Actually the case? */
|
||||
sr_err("%s: session->devs was NULL; a session "
|
||||
"cannot be run without devices.", __func__);
|
||||
return SR_ERR_BUG;
|
||||
if (session->running == TRUE){
|
||||
sr_err("%s", "Session is running.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
|
||||
session->running = TRUE;
|
||||
|
||||
sr_dbg("Running...");
|
||||
@@ -429,47 +216,13 @@ SR_API int sr_session_run(void)
|
||||
}
|
||||
|
||||
g_mutex_lock(&session->stop_mutex);
|
||||
sr_session_stop_sync();
|
||||
current_device_acquisition_stop();
|
||||
session->abort_session = FALSE;
|
||||
session->running = FALSE;
|
||||
g_mutex_unlock(&session->stop_mutex);
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the current session.
|
||||
*
|
||||
* The current session is stopped immediately, with all acquisition sessions
|
||||
* being stopped and hardware drivers cleaned up.
|
||||
*
|
||||
* This must be called from within the session thread, to prevent freeing
|
||||
* resources that the session thread will try to use.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
|
||||
*/
|
||||
SR_PRIV int sr_session_stop_sync(void)
|
||||
{
|
||||
struct sr_dev_inst *sdi;
|
||||
GSList *l;
|
||||
|
||||
if (!session) {
|
||||
sr_err("%s: session was NULL", __func__);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
sr_info("Stopping.");
|
||||
|
||||
for (l = session->devs; l; l = l->next) {
|
||||
sdi = l->data;
|
||||
if (sdi->driver) {
|
||||
if (sdi->driver->dev_acquisition_stop)
|
||||
sdi->driver->dev_acquisition_stop(sdi, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the current session.
|
||||
*
|
||||
@@ -552,44 +305,6 @@ static void datafeed_dump(const struct sr_datafeed_packet *packet)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to whatever is listening on the datafeed bus.
|
||||
*
|
||||
* Hardware drivers use this to send a data packet to the frontend.
|
||||
*
|
||||
* @param sdi TODO.
|
||||
* @param packet The datafeed packet to send to the session bus.
|
||||
*
|
||||
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet)
|
||||
{
|
||||
GSList *l;
|
||||
struct datafeed_callback *cb_struct;
|
||||
|
||||
if (!sdi) {
|
||||
sr_err("%s: sdi was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
if (!packet) {
|
||||
sr_err("%s: packet was NULL", __func__);
|
||||
return SR_ERR_ARG;
|
||||
}
|
||||
|
||||
for (l = session->datafeed_callbacks; l; l = l->next) {
|
||||
//if (sr_log_loglevel_get() >= SR_LOG_DBG)
|
||||
// datafeed_dump(packet);
|
||||
cb_struct = l->data;
|
||||
cb_struct->cb(sdi, packet, cb_struct->cb_data);
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event source for a file descriptor.
|
||||
*
|
||||
@@ -752,7 +467,8 @@ static int _sr_session_source_remove(gintptr poll_object)
|
||||
g_free(session->sources);
|
||||
session->pollfds = NULL;
|
||||
session->sources = NULL;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (old != session->num_sources) {
|
||||
memmove(&session->pollfds[old], &session->pollfds[old+1],
|
||||
(session->num_sources - old) * sizeof(GPollFD));
|
||||
|
||||
@@ -174,7 +174,7 @@ static void send_error_packet(const struct sr_dev_inst *cb_sdi, struct session_v
|
||||
{
|
||||
packet->type = SR_DF_END;
|
||||
packet->status = SR_PKT_SOURCE_ERROR;
|
||||
sr_session_send(cb_sdi, packet);
|
||||
ds_data_forward(cb_sdi, packet);
|
||||
sr_session_source_remove(-1);
|
||||
close_archive(vdev);
|
||||
}
|
||||
@@ -311,7 +311,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *cb_sdi)
|
||||
}
|
||||
|
||||
vdev->bytes_read += ret;
|
||||
sr_session_send(cb_sdi, &packet);
|
||||
ds_data_forward(cb_sdi, &packet);
|
||||
}
|
||||
else{
|
||||
/* done with this capture file */
|
||||
@@ -335,7 +335,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *cb_sdi)
|
||||
|
||||
if (!vdev || vdev->cur_channel >= vdev->num_probes || revents == -1) {
|
||||
packet.type = SR_DF_END;
|
||||
sr_session_send(cb_sdi, &packet);
|
||||
ds_data_forward(cb_sdi, &packet);
|
||||
sr_session_source_remove(-1);
|
||||
|
||||
if (NULL != vdev){
|
||||
@@ -1006,7 +1006,7 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi,
|
||||
session_trigger.real_pos = vdev->trig_pos;
|
||||
packet.type = SR_DF_TRIGGER;
|
||||
packet.payload = &session_trigger;
|
||||
sr_session_send(sdi, &packet);
|
||||
ds_data_forward(sdi, &packet);
|
||||
}
|
||||
|
||||
/* freewheeling source */
|
||||
|
||||
@@ -159,7 +159,9 @@ SR_API int sr_session_load(const char *filename)
|
||||
/* first device, init the driver */
|
||||
sdi->driver->init(NULL);
|
||||
sr_dev_open(sdi);
|
||||
sr_session_dev_add(sdi);
|
||||
//sr_session_dev_add(sdi);
|
||||
g_assert(0);
|
||||
|
||||
sdi->driver->config_set(SR_CONF_SESSIONFILE,
|
||||
g_variant_new_bytestring(filename), sdi, NULL, NULL);
|
||||
sdi->driver->config_set(SR_CONF_CAPTUREFILE,
|
||||
|
||||
@@ -93,7 +93,7 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
|
||||
header.feed_version = 1;
|
||||
gettimeofday(&header.starttime, NULL);
|
||||
|
||||
if ((ret = sr_session_send(sdi, &packet)) < 0) {
|
||||
if ((ret = ds_data_forward(sdi, &packet)) < 0) {
|
||||
sr_err("%sFailed to send header packet: %d.", prefix, ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ SR_PRIV int std_hw_dev_acquisition_stop_serial(struct sr_dev_inst *sdi,
|
||||
packet.type = SR_DF_END;
|
||||
packet.status = SR_PKT_OK;
|
||||
packet.payload = NULL;
|
||||
if ((ret = sr_session_send(cb_data, &packet)) < 0) {
|
||||
if ((ret = ds_data_forward(cb_data, &packet)) < 0) {
|
||||
sr_err("%sFailed to send SR_DF_END packet: %d.", prefix, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ int main()
|
||||
{
|
||||
xlog_context *log_ctx = xlog_new2(0);
|
||||
|
||||
sr_log_level(XLOG_LEVEL_INFO);
|
||||
sr_log_set_context(log_ctx);
|
||||
ds_log_level(XLOG_LEVEL_INFO);
|
||||
ds_log_set_context(log_ctx);
|
||||
|
||||
xlog_add_receiver(log_ctx, print_log, 0);
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ struct ds_trigger *trigger = NULL;
|
||||
*
|
||||
* @return SR_OK upon success.
|
||||
*/
|
||||
SR_API int ds_trigger_init(void)
|
||||
SR_PRIV int ds_trigger_init(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
@@ -83,7 +83,7 @@ SR_API int ds_trigger_init(void)
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
SR_API int ds_trigger_destroy(void)
|
||||
SR_PRIV int ds_trigger_destroy(void)
|
||||
{
|
||||
if (trigger)
|
||||
g_free(trigger);
|
||||
@@ -91,15 +91,6 @@ SR_API int ds_trigger_destroy(void)
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
SR_API struct ds_trigger *ds_trigger_get(void)
|
||||
{
|
||||
return trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* set trigger based on stage
|
||||
@@ -111,6 +102,11 @@ SR_API int ds_trigger_stage_set_value(uint16_t stage, uint16_t probes, char *tri
|
||||
assert(stage < TriggerStages);
|
||||
assert(probes <= MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_stage_set_value() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
int j;
|
||||
|
||||
for (j = 0; j< probes; j++) {
|
||||
@@ -125,6 +121,11 @@ SR_API int ds_trigger_stage_set_logic(uint16_t stage, uint16_t probes, unsigned
|
||||
assert(stage < TriggerStages);
|
||||
assert(probes <= MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_stage_set_logic() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger_logic[stage] = trigger_logic;
|
||||
|
||||
return SR_OK;
|
||||
@@ -134,6 +135,11 @@ SR_API int ds_trigger_stage_set_inv(uint16_t stage, uint16_t probes, unsigned ch
|
||||
assert(stage < TriggerStages);
|
||||
assert(probes <= MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_stage_set_inv() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger0_inv[stage] = trigger0_inv;
|
||||
trigger->trigger1_inv[stage] = trigger1_inv;
|
||||
|
||||
@@ -144,6 +150,11 @@ SR_API int ds_trigger_stage_set_count(uint16_t stage, uint16_t probes, uint32_t
|
||||
assert(stage < TriggerStages);
|
||||
assert(probes <= MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_stage_set_count() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger0_count[stage] = trigger0_count;
|
||||
trigger->trigger1_count[stage] = trigger1_count;
|
||||
|
||||
@@ -159,6 +170,11 @@ SR_API int ds_trigger_probe_set(uint16_t probe, unsigned char trigger0, unsigned
|
||||
{
|
||||
assert(probe < MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_probe_set() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger0[TriggerStages][probe] = trigger0;
|
||||
trigger->trigger1[TriggerStages][probe] = trigger1;
|
||||
|
||||
@@ -174,6 +190,11 @@ SR_API int ds_trigger_set_stage(uint16_t stages)
|
||||
{
|
||||
assert(stages <= TriggerStages);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_set_stage() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger_stages = stages;
|
||||
|
||||
return SR_OK;
|
||||
@@ -188,6 +209,11 @@ SR_API int ds_trigger_set_pos(uint16_t position)
|
||||
{
|
||||
assert(position <= 100);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_set_pos() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger_pos = position;
|
||||
|
||||
return SR_OK;
|
||||
@@ -200,6 +226,11 @@ SR_API int ds_trigger_set_pos(uint16_t position)
|
||||
*/
|
||||
SR_API uint16_t ds_trigger_get_pos()
|
||||
{
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_pos() error, trigger have'nt be inited.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return trigger->trigger_pos;
|
||||
}
|
||||
|
||||
@@ -210,6 +241,10 @@ SR_API uint16_t ds_trigger_get_pos()
|
||||
*/
|
||||
SR_API int ds_trigger_set_en(uint16_t enable)
|
||||
{
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_set_en() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger_en = enable;
|
||||
|
||||
@@ -236,6 +271,10 @@ SR_API uint16_t ds_trigger_get_en()
|
||||
*/
|
||||
SR_API int ds_trigger_set_mode(uint16_t mode)
|
||||
{
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_set_en() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
trigger->trigger_mode = mode;
|
||||
|
||||
@@ -251,6 +290,11 @@ SR_PRIV uint16_t ds_trigger_get_mask0(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
assert(lsc <= msc);
|
||||
assert(msc < MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_mask0() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
uint16_t mask = 0;
|
||||
const uint16_t qutr_mask = (0xffff >> (TriggerProbes - TriggerProbes/4));
|
||||
const uint16_t half_mask = (0xffff >> (TriggerProbes - TriggerProbes/2));
|
||||
@@ -278,6 +322,11 @@ SR_PRIV uint16_t ds_trigger_get_mask1(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
assert(lsc <= msc);
|
||||
assert(msc < MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_mask1() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
uint16_t mask = 0;
|
||||
const uint16_t qutr_mask = (0xffff >> (TriggerProbes - TriggerProbes/4));
|
||||
const uint16_t half_mask = (0xffff >> (TriggerProbes - TriggerProbes/2));
|
||||
@@ -305,6 +354,11 @@ SR_PRIV uint16_t ds_trigger_get_value0(uint16_t stage, uint16_t msc, uint16_t ls
|
||||
assert(lsc <= msc);
|
||||
assert(msc < MaxTriggerProbes);
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_value0() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
uint16_t value = 0;
|
||||
const uint16_t qutr_mask = (0xffff >> (TriggerProbes - TriggerProbes/4));
|
||||
const uint16_t half_mask = (0xffff >> (TriggerProbes - TriggerProbes/2));
|
||||
@@ -337,6 +391,11 @@ SR_PRIV uint16_t ds_trigger_get_value1(uint16_t stage, uint16_t msc, uint16_t ls
|
||||
const uint16_t half_mask = (0xffff >> (TriggerProbes - TriggerProbes/2));
|
||||
int i;
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_value1() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
for (i = msc; i >= lsc ; i--) {
|
||||
value = (value << 1);
|
||||
value += ((trigger->trigger1[stage][i] == '1') | (trigger->trigger1[stage][i] == 'R'));
|
||||
@@ -364,6 +423,11 @@ SR_PRIV uint16_t ds_trigger_get_edge0(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
const uint16_t half_mask = (0xffff >> (TriggerProbes - TriggerProbes/2));
|
||||
int i;
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_edge0() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
for (i = msc; i >= lsc ; i--) {
|
||||
edge = (edge << 1);
|
||||
edge += ((trigger->trigger0[stage][i] == 'R') | (trigger->trigger0[stage][i] == 'F') |
|
||||
@@ -392,6 +456,11 @@ SR_PRIV uint16_t ds_trigger_get_edge1(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
const uint16_t half_mask = (0xffff >> (TriggerProbes - TriggerProbes/2));
|
||||
int i;
|
||||
|
||||
if (trigger == NULL){
|
||||
sr_err("%s", "ds_trigger_get_edge1() error, trigger have'nt be inited.");
|
||||
return SR_ERR_CALL_STATUS;
|
||||
}
|
||||
|
||||
for (i = msc; i >= lsc ; i--) {
|
||||
edge = (edge << 1);
|
||||
edge += ((trigger->trigger1[stage][i] == 'R') | (trigger->trigger1[stage][i] == 'F') |
|
||||
|
||||
Reference in New Issue
Block a user