WiP: init phase refactor 2

This commit is contained in:
Mati committed 2019-07-16 17:52:25 +02:00
1 parent f71e016339
commit db83a0ded5
7 files changed
+14 -18

No files matched your search

+2 -2
View File
@@ -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)
+2 -2
View File
@@ -21,7 +21,7 @@
namespace bsp{
std::unique_ptr<Cellular> Cellular::Create(const char* term) {
std::optional<std::unique_ptr<Cellular>> Cellular::Create(const char* term) {
std::unique_ptr<Cellular> inst;
@@ -37,7 +37,7 @@ namespace bsp{
return inst;
}
return nullptr;
return {};
}
}
+2 -1
View File
@@ -12,6 +12,7 @@
#ifndef PUREPHONE_BSP_CELLULAR_HPP
#define PUREPHONE_BSP_CELLULAR_HPP
#include <optional>
#include <stdint.h>
#include <stddef.h>
#include <memory>
@@ -21,7 +22,7 @@ namespace bsp {
class Cellular {
public:
static std::unique_ptr<Cellular> Create(const char* term = "/dev/ttyUSB0");
static std::optional<std::unique_ptr<Cellular>> Create(const char* term = "/dev/ttyUSB0");
Cellular() {}
virtual ~Cellular() {}
-3
View File
@@ -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}")
+4 -5
View File
@@ -15,14 +15,14 @@
#include "cellular/bsp_cellular.hpp"
std::unique_ptr<InOutSerialWorker> InOutSerialWorker::Create(MuxDaemon *mux) {
std::optional<std::unique_ptr<InOutSerialWorker>> InOutSerialWorker::Create(MuxDaemon *mux) {
auto inst = std::make_unique<InOutSerialWorker>(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;
}
+3 -2
View File
@@ -12,6 +12,7 @@
#ifndef PUREPHONE_INOUTSERIALWORKER_HPP
#define PUREPHONE_INOUTSERIALWORKER_HPP
#include <optional>
#include "FreeRTOS.h"
#include "task.h"
#include "GSM0710.hpp"
@@ -33,13 +34,13 @@ public:
CMUX
};
static std::unique_ptr<InOutSerialWorker> Create(MuxDaemon* mux);
static std::optional<std::unique_ptr<InOutSerialWorker>> 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);
+1 -3
View File
@@ -98,13 +98,11 @@ std::unique_ptr<MuxDaemon> 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;
}