From adda695630eab92ddc45dc4ab28d30d1d75ae3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 23 Sep 2020 12:09:28 -0300 Subject: [PATCH] AP_Common: Update AP_FWVersion struct to be used with binary parsers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add an uint64_t header to allow easy detection of struct - Add an uint16_t version - MSB is for major release, compatibility break - LSB for minor version, no compatibility break - Add pointer size variable to allow decode of pointers - Add vehicle type information - Add board type and subtype to allow hardware identification - Set type of fw_type to uint8_t since enum is declared as int - Organize struct to be packed inside 32bits system Signed-off-by: Patrick José Pereira --- libraries/AP_Common/AP_FWVersion.h | 20 +++++++++++++++++--- libraries/AP_Common/AP_FWVersionDefine.h | 21 +++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/libraries/AP_Common/AP_FWVersion.h b/libraries/AP_Common/AP_FWVersion.h index 0bf66e978e..bbbbe9c621 100644 --- a/libraries/AP_Common/AP_FWVersion.h +++ b/libraries/AP_Common/AP_FWVersion.h @@ -3,21 +3,35 @@ #include #include -class AP_FWVersion { +class PACKED AP_FWVersion { public: + /** + * @brief Struct to hold infomation about the software version struct + * + */ + // First 7 MSBs are a start sequence, LSB is a checksum + const uint64_t header; + // MSB (major version breaks compatibility), LSB (minor version no compatibility break) + const uint16_t header_version; + // Pointer size to extract pointer values + const uint8_t pointer_size; + const uint8_t reserved; // padding + const uint8_t vehicle_type; + const uint8_t board_type; + const uint16_t board_subtype; const uint8_t major; const uint8_t minor; const uint8_t patch; - const FIRMWARE_VERSION_TYPE fw_type; + const uint8_t fw_type; /*FIRMWARE_VERSION_TYPE*/ + const uint32_t os_sw_version; const char *fw_string; const char *fw_hash_str; const char *middleware_name; const char *middleware_hash_str; const char *os_name; const char *os_hash_str; - const uint32_t os_sw_version; static const AP_FWVersion &get_fwverz() { return fwver; } diff --git a/libraries/AP_Common/AP_FWVersionDefine.h b/libraries/AP_Common/AP_FWVersionDefine.h index a93fc7c78c..aff9210b8d 100644 --- a/libraries/AP_Common/AP_FWVersionDefine.h +++ b/libraries/AP_Common/AP_FWVersionDefine.h @@ -21,12 +21,27 @@ #endif #include +#include const AP_FWVersion AP_FWVersion::fwver{ + // Version header struct + .header = 0x61706677766572fb, // First 7 MSBs: "apfwver", LSB is the checksum of the previous string: 0xfb + .header_version = 0x0100U, // Major and minor version + .pointer_size = static_cast(sizeof(void*)), + .reserved = 0, + .vehicle_type = static_cast(APM_BUILD_DIRECTORY), + .board_type = static_cast(CONFIG_HAL_BOARD), + .board_subtype = static_cast(CONFIG_HAL_BOARD_SUBTYPE), .major = FW_MAJOR, .minor = FW_MINOR, .patch = FW_PATCH, .fw_type = FW_TYPE, +#ifdef BUILD_DATE_YEAR + // encode build date in os_sw_version + .os_sw_version = (BUILD_DATE_YEAR*100*100) + (BUILD_DATE_MONTH*100) + BUILD_DATE_DAY, +#else + .os_sw_version = 0, +#endif #ifndef GIT_VERSION .fw_string = THISFIRMWARE, .fw_hash_str = "", @@ -43,10 +58,4 @@ const AP_FWVersion AP_FWVersion::fwver{ .os_name = nullptr, .os_hash_str = nullptr, #endif -#ifdef BUILD_DATE_YEAR - // encode build date in os_sw_version - .os_sw_version = (BUILD_DATE_YEAR*100*100) + (BUILD_DATE_MONTH*100) + BUILD_DATE_DAY, -#else - .os_sw_version = 0, -#endif };