diff --git a/src/systemcmds/bl_update/CMakeLists.txt b/src/systemcmds/bl_update/CMakeLists.txt index c3ea9ccf17..7e0ddc5075 100644 --- a/src/systemcmds/bl_update/CMakeLists.txt +++ b/src/systemcmds/bl_update/CMakeLists.txt @@ -37,5 +37,5 @@ px4_add_module( COMPILE_FLAGS -Wno-cast-align # TODO: fix and enable SRCS - bl_update.c + bl_update.cpp ) diff --git a/src/systemcmds/bl_update/bl_update.c b/src/systemcmds/bl_update/bl_update.cpp similarity index 97% rename from src/systemcmds/bl_update/bl_update.c rename to src/systemcmds/bl_update/bl_update.cpp index d83e449f88..535402a468 100644 --- a/src/systemcmds/bl_update/bl_update.c +++ b/src/systemcmds/bl_update/bl_update.cpp @@ -66,8 +66,6 @@ # define STM_RAM_BASE STM32_SRAM_BASE #endif -__EXPORT int bl_update_main(int argc, char *argv[]); - #if defined (CONFIG_STM32_STM32F4XXX) || defined (CONFIG_ARCH_CHIP_STM32F7) || \ defined (CONFIG_ARCH_CHIP_STM32H7) @@ -90,8 +88,7 @@ static void print_usage(const char *reason) #endif // defined (CONFIG_STM32_STM32F4XXX) || defined (CONFIG_ARCH_CHIP_STM32F7) -int -bl_update_main(int argc, char *argv[]) +extern "C" __EXPORT int bl_update_main(int argc, char *argv[]) { #if !(defined (CONFIG_STM32_STM32F4XXX) || defined (CONFIG_ARCH_CHIP_STM32F7) \ || defined (CONFIG_ARCH_CHIP_STM32H7)) @@ -144,9 +141,9 @@ bl_update_main(int argc, char *argv[]) image_size = (file_size + page_size) & ~page_size; #endif - uint8_t *buf = malloc(image_size); + uint8_t *buf = (uint8_t *)malloc(image_size); - if (buf == NULL) + if (buf == nullptr) { PX4_ERR("failed to allocate %jd bytes for firmware buffer", (intmax_t) file_size); close(fd); diff --git a/src/systemcmds/dumpfile/CMakeLists.txt b/src/systemcmds/dumpfile/CMakeLists.txt index 28b589b2d2..e8a7c1c5ac 100644 --- a/src/systemcmds/dumpfile/CMakeLists.txt +++ b/src/systemcmds/dumpfile/CMakeLists.txt @@ -36,7 +36,7 @@ px4_add_module( STACK_MAIN 4096 COMPILE_FLAGS SRCS - dumpfile.c + dumpfile.cpp DEPENDS ) diff --git a/src/systemcmds/dumpfile/dumpfile.c b/src/systemcmds/dumpfile/dumpfile.cpp similarity index 95% rename from src/systemcmds/dumpfile/dumpfile.c rename to src/systemcmds/dumpfile/dumpfile.cpp index ce947518ea..21e7917c65 100644 --- a/src/systemcmds/dumpfile/dumpfile.c +++ b/src/systemcmds/dumpfile/dumpfile.cpp @@ -49,19 +49,15 @@ #include -__EXPORT int dumpfile_main(int argc, char *argv[]); - -static void print_usage(void) +static void print_usage() { PRINT_MODULE_DESCRIPTION("Dump file utility. Prints file size and contents in binary mode (don't replace LF with CR LF) to stdout."); PRINT_MODULE_USAGE_NAME_SIMPLE("dumpfile", "command"); PRINT_MODULE_USAGE_ARG("", "File to dump", false); - } -int -dumpfile_main(int argc, char *argv[]) +extern "C" __EXPORT int dumpfile_main(int argc, char *argv[]) { if (argc < 2) { print_usage(); @@ -72,7 +68,7 @@ dumpfile_main(int argc, char *argv[]) FILE *f; f = fopen(argv[1], "r"); - if (f == NULL) { + if (f == nullptr) { PX4_ERR("Failed to open file (%i)", errno); return 1; } diff --git a/src/systemcmds/esc_calib/CMakeLists.txt b/src/systemcmds/esc_calib/CMakeLists.txt index 80c1764049..b41e849bd1 100644 --- a/src/systemcmds/esc_calib/CMakeLists.txt +++ b/src/systemcmds/esc_calib/CMakeLists.txt @@ -36,7 +36,7 @@ px4_add_module( STACK_MAIN 4096 COMPILE_FLAGS SRCS - esc_calib.c + esc_calib.cpp DEPENDS ) diff --git a/src/systemcmds/esc_calib/esc_calib.c b/src/systemcmds/esc_calib/esc_calib.cpp similarity index 94% rename from src/systemcmds/esc_calib/esc_calib.c rename to src/systemcmds/esc_calib/esc_calib.cpp index 6d60f9d311..d90bb62d1d 100644 --- a/src/systemcmds/esc_calib/esc_calib.c +++ b/src/systemcmds/esc_calib/esc_calib.cpp @@ -53,19 +53,13 @@ #include #include - - #include "drivers/drv_pwm_output.h" #include -static void usage(const char *reason); -__EXPORT int esc_calib_main(int argc, char *argv[]); - -static void -usage(const char *reason) +static void usage(const char *reason) { - if (reason != NULL) { + if (reason != nullptr) { PX4_ERR("%s", reason); } @@ -82,14 +76,13 @@ usage(const char *reason) PRINT_MODULE_USAGE_PARAM_STRING('d', "/dev/pwm_output0", "", "Select PWM output device", true); PRINT_MODULE_USAGE_PARAM_INT('l', 1000, 0, 3000, "Low PWM value in us", true); PRINT_MODULE_USAGE_PARAM_INT('h', 2000, 0, 3000, "High PWM value in us", true); - PRINT_MODULE_USAGE_PARAM_STRING('c', NULL, NULL, "select channels in the form: 1234 (1 digit per channel, 1=first)", - true); + PRINT_MODULE_USAGE_PARAM_STRING('c', nullptr, nullptr, + "select channels in the form: 1234 (1 digit per channel, 1=first)", true); PRINT_MODULE_USAGE_PARAM_INT('m', -1, 0, 4096, "Select channels via bitmask (eg. 0xF, 3)", true); PRINT_MODULE_USAGE_PARAM_FLAG('a', "Select all channels", true); } -int -esc_calib_main(int argc, char *argv[]) +extern "C" __EXPORT int esc_calib_main(int argc, char *argv[]) { const char *dev = PWM_OUTPUT0_DEVICE_PATH; char *ep; @@ -116,7 +109,7 @@ esc_calib_main(int argc, char *argv[]) } int myoptind = 1; - const char *myoptarg = NULL; + const char *myoptarg = nullptr; while ((ch = px4_getopt(argc, argv, "d:c:m:al:h:", &myoptind, &myoptarg)) != EOF) { switch (ch) { @@ -184,7 +177,7 @@ esc_calib_main(int argc, char *argv[]) break; default: - usage(NULL); + usage(nullptr); return 1; } } @@ -201,10 +194,10 @@ esc_calib_main(int argc, char *argv[]) /* make sure no other source is publishing control values now */ struct actuator_controls_s actuators; - int act_sub = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS); + int act_sub = orb_subscribe(ORB_ID(actuator_controls_0)); /* clear changed flag */ - orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, act_sub, &actuators); + orb_copy(ORB_ID(actuator_controls_0), act_sub, &actuators); /* wait 50 ms */ px4_usleep(50000); diff --git a/src/systemcmds/mft/mft.cpp b/src/systemcmds/mft/mft.cpp index f113e8fa5e..f390441159 100644 --- a/src/systemcmds/mft/mft.cpp +++ b/src/systemcmds/mft/mft.cpp @@ -71,14 +71,12 @@ #include -extern "C" __EXPORT int mft_main(int argc, char *argv[]); - static int mft_status(void) { return 0; } -static void print_usage(void) +static void print_usage() { PRINT_MODULE_DESCRIPTION("Utility interact with the manifest"); @@ -86,9 +84,7 @@ static void print_usage(void) PRINT_MODULE_USAGE_COMMAND_DESCR("query", "Returns true if not existed"); } - - -int mft_main(int argc, char *argv[]) +extern "C" __EXPORT int mft_main(int argc, char *argv[]) { static const char *keys[] = PX4_MFT_STR_TYPES; static const px4_manifest_types_e types[] = PX4_MFT_TYPES; diff --git a/src/systemcmds/microbench/microbench_main.cpp b/src/systemcmds/microbench/microbench_main.cpp index e476a3b7c4..f56dbd6a2c 100644 --- a/src/systemcmds/microbench/microbench_main.cpp +++ b/src/systemcmds/microbench/microbench_main.cpp @@ -69,7 +69,7 @@ const struct { {"microbench_matrix", test_microbench_matrix, 0}, {"microbench_uorb", test_microbench_uorb, 0}, - {NULL, NULL, 0} + {nullptr, nullptr, 0} }; #define NMICROBENCHMARKS (sizeof(microbenchmarks) / sizeof(microbenchmarks[0])) @@ -93,7 +93,7 @@ static int microbench_all(int argc, char *argv[]) static int microbench_runner(unsigned option) { size_t i; - char *args[2] = {"all", NULL}; + char *args[2] = {"all", nullptr}; unsigned int failcount = 0; unsigned int testcount = 0; unsigned int passed[NMICROBENCHMARKS]; diff --git a/src/systemcmds/motor_ramp/motor_ramp.cpp b/src/systemcmds/motor_ramp/motor_ramp.cpp index 49f3665561..077d1fcff8 100644 --- a/src/systemcmds/motor_ramp/motor_ramp.cpp +++ b/src/systemcmds/motor_ramp/motor_ramp.cpp @@ -313,10 +313,10 @@ int prepare(int fd, unsigned long *max_channels) { /* make sure no other source is publishing control values now */ struct actuator_controls_s actuators; - int act_sub = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS); + int act_sub = orb_subscribe(ORB_ID(actuator_controls_0)); /* clear changed flag */ - orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, act_sub, &actuators); + orb_copy(ORB_ID(actuator_controls_0), act_sub, &actuators); /* wait 50 ms */ px4_usleep(50000); diff --git a/src/systemcmds/mtd/mtd.cpp b/src/systemcmds/mtd/mtd.cpp index b3728fa69e..609c7ada29 100644 --- a/src/systemcmds/mtd/mtd.cpp +++ b/src/systemcmds/mtd/mtd.cpp @@ -135,7 +135,7 @@ static int mtd_status(void) return ret; } -static void print_usage(void) +static void print_usage() { #if !defined(CONSTRAINED_FLASH) @@ -304,7 +304,7 @@ int mtd_rwtest(const mtd_instance_s &instance) int mtd_main(int argc, char *argv[]) { int myoptind = 1; - const char *myoptarg = NULL; + const char *myoptarg = nullptr; int ch; int instance = 0; diff --git a/src/systemcmds/nshterm/CMakeLists.txt b/src/systemcmds/nshterm/CMakeLists.txt index a8bb6ce56f..14f669c3de 100644 --- a/src/systemcmds/nshterm/CMakeLists.txt +++ b/src/systemcmds/nshterm/CMakeLists.txt @@ -36,7 +36,7 @@ px4_add_module( PRIORITY "SCHED_PRIORITY_DEFAULT-30" COMPILE_FLAGS SRCS - nshterm.c + nshterm.cpp DEPENDS ) diff --git a/src/systemcmds/nshterm/nshterm.c b/src/systemcmds/nshterm/nshterm.cpp similarity index 95% rename from src/systemcmds/nshterm/nshterm.c rename to src/systemcmds/nshterm/nshterm.cpp index 7c44ac6882..aa4a615c2f 100644 --- a/src/systemcmds/nshterm/nshterm.c +++ b/src/systemcmds/nshterm/nshterm.cpp @@ -50,9 +50,7 @@ #include #include -__EXPORT int nshterm_main(int argc, char *argv[]); - -static void print_usage(void) +static void print_usage() { PRINT_MODULE_DESCRIPTION("Start an NSH shell on a given port.\n" "\n" @@ -64,7 +62,7 @@ static void print_usage(void) PRINT_MODULE_USAGE_ARG("", "Device on which to start the shell (eg. /dev/ttyACM0)", false); } -int nshterm_main(int argc, char *argv[]) +extern "C" __EXPORT int nshterm_main(int argc, char *argv[]) { if (argc < 2) { print_usage(); @@ -102,7 +100,7 @@ int nshterm_main(int argc, char *argv[]) dup2(fd, 1); dup2(fd, 2); - nsh_consolemain(0, NULL); + nsh_consolemain(0, nullptr); close(fd); diff --git a/src/systemcmds/perf/CMakeLists.txt b/src/systemcmds/perf/CMakeLists.txt index efae6abb16..a782e2c6ba 100644 --- a/src/systemcmds/perf/CMakeLists.txt +++ b/src/systemcmds/perf/CMakeLists.txt @@ -35,7 +35,7 @@ px4_add_module( MAIN perf COMPILE_FLAGS SRCS - perf.c + perf.cpp DEPENDS perf ) diff --git a/src/systemcmds/perf/perf.c b/src/systemcmds/perf/perf.cpp similarity index 94% rename from src/systemcmds/perf/perf.c rename to src/systemcmds/perf/perf.cpp index c58daf0359..1b8a2df65f 100644 --- a/src/systemcmds/perf/perf.c +++ b/src/systemcmds/perf/perf.cpp @@ -39,12 +39,9 @@ #include #include -#include +#include -__EXPORT int perf_main(int argc, char *argv[]); - - -static void print_usage(void) +static void print_usage() { PRINT_MODULE_DESCRIPTION("Tool to print performance counters"); @@ -55,8 +52,7 @@ static void print_usage(void) PRINT_MODULE_USAGE_PARAM_COMMENT("Prints all performance counters if no arguments given"); } - -int perf_main(int argc, char *argv[]) +extern "C" __EXPORT int perf_main(int argc, char *argv[]) { if (argc > 1) { if (strcmp(argv[1], "reset") == 0) { @@ -77,5 +73,3 @@ int perf_main(int argc, char *argv[]) fflush(stdout); return 0; } - - diff --git a/src/systemcmds/sd_bench/CMakeLists.txt b/src/systemcmds/sd_bench/CMakeLists.txt index 8522c57ad0..9ab943a90b 100644 --- a/src/systemcmds/sd_bench/CMakeLists.txt +++ b/src/systemcmds/sd_bench/CMakeLists.txt @@ -35,7 +35,7 @@ px4_add_module( MAIN sd_bench COMPILE_FLAGS SRCS - sd_bench.c + sd_bench.cpp DEPENDS ) diff --git a/src/systemcmds/sd_bench/sd_bench.c b/src/systemcmds/sd_bench/sd_bench.cpp similarity index 96% rename from src/systemcmds/sd_bench/sd_bench.c rename to src/systemcmds/sd_bench/sd_bench.cpp index b15c6b5371..1f38364f19 100644 --- a/src/systemcmds/sd_bench/sd_bench.c +++ b/src/systemcmds/sd_bench/sd_bench.cpp @@ -58,8 +58,6 @@ typedef struct sdb_config { unsigned int total_blocks_written; } sdb_config_t; -static void usage(void); - /** sequential write speed test */ static void write_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size); /** sequential read speed test */ @@ -72,12 +70,9 @@ static int read_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size); */ static inline unsigned int time_fsync(int fd); -__EXPORT int sd_bench_main(int argc, char *argv[]); - static const char *BENCHMARK_FILE = PX4_STORAGEDIR"/benchmark.tmp"; -static void -usage() +static void usage() { PRINT_MODULE_DESCRIPTION("Test the speed of an SD Card"); @@ -91,34 +86,33 @@ usage() PRINT_MODULE_USAGE_PARAM_FLAG('v', "Verify data and block number", true); } -int -sd_bench_main(int argc, char *argv[]) +extern "C" __EXPORT int sd_bench_main(int argc, char *argv[]) { int block_size = 4096; bool verify = false; bool keep = false; int myoptind = 1; int ch; - const char *myoptarg = NULL; + const char *myoptarg = nullptr; sdb_config_t cfg; cfg.synchronized = false; cfg.num_runs = 5; cfg.run_duration = 2000; cfg.aligned = true; - uint8_t *block = NULL; + uint8_t *block = nullptr; while ((ch = px4_getopt(argc, argv, "b:r:d:ksuv", &myoptind, &myoptarg)) != EOF) { switch (ch) { case 'b': - block_size = strtol(myoptarg, NULL, 0); + block_size = strtol(myoptarg, nullptr, 0); break; case 'r': - cfg.num_runs = strtol(myoptarg, NULL, 0); + cfg.num_runs = strtol(myoptarg, nullptr, 0); break; case 'd': - cfg.run_duration = strtol(myoptarg, NULL, 0); + cfg.run_duration = strtol(myoptarg, nullptr, 0); break; case 'k': @@ -259,7 +253,7 @@ void write_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size) int read_test(int fd, sdb_config_t *cfg, uint8_t *block, int block_size) { - uint8_t *read_block = NULL; + uint8_t *read_block = nullptr; PX4_INFO(""); PX4_INFO("Testing Sequential Read Speed of %d blocks", cfg->total_blocks_written); diff --git a/src/systemcmds/sd_stress/CMakeLists.txt b/src/systemcmds/sd_stress/CMakeLists.txt index 346218764c..e928abc707 100644 --- a/src/systemcmds/sd_stress/CMakeLists.txt +++ b/src/systemcmds/sd_stress/CMakeLists.txt @@ -35,6 +35,6 @@ px4_add_module( MAIN sd_stress COMPILE_FLAGS SRCS - sd_stress.c + sd_stress.cpp DEPENDS ) diff --git a/src/systemcmds/sd_stress/sd_stress.c b/src/systemcmds/sd_stress/sd_stress.cpp similarity index 96% rename from src/systemcmds/sd_stress/sd_stress.c rename to src/systemcmds/sd_stress/sd_stress.cpp index 7095426074..05c9ba7044 100644 --- a/src/systemcmds/sd_stress/sd_stress.c +++ b/src/systemcmds/sd_stress/sd_stress.cpp @@ -49,16 +49,13 @@ #include - static const unsigned MAX_PATH_LEN = 52; static const char *TEMPDIR = PX4_STORAGEDIR"/stress"; static const char *TEMPDIR2 = PX4_STORAGEDIR"/moved"; static const char *TEMPFILE = "tmp"; - -static void -usage(void) +static void usage() { PRINT_MODULE_DESCRIPTION("Test operations on an SD Card"); @@ -175,23 +172,22 @@ static bool rename_dir(const char *old_dir, const char *new_dir) return true; } -int -sd_stress_main(int argc, char *argv[]) +extern "C" __EXPORT int sd_stress_main(int argc, char *argv[]) { int myoptind = 1; int ch; - const char *myoptarg = NULL; + const char *myoptarg = nullptr; unsigned num_runs = 5; unsigned num_bytes = 100; while ((ch = px4_getopt(argc, argv, "r:b:", &myoptind, &myoptarg)) != EOF) { switch (ch) { case 'r': - num_runs = strtol(myoptarg, NULL, 0); + num_runs = strtol(myoptarg, nullptr, 0); break; case 'b': - num_bytes = strtol(myoptarg, NULL, 0); + num_bytes = strtol(myoptarg, nullptr, 0); break; default: diff --git a/src/systemcmds/tests/CMakeLists.txt b/src/systemcmds/tests/CMakeLists.txt index ddffe6ac5b..0f953e6767 100644 --- a/src/systemcmds/tests/CMakeLists.txt +++ b/src/systemcmds/tests/CMakeLists.txt @@ -55,8 +55,8 @@ set(srcs test_parameters.cpp test_perf.c test_ppm.cpp - test_ppm_loopback.c - test_rc.c + test_ppm_loopback.cpp + test_rc.cpp test_search_min.cpp test_sleep.c test_uart_baudchange.c diff --git a/src/systemcmds/tests/test_mount.cpp b/src/systemcmds/tests/test_mount.cpp index 2e7ddbf153..d7675714de 100644 --- a/src/systemcmds/tests/test_mount.cpp +++ b/src/systemcmds/tests/test_mount.cpp @@ -80,7 +80,7 @@ int test_mount(int argc, char *argv[]) if (d) { - while ((dir = readdir(d)) != NULL) { + while ((dir = readdir(d)) != nullptr) { //printf("%s\n", dir->d_name); } diff --git a/src/systemcmds/tests/test_ppm_loopback.c b/src/systemcmds/tests/test_ppm_loopback.cpp similarity index 98% rename from src/systemcmds/tests/test_ppm_loopback.c rename to src/systemcmds/tests/test_ppm_loopback.cpp index af9879b71a..b257fb580a 100644 --- a/src/systemcmds/tests/test_ppm_loopback.c +++ b/src/systemcmds/tests/test_ppm_loopback.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ /** - * @file test_ppm_loopback.c + * @file test_ppm_loopback.cpp * Tests the PWM outputs and PPM input */ @@ -120,7 +120,7 @@ int test_ppm_loopback(int argc, char *argv[]) warnx("servo count: %d", servo_count); - struct pwm_output_values pwm_out = {.values = {0}, .channel_count = 0}; + pwm_output_values pwm_out{}; for (unsigned i = 0; (i < servo_count) && (i < sizeof(pwm_values) / sizeof(pwm_values[0])); i++) { pwm_out.values[i] = pwm_values[i]; diff --git a/src/systemcmds/tests/test_rc.c b/src/systemcmds/tests/test_rc.cpp similarity index 99% rename from src/systemcmds/tests/test_rc.c rename to src/systemcmds/tests/test_rc.cpp index 83fe6aa703..97f7065115 100644 --- a/src/systemcmds/tests/test_rc.c +++ b/src/systemcmds/tests/test_rc.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ /** - * @file test_rc.c + * @file test_rc.cpp * Tests RC input. */ diff --git a/src/systemcmds/top/top.cpp b/src/systemcmds/top/top.cpp index 0dd921d05a..64658b540e 100644 --- a/src/systemcmds/top/top.cpp +++ b/src/systemcmds/top/top.cpp @@ -52,7 +52,7 @@ #include #include -static void print_usage(void) +static void print_usage() { PRINT_MODULE_DESCRIPTION("Monitor running processes and their CPU, stack usage, priority and state"); diff --git a/src/systemcmds/usb_connected/CMakeLists.txt b/src/systemcmds/usb_connected/CMakeLists.txt index fc56f45ab8..f06ba157a9 100644 --- a/src/systemcmds/usb_connected/CMakeLists.txt +++ b/src/systemcmds/usb_connected/CMakeLists.txt @@ -35,7 +35,7 @@ px4_add_module( MAIN usb_connected COMPILE_FLAGS SRCS - usb_connected.c + usb_connected.cpp DEPENDS ) diff --git a/src/systemcmds/usb_connected/usb_connected.c b/src/systemcmds/usb_connected/usb_connected.cpp similarity index 93% rename from src/systemcmds/usb_connected/usb_connected.c rename to src/systemcmds/usb_connected/usb_connected.cpp index 76411d743a..8ce3b312de 100644 --- a/src/systemcmds/usb_connected/usb_connected.c +++ b/src/systemcmds/usb_connected/usb_connected.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ /** - * @file usb_connected.c + * @file usb_connected.cpp * * @author Andrew Tridgell */ @@ -45,11 +45,8 @@ #include -__EXPORT int usb_connected_main(int argc, char *argv[]); - -static void print_usage(void) +static void print_usage() { - PRINT_MODULE_DESCRIPTION("Utility to check if USB is connected. Was previously used in startup scripts.\n" "A return value of 0 means USB is connected, 1 otherwise." ); @@ -57,8 +54,7 @@ static void print_usage(void) PRINT_MODULE_USAGE_NAME_SIMPLE("usb_connected", "command"); } -int -usb_connected_main(int argc, char *argv[]) +extern "C" __EXPORT int usb_connected_main(int argc, char *argv[]) { if (argc > 1) { print_usage(); diff --git a/src/systemcmds/ver/CMakeLists.txt b/src/systemcmds/ver/CMakeLists.txt index e4f3353fa0..708cde7604 100644 --- a/src/systemcmds/ver/CMakeLists.txt +++ b/src/systemcmds/ver/CMakeLists.txt @@ -35,7 +35,7 @@ px4_add_module( MAIN ver COMPILE_FLAGS SRCS - ver.c + ver.cpp DEPENDS version ) diff --git a/src/systemcmds/ver/ver.c b/src/systemcmds/ver/ver.cpp similarity index 96% rename from src/systemcmds/ver/ver.c rename to src/systemcmds/ver/ver.cpp index b5e9885f07..5028adff93 100644 --- a/src/systemcmds/ver/ver.c +++ b/src/systemcmds/ver/ver.cpp @@ -61,7 +61,7 @@ static const char px4_guid_str[] = "px4guid"; static void usage(const char *reason) { - if (reason != NULL) { + if (reason != nullptr) { printf("%s\n\n", reason); } @@ -86,19 +86,17 @@ static void usage(const char *reason) "Hardware type to compare against (eg. V2). An OR comparison is used if multiple are specified", false); } -__EXPORT int ver_main(int argc, char *argv[]); - -int ver_main(int argc, char *argv[]) +extern "C" __EXPORT int ver_main(int argc, char *argv[]) { /* defaults to an error */ int ret = 1; /* first check if there are at least 2 params */ if (argc >= 2) { - if (argv[1] != NULL) { + if (argv[1] != nullptr) { if (!strncmp(argv[1], sz_ver_hwcmp_str, sizeof(sz_ver_hwcmp_str))) { - if (argc >= 3 && argv[2] != NULL) { + if (argc >= 3 && argv[2] != nullptr) { const char *board_name = px4_board_name(); for (int i = 2; i < argc; ++i) { @@ -115,7 +113,7 @@ int ver_main(int argc, char *argv[]) } if (!strncmp(argv[1], sz_ver_hwtypecmp_str, sizeof(sz_ver_hwtypecmp_str))) { - if (argc >= 3 && argv[2] != NULL) { + if (argc >= 3 && argv[2] != nullptr) { const char *board_type = px4_board_sub_type(); for (int i = 2; i < argc; ++i) { @@ -238,8 +236,8 @@ int ver_main(int argc, char *argv[]) if (show_all || !strncmp(argv[1], mcu_ver_str, sizeof(mcu_ver_str))) { char rev = ' '; - const char *revstr = NULL; - const char *errata = NULL; + const char *revstr = nullptr; + const char *errata = nullptr; int chip_version = board_mcu_version(&rev, &revstr, &errata); @@ -249,7 +247,7 @@ int ver_main(int argc, char *argv[]) } else { printf("MCU: %s, rev. %c\n", revstr, rev); - if (errata != NULL) { + if (errata != nullptr) { printf("\nWARNING WARNING WARNING!\n" "Revision %c has a silicon errata:\n" "%s"