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
dec6a9be
Commit
dec6a9be
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
added help flag to monitor command
parent
c4d5cbdf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
groundStation/src/cli/cli.c
+26
-18
26 additions, 18 deletions
groundStation/src/cli/cli.c
groundStation/src/cli/cli_monitor.c
+23
-3
23 additions, 3 deletions
groundStation/src/cli/cli_monitor.c
with
49 additions
and
21 deletions
groundStation/src/cli/cli.c
+
26
−
18
View file @
dec6a9be
...
@@ -13,15 +13,7 @@ int main(int argc, char **argv)
...
@@ -13,15 +13,7 @@ int main(int argc, char **argv)
int
c
;
int
c
;
int
i
,
useSymlink
=
0
;
int
i
,
useSymlink
=
0
;
struct
backend_conn
*
conn
;
struct
backend_conn
*
conn
;
static
int
needHelp
=
0
;
int
needCliHelp
=
0
,
needCommandHelp
=
0
;
static
struct
option
long_options
[]
=
{
/* These options don’t set a flag. We distinguish them by their indices. */
{
"help"
,
no_argument
,
&
needHelp
,
1
},
{
0
,
0
,
0
,
0
}
};
int
option_index
=
0
;
c
=
getopt_long
(
argc
,
argv
,
""
,
long_options
,
&
option_index
);
// Determine if the cli was called using a symlink
// Determine if the cli was called using a symlink
command
=
basename
(
argv
[
0
]);
command
=
basename
(
argv
[
0
]);
...
@@ -34,7 +26,7 @@ int main(int argc, char **argv)
...
@@ -34,7 +26,7 @@ int main(int argc, char **argv)
}
}
// Verify the user has entered enough information to continue
// Verify the user has entered enough information to continue
if
(
argc
<
2
&&
!
useSymlink
)
{
if
(
argc
<
2
&&
!
useSymlink
)
{
printf
(
"Incorrect usage :
\n
"
);
printf
(
"Incorrect usage :
\n
"
);
printf
(
"
\n\t
Usage : ./Cli command [options]
\n
"
);
printf
(
"
\n\t
Usage : ./Cli command [options]
\n
"
);
printf
(
"
\t
For a list of available commands run ./Cli --help
\n\n
"
);
printf
(
"
\t
For a list of available commands run ./Cli --help
\n\n
"
);
...
@@ -42,8 +34,12 @@ int main(int argc, char **argv)
...
@@ -42,8 +34,12 @@ int main(int argc, char **argv)
return
-
1
;
return
-
1
;
}
}
// Determine if the user called for help on the cli
needCliHelp
=
(
strncmp
(
"--help"
,
argv
[
1
],
strlen
(
argv
[
1
]))
==
0
);
// If the user runs './Cli help' , provide the user with a list of commands available.
// If the user runs './Cli help' , provide the user with a list of commands available.
if
(
needHelp
)
{
if
(
need
Cli
Help
)
{
printf
(
"Usage : ./Cli command [options]
\n
"
);
printf
(
"Usage : ./Cli command [options]
\n
"
);
printf
(
"For a list of available options for a command run ./Cli command --help
\n\n
"
);
printf
(
"For a list of available options for a command run ./Cli command --help
\n\n
"
);
printf
(
"Available commands include the following
\n
"
);
printf
(
"Available commands include the following
\n
"
);
...
@@ -53,9 +49,8 @@ int main(int argc, char **argv)
...
@@ -53,9 +49,8 @@ int main(int argc, char **argv)
return
0
;
return
0
;
}
}
// recognize which cli command the user has entered
// recognize which cli command the user has entered
if
(
cmdID
==
-
1
)
{
if
(
cmdID
==
-
1
)
{
command
=
argv
[
1
];
command
=
argv
[
1
];
for
(
i
=
0
;
i
<
MAX_COMMANDS
;
++
i
)
{
for
(
i
=
0
;
i
<
MAX_COMMANDS
;
++
i
)
{
if
(
strncmp
(
command
,
commandNames
[
i
],
strlen
(
commandNames
[
i
]))
==
0
)
if
(
strncmp
(
command
,
commandNames
[
i
],
strlen
(
commandNames
[
i
]))
==
0
)
...
@@ -65,7 +60,7 @@ int main(int argc, char **argv)
...
@@ -65,7 +60,7 @@ int main(int argc, char **argv)
}
}
}
}
if
(
cmdID
==
-
1
){
if
(
cmdID
==
-
1
){
printf
(
"Could not match '%s' with a command. Please try again...
\n
"
,
command
);
printf
(
"Could not match '%s' with a command. Please try again...
\n
"
,
command
);
printf
(
"For help running the program, run ./Cli --help
\n
"
);
printf
(
"For help running the program, run ./Cli --help
\n
"
);
return
-
1
;
return
-
1
;
...
@@ -73,6 +68,17 @@ int main(int argc, char **argv)
...
@@ -73,6 +68,17 @@ int main(int argc, char **argv)
printf
(
"Parsed Command : %s
\n
"
,
commandNames
[
cmdID
]);
printf
(
"Parsed Command : %s
\n
"
,
commandNames
[
cmdID
]);
// Determine if the user called for help on the command
if
(
!
useSymlink
&&
argc
>
2
)
{
if
(
strncmp
(
"--help"
,
argv
[
2
],
strlen
(
argv
[
2
]))
==
0
)
{
needCommandHelp
=
1
;
}
}
else
if
(
useSymlink
&&
argc
>
1
)
{
if
(
strncmp
(
"--help"
,
argv
[
1
],
strlen
(
argv
[
1
]))
==
0
)
{
needCommandHelp
=
1
;
}
}
/**
/**
* I the user has asked for help, and we have already found
* I the user has asked for help, and we have already found
* the command that they are trying to use. Then we need
* the command that they are trying to use. Then we need
...
@@ -85,22 +91,24 @@ int main(int argc, char **argv)
...
@@ -85,22 +91,24 @@ int main(int argc, char **argv)
*/
*/
// Only require the backend if we will need to use it.
// Only require the backend if we will need to use it.
if
(
!
needHelp
)
{
if
(
!
need
Command
Help
)
{
// Create the connection to the backend
// Create the connection to the backend
conn
=
ucart_backendConnect
();
conn
=
ucart_backendConnect
();
if
(
conn
==
NULL
)
{
if
(
conn
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
}
}
// Call the appropriate function
// Call the appropriate function
if
(
useSymlink
)
{
if
(
useSymlink
)
{
(
*
cli_functions
[
cmdID
])
(
conn
,
argc
,
&
argv
[
0
]);
(
*
cli_functions
[
cmdID
])
(
conn
,
argc
,
&
argv
[
0
]);
}
else
{
}
else
{
(
*
cli_functions
[
cmdID
])
(
conn
,
argc
-
1
,
&
argv
[
1
]);
(
*
cli_functions
[
cmdID
])
(
conn
,
argc
-
1
,
&
argv
[
1
]);
}
}
// Disconnect from the backend
// Disconnect from the backend
ucart_backendDisconnect
(
conn
);
if
(
!
needCommandHelp
)
{
ucart_backendDisconnect
(
conn
);
}
return
0
;
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
groundStation/src/cli/cli_monitor.c
+
23
−
3
View file @
dec6a9be
...
@@ -13,12 +13,27 @@
...
@@ -13,12 +13,27 @@
int
cli_monitor
(
struct
backend_conn
*
conn
,
int
argc
,
char
**
argv
)
{
int
cli_monitor
(
struct
backend_conn
*
conn
,
int
argc
,
char
**
argv
)
{
int
c
,
result
;
int
c
,
result
;
int
countFlag
=
0
;
int
countFlag
=
0
;
/* getopt_long stores the option index here. */
int
option_index
=
0
;
int
count
,
rate
=
10
;
int
count
,
rate
=
10
;
int
forever
=
0
;
int
forever
=
0
;
static
int
needHelp
=
0
;
static
struct
option
long_options
[]
=
{
/* These options don’t set a flag. We distinguish them by their indices. */
{
"help"
,
no_argument
,
&
needHelp
,
1
},
{
0
,
0
,
0
,
0
}
};
while
(
1
)
{
// If you change this VVV please also update the help message
c
=
getopt_long
(
argc
,
argv
,
"fc:r:"
,
long_options
,
&
option_index
);
while
((
c
=
getopt
(
argc
,
argv
,
"fc:r:"
))
!=
-
1
)
{
if
(
c
==
-
1
)
switch
(
c
)
{
break
;
switch
(
c
)
{
case
'c'
:
case
'c'
:
count
=
atoi
(
optarg
);
count
=
atoi
(
optarg
);
countFlag
=
1
;
countFlag
=
1
;
...
@@ -34,6 +49,11 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv) {
...
@@ -34,6 +49,11 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv) {
}
}
}
}
if
(
needHelp
)
{
printf
(
"helping you
\n
"
);
return
0
;
}
if
(
forever
)
{
if
(
forever
)
{
for
(;;)
{
for
(;;)
{
struct
timespec
req
;
struct
timespec
req
;
...
...
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