gclogger/src/GcLogger.cpp

64 lines
1.7 KiB
C++
Raw Normal View History

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