From 0218391ea0b0a12205c3bc4fcd255fea509df68b Mon Sep 17 00:00:00 2001 From: Tim Zeuner Date: Sun, 15 Jan 2023 22:37:21 +0100 Subject: [PATCH] Better cmake; separate main method in own file --- Communication/CMakeLists.txt | 7 ++++++- Communication/uart_communication.cpp | 18 +----------------- Communication/uart_communication_main.cpp | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 Communication/uart_communication_main.cpp diff --git a/Communication/CMakeLists.txt b/Communication/CMakeLists.txt index e33619d..223bc16 100644 --- a/Communication/CMakeLists.txt +++ b/Communication/CMakeLists.txt @@ -8,9 +8,14 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -add_executable(lfr_uart uart_communication.cpp) +add_executable(lfr_uart uart_communication.cpp uart_communication_main.cpp) +add_library(lfr_uart_lib uart_communication.cpp) target_link_libraries( lfr_uart Threads::Threads) +target_link_libraries( lfr_uart_lib Threads::Threads) + +target_include_directories(lfr_uart PUBLIC .) +target_include_directories(lfr_uart_lib PUBLIC .) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) diff --git a/Communication/uart_communication.cpp b/Communication/uart_communication.cpp index 3a1fa65..d95677d 100644 --- a/Communication/uart_communication.cpp +++ b/Communication/uart_communication.cpp @@ -133,20 +133,4 @@ void LFR_UART::closeSerialPort() { this->closeFile(); } -int main(void) { - printf("Starting the loopback application...\r\n"); - - LFR_UART uartCommunicator; - uartCommunicator.sendTelegram(-1.0, -0.99, 0.99, 1.0); - double buffer[4] = {0.0, 0.0, 0.0, 0.0}; - sleep(1); - if(uartCommunicator.readTelegram(buffer)){ - for(int i = 0; i < 4; i++) { - std::cout << buffer[i] << " "; - } - } - else { - std::cout<<"ne"; - } - return 0; -} + diff --git a/Communication/uart_communication_main.cpp b/Communication/uart_communication_main.cpp new file mode 100644 index 0000000..6e08c6c --- /dev/null +++ b/Communication/uart_communication_main.cpp @@ -0,0 +1,19 @@ +#include "uart_communication.h" + +int main(void) { + printf("Starting the loopback application...\r\n"); + + LFR_UART uartCommunicator; + uartCommunicator.sendTelegram(-1.0, -0.99, 0.99, 1.0); + double buffer[4] = {0.0, 0.0, 0.0, 0.0}; + sleep(1); + if(uartCommunicator.readTelegram(buffer)){ + for(int i = 0; i < 4; i++) { + std::cout << buffer[i] << " "; + } + } + else { + std::cout<<"ne"; + } + return 0; +} \ No newline at end of file