X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=505f10e4f2ebd461a50fea41ec1d16f1639a92ee;hp=d51c893ebbc10fe58e6f28aebc06da4fe35a1ff7;hb=15d920a97c10e6f04147094b48936468fac910b0;hpb=878e90d9779a1881840454e2ad7bd90a4b470221 diff --git a/sigrok-cli.c b/sigrok-cli.c index d51c893..505f10e 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -93,8 +93,9 @@ static void show_version(void) int i; printf("sigrok-cli %s\n\n", VERSION); + printf("Supported hardware drivers:\n"); - plugins = sr_list_hwplugins(); + plugins = sr_hwplugins_list(); for (p = plugins; p; p = p->next) { plugin = p->data; printf(" %-20s %s\n", plugin->name, plugin->longname); @@ -113,24 +114,24 @@ static void show_version(void) printf(" %-20s %s\n", outputs[i]->id, outputs[i]->description); printf("\n"); - /* TODO: Error handling. */ - srd_init(); - - printf("Supported protocol decoders:\n"); - for (l = srd_list_decoders(); l; l = l->next) { - dec = l->data; - printf(" %-20s %s\n", dec->id, dec->longname); + if (srd_init(NULL) == SRD_OK) { + printf("Supported protocol decoders:\n"); + srd_load_all_decoders(); + for (l = srd_list_decoders(); l; l = l->next) { + dec = l->data; + printf(" %-20s %s\n", dec->id, dec->longname); + } + srd_exit(); } printf("\n"); - srd_exit(); } static void print_device_line(const struct sr_device *device) { const struct sr_device_instance *sdi; - sr_device_get_info(device, SR_DI_INSTANCE, (const void **) &sdi); + sr_dev_info_get(device, SR_DI_INSTANCE, (const void **)&sdi); if (sdi->vendor && sdi->vendor[0]) printf("%s ", sdi->vendor); @@ -150,7 +151,7 @@ static void show_device_list(void) int devcnt; devcnt = 0; - devices = sr_device_list(); + devices = sr_dev_list(); if (g_slist_length(devices) == 0) return; @@ -159,7 +160,7 @@ static void show_device_list(void) demo_device = NULL; for (l = devices; l; l = l->next) { device = l->data; - if (sr_device_has_hwcap(device, SR_HWCAP_DEMO_DEVICE)) { + if (sr_dev_has_hwcap(device, SR_HWCAP_DEMO_DEVICE)) { demo_device = device; continue; } @@ -189,8 +190,8 @@ static void show_device_detail(void) print_device_line(device); - if (sr_device_get_info(device, SR_DI_TRIGGER_TYPES, - (const void **) &charopts) == SR_OK) { + if (sr_dev_info_get(device, SR_DI_TRIGGER_TYPES, + (const void **)&charopts) == SR_OK) { printf("Supported triggers: "); while (*charopts) { printf("%c ", *charopts); @@ -202,7 +203,7 @@ static void show_device_detail(void) title = "Supported options:\n"; capabilities = device->plugin->get_capabilities(); for (cap = 0; capabilities[cap]; cap++) { - if (!(hwo = sr_find_hwcap_option(capabilities[cap]))) + if (!(hwo = sr_hwplugins_hwcap_get(capabilities[cap]))) continue; if (title) { @@ -212,8 +213,8 @@ static void show_device_detail(void) if (hwo->capability == SR_HWCAP_PATTERN_MODE) { printf(" %s", hwo->shortname); - if (sr_device_get_info(device, SR_DI_PATTERNMODES, - (const void **) &stropts) == SR_OK) { + if (sr_dev_info_get(device, SR_DI_PATTERNMODES, + (const void **)&stropts) == SR_OK) { printf(" - supported modes:\n"); for (i = 0; stropts[i]; i++) printf(" %s\n", stropts[i]); @@ -223,8 +224,8 @@ static void show_device_detail(void) } else if (hwo->capability == SR_HWCAP_SAMPLERATE) { printf(" %s", hwo->shortname); /* Supported samplerates */ - if (sr_device_get_info(device, SR_DI_SAMPLERATES, - (const void **) &samplerates) != SR_OK) { + if (sr_dev_info_get(device, SR_DI_SAMPLERATES, + (const void **)&samplerates) != SR_OK) { printf("\n"); continue; } @@ -234,17 +235,17 @@ static void show_device_detail(void) if (!(s = sr_samplerate_string(samplerates->low))) continue; printf(" (%s", s); - free(s); + g_free(s); /* high */ if (!(s = sr_samplerate_string(samplerates->high))) continue; printf(" - %s", s); - free(s); + g_free(s); /* step */ if (!(s = sr_samplerate_string(samplerates->step))) continue; printf(" in steps of %s)\n", s); - free(s); + g_free(s); } else { printf(" - supported samplerates:\n"); for (i = 0; samplerates->list[i]; i++) { @@ -313,7 +314,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac case SR_DF_HEADER: g_message("cli: Received SR_DF_HEADER"); /* Initialize the output module. */ - if (!(o = malloc(sizeof(struct sr_output)))) { + if (!(o = g_try_malloc(sizeof(struct sr_output)))) { printf("Output module malloc failed.\n"); exit(1); } @@ -370,7 +371,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac if (output_len) { if (outfile) fwrite(output_buf, 1, output_len, outfile); - free(output_buf); + g_free(output_buf); output_len = 0; } } @@ -383,7 +384,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac sr_session_halt(); if (outfile && outfile != stdout) fclose(outfile); - free(o); + g_free(o); o = NULL; break; case SR_DF_TRIGGER: @@ -447,7 +448,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac o->format->data(o, filter_out, filter_out_len, &output_buf, &output_len); if (output_len) { fwrite(output_buf, 1, output_len, outfile); - free(output_buf); + g_free(output_buf); } } @@ -484,8 +485,12 @@ static int register_pds(struct sr_device *device, const char *pdstring) pd_name = g_strdup(g_hash_table_lookup(pd_opthash, "sigrok_key")); g_hash_table_remove(pd_opthash, "sigrok_key"); + if (srd_load_decoder(pd_name) != SRD_OK) { + fprintf(stderr, "Failed to load protocol decoder %s\n", pd_name); + goto err_out; + } if (!(di = srd_inst_new(pd_name, pd_opthash))) { - fprintf(stderr, "Failed to instantiate PD %s\n", pd_name); + fprintf(stderr, "Failed to instantiate protocol decoder %s\n", pd_name); goto err_out; } g_datalist_set_data(&pd_ann_visible, di->inst_id, pd_name); @@ -510,11 +515,14 @@ err_out: return 0; } -void show_pd_annotation(struct srd_proto_data *pdata) +void show_pd_annotation(struct srd_proto_data *pdata, void *user_data) { int i; char **annotations; + /* 'user_data' is not used in this specific callback. */ + (void)user_data; + if (pdata->ann_format != 0) { /* CLI only shows the default annotation format. */ return; @@ -556,10 +564,10 @@ static int select_probes(struct sr_device *device) for (i = 0; i < max_probes; i++) { if (probelist[i]) { - sr_device_probe_name(device, i + 1, probelist[i]); + sr_dev_probe_name(device, i + 1, probelist[i]); g_free(probelist[i]); } else { - probe = sr_device_probe_find(device, i + 1); + probe = sr_dev_probe_find(device, i + 1); probe->enabled = FALSE; } } @@ -646,7 +654,7 @@ static void load_input_file_format(void) } /* Initialize the input module. */ - if (!(in = malloc(sizeof(struct sr_input)))) { + if (!(in = g_try_malloc(sizeof(struct sr_input)))) { printf("Failed to allocate input module.\n"); exit(1); } @@ -703,10 +711,10 @@ int num_real_devices(void) int num_devices; num_devices = 0; - devices = sr_device_list(); + devices = sr_dev_list(); for (l = devices; l; l = l->next) { device = l->data; - if (!sr_device_has_hwcap(device, SR_HWCAP_DEMO_DEVICE)) + if (!sr_dev_has_hwcap(device, SR_HWCAP_DEMO_DEVICE)) num_devices++; } @@ -779,7 +787,7 @@ static void run_session(void) { struct sr_device *device; GHashTable *devargs; - int num_devices, max_probes, *capabilities, i; + int num_devices, max_probes, i; uint64_t time_msec; char **probelist, *devspec; @@ -829,8 +837,7 @@ static void run_session(void) return; if (opt_continuous) { - capabilities = device->plugin->get_capabilities(); - if (!sr_find_hwcap(capabilities, SR_HWCAP_CONTINUOUS)) { + if (!sr_hwplugin_has_hwcap(device->plugin, SR_HWCAP_CONTINUOUS)) { printf("This device does not support continuous sampling."); sr_session_destroy(); return; @@ -847,7 +854,7 @@ static void run_session(void) max_probes = g_slist_length(device->probes); for (i = 0; i < max_probes; i++) { if (probelist[i]) { - sr_device_trigger_set(device, i + 1, probelist[i]); + sr_dev_trigger_set(device, i + 1, probelist[i]); g_free(probelist[i]); } } @@ -862,8 +869,7 @@ static void run_session(void) return; } - capabilities = device->plugin->get_capabilities(); - if (sr_find_hwcap(capabilities, SR_HWCAP_LIMIT_MSEC)) { + if (sr_hwplugin_has_hwcap(device->plugin, SR_HWCAP_LIMIT_MSEC)) { if (device->plugin->set_configuration(device->plugin_index, SR_HWCAP_LIMIT_MSEC, &time_msec) != SR_OK) { printf("Failed to configure time limit.\n"); @@ -876,12 +882,12 @@ static void run_session(void) * convert to samples based on the samplerate. */ limit_samples = 0; - if (sr_device_has_hwcap(device, SR_HWCAP_SAMPLERATE)) { + if (sr_dev_has_hwcap(device, SR_HWCAP_SAMPLERATE)) { const uint64_t *samplerate; - sr_device_get_info(device, SR_DI_CUR_SAMPLERATE, - (const void **) &samplerate); - limit_samples = (*samplerate) * time_msec / (uint64_t) 1000; + sr_dev_info_get(device, SR_DI_CUR_SAMPLERATE, + (const void **)&samplerate); + limit_samples = (*samplerate) * time_msec / (uint64_t)1000; } if (limit_samples == 0) { printf("Not enough time at this samplerate.\n"); @@ -1003,7 +1009,7 @@ int main(int argc, char **argv) return 1; if (opt_pds) { - if (srd_init() != SRD_OK) { + if (srd_init(NULL) != SRD_OK) { printf("Failed to initialize sigrokdecode\n"); return 1; } @@ -1012,7 +1018,7 @@ int main(int argc, char **argv) return 1; } if (srd_register_callback(SRD_OUTPUT_ANN, - show_pd_annotation) != SRD_OK) { + show_pd_annotation, NULL) != SRD_OK) { printf("Failed to register protocol decoder callback\n"); return 1; }