Skip to content
Snippets Groups Projects
Unverified Commit 6519d941 authored by Jake Drahos's avatar Jake Drahos
Browse files

Monitor of trackerdata finally works

Added nanosleep to make rate work right, also
switched from -t for total time to -c for count
parent 993c25bf
No related branches found
No related tags found
No related merge requests found
......@@ -635,7 +635,10 @@ static void client_recv(int fd) {
if (strncmp(buffer, TD_MAGIC, strlen(TD_MAGIC)) == 0) {
/* Request for tracker data */
struct ucart_vrpn_TrackerData td;
if (ucart_vrpn_tracker_getData(tracker, &td)) {
if (tracker == NULL) {
char * dummy = TD_MAGIC " 1.0 2.0 3.0 4.0 5.0 6.0\n";
write(fd, dummy, strlen(dummy));
}else if (ucart_vrpn_tracker_getData(tracker, &td)) {
write(fd, TD_MAGIC " ERROR\n", strlen(TD_MAGIC " ERROR\n"));
} else {
/* more than sufficient buffer */
......
......@@ -14,20 +14,17 @@ static void timespec_diff(struct timespec *start, struct timespec *result);
int cli_monitor(struct backend_conn * conn, int argc, char **argv) {
int c, result;
int timeFlag = 0;
int countFlag = 0;
static struct timespec startTime;
static struct timespec elapsedTime;
static struct timespec lastChecked;
static int nsecs, rate = 10;
static int forever = 0;
int count, rate = 10;
int forever = 0;
while ((c = getopt(argc, argv, "ft:r:")) != -1) {
while ((c = getopt(argc, argv, "fc:r:")) != -1) {
switch(c) {
case 't' :
nsecs = atoi(optarg);
timeFlag = 1;
case 'c' :
count = atoi(optarg);
countFlag = 1;
break;
case 'r' :
rate = atoi(optarg) + 1;
......@@ -42,23 +39,30 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv) {
if (forever) {
for (;;) {
struct timespec req;
if (rate == 1) {
req.tv_sec = 1;
req.tv_nsec = 0;
} else {
req.tv_sec = 0;
req.tv_nsec = 1000000000 / rate;
}
nanosleep(&req, NULL);
monitor(conn);
}
} else if (timeFlag) {
clock_gettime(CLOCK_REALTIME, &startTime);
clock_gettime(CLOCK_REALTIME, &lastChecked);
while((result = monitor(conn)) == 0) {
timespec_diff(&startTime, &elapsedTime);
if(elapsedTime.tv_sec > nsecs) {
break;
}
while(1) {
timespec_diff(&lastChecked, &elapsedTime);
if(elapsedTime.tv_nsec >= (long) ((SECOND_IN_NANO * 2) / rate)) {
clock_gettime(CLOCK_REALTIME, &lastChecked);
break;
}
} else if (countFlag) {
for (int i = 0; i < count; i++) {
result = monitor(conn);
struct timespec req;
if (rate == 1) {
req.tv_sec = 1;
req.tv_nsec = 0;
} else {
req.tv_sec = 0;
req.tv_nsec = 1000000000 / rate;
}
nanosleep(&req, NULL);
}
} else {
return monitor(conn);
......@@ -81,14 +85,14 @@ int monitor(struct backend_conn * conn) {
printf("\033[2J");
printf("STATUS: NA\n");
printf("CTRLR :\tP\tR\tY\tP_V\tR_V\tY_V\tH\tLAT\tLON\n");
printf(" P :\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\n",
printf(" P :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
printf(" I :\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\n",
printf(" I :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
printf(" D :\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\n",
printf(" D :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
printf("PosAtt:\tH\tLAT\tLON\tP\tR\tY\n");
printf(" :\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\t%7lf\n",
printf(" :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
td.height, td.lateral, td.longitudinal,
td.pitch, td.roll, td.yaw);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment