-
Notifications
You must be signed in to change notification settings - Fork 1
/
readTracker.cpp
78 lines (64 loc) · 1.74 KB
/
readTracker.cpp
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
/**
* @file readTracker.cpp
* @brief Reads the tracker signals and stores them in a file
*/
#include <sns.h>
#include <unistd.h>
#include <fstream>
#include "tracker_msg.h"
struct timespec t_now;
struct timespec t_timeout;
ach_channel chan;
std::string chan_opt("tracker");
std::string output_file( "tracker_output.txt" );
int main( int argc, char* argv[] ) {
int v;
while( (v=getopt(argc,argv,"c:ho:")) != -1 ) {
switch(v) {
case 'c': {
chan_opt.assign(optarg);
} break;
case 'o': {
output_file.assign(optarg);
} break;
case 'h': {
printf("Syntax: %s -c CHANNEL_NAME -o OUTPUT_FILE.txt\n", argv[0]);
return 1;
} break;
}
}
// Open channel
if( ach_open( &chan, chan_opt.c_str(), NULL ) != ACH_OK ) {
printf("Error opening channel %s \n", chan_opt.c_str() );
return -1;
}
// Loop
std::ofstream output( output_file.c_str(), std::ofstream::out );
while(true) {
// Read channel
if( clock_gettime( ACH_DEFAULT_CLOCK, &t_now ) ) {
SNS_LOG( LOG_ERR, "clock_gettime failed: '%s' \n", strerror(errno) );
break;
}
t_timeout = sns_time_add_ns( t_now, 1000*1000*1 );
size_t frame_size;
void* buf = NULL;
ach_status_t r;
r = sns_msg_local_get( &chan, &buf, &frame_size, &t_timeout,
ACH_O_LAST | ACH_O_WAIT );
switch(r) {
case ACH_OK:
case ACH_MISSED_FRAME: {
struct sns_msg_tracker* msg = (struct sns_msg_tracker*)buf;
sns_msg_tracker_dump( stdout, msg );
for( int i = 0; i < msg->header.n; ++i ) {
printf("Writing \n");
output << msg->u[i].x << " " << msg->u[i].y << " " << msg->u[i].z << " ";
}
output <<std::endl;
} break;
}
usleep(0.25e6);
} // end while
output.close();
}