diff --git a/groundStation/Makefile b/groundStation/Makefile index d62850d9b18b266043e0ab688bc37c907a43ba31..91b61ceb4af906136e96199ad46b50060cb003e4 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -2,7 +2,7 @@ GCC=gcc GXX=g++ CFLAGS= -Wall -Wpedantic -Wextra -Werror -std=c99 -g -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -CXXFLAGS= -Wall -Wno-reorder -std=c++11 -g +CXXFLAGS= -Wall -Wno-reorder -std=c++0x -g INCLUDES = $(foreach dir, $(INCDIR), -I$(dir)) # Directories diff --git a/groundStation/src/config.h b/groundStation/src/config.h index 0e2077cca5fbe03aee3ee8c89bc9cd5a91ecb16b..916058810e1834cb57a3e7af0cad2cd745e3c922 100644 --- a/groundStation/src/config.h +++ b/groundStation/src/config.h @@ -6,5 +6,10 @@ #define SOCKET_ENV "UCART_SOCKET" #define NOQUAD_ENV "UCART_NO_QUAD" +#define QUAD_WIFI_ENV "UCART_USE_WIFI" +#define QUAD_IP_ENV "UCART_QUAD_IP" +#define QUAD_IP_DEFAULT "192.168.4.1" +#define QUAD_PORT_ENV "UCART_QUAD_PORT" +#define QUAD_PORT_DEFAULT 8080 #endif diff --git a/groundStation/src/microcart_cli.c b/groundStation/src/microcart_cli.c index a439a897a58b347ca43b57ee30663908fbfcfc1a..9ee3712b861bbedfa9982304d6261611253547d2 100644 --- a/groundStation/src/microcart_cli.c +++ b/groundStation/src/microcart_cli.c @@ -4,6 +4,7 @@ */ #define _GNU_SOURCE +#define _BSD_SOURCE //system includes #include <err.h> @@ -13,6 +14,8 @@ #include <signal.h> #include <sys/socket.h> #include <sys/un.h> +#include <netinet/in.h> +#include <arpa/inet.h> #include <sys/select.h> #include <bluetooth/bluetooth.h> #include <bluetooth/rfcomm.h> @@ -366,25 +369,62 @@ void printVrpnData(struct ucart_vrpn_TrackerData * td) { int connectToZybo() { int sock; - struct sockaddr_rc addr; + int status; - // allocate a socket - sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + /* Use bluetooth by default */ + if (getenv(QUAD_WIFI_ENV) == NULL) { + struct sockaddr_rc addr; - //set the connection params ie. who to connect to - addr.rc_family = AF_BLUETOOTH; - addr.rc_channel = (uint8_t) QUAD_BT_CHANNEL; - str2ba( QUAD_BT_ADDR, &addr.rc_bdaddr ); - - printf("Attempting to connect to zybo. Please be patient...\n"); - // blocking call to connect to socket sock ie. zybo board - int status = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); + // allocate a socket + sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + + //set the connection params ie. who to connect to + addr.rc_family = AF_BLUETOOTH; + addr.rc_channel = (uint8_t) QUAD_BT_CHANNEL; + str2ba( QUAD_BT_ADDR, &addr.rc_bdaddr ); + + printf("Attempting to connect to zybo. Please be patient...\n"); + // blocking call to connect to socket sock ie. zybo board + status = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); + } else { + struct sockaddr_in addr; + + addr.sin_family = AF_INET; + + /* Quick and Dirty */ + if (getenv(QUAD_IP_ENV)) { + if (!inet_aton(getenv(QUAD_IP_ENV), &addr.sin_addr)) { + fprintf(stderr, "Env var %s invalid IP %s\n", + QUAD_IP_ENV, getenv(QUAD_IP_ENV)); + return -1; + } + } else { + if (!inet_aton(QUAD_IP_DEFAULT, &addr.sin_addr)) { + fprintf(stderr, "Default IP %s is invalid\n", + QUAD_IP_DEFAULT); + return -1; + } + } + + if (getenv(QUAD_PORT_ENV)) { + /* Quick 'n dirty, oh yeah! */ + addr.sin_family = atoi(getenv(QUAD_PORT_ENV)); + } else { + addr.sin_family = QUAD_PORT_DEFAULT; + } + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + perror("socket"); + return -1; + } + } // connection failed if(status < 0) { close(sock); - printf("Connection failed!...\n"); + perror("connect"); return -1; } else