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

Merge branch 'master' of git.ece.iastate.edu:danc/MicroCART_17-18

parents bd916f39 4b5772bb
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>
#include <err.h>
#include "cli.h"
#include "frontend_common.h"
int connectToBackEnd();
......@@ -18,7 +12,8 @@ int main(int argc, char **argv)
{
int cmdID = -1;
char * command;
int i , s, useSymlink = 0;
int i , useSymlink = 0;
struct backend_conn *conn;
command = argv[0];
for(i = 0; i < MAX_COMMANDS; ++i) {
......@@ -26,7 +21,7 @@ int main(int argc, char **argv)
{
cmdID = i;
useSymlink = 1;
}
}
}
if(cmdID == -1) {
......@@ -45,47 +40,16 @@ int main(int argc, char **argv)
}
printf("Parsed Command : %s\n", commandNames[cmdID]);
if((s = connectToBackEnd()) == -1) {
err(-1, "connectToBackEnd");
}
conn = ucart_backendConnect();
printf("connection to backend Successful\n");
if(useSymlink) {
//TODO Call correct command function pointer with (argv[1] ... argc[argc])
}else {
//TODO Call correct command function pointer with (argv[2] ... argv[argc])
}
close(s);
ucart_backendDisconnect(conn);
return 0;
}
int connectToBackEnd() {
int s, t, len;
struct sockaddr_un remote;
char str[100];
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
printf("Trying to connect...\n");
remote.sun_family = AF_UNIX;
strcpy(remote.sun_path, SOCK_PATH);
len = strlen(remote.sun_path) + sizeof(remote.sun_family);
if (connect(s, (struct sockaddr *)&remote, sizeof(remote)) == -1) {
perror("connect");
exit(1);
} else {
printf("Connected.\n");
return s;
}
}
\ No newline at end of file
#ifndef __CLI_H
#define __CLI_H
#define SOCK_PATH "/var/run/ucart.socket"
enum CommandNameIds{
CMD_MONITOR,
CMD_SETPID,
......@@ -18,4 +16,6 @@ static char* commandNames[MAX_COMMANDS] = {
"getImu"
};
static
#endif
\ No newline at end of file
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