Linux
Linux software install
Google repo的使用
Vector AP StartApplication编译脚本解析
Yocto的cmake版本升级
不能自动安装的解决方式
S32G-BSP35.0-SDK使用方法
S32G从SDK生成文件系统的制作过程
Linux Samba设置
Linux添加双网卡
S32G USB-Redirector安装指南
VS code自动生成Doxygen格式注释
Linux下使用多线程下载
使用pandoc 生成带中文的pdf
minicom无法输入的问题解决办法
使用 systemd unit 添加一条路由规则
CMake 教程
步骤 1:基本起点
步骤 2:添加lib库
步骤 3:为库添加使用要求
步骤 4:添加生成器表达式
步骤 5:安装和测试
步骤 6:添加支持测试仪表板
步骤 7: 添加系统内省
步骤 8:自定义命令和生成的文
步骤 9:打包安装程序
步骤 10:选择静态库或共享库
步骤 11:添加导出配置
步骤 12:打包 Debug 和 Release
添加虚拟网卡
Vector AP 去掉防篡改校验
Vector AP startapplication编译与使用
Vector AP问题汇总
Vector AP大型项目开发流程
Vector AP EM
Vector AP 最简单的开发示例
Linux kernel 版本降级
Vector AP StartApplicaiton
startappplication-machine-design
startapplicaiton-machine-integration
amsr-vector-fs-em-executionmanager-design
amsr-vector-fs-em-executionmanager
Vector AP 复杂模型的开发
第一章 Machine和MachineDesign
第二章 Execute Manager
第三章 Log
第四章 State Manager
第五章 State Manager 源码的理解
第六章 Someip daemon
第七章 IPC Service Discovery Daemon
crond的使用方法
解决蓝牙鼠标在 Ubuntu 中单位时间内断开的问题
VPS服务器自建教程
v2rayA的客户端使用配置
GDB调试指南入门篇:揭开程序运行世界的神秘面纱
GDB调试指南高级篇:成为调试专家,掌控程序的命运
Linux安装PyQt5并配置Qt Designer
ADB 命令大全
GoogleTest(一)
GoogleTest(二)简单的TEST宏
GoogleTest(三)简单类函数测试
C++ Template
1. 函数模板
2. 类模板
3. 非类型模板参数
软件版本号规范
EPOLL
C++手札
C++ 使用{}初始化有哪些好处?
现代 C++ decltype 深入解析
函数对象(functor)
Linux性能剖析:CPU、内存、网络与I/O压力测试
AP StateManager
C++ Lambda表达式
C++ 中的Lambda表达式
Lambda 表达式语法
Lambda 表达式的示例
手动发送UDP数据包
pyqt5生成的UI界面不能输入中文
自己搭建repo镜像
摄影
Sony仿富士PP值设置
诗词歌赋
本文档使用 MrDoc 发布
-
+
首页
Vector AP 最简单的开发示例
## 前言 <span style="color:darkred;">开发第一条:app最下层的CMakeLists.txt中,`set(TARGET xxxx)` ,这个`xxxx`一定要和`Executable`中的`SHORT-NAME` 一致。</span> ## 创建工程kochi-hello 1. 新建kochi-hello工程 2. 创建Executable 注意:这个Name就是前言中所说的`Executable`中的`SHORT-NAME` a. Application 选项 b. Executable->Create Name: kochi_hello Package: /kochi/helloworld File: kochi_machines.arxml  创建SWC  3. 创建Machine 创建KochiMachine,名字无所谓。通过想到创建的Machine的同时会创建MachineDesgin,这个MachineDesgin要不要都是无所谓的。  4. 编辑Machine 编辑Machine,创建LogAndTrace  右键Logging,选择点击Create Log And Trace Instantiation。  Create Log And Trace Instantiation之后就可以创建LogChannel  编辑LogChannel  5. 创建Process 创建Process  创建ProcessDesgin, 这里默认就可以了,直接next。不用增加什么东西  关联到Executable  勾选,并finish  Mapping Process  Mapping LogAndTraceIntantiation  这里有一个值需要记录一下 `/kochi/helloworld/kochi_hello_process`  6. Model Scopes  然后校验一下配置的工程,这里只要配置了log,因此只要选择两个生成器就可以了。即:`amsr_logapi_config Generator`和`amsr_applicationbase Generator`勾选即可   然后点击validate,通过即表示可以写代码了 ## 手写代码 ### 目录结构 sam@sam-pn64:/diskA/vector-CBD1800182_D94/Examples$ tree kochi-hello kochi-hello ├── app │ ├── CMakeLists.txt │ └── hewo_kochihelloworld │ ├── CMakeLists.txt │ ├── etc │ │ └── version.txt │ └── src │ └── main.cpp ├── arxml │ ├── AUTOSAR_MOD_StandardTypes.arxml │ └── kochi_machines.arxml ├── build_startapplication.sh ├── CMakeLists.txt ├── CMakePresets.json ├── msra -> /diskA/vector-CBD1800182_D94/ ├── run_startapplication.sh └── scripts 1. 首先要软链接 ln -s /diskA/vector-CBD1800182_D94/ msra 2. 创建顶层CMakeLists.txt ```cmake cmake_minimum_required(VERSION 3.25) # The MSRA stack is mounted here as symlink to match the actual structure which expects a subfolder. # The same is needed for ccache, since the paths are part of the cached manifests. set(MSRA_SRC_SYMLINK "${CMAKE_SOURCE_DIR}/msra") if(NOT EXISTS "${MSRA_SRC_SYMLINK}") message(FATAL_ERROR "The MSRA symlink to ${MSRA_SRC_SYMLINK} is missing") endif() if(NOT EXISTS "${MSRA_SRC_SYMLINK}/CMakeLists.txt") message(FATAL_ERROR "The MSRA root directory (CSP) seems not to be valid") endif() # If not set explicitly externally, a direct use of CMakeLists.txt root file is assumed! if(NOT CMAKE_MODULE_PATH) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/msra/CMake/Module") endif() # Functions for common project config include(TacoConfig) # These options have to be set before CMake detects/configures the toolchain # Avoid in-source builds taco_no_insource_build() # Define build configurations taco_build_config(CUSTOM ALsan Tsan Ubsan ReleaseWithO2) # Top level project info project(STARTAPP DESCRIPTION "VSA STARTAPP - Vehicle Update Manager Start Application uses MICROSAR Adaptive as sub-project" HOMEPAGE_URL "vector.com") # Project specific language settings set(CMAKE_C_STANDARD "14") set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD "17" CACHE STRING "") set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) set_property(CACHE CMAKE_CXX_STANDARD PROPERTY STRINGS "14;17") if(NOT CMAKE_CXX_STANDARD MATCHES "(14|17)") message(FATAL_ERROR "The CXX standard '${CMAKE_CXX_STANDARD}' is not supported by MICROSAR Adaptive, use 14 or 17") endif() # Find appropriate compile launchers find_package(Ccache) # Optimization of build time with Ccache taco_compile_launcher() # CMake build options set(BUILD_SHARED_LIBS OFF CACHE BOOL "ON to build shared libraries, OFF to build them as static libraries" FORCE) # Install behavior is changed due to Adaptive default set(TACO_INSTALL_BINDIR "opt/$<TARGET_FILE_BASE_NAME:*>/bin" CACHE STRING "") set(TACO_WORKING_BINDIR "opt/$<TARGET_FILE_BASE_NAME:*>" CACHE STRING "") # Not a cache variable to allow top-level projects to define a # different regex for installing resource files of executables. set(TACO_REGEX_RESOURCES "/etc/.*(\\.json(\\.validation)?|\\.txt)") # Functions for customized project properties include(TacoProperty) # Execution Manager add_subdirectory("${MSRA_SRC_SYMLINK}" "MSRA" EXCLUDE_FROM_ALL) # Necessarily enable ctest for file generation enable_testing() # Collect all targets of interest found in project path add_subdirectory(app) taco_target_list(targetList PATTERN "^kochi_.*") if(targetList) # Set project specific properties for each project target taco_target_properties("${targetList}" NAMESPACE "startapplication") endif() ``` 注意`taco_target_list(targetList PATTERN "^kochi_.*")`这里如果你将来建的target不是`kochi_`开头的,这里需要修改成你的target 正则表达式 3. 创建第二层CMakeLists.txt ```cmake add_subdirectory(hewo_kochihelloworld) # We add a custom target to simplify the build of this project # and its direct dependencies. We avoid a build all and reduce # the build time to the necessary minimum. add_custom_target(startapp_apps DEPENDS kochi_hello ) ``` 注意,这里的`hewo_kochihelloworld`是文件夹名字, `kochi_hello`是target名字(要与Executable中的SHORT-NAME对应) 4. 创建第三层CMakeLists.txt ```cmake set(TARGET kochi_hello) add_executable(${TARGET}) target_sources( ${TARGET} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp" ) dvacfg_file_gen(${TARGET} INPUT "${CMAKE_CURRENT_SOURCE_DIR}/../../arxml" OUTPUT "amsr_applicationbase.cmake" "amsr_logapi_config.cmake" GENERATOR DvACfg::amsr_applicationbase DvACfg::amsr_logapi_config DIRECTORY "${TARGET}" ) target_include_directories(${TARGET} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_link_libraries(${TARGET} PRIVATE amsr::log_ara_logging amsr::applicationbase ) add_custom_command( TARGET ${TARGET} POST_BUILD COMMENT "Copying config files for '${TARGET}' to resource directory... ${CMAKE_INSTALL_PREFIX}" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/etc/version.txt" "${CMAKE_INSTALL_PREFIX}/opt/${TARGET}/etc/version.txt" ) ``` 这里最主要的是`set(TARGET kochi_hello)`, 必须跟Executable中的SHORT-NAME一致。以及定义好arxml的所在路径。 ```c++ #include <ara/core/initialization.h> #include <ara/log/logging.h> #include <iostream> #include <fstream> #include <filesystem> /*! * \brief Helper to (de-)initialize MSRA */ class MsraInitHelper final { public: /*! * \brief Constructs an instance of MSRAInitHelper */ MsraInitHelper() noexcept { ara::core::Result<void> const init_result{ara::core::Initialize()}; if (!init_result) { std::cerr << "Initialization of MSRA for HelloWorld failed." << std::endl; std::cerr << "Result contains: " << init_result.Error().Message() << "\n"; ara::core::Abort("Could not initialize HelloWorld!"); } }; /*! * \brief Destructs an instance of MSRAInitHelper */ ~MsraInitHelper() noexcept { ara::core::Result<void> const deinit_result{ara::core::Deinitialize()}; if (!deinit_result) { std::cerr << "Deinitialization of MSRA for HelloWorld failed." << std::endl; std::cerr << "Result contains: " << deinit_result.Error().Message() << "\n"; ara::core::Abort("Could not deinitialize HelloWorld!"); } }; MsraInitHelper(MsraInitHelper const&) = delete; MsraInitHelper(MsraInitHelper&&) = delete; auto operator=(MsraInitHelper const&) -> MsraInitHelper& = delete; auto operator=(MsraInitHelper&&) -> MsraInitHelper& = delete; }; /*! * \brief Entry Point of the process. * \return Zero when successfully executed. */ auto main() -> int { // Set the short name path environment variable which is usually done by the ExecutionManager ::setenv("AMSR_PROCESS_SHORT_NAME_PATH", "/kochi/helloworld/kochi_hello_process", 0); // ::setenv("AMSR_DISABLE_INTEGRITY_CHECK", "1", 1); // Initialize MSRA MsraInitHelper const msra_init_helper{}; // Create a logger instance ara::log::Logger& logger{ara::log::CreateLogger(ara::core::StringView{"VLOG"}, ara::core::StringView{"HelloWorld"})}; logger.LogInfo() << "AAAAAAA Hello World!"; // Read application specific info from configuration file std::string app_info{}; const std::filesystem::path kConfigFileName{"./etc/version.txt"}; std::ifstream config_file{kConfigFileName}; if (config_file.is_open()) { std::getline(config_file, app_info); config_file.close(); logger.LogInfo() << app_info; } else { logger.LogError() << "Failed to read " << kConfigFileName.c_str() << "."; } return 0; } ``` 这里记得要改个路径`::setenv("AMSR_PROCESS_SHORT_NAME_PATH", "/kochi/helloworld/kochi_hello_process", 0);`,就是要将环境变量`AMSR_PROCESS_SHORT_NAME_PATH`设置成`/kochi/helloworld/kochi_hello_process`这个路径就是之前让你记住的process的路径 ### 编译脚本 ```shell set -e set -o pipefail RED='\033[0;31m' BLUE='\033[1;34m' NOCOLOR='\033[0m' EXEC=echo DRY_RUN=1 COMPILE_ONLY=false STARTAPPLICATION_DIR="$(cd "$(dirname "$0")" && pwd)" MSRA_DIR=$STARTAPPLICATION_DIR/msra # The CSP is not part of the startapplication # The approach from the CSP startapplication does not work as the structure is different. # We expect the CSP to be existing before starting. if [ ! -d "$MSRA_DIR" ]; then echo -e "${RED}Error: CSP Directory does not exists: $MSRA_DIR" echo "hint: ln -s {your CSP folder} msra" exit 1 fi BUILD_DIR=$STARTAPPLICATION_DIR/BuildStartApplication INSTALL_DIR=$BUILD_DIR/install INSTALL_ADDON_DIR=$BUILD_DIR/install_addon PRESET="gcc9_linux_x86_64" CMAKE_INITIAL_CACHE_FILE="$MSRA_DIR/CMakeConfig/linux_gcc9.cmake" help_text () { echo "" echo "Usage:" echo " build_startapplication.sh [options]" echo "" echo "The execution of the build script without any options will run the script in the dry run mode." echo "The parameter --execute must be given explicitly along with the following options to execute the Start Application build." echo "Otherwise a dry run of the script takes place." echo "" echo "Options:" echo echo " --execute Execute the Start Application build." echo " --cmake-preset <compiler-name> Use another compiler." echo " e.g. --cmake-preset gcc9_linux_x86_64" echo " --cmake-initial-cache-file <path> Provide the path to a cmake initial cache file." echo " This path must be relative to the SIP directory." echo " e.g. --cmake-initial-cache-file ./CMakeConfig/linux_gcc9.cmake" echo " --cmake-settings <settings> Use non-default compiler and cmake settings." echo " e.g. --cmake-settings \"-D AMSR_IPCMULTICAST_IMPL=DAEMON" echo " -D CMAKE_BUILD_TYPE=Release\"" echo " --compile-only Skip build cache initialisations and generator calls and perform" echo " only build and install of the targets." echo " --help Display the usage and other script options." echo "" } # Extract arguments and corresponding values while [ $# -gt 0 ] do argument="$1" case $argument in --execute) EXEC="" DRY_RUN=0 IGNORE_COMMAND="" # Shift argument and value shift ;; --cmake-preset) if [ -z $2 ]; then echo -e "${RED}Error: Invalid argument value" echo "--cmake-preset is empty" exit 1 fi PRESET="$2" # Shift argument and value shift shift ;; --cmake-initial-cache-file) if [ -z $2 ]; then echo -e "${RED}Error: Invalid argument value" echo "--cmake-initial-cache-file is empty" exit 1 fi CMAKE_INITIAL_CACHE_FILE="$MSRA_DIR/$2" if [ ! -f "$CMAKE_INITIAL_CACHE_FILE" ]; then echo -e "${RED}Error: File not exists: $MSRA_DIR/$2" exit 1 fi # Shift argument and value shift shift ;; --cmake-settings) if [ -z $2 ]; then echo -e "${RED}Error: No cmake options set" echo "--cmake-settings is empty" fi CMAKE_SETTINGS="$2" # Shift argument and value shift shift ;; --compile-only) COMPILE_ONLY=true # Check if Build Cache is available if [ ! -d $BUILD_DIR ]; then echo -e "${RED}Error: No build cache available" echo -e "${NOCOLOR}Use --execute to run a full build of the Start Application." exit 1 fi shift ;; --help) help_text shift exit 1 ;; *) echo -e "${RED}Error: Invalid argument "$1" used" exit 1 esac done echo "" echo -e "${NOCOLOR}" echo "=================== Build the Start Application using TACO =========================" echo " Call CMake with the Start Application target. This will build and" echo " install the Start Application and all required BSW components." echo "------------------------------------------------------------------------------------" if [ $COMPILE_ONLY = false ]; then # Initialize cache for building the Start Application using TACO $EXEC cmake -S . $CMAKE_SETTINGS \ -B $BUILD_DIR \ --preset=$PRESET \ -C $CMAKE_INITIAL_CACHE_FILE fi # Change directory to the previously created build cache directory $EXEC cd $BUILD_DIR if [ $COMPILE_ONLY = false ]; then # Generating source code for Start Application using ctest $EXEC ctest -R '.*\.DvACfg\.Generate' --verbose --parallel $(nproc) fi # Build the Start Application by building for target startapp_apps $EXEC cmake --build . --target startapp_apps --parallel $(nproc) # Install the Start Application to INSTALL_DIR using parameter --prefix $EXEC cmake --install . --component STARTAPP_Runtime --prefix $INSTALL_DIR RETVAL=$? if [ $DRY_RUN -eq 0 ]; then if [ $RETVAL -ne 0 ]; then exit $RETVAL else echo "--------------------------------------------------------------------------------" echo " The Start Application was installed to:" echo " $INSTALL_DIR" if [ ! -z $CMAKE_TOOLCHAIN_FILE_PATH ]; then echo " with toolchain file: $CMAKE_TOOLCHAIN_FILE_PATH" fi fi fi if [ $DRY_RUN -eq 1 ]; then echo "" echo "==================================================================================" echo "This is only a dry run." echo "To execute the Start Application build, call the script with --execute." echo "To display the help for other script options, call the script with --help." echo "==================================================================================" fi ``` 编译命令:`./build_startapplication.sh --execute` ### 运行脚本 ```shell RED='\033[0;31m' BLUE='\033[1;34m' GREEN='\033[0;32m' NOCOLOR='\033[0m' SW_ROOT="./BuildStartApplication/install/opt" cd $SW_ROOT HEWO_PATH=`pwd`"/kochi_hello" echo "${BLUE}###################### executing hello world application" cd $HEWO_PATH bin/kochi_hello ``` 运行命令:`./run_startapplication.sh` ### 运行结果 
admin
2024年4月26日 18:52
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码