changeset 206:70bb11ba7485

fc-tsid-shell (fc-cmu200d development aid) written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 May 2017 00:34:23 +0000
parents de8f75783b3b
children d1eb8518f23d
files .hgignore rfcal/tsid-test/Makefile rfcal/tsid-test/fc-tsid-shell.c
diffstat 3 files changed, 126 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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$
 
--- /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}
--- /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 <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+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);
+		}
+	}
+}