-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
78 lines (62 loc) · 2.26 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <QApplication>
#include <QtSerialPort/QSerialPort>
#include "logging.hpp"
#include "modem/serial.hpp"
#include "modem/utils/cache_manager.hpp"
#include "cli/cli.hpp"
#include "cli/modem_controller.hpp"
#include "cli/definitions/colors.hpp"
#include <thread>
//#define DEBUG
int main(int argc, char *argv[]) {
qInstallMessageHandler(logOutputHandler);
QApplication app(argc, argv);
auto mainLogger = spdlog::basic_logger_mt("main",
LOGS_FILEPATH,
true);
spdlog::flush_on(spdlog::level::debug);
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [%n] [function %!] [line %#] %v");
#ifdef __APPLE__
const char* portName = "/dev/tty.usbserial-1410";
#elif __linux__
const char* portName = "/dev/ttyUSB0";
#endif
SerialPort serial(portName,
500,
QSerialPort::Baud115200,
QSerialPort::Data8,
QSerialPort::NoParity,
QSerialPort::OneStop,
QSerialPort::NoFlowControl);
#ifndef DEBUG
if (!serial.openSerialPort()) {
std::cout << RED_COLOR << "Serial port error: " << serial.errorString().toStdString() <<
". Check module connection" << RESET << std::endl;
SPDLOG_LOGGER_ERROR(mainLogger, "Serial port was not opened: \"{}\"", serial.errorString().toStdString());
return 1;
} else {
SPDLOG_LOGGER_INFO(mainLogger, "Serial port was opened successfully. Starting modem");
}
#endif
Modem modem{serial};
CLI cli;
ModemController modemController{cli, modem};
cli.setModemController(&modemController);
#ifndef DEBUG
bool modemReady = modem.initialize();
if (!modemReady) {
SPDLOG_LOGGER_ERROR(mainLogger, "Modem initialization was not successful");
return 1;
} else {
SPDLOG_LOGGER_INFO(mainLogger, "Modem initialization was successful. Preparing CLI");
}
#endif
std::thread workerThread([&cli, &mainLogger] {
SPDLOG_LOGGER_INFO(mainLogger, "CLI listener thread started successfully");
cli.listen();
});
modem.worker();
workerThread.join();
serial.close();
return 0;
}