Skip to content

Commit 972a6f7

Browse files
committed
Fix MAVLink reporting of Firmware version, implement dev / release version reporting
1 parent 2a72902 commit 972a6f7

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

src/modules/mavlink/mavlink_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,8 @@ void Mavlink::send_autopilot_capabilites()
12221222
msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET;
12231223
msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED;
12241224
msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_ACTUATOR_TARGET;
1225-
msg.flight_sw_version = version_tag_to_number(px4_git_version);
1226-
msg.middleware_sw_version = version_tag_to_number(px4_git_version);
1225+
msg.flight_sw_version = version_tag_to_number(px4_git_tag);
1226+
msg.middleware_sw_version = version_tag_to_number(px4_git_tag);
12271227
msg.os_sw_version = version_tag_to_number(os_git_tag);
12281228
msg.board_version = px4_board_version;
12291229
memcpy(&msg.flight_custom_version, &px4_git_version_binary, sizeof(msg.flight_custom_version));

src/modules/systemlib/battery_params.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ PARAM_DEFINE_FLOAT(BAT_V_LOAD_DROP, 0.3f);
125125
*
126126
* @group Battery Calibration
127127
* @unit S
128+
* @value 0 Unconfigured
128129
* @value 2 2S Battery
129130
* @value 3 3S Battery
130131
* @value 4 4S Battery
@@ -141,7 +142,7 @@ PARAM_DEFINE_FLOAT(BAT_V_LOAD_DROP, 0.3f);
141142
* @value 15 15S Battery
142143
* @value 16 16S Battery
143144
*/
144-
PARAM_DEFINE_INT32(BAT_N_CELLS, 3);
145+
PARAM_DEFINE_INT32(BAT_N_CELLS, 0);
145146

146147
/**
147148
* Battery capacity.

src/systemcmds/ver/ver.c

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

117161
static 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

Comments
 (0)