Skip to content
Snippets Groups Projects
Commit cfba4748 authored by burneykb's avatar burneykb
Browse files

implemented cb_addnode in the quad_app library

parent cc49ff74
No related branches found
No related tags found
No related merge requests found
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment