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
c3ad96ae
Unverified
Commit
c3ad96ae
authored
8 years ago
by
Jake Drahos
Browse files
Options
Downloads
Patches
Plain Diff
Thread-safe writes to quad
parent
f492b4d3
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
Makefile
+3
-1
3 additions, 1 deletion
Makefile
src/microcart_cli.c
+39
-11
39 additions, 11 deletions
src/microcart_cli.c
with
42 additions
and
12 deletions
Makefile
+
3
−
1
View file @
c3ad96ae
...
...
@@ -23,7 +23,9 @@ OBJECTS = $(CPPOBJECTS) $(COBJECTS)
LIBS
=
-lpthread
-lbluetooth
-lvrpn
-lquat
-Lsrc
/vrpn/build
-Lsrc
/vrpn/build/quat
# Default target
all
:
logs vrpn/build $(EXE)
all
:
logs $(EXE)
vrpn
:
vrpn/build
# Main target
$(EXE)
:
$(OBJECTS)
...
...
This diff is collapsed.
Click to expand it.
src/microcart_cli.c
+
39
−
11
View file @
c3ad96ae
...
...
@@ -3,6 +3,7 @@
* BlueTooth socket program for passing vrpn data to quad.
*/
//system includes
#include
<err.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
...
...
@@ -44,15 +45,13 @@ int safe_fd_clr(int , fd_set* , int* );
static
void
cb
(
struct
ucart_vrpn_TrackerData
*
);
/* Thread-safe wrappers */
pthread_mutex_t
quadSocketMutex
,
logFileMutex
;
ssize_t
writeQuad
(
const
char
*
buf
,
size_t
count
);
ssize_t
dprintfLog
(
const
char
*
fmt
,
...);
pthread_mutex_t
quadSocketMutex
;
static
ssize_t
writeQuad
(
const
char
*
buf
,
size_t
count
);
// global variables
static
volatile
int
keepRunning
=
1
;
const
char
*
TRACKER_IP
=
"UAV@192.168.0.120:3883"
;
int
quadlog_file
;
int
zyboSocket
,
status
,
bytes_read
;
static
int
zyboSocket
;
struct
ucart_vrpn_tracker
*
tracker
=
NULL
;
const
char
*
logHeader
=
""
;
//"#\n#\tDefault log header\n#\tEverything after '#'`s will be printed as is in the processed logs.\n#\n\0";
...
...
@@ -96,6 +95,10 @@ int main(int argc, char **argv)
signal
(
SIGINT
,
killHandler
);
if
(
pthread_mutex_lock
(
&
quadSocketMutex
))
{
err
(
-
2
,
"pthrtead_mutex_lock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
// if ((zyboSocket = connectToZybo()) < 0)
// {
// perror("Error connecting to Zybo...");
...
...
@@ -103,12 +106,16 @@ int main(int argc, char **argv)
// free(commandBuf);
// exit(1);
// }
if
(
pthread_mutex_unlock
(
&
quadSocketMutex
))
{
err
(
-
2
,
"pthrtead_mutex_unlock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
// create vrpnTracker instance
//tracker = ucart_vrpn_tracker_createInstance(TRACKER_IP);
// open the log file
if
(
(
status
=
createLogFile
(
argc
,
argv
[
1
]))
<
0
)
if
(
createLogFile
(
argc
,
argv
[
1
]))
{
perror
(
"Error creating log file..."
);
exit
(
1
);
...
...
@@ -162,7 +169,7 @@ int main(int argc, char **argv)
fprintf
(
stdout
,
"CLI sees as: %f
\n
"
,
getFloat
(
packet
,
7
));
// Write the command to the control_loop socket
// int n = write
(zyboSocket,
packet, ((packet[6] << 8) | packet[5]) + 8);
// int n = write
Quad(
packet, ((packet[6] << 8) | packet[5]) + 8);
// if(n < 0) {
// fprintf(stdout, "CLI: ERROR writing to socket\n");
// }
...
...
@@ -180,8 +187,16 @@ int main(int argc, char **argv)
}
// ucart_vrpn_tracker_freeInstance(tracker);
if
(
pthread_mutex_lock
(
&
quadSocketMutex
))
{
err
(
-
2
,
"pthrtead_mutex_lock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
close
(
zyboSocket
);
close
(
quadlog_file
);
if
(
pthread_mutex_unlock
(
&
quadSocketMutex
))
{
err
(
-
2
,
"pthrtead_mutex_unlock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
closeLogFile
();
return
0
;
}
...
...
@@ -217,7 +232,7 @@ void sendStartPacket() {
checksum
^=
packet
[
i
];
packet
[
metadata
.
data_len
+
7
]
=
checksum
;
//PACKET_END_BYTE;
status
=
write
(
zyboSocket
,
&
packet
,
metadata
.
data_len
+
8
);
int
status
=
write
Quad
((
char
*
)
packet
,
metadata
.
data_len
+
8
);
if
(
status
!=
8
)
{
perror
(
"Error sending start packet...
\n
"
);
...
...
@@ -249,7 +264,7 @@ void sendVrpnPacket(struct ucart_vrpn_TrackerData *info) {
packet
[
pSize
-
1
]
=
checksum
;
//PACKET_END_BYTE;
n
=
write
(
zyboSocket
,
packet
,
pSize
);
n
=
write
Quad
(
packet
,
pSize
);
if
(
n
<
0
)
{
perror
(
"vrpnhandler: ERROR writing to socket"
);
keepRunning
=
0
;
...
...
@@ -284,7 +299,7 @@ int connectToZybo() {
printf
(
"Attempting to connect to zybo. Please be patient...
\n
"
);
// blocking call to connect to socket sock ie. zybo board
status
=
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
));
int
status
=
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
));
// connection failed
if
(
status
<
0
)
...
...
@@ -335,3 +350,16 @@ int safe_fd_clr(int fd, fd_set* fds, int* max_fd) {
}
return
0
;
}
static
ssize_t
writeQuad
(
const
char
*
buf
,
size_t
count
)
{
ssize_t
retval
;
if
(
pthread_mutex_lock
(
&
quadSocketMutex
))
{
err
(
-
2
,
"pthrtead_mutex_lock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
retval
=
writeQuad
(
buf
,
count
);
if
(
pthread_mutex_unlock
(
&
quadSocketMutex
))
{
err
(
-
2
,
"pthrtead_mutex_unlock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
return
retval
;
}
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