gclogger/src/GcLogger.cpp

64 lines
1.7 KiB
C++

//
// Created by h44z on 07.05.19.
//
#include <fstream>
#include "GcLogger.h"
void GcLogger::setup(const string &deviceSerialPort, int deviceBaudRate) {
baudRate = deviceBaudRate;
serialPort = deviceSerialPort;
cout << "Serial port configuration: port=" << deviceSerialPort << " baud=" << deviceBaudRate << endl;
device = new GmcDevice(deviceSerialPort, deviceBaudRate);
if (!device->isConnected()) {
cout << "Failed to connect to device!" << endl;
} else {
cout << "Device connected!" << endl;
isSetup = true;
}
}
int GcLogger::run() {
if (!isSetup) {
cout << "Setup not completed successfully, cannot run gclogger!" << endl;
return EXIT_FAILURE;
} else {
cout << "Running gclogger!" << endl;
string deviceVersion = device->getVersion();
cout << "GMC Device version: " << deviceVersion << endl;
int cpm = device->getCPM();
cout << "CPM: " << cpm << endl;
float temperature = device->getTemperature();
cout << "Temperature: " << temperature << endl;
device->close();
return EXIT_SUCCESS;
}
}
void GcLogger::readIni(const 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);
}
}