X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdemo%2Fapi.c;h=d0abe4ff92e053f111c6cb44b7cc9e66f9aa0f50;hb=03733430464abbc8eb23d50c8bef822dcd2ee20b;hp=e9c504a2aca826c5afb35b9f0022827297c23d2b;hpb=463160cbca37367ef94dfead0c64531d82b83ab8;p=libsigrok.git diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index e9c504a2..d0abe4ff 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -44,6 +44,7 @@ static const char *logic_pattern_str[] = { "all-low", "all-high", "squid", + "graycode", }; static const uint32_t scanopts[] = { @@ -119,6 +120,9 @@ 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; @@ -197,8 +201,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 +261,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 +295,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 +341,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; @@ -362,7 +352,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * case SR_CONF_DEVICE_OPTIONS: return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); case SR_CONF_SAMPLERATE: - *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates)); + *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates)); break; default: return SR_ERR_NA; @@ -372,18 +362,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; @@ -394,11 +378,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; @@ -422,6 +404,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 @@ -475,6 +458,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; @@ -486,6 +472,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;