# HG changeset patch # User Mychaela Falconia # Date 1494722063 0 # Node ID 70bb11ba74859d124ea8e85c82befbe86a84e1ef # Parent de8f75783b3b88b9cb92b88a4ff04e896aa1c4a5 fc-tsid-shell (fc-cmu200d development aid) written diff -r de8f75783b3b -r 70bb11ba7485 .hgignore --- a/.hgignore Tue May 02 03:24:30 2017 +0000 +++ b/.hgignore Sun May 14 00:34:23 2017 +0000 @@ -29,6 +29,7 @@ ^rfcal/cmu200/fc-cmu200d$ ^rfcal/cmu200/fc-serscpi$ +^rfcal/tsid-test/fc-tsid-shell$ ^rfcal/vcxo-manual/fc-vcxo-linear$ ^rfcal/vcxo-manual/fc-vcxo-param$ diff -r de8f75783b3b -r 70bb11ba7485 rfcal/tsid-test/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rfcal/tsid-test/Makefile Sun May 14 00:34:23 2017 +0000 @@ -0,0 +1,16 @@ +CC= gcc +CFLAGS= -O2 +PROGS= fc-tsid-shell +INSTBIN=/opt/freecalypso/bin + +all: ${PROGS} + +fc-tsid-shell: fc-tsid-shell.c + ${CC} ${CFLAGS} -o $@ $@.c + +install: + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f *.o *.out *errs ${PROGS} diff -r de8f75783b3b -r 70bb11ba7485 rfcal/tsid-test/fc-tsid-shell.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rfcal/tsid-test/fc-tsid-shell.c Sun May 14 00:34:23 2017 +0000 @@ -0,0 +1,109 @@ +/* + * This program connects to the RF calibration Test System Interface Daemon + * (TSID) over the local socket interface and allows manual human interaction + * with the TSID for development. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern int errno; + +static char default_socket_pathname[] = "/tmp/fc_rftest_socket"; + +char *socket_pathname; +int sock; + +connect_local_socket() +{ + /* local socket binding voodoo copied from osmocon */ + struct sockaddr_un local; + unsigned int namelen; + int rc; + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock < 0) { + perror("socket(AF_UNIX, SOCK_STREAM, 0)"); + exit(1); + } + + local.sun_family = AF_UNIX; + strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path)); + local.sun_path[sizeof(local.sun_path) - 1] = '\0'; + + /* we use the same magic that X11 uses in Xtranssock.c for + * calculating the proper length of the sockaddr */ +#if defined(BSD44SOCKETS) || defined(__UNIXWARE__) + local.sun_len = strlen(local.sun_path); +#endif +#if defined(BSD44SOCKETS) || defined(SUN_LEN) + namelen = SUN_LEN(&local); +#else + namelen = strlen(local.sun_path) + + offsetof(struct sockaddr_un, sun_path) + 1; +#endif + + rc = connect(sock, (struct sockaddr *) &local, namelen); + if (rc != 0) { + perror(socket_pathname); + exit(1); + } + + return(0); +} + +main(argc, argv) + char **argv; +{ + char buf[BUFSIZ]; + fd_set fds, fds1; + register int i, cc, max; + + switch (argc) { + case 1: + socket_pathname = default_socket_pathname; + break; + case 2: + socket_pathname = argv[1]; + break; + default: + fprintf(stderr, "usage: %s [socket-pathname]\n", argv[0]); + exit(1); + } + connect_local_socket(); + FD_ZERO(&fds); + FD_SET(0, &fds); + FD_SET(sock, &fds); + max = sock + 1; + for (;;) { + bcopy(&fds, &fds1, sizeof(fd_set)); + i = select(max, &fds1, NULL, NULL, NULL); + if (i < 0) { + if (errno == EINTR) + continue; + perror("select"); + exit(1); + } + if (FD_ISSET(0, &fds1)) { + cc = read(0, buf, sizeof buf); + if (cc <= 0) + exit(0); + write(sock, buf, cc); + } + if (FD_ISSET(sock, &fds1)) { + cc = read(sock, buf, sizeof buf); + if (cc <= 0) { + fprintf(stderr, "EOF/error on socket read\n"); + exit(1); + } + write(1, buf, cc); + } + } +}