From db83a0ded5a1ec415a839dba3b986270dfd80bd0 Mon Sep 17 00:00:00 2001 From: Mati Date: Tue, 16 Jul 2019 17:52:25 +0200 Subject: [PATCH] WiP: init phase refactor 2 --- CMakeLists.txt | 4 ++-- module-bsp/bsp/cellular/bsp_cellular.cpp | 4 ++-- module-bsp/bsp/cellular/bsp_cellular.hpp | 3 ++- module-cellular/CMakeLists.txt | 3 --- module-cellular/Modem/InOutSerialWorker.cpp | 9 ++++----- module-cellular/Modem/InOutSerialWorker.hpp | 5 +++-- module-cellular/Modem/MuxDaemon.cpp | 4 +--- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95acb4035..53c75387a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.14) set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") include(env.cmake) project(PurePhone) @@ -110,8 +112,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDES}) - - message("${PROJECT_NAME}: add_subdirectory module-sys") add_subdirectory(module-sys) diff --git a/module-bsp/bsp/cellular/bsp_cellular.cpp b/module-bsp/bsp/cellular/bsp_cellular.cpp index 469db6e39..ee5103d0f 100644 --- a/module-bsp/bsp/cellular/bsp_cellular.cpp +++ b/module-bsp/bsp/cellular/bsp_cellular.cpp @@ -21,7 +21,7 @@ namespace bsp{ - std::unique_ptr Cellular::Create(const char* term) { + std::optional> Cellular::Create(const char* term) { std::unique_ptr inst; @@ -37,7 +37,7 @@ namespace bsp{ return inst; } - return nullptr; + return {}; } } \ No newline at end of file diff --git a/module-bsp/bsp/cellular/bsp_cellular.hpp b/module-bsp/bsp/cellular/bsp_cellular.hpp index 477b2c05b..82acbfd02 100644 --- a/module-bsp/bsp/cellular/bsp_cellular.hpp +++ b/module-bsp/bsp/cellular/bsp_cellular.hpp @@ -12,6 +12,7 @@ #ifndef PUREPHONE_BSP_CELLULAR_HPP #define PUREPHONE_BSP_CELLULAR_HPP +#include #include #include #include @@ -21,7 +22,7 @@ namespace bsp { class Cellular { public: - static std::unique_ptr Create(const char* term = "/dev/ttyUSB0"); + static std::optional> Create(const char* term = "/dev/ttyUSB0"); Cellular() {} virtual ~Cellular() {} diff --git a/module-cellular/CMakeLists.txt b/module-cellular/CMakeLists.txt index 9391113ac..8f3353fae 100644 --- a/module-cellular/CMakeLists.txt +++ b/module-cellular/CMakeLists.txt @@ -3,9 +3,6 @@ cmake_minimum_required(VERSION 3.12) project(module-cellular VERSION 1.0 DESCRIPTION "Cellular module library") -set(CMAKE_CXX_STANDARD 14) - - if(NOT DEFINED PROJECT_LIB_DIRECTORY ) set(PROJECT_LIB_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/" CACHE STRING "Output path for static libraries") message("Setting PROJECT_LIB_DIRECTORY to ${PROJECT_LIB_DIRECTORY}") diff --git a/module-cellular/Modem/InOutSerialWorker.cpp b/module-cellular/Modem/InOutSerialWorker.cpp index 8ed0627fa..023f2c1fc 100644 --- a/module-cellular/Modem/InOutSerialWorker.cpp +++ b/module-cellular/Modem/InOutSerialWorker.cpp @@ -15,14 +15,14 @@ #include "cellular/bsp_cellular.hpp" -std::unique_ptr InOutSerialWorker::Create(MuxDaemon *mux) { +std::optional> InOutSerialWorker::Create(MuxDaemon *mux) { auto inst = std::make_unique(mux); if(inst->isInitialized){ return inst; } else{ - return nullptr; + return {}; } } @@ -47,8 +47,7 @@ InOutSerialWorker::InOutSerialWorker(MuxDaemon *mux) : muxDaemon(mux) { } // Create and initialize bsp::Cellular module - cellular = bsp::Cellular::Create(SERIAL_PORT); - if (cellular == nullptr) { + if (cellular = bsp::Cellular::Create(SERIAL_PORT).value_or(nullptr)) { return; } @@ -422,7 +421,7 @@ int InOutSerialWorker::HandleCtrlChannelCommands(GSM0710Frame *frame) { return 0; } -void InOutSerialWorker::SwitchMode(InOutSerialWorker::Mode newMode) { +void InOutSerialWorker::SwitchMode(const InOutSerialWorker::Mode newMode) { mode = newMode; } diff --git a/module-cellular/Modem/InOutSerialWorker.hpp b/module-cellular/Modem/InOutSerialWorker.hpp index 9d0f775f8..35be083bf 100644 --- a/module-cellular/Modem/InOutSerialWorker.hpp +++ b/module-cellular/Modem/InOutSerialWorker.hpp @@ -12,6 +12,7 @@ #ifndef PUREPHONE_INOUTSERIALWORKER_HPP #define PUREPHONE_INOUTSERIALWORKER_HPP +#include #include "FreeRTOS.h" #include "task.h" #include "GSM0710.hpp" @@ -33,13 +34,13 @@ public: CMUX }; - static std::unique_ptr Create(MuxDaemon* mux); + static std::optional> Create(MuxDaemon* mux); InOutSerialWorker(MuxDaemon* mux); ~InOutSerialWorker(); - void SwitchMode(Mode newMode); + void SwitchMode(const Mode newMode); // Write data to output buffers ssize_t WriteData(unsigned char *input, size_t length); diff --git a/module-cellular/Modem/MuxDaemon.cpp b/module-cellular/Modem/MuxDaemon.cpp index 59cda7453..f3550458e 100644 --- a/module-cellular/Modem/MuxDaemon.cpp +++ b/module-cellular/Modem/MuxDaemon.cpp @@ -98,13 +98,11 @@ std::unique_ptr MuxDaemon::Create(NotificationMuxChannel::Notificatio } } -//#define SERIAL_PORT "dev/ttyUSB0" bool MuxDaemon::Start() { // Spawn input serial stream worker - inSerialDataWorker = InOutSerialWorker::Create(this); - if(inSerialDataWorker == nullptr){ + if(inSerialDataWorker = InOutSerialWorker::Create(this).value_or(nullptr)){ return false; }