diff --git a/cmake/configs/nuttx_aerofc-v1_default.cmake b/cmake/configs/nuttx_aerofc-v1_default.cmake index 043cdde96f9673bb68ee97659a4b5dcc186f3406..bcda504bcc998c2b64d3f44a2cadec9c32f59540 100644 --- a/cmake/configs/nuttx_aerofc-v1_default.cmake +++ b/cmake/configs/nuttx_aerofc-v1_default.cmake @@ -101,6 +101,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework lib/rc platforms/nuttx diff --git a/cmake/configs/nuttx_auav-x21_default.cmake b/cmake/configs/nuttx_auav-x21_default.cmake index fc48ab724d38e3d4a6b6573e442f8ab5fe4a200b..98d43191185be0d62f096a65793e9b0adedd8101 100644 --- a/cmake/configs/nuttx_auav-x21_default.cmake +++ b/cmake/configs/nuttx_auav-x21_default.cmake @@ -143,6 +143,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_crazyflie_default.cmake b/cmake/configs/nuttx_crazyflie_default.cmake index 680731b207bcc46450799379be8093dd4c2c7c31..3459aaa4c7e4554f5c1d026af735932b622a2f62 100644 --- a/cmake/configs/nuttx_crazyflie_default.cmake +++ b/cmake/configs/nuttx_crazyflie_default.cmake @@ -97,6 +97,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_mindpx-v2_default.cmake b/cmake/configs/nuttx_mindpx-v2_default.cmake index ea661796b6a67ac0e973c6cf4f9a22006dbc4e6b..04056a74f6e62dd794bb0c33f0b484b2678ab74b 100644 --- a/cmake/configs/nuttx_mindpx-v2_default.cmake +++ b/cmake/configs/nuttx_mindpx-v2_default.cmake @@ -148,6 +148,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_px4fmu-v1_default.cmake b/cmake/configs/nuttx_px4fmu-v1_default.cmake index f4480c789f00b126820f9aba4c7e7bc92e562a0e..87e690364536fb524c5457b865dd0ffdfa3eb38c 100644 --- a/cmake/configs/nuttx_px4fmu-v1_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v1_default.cmake @@ -118,6 +118,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_px4fmu-v2_default.cmake b/cmake/configs/nuttx_px4fmu-v2_default.cmake index d15c8cff3d6077706e1f240e11a9dadaaeb689bf..321cb027608ad6c3fb2f7530bea445ac9245994b 100644 --- a/cmake/configs/nuttx_px4fmu-v2_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v2_default.cmake @@ -144,6 +144,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_px4fmu-v2_test.cmake b/cmake/configs/nuttx_px4fmu-v2_test.cmake index e681f3278fcd2ec1c2ebfc7afdcde5ec0658c8f3..68d0f631ec0cf884adb4f02e4470fede1a35db95 100644 --- a/cmake/configs/nuttx_px4fmu-v2_test.cmake +++ b/cmake/configs/nuttx_px4fmu-v2_test.cmake @@ -144,6 +144,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_px4fmu-v3_default.cmake b/cmake/configs/nuttx_px4fmu-v3_default.cmake index 086d1caea429f51a33c16dec09bb8a849512a453..7faa2cd40e6d31d554f25db1eb954415ddf4817b 100644 --- a/cmake/configs/nuttx_px4fmu-v3_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v3_default.cmake @@ -149,6 +149,7 @@ set(config_module_list lib/runway_takeoff lib/tailsitter_recovery lib/terrain_estimation + lib/version platforms/nuttx # had to add for cmake, not sure why wasn't in original config diff --git a/cmake/configs/nuttx_px4fmu-v4_default.cmake b/cmake/configs/nuttx_px4fmu-v4_default.cmake index 23e411865ff0126c50b935fc69a13c499b66b066..f62e9ff7367ee0416854cc7348eafa50306177cf 100644 --- a/cmake/configs/nuttx_px4fmu-v4_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v4_default.cmake @@ -148,6 +148,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/nuttx diff --git a/cmake/configs/nuttx_tap-v1_default.cmake b/cmake/configs/nuttx_tap-v1_default.cmake index c5970f4ee13ab64d8f358d49ce95d5fd904d9a70..b8b9857437816363c67ce917bbb9f041673f99be 100644 --- a/cmake/configs/nuttx_tap-v1_default.cmake +++ b/cmake/configs/nuttx_tap-v1_default.cmake @@ -97,11 +97,12 @@ set(config_module_list lib/geo_lookup lib/conversion lib/launchdetection - lib/terrain_estimation + lib/rc lib/runway_takeoff lib/tailsitter_recovery + lib/terrain_estimation + lib/version lib/DriverFramework/framework - lib/rc platforms/nuttx # had to add for cmake, not sure why wasn't in original config diff --git a/cmake/configs/posix_bebop_default.cmake b/cmake/configs/posix_bebop_default.cmake index 749d81f08e97f0d7b0621a0babfd9f14c0207453..6a3969db2773170af53b18eeec44cba30868b18d 100644 --- a/cmake/configs/posix_bebop_default.cmake +++ b/cmake/configs/posix_bebop_default.cmake @@ -89,6 +89,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework # diff --git a/cmake/configs/posix_eagle_hil.cmake b/cmake/configs/posix_eagle_hil.cmake index 4c4ba9f8ae09f83c6888934e4e691e3b7985139e..14f4cdae03fcd503a2c60ff89dc9bce1cca0d834 100644 --- a/cmake/configs/posix_eagle_hil.cmake +++ b/cmake/configs/posix_eagle_hil.cmake @@ -45,6 +45,7 @@ set(config_module_list lib/geo lib/geo_lookup lib/conversion + lib/version lib/DriverFramework/framework platforms/common diff --git a/cmake/configs/posix_eagle_legacy_driver_default.cmake b/cmake/configs/posix_eagle_legacy_driver_default.cmake index e24dafa6a5a707e9da676d304c4423c8fbf50a00..fe716f797c07aebdd3a3ad791edea2a6bca3dfa4 100644 --- a/cmake/configs/posix_eagle_legacy_driver_default.cmake +++ b/cmake/configs/posix_eagle_legacy_driver_default.cmake @@ -69,6 +69,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/common diff --git a/cmake/configs/posix_rpi_common.cmake b/cmake/configs/posix_rpi_common.cmake index b4f20c88c41f8ac81dbbaf1dac0cbc7f5a8b7e19..ffcb1633c97e8a1aa24223b71829eb899adf19b4 100644 --- a/cmake/configs/posix_rpi_common.cmake +++ b/cmake/configs/posix_rpi_common.cmake @@ -91,6 +91,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework # diff --git a/cmake/configs/posix_sdflight_default.cmake b/cmake/configs/posix_sdflight_default.cmake index 3ebdfbeed37da9ee170ca6e8c0b1e0888606a5c1..af1c7ed4255f70c0a63fff19a085ba8305b72264 100644 --- a/cmake/configs/posix_sdflight_default.cmake +++ b/cmake/configs/posix_sdflight_default.cmake @@ -69,6 +69,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework platforms/common diff --git a/cmake/configs/posix_sitl_default.cmake b/cmake/configs/posix_sitl_default.cmake index 3bea67a31547c2f1dd9b1c4f5da3a4123b9b774c..e610470ba43c4a332d7ed01c86ea7029bebd1429 100644 --- a/cmake/configs/posix_sitl_default.cmake +++ b/cmake/configs/posix_sitl_default.cmake @@ -71,6 +71,7 @@ set(config_module_list lib/runway_takeoff lib/tailsitter_recovery lib/terrain_estimation + lib/version examples/px4_simple_app examples/mc_att_control_multiplatform diff --git a/cmake/configs/posix_sitl_replay.cmake b/cmake/configs/posix_sitl_replay.cmake index 3c359b279d8e711ec8109b85b5bb21028a1a69e6..a6a3d23d0a30ba018330dc615ef62aad7b5c9f80 100644 --- a/cmake/configs/posix_sitl_replay.cmake +++ b/cmake/configs/posix_sitl_replay.cmake @@ -26,6 +26,7 @@ set(config_module_list lib/external_lgpl lib/geo lib/geo_lookup + lib/version lib/DriverFramework/framework ) diff --git a/cmake/configs/qurt_eagle_hil.cmake b/cmake/configs/qurt_eagle_hil.cmake index 8720104fb0661d68ea62c41dafbca05483b6aec3..ed84285d1909a863ba96ea4ae4f8a315fed656a4 100644 --- a/cmake/configs/qurt_eagle_hil.cmake +++ b/cmake/configs/qurt_eagle_hil.cmake @@ -69,6 +69,7 @@ set(config_module_list lib/runway_takeoff lib/tailsitter_recovery lib/controllib + lib/version lib/DriverFramework/framework # diff --git a/cmake/configs/qurt_eagle_legacy_driver_default.cmake b/cmake/configs/qurt_eagle_legacy_driver_default.cmake index 1d66edc878ed43831b7a1c14f6236cdb0a7de690..ba56439615df18267bc1b21e2c65a9307ae08b4f 100644 --- a/cmake/configs/qurt_eagle_legacy_driver_default.cmake +++ b/cmake/configs/qurt_eagle_legacy_driver_default.cmake @@ -92,6 +92,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework # diff --git a/cmake/configs/qurt_eagle_muorb.cmake b/cmake/configs/qurt_eagle_muorb.cmake index 828f5b420ef66d18c7ad72beb2991408452033cd..0e0152ab1ec7b642a5432d2694f75ebe4fd058db 100644 --- a/cmake/configs/qurt_eagle_muorb.cmake +++ b/cmake/configs/qurt_eagle_muorb.cmake @@ -43,6 +43,7 @@ set(config_module_list lib/geo lib/geo_lookup lib/conversion + lib/version lib/DriverFramework/framework # diff --git a/cmake/configs/qurt_eagle_travis.cmake b/cmake/configs/qurt_eagle_travis.cmake index 0063827b01f1047c76618865faf1a9e20b126d0b..52646638ec440cba8b231965c78937345f7bbee5 100644 --- a/cmake/configs/qurt_eagle_travis.cmake +++ b/cmake/configs/qurt_eagle_travis.cmake @@ -75,6 +75,7 @@ set(config_module_list lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery + lib/version lib/DriverFramework/framework # diff --git a/cmake/configs/qurt_sdflight_default.cmake b/cmake/configs/qurt_sdflight_default.cmake index 12175dbfbea6a79e7b80451362bb80dad36cdad6..b8e111d3feef2c96b9f76816775d33c7cc5c2e9a 100644 --- a/cmake/configs/qurt_sdflight_default.cmake +++ b/cmake/configs/qurt_sdflight_default.cmake @@ -87,6 +87,7 @@ set(config_module_list lib/runway_takeoff lib/tailsitter_recovery lib/rc + lib/version lib/DriverFramework/framework # diff --git a/src/lib/version/CMakeLists.txt b/src/lib/version/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8698814b01d105752bbc7b9f1d5fc7c9db95a4b0 --- /dev/null +++ b/src/lib/version/CMakeLists.txt @@ -0,0 +1,41 @@ +############################################################################ +# +# Copyright (c) 2016 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ +px4_add_module( + MODULE lib__version + COMPILE_FLAGS + SRCS + version.c + DEPENDS + platforms__common + ) +# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/lib/version/version.c b/src/lib/version/version.c new file mode 100644 index 0000000000000000000000000000000000000000..4735038339639d15d11a7541c4f1ccee4995617f --- /dev/null +++ b/src/lib/version/version.c @@ -0,0 +1,258 @@ +/**************************************************************************** + * + * Copyright (c) 2016 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include "version.h" + +#include "build_git_version.h" //generated from build_git_version.h.in + +#include <string.h> + +#if !defined(CONFIG_CDCACM_PRODUCTID) +# define CONFIG_CDCACM_PRODUCTID 0 +#endif + +#if defined(__PX4_LINUX) +#include <sys/utsname.h> +#endif + +// dev >= 0 +// alpha >= 64 +// beta >= 128 +// release candidate >= 192 +// release == 255 +enum FIRMWARE_TYPE { + FIRMWARE_TYPE_DEV = 0, + FIRMWARE_TYPE_ALPHA = 64, + FIRMWARE_TYPE_BETA = 128, + FIRMWARE_TYPE_RC = 192, + FIRMWARE_TYPE_RELEASE = 255 +}; + +/** + * Convert a version tag string to a number + * @param tag version tag in one of the following forms: + * - dev: v1.4.0rc3-7-g7e282f57 + * - rc: v1.4.0rc4 + * - release: v1.4.0 + * - linux: 7.9.3 + * @return version in the form 0xAABBCCTT (AA: Major, BB: Minor, CC: Patch, TT Type @see FIRMWARE_TYPE) + */ +static uint32_t version_tag_to_number(const char *tag) +{ + uint32_t ver = 0; + unsigned len = strlen(tag); + unsigned mag = 0; + int32_t type = -1; + unsigned dashcount = 0; + + for (int i = len - 1; i >= 0; i--) { + + if (tag[i] == '-') { + dashcount++; + } + + if (tag[i] >= '0' && tag[i] <= '9') { + if (mag < 32) { + unsigned number = tag[i] - '0'; + + ver += (number << mag); + mag += 8; + } + + } else if (tag[i] == '.') { + continue; + + } else if (i > 3 && type == -1) { + /* scan and look for signature characters for each type */ + const char *curr = &tag[i - 1]; + + while (curr > &tag[0]) { + if (*curr == 'v') { + type = FIRMWARE_TYPE_DEV; + break; + + } else if (*curr == 'p') { + type = FIRMWARE_TYPE_ALPHA; + break; + + } else if (*curr == 't') { + type = FIRMWARE_TYPE_BETA; + break; + + } else if (*curr == 'r') { + type = FIRMWARE_TYPE_RC; + break; + } + + curr--; + } + + /* looks like a release */ + if (type == -1) { + type = FIRMWARE_TYPE_RELEASE; + } + + } else if (tag[i] != 'v') { + /* reset, because we don't have a full tag but + * are seeing non-numeric characters (eg. '-') + */ + ver = 0; + mag = 0; + } + } + + /* if git describe contains dashes this is not a real tag */ + if (dashcount > 0) { + type = FIRMWARE_TYPE_DEV; + } + + /* looks like a release */ + if (type == -1) { + type = FIRMWARE_TYPE_RELEASE; + } + + ver = (ver << 8); + + return ver | type; +} + + +uint32_t px4_firmware_version(void) +{ + return version_tag_to_number(PX4_GIT_TAG_STR); +} + +uint32_t px4_board_version(void) +{ +#if defined(__PX4_NUTTX) + return CONFIG_CDCACM_PRODUCTID; +#else + return 1; +#endif +} + +uint32_t px4_os_version(void) +{ +#if defined(__PX4_DARWIN) + return 0; //TODO: implement version for Darwin +#elif defined(__PX4_LINUX) + struct utsname name; + + if (uname(&name) == 0) { + char *c = name.release; + + // cut the part after the first '-' + while (*c && *c != '-') { + ++c; + } + + *c = 0; + return version_tag_to_number(name.release); + + } else { + return 0; + } + +#elif defined(__PX4_QURT) + return 0; //TODO: implement version for QuRT +#elif defined(__PX4_NUTTX) + return version_tag_to_number("v7.18.0"); //TODO: get correct version +#else +# error "px4_os_version not implemented for current OS" +#endif +} + +const char *px4_os_version_string(void) +{ +#if defined(__PX4_NUTTX) + return NULL; //TODO: get NuttX git tag as string +#else + return NULL; +#endif +} + +const char *px4_os_name(void) +{ +#if defined(__PX4_DARWIN) + return "Darwin"; +#elif defined(__PX4_LINUX) + return "Linux"; +#elif defined(__PX4_QURT) + return "QuRT"; +#elif defined(__PX4_NUTTX) + return "NuttX"; +#else +# error "px4_os_name not implemented for current OS" +#endif +} + +const char *px4_toolchain_name(void) +{ +#if defined(__clang__) + return "Clang/LLVM"; +#elif defined(__ICC) || defined(__INTEL_COMPILER) + return "Intel ICC"; +#elif defined(__GNUC__) || defined(__GNUG__) + return "GNU GCC"; +#elif defined(_MSC_VER) + return "MS Visual Studio"; +#else + return "Unknown"; +#endif +} + +const char *px4_toolchain_version(void) +{ +#ifdef __VERSION__ + return __VERSION__; +#else + return ""; +#endif +} + +const char *px4_firmware_version_string(void) +{ + return PX4_GIT_VERSION_STR; +} + +uint64_t px4_firmware_version_binary(void) +{ + return PX4_GIT_VERSION_BINARY; +} + +uint64_t px4_os_version_binary(void) +{ + //TODO: get NuttX version via git tag + return 0; +} + diff --git a/src/lib/version/version.h b/src/lib/version/version.h index 4d23e5ade66ca4ec0d5dedaa0762cb6e1450be45..71ec5a6c8990231773bf21c3739339f36a28566f 100644 --- a/src/lib/version/version.h +++ b/src/lib/version/version.h @@ -38,10 +38,12 @@ * Tools for system version detection. * * @author Anton Babushkin <anton.babushkin@me.com> + * @author Beat Küng <beat-kueng@gmx.net> */ #pragma once +#include <stdint.h> #define FREEZE_STR(s) #s #define STRINGIFY(s) FREEZE_STR(s) @@ -79,7 +81,60 @@ static inline const char *px4_board_name(void) return BOARD_NAME; } +/** + * get the PX4 Firmware version + * @return version in the form 0xAABBCCTT (AA: Major, BB: Minor, CC: Patch, TT Type @see FIRMWARE_TYPE) + */ +__EXPORT uint32_t px4_firmware_version(void); + +/** + * get the board version (last 8 bytes should be silicon ID, if any) + */ +__EXPORT uint32_t px4_board_version(void); + +/** + * operating system version + * @return version in the form 0xAABBCCTT (AA: Major, BB: Minor, CC: Patch, TT Type @see FIRMWARE_TYPE) + */ +__EXPORT uint32_t px4_os_version(void); + +/** + * Operating system version as human readable string (git tag) + * @return string or NULL if not defined + */ +__EXPORT const char *px4_os_version_string(void); + +/** + * name of the operating system + * @return human readable string + */ +__EXPORT const char *px4_os_name(void); +/** + * Toolchain name used to compile PX4 + */ +__EXPORT const char *px4_toolchain_name(void); + +/** + * Toolchain version used to compile PX4 (no particular format) + */ +__EXPORT const char *px4_toolchain_version(void); + +/** + * Firmware version as human readable string (git tag) + */ +__EXPORT const char *px4_firmware_version_string(void); + +/** + * Firmware version in binary form (first part of the git tag) + */ +__EXPORT uint64_t px4_firmware_version_binary(void); + +/** + * Operating system version in binary form (first part of the git tag) + * @return this is not available on all OSes and can return 0 + */ +__EXPORT uint64_t px4_os_version_binary(void); __END_DECLS diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index aa9a6c398b2afc9bfe07ae37d088ddca59974f90..380816aacb88419d661ba159cdf052224e54dfe3 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -1361,7 +1361,7 @@ void Logger::write_header() /* write version info messages */ void Logger::write_version() { - write_info("ver_sw", PX4_GIT_VERSION_STR); + write_info("ver_sw", px4_firmware_version_string()); write_info("ver_hw", px4_board_name()); write_info("sys_name", "PX4"); int32_t utc_offset = 0; diff --git a/src/modules/logger/logger.h b/src/modules/logger/logger.h index 17cc8745d8ec360fff739f3b3ccc4f9ff00b022d..e0cb87d27d9fbb3bb70582ad25eacf780d904015 100644 --- a/src/modules/logger/logger.h +++ b/src/modules/logger/logger.h @@ -39,7 +39,6 @@ #include <drivers/drv_hrt.h> #include <uORB/Subscription.hpp> #include <version/version.h> -#include <systemlib/git_version.h> #include <systemlib/param/param.h> extern "C" __EXPORT int logger_main(int argc, char *argv[]); diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index 057f957d9dc7f3a441033286bc3459633cbfa37b..dda8ea95208ea889cd63b44f615fc29e72f7165f 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -72,11 +72,10 @@ #include <systemlib/perf_counter.h> #include <systemlib/systemlib.h> #include <systemlib/mcu_version.h> -#include <systemlib/git_version.h> #include <systemlib/mavlink_log.h> #include <geo/geo.h> #include <dataman/dataman.h> -//#include <mathlib/mathlib.h> +#include <version/version.h> #include <uORB/topics/parameter_update.h> #include <uORB/topics/vehicle_command_ack.h> @@ -1283,13 +1282,15 @@ void Mavlink::send_autopilot_capabilites() msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED; msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_ACTUATOR_TARGET; msg.capabilities |= MAV_PROTOCOL_CAPABILITY_MAVLINK2; - msg.flight_sw_version = version_tag_to_number(px4_git_tag); - msg.middleware_sw_version = version_tag_to_number(px4_git_tag); - msg.os_sw_version = version_tag_to_number(os_git_tag); - msg.board_version = px4_board_version; - memcpy(&msg.flight_custom_version, &px4_git_version_binary, sizeof(msg.flight_custom_version)); - memcpy(&msg.middleware_custom_version, &px4_git_version_binary, sizeof(msg.middleware_custom_version)); - memset(&msg.os_custom_version, 0, sizeof(msg.os_custom_version)); + msg.flight_sw_version = px4_firmware_version(); + msg.middleware_sw_version = px4_firmware_version(); + msg.os_sw_version = px4_os_version(); + msg.board_version = px4_board_version(); + uint64_t fw_git_version_binary = px4_firmware_version_binary(); + memcpy(&msg.flight_custom_version, &fw_git_version_binary, sizeof(msg.flight_custom_version)); + memcpy(&msg.middleware_custom_version, &fw_git_version_binary, sizeof(msg.middleware_custom_version)); + uint64_t os_git_version_binary = px4_os_version_binary(); + memcpy(&msg.os_custom_version, &os_git_version_binary, sizeof(msg.os_custom_version)); #ifdef CONFIG_CDCACM_VENDORID msg.vendor_id = CONFIG_CDCACM_VENDORID; #else diff --git a/src/modules/sdlog2/sdlog2.c b/src/modules/sdlog2/sdlog2.c index a1df573ae77ce5bf38ca6a4b1adfd15e9103da6c..a918d6de3dfc8242e2ad177070d48af1837c2002 100644 --- a/src/modules/sdlog2/sdlog2.c +++ b/src/modules/sdlog2/sdlog2.c @@ -116,7 +116,6 @@ #include <systemlib/systemlib.h> #include <systemlib/param/param.h> #include <systemlib/perf_counter.h> -#include <systemlib/git_version.h> #include <systemlib/printload.h> #include <systemlib/mavlink_log.h> #include <version/version.h> @@ -873,7 +872,7 @@ int write_version(int fd) }; /* fill version message and write it */ - strncpy(log_msg_VER.body.fw_git, px4_git_version, sizeof(log_msg_VER.body.fw_git)); + strncpy(log_msg_VER.body.fw_git, px4_firmware_version_string(), sizeof(log_msg_VER.body.fw_git)); strncpy(log_msg_VER.body.arch, px4_board_name(), sizeof(log_msg_VER.body.arch)); return write(fd, &log_msg_VER, sizeof(log_msg_VER)); } diff --git a/src/modules/systemlib/git_version.h b/src/modules/systemlib/git_version.h deleted file mode 100644 index a81ac035eefc2239881f8b7a4c4d8d1eca8d82bf..0000000000000000000000000000000000000000 --- a/src/modules/systemlib/git_version.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2015 PX4 Development Team. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/** - * @file git_version.h - * - * GIT repository version - */ - -#pragma once - -#include <stdint.h> - -#include "build_git_version.h" - -__BEGIN_DECLS - -__EXPORT extern const char *px4_git_version; -__EXPORT extern const uint64_t px4_git_version_binary; -__EXPORT extern const char *px4_git_tag; -__EXPORT extern const char *os_git_tag; -__EXPORT extern const uint32_t px4_board_version; - -__EXPORT uint32_t version_tag_to_number(const char *tag); - -__END_DECLS diff --git a/src/modules/systemlib/mcu_version.h b/src/modules/systemlib/mcu_version.h index f40ac069e141cdca22b93b51dc18f9f787e0f286..2aca31b99bb11f74712d3ee6b3403810eff9a26d 100644 --- a/src/modules/systemlib/mcu_version.h +++ b/src/modules/systemlib/mcu_version.h @@ -60,7 +60,7 @@ __EXPORT void mcu_unique_id(uint32_t *uid_96_bit); * * @param rev The silicon revision character * @param revstr The full chip name string - * @return The silicon revision / version number as integer + * @return The silicon revision / version number as integer. -1 on error (rev and revstr will not be set) */ __EXPORT int mcu_version(char *rev, char **revstr); diff --git a/src/modules/uavcan/uavcan_main.cpp b/src/modules/uavcan/uavcan_main.cpp index a776179b1a6260ff027a3769f14dd58b01ffb149..fafafda400cdd78c5eee22e23c0afa4120446c9e 100644 --- a/src/modules/uavcan/uavcan_main.cpp +++ b/src/modules/uavcan/uavcan_main.cpp @@ -53,7 +53,6 @@ #include <systemlib/mixer/mixer.h> #include <systemlib/board_serial.h> #include <systemlib/scheduling_priorities.h> -#include <systemlib/git_version.h> #include <version/version.h> #include <arch/board/board.h> #include <arch/chip/chip.h> @@ -622,7 +621,7 @@ void UavcanNode::fill_node_info() // Extracting the first 8 hex digits of GIT_VERSION and converting them to int char fw_git_short[9] = {}; - std::memmove(fw_git_short, px4_git_version, 8); + std::memmove(fw_git_short, px4_firmware_version_string(), 8); assert(fw_git_short[8] == '\0'); char *end = nullptr; swver.vcs_commit = std::strtol(fw_git_short, &end, 16); diff --git a/src/modules/uavcan/uavcan_servers.cpp b/src/modules/uavcan/uavcan_servers.cpp index b05f4ea32053f9b36935c9e504bfec1b78f5ba3f..09d2389e00211f5f433274767c77a14db70ff325 100644 --- a/src/modules/uavcan/uavcan_servers.cpp +++ b/src/modules/uavcan/uavcan_servers.cpp @@ -45,7 +45,6 @@ #include <systemlib/mixer/mixer.h> #include <systemlib/board_serial.h> #include <systemlib/scheduling_priorities.h> -#include <systemlib/git_version.h> #include <version/version.h> #include <arch/board/board.h> #include <arch/chip/chip.h> diff --git a/src/systemcmds/ver/ver.c b/src/systemcmds/ver/ver.c index 4894c35c5dc285737154a0539ce933cc36c474ab..f27537bdb057a2f6fddca7763b5e987648aa3089 100644 --- a/src/systemcmds/ver/ver.c +++ b/src/systemcmds/ver/ver.c @@ -46,7 +46,6 @@ #include <version/version.h> #include <systemlib/err.h> #include <systemlib/mcu_version.h> -#include <systemlib/git_version.h> /* string constants for version commands */ static const char sz_ver_hw_str[] = "hw"; @@ -59,123 +58,6 @@ static const char sz_ver_all_str[] = "all"; static const char mcu_ver_str[] = "mcu"; static const char mcu_uid_str[] = "uid"; -const char *px4_git_version = PX4_GIT_VERSION_STR; -const uint64_t px4_git_version_binary = PX4_GIT_VERSION_BINARY; -#if !defined(CONFIG_CDCACM_PRODUCTID) -# define CONFIG_CDCACM_PRODUCTID 0 -#endif -const char *px4_git_tag = PX4_GIT_TAG_STR; - -#if defined(__PX4_NUTTX) -__EXPORT const char *os_git_tag = "7.18"; -__EXPORT const uint32_t px4_board_version = CONFIG_CDCACM_PRODUCTID; -#else -__EXPORT const char *os_git_tag = ""; -__EXPORT const uint32_t px4_board_version = 1; -#endif - -// dev >= 0 -// alpha >= 64 -// beta >= 128 -// release candidate >= 192 -// release == 255 -enum FIRMWARE_TYPE { - FIRMWARE_TYPE_DEV = 0, - FIRMWARE_TYPE_ALPHA = 64, - FIRMWARE_TYPE_BETA = 128, - FIRMWARE_TYPE_RC = 192, - FIRMWARE_TYPE_RELEASE = 255 -}; - -/** - * Convert a version tag string to a number - */ -uint32_t version_tag_to_number(const char *tag) -{ - uint32_t ver = 0; - unsigned len = strlen(tag); - unsigned mag = 0; - int32_t type = -1; - bool dotparsed = false; - unsigned dashcount = 0; - - for (int i = len - 1; i >= 0; i--) { - - if (tag[i] == '-') { - dashcount++; - } - - if (tag[i] >= '0' && tag[i] <= '9') { - unsigned number = tag[i] - '0'; - - ver += (number << mag); - mag += 8; - - } else if (tag[i] == '.') { - continue; - - } else if (mag > 2 * 8 && dotparsed) { - /* this is a full version and we have enough digits */ - return ver; - - } else if (i > 3 && type == -1) { - /* scan and look for signature characters for each type */ - const char *curr = &tag[i - 1]; - - // dev: v1.4.0rc3-7-g7e282f57 - // rc: v1.4.0rc4 - // release: v1.4.0 - - while (curr > &tag[0]) { - if (*curr == 'v') { - type = FIRMWARE_TYPE_DEV; - break; - - } else if (*curr == 'p') { - type = FIRMWARE_TYPE_ALPHA; - break; - - } else if (*curr == 't') { - type = FIRMWARE_TYPE_BETA; - break; - - } else if (*curr == 'r') { - type = FIRMWARE_TYPE_RC; - break; - } - - curr--; - } - - /* looks like a release */ - if (type == -1) { - type = FIRMWARE_TYPE_RELEASE; - } - - } else if (tag[i] != 'v') { - /* reset, because we don't have a full tag but - * are seeing non-numeric characters - */ - ver = 0; - mag = 0; - } - } - - /* if git describe contains dashes this is not a real tag */ - if (dashcount > 0) { - type = FIRMWARE_TYPE_DEV; - } - - /* looks like a release */ - if (type == -1) { - type = FIRMWARE_TYPE_RELEASE; - } - - ver = (ver << 8); - - return ver | type; -} - static void usage(const char *reason) { if (reason != NULL) { @@ -224,16 +106,41 @@ int ver_main(int argc, char *argv[]) } if (show_all || !strncmp(argv[1], sz_ver_git_str, sizeof(sz_ver_git_str))) { - printf("FW git-hash: %s\n", px4_git_version); - unsigned fwver = version_tag_to_number(px4_git_tag); + printf("FW git-hash: %s\n", px4_firmware_version_string()); + unsigned fwver = px4_firmware_version(); unsigned major = (fwver >> (8 * 3)) & 0xFF; unsigned minor = (fwver >> (8 * 2)) & 0xFF; unsigned patch = (fwver >> (8 * 1)) & 0xFF; unsigned type = (fwver >> (8 * 0)) & 0xFF; - printf("FW version: %s (%u.%u.%u %u), %u\n", px4_git_tag, major, minor, patch, - type, fwver); - /* middleware is currently the same thing as firmware, so not printing yet */ - printf("OS version: %s (%u)\n", os_git_tag, version_tag_to_number(os_git_tag)); + + if (type == 255) { + printf("FW version: Release %u.%u.%u (%u)\n", major, minor, patch, fwver); + + } else { + printf("FW version: %u.%u.%u %u (%u)\n", major, minor, patch, type, fwver); + } + + + fwver = px4_os_version(); + major = (fwver >> (8 * 3)) & 0xFF; + minor = (fwver >> (8 * 2)) & 0xFF; + patch = (fwver >> (8 * 1)) & 0xFF; + type = (fwver >> (8 * 0)) & 0xFF; + printf("OS: %s\n", px4_os_name()); + + if (type == 255) { + printf("OS version: Release %u.%u.%u (%u)\n", major, minor, patch, fwver); + + } else { + printf("OS version: %u.%u.%u %u (%u)\n", major, minor, patch, type, fwver); + } + + const char *os_git_hash = px4_os_version_string(); + + if (os_git_hash) { + printf("OS git-hash: %s\n", os_git_hash); + } + ret = 0; } @@ -252,7 +159,7 @@ int ver_main(int argc, char *argv[]) if (show_all || !strncmp(argv[1], sz_ver_gcc_str, sizeof(sz_ver_gcc_str))) { - printf("Toolchain: %s\n", __VERSION__); + printf("Toolchain: %s, %s\n", px4_toolchain_name(), px4_toolchain_version()); ret = 0; }