Skip to content

Commit

Permalink
Update Template
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-coast committed Jul 2, 2024
1 parent 17bef5b commit 642265e
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
23 changes: 8 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# **********************************************************
# 2024 : Arthur JEULIN
# Copyright (c) Arthur JEULIN
# Created by Arthur JEULIN on 06/22/2024.
# Created by Arthur JEULIN on 07/05/2024.
# **********************************************************
cmake_minimum_required(VERSION 3.27.5)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Indiquez à CMake d'utiliser les outils de vcpkg
if(UNIX)
endif()
if(WIN32)
set(CMAKE_GENERATOR_TOOLSET "v142")
set(VCPKG_PLATFORM_TOOLSET v142)
endif()

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")


set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

project(template
DESCRIPTION "Template Project Library "
LANGUAGES CXX
Expand All @@ -28,20 +30,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

option(BUILD_SHARED_LIBS "Build shared libraries" OFF)


include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing() #to discover tests in test explorer

include_directories(include)
include_directories( "${PROJECT_SOURCE_DIR}/build/vcpkg_installed/x64-windows/include")

add_subdirectory(src)
add_subdirectory(example)
add_subdirectory(test)
add_subdirectory(test)
add_subdirectory(rtmaps)
37 changes: 37 additions & 0 deletions install_vcpkg.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@echo off
SETLOCAL
:: **********************************************************
:: 2024 : Arthur JEULIN
:: Copyright (c) Coast Autonomous
:: Created by Arthur JEULIN on 07/03/2024.
:: **********************************************************
::
:: Module : Install VCPKG Folder for Windows User
::

:: to run this script on windows
:: open powershell and run:
:: ./install_vcpkg.bat
::
:: Définition du répertoire d'installation de vcpkg
set VCPKG_DIR=%~dp0vcpkg

:: Clonage de vcpkg
echo Clonage de vcpkg...
git clone https://github.com/microsoft/vcpkg.git "%VCPKG_DIR%"
if %errorlevel% neq 0 (
echo Échec du clonage de vcpkg.
exit /b 1
)

:: Exécution de bootstrap-vcpkg.bat
echo Execution of bootstrap-vcpkg.bat...
cd /d "%VCPKG_DIR%"
call bootstrap-vcpkg.bat
if %errorlevel% neq 0 (
echo Fail to intialize vcpkg.
exit /b 1
)

echo vcpkg has been install and initiate with success.
ENDLOCAL
21 changes: 21 additions & 0 deletions install_vcpkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/bash
# **********************************************************
# 2024 : Arthur JEULIN
# Copyright (c) Coast Autonomous
# Created by Arthur JEULIN on 07/02/2024.
# **********************************************************
#
# Module : Install VCPKG Folder for Linux User
#

# to run this script on windows
# open wsl terminal and go to cd /mnt/c/dev/rtmaps/inventory
# ./install_vcpkg.sh
#
# CAUTION: THE FILE HAS TO BE LF AND NOTE CRLF
#


git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
136 changes: 136 additions & 0 deletions rtmaps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# **********************************************************
# 2024 : Arthur JEULIN
# Copyright (c) Coast Autonomous
# Created by Arthur JEULIN on 05/05/2024.
# **********************************************************
cmake_minimum_required(VERSION 3.27.5)


# RTMaps Package Name
set(PCK pck)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY C:/dev/rtmaps/user_sdk/packages/${PCK})

set(CMAKE_CXX_STANDARD 20)
set(POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enforce the C++ standard requirement
set(CMAKE_CXX_EXTENSIONS OFF) # Non-portable compiler-specific extensions are NOT required

if(UNIX)
set(RTMAPS_SDKDIR "/opt/rtmaps")
endif()
if(WIN32)
set(RTMAPS_SDKDIR "C:/Program Files/Intempora/RTMaps 4")
set(rtmaps_input_reader "C:/Program Files/Intempora/RTMaps 4/packages/rtmaps_input_reader")
endif()


project("${PCK}.u"
VERSION 0.0.1
DESCRIPTION "pck RTMaps package"
LANGUAGES C CXX
)


# If -D"RTMAPS_SDKDIR=<RTMaps Install Dir>" has NOT been passed to
# the "cmake" command
if (NOT DEFINED RTMAPS_SDKDIR)
# Try to use the default RTMaps installation
if (DEFINED ENV{RTMAPS_SDKDIR})
set(RTMAPS_SDKDIR "$ENV{RTMAPS_SDKDIR}"
CACHE PATH "Path the RTMaps installation directory")
else()
message(FATAL_ERROR
"RTMAPS_SDKDIR not defined. Either pass -D/"RTMAPS_SDKDIR=.../"
to CMake or define an RTMAPS_SDKDIR environment variable")
endif()
endif()

if (NOT TARGET rtmaps_input_reader)
# In this particular example, we know the path of of the rtmaps_input_readerConfig.cmake file.
# In your custom components, you might want to use something like:
set(rtmaps_input_reader_DIR "${RTMAPS_SDKDIR}/packages/rtmaps_input_reader/lib/cmake/rtmaps_input_reader" CACHE PATH "")
if (NOT rtmaps_input_reader_DIR)
get_filename_component(rtmaps_input_reader_DIR "${CMAKE_CURRENT_LIST_DIR}/../lib/cmake/rtmaps_input_reader" ABSOLUTE CACHE)
endif()
find_package(rtmaps_input_reader CONFIG REQUIRED NO_DEFAULT_PATH)
endif()



# REQUIRED: Include the RTMaps CMake configuration file
include("${RTMAPS_SDKDIR}/templates.u/rtmaps.cmake")


add_rtmaps_package(${PCK} PCKINFO "${PCK}.pckinfo"
# add sources, headers and/or directories
"local_interfaces"
"src"
)


target_include_directories(${PCK} PRIVATE
${PROJECT_SOURCE_DIR}/rtmaps/local_interfaces
)

# HIGHLY RECOMMENDED: Append useful compiler flags
if (MSVC)
# Winmm.lib Needed in Windows to Gettime (API of Windows)
target_link_libraries(${PCK}
Winmm.lib
kernel32.lib
rtmaps_input_reader
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# NE BUILD PAS EN DEBUG AVEC RTMAPS
# Options pour le mode Debug
# Ne peut pas utiliser se flag pour une raison que j'igonre /MPd
# rtmaps_pck.lib est compiler en release donc on ne peut pas utliser
# certains flags de debug car non compatible => rechercher a faire
target_compile_options(${PCK} PRIVATE /W3 /WX /MD )
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
# Options pour le mode Release
target_compile_options(${PCK} PRIVATE /MD /MP /GL /W3 /WX -DNDEBUG)
endif()
# TO IMPROVE IN THE FUTURE
# Trouver un moyen de ne pas à copier manuellement le nom des dll
# Attention *.dll ne fonctionne pas sur windows
# add_custom_command(TARGET ${PCK} POST_BUILD
# # Create the bin folder next to the pck
# COMMAND ${CMAKE_COMMAND} -E make_directory C:/dev/rtmaps/user_sdk/packages/${PCK}/$<CONFIG>/bin
# # Copy the dll in the bin folder
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# C:/dev/rtmaps/user_sdk/packages/${PCK}/$<CONFIG>/gflags.dll
# C:/dev/rtmaps/user_sdk/packages/${PCK}/$<CONFIG>/glog.dll
# # Destination
# C:/dev/rtmaps/user_sdk/packages/${PCK}/$<CONFIG>/bin


# # Delete the dll the where in the same folder as CMAKE_RUNTIME_OUTPUT_DIRECTORY
# COMMAND ${CMAKE_COMMAND} -E remove
# C:/dev/rtmaps/user_sdk/packages/${PCK}/$<CONFIG>/gflags.dll
# C:/dev/rtmaps/user_sdk/packages/${PCK}/$<CONFIG>/glog.dll
# VERBATIM
# )

else()
# LINUX
target_link_libraries(${PCK})
target_compile_options(${PCK} PRIVATE
-Wall -Wextra -Wpedantic -finline-functions -fexceptions
-O3 -fdiagnostics-show-option -pedantic)
endif()


if(WIN32)
install(TARGETS ${PCK}
CONFIGURATIONS Release
RUNTIME DESTINATION ${RTMAPS_SDKDIR}/user_sdk/packages/${PCK}
)
# this copies more than strictly necessary but I don't know how to do it better
install(DIRECTORY
"C:/dev/rtmaps/user_sdk/packages/${PCK}/Release/bin"
# Destination (pas besoin d'ajouter bin dans le chemin on copie le dossier bin)
DESTINATION ${RTMAPS_SDKDIR}/user_sdk/packages/${PCK}
)
endif()
42 changes: 42 additions & 0 deletions rtmaps/local_interfaces/maps_template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// **********************************************************
// 2024 : Arthur JEULIN
// Copyright (c) Coast Autonomous
// Created by Arthur JEULIN on 07/05/2024.
// **********************************************************
//
// Module : To be define
//

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#ifndef MAPS_TEMPLATE_H
#define MAPS_TEMPLATE_H

//#define __IPL_H__
#include <maps.hpp>
// Includes the MAPS::InputReader class and its dependencies
#include <maps/input_reader/maps_input_reader.hpp>

// Declares a new MAPSComponent child class
class MAPS_TEMPLATE : public MAPSComponent
{
// Use standard header definition macro
MAPS_COMPONENT_STANDARD_HEADER_CODE(MAPS_TEMPLATE)


private :
// Declare an input reader
std::unique_ptr<MAPS::InputReader> _inputReader;

int _log_destination;

/**
* IL faut toujours MAPSTimestamp ts en premier argument de la callback.
* Sinon erreur de compilation
*/
void ProcessData(MAPSTimestamp ts, const MAPS::InputElt<double> input);
};

#endif /*MAPS_TEMPLATE_H*/
6 changes: 6 additions & 0 deletions rtmaps/pck.pckinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Package information
VERSION=0.0.1
DESCRIPTION=User package

# LOG
# 0.0.1: initial development
85 changes: 85 additions & 0 deletions rtmaps/src/maps_template.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// **********************************************************
// 2024 : Arthur JEULIN
// Copyright (c) Coast Autonomous
// Created by Arthur JEULIN on 07/05/2024.
// **********************************************************
//
// Module : To be define
//

#include "maps_template.h" // Includes the header of this component

// Use the macros to declare the inputs
MAPS_BEGIN_INPUTS_DEFINITION(MAPS_TEMPLATE)
MAPS_INPUT("Input", MAPS::FilterFloat64,MAPS::FifoReader)
MAPS_END_INPUTS_DEFINITION

// Use the macros to declare the outputs
MAPS_BEGIN_OUTPUTS_DEFINITION(MAPS_TEMPLATE)
MAPS_OUTPUT("Output", MAPS::Float64, NULL,NULL,1)
MAPS_END_OUTPUTS_DEFINITION

// Use the macros to declare the properties
MAPS_BEGIN_PROPERTIES_DEFINITION(MAPS_TEMPLATE)
MAPS_PROPERTY_ENUM("LogDestination", "Log|Console",0, false, false)
MAPS_PROPERTY("LoggingPath", "C:/dev/log", false, false)
MAPS_END_PROPERTIES_DEFINITION

// Use the macros to declare the actions
MAPS_BEGIN_ACTIONS_DEFINITION(MAPS_TEMPLATE)
MAPS_END_ACTIONS_DEFINITION


// Use the macros to declare this component (SaveRFID) behaviour
MAPS_COMPONENT_DEFINITION(MAPS_TEMPLATE,"save_rfid","1.0",128,
MAPS::Threaded,MAPS::Threaded,
-1, // Nb of inputs. Leave -1 to use the number of declared input definitions
-1, // Nb of outputs. Leave -1 to use the number of declared output definitions
-1, // Nb of properties. Leave -1 to use the number of declared property definitions
-1) // Nb of actions. Leave -1 to use the number of declared action definitions

//Initialization: Birth() will be called once at diagram execution startup.
void MAPS_TEMPLATE::Birth()
{

_inputReader = MAPS::MakeInputReader::Triggered(
this,
// The input reader will first wait for data on this input
Input("Input"),

// TriggerKind::DataInput means that we want to access the "value" of the data of the trigger input in the callback.
// In this case, the trigger input MUST be added to the list of data inputs (see the next argument)
MAPS::InputReaderOption::Triggered::TriggerKind::DataInput,
// SamplingBehavior::WaitForAllInputs means that the data callback will be called
// only if there are data samples on all inputs
MAPS::InputReaderOption::Triggered::SamplingBehavior::WaitForAllInputs,

MAPS::MakeArray(&Input("Input")),

// This callback will be called when data was read from the trigger AND the data inputs.
&MAPS_TEMPLATE::ProcessData
);

}


void MAPS_TEMPLATE::Core()
{
_inputReader->Read();
}

void MAPS_TEMPLATE::Death()
{
_inputReader.reset();
}

void MAPS_TEMPLATE::ProcessData(MAPSTimestamp ts, const MAPS::InputElt<double> input)
{

MAPS::OutputGuard<double> outGuard{this, Output("oRFID")};
outGuard.Data() = input.Data() * 2;
// As always, set the VectorSize and the Timestamp
outGuard.VectorSize() = 1;
// outGuard.VectorSize() = (MAPSInt32)output_string.size();
outGuard.Timestamp() = MAPS::CurrentTime();
}
Loading

0 comments on commit 642265e

Please sign in to comment.