Skip to content
Snippets Groups Projects
Commit 6384c4dc authored by burneykb's avatar burneykb
Browse files

creating monitoring code

parent a0a83e56
No related branches found
No related tags found
No related merge requests found
......@@ -592,13 +592,13 @@ static void client_recv(int fd) {
printf("Could not recognize command '%s'\n", buffer);
} else {
int datalen = (packet[6] << 8) | (packet[5]);
writeQuad((char *) packet, datalen +7);
writeQuad((char *) packet, datalen +8);
}
char * rest = &buffer[newline] + 1;
size_t restLen = (strlen(rest) == 0) ? 1 : strlen(rest);
/* Delete parsed data and move the rest to the left */
memmove(buffer, rest, restLen + 1);
memmove(buffer, rest, restLen +1);
}
}
......
#ifndef __CLI_H
#define __CLI_H
#include "frontend_getpid.h"
// #include "cli_monitor.h"
#include "cli_monitor.h"
// #include "cli_setpid.h"
#include "cli_getpid.h"
// #include "cli_getimu.h"
......@@ -15,8 +14,8 @@ enum CommandNameIds{
};
typedef int (*cli_function_ptr)(struct backend_conn *, int, char **);
static cli_function_ptr cli_functions[1] = {
// &cli_monitor,
static cli_function_ptr cli_functions[2] = {
&cli_monitor,
// &cli_setpid,
&cli_getpid
// &cli_getimu
......
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <time.h>
#include <unistd.h>
#include "cli_monitor.h"
int cli_monitor(struct backend_conn * conn, int argc, char **argv) {
int c, result;
int timeFlag = 0;
static struct timespec startTime;
static struct timespec elapsedTime;
static struct timespec lastChecked;
static int nsecs, rate = 10;
while ((c = getopt(argc, argv, "t:r:")) != -1) {
switch(c) {
case 't' :
nsecs = atoi(optarg);
timeFlag = 1;
break;
case 'r' :
rate = atoi(optarg) + 1;
break;
default :
break;
}
}
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 {
return monitor(conn);
}
return result;
}
int monitor(struct backend_conn * conn) {
static char * line = "monitor\n";
printf("monitoring\n");
int size;
if((size = ucart_backendWrite(conn, line)) < 0 ) {
return 1;
}
return 0;
}
void timespec_diff(struct timespec *start, struct timespec *result)
{
struct timespec stop;
clock_gettime(CLOCK_REALTIME, &stop);
if ((stop.tv_nsec - start->tv_nsec) < 0) {
result->tv_sec = stop.tv_sec - start->tv_sec - 1;
result->tv_nsec = stop.tv_nsec - start->tv_nsec + 1000000000;
} else {
result->tv_sec = stop.tv_sec - start->tv_sec;
result->tv_nsec = stop.tv_nsec - start->tv_nsec;
}
return;
}
\ No newline at end of file
#ifndef CLI_MONITOR_H
#define CLI_MONITOR_H
#include <time.h>
#include "frontend_getpid.h"
int cli_getpid(
struct backend_conn * conn,
struct frontend_pid_data * pid_data);
#define SECOND_IN_NANO 1000000000
int cli_monitor(struct backend_conn * conn, int argc, char **argv);
// Return 0 on success and 1 otherwise
int monitor(struct backend_conn * conn);
void timespec_diff(struct timespec *start, struct timespec *result);
#endif
\ No newline at end of file
......@@ -38,7 +38,6 @@ int frontend_getpid(
}
int size;
printf("sending '%s'\n",line);
if((size = ucart_backendWrite(conn, line)) < 0 ) {
return 1;
}
......
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