ITS
mainGeonet.cpp
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <signal.h>
3 #include <iostream>
4 #include <QMutex>
5 #include <QCoreApplication>
6 #include <GPSProvider.h>
7 #include <Geonet.h>
8 #include <Manager.h>
9 #include <UpperTester.h>
10 #include <QTimer>
11 #include <QThread>
12 #include <Facilities.h>
13 #include <getopt.h>
14 #include <unistd.h>
15 #include <ParameterUpperTester.h>
16 #include <ParameterDENM.h>
17 #include <QMetaType>
18 //#include <BluetoothBridge.h>
19 #include <DENM.h>
20 #include <ApplicationManagement.h>
21 
22 #include <decodeSecurity.h>
23 
24 Q_DECLARE_METATYPE(ActionID_t)
25 Q_DECLARE_METATYPE(DENM_t*)
26 
27 void help(char* argv)
28 {
29  fprintf(stderr, "Usage : %s <abcfCDgHnuh>\n"
30  "-a --application Activate the application management\n"
31  "-b --bluetooth Activate the Bluetooth communication\n"
32  "-c --can Use the CAN provider\n"
33  "-f --facilities Activate the facilities layer\n"
34  " -C --cam Activate CAM only\n"
35  " -D --denm Activate DENM only\n"
36  "-g --gps Use the GPS provider\n"
37  "-H --hybrid Activate the hybridization\n"
38  "-n --geonet Activate the GeoNetworking layer\n"
39  "-u --upperTester Activate the UpperTester\n"
40  "-h --help Print this message and quit\n", argv);
41  QFile file("/etc/its/security/FR01IDN00000001-AT16-verification.cert");
42  file.open(QIODevice::ReadOnly);
43  QByteArray content = file.readAll();
44  file.close();
45  Certificate_t cert;
46  decode_Certificate((unsigned char*)content.data(), &cert);
47  asn_fprint(stdout, &asn_DEF_Certificate, &cert);
48 }
49 
50 void cleanExit(int sig)
51 {
52  Q_UNUSED(sig);
53  printf("\nFin volontaire\n\n");
54  exit(0);
55 }
56 
57 int main(int argc, char *argv[])
58 {
59  signal(SIGINT, cleanExit);
60  QCoreApplication a(argc, argv);
61 
62  setenv("TZ", "UTC", 1);
63  tzset();
64 
65  qRegisterMetaType<gnDataRequest_t>("gnDataRequest_t");
66  qRegisterMetaType<GBCPacket>("GBCPacket");
67  qRegisterMetaType<GUCPacket>("GUCPacket");
68  qRegisterMetaType<ActionID_t>("ActionID_t");
69  qRegisterMetaType<DENM_t*>("DENM_t*");
70 
71  char c;
72  bool applicationFlag = false, bluetoothFlag = false, canFlag = false, facilitiesFlag = false, geonetFlag = false,
73  gpsFlag = false, upperTesterFlag = false, helpFlag = false, camFlag = false, denmFlag = false, hybridFlag = false;
74 
75  static struct option long_options[] =
76  {
77  {"application", no_argument, 0, 'a'},
78  {"bluetooth", no_argument, 0, 'b'},
79  {"can", no_argument, 0, 'c'},
80  {"facilities", no_argument, 0, 'f'},
81  {"cam", no_argument, 0, 'C'},
82  {"denm", no_argument, 0, 'D'},
83  {"gpsProvider", no_argument, 0, 'g'},
84  {"hybrid", no_argument, 0, 'H'},
85  {"geonet", no_argument, 0, 'n'},
86  {"upperTester", no_argument, 0, 'u'},
87  {"help", no_argument, 0, 'h'},
88  {0, 0, 0, 0}
89  };
90 
91  int option_index = 0;
92  if(argc > 1)
93  {
94  while((c = getopt_long(argc, argv, "abcfCDgHnuh", long_options, &option_index)) != -1)
95  {
96  switch(c)
97  {
98  case 0:
99  if (long_options[option_index].flag != 0)
100  break;
101  printf ("option %s", long_options[option_index].name);
102  if (optarg)
103  printf (" with arg %s", optarg);
104  printf ("\n");
105  return -1;
106  break;
107  case 'a':
108  applicationFlag = true;
109  break;
110  case 'b':
111  bluetoothFlag = true;
112  break;
113  case 'c':
114  canFlag = true;
115  break;
116  case 'f':
117  facilitiesFlag = true;
118  break;
119  case 'n':
120  geonetFlag = true;
121  break;
122  case 'g':
123  gpsFlag = true;
124  break;
125  case 'u':
126  upperTesterFlag = true;
127  break;
128  case 'h':
129  helpFlag = true;
130  break;
131  case 'H':
132  hybridFlag = true;
133  break;
134  case 'C':
135  facilitiesFlag = true;
136  camFlag = true;
137  break;
138  case 'D':
139  facilitiesFlag = true;
140  denmFlag = true;
141  break;
142  default:
143  return -1;
144  break;
145  }
146  }
147  }
148  else
149  {
150  help(argv[0]);
151  exit(EXIT_FAILURE);
152  }
153 
154  if(helpFlag)
155  {
156  help(argv[0]);
157  exit(EXIT_SUCCESS);
158  }
159 
160  qsrand(time(NULL));
161 
162  QMutex* mutex = new QMutex;
163 
164  ParameterDENM* denm;
165  ParameterUpperTester* paramUt;
166  FakeGPSProvider* gps = 0;
167  FakeCANProvider* can = 0;
168  FakeApplicationProvider* application = 0 ;
169  Manager* man = 0;
170  GeoNet* gn = 0;
171  Facilities* fac = 0;
172  UpperTester* ut = 0;
173 
174  denm = new ParameterDENM;
175 
176  if(upperTesterFlag)
177  paramUt = new ParameterUpperTester;
178  else
179  paramUt = 0;
180 
181  if(gpsFlag && !upperTesterFlag)
182  {
183  QThread* threadGPS = new QThread;
184  gps = new GPSProvider();
185  gps->moveToThread(threadGPS);
186  QObject::connect(threadGPS, SIGNAL(started()), gps, SLOT(execute()));
187  threadGPS->start();
188  }
189  else
190  gps = new FakeGPSProvider(mutex);
191 
192  if(canFlag && !upperTesterFlag)
193  can = new FakeCANProvider(mutex);
194  else
195  can = new FakeCANProvider(mutex);
196 
197  if(applicationFlag && !upperTesterFlag)
198  application = new FakeApplicationProvider(mutex);
199  else
200  application = new FakeApplicationProvider(mutex);
201 
202 
203  QThread* threadManager = new QThread;
204  man = new Manager(mutex, gps, can, denm, application, paramUt);
205  man->moveToThread(threadManager);
206  QObject::connect(threadManager, SIGNAL(started()), man, SLOT(execute()));
207  threadManager->start();
208 
209  QThread* threadGeonet = new QThread;
210  gn = new GeoNet(man, geonetFlag, hybridFlag, mutex);
211  gn->moveToThread(threadGeonet);
212  QObject::connect(threadGeonet, SIGNAL(started()), gn, SLOT(execute()));
213  threadGeonet->start();
214 
215 
216  ApplicationManagement *appManagement = new ApplicationManagement(man, bluetoothFlag, upperTesterFlag, applicationFlag);
217  QThread* threadApplication = new QThread;
218  appManagement->moveToThread(threadApplication);
219  //QObject::connect(threadApplication, SIGNAL(started()), appManagement, SLOT(execute()));
220  threadApplication->start();
221 
222  if(facilitiesFlag)
223  {
224  printf("UT = %d\n", upperTesterFlag);
225  QThread* threadFacilities = new QThread;
226  fac = new Facilities(man, gn, camFlag, denmFlag, bluetoothFlag, upperTesterFlag, mutex);
227  fac->moveToThread(threadFacilities);
228  QObject::connect(threadFacilities, SIGNAL(started()), fac, SLOT(execute()));
229  threadFacilities->start();
230  }
231 
232  if(upperTesterFlag)
233  {
234  ut = new UpperTester(man, can, gps, gn, fac, mutex);
235  }
236 
237  return a.exec();
238 }
void cleanExit(int sig)
Definition: mainGeonet.cpp:50
DENM configuration initializer.
Security layer decoder.
void help(char *argv)
Definition: mainGeonet.cpp:27
Manager class.
asn_TYPE_descriptor_t asn_DEF_Certificate
Definition: Certificate.c:177
N&T layer.
Facilities layer.
int main(int argc, char *argv[])
Definition: mainGeonet.cpp:57
UpperTester definition.
Real GPS sensor.
int asn_fprint(FILE *stream, asn_TYPE_descriptor_t *td, const void *struct_ptr)
Definition: constr_TYPE.c:36
Definition: DENM.h:23
quint64 decode_Certificate(uchar *field, Certificate_t *certificate)
decode_Certificate Decode a Certificate.
UpperTester configuration.
Definition: Geonet.h:42
Manager of the Application layer.