-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add system module that publishes firmware info
- Loading branch information
1 parent
d4bb13e
commit 7948747
Showing
8 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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}) |