46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
//
|
|
// Created by h44z on 07.05.19.
|
|
//
|
|
|
|
#include <fstream>
|
|
#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);
|
|
}
|
|
}
|