mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 06:53:34 +08:00
Systemlib: Add FW and OS versioning
This commit is contained in:
@@ -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