-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·95 lines (74 loc) · 2.56 KB
/
main.cpp
File metadata and controls
executable file
·95 lines (74 loc) · 2.56 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <fstream>
#include <string>
#include <iostream>
#include <chrono>
#include <thread>
#include <chrono>
#include "GPSParser.h"
#include "Navigation.h"
#include "GPSFileReader.h"
#include "BoatMotorDriver.h"
#include <filesystem>
#include "PaulNovackGlobals.h"
#include "AppConfig.h"
#include "WebServer.h"
#include "DataStore.h"
using namespace PaulNovack;
using namespace std;
bool isDirectory(const string& path) {
struct stat fileInfo;
if (stat(path.c_str(), &fileInfo) != 0) {
// Error occurred while retrieving file information
return false;
}
return S_ISDIR(fileInfo.st_mode);
}
int main(int argc, char* argv[]) {
// Create instances of Navigation and GPSParser FileReader and GPSReader
if (argc > 1 && string(argv[1]) == "--help") {
cout << "Usage: " << argv[0] << " <application_root>" << endl;
cout << "Provide the application root directory as an argument." << endl;
return 0;
}
// Check if the application root is provided as an argument
if (argc < 2) {
cerr << "Error: Application root not provided." << endl;
cerr << "Usage: " << argv[0] << " <application_root>" << endl;
return 1;
}
string applicationRoot = argv[1];
// Check if the provided directory exists
if (!isDirectory(applicationRoot)) {
cerr << "Error: Directory does not exist: " << applicationRoot << endl;
return 1;
}
AppConfig config(applicationRoot + "/.env");
DataStore ds(config);
GPSParser gpsParser;
Navigation navigation;
navigation.setConfig(config);
BoatMotorDriver boatMotorDriver;
GPSUtils gpsUtils;
gpsParser.setConfig(config);
gpsParser.setNavigation(navigation);
gpsParser.setGPSUtils(gpsUtils);
navigation.setGPSParser(gpsParser);
navigation.setGPSUtils(gpsUtils);
boatMotorDriver.setConfig(config);
boatMotorDriver.setNavigation(navigation);
// start the MotorDriver watching the GPS coordinates in thread
thread boatMotorDriverThread(&PaulNovack::BoatMotorDriver::runCheck, &boatMotorDriver);
thread destinationReaderThread(&PaulNovack::Navigation::ReadDestination, &navigation);
PaulNovack::GPSFileReader gpsFileReader;
gpsFileReader.setPlugins(navigation, gpsParser);
// BoatAutoPilotCrowWebServer boatAutoPilotCrowWebServer;
// boatAutoPilotCrowWebServer.setPlugins(navigation,gpsParser);
thread gpsMockReaderThread(&PaulNovack::GPSFileReader::RunFileReader, &gpsFileReader);
// Read from a file simulate a GPS Reciever
// gpsFileReader.RunFileReader();
WebServer webserver;
webserver.setNavigation(navigation);
webserver.setDataStore(ds);
webserver.Run();
return 0;
}