Skip to content

Commit

Permalink
add system module that publishes firmware info
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Sep 24, 2024
1 parent d4bb13e commit 7948747
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

include(${CMAKE_DIR}/full_firmware_info.cmake)

add_subdirectory(${ROOT_DIR}/Src/platform/${APP_PLATFORM})
1 change: 1 addition & 0 deletions Src/applications/dronecan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cmake_path(GET APPLICATIONS_DIR PARENT_PATH SRC_DIR)
add_definitions(-DCONFIG_USE_DRONECAN=1)

include(${SRC_DIR}/modules/dronecan/core/CMakeLists.txt)
include(${SRC_DIR}/modules/system/CMakeLists.txt)
include(${SRC_DIR}/modules/dronecan/arming/CMakeLists.txt)
include(${SRC_DIR}/modules/circuit_status/dronecan/CMakeLists.txt)
include(${SRC_DIR}/modules/dronecan/feedback/CMakeLists.txt)
Expand Down
15 changes: 15 additions & 0 deletions Src/modules/system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2023 Dmitry Ponomarev <[email protected]>
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.


list(APPEND APPLICATION_HEADERS
${CMAKE_CURRENT_LIST_DIR}
)

list(APPEND APPLICATION_SOURCES
${CMAKE_CURRENT_LIST_DIR}/main.cpp
)

list(APPEND LIBPARAMS_PARAMS
${CMAKE_CURRENT_LIST_DIR}/params.yaml
)
35 changes: 35 additions & 0 deletions Src/modules/system/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* This program is free software under the GNU General Public License v3.
* See <https://www.gnu.org/licenses/> for details.
* Author: Dmitry Ponomarev <[email protected]>
*/

#include "modules/system/main.hpp"
#include <storage.h>
#include "can_driver.h"
#include "common/algorithms.hpp"
#include "params.hpp"
#include "logger.hpp"

static Logger logger = Logger("SYS");

REGISTER_MODULE(SystemModule)

void SystemModule::init() {
health = Status::OK;
need_notification = paramsGetIntegerValue(IntParamsIndexes::PARAM_LOG_LEVEL) <= 1;
mode = Module::Mode::STANDBY;
}

void SystemModule::spin_once() {
if (!need_notification || HAL_GetTick() < 1000) {
return;
}

need_notification = false;

// Maximum expected firmware full info size
constexpr size_t max_full_info_size = sizeof("Node v99.99.99_BADCOFFE RelWithDebInfo CLANG 999.999.999");
static_assert(sizeof(FIRMWARE_FULL_INFO) < max_full_info_size);
logger.log_info(FIRMWARE_FULL_INFO);
}
30 changes: 30 additions & 0 deletions Src/modules/system/main.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This program is free software under the GNU General Public License v3.
* See <https://www.gnu.org/licenses/> for details.
* Author: Dmitry Ponomarev <[email protected]>
*/

#ifndef SRC_MODULES_SYSTEM_HPP_
#define SRC_MODULES_SYSTEM_HPP_

#include "module.hpp"

#ifdef __cplusplus
extern "C" {
#endif

class SystemModule : public Module {
public:
SystemModule() : Module(2, Protocol::DRONECAN) {}
void init() override;

protected:
void spin_once() override;
bool need_notification{false};
};

#ifdef __cplusplus
}
#endif

#endif // SRC_MODULES_SYSTEM_HPP_
15 changes: 15 additions & 0 deletions Src/modules/system/params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
system.log_level:
type: Integer
note:
"Log level. See [debug.LogLevel](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#loglevel) and [diagnostic.Severity](https://github.com/OpenCyphal/public_regulated_data_types/blob/master/uavcan/diagnostic/Severity.1.0.dsdl).
</br> 0 - Log everything (DEBUG, INFO, WARNING, ERROR)
</br> 1 - Log at least INFO level
</br> 2 - Log at least WARNING level
</br> 3 - Log at least ERROR level
</br> 4 - Disable logging
</br> By default 3 to show only realy important messages."
enum: PARAM_LOG_LEVEL
flags: mutable
default: 3
min: 0
max: 4
8 changes: 8 additions & 0 deletions cmake/full_firmware_info.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (C) 2023-2024 Dmitry Ponomarev <[email protected]>
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.

if(NOT CMAKE_CXX_COMPILER_ID)
message(FATAL_ERROR "C++ compiler not set yet")
endif()
set(TOOLCHAIN_INFO "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
add_definitions(-DFIRMWARE_FULL_INFO="Node v${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH}_${GIT_HASH_SHORT_8_DIGITS} ${CMAKE_BUILD_TYPE} ${TOOLCHAIN_INFO}")
30 changes: 28 additions & 2 deletions cmake/git.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Copyright (C) 2023-2024 Dmitry Ponomarev <[email protected]>
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.

# Function to ensure a variable is within the range of 0 to 99
function(check_version_component component_name component_value)
if(NOT ("${component_value}" MATCHES "^[0-9]+$"))
message(FATAL_ERROR "${component_name} must be an integer.")
endif()

if(${component_value} GREATER 99 OR ${component_value} LESS 0)
message(FATAL_ERROR "${component_name} must be between 0 and 99. Current value: ${component_value}")
endif()
endfunction()

execute_process(
COMMAND git rev-parse --short=16 HEAD
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_VARIABLE GIT_HASH_SHORT
OUTPUT_VARIABLE GIT_HASH_SHORT_16_DIGITS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(SUBSTRING "${GIT_HASH_SHORT_16_DIGITS}" 0 8 GIT_HASH_SHORT_8_DIGITS)

execute_process(
COMMAND rl-git-info --major
COMMAND_ERROR_IS_FATAL ANY
Expand All @@ -19,8 +32,21 @@ execute_process(
OUTPUT_VARIABLE APP_VERSION_MINOR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND rl-git-info --patch
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_VARIABLE APP_VERSION_PATCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Check each version component
check_version_component("APP_VERSION_MAJOR" ${APP_VERSION_MAJOR})
check_version_component("APP_VERSION_MINOR" ${APP_VERSION_MINOR})
check_version_component("APP_VERSION_PATCH" ${APP_VERSION_PATCH})

add_definitions(-DAPP_VERSION_MAJOR=${APP_VERSION_MAJOR})
add_definitions(-DAPP_VERSION_MINOR=${APP_VERSION_MINOR})
add_definitions(-DAPP_VERSION_PATCH=${APP_VERSION_PATCH})

set(GIT_HASH "0x${GIT_HASH_SHORT}")
set(GIT_HASH "0x${GIT_HASH_SHORT_16_DIGITS}")
add_definitions(-DGIT_HASH=${GIT_HASH})

0 comments on commit 7948747

Please sign in to comment.