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
990a2de5
Commit
990a2de5
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
Fixing message id formating and cmd tokenizing
parent
1308937f
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
groundStation/src/backend/communication.c
+27
-21
27 additions, 21 deletions
groundStation/src/backend/communication.c
with
27 additions
and
21 deletions
groundStation/src/backend/communication.c
+
27
−
21
View file @
990a2de5
...
@@ -53,7 +53,7 @@ int checkInt(char *intString, int *value) {
...
@@ -53,7 +53,7 @@ int checkInt(char *intString, int *value) {
// Formatting commands from ground station CLI
// Formatting commands from ground station CLI
int
formatCommand
(
char
*
command
,
unsigned
char
**
formattedCommand
)
{
int
formatCommand
(
char
*
command
,
unsigned
char
**
formattedCommand
)
{
fprintf
(
stderr
,
"length = %li , received '%s'
\n
"
,
strlen
(
command
),
command
);
//
fprintf(stderr, "length = %li , received '%s'\n", strlen(command), command);
char
cmd
[
strlen
(
command
)];
char
cmd
[
strlen
(
command
)];
strncpy
(
cmd
,
command
,
strlen
(
command
));
strncpy
(
cmd
,
command
,
strlen
(
command
));
cmd
[
strlen
(
command
)]
=
'\0'
;
cmd
[
strlen
(
command
)]
=
'\0'
;
...
@@ -65,7 +65,7 @@ int formatCommand(char *command, unsigned char **formattedCommand) {
...
@@ -65,7 +65,7 @@ int formatCommand(char *command, unsigned char **formattedCommand) {
metadata_t
metadata
;
metadata_t
metadata
;
// ----------------------------------------------
// ----------------------------------------------
if
(
tokens
.
numTokens
>
1
)
{
if
(
tokens
.
numTokens
>
0
)
{
for
(
int
type
=
0
;
type
<
MAX_TYPE
;
type
++
)
for
(
int
type
=
0
;
type
<
MAX_TYPE
;
type
++
)
{
{
for
(
int
subtype
=
0
;
subtype
<
MAX_SUBTYPE
;
subtype
++
)
for
(
int
subtype
=
0
;
subtype
<
MAX_SUBTYPE
;
subtype
++
)
...
@@ -79,36 +79,41 @@ int formatCommand(char *command, unsigned char **formattedCommand) {
...
@@ -79,36 +79,41 @@ int formatCommand(char *command, unsigned char **formattedCommand) {
{
{
// Validate the float input
// Validate the float input
case
floatType
:
case
floatType
:
valid
=
checkFloat
(
tokens
.
tokens
[
1
],
&
floatValue
);
if
(
!
valid
)
{
return
-
1
;
}
printf
(
"%f, %s
\n
"
,
floatValue
,
tokens
.
tokens
[
1
]);
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
msg_type
=
MessageTypes
[
type
].
ID
;
metadata
.
msg_type
=
MessageTypes
[
type
].
ID
;
metadata
.
msg_subtype
=
MessageTypes
[
type
].
subtypes
[
subtype
].
ID
;
metadata
.
msg_subtype
=
MessageTypes
[
type
].
subtypes
[
subtype
].
ID
;
metadata
.
msg_id
=
msgNum
++
;
metadata
.
data_len
=
sizeof
(
floatValue
);
if
(
MessageTypes
[
type
].
ID
==
0x01
)
{
valid
=
checkFloat
(
tokens
.
tokens
[
1
],
&
floatValue
);
if
(
!
valid
)
{
return
-
1
;
}
metadata
.
data_len
=
sizeof
(
floatValue
);
}
else
{
metadata
.
data_len
=
0
;
}
metadata
.
msg_id
=
msgNum
++
;
formatPacket
(
&
metadata
,
&
floatValue
,
formattedCommand
);
formatPacket
(
&
metadata
,
&
floatValue
,
formattedCommand
);
break
;
break
;
// Validate the integer input
// Validate the integer input
case
intType
:
case
intType
:
valid
=
checkInt
(
tokens
.
tokens
[
1
],
&
intValue
);
if
(
!
valid
)
{
return
-
1
;
}
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
msg_type
=
MessageTypes
[
type
].
ID
;
metadata
.
msg_type
=
MessageTypes
[
type
].
ID
;
metadata
.
msg_subtype
=
MessageTypes
[
type
].
subtypes
[
subtype
].
ID
;
metadata
.
msg_subtype
=
MessageTypes
[
type
].
subtypes
[
subtype
].
ID
;
metadata
.
msg_id
=
msgNum
++
;
metadata
.
data_len
=
sizeof
(
intValue
);
if
(
MessageTypes
[
type
].
ID
==
0x01
)
{
valid
=
checkInt
(
tokens
.
tokens
[
1
],
&
intValue
);
if
(
!
valid
)
{
return
-
1
;
}
metadata
.
data_len
=
sizeof
(
intValue
);
}
else
{
metadata
.
data_len
=
0
;
}
metadata
.
msg_id
=
msgNum
++
;
formatPacket
(
&
metadata
,
&
intValue
,
formattedCommand
);
formatPacket
(
&
metadata
,
&
intValue
,
formattedCommand
);
break
;
break
;
...
@@ -160,7 +165,8 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
...
@@ -160,7 +165,8 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
(
*
formattedCommand
)[
2
]
=
metadata
->
msg_subtype
;
(
*
formattedCommand
)[
2
]
=
metadata
->
msg_subtype
;
//Msg id (msgNum is 2 bytes)
//Msg id (msgNum is 2 bytes)
(
*
formattedCommand
)[
3
]
=
metadata
->
msg_id
;
(
*
formattedCommand
)[
3
]
=
(
metadata
->
msg_id
&
0x000000ff
);
(
*
formattedCommand
)[
4
]
=
((
metadata
->
msg_id
>>
8
)
&
0x000000ff
);
// Data length and data - bytes 5&6 for len, 7+ for data
// Data length and data - bytes 5&6 for len, 7+ for data
(
*
formattedCommand
)[
5
]
=
metadata
->
data_len
&
0x000000ff
;
(
*
formattedCommand
)[
5
]
=
metadata
->
data_len
&
0x000000ff
;
...
@@ -176,7 +182,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
...
@@ -176,7 +182,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
{
{
data_checksum
^=
(
*
formattedCommand
)[
i
];
data_checksum
^=
(
*
formattedCommand
)[
i
];
}
}
printf
(
"checksum = %x
\n
"
,
(
unsigned
)
data_checksum
);
(
*
formattedCommand
)[
7
+
metadata
->
data_len
]
=
data_checksum
;
(
*
formattedCommand
)[
7
+
metadata
->
data_len
]
=
data_checksum
;
return
0
;
return
0
;
...
...
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