mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
Systemlib: Add FW and OS versioning
This commit is contained in:
@@ -765,6 +765,13 @@ function(px4_create_git_hash_header)
|
||||
ONE_VALUE HEADER
|
||||
REQUIRED HEADER
|
||||
ARGN ${ARGN})
|
||||
execute_process(
|
||||
COMMAND git describe --tags
|
||||
OUTPUT_VARIABLE git_tag
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
message(STATUS "GIT_TAG = ${git_tag}")
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
OUTPUT_VARIABLE git_desc
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
/* Do not edit! */
|
||||
#define PX4_GIT_VERSION_STR "@git_desc@"
|
||||
#define PX4_GIT_VERSION_BINARY 0x@git_desc_short@
|
||||
#define PX4_GIT_TAG_STR "@git_tag@"
|
||||
|
||||
@@ -47,5 +47,10 @@ __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
|
||||
|
||||
@@ -60,6 +60,48 @@ 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;
|
||||
const char *px4_git_tag = PX4_GIT_TAG_STR;
|
||||
|
||||
#if defined(__PX4_NUTTX)
|
||||
__EXPORT const char *os_git_tag = "6.27";
|
||||
__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
|
||||
|
||||
/**
|
||||
* 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 = 1;
|
||||
bool dotparsed = false;
|
||||
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
if (tag[i] >= '0' && tag[i] <= '9') {
|
||||
unsigned number = tag[i] - '0';
|
||||
|
||||
ver += number * mag;
|
||||
mag *= 10;
|
||||
} else if (tag[i] == '.') {
|
||||
continue;
|
||||
} else if (ver > 100 && dotparsed) {
|
||||
/* this is a full version and we have enough digits */
|
||||
return ver;
|
||||
} else if (tag[i] != 'v') {
|
||||
/* reset, because we don't have a full tag but
|
||||
* are seeing non-numeric characters again
|
||||
*/
|
||||
ver = 0;
|
||||
mag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ver;
|
||||
}
|
||||
|
||||
static void usage(const char *reason)
|
||||
{
|
||||
@@ -109,6 +151,9 @@ 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);
|
||||
printf("FW version: %s (%u)\n", px4_git_tag, version_tag_to_number(px4_git_tag));
|
||||
/* 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));
|
||||
ret = 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user