From ce6bb39c71e4ae876409c2827446a9be6b4e87e1 Mon Sep 17 00:00:00 2001 From: Timo Sairiala Date: Wed, 31 Jul 2024 16:06:02 +0300 Subject: [PATCH] add git top info --- src/lib/version/version.c | 41 +++++++++++++++++++++++++++++++++++++++ src/lib/version/version.h | 19 ++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/lib/version/version.c b/src/lib/version/version.c index 6c49e1fd8d04..57f74b426d7e 100644 --- a/src/lib/version/version.c +++ b/src/lib/version/version.c @@ -146,6 +146,42 @@ uint32_t version_tag_to_number(const char *tag) return version_number; } +uint32_t version_tag_to_git_top(const char *tag) +{ + uint32_t git_top = 0; + size_t dash_count = 0; + + // git tag top exists between the 2nd and 3rh dash + for( size_t i = 0; i < strlen(tag); i++ ) { + // if dash_count is 2, we are reading the git top + if (dash_count == 2) { + // next dash means the end of the git top + if (tag[i] == '-') { + break; + } + + // we are expecting a digit, otherwise there is something wrong + if (tag[i] >= '0' && tag[i] <= '9') { + // shift possibly existing git top to the left by 1 digit + git_top = git_top * 10; + git_top += (tag[i] - '0'); + continue; + } + else { + return 0; + } + } + + // looking for the 2nd dash which marks beginning of git top + if (tag[i] == '-') { + dash_count++; + continue; + } + } + + return git_top; +} + uint32_t px4_firmware_version(void) { return version_tag_to_number(PX4_GIT_TAG_STR); @@ -242,6 +278,11 @@ uint32_t px4_firmware_vendor_version(void) return version_tag_to_vendor_version_number(PX4_GIT_TAG_STR); } +uint32_t px4_firmware_git_top_number(void) +{ + return version_tag_to_git_top(PX4_GIT_TAG_STR); +} + const char *px4_firmware_git_branch(void) { return PX4_GIT_BRANCH_NAME; diff --git a/src/lib/version/version.h b/src/lib/version/version.h index d6cb16310e05..bd7d32cc3573 100644 --- a/src/lib/version/version.h +++ b/src/lib/version/version.h @@ -116,6 +116,19 @@ const char *px4_build_uri(void); */ __EXPORT uint32_t version_tag_to_number(const char *tag); +/** + * Find a git tag top number from version tag string + * @param tag version tag in one of the following forms: + * - vendor: v1.4.0-0.2.0 + * - dev: v1.4.0-rc3-7-g7e282f57 + * - rc: v1.4.0-rc4 + * - beta: v1.4.0-beta1 + * - release: v1.4.0 + * - linux: 7.9.3 + * @return git tag top uint32_t number + */ +__EXPORT uint32_t version_tag_to_git_top(const char *tag); + /** * get the PX4 Firmware version * @return version in the form 0xAABBCCTT (AA: Major, BB: Minor, CC: Patch, TT Type @see FIRMWARE_TYPE) @@ -141,6 +154,12 @@ __EXPORT uint32_t version_tag_to_vendor_version_number(const char *tag); */ __EXPORT uint32_t px4_firmware_vendor_version(void); +/** + * get the PX4 Firmware vendor version git tag top number + * @return number of git commits after git tag + */ +__EXPORT uint32_t px4_firmware_git_top_number(void); + /** * get the board version (last 8 bytes should be silicon ID, if any) */