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

start of socket creation and command parsing of cli

parent f073e351
No related branches found
No related tags found
No related merge requests found
......@@ -42,4 +42,5 @@ logs
client
BackEnd
obj
cli
monitorQuad
......@@ -32,13 +32,11 @@ all: logs objdir backend cli
vrpn: vrpn/build
cli: $(CLIOBJECTS) $(CLIBINARIES)
cli: $(CLIBINARIES)
$(CLIOBJECTS) : $(OBJDIR)/%.o : $(CLISRCDIR)/%.c
$(GCC) $(CFLAGS) -c $^ -o $@ $(INCLUDES) $(LIBS)
$(CLIBINARIES): % : $(CLISRCDIR)/%.c
$(GCC) $(CFLAGS) $< -o $@ $(INCLUDES) $(LIBS)
$(CLIBINARIES): % : $(OBJDIR)/%.o
$(GCC) $(CFLAGS) $^ -o $@ $(INCLUDES) $(LIBS)
backend: $(BECPPOBJECTS) $(BECOBJECTS)
$(GXX) $(CXXFLAGS) $^ -o $(BEBINARY) $(INCLUDES) $(LIBS)
......
......@@ -106,7 +106,7 @@ static void cb(struct ucart_vrpn_TrackerData * td)
static int count = 0;
if(!(count % 10)) {
sendVrpnPacket(td);
//sendVrpnPacket(td);
//updateLogFile(td);
}
count++;
......
#ifndef __BACKEND_H
#define __BACKEND_H
#ifndef __CONFIG_H
#define __CONFIG_H
#define DEFAULT_SOCKET "/var/run/ucart.socket"
......
#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 <getopt.h>
#include <err.h>
#include "cli.h"
int parseInput(int argc, char **argv);
int connectToBackEnd();
int main(int argc, char **argv)
{
int cmdID = -1;
if((cmdID = parseInput(argc, argv)) == -1) {
exit(1);
}
int s;
if((s = connectToBackEnd()) == -1) {
err(-1, "connectToBackEnd");
}
close(s);
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;
}
}
int parseInput(int argc, char **argv) {
static int cmdID = -1;
int c;
static struct option long_options[] =
{
/* These options don’t set a flag. We distinguish them by their indices. */
{"monitor", no_argument, &cmdID, CMD_MONITOR},
{0, 0, 0, 0}
};
while (1)
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "",
long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
}
if(cmdID == -1)
{
printf("Invalid command\n");
return cmdID;
}
return 0;
}
\ No newline at end of file
#ifndef __CLI_H
#define __CLI_H
#define SOCK_PATH "/var/run/ucart.socket"
enum CommandNameIds{
CMD_MONITOR,
MAX_COMMANDS
};
char* commandNames[MAX_COMMANDS] = {
"monitor",
};
#endif
\ No newline at end of file
int main(int argc, char **argv)
{
return 0;
}
\ No newline at end of file
#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>
#define SOCK_PATH "/var/run/ucart.socket"
int main(void)
{
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);
}
printf("Connected.\n");
while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
if (send(s, str, strlen(str), 0) == -1) {
perror("send");
exit(1);
}
/*
if ((t=recv(s, str, 100, 0)) > 0) {
str[t] = '\0';
printf("echo> %s", str);
} else {
if (t < 0) perror("recv");
else printf("Server closed connection\n");
exit(1);
}
*/
}
close(s);
return 0;
}
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