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
403565df
Commit
403565df
authored
8 years ago
by
dawehr
Browse files
Options
Downloads
Patches
Plain Diff
Fixed issue with getParam size check.
parent
0273b0d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
quad/src/quad_app/callbacks.c
+76
-8
76 additions, 8 deletions
quad/src/quad_app/callbacks.c
with
76 additions
and
8 deletions
quad/src/quad_app/callbacks.c
+
76
−
8
View file @
403565df
...
...
@@ -179,7 +179,7 @@ int cb_setparam(modular_structs_t *structs, metadata_t *meta, u8 *data, u16 leng
int
cb_getparam
(
modular_structs_t
*
structs
,
metadata_t
*
meta
,
u8
*
data
,
u16
length
)
{
// Check if the data length is correct
if
(
length
!=
8
)
{
return
-
1
;}
if
(
length
!=
4
)
{
return
-
1
;}
u16
msg_id
=
meta
->
msg_id
;
// Get the controller ID, parameter ID
...
...
@@ -306,18 +306,86 @@ int cb_getoutput(modular_structs_t* structs, metadata_t *meta, u8 *data, u16 le
/*
* Handles a request for the list of nodes in the graph
* For N total nodes, returns data in the following format:
* |---------------------------------------------------------------------------|
* | data index || 0 - 2*N | 2 - 3 | 4 - 5 | 6 - 7 |
* |---------------------------------------------------------------------------|
* | parameter || Array of node | dest input ID | src node ID | src output ID |
* |---------------------------------------------------------------------------|
* | bytes || 2 | 2 | 2 | 2 |
* |---------------------------------------------------------------------------|
* The node IDs and type IDs are consecutive shorts
* The node names are null-separated
* |---------------------------------------------------------------|
* | data index || 0 - 2*N-1 | 2*N - 4*N-1 | 4*N - (< 4096) |
* |---------------------------------------------------------------|
* | parameter || Node IDs | Node type IDs | Node names |
* |---------------------------------------------------------------|
* | bytes || 2*N | 2*N | < 4096 |
* |---------------------------------------------------------------|
*/
int
cb_getnodes
(
modular_structs_t
*
structs
,
metadata_t
*
meta
,
u8
*
data
,
u16
length
)
{
const
struct
computation_graph
*
graph
=
structs
->
parameter_struct
.
graph
;
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
));
return
-
1
;
}
// Number of bytes in node ID being sent. Currently short (16 bits)
size_t
id_len
=
2
;
char
resp_buf
[
4096
];
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
));
}
// 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
));
}
// 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
;
size_t
name_len
=
strlen
(
name
);
if
(
name_len
+
1
<=
remaining_size
)
{
memcpy
(
resp_buf
+
offset
,
name
,
name_len
);
offset
+=
name_len
;
// Add null-terminator separator
resp_buf
[
offset
]
=
0
;
offset
+=
1
;
}
}
send_data
(
&
structs
->
hardware_struct
.
uart
,
RESPNODES_ID
,
meta
->
msg_id
,
resp_buf
,
offset
);
return
0
;
}
/*
* Handles adding a new node with a particular type and name
* Expects the uart buff to have data in the following format:
* |---------------------------------------------|
* | data index || 0 - 1 | 2 - ? |
* |---------------------------------------------|
* | parameter || type ID | New node name |
* |---------------------------------------------|
* | bytes || 2 | ? |
* |---------------------------------------------|
*
* Returns the new node ID in the following format:
* |-----------------------------|
* | data index || 0 - 1 |
* |-----------------------------|
* | parameter || node ID |
* |------------------------------
* | bytes || 2 |
* |-----------------------------|
*/
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
;
return
0
;
}
\ No newline at end of file
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