From cfba4748de55f2adbabb1c50beff0e17c242d8dc Mon Sep 17 00:00:00 2001 From: burneykb <burneykb@iastate.edu> Date: Mon, 27 Mar 2017 05:01:20 -0500 Subject: [PATCH] implemented cb_addnode in the quad_app library --- quad/src/quad_app/callbacks.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/quad/src/quad_app/callbacks.c b/quad/src/quad_app/callbacks.c index 2eef7ca78..f55a8ecb6 100644 --- a/quad/src/quad_app/callbacks.c +++ b/quad/src/quad_app/callbacks.c @@ -1,5 +1,6 @@ #include "communication.h" #include "commands.h" +#include "graph_blocks.h" #include "type_def.h" #include "computation_graph.h" #include "util.h" @@ -382,10 +383,29 @@ int cb_getnodes(struct modular_structs *structs, struct metadata *meta, unsigned * |-----------------------------| */ int cb_addnode(struct modular_structs *structs, struct metadata *meta, unsigned char *data, unsigned short length) { - const struct computation_graph* graph = structs->parameter_struct.graph; + // Check if the data length is large enough if (length < 2) {return -1;} + // Size of name size_t name_len = length - 2; + struct computation_graph* graph = structs->parameter_struct.graph; + char resp_buf[2]; + int16_t node_type = build_short(data); + if (node_type < 0 && node_type >= MAX_BLOCK_TYPES) { + pack_short(-1, resp_buf); + send_data(&structs->hardware_struct.uart, RESPADDNODE_ID, meta->msg_id, resp_buf, 2); + return -1; + } + + char* name = strndup(data+2, name_len); + int new_block_id = graph_add_defined_block(graph, node_type, name); + free(name); + // Format the response data + // New Block Id + pack_short(new_block_id, resp_buf); + + // Send the response + send_data(&structs->hardware_struct.uart, RESPADDNODE_ID, meta->msg_id, resp_buf, 2); return 0; } -- GitLab