@@ -70,6 +70,19 @@ __EXPORT const char *os_git_tag = "";
7070__EXPORT const uint32_t px4_board_version = 1 ;
7171#endif
7272
73+ // dev >= 0
74+ // alpha >= 64
75+ // beta >= 128
76+ // release candidate >= 192
77+ // release == 255
78+ enum FIRMWARE_TYPE {
79+ FIRMWARE_TYPE_DEV = 0 ,
80+ FIRMWARE_TYPE_ALPHA = 64 ,
81+ FIRMWARE_TYPE_BETA = 128 ,
82+ FIRMWARE_TYPE_RC = 192 ,
83+ FIRMWARE_TYPE_RELEASE = 255
84+ };
85+
7386/**
7487 * Convert a version tag string to a number
7588 */
@@ -78,9 +91,16 @@ uint32_t version_tag_to_number(const char *tag)
7891 uint32_t ver = 0 ;
7992 unsigned len = strlen (tag );
8093 unsigned mag = 0 ;
94+ int32_t type = -1 ;
8195 bool dotparsed = false;
96+ unsigned dashcount = 0 ;
8297
8398 for (int i = len - 1 ; i >= 0 ; i -- ) {
99+
100+ if (tag [i ] == '-' ) {
101+ dashcount ++ ;
102+ }
103+
84104 if (tag [i ] >= '0' && tag [i ] <= '9' ) {
85105 unsigned number = tag [i ] - '0' ;
86106
@@ -94,6 +114,29 @@ uint32_t version_tag_to_number(const char *tag)
94114 /* this is a full version and we have enough digits */
95115 return ver ;
96116
117+ } else if (tag [i ] == '-' && i > 3 && type == -1 ) {
118+ /* scan until the first number */
119+ const char * curr = & tag [i - 1 ];
120+
121+ // dev: v1.4.0rc3-7-g7e282f57
122+
123+ while (curr >= & tag [0 ] && (* curr <= '0' || * curr >= '9' )) {
124+ if (* curr == 'd' ) {
125+ type = FIRMWARE_TYPE_DEV ;
126+ break ;
127+ } else if (* curr == 'a' ) {
128+ type = FIRMWARE_TYPE_ALPHA ;
129+ break ;
130+ } else if (* curr == 'b' ) {
131+ type = FIRMWARE_TYPE_BETA ;
132+ break ;
133+ } else if (* curr == 'r' ) {
134+ type = FIRMWARE_TYPE_BETA ;
135+ break ;
136+ }
137+ curr -- ;
138+ }
139+
97140 } else if (tag [i ] != 'v' ) {
98141 /* reset, because we don't have a full tag but
99142 * are seeing non-numeric characters again
@@ -103,15 +146,16 @@ uint32_t version_tag_to_number(const char *tag)
103146 }
104147 }
105148
106- // XXX not reporting patch version yet
107- // dev > 0
108- // alpha > 64
109- // beta > 128
110- // release candidate > 192
111- // release > 255
149+ /* if the type is still uninitialized, check if there is a single dash in git describe */
150+ if (type == -1 && dashcount == 1 ) {
151+ type = FIRMWARE_TYPE_RELEASE ;
152+ } else if (type == -1 ) {
153+ type = FIRMWARE_TYPE_DEV ;
154+ }
155+
112156 ver = (ver << 8 );
113157
114- return ver ;
158+ return ver | type ;
115159}
116160
117161static void usage (const char * reason )
@@ -167,8 +211,8 @@ int ver_main(int argc, char *argv[])
167211 unsigned minor = (fwver >> (8 * 2 )) & 0xFF ;
168212 unsigned patch = (fwver >> (8 * 1 )) & 0xFF ;
169213 unsigned type = (fwver >> (8 * 0 )) & 0xFF ;
170- printf ("FW version: %s (%u.%u.%u %s) \n" , px4_git_tag , major , minor , patch ,
171- ( type == 0 ) ? "dev" : "stable" );
214+ printf ("FW version: %s (%u.%u.%u %u), %u \n" , px4_git_tag , major , minor , patch ,
215+ type , fwver );
172216 /* middleware is currently the same thing as firmware, so not printing yet */
173217 printf ("OS version: %s (%u)\n" , os_git_tag , version_tag_to_number (os_git_tag ));
174218 ret = 0 ;
0 commit comments