diff --git a/.gitignore b/.gitignore index ba09336..636e6d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -gclogger \ No newline at end of file +gclogger +build +cmake-build-debug +cmake-build-release +.vscode +.idea +.clion \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..445892f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.14) +project(gclogger) + +set(CMAKE_CXX_STANDARD 17) + +# Add sub CMakeList.txt +add_subdirectory(src) +add_subdirectory(libs/inipp) \ No newline at end of file diff --git a/data/sample.ini b/data/sample.ini new file mode 100644 index 0000000..b833f38 --- /dev/null +++ b/data/sample.ini @@ -0,0 +1,45 @@ +; +; Geiger Counter Logger - configuration file +; + +; Serial device filename +; ------------------------ +[serial] +port=/dev/ttyUSB0 +baud=115200 + +; GPS location of your sensor +; ----------------------------- +location=Innsbruck, AT +latitude=47.2530 +longitude=11.3969 + +; Polling interval in seconds (60..3600) +; ---------------------------------------- +interval=60 + +; +; Log portal configurations +; +; Uncomment sections to enable them +; + +; Custom REST logging portal +; ---------------------------------------------- +[custlog] +;id=example_device_id +;url=https://api.mygclog.com/log +;type=GET +;param_id=id +;param_cpm=cpm +;param_temp=temp +;param_lng=lng +;param_lat=lat +;param_loc=loc +;param_version=version +;param_time=captured_at + +; Log to CSV file +; ---------------------------------------------- +[csv] +;path=/tmp/gclog.csv \ No newline at end of file diff --git a/libs/.gitkeep b/libs/.gitkeep new file mode 100644 index 0000000..7f437bd --- /dev/null +++ b/libs/.gitkeep @@ -0,0 +1 @@ +EXTERNAL STATIC LIBRARIES GO HERE \ No newline at end of file diff --git a/libs/inipp b/libs/inipp new file mode 160000 index 0000000..a120817 --- /dev/null +++ b/libs/inipp @@ -0,0 +1 @@ +Subproject commit a12081742209b122108c159517259c16e2335345 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..8634b9f --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,8 @@ +# Notice name prefix of this variable, set by CMake according +# to value given with "project()" in the root CMakeLists.txt. +include_directories(${gclogger_SOURCE_DIR}/include) +add_executable(gclogger main.cpp GcLogger.cpp GcLogger.h) + +# I assume you want to use LibProject as a library in MainProject. +include_directories(${gclogger_SOURCE_DIR}/libs) +link_directories(${gclogger_SOURCE_DIR}/libs) \ No newline at end of file diff --git a/src/GcLogger.cpp b/src/GcLogger.cpp new file mode 100644 index 0000000..22b71b4 --- /dev/null +++ b/src/GcLogger.cpp @@ -0,0 +1,45 @@ +// +// Created by h44z on 07.05.19. +// + +#include +#include "GcLogger.h" + + +void GcLogger::setup(std::string serialPort, int baudRate) { + this->baudRate = baudRate; + this->serialPort = serialPort; + this->isSetup = true; + + cout << "Serial port configuration: port=" << serialPort << " baud=" << baudRate << endl; +} + +int GcLogger::run() { + if (!isSetup) { + cout << "Setup not completed successfully, cannot run gclogger!" << endl; + + return EXIT_FAILURE; + } else { + cout << "Running gclogger!" << endl; + + return EXIT_SUCCESS; + } +} + +void GcLogger::readIni(string filePath) { + cout << "Reading configuration from: " << filePath << endl; + + ifstream is(filePath); + if (!is.is_open()) { + cout << "Failed to open configuration file: " << filePath << endl; + } else { + this->ini.parse(is); + + int iniBaudRate = -1; + string iniSerialPort; + inipp::extract(ini.sections["serial"]["baud"], iniBaudRate); + inipp::extract(ini.sections["serial"]["port"], iniSerialPort); + + this->setup(iniSerialPort, iniBaudRate); + } +} diff --git a/src/GcLogger.h b/src/GcLogger.h new file mode 100644 index 0000000..da657fa --- /dev/null +++ b/src/GcLogger.h @@ -0,0 +1,30 @@ +// +// Created by h44z on 07.05.19. +// + +#ifndef GCLOGGER_GCLOGGER_H +#define GCLOGGER_GCLOGGER_H + + +#include +#include + +#include "inipp/inipp/inipp.h" + +using namespace std; + +class GcLogger { + bool isSetup = false; + string serialPort; + int baudRate; + inipp::Ini ini; + + void setup(string, int); + +public: + void readIni(string); + int run(); +}; + + +#endif //GCLOGGER_GCLOGGER_H diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..66ea62e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,17 @@ +// +// Created by h44z on 07.05.19. +// + +#include +#include "GcLogger.h" + +using namespace std; + +int main(int argc, char *argv[]) { + cout << "Starting up gclogger..." << endl; + + GcLogger logger; + logger.readIni("/home/h44z/workspace/gclogger/data/sample.ini"); + + return logger.run(); +} \ No newline at end of file diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..783e969 --- /dev/null +++ b/tests/.gitkeep @@ -0,0 +1 @@ +UNIT TESTS GO HERE \ No newline at end of file