From 472e18c25b40bbbd7c15e68e4464416a46d3795f Mon Sep 17 00:00:00 2001
From: burneykb <burneykb@iastate.edu>
Date: Sat, 25 Mar 2017 20:26:56 -0500
Subject: [PATCH] solved fe response issues

---
 groundStation/addnode               |  1 +
 groundStation/getnodes              |  1 +
 groundStation/getoutput             |  1 +
 groundStation/getparam              |  1 +
 groundStation/getsource             |  1 +
 groundStation/setparam              |  1 +
 groundStation/setsource             |  1 +
 groundStation/src/backend/backend.c | 59 +++++++++++++++--------------
 groundStation/src/backend/param.c   |  2 +-
 groundStation/src/cli/cli_param.c   |  2 +-
 10 files changed, 40 insertions(+), 30 deletions(-)
 create mode 120000 groundStation/addnode
 create mode 120000 groundStation/getnodes
 create mode 120000 groundStation/getoutput
 create mode 120000 groundStation/getparam
 create mode 120000 groundStation/getsource
 create mode 120000 groundStation/setparam
 create mode 120000 groundStation/setsource

diff --git a/groundStation/addnode b/groundStation/addnode
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/addnode
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/getnodes b/groundStation/getnodes
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/getnodes
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/getoutput b/groundStation/getoutput
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/getoutput
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/getparam b/groundStation/getparam
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/getparam
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/getsource b/groundStation/getsource
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/getsource
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/setparam b/groundStation/setparam
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/setparam
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/setsource b/groundStation/setsource
new file mode 120000
index 000000000..83c63a5d9
--- /dev/null
+++ b/groundStation/setsource
@@ -0,0 +1 @@
+Cli
\ No newline at end of file
diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c
index 1088a84cb..94e8e7dcc 100644
--- a/groundStation/src/backend/backend.c
+++ b/groundStation/src/backend/backend.c
@@ -563,7 +563,6 @@ static int clientAddPendResponses(int fd, uint16_t packet_id) {
 static int clientRemovePendResponses(int fd, uint16_t packet_id) {
 	int *pendingResponses = get_client_pend_responses(fd);
 	for(int i = 0; i < CLIENT_MAX_PENDING_RESPONSES; i++) {
-		printf("might remove pendingResponses[%d], if it equals %d\n", i, packet_id);
 		if(pendingResponses[i] == packet_id) {
 			pendingResponses[i] = -1;
 			return i;
@@ -737,22 +736,22 @@ static void client_recv(int fd) {
 			}
 
 			/* Only add the client to the pending responses if it was a getparam command */
-			// if (m.msg_type == GETPARAM_ID || m.msg_type == GETOUTPUT_ID || 
-			// 	m.msg_type == GETSOURCE_ID || m.msg_type == GETNODES_ID || m.msg_type == ADDNODE_ID) {
-			// 	printf("adding fd %d with id %d\n", fd, BytesTo16(packet[ID_L], packet[ID_H]));
-			// 	if (clientAddPendResponses(fd, BytesTo16(packet[ID_L], packet[ID_H])) == -1) {
-			// 		warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n");
-			// 	}
-			// }
-
-			printf("packetToQuad = '");
-			for(int i = 0; i < (int)psize; ++i) {
-				printf(" %.2x ", packet[i]);
+			if (m.msg_type == GETPARAM_ID || m.msg_type == GETOUTPUT_ID || 
+				m.msg_type == GETSOURCE_ID || m.msg_type == GETNODES_ID || m.msg_type == ADDNODE_ID) {
+				printf("adding fd %d with id %d\n", fd, BytesTo16(packet[ID_L], packet[ID_H]));
+				if (clientAddPendResponses(fd, BytesTo16(packet[ID_L], packet[ID_H])) == -1) {
+					warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n");
+				}
 			}
-			printf("'\n");
+
+			// printf("packetToQuad = '");
+			// for(int i = 0; i < (int)psize; ++i) {
+			// 	printf(" %.2x ", packet[i]);
+			// }
+			// printf("'\n");
 			
 			int retval = writeQuad(packet, psize);
-			printf("sent %d bytes\n", retval);
+			// printf("sent %d bytes\n", retval);
 			free(data);
 		}
 
@@ -782,11 +781,11 @@ static void quad_recv() {
 	}
 	respBufLen += respLen;
 
-	printf("packetFromQuad = '");
-	for(int i = 0; i < (int)respBufLen; ++i) {
-		printf(" %.2x ", respBuf[i]);
-	}
-	printf("'\n");
+	// printf("packetFromQuad = '");
+	// for(int i = 0; i < (int)respBufLen; ++i) {
+	// 	printf(" %.2x ", respBuf[i]);
+	// }
+	// printf("'\n");
 
 	while(respBufLen){
 		datalen = DecodePacket(&m, data, CMD_MAX_LENGTH, respBuf, respBufLen);
@@ -833,11 +832,9 @@ static void quad_recv() {
 					printf("New log file created: '%s'\n", log_file);
 					quadlog_file = fopen(log_file, "a");
 					quadlog_file_open = 1;
-				}	
-				/* something like this */
+				}
 				//printf("(Quad) : Log found\n");
 				fwrite((char *) data, sizeof(char), m.data_len, quadlog_file);
-				// fflush(quadlog_file);
 				break;
 			case RESPPARAM_ID:
 			case RESPSOURCE_ID:
@@ -855,6 +852,7 @@ static void quad_recv() {
 				break;
 			default:
 				printf("(Backend): message type %d ignored from quad\n", m.msg_type);
+				break;
 		}
 	}	
 }
@@ -882,6 +880,7 @@ static void handleResponse(struct metadata *m, uint8_t * data)
 			break;
 		default:
 			result = -1;
+			break;
 	}
 
 	if (result < 0) {
@@ -890,12 +889,16 @@ static void handleResponse(struct metadata *m, uint8_t * data)
 		return;
 	}
 
-	// for(int fd = 0; fd <= max_fd; ++fd) {
-	// 	if (get_client_index(fd) < 0) {
-	// 		clientRemovePendResponses(fd, m->msg_id);
-	// 		write(fd, buffer, result);
-	// 	}
-	// }
+	printf("msg to client = '%s'\n", buffer);
+
+	for(int fd = 0; fd <= max_fd; ++fd) {
+		if (get_client_index(fd) > -1) {
+			clientRemovePendResponses(fd, m->msg_id);
+			write(fd, buffer, result);
+		}
+	}
+
+	printf("leaving handleResponse\n");
 	free(buffer);
 }
 
diff --git a/groundStation/src/backend/param.c b/groundStation/src/backend/param.c
index 8912b65f9..5fdba8fd5 100644
--- a/groundStation/src/backend/param.c
+++ b/groundStation/src/backend/param.c
@@ -120,7 +120,7 @@ int DecodeResponseParam(
 		return -1;
 	}
 
-	return snprintf(msg, max_len, "getparam %" PRId16 " %" PRId16 " %f", 
+	return snprintf(msg, max_len, "getparam %" PRId16 " %" PRId16 " %f\n", 
 		BytesTo16(data[RESP_BLOCK_ID_L], data[RESP_BLOCK_ID_H]), 
 		BytesTo16(data[RESP_PARAM_ID_L], data[RESP_PARAM_ID_H]), 
 		BytesToFloat(data[RESP_VAL_1], data[RESP_VAL_2],
diff --git a/groundStation/src/cli/cli_param.c b/groundStation/src/cli/cli_param.c
index 478682cce..f509ed092 100644
--- a/groundStation/src/cli/cli_param.c
+++ b/groundStation/src/cli/cli_param.c
@@ -30,7 +30,7 @@ int cli_getparam(struct backend_conn * conn, int argc, char ** argv) {
 	}
 
 	printf("BLOCK.PARAM = VAL\n" \
-		   "  %" PRId16 ".%" PRId16 "   =  %lf\n",
+		   "   %2" PRId16 ".%2" PRId16 "   =  %lf\n",
 		   param_data.block,
 		   param_data.param,
 		   param_data.value);
-- 
GitLab