From 972a6f7be8a7d716d263d1731b0c9b0a49848a97 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 2 Jul 2016 11:43:24 +0200 Subject: [PATCH] Fix MAVLink reporting of Firmware version, implement dev / release version reporting --- src/modules/mavlink/mavlink_main.cpp | 4 +- src/modules/systemlib/battery_params.c | 3 +- src/systemcmds/ver/ver.c | 62 ++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index 42c17a8fdc73..b9ca1f25762d 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -1222,8 +1222,8 @@ void Mavlink::send_autopilot_capabilites() msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_ATTITUDE_TARGET; msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_POSITION_TARGET_LOCAL_NED; msg.capabilities |= MAV_PROTOCOL_CAPABILITY_SET_ACTUATOR_TARGET; - msg.flight_sw_version = version_tag_to_number(px4_git_version); - msg.middleware_sw_version = version_tag_to_number(px4_git_version); + msg.flight_sw_version = version_tag_to_number(px4_git_tag); + msg.middleware_sw_version = version_tag_to_number(px4_git_tag); msg.os_sw_version = version_tag_to_number(os_git_tag); msg.board_version = px4_board_version; memcpy(&msg.flight_custom_version, &px4_git_version_binary, sizeof(msg.flight_custom_version)); diff --git a/src/modules/systemlib/battery_params.c b/src/modules/systemlib/battery_params.c index fdf4826afdd5..e6d9b62030ed 100644 --- a/src/modules/systemlib/battery_params.c +++ b/src/modules/systemlib/battery_params.c @@ -125,6 +125,7 @@ PARAM_DEFINE_FLOAT(BAT_V_LOAD_DROP, 0.3f); * * @group Battery Calibration * @unit S + * @value 0 Unconfigured * @value 2 2S Battery * @value 3 3S Battery * @value 4 4S Battery @@ -141,7 +142,7 @@ PARAM_DEFINE_FLOAT(BAT_V_LOAD_DROP, 0.3f); * @value 15 15S Battery * @value 16 16S Battery */ -PARAM_DEFINE_INT32(BAT_N_CELLS, 3); +PARAM_DEFINE_INT32(BAT_N_CELLS, 0); /** * Battery capacity. diff --git a/src/systemcmds/ver/ver.c b/src/systemcmds/ver/ver.c index 0b7584c88855..b69fd39e4766 100644 --- a/src/systemcmds/ver/ver.c +++ b/src/systemcmds/ver/ver.c @@ -70,6 +70,19 @@ __EXPORT const char *os_git_tag = ""; __EXPORT const uint32_t px4_board_version = 1; #endif +// dev >= 0 +// alpha >= 64 +// beta >= 128 +// release candidate >= 192 +// release == 255 +enum FIRMWARE_TYPE { + FIRMWARE_TYPE_DEV = 0, + FIRMWARE_TYPE_ALPHA = 64, + FIRMWARE_TYPE_BETA = 128, + FIRMWARE_TYPE_RC = 192, + FIRMWARE_TYPE_RELEASE = 255 +}; + /** * Convert a version tag string to a number */ @@ -78,9 +91,16 @@ uint32_t version_tag_to_number(const char *tag) uint32_t ver = 0; unsigned len = strlen(tag); unsigned mag = 0; + int32_t type = -1; bool dotparsed = false; + unsigned dashcount = 0; for (int i = len - 1; i >= 0; i--) { + + if (tag[i] == '-') { + dashcount++; + } + if (tag[i] >= '0' && tag[i] <= '9') { unsigned number = tag[i] - '0'; @@ -94,6 +114,29 @@ uint32_t version_tag_to_number(const char *tag) /* this is a full version and we have enough digits */ return ver; + } else if (tag[i] == '-' && i > 3 && type == -1) { + /* scan until the first number */ + const char *curr = &tag[i - 1]; + + // dev: v1.4.0rc3-7-g7e282f57 + + while (curr >= &tag[0] && (*curr <= '0' || *curr >= '9')) { + if (*curr == 'd') { + type = FIRMWARE_TYPE_DEV; + break; + } else if (*curr == 'a') { + type = FIRMWARE_TYPE_ALPHA; + break; + } else if (*curr == 'b') { + type = FIRMWARE_TYPE_BETA; + break; + } else if (*curr == 'r') { + type = FIRMWARE_TYPE_BETA; + break; + } + curr--; + } + } else if (tag[i] != 'v') { /* reset, because we don't have a full tag but * are seeing non-numeric characters again @@ -103,15 +146,16 @@ uint32_t version_tag_to_number(const char *tag) } } - // XXX not reporting patch version yet - // dev > 0 - // alpha > 64 - // beta > 128 - // release candidate > 192 - // release > 255 + /* if the type is still uninitialized, check if there is a single dash in git describe */ + if (type == -1 && dashcount == 1) { + type = FIRMWARE_TYPE_RELEASE; + } else if (type == -1) { + type = FIRMWARE_TYPE_DEV; + } + ver = (ver << 8); - return ver; + return ver | type; } static void usage(const char *reason) @@ -167,8 +211,8 @@ int ver_main(int argc, char *argv[]) unsigned minor = (fwver >> (8 * 2)) & 0xFF; unsigned patch = (fwver >> (8 * 1)) & 0xFF; unsigned type = (fwver >> (8 * 0)) & 0xFF; - printf("FW version: %s (%u.%u.%u %s)\n", px4_git_tag, major, minor, patch, - (type == 0) ? "dev" : "stable"); + printf("FW version: %s (%u.%u.%u %u), %u\n", px4_git_tag, major, minor, patch, + type, fwver); /* 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;