diff --git a/groundStation/.gitignore b/groundStation/.gitignore index 243744841d61593c6d6a49e937c869872a46de35..a22e4503492700a44a6e97382e46376868309b5c 100644 --- a/groundStation/.gitignore +++ b/groundStation/.gitignore @@ -42,4 +42,5 @@ logs client BackEnd obj +cli monitorQuad diff --git a/groundStation/Makefile b/groundStation/Makefile index 1f4d4be95e7321ab65e131747b35536558078024..372c220dc0c1cb8b672b19c8f2b5e2fea8db2d2c 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -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) diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index 8d1bf6b8e4c4448ab923136dfda68a21cfb5202b..5815c758d97faea224564d7d2569db1108a8b19e 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -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++; diff --git a/groundStation/src/backend/config.h b/groundStation/src/backend/config.h index 74b0bc671b11b02c99f5dddc16e7d7f8d48678f4..db6d68ca75b4c000bad26f1efc7dc653ea2e6144 100644 --- a/groundStation/src/backend/config.h +++ b/groundStation/src/backend/config.h @@ -1,5 +1,5 @@ -#ifndef __BACKEND_H -#define __BACKEND_H +#ifndef __CONFIG_H +#define __CONFIG_H #define DEFAULT_SOCKET "/var/run/ucart.socket" diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c new file mode 100644 index 0000000000000000000000000000000000000000..39a12ebf45f2922c17605f44257faf85c18a8030 --- /dev/null +++ b/groundStation/src/cli/cli.c @@ -0,0 +1,91 @@ +#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 diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h new file mode 100644 index 0000000000000000000000000000000000000000..2e6654be1e5284e6cf601ec8c625c20939b9427c --- /dev/null +++ b/groundStation/src/cli/cli.h @@ -0,0 +1,15 @@ +#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 diff --git a/groundStation/src/cli/monitorQuad.c b/groundStation/src/cli/monitorQuad.c deleted file mode 100644 index 09540d0239dfcc2c493b8941799aaf1d199356f7..0000000000000000000000000000000000000000 --- a/groundStation/src/cli/monitorQuad.c +++ /dev/null @@ -1,4 +0,0 @@ -int main(int argc, char **argv) -{ - return 0; -} \ No newline at end of file diff --git a/groundStation/src/cli/testClient.c b/groundStation/src/cli/testClient.c new file mode 100644 index 0000000000000000000000000000000000000000..c6db27cd25cfc64167aa8c7296f85a3efd987c0a --- /dev/null +++ b/groundStation/src/cli/testClient.c @@ -0,0 +1,55 @@ +#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; +}