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
7fdfdfdd
Commit
7fdfdfdd
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
CLI responds correctly to user input
parent
19f848b4
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
.gitignore
+1
-1
1 addition, 1 deletion
.gitignore
BlueTooth
+0
-0
0 additions, 0 deletions
BlueTooth
src/microcart_cli.c
+34
-14
34 additions, 14 deletions
src/microcart_cli.c
with
35 additions
and
15 deletions
.gitignore
+
1
−
1
View file @
7fdfdfdd
...
...
@@ -34,5 +34,5 @@
# vrpn/build files
bt_poc/
src/vrpn/build*
src/vrpn/build*
src/vrpn/pc_linux64/*
This diff is collapsed.
Click to expand it.
BlueTooth
+
0
−
0
View file @
7fdfdfdd
No preview for this file type
This diff is collapsed.
Click to expand it.
src/microcart_cli.c
+
34
−
14
View file @
7fdfdfdd
...
...
@@ -34,6 +34,7 @@ void printVrpnData(struct ucart_vrpn_TrackerData *);
int
connectToZybo
();
void
*
handleQuadResponse
();
void
*
handleCliInput
();
int
atomic_check
(
int
*
,
pthread_mutex_t
*
);
static
void
cb
(
struct
ucart_vrpn_TrackerData
*
);
...
...
@@ -80,14 +81,12 @@ void *handleQuadResponse() {
unsigned
char
buffer
[
255
];
while
(
keepRunning
)
{
printf
(
"in quad response thread
\n
"
);
fflush
(
0
);
// Clear the buffer and read the message from the socket (from the server)
memset
(
buffer
,
0
,
255
);
// If there was an error reading from the socket, throw an error
if
(
read
(
zyboSocket
,
buffer
,
255
)
<=
0
)
{
fprintf
(
stderr
,
"CLI QUAD: ERROR reading from quad.
\n
"
);
fflush
(
stderr
);
continue
;
}
...
...
@@ -98,7 +97,7 @@ void *handleQuadResponse() {
//parse_packet(buffer, &respBuf, &metadata);
printf
(
"CLI QUAD: %s
\n
"
,
buffer
);
f
printf
(
stderr
,
"CLI QUAD: %s
\n
"
,
buffer
);
}
pthread_exit
(
NULL
);
...
...
@@ -107,7 +106,6 @@ void *handleQuadResponse() {
void
*
handleCliInput
()
{
while
(
keepRunning
)
{
printf
(
"in cli input thread
\n
"
);
fflush
(
0
);
char
userCommand
[
CMD_MAX_LENGTH
]
=
{};
fprintf
(
stderr
,
"$microcart> "
);
...
...
@@ -123,6 +121,9 @@ void *handleCliInput() {
continue
;
}
if
((
userCommand
[
strlen
(
userCommand
)
-
1
]
==
'\n'
)
||
(
userCommand
[
strlen
(
userCommand
)
-
1
]
==
'\r'
))
userCommand
[
strlen
(
userCommand
)
-
1
]
=
'\0'
;
pthread_mutex_lock
(
&
cliInputMutex
);
newCliInput
=
1
;
memcpy
(
commandBuf
,
&
userCommand
,
CMD_MAX_LENGTH
);
...
...
@@ -148,11 +149,11 @@ int main(int argc, char **argv)
signal
(
SIGINT
,
killHandler
);
//
if ((zyboSocket = connectToZybo()) < 0)
//
{
//
perror("Error connecting to Zybo...");
//
exit(1);
//
}
if
((
zyboSocket
=
connectToZybo
())
<
0
)
{
perror
(
"Error connecting to Zybo..."
);
exit
(
1
);
}
// create vrpnTracker instance
// tracker = ucart_vrpn_tracker_createInstance(TRACKER_IP);
...
...
@@ -181,12 +182,21 @@ int main(int argc, char **argv)
// this function will be called whenever tracker receives data
// ucart_vrpn_tracker_addCallback(tracker, cb);
int
updatePrompt
=
0
;
while
(
1
)
{
char
tmpRespBuf
[
1024
];
char
tmpCommandBuf
[
CMD_MAX_LENGTH
];
if
(
updatePrompt
)
{
fprintf
(
stderr
,
"$microcart> "
);
updatePrompt
=
!
updatePrompt
;
}
//check for user input via cli
if
(
newCliInput
)
if
(
atomic_check
(
&
newCliInput
,
&
cliInputMutex
)
)
{
pthread_mutex_lock
(
&
cliInputMutex
);
newCliInput
=
0
;
...
...
@@ -194,21 +204,24 @@ int main(int argc, char **argv)
pthread_mutex_unlock
(
&
cliInputMutex
);
// I can use printf becuase the command was gathered using fgets.
printf
(
"
\n
INPUT FOUND via CLI: '%s'
\n
"
,
tmpCommandBuf
);
fflush
(
0
);
fprintf
(
stderr
,
"
\r
INPUT FOUND via CLI: '%s'
\n
"
,
tmpCommandBuf
);
updatePrompt
=
1
;
}
//check for update/response from quad
if
(
newQuadResponse
)
if
(
atomic_check
(
&
newQuadResponse
,
&
quadResponseMutex
)
)
{
pthread_mutex_lock
(
&
quadResponseMutex
);
newQuadResponse
=
0
;
memcpy
(
tmpRespBuf
,
respBuf
,
1024
);
pthread_mutex_unlock
(
&
quadResponseMutex
);
printf
(
"
\
n
INPUT FOUND via QUAD: '"
);
fflush
(
0
);
f
printf
(
stderr
,
"
\
r
INPUT FOUND via QUAD: '"
);
fwrite
(
tmpRespBuf
,
1024
,
1
,
stdout
);
printf
(
"'
\n
"
);
fflush
(
0
);
fprintf
(
stderr
,
"'
\n
"
);
updatePrompt
=
1
;
}
usleep
(
10000
);
}
...
...
@@ -351,3 +364,10 @@ int connectToZybo() {
return
sock
;
}
}
int
atomic_check
(
int
*
atomicFlag
,
pthread_mutex_t
*
mutex
)
{
pthread_mutex_lock
(
mutex
);
int
result
=
*
atomicFlag
;
pthread_mutex_unlock
(
mutex
);
return
result
;
}
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