16
16
#include < signal.h>
17
17
#include " lib.c"
18
18
#include " candump.cpp"
19
+ #include < fstream>
19
20
20
21
using namespace std ;
21
22
@@ -27,9 +28,9 @@ pcap_t *descr;
27
28
28
29
int main (int argc, char *argv[])
29
30
{
30
- // define the ethernet ports to acquire data from
31
31
char *eth_port_1 = " eth0" ;
32
32
char *eth_port_2 = " eth10" ;
33
+ char *can_port = " vcan0" ;
33
34
34
35
pause_sim_kb = (unsigned int *) mmap (NULL , sizeof (*pause_sim_kb), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1 , 0 );
35
36
string s[3 ] = {" live" , " record" , " offline" };
@@ -64,25 +65,25 @@ int main(int argc, char *argv[])
64
65
65
66
while (!viewer.wasStopped ()){
66
67
// do nothing
67
- }
68
+ }
68
69
}
69
70
else {
70
71
71
- pcl::visualization::CloudViewer viewer (" Data from eth1 " );
72
- std::thread t1 (video::playback_video, 1 );
73
- descr = pcap_open_live (eth_port_2, 1248 , 1 , 1 , errbuf);
74
- if (descr == NULL ) {
75
- cout << " pcap_open_live() failed: " << errbuf << endl;
76
- return 1 ;
77
- }
78
- viewer.runOnVisualizationThreadOnce (viewerOneOff);
79
- viewer.runOnVisualizationThread (viewerPsycho);
80
- pcap_loop (descr, 0 , live::packetHandler_II, (u_char *) &viewer);
81
- int w = wait (NULL );
82
- t1.join ();
83
- while (!viewer.wasStopped ()){
84
- // do nothing
85
- }
72
+ pcl::visualization::CloudViewer viewer (" Data from eth10 " );
73
+ std::thread t1 (video::playback_video, 1 );
74
+ descr = pcap_open_live (eth_port_2, 1248 , 1 , 1 , errbuf);
75
+ if (descr == NULL ) {
76
+ cout << " pcap_open_live() failed: " << errbuf << endl;
77
+ return 1 ;
78
+ }
79
+ viewer.runOnVisualizationThreadOnce (viewerOneOff);
80
+ viewer.runOnVisualizationThread (viewerPsycho);
81
+ pcap_loop (descr, 0 , live::packetHandler_II, (u_char *) &viewer);
82
+ int w = wait (NULL );
83
+ t1.join ();
84
+ while (!viewer.wasStopped ()){
85
+ // do nothing
86
+ }
86
87
}
87
88
}
88
89
@@ -107,8 +108,8 @@ int main(int argc, char *argv[])
107
108
int exec_return = execvp(myargs[0], myargs);
108
109
*/
109
110
110
- char *myargv[3 ] = {" ./candump" , " can0 " , NULL };
111
- int myargc = 2 ;
111
+ char *myargv[4 ] = {" ./candump" , " -tz " , can_port , NULL };
112
+ int myargc = 3 ;
112
113
int can_return = can_main (myargc, myargv);
113
114
cout << " return from can_main function: " << can_return << endl;
114
115
@@ -151,14 +152,14 @@ int main(int argc, char *argv[])
151
152
pcap_loop (descr_II, 0 , offline::pcap_copier_II, (u_char *) &giant_vector_II);
152
153
153
154
int pid = fork ();
154
- if (pid < 0 ){
155
- cout << " fork error" << endl;
156
- exit (0 );
157
- }
155
+ if (pid < 0 ){
156
+ cout << " fork error" << endl;
157
+ exit (0 );
158
+ }
158
159
159
160
else if (pid == 0 ){
160
161
pcl::visualization::CloudViewer viewer (" Sample_1" );
161
- viewer.registerMouseCallback (mouseEventOccurred, (void *) &viewer);
162
+ // viewer.registerMouseCallback (mouseEventOccurred, (void*) &viewer);
162
163
viewer.registerKeyboardCallback (keyboardEventOccurred, (void *) &viewer);
163
164
viewer.runOnVisualizationThreadOnce (viewerOneOff);
164
165
viewer.runOnVisualizationThread (viewerPsycho);
@@ -169,31 +170,51 @@ int main(int argc, char *argv[])
169
170
}
170
171
}
171
172
else {
172
- // int pid1 = fork();
173
- // if(pid1 < 0){
174
- // cout << "fork error" << endl;
175
- // exit(0);
176
- // }
177
- // else if(pid1 == 0){
178
- // video::playback_video(0);
179
- // }
180
-
181
- // else{
182
-
183
- thread t1 (video::playback_video, 0 );
184
- pcl::visualization::CloudViewer viewer (" Sample_2" );
185
- viewer.registerMouseCallback (mouseEventOccurred, (void *) &viewer);
186
- viewer.registerKeyboardCallback (keyboardEventOccurred, (void *) &viewer);
187
- viewer.runOnVisualizationThreadOnce (viewerOneOff);
188
- viewer.runOnVisualizationThread (viewerPsycho);
189
- offline::pcap_viewer_II ((u_char *) &giant_vector_II, (u_char *) &viewer);
190
- while (!viewer.wasStopped ()){
191
- // do nothing
192
- }
193
- t1.join ();
194
- int w = wait (NULL );
173
+ int pid1 = fork ();
174
+ if (pid1 < 0 ){
175
+ cout << " fork error" << endl;
176
+ exit (0 );
177
+ }
178
+ else if (pid1 == 0 ){
179
+
180
+ ifstream canData (" canData.txt" );
181
+ string line, tempStrTime, strTime;
182
+ float time = 0 , timePrev = 0 ;
183
+ std::string::size_type first, last;
184
+ while (getline (canData, line))
185
+ {
186
+ while (*pause_sim_kb == 1 ){}
187
+ canData >> strTime;
188
+ first = strTime.find (" (" );
189
+ last = strTime.find (" )" );
190
+ if (last == std::string::npos){
191
+ break ;
192
+ }
193
+
194
+ tempStrTime = strTime.substr (first+1 , last-1 );
195
+ timePrev = time ;
196
+ time = stod (tempStrTime);
197
+ cout << line << endl;
198
+ usleep ((time - timePrev) * 1000000 );
199
+ }
200
+ }
201
+
202
+ else {
203
+
204
+ thread t1 (video::playback_video, 0 );
205
+ pcl::visualization::CloudViewer viewer (" Sample_2" );
206
+ // viewer.registerMouseCallback (mouseEventOccurred, (void*) &viewer);
207
+ viewer.registerKeyboardCallback (keyboardEventOccurred, (void *) &viewer);
208
+ viewer.runOnVisualizationThreadOnce (viewerOneOff);
209
+ viewer.runOnVisualizationThread (viewerPsycho);
210
+ offline::pcap_viewer_II ((u_char *) &giant_vector_II, (u_char *) &viewer);
211
+ while (!viewer.wasStopped ()){
212
+ // do nothing
213
+ }
214
+ t1.join ();
215
+ int w = wait (NULL );
216
+ }
195
217
}
196
-
197
218
cout << " ------------" << endl;
198
219
}
199
220
return 0 ;
0 commit comments