Skip to content
Snippets Groups Projects
Commit 2f4f6cf0 authored by dawehr's avatar dawehr
Browse files

Fixed bugs with quad callbacks for graph commands.

parent b68e7598
No related branches found
No related tags found
No related merge requests found
...@@ -213,7 +213,7 @@ struct MessageType MessageTypes[MAX_TYPE_ID] = ...@@ -213,7 +213,7 @@ struct MessageType MessageTypes[MAX_TYPE_ID] =
// Type of the command data // Type of the command data
floatType, floatType,
// Function pointer // Function pointer
&cb_respoutput &cb_getoutput
}, },
// RESPOUTPUT // RESPOUTPUT
{ {
......
...@@ -34,8 +34,8 @@ enum BlockTypes { ...@@ -34,8 +34,8 @@ enum BlockTypes {
BLOCK_GAIN, // 03 BLOCK_GAIN, // 03
BLOCK_ACCUMULATE, // 04 BLOCK_ACCUMULATE, // 04
BLOCK_BOUNDS, // 05 BLOCK_BOUNDS, // 05
BLOCK_MIXER, // 07 BLOCK_MIXER, // 06
BLOCK_PID, // 08 BLOCK_PID, // 07
// <-- Insert new block type here // <-- Insert new block type here
MAX_BLOCK_TYPES MAX_BLOCK_TYPES
}; };
......
...@@ -258,17 +258,16 @@ int cb_getsource(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le ...@@ -258,17 +258,16 @@ int cb_getsource(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le
if (length != 4) {return -1;} if (length != 4) {return -1;}
u16 msg_id = meta->msg_id; u16 msg_id = meta->msg_id;
// Get requested IDs // Get requested IDs
int16_t node_id = build_short(data); struct node_ids ids = get_node_ids(data);
int16_t input_id = build_short(data + 2);
u8 resp_data[8]; u8 resp_data[8];
pack_short(node_id, resp_data); pack_short(ids.id, resp_data);
pack_short(input_id, resp_data + 2); pack_short(ids.sub_id, resp_data + 2);
struct computation_graph* graph = structs->parameter_struct.graph; struct computation_graph* graph = structs->parameter_struct.graph;
struct node_src source = graph_get_source(graph, node_id, input_id); struct node_src source = graph_get_source(graph, ids.id, ids.sub_id);
pack_short(source.controller_id, data + 4); pack_short(source.controller_id, resp_data + 4);
pack_short(source.controller_output, data + 6); pack_short(source.controller_output, resp_data + 6);
send_data(&structs->hardware_struct.uart, RESPSOURCE_ID, msg_id, resp_data, sizeof(resp_data)); send_data(&structs->hardware_struct.uart, RESPSOURCE_ID, msg_id, resp_data, sizeof(resp_data));
} }
...@@ -280,7 +279,7 @@ int cb_getsource(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le ...@@ -280,7 +279,7 @@ int cb_getsource(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le
int cb_getoutput(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 length) int cb_getoutput(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 length)
{ {
// Check if the data length is correct // Check if the data length is correct
if (length != 8) {return -1;} if (length != 4) {return -1;}
u16 msg_id = meta->msg_id; u16 msg_id = meta->msg_id;
// Get the controller ID, parameter ID // Get the controller ID, parameter ID
...@@ -388,4 +387,4 @@ int cb_addnode(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 leng ...@@ -388,4 +387,4 @@ int cb_addnode(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 leng
size_t name_len = length - 2; size_t name_len = length - 2;
return 0; return 0;
} }
\ No newline at end of file
...@@ -56,7 +56,7 @@ int control_algorithm_init(parameter_t * ps) ...@@ -56,7 +56,7 @@ int control_algorithm_init(parameter_t * ps)
ps->throttle_trim_add = graph_add_defined_block(graph, BLOCK_ADD, "T trim add"); ps->throttle_trim_add = graph_add_defined_block(graph, BLOCK_ADD, "T trim add");
// Create blocks for sensor inputs // Create blocks for sensor inputs
ps->cur_pitch = graph_add_defined_block(graph, BLOCK_CONSTANT, "Pitch"); // ID 20 ps->cur_pitch = graph_add_defined_block(graph, BLOCK_CONSTANT, "Pitch"); // ID 15
ps->cur_roll = graph_add_defined_block(graph, BLOCK_CONSTANT, "Roll"); ps->cur_roll = graph_add_defined_block(graph, BLOCK_CONSTANT, "Roll");
ps->cur_yaw = graph_add_defined_block(graph, BLOCK_CONSTANT, "Yaw"); ps->cur_yaw = graph_add_defined_block(graph, BLOCK_CONSTANT, "Yaw");
// Yaw angular velocity PID // Yaw angular velocity PID
......
...@@ -95,14 +95,14 @@ float build_float(u8 *buff) { ...@@ -95,14 +95,14 @@ float build_float(u8 *buff) {
} }
int16_t build_short(u8* buff) { int16_t build_short(u8* buff) {
return buff[1] << 8 | buff[0]; return (buff[0] & 0xFF) | ((buff[1] & 0xFF) << 8);
} }
void pack_short(int16_t val, u8* buff) { void pack_short(int16_t val, u8* buff) {
buff[0] = val | 0x0F; buff[0] = val & 0xFF;
buff[1] = (val >> 8) | 0x0F; buff[1] = (val >> 8) & 0xFF;
} }
void pack_float(float val, u8* buff) { void pack_float(float val, u8* buff) {
memcpy(&buff, &val, sizeof(val)); memcpy(buff, &val, sizeof(val));
} }
\ No newline at end of file
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