Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART_17-18
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
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
bbartels
MicroCART_17-18
Commits
2774d5a5
Commit
2774d5a5
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
simplifying and finishing command parsing
parent
df6006c1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
groundStation/.gitignore
+1
-0
1 addition, 0 deletions
groundStation/.gitignore
groundStation/src/cli/cli.c
+38
-38
38 additions, 38 deletions
groundStation/src/cli/cli.c
groundStation/src/cli/cli.h
+7
-1
7 additions, 1 deletion
groundStation/src/cli/cli.h
with
46 additions
and
39 deletions
groundStation/.gitignore
+
1
−
0
View file @
2774d5a5
...
...
@@ -44,3 +44,4 @@ BackEnd
obj
cli
monitorQuad
testClient
This diff is collapsed.
Click to expand it.
groundStation/src/cli/cli.c
+
38
−
38
View file @
2774d5a5
...
...
@@ -6,36 +6,67 @@
#include
<sys/socket.h>
#include
<sys/un.h>
#include
<unistd.h>
#include
<
getopt
.h>
#include
<
string
.h>
#include
<err.h>
#include
"cli.h"
int
parseInput
(
int
argc
,
char
**
argv
);
int
connectToBackEnd
();
int
main
(
int
argc
,
char
**
argv
)
{
int
cmdID
=
-
1
;
if
((
cmdID
=
parseInput
(
argc
,
argv
))
==
-
1
)
{
exit
(
1
);
char
*
command
;
int
i
,
s
,
useSymlink
=
0
;
command
=
argv
[
0
];
for
(
i
=
0
;
i
<
MAX_COMMANDS
;
++
i
)
{
if
(
strncmp
(
command
,
commandNames
[
i
],
strlen
(
commandNames
[
i
]))
==
0
)
{
cmdID
=
i
;
useSymlink
=
1
;
}
}
int
s
;
if
(
cmdID
==
-
1
)
{
command
=
argv
[
1
];
for
(
i
=
0
;
i
<
MAX_COMMANDS
;
++
i
)
{
if
(
strncmp
(
command
,
commandNames
[
i
],
strlen
(
commandNames
[
i
]))
==
0
)
{
cmdID
=
i
;
}
}
}
if
(
cmdID
==
-
1
){
printf
(
"Could not match input with a command. Please try again...
\n
"
);
return
-
1
;
}
printf
(
"Parsed Command : %s
\n
"
,
commandNames
[
cmdID
]);
if
((
s
=
connectToBackEnd
())
==
-
1
)
{
err
(
-
1
,
"connectToBackEnd"
);
}
printf
(
"connection to backend Successful
\n
"
);
if
(
useSymlink
)
{
//TODO Call correct command function pointer with (argv[1] ... argc[argc])
}
else
{
//TODO Call correct command function pointer with (argv[2] ... argv[argc])
}
close
(
s
);
return
0
;
}
int
connectToBackEnd
()
{
int
s
,
t
,
len
;
struct
sockaddr_un
remote
;
char
str
[
100
];
...
...
@@ -57,35 +88,4 @@ int connectToBackEnd() {
printf
(
"Connected.
\n
"
);
return
s
;
}
}
int
parseInput
(
int
argc
,
char
**
argv
)
{
static
int
cmdID
=
-
1
;
int
c
;
static
struct
option
long_options
[]
=
{
/* These options don’t set a flag. We distinguish them by their indices. */
{
"monitor"
,
no_argument
,
&
cmdID
,
CMD_MONITOR
},
{
0
,
0
,
0
,
0
}
};
while
(
1
)
{
/* getopt_long stores the option index here. */
int
option_index
=
0
;
c
=
getopt_long
(
argc
,
argv
,
""
,
long_options
,
&
option_index
);
/* Detect the end of the options. */
if
(
c
==
-
1
)
break
;
}
if
(
cmdID
==
-
1
)
{
printf
(
"Invalid command
\n
"
);
return
cmdID
;
}
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
groundStation/src/cli/cli.h
+
7
−
1
View file @
2774d5a5
...
...
@@ -5,11 +5,17 @@
enum
CommandNameIds
{
CMD_MONITOR
,
CMD_SETPID
,
CMD_GETPID
,
CMD_GETImu
,
MAX_COMMANDS
};
char
*
commandNames
[
MAX_COMMANDS
]
=
{
static
char
*
commandNames
[
MAX_COMMANDS
]
=
{
"monitor"
,
"setPid"
,
"getPid"
,
"getImu"
};
#endif
\ 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