int cmd_version(struct cli_state *state, int argc, char **argv) { int status; struct bladerf_version fw_version, fpga_version, lib_version; bool fpga_loaded = false; bladerf_version(&lib_version); printf("\n"); printf(" bladeRF-cli version: " BLADERF_CLI_VERSION "\n"); printf(" libbladeRF version: %s\n", lib_version.describe); printf("\n"); /* Exit cleanly if no device is attached */ if (state->dev == NULL) { printf(" Device version information unavailable: No device attached.\n"); return 0; } status = bladerf_is_fpga_configured(state->dev); if (status < 0) { state->last_lib_error = status; return CLI_RET_LIBBLADERF; } else if (status != 0) { fpga_loaded = true; status = bladerf_fpga_version(state->dev, &fpga_version); if (status < 0) { state->last_lib_error = status; return CLI_RET_LIBBLADERF; } } status = bladerf_fw_version(state->dev, &fw_version); if (status < 0) { state->last_lib_error = status; return CLI_RET_LIBBLADERF; } printf(" Firmware version: %s\n", fw_version.describe); if (fpga_loaded) { printf(" FPGA version: %s\n", fpga_version.describe); } else { printf(" FPGA version: Unknown (FPGA not loaded)\n"); } printf("\n"); return CLI_RET_OK; }
int main(void) { #ifdef LIBBLADERF_API_VERSION struct bladerf_version api_ver; #endif struct bladerf_version lib_ver; /* Fetch the version from the library */ bladerf_version(&lib_ver); printf("libbladeRF version values: %u.%u.%u\n", lib_ver.major, lib_ver.minor, lib_ver.patch); printf("libbladeRF version description: %s\n", lib_ver.describe); /* Fetch the version from the header */ #ifdef LIBBLADERF_API_VERSION api_ver.major = (LIBBLADERF_API_VERSION >> 24) & 0xff; api_ver.minor = (LIBBLADERF_API_VERSION >> 16) & 0xff; api_ver.patch = (LIBBLADERF_API_VERSION >> 8) & 0xff; printf("libbladeRF version from header: %u.%u.%u(.%u)\n", api_ver.major, api_ver.minor, api_ver.patch, LIBBLADERF_API_VERSION & 0xff); if (lib_ver.major != api_ver.major) { fprintf(stderr, "Library and API header mismatch: major\n"); return 1; } if (lib_ver.minor != api_ver.minor) { fprintf(stderr, "Library and API header mismatch: major\n"); return 1; } if (lib_ver.patch != api_ver.patch) { fprintf(stderr, "Library and API header mismatch: major\n"); return 1; } return 0; #else printf("libbladeRF API header does not define LIBBLADERF_API_VERSION.\n"); return 1; #endif }
int main(int argc, char *argv[]) { int status = 0; struct rc_config rc; struct cli_state *state; bool exit_immediately = false; /* If no actions are specified, just show the usage text and exit */ if (argc == 1) { usage(argv[0]); return 0; } init_rc_config(&rc); if (get_rc_config(argc, argv, &rc)) { return 1; } state = cli_state_create(); if (!state) { fprintf(stderr, "Failed to create state object\n"); return 1; } bladerf_log_set_verbosity(rc.verbosity); if (rc.show_help) { usage(argv[0]); exit_immediately = true; } else if (rc.show_version) { printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { struct bladerf_version version; bladerf_version(&version); printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe"); exit_immediately = true; } if (!exit_immediately) { /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); if (status) { fprintf(stderr, "Could not open device\n"); goto main__issues ; } status = flash_fw(&rc, state, status); if (status) { fprintf(stderr, "Could not flash firmware\n"); goto main__issues ; } status = flash_fpga(&rc, state, status); if (status) { fprintf(stderr, "Could not flash fpga\n"); goto main__issues ; } status = load_fpga(&rc, state, status); if (status) { fprintf(stderr, "Could not load fpga\n"); goto main__issues ; } status = open_script(&rc, state, status); if (status) { fprintf(stderr, "Could not load scripts\n"); goto main__issues ; } main__issues: /* These items are no longer needed */ free(rc.device); rc.device = NULL; free(rc.fw_file); rc.fw_file = NULL; free(rc.fpga_file); rc.fpga_file = NULL; free(rc.script_file); rc.script_file = NULL; /* Drop into interactive mode or begin executing commands * from a script. If we're not requested to do either, exit cleanly */ if (rc.interactive_mode || state->script != NULL) { status = interactive(state, !rc.interactive_mode); } } cli_state_destroy(state); return status; }
int main(int argc, char *argv[]) { int status = 0; struct rc_config rc; struct cli_state *state; bool exit_immediately = false; struct str_queue exec_list; /* If no actions are specified, just show the usage text and exit */ if (argc == 1) { usage(argv[0]); return 0; } str_queue_init(&exec_list); init_rc_config(&rc); if (get_rc_config(argc, argv, &rc, &exec_list)) { return 1; } state = cli_state_create(); if (!state) { fprintf(stderr, "Failed to create state object\n"); return 1; } state->exec_list = &exec_list; bladerf_log_set_verbosity(rc.verbosity); if (rc.show_help) { usage(argv[0]); exit_immediately = true; } else if (rc.show_help_interactive) { printf("Interactive Commands:\n\n"); cmd_show_help_all(); exit_immediately = true; } else if (rc.show_version) { printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { struct bladerf_version version; bladerf_version(&version); printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe strict"); exit_immediately = true; } if (!exit_immediately) { check_for_bootloader_devs(); /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); if (status) { goto main_issues; } status = flash_fw(&rc, state, status); if (status) { goto main_issues; } status = flash_fpga(&rc, state, status); if (status) { goto main_issues; } status = load_fpga(&rc, state, status); if (status) { goto main_issues; } if (rc.script_file) { status = cli_open_script(&state->scripts, rc.script_file); if (status != 0) { fprintf(stderr, "Failed to open script file \"%s\": %s\n", rc.script_file, strerror(-status)); goto main_issues; } } /* Drop into interactive mode or begin executing commands from a a * command-line list or a script. If we're not requested to do either, * exit cleanly */ if (!str_queue_empty(&exec_list) || rc.interactive_mode || cli_script_loaded(state->scripts)) { status = cli_start_tasks(state); if (status == 0) { status = input_loop(state, rc.interactive_mode); } } } main_issues: cli_state_destroy(state); str_queue_deinit(&exec_list); deinit_rc_config(&rc); return status; }