X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdemo%2Fapi.c;h=c5259b286144621d6f763ec611b7045df7ab49f2;hb=3e7fb88f21d9b6d87652af2d988c83d8481592de;hp=4d95ddda3f13776ee30973445ed6e3e95d8fc521;hpb=a9010323ddf4e479663e871386c05db05ea3522e;p=libsigrok.git diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 4d95ddda..c5259b28 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -46,17 +46,17 @@ static const char *logic_pattern_str[] = { "squid", }; +static const uint32_t scanopts[] = { + SR_CONF_NUM_LOGIC_CHANNELS, + SR_CONF_NUM_ANALOG_CHANNELS, +}; + static const uint32_t drvopts[] = { SR_CONF_DEMO_DEV, SR_CONF_LOGIC_ANALYZER, SR_CONF_OSCILLOSCOPE, }; -static const uint32_t scanopts[] = { - SR_CONF_NUM_LOGIC_CHANNELS, - SR_CONF_NUM_ANALOG_CHANNELS, -}; - static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, @@ -197,8 +197,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; @@ -257,16 +257,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; @@ -293,21 +291,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,40 +337,18 @@ 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; - GVariant *gvar; - GVariantBuilder gvb; - - if (key == SR_CONF_SCAN_OPTIONS) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - return SR_OK; - } - - if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); - return SR_OK; - } - - if (!sdi) - return SR_ERR_ARG; if (!cg) { switch (key) { + case SR_CONF_SCAN_OPTIONS: case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); case SR_CONF_SAMPLERATE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, - ARRAY_SIZE(samplerates), sizeof(uint64_t)); - g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar); - *data = g_variant_builder_end(&gvb); + *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates)); break; default: return SR_ERR_NA; @@ -394,18 +358,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_DEVICE_OPTIONS: if (ch->type == SR_CHANNEL_LOGIC) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_logic, ARRAY_SIZE(devopts_cg_logic), - sizeof(uint32_t)); + *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_logic)); else if (ch->type == SR_CHANNEL_ANALOG) { if (strcmp(cg->name, "Analog") == 0) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_analog_group, ARRAY_SIZE(devopts_cg_analog_group), - sizeof(uint32_t)); + *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog_group)); else - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_analog_channel, ARRAY_SIZE(devopts_cg_analog_channel), - sizeof(uint32_t)); + *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog_channel)); } else return SR_ERR_BUG; @@ -416,11 +374,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return SR_ERR_NA; if (ch->type == SR_CHANNEL_LOGIC) - *data = g_variant_new_strv(logic_pattern_str, - ARRAY_SIZE(logic_pattern_str)); + *data = g_variant_new_strv(ARRAY_AND_SIZE(logic_pattern_str)); else if (ch->type == SR_CHANNEL_ANALOG) - *data = g_variant_new_strv(analog_pattern_str, - ARRAY_SIZE(analog_pattern_str)); + *data = g_variant_new_strv(ARRAY_AND_SIZE(analog_pattern_str)); else return SR_ERR_BUG; break; @@ -444,6 +400,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 @@ -497,6 +454,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) std_session_send_df_header(sdi); + if (SAMPLES_PER_FRAME > 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; @@ -508,6 +468,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { sr_session_source_remove(sdi->session, -1); + + if (SAMPLES_PER_FRAME > 0) + std_session_send_frame_end(sdi); + std_session_send_df_end(sdi); return SR_OK;