Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Distributed Autonomous Networked Control Lab
MicroCART
Commits
dae108dd
Commit
dae108dd
authored
8 years ago
by
dawehr
Browse files
Options
Downloads
Patches
Plain Diff
Added cb_addnode and fixed bugs with getnodes callback.
parent
ced15288
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
quad/src/quad_app/callbacks.c
+32
-15
32 additions, 15 deletions
quad/src/quad_app/callbacks.c
quad/src/quad_app/communication.c
+2
-2
2 additions, 2 deletions
quad/src/quad_app/communication.c
quad/src/quad_app/communication.h
+1
-1
1 addition, 1 deletion
quad/src/quad_app/communication.h
with
35 additions
and
18 deletions
quad/src/quad_app/callbacks.c
+
32
−
15
View file @
dae108dd
...
...
@@ -3,6 +3,7 @@
#include
"type_def.h"
#include
"computation_graph.h"
#include
"util.h"
#include
"graph_blocks.h"
/*
* Static variables used to keep track of packet counts
...
...
@@ -18,14 +19,14 @@ static size_t total_payload_received = 0;
*/
int
cb_debug
(
modular_structs_t
*
structs
,
metadata_t
*
meta
,
u8
*
data
,
u16
length
)
{
char
buf
[
255
];
u8
buf
[
255
];
// Get the node ID, parameter ID, parameter value
u8
node_id
=
data
[
0
];
struct
computation_graph
*
graph
=
structs
->
parameter_struct
.
graph
;
float
param_val
=
graph_get_output
(
graph
,
node_id
,
0
);
int
len
=
snprintf
(
buf
,
sizeof
buf
,
"%f"
,
param_val
);
int
len
=
snprintf
(
(
char
*
)
buf
,
sizeof
buf
,
"%f"
,
param_val
);
send_data
(
&
structs
->
hardware_struct
.
uart
,
DEBUG_ID
,
0
,
buf
,
len
>=
sizeof
(
buf
)
?
255
:
length
+
1
);
return
0
;
}
...
...
@@ -44,10 +45,10 @@ int cb_packetlog(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 len
* with the packet log data.
*/
int
cb_getpacketlogs
(
modular_structs_t
*
structs
,
metadata_t
*
meta
,
u8
*
data
,
u16
length
)
{
char
buf
[
255
];
u8
buf
[
255
];
// Message logging number of messages received and size of payload received
int
len
=
snprintf
(
buf
,
sizeof
buf
,
"%d,%d"
,
n_msg_received
,
total_payload_received
);
int
len
=
snprintf
(
(
char
*
)
buf
,
sizeof
buf
,
"%d,%d"
,
n_msg_received
,
total_payload_received
);
send_data
(
&
structs
->
hardware_struct
.
uart
,
LOG_ID
,
0
,
buf
,
len
>=
sizeof
(
buf
)
?
255
:
len
+
1
);
return
0
;
...
...
@@ -188,7 +189,7 @@ int cb_getparam(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 len
float
param_val
=
graph_get_param_val
(
graph
,
ids
.
id
,
ids
.
sub_id
);
// Format the response data
char
resp_data
[
8
];
u8
resp_data
[
8
];
// Controller ID
pack_short
(
ids
.
id
,
resp_data
);
// Parameter ID
...
...
@@ -270,6 +271,7 @@ int cb_getsource(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le
pack_short
(
source
.
controller_output
,
resp_data
+
6
);
send_data
(
&
structs
->
hardware_struct
.
uart
,
RESPSOURCE_ID
,
msg_id
,
resp_data
,
sizeof
(
resp_data
));
return
0
;
}
/**
...
...
@@ -288,7 +290,7 @@ int cb_getoutput(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le
float
output_val
=
graph_get_output
(
graph
,
ids
.
id
,
ids
.
sub_id
);
// Format the response data
char
resp_data
[
8
];
u8
resp_data
[
8
];
// Controller ID
pack_short
(
ids
.
id
,
resp_data
);
// Output ID
...
...
@@ -320,30 +322,36 @@ int cb_getnodes(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 len
if
(
graph
->
n_nodes
>=
150
)
{
static
char
*
error_msg
=
"Over 150 nodes. Not responding to cb_getnodes for fear of buffer overflow."
;
send_data
(
&
structs
->
hardware_struct
.
uart
,
DEBUG_ID
,
0
,
error_msg
,
sizeof
(
error_msg
));
(
u8
*
)
error_msg
,
sizeof
(
error_msg
));
return
-
1
;
}
// Number of bytes in node ID being sent. Currently short (16 bits)
size_t
id_len
=
2
;
const
size_t
id_len
=
2
;
u8
resp_buf
[
4096
];
size_t
offset
=
0
;
// Send the number of nodes there are in the graph
pack_short
(
graph
->
n_nodes
,
resp_buf
+
offset
);
offset
+=
id_len
;
char
resp_buf
[
4096
];
// Send all the node data
int
i
;
// Currently ID is always index in array.
// computation_graph provides no method of accessing ID, since it is implicit
for
(
i
=
0
;
i
<
graph
->
n_nodes
;
i
++
)
{
pack_short
(
i
,
resp_buf
+
(
id_len
*
i
));
pack_short
(
i
,
resp_buf
+
offset
);
offset
+=
id_len
;
}
// Construct type IDs
size_t
offset
=
id_len
*
graph
->
n_nodes
;
for
(
i
=
0
;
i
<
graph
->
n_nodes
;
i
++
)
{
int
type_id
=
graph
->
nodes
[
i
].
type
->
type_id
;
pack_short
(
type_id
,
resp_buf
+
offset
+
(
id_len
*
i
));
pack_short
(
type_id
,
resp_buf
+
offset
);
offset
+=
id_len
;
}
// Construct list of node names
offset
+=
id_len
*
graph
->
n_nodes
;
for
(
i
=
0
;
i
<
graph
->
n_nodes
;
i
++
)
{
size_t
remaining_size
=
sizeof
(
resp_buf
)
-
offset
;
const
char
*
name
=
graph
->
nodes
[
i
].
name
;
...
...
@@ -383,8 +391,17 @@ int cb_getnodes(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 len
*/
int
cb_addnode
(
modular_structs_t
*
structs
,
metadata_t
*
meta
,
u8
*
data
,
u16
length
)
{
if
(
length
<
2
)
{
return
-
1
;}
// Size of name
size_t
name_len
=
length
-
2
;
struct
computation_graph
*
graph
=
structs
->
parameter_struct
.
graph
;
// Get the data for the new node
int
block_type
=
build_short
(
data
);
char
*
name
=
(
char
*
)
&
data
[
2
];
int
new_node_id
=
graph_add_defined_block
(
graph
,
block_type
,
name
);
// Respond with the result of graph_add_defined_block, which will be -1 if failure
u8
resp_buf
[
2
];
pack_short
(
new_node_id
,
resp_buf
);
send_data
(
&
structs
->
hardware_struct
.
uart
,
RESPADDNODE_ID
,
meta
->
msg_id
,
resp_buf
,
sizeof
(
resp_buf
));
return
0
;
}
This diff is collapsed.
Click to expand it.
quad/src/quad_app/communication.c
+
2
−
2
View file @
dae108dd
...
...
@@ -103,7 +103,7 @@ void process_received(modular_structs_t *structs) {
}
}
int
send_data
(
struct
UARTDriver
*
uart
,
u16
type_id
,
u16
msg_id
,
char
*
data
,
size_t
size
)
{
int
send_data
(
struct
UARTDriver
*
uart
,
u16
type_id
,
u16
msg_id
,
u8
*
data
,
size_t
size
)
{
//----------------------------------------------------------------------------------------------
// index|| 0 | 1 | 2 | 3 & 4 | 5 & 6 | 7+ | end |
//---------------------------------------------------------------------------------------------|
...
...
@@ -135,7 +135,7 @@ int send_data(struct UARTDriver *uart, u16 type_id, u16 msg_id, char* data, size
}
for
(
i
=
0
;
i
<
size
;
i
++
)
{
packet_checksum
^=
data
[
i
];
uart
->
write
(
uart
,
(
unsigned
char
)
data
[
i
]);
uart
->
write
(
uart
,
data
[
i
]);
}
uart
->
write
(
uart
,
packet_checksum
);
...
...
This diff is collapsed.
Click to expand it.
quad/src/quad_app/communication.h
+
1
−
1
View file @
dae108dd
...
...
@@ -10,6 +10,6 @@
int
initUartComms
();
void
process_received
(
modular_structs_t
*
structs
);
int
send_data
(
struct
UARTDriver
*
uart
,
u16
type_id
,
u16
msg_id
,
char
*
data
,
size_t
size
);
int
send_data
(
struct
UARTDriver
*
uart
,
u16
type_id
,
u16
msg_id
,
u8
*
data
,
size_t
size
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment