Skip to content

Commit c04e3b9

Browse files
committed
Warnings no longer printed while compiling; Minor changes
1 parent 59c9aac commit c04e3b9

File tree

3 files changed

+76
-55
lines changed

3 files changed

+76
-55
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Makefile
22

33
CXX = g++
4-
OFLAG = -O3
4+
OFLAG = -O3 -Wno-deprecated -Wno-write-strings
55

66
CFLAGS = `pkg-config --cflags opencv`
77
LDFLAGS = `pkg-config --libs opencv`
88

99
all: main
1010

1111
main:
12-
$(CXX) -std=c++11 -o main main.cpp $(OFLAG) \
12+
@$(CXX) -std=c++11 -o main main.cpp $(OFLAG) \
1313
-I. -I/usr/include/pcap/ -I/usr/include/pcl-1.7 -I/usr/include/eigen3 \
1414
-I/usr/include/vtk-5.8 \
1515
-I/usr/lib/x86_64-linux-gnu/ \

functions.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ namespace data_structure
167167
printf("Warning! Capture size different than packet size: %ld bytes\n", (long)pkthdr->len);
168168

169169
// return an empty struct if the packet length is not 1248 bytes
170-
if(pkthdr -> len != 1248){
171-
processed_packet = (const struct data_packet){0};
172-
return;
173-
}
170+
// if(pkthdr -> len != 1248){
171+
// processed_packet = (const struct data_packet){0};
172+
// return;
173+
// }
174174

175175
for(int i = 0; i < 42; i++){
176176
processed_packet.header[i] = data[i]; // fill in the header
@@ -351,7 +351,7 @@ namespace record
351351
int pcount;
352352
//usleep(100000);
353353
if((pcount = pcap_loop(descr1, 0, &pcap_dump, (u_char *) pd)) < 0){
354-
cout << "Error in reeading packets " << endl;
354+
cout << "Error in reading packets " << endl;
355355
exit(0);
356356
}
357357

main.cpp

+69-48
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <signal.h>
1717
#include "lib.c"
1818
#include "candump.cpp"
19+
#include <fstream>
1920

2021
using namespace std;
2122

@@ -27,9 +28,9 @@ pcap_t *descr;
2728

2829
int main(int argc, char *argv[])
2930
{
30-
//define the ethernet ports to acquire data from
3131
char *eth_port_1 = "eth0";
3232
char *eth_port_2 = "eth10";
33+
char *can_port = "vcan0";
3334

3435
pause_sim_kb = (unsigned int *) mmap(NULL, sizeof (*pause_sim_kb), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
3536
string s[3] = {"live", "record", "offline"};
@@ -64,25 +65,25 @@ int main(int argc, char *argv[])
6465

6566
while(!viewer.wasStopped()){
6667
//do nothing
67-
}
68+
}
6869
}
6970
else {
7071

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+
}
8687
}
8788
}
8889

@@ -107,8 +108,8 @@ int main(int argc, char *argv[])
107108
int exec_return = execvp(myargs[0], myargs);
108109
*/
109110

110-
char *myargv[3] = {"./candump", "can0", NULL};
111-
int myargc = 2;
111+
char *myargv[4] = {"./candump", "-tz", can_port, NULL};
112+
int myargc = 3;
112113
int can_return = can_main(myargc, myargv);
113114
cout << "return from can_main function: " << can_return << endl;
114115

@@ -151,14 +152,14 @@ int main(int argc, char *argv[])
151152
pcap_loop(descr_II, 0, offline::pcap_copier_II, (u_char *) &giant_vector_II);
152153

153154
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+
}
158159

159160
else if(pid == 0){
160161
pcl::visualization::CloudViewer viewer("Sample_1");
161-
viewer.registerMouseCallback (mouseEventOccurred, (void*) &viewer);
162+
//viewer.registerMouseCallback (mouseEventOccurred, (void*) &viewer);
162163
viewer.registerKeyboardCallback (keyboardEventOccurred, (void*) &viewer);
163164
viewer.runOnVisualizationThreadOnce (viewerOneOff);
164165
viewer.runOnVisualizationThread (viewerPsycho);
@@ -169,31 +170,51 @@ int main(int argc, char *argv[])
169170
}
170171
}
171172
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+
}
195217
}
196-
197218
cout << "------------" << endl;
198219
}
199220
return 0;

0 commit comments

Comments
 (0)