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

first go at the local socket virt-quad test system

parent 38e74b24
No related branches found
No related tags found
No related merge requests found
......@@ -341,28 +341,48 @@ void printVrpnData(struct ucart_vrpn_TrackerData * td) {
int connectToZybo() {
int sock;
int status = 0;
int status = -1;
if (getenv(NOQUAD_ENV)) {
return 0;
}
/* Use bluetooth by default */
if (!getenv(QUAD_WIFI_ENV)) {
printf("Using BT Settings\n");
struct sockaddr_rc addr;
/* Use wifi by default */
if (getenv(QUAD_COMM_ENV)) {
/* Determine if we are using bluetooth or local */
if(strcmp(getenv(QUAD_COMM_ENV), "local") == 0) {
printf("Using Local Socket Settings\n");
struct sockaddr_un remote;
char str[100];
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
// allocate a socket
sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
remote.sun_family = AF_UNIX;
char * sock_env = getenv(QUAD_LOCAL_SOCKET);
strcpy(remote.sun_path, sock_env ? sock_env : QUAD_DEFAULT_LOCAL_SOCKET);
printf("Attempting to connect to local socket at '%s'. please be patiend.\n", remote.sun_path);
//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));
status = connect(sock, (struct sockaddr *)&remote, sizeof(remote));
} else if (strcmp(getenv(QUAD_COMM_ENV), "bluetooth") == 0) {
printf("Using BT Settings\n");
struct sockaddr_rc 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 {
printf("Using WIFI settings\n");
struct sockaddr_in addr;
......
......@@ -11,7 +11,10 @@
// If you are planning on using any of these env vars and you have
// exported them with normal user rights. You will need to run the
// backend with sudo elevation and with the --preserve-env flag or -E
#define QUAD_WIFI_ENV "UCART_USE_WIFI"
#define QUAD_COMM_ENV "UCART_COMM_CHANNEL"
#define QUAD_DEFAULT_LOCAL_SOCKET "./virtquad.socket"
#define QUAD_LOCAL_SOCKET "UCART_LOCAL_SOCKET"
#define QUAD_IP_ENV "UCART_QUAD_IP"
#define QUAD_IP_DEFAULT "192.168.1.1"
#define QUAD_PORT_ENV "UCART_QUAD_PORT"
......
#include "hw_impl_unix.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/un.h>
#include <err.h>
#include <netinet/in.h>
#define DEFAULT_SOCKET "../../groundStation/virtquad.socket"
#define SOCKET_ENV "VIRT_QUAD_SOCKET"
static int backendSocket;
static int sendSocket;
int unix_uart_reset(struct UARTDriver *self) {
char * backend_socket_path = DEFAULT_SOCKET;
if (getenv(SOCKET_ENV)) {
backend_socket_path = getenv(SOCKET_ENV);
}
/* Unlink if it exists */
unlink(backend_socket_path);
printf("using socket at '%s'\n", backend_socket_path);
/* Create socket */
backendSocket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
/* Create sockaddr and bind */
struct sockaddr_un sa;
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, backend_socket_path, 107);
sa.sun_path[107] = '\0';
if (bind(backendSocket, (struct sockaddr *) &sa, sizeof(sa))) {
err(-1, "bind");
}
/* Listen */
if (listen(backendSocket, 1)) {
err(-1, "listen");
}
while (1) {
sendSocket = accept(backendSocket, NULL, NULL);
if (sendSocket > 0)
break;
}
printf(" accpet() returned with %d\n", sendSocket);
return 0;
}
int unix_uart_write(struct UARTDriver *self, unsigned char c) {
return 0;
printf("sending %c\n", c);
return send(sendSocket, &c, 1, 0);
}
int unix_uart_read(struct UARTDriver *self, unsigned char *c) {
return 0;
int bytes = read(sendSocket, c, 1);
printf("read in %d byte [%x], msg=%d\n", bytes, *c, self->msg);
return bytes;
}
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