-
Notifications
You must be signed in to change notification settings - Fork 0
/
robotlogger.c
62 lines (50 loc) · 1.47 KB
/
robotlogger.c
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
/*
This program is the basic form of the code to read data from a robot.
It should be modified based on the type of data needed for logging.
It makes use of the curl libraries, and it depends on robot.h/c, timing.h/c
gcc robotlogger.c robot.c timing.c -lcurl -Wall -o
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "robot.h"
#include "timing.h"
void fetchData(void) {
data temp;
double px = -1, py = -1, pz = -1, ox = -1, oy = -1, oz = -1, ow = -1, t = -1;
temp=getFromRobot("state?");
sscanf(temp.contents, "%lf,%lf,%lf,%lf,%lf,%lf,%lf", &px, &py, &pz, &ox, &oy, &oz, &ow);
printf("%lf %lf %lf %lf %lf %lf %lf %lf\n", ClockGetTime(), px, py, pz, ox, oy, oz, ow);
return;
}
void signalHandler(int cause, siginfo_t *HowCome, void *ucontext) {
fetchData();
}
int main(void)
{
char temp_base_url[64] = "http://somehost:someport/";
char permissions[64] = "&id=someID";
setHost(temp_base_url);
setPermission(permissions);
struct itimerval it_val; /* for setting itimer */
it_val.it_value.tv_sec = 0;
it_val.it_value.tv_usec = 986000/10;
it_val.it_interval = it_val.it_value;
struct sigaction sa;
sa.sa_sigaction = signalHandler;
sigemptyset( &sa.sa_mask );
sa.sa_flags = SA_SIGINFO; /* we want a siginfo_t */
if (sigaction (SIGPROF, &sa, 0))
{
perror("Unable to catch SIGPROF");
}
else
{
setitimer(ITIMER_PROF, &it_val, NULL);
while (1)
{
;
}
}
return 0;
}