Skip to content

Commit

Permalink
add git top info
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoSairiala committed Aug 1, 2024
1 parent 742b309 commit ce6bb39
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/lib/version/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/lib/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
*/
Expand Down

0 comments on commit ce6bb39

Please sign in to comment.