X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdemo%2Fapi.c;h=a44aa0985141bf11a13d15005f29790f94247c61;hb=9bf093011ae7692c4808d52f540b4be23b89ffcf;hp=fcf61cb3f54d1c2b9727a50cd4e7579d835fb2b6;hpb=53012da658ae94b245240c8a3e115723eede4c7d;p=libsigrok.git diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index fcf61cb3..a44aa098 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -44,11 +44,13 @@ static const char *logic_pattern_str[] = { "all-low", "all-high", "squid", + "graycode", }; static const uint32_t scanopts[] = { SR_CONF_NUM_LOGIC_CHANNELS, SR_CONF_NUM_ANALOG_CHANNELS, + SR_CONF_LIMIT_FRAMES, }; static const uint32_t drvopts[] = { @@ -61,6 +63,7 @@ static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, + SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_AVERAGING | SR_CONF_GET | SR_CONF_SET, SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET, @@ -95,10 +98,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct analog_gen *ag; GSList *l; int num_logic_channels, num_analog_channels, pattern, i; + uint64_t limit_frames; char channel_name[16]; num_logic_channels = DEFAULT_NUM_LOGIC_CHANNELS; num_analog_channels = DEFAULT_NUM_ANALOG_CHANNELS; + limit_frames = DEFAULT_LIMIT_FRAMES; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { @@ -108,6 +113,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) case SR_CONF_NUM_ANALOG_CHANNELS: num_analog_channels = g_variant_get_int32(src->data); break; + case SR_CONF_LIMIT_FRAMES: + limit_frames = g_variant_get_uint64(src->data); + break; } } @@ -119,8 +127,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devc->cur_samplerate = SR_KHZ(200); devc->num_logic_channels = num_logic_channels; devc->logic_unitsize = (devc->num_logic_channels + 7) / 8; + devc->all_logic_channels_mask = 1UL << 0; + devc->all_logic_channels_mask <<= devc->num_logic_channels; + devc->all_logic_channels_mask--; devc->logic_pattern = DEFAULT_LOGIC_PATTERN; devc->num_analog_channels = num_analog_channels; + devc->limit_frames = limit_frames; if (num_logic_channels > 0) { /* Logic channels, all in one channel group. */ @@ -197,8 +209,8 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper); } -static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_get(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct sr_channel *ch; @@ -219,6 +231,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s case SR_CONF_LIMIT_MSEC: *data = g_variant_new_uint64(devc->limit_msec); break; + case SR_CONF_LIMIT_FRAMES: + *data = g_variant_new_uint64(devc->limit_frames); + break; case SR_CONF_AVERAGING: *data = g_variant_new_boolean(devc->avg); break; @@ -257,16 +272,14 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_set(uint32_t key, GVariant *data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct analog_gen *ag; struct sr_channel *ch; GSList *l; int logic_pattern, analog_pattern; - unsigned int i; - const char *stropt; devc = sdi->priv; @@ -282,6 +295,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd devc->limit_msec = g_variant_get_uint64(data); devc->limit_samples = 0; break; + case SR_CONF_LIMIT_FRAMES: + devc->limit_frames = g_variant_get_uint64(data); + break; case SR_CONF_AVERAGING: devc->avg = g_variant_get_boolean(data); sr_dbg("%s averaging", devc->avg ? "Enabling" : "Disabling"); @@ -293,21 +309,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd case SR_CONF_PATTERN_MODE: if (!cg) return SR_ERR_CHANNEL_GROUP; - stropt = g_variant_get_string(data, NULL); - logic_pattern = analog_pattern = -1; - for (i = 0; i < ARRAY_SIZE(logic_pattern_str); i++) { - if (!strcmp(stropt, logic_pattern_str[i])) { - logic_pattern = i; - break; - } - } - for (i = 0; i < ARRAY_SIZE(analog_pattern_str); i++) { - if (!strcmp(stropt, analog_pattern_str[i])) { - analog_pattern = i; - break; - } - } - if (logic_pattern == -1 && analog_pattern == -1) + logic_pattern = std_str_idx(data, ARRAY_AND_SIZE(logic_pattern_str)); + analog_pattern = std_str_idx(data, ARRAY_AND_SIZE(analog_pattern_str)); + if (logic_pattern < 0 && analog_pattern < 0) return SR_ERR_ARG; for (l = cg->channels; l; l = l->next) { ch = l->data; @@ -351,8 +355,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return SR_OK; } -static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct sr_channel *ch; @@ -414,6 +418,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc = sdi->priv; devc->sent_samples = 0; + devc->sent_frame_samples = 0; /* * Determine the numbers of logic and analog channels that are @@ -467,6 +472,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) std_session_send_df_header(sdi); + if (devc->limit_frames > 0) + std_session_send_frame_begin(sdi); + /* We use this timestamp to decide how many more samples to send. */ devc->start_us = g_get_monotonic_time(); devc->spent_us = 0; @@ -477,7 +485,14 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { + struct dev_context *devc; + sr_session_source_remove(sdi->session, -1); + + devc = sdi->priv; + if (devc->limit_frames > 0) + std_session_send_frame_end(sdi); + std_session_send_df_end(sdi); return SR_OK;