-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
137 lines (103 loc) · 3.93 KB
/
main.cpp
File metadata and controls
137 lines (103 loc) · 3.93 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "config.h"
#include "livoxbroadcaster.h"
#include "livoxdriver.h"
#include "livoxmessages.h"
#include "vlog.h"
#include "vgit.h"
#include "vbyte_buffer.h"
#include "vbyte_buffer_view.h"
#ifdef GUI
#include <QApplication>
#else
#include <QCoreApplication>
#endif
#include <QUdpSocket>
#include <QNetworkDatagram>
#include <QStringList>
#include <QSettings>
#include <QString>
#include <QMap>
using namespace std;
//=======================================================================================
using DriverList = QMap<QString, LivoxDriver*>;
//=======================================================================================
int main( int argc, char **argv )
{
QCoreApplication::setOrganizationName( "JSC NIIAS" );
#ifdef GUI
QApplication qapp( argc, argv );
#else
QCoreApplication qapp( argc, argv );
#endif
//-----------------------------------------------------------------------------------
auto qargs = qapp.arguments();
auto cfg_path = qargs.at( qargs.indexOf( "-c" ) + 1 );
//-----------------------------------------------------------------------------------
Config config( cfg_path );
//-----------------------------------------------------------------------------------
if ( qargs.contains( "--help" ) )
{
vdeb << "Help: \n"
<< "-p - pid name \n"
<< "-c - config path \n"
<< "--vgit - print version \n"
<< "-V - print version & exit \n"
<< "--version - print version & exit \n"
<< "--print_conf - print config & exit \n"
<< "--save_conf - save config alongside the binary & exit \n";
return 0;
}
//-----------------------------------------------------------------------------------
// Print conf & exit
if ( qargs.contains( "--print_conf" ) )
{
config.deb();
return 0;
}
//-----------------------------------------------------------------------------------
// Save config as file & exit
if ( qargs.contains( "--save_conf" ) )
{
config.to_file( qapp.applicationFilePath() );
return 0;
}
//-----------------------------------------------------------------------------------
// Print version & exit
if ( qargs.contains( "-V" ) || qargs.contains( "--version" ) )
{
vdeb << vgit::as_message() << "\n\n";
return 0;
}
//-----------------------------------------------------------------------------------
if ( qargs.contains( "--vgit" ) )
vdeb << vgit::as_message() << "\n\n";
//-----------------------------------------------------------------------------------
// For listen all livox datagrams in network area
LivoxBroadcaster lbroadcast( config, &qapp );
// List of connected devices
DriverList broabcast_list;
// Start listen datagrams on local port 55000
QObject::connect( &lbroadcast, &LivoxBroadcaster::receive,
[&]( const BroabcastInfo& info )
{
if ( !config.contains( info.broadcast_code ) )
{
vdeb << "The Config doesn't contain" << info.broadcast_code;
return - 1;
}
else if ( config.contains( info.broadcast_code ) &&
!broabcast_list.contains( info.broadcast_code ) )
{
vdeb << "Register new Livox Driver with broadcast: " << info.broadcast_code;
broabcast_list.insert( info.broadcast_code,
new LivoxDriver( config, info, &qapp ) );
}
else if ( config.contains( info.broadcast_code ) &&
broabcast_list.contains( info.broadcast_code ) )
vwarning << "The Driver List already contains Device with broadcast!"
<< info.broadcast_code;
return 0;
} );
return qapp.exec();
}
//=======================================================================================