diff --git a/groundStation/addnode b/groundStation/addnode deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/addnode +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/getnodes b/groundStation/getnodes deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/getnodes +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/getoutput b/groundStation/getoutput deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/getoutput +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/getparam b/groundStation/getparam deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/getparam +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/getsource b/groundStation/getsource deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/getsource +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/setparam b/groundStation/setparam deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/setparam +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/setsource b/groundStation/setsource deleted file mode 120000 index 83c63a5d9a0f1ab92f86859877d2d168eca32fc0..0000000000000000000000000000000000000000 --- a/groundStation/setsource +++ /dev/null @@ -1 +0,0 @@ -Cli \ No newline at end of file diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index 94e8e7dcc17b539223c155b8a94b2dbff77b4a69..5115a25c9919f6fd2a1422d5c5aa962d334d93de 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -738,7 +738,6 @@ 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"); } @@ -889,7 +888,7 @@ static void handleResponse(struct metadata *m, uint8_t * data) return; } - printf("msg to client = '%s'\n", buffer); + // printf("msg to client = '%s'\n", buffer); for(int fd = 0; fd <= max_fd; ++fd) { if (get_client_index(fd) > -1) { @@ -898,7 +897,6 @@ static void handleResponse(struct metadata *m, uint8_t * data) } } - printf("leaving handleResponse\n"); free(buffer); } diff --git a/groundStation/src/backend/nodes.c b/groundStation/src/backend/nodes.c index 119fac877d2182d321602c136328e7accaa418e7..695f58a00a0c67d0cdbe86db9a88c544bb6c67af 100644 --- a/groundStation/src/backend/nodes.c +++ b/groundStation/src/backend/nodes.c @@ -69,6 +69,18 @@ enum ResponseGetnodesData { RESP_GN_MIN_DATA_SIZE }; +static int resizeMsg(char **msg_ptr, int *curr_max, int check_val) { + /* resize the msg if necessary */ + if (*curr_max < check_val) { + *curr_max = *curr_max * 4; + *msg_ptr = realloc(*msg_ptr, sizeof(**msg_ptr) * *curr_max); + if (!msg_ptr) { + return -1; + } + } + return 0; +} + /* Decode a metadata and data to populate a. * Returns bytes written to msg, -1 on failure. */ @@ -87,42 +99,38 @@ int DecodeResponseGetNodes( } uint16_t num_nodes = BytesTo16(data[RESP_GN_NUM_NODES_L], data[RESP_GN_NUM_NODES_H]); - - /* resize the msg if necessary */ - if (max_len < (m->data_len * 2)) { - max_len = max_len * 2; - msg = realloc(msg, sizeof(*msg) * max_len); - if (!msg) { - return -1; - } + + if (resizeMsg(&msg, (int *)&max_len, (m->data_len *2)) == -1) { + return -1; } - - int16_t val; - char name[512]; /* Corresponding to the maximum name len that the frontend will accept */ + char name[512] = "";/* Corresponding to the maximum name len that the frontend will accept */ size_t i; - int msg_offset = 0; - int data_offset = RESP_GN_MIN_DATA_SIZE; - + int msg_len = 0, msg_offset = 0, data_offset = RESP_GN_MIN_DATA_SIZE; sprintf(msg, "getnodes %hu %n", num_nodes, &msg_offset); - msg += msg_offset; + msg_len += msg_offset; + for(i = 0; i < num_nodes * 3; ++i) { if (i < num_nodes * 2) { val = BytesTo16(data[data_offset], data[data_offset+1]); data_offset += 2; - sprintf(msg, "%" PRId16 " %n", val, &msg_offset); + sprintf(&msg[msg_len], "%" PRId16 " %n", val, &msg_offset); } else { - strncpy(name, (char *) &data[data_offset], 512); + strncpy(name, (char *) (data + data_offset), 512); data_offset += strlen(name) + 1; - sprintf(msg, "%s %n", name, &msg_offset); + sprintf(&msg[msg_len], "'%s' %n", name, &msg_offset); } + msg_len += msg_offset; - msg += msg_offset; - } + if (resizeMsg(&msg, (int *)&max_len, msg_len + (msg_offset *2)) == -1) { + return -1; + } + } + strcat(&msg[msg_len], "\n"); return strlen(msg); } @@ -148,6 +156,6 @@ int DecodeResponseAddNode( return -1; } - return sprintf(msg, "addnode %d", + return sprintf(msg, "addnode %d\n", BytesTo16(data[RESP_AN_BLOCK_ID_L], data[RESP_AN_BLOCK_ID_H])); } \ No newline at end of file diff --git a/groundStation/src/backend/output.c b/groundStation/src/backend/output.c index d72f04bcddf5a0f8645f1ad061fa6346fe3c458e..9176be6fb7678db8708f5002ac17d31c915f4acc 100644 --- a/groundStation/src/backend/output.c +++ b/groundStation/src/backend/output.c @@ -70,7 +70,7 @@ int DecodeResponseOutput( return -1; } - return snprintf(msg, max_len, "getoutput %" PRId16 " %" PRId16 " %f", + return snprintf(msg, max_len, "getoutput %" PRId16 " %" PRId16 " %f\n", BytesTo16(data[RESP_BLOCK_ID_L], data[RESP_BLOCK_ID_H]), BytesTo16(data[RESP_OUTPUT_ID_L], data[RESP_OUTPUT_ID_H]), BytesToFloat(data[RESP_VAL_1], data[RESP_VAL_2], diff --git a/groundStation/src/backend/source.c b/groundStation/src/backend/source.c index 683a3011f0974898dd15ab71258380e0ee15e206..dd2540e371ee6d8b0d5aa91535e6af13f76145bf 100644 --- a/groundStation/src/backend/source.c +++ b/groundStation/src/backend/source.c @@ -116,7 +116,7 @@ int DecodeResponseSource( return -1; } - return snprintf(msg, max_len, "getsource %" PRId16 " %" PRId16 " %" PRId16" %" PRId16, + return snprintf(msg, max_len, "getsource %" PRId16 " %" PRId16 " %" PRId16" %" PRId16 "\n", BytesTo16(data[RESP_DST_BLOCK_ID_L], data[RESP_DST_BLOCK_ID_H]), BytesTo16(data[RESP_DST_INPUT_ID_L], data[RESP_DST_INPUT_ID_H]), BytesTo16(data[RESP_SRC_BLOCK_ID_L], data[RESP_SRC_BLOCK_ID_H]), diff --git a/groundStation/src/cli/cli_nodes.c b/groundStation/src/cli/cli_nodes.c index 79d0633fbcc6b86edbe2c62680e801200c642854..af51d9cb2c3c3d2954547dc102f88d682e5ff13c 100644 --- a/groundStation/src/cli/cli_nodes.c +++ b/groundStation/src/cli/cli_nodes.c @@ -25,14 +25,21 @@ int cli_getnodes(struct backend_conn * conn, int argc, char ** argv) { return 1; } - node_data = malloc(sizeof(*node_data) * num_nodes); + node_data = malloc(sizeof(*node_data)); - if (frontend_getnodes(conn, node_data, &num_nodes)) { + if (frontend_getnodes(conn, &node_data, &num_nodes)) { free(node_data); return 1; } - printf("unimplemented\n"); + printf("------------------------------------------------\n"); + printf("The following %lu Nodes have been found:\n", num_nodes); + printf("------------------------------------------------\n"); + printf("\tBLOCK\t\tTYPE\t\tNAME\n"); + printf("------------------------------------------------\n"); + for(size_t i = 0; i < num_nodes; ++i) { + printf("\t%3d\t\t%3d\t\t%s\n", node_data[i].block, node_data[i].type, node_data[i].name); + } free(node_data); return 0; } diff --git a/groundStation/src/frontend/frontend_nodes.c b/groundStation/src/frontend/frontend_nodes.c index b1284b409831042b8e3de75fa01a8b986d7520a8..26a45c60a609df3e4725a834f26061b898385949 100644 --- a/groundStation/src/frontend/frontend_nodes.c +++ b/groundStation/src/frontend/frontend_nodes.c @@ -13,7 +13,7 @@ */ int frontend_getnodes( struct backend_conn * conn, - struct frontend_node_data * node_data, + struct frontend_node_data ** node_data, size_t * num_nodes) { char msg[64] = ""; @@ -48,16 +48,28 @@ int frontend_getnodes( /* Resize if necessary */ if (num_nodes_ret != *num_nodes) { *num_nodes = num_nodes_ret; - node_data = realloc(node_data, sizeof(*node_data) * (*num_nodes)); - if (!node_data) { + *node_data = realloc(*node_data, sizeof(**node_data) * (*num_nodes)); + if (!*node_data) { return 1; } } + struct frontend_node_data * arr = *node_data; for (size_t i = 0; i < *num_nodes; ++i) { - sscanf(response, "%" SCNd16 " %" SCNd16 " %s %n", - &node_data[i].block, &node_data[i].type, (char *) &node_data[i].name, - (int *)&offset); + sscanf(response, "%" SCNd16 " %n", &arr[i].block, (int*)&offset); + // printf("found block %d\n", arr[i].block); + response += offset; + } + + for (size_t i = 0; i < *num_nodes; ++i) { + sscanf(response, "%" SCNd16 " %n", &arr[i].type, (int*)&offset); + // printf("found type %d\n", arr[i].type); + response += offset; + } + + for (size_t i = 0; i < *num_nodes; ++i) { + sscanf(response, " '%[^\t\n']' %n", (char *)&arr[i].name, (int *)&offset); + // printf("found name '%s'\n", arr[i].name); response += offset; } diff --git a/groundStation/src/frontend/frontend_nodes.h b/groundStation/src/frontend/frontend_nodes.h index 430301308e5de854260e7b49e7ca896723b4fd60..538a7cad6b132f42083f13fd6129a3b061c34b76 100644 --- a/groundStation/src/frontend/frontend_nodes.h +++ b/groundStation/src/frontend/frontend_nodes.h @@ -10,7 +10,7 @@ */ int frontend_getnodes( struct backend_conn * conn, - struct frontend_node_data * node_data, + struct frontend_node_data ** node_data, size_t * num_nodes);