14
14
// #include "data_structures.cpp"
15
15
#include " functions.cpp"
16
16
#include < signal.h>
17
- #include " lib.c"
18
- #include " candump.cpp"
19
17
#include < fstream>
20
18
21
19
using namespace std ;
@@ -69,8 +67,14 @@ int main(int argc, char *argv[])
69
67
}
70
68
else {
71
69
70
+ int pid1 = fork ();
71
+ if (pid1 == 0 ){
72
+ canData ();
73
+ }
74
+ else {
72
75
pcl::visualization::CloudViewer viewer (" Data from eth10" );
73
76
std::thread t1 (video::playback_video, 1 );
77
+ // std::thread t2(canData);
74
78
descr = pcap_open_live (eth_port_2, 1248 , 1 , 1 , errbuf);
75
79
if (descr == NULL ) {
76
80
cout << " pcap_open_live() failed: " << errbuf << endl;
@@ -79,12 +83,17 @@ int main(int argc, char *argv[])
79
83
viewer.runOnVisualizationThreadOnce (viewerOneOff);
80
84
viewer.runOnVisualizationThread (viewerPsycho);
81
85
pcap_loop (descr, 0 , live::packetHandler_II, (u_char *) &viewer);
82
- int w = wait (NULL );
86
+
87
+ // t2.join();
83
88
t1.join ();
84
- while (!viewer.wasStopped ()){
85
- // do nothing
86
- }
89
+ int w = wait (NULL );
90
+ int w1 = wait (NULL );
91
+ // while(!viewer.wasStopped()){
92
+ // //do nothing
93
+ // }
94
+
87
95
}
96
+ }
88
97
}
89
98
90
99
if (argv[1 ] == s[1 ]) // record mode
@@ -95,41 +104,42 @@ int main(int argc, char *argv[])
95
104
exit (0 );
96
105
}
97
106
else if (ret == 0 ){
98
- close (1 );
107
+
108
+ close (1 ); // redirecting the ouput
99
109
int fd = open (" canData.txt" , O_WRONLY | O_CREAT | O_TRUNC, 0660 );
100
110
if (fd < 0 ){
101
111
cout << " cannot open file canData.txt" << endl;
102
112
exit (0 );
103
113
}
104
- /* char *myargs[3];
105
- myargs[0] = (const char *) "candump";
106
- myargs[1] = (const char *) "can0";
107
- myargs[2] = NULL;
108
- int exec_return = execvp(myargs[0], myargs);
109
- */
110
-
114
+
111
115
char *myargv[4 ] = {" ./candump" , " -tz" , can_port, NULL };
112
116
int myargc = 3 ;
113
117
int can_return = can_main (myargc, myargv);
114
118
cout << " return from can_main function: " << can_return << endl;
115
119
116
120
}
117
121
else {
122
+ signal (SIGINT, compressFiles);
118
123
thread t1 (video::capture_video);
119
124
thread t2 (record::save_pcap, eth_port_1, " Sample_1.pcap" );
120
125
thread t3 (record::save_pcap, eth_port_2, " Sample_2.pcap" );
121
126
122
127
t2.join ();
123
128
t3.join ();
124
129
t1.join ();
125
- int w1 = wait (NULL );
130
+ int w = wait (NULL );
131
+ compressFunct ();
126
132
}
127
133
128
134
}
129
135
130
136
if (argv[1 ] == s[2 ]) // offline mode
131
137
{
132
138
cout << " Offline Mode Entered" << endl;
139
+ if (system (" tar -xzvf data.tar.gz" ) < 0 ){
140
+ cout << " error in extracting the data from tar file" << endl;
141
+ return 0 ;
142
+ }
133
143
134
144
// Fill 2 giant vectors with the contents of the 2 pcap files
135
145
pcap_t *descr_I;
@@ -140,26 +150,26 @@ int main(int argc, char *argv[])
140
150
cout << " pcap_open_offline() failed: " << errbuf << endl;
141
151
return 1 ;
142
152
}
143
- vector<struct data_packet > giant_vector_I;
144
- pcap_loop (descr_I, 0 , offline::pcap_copier_I, (u_char *) &giant_vector_I);
153
+ vector<struct data_packet > giant_vector_I;
154
+ pcap_loop (descr_I, 0 , offline::pcap_copier_I, (u_char *) &giant_vector_I);
145
155
146
- descr_II = pcap_open_offline (" Sample_2.pcap" , errbuf);
147
- if (descr_II == NULL ) {
148
- cout << " pcap_open_offline() failed: " << errbuf << endl;
149
- return 1 ;
150
- }
151
- vector<struct data_packet > giant_vector_II;
152
- pcap_loop (descr_II, 0 , offline::pcap_copier_II, (u_char *) &giant_vector_II);
156
+ descr_II = pcap_open_offline (" Sample_2.pcap" , errbuf);
157
+ if (descr_II == NULL ) {
158
+ cout << " pcap_open_offline() failed: " << errbuf << endl;
159
+ return 1 ;
160
+ }
161
+ vector<struct data_packet > giant_vector_II;
162
+ pcap_loop (descr_II, 0 , offline::pcap_copier_II, (u_char *) &giant_vector_II);
153
163
154
- int pid = fork ();
155
- if (pid < 0 ){
156
- cout << " fork error" << endl;
157
- exit (0 );
158
- }
164
+ int pid = fork ();
165
+ if (pid < 0 ){
166
+ cout << " fork error in offline mode " << endl;
167
+ exit (0 );
168
+ }
159
169
160
170
else if (pid == 0 ){
161
171
pcl::visualization::CloudViewer viewer (" Sample_1" );
162
- // viewer.registerMouseCallback (mouseEventOccurred, (void*) &viewer);
172
+ viewer.registerMouseCallback (mouseEventOccurred, (void *) &viewer);
163
173
viewer.registerKeyboardCallback (keyboardEventOccurred, (void *) &viewer);
164
174
viewer.runOnVisualizationThreadOnce (viewerOneOff);
165
175
viewer.runOnVisualizationThread (viewerPsycho);
@@ -175,7 +185,7 @@ int main(int argc, char *argv[])
175
185
cout << " fork error" << endl;
176
186
exit (0 );
177
187
}
178
- else if (pid1 == 0 ){
188
+ else if (pid1 == 0 ){ // displaying canData on terminal
179
189
180
190
ifstream canData (" canData.txt" );
181
191
string line, tempStrTime, strTime;
@@ -200,10 +210,10 @@ int main(int argc, char *argv[])
200
210
}
201
211
202
212
else {
203
-
204
- thread t1 (video::playback_video, 0 );
213
+ signal (SIGINT, deleteFiles);
214
+ thread t1 (video::playback_video, 0 );
205
215
pcl::visualization::CloudViewer viewer (" Sample_2" );
206
- // viewer.registerMouseCallback (mouseEventOccurred, (void*) &viewer);
216
+ viewer.registerMouseCallback (mouseEventOccurred, (void *) &viewer);
207
217
viewer.registerKeyboardCallback (keyboardEventOccurred, (void *) &viewer);
208
218
viewer.runOnVisualizationThreadOnce (viewerOneOff);
209
219
viewer.runOnVisualizationThread (viewerPsycho);
@@ -212,7 +222,8 @@ int main(int argc, char *argv[])
212
222
// do nothing
213
223
}
214
224
t1.join ();
215
- int w = wait (NULL );
225
+ int w = wait (NULL );
226
+ int w1 = wait (NULL );
216
227
}
217
228
}
218
229
cout << " ------------" << endl;
0 commit comments