changeset 19:f67f46e56355

autocal/tsidsock.c: implemented command/response protocol
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 May 2017 20:20:49 +0000
parents af77b95feeba
children 7ac866c3baf6
files autocal/tsidsock.c
diffstat 1 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/autocal/tsidsock.c	Mon May 22 18:36:26 2017 +0000
+++ b/autocal/tsidsock.c	Mon May 22 20:20:49 2017 +0000
@@ -14,6 +14,7 @@
 
 char *tsid_socket_pathname = "/tmp/fc_rftest_socket";
 int tsid_socket;
+char tsid_response[4096];
 
 connect_tsid_socket()
 {
@@ -49,6 +50,43 @@
 		perror(tsid_socket_pathname);
 		exit(ERROR_RFTEST);
 	}
-
+	collect_tsid_response();
 	return(0);
 }
+
+collect_tsid_response()
+{
+	char buf[BUFSIZ];
+	int cc, pos;
+
+	for (pos = 0; ; ) {
+		cc = read(tsid_socket, buf, sizeof buf);
+		if (cc <= 0) {
+			perror("read from TSID socket");
+			exit(ERROR_RFTEST);
+		}
+		if (pos + cc > sizeof tsid_response) {
+			fprintf(stderr,
+			"error: response from TSID exceeds our buffer size\n");
+			exit(ERROR_RFTEST);
+		}
+		bcopy(buf, tsid_response + pos, cc);
+		pos += cc;
+		if (tsid_response[pos-1] == '\n')
+			break;
+	}
+	tsid_response[pos-1] = '\0';
+	if (tsid_response[0] != '+') {
+		fprintf(stderr, "Error from TSID: %s\n", tsid_response);
+		exit(ERROR_RFTEST);
+	}
+	return(0);
+}
+
+tsid_command(cmd)
+	char *cmd;
+{
+	write(tsid_socket, cmd, strlen(cmd));
+	collect_tsid_response();
+	return(0);
+}