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
22e11921
Unverified
Commit
22e11921
authored
8 years ago
by
Jake Drahos
Browse files
Options
Downloads
Patches
Plain Diff
Finished implementing backend socket.
Untested
parent
37a7a58a
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/Makefile
+4
-4
4 additions, 4 deletions
groundStation/Makefile
groundStation/src/communication.c
+4
-4
4 additions, 4 deletions
groundStation/src/communication.c
groundStation/src/microcart_cli.c
+64
-9
64 additions, 9 deletions
groundStation/src/microcart_cli.c
with
72 additions
and
17 deletions
groundStation/Makefile
+
4
−
4
View file @
22e11921
# Declaration of variables
GCC
=
gcc
GXX
=
g++
CFLAGS
=
-Wall
-std
=
c99
-g
C
PP
FLAGS
=
-Wall
-std
=
c++11
-g
CFLAGS
=
-Wall
-Wpedantic
-Wextra
-Werror
-std
=
c99
-g
-Wno-unused-parameter
-Wno-unused-variable
-Wno-unused-function
C
XX
FLAGS
=
-Wall
-Wno-reorder
-std
=
c++11
-g
INCLUDES
=
$(
foreach
dir
,
$(
INCDIR
)
,
-I
$(
dir
))
# Directories
...
...
@@ -29,13 +29,13 @@ vrpn: vrpn/build
# Main target
$(EXE)
:
$(OBJECTS)
$(
GXX
)
$(
C
PP
FLAGS
)
$^
-o
$@
$(
INCLUDES
)
$(
LIBS
)
$(
GXX
)
$(
C
XX
FLAGS
)
$^
-o
$@
$(
INCLUDES
)
$(
LIBS
)
$(COBJECTS)
:
%.o : %.c
$(
GCC
)
$(
CFLAGS
)
-c
$<
-o
$@
$(
INCLUDES
)
$(
LIBS
)
$(CPPOBJECTS)
:
%.o : %.cpp
$(
G
CC
)
$(
C
PP
FLAGS
)
-c
$<
-o
$@
$(
INCLUDES
)
$(
LIBS
)
$(
G
XX
)
$(
C
XX
FLAGS
)
-c
$<
-o
$@
$(
INCLUDES
)
$(
LIBS
)
vrpn/build
:
mkdir
-p
src/vrpn/build
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/communication.c
+
4
−
4
View file @
22e11921
...
...
@@ -59,7 +59,7 @@ int formatCommand(unsigned char *command, unsigned char **formattedCommand) {
float
floatValue
=
0
.
0
;
int
intValue
=
0
;
int
valid
;
metadata_t
metadata
=
{}
;
metadata_t
metadata
;
// ----------------------------------------------
if
(
tokens
.
numTokens
>
1
)
{
...
...
@@ -78,7 +78,7 @@ int formatCommand(unsigned char *command, unsigned char **formattedCommand) {
printf
(
"%f, %s
\n
"
,
floatValue
,
tokens
.
tokens
[
1
]);
metadata
.
begin_char
=
BEGIN_CHAR
;
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
msg_type
=
registeredCommands
[
cmdIndex
].
ID
;
metadata
.
msg_subtype
=
registeredCommands
[
cmdIndex
].
subID
;
metadata
.
msg_id
=
msgNum
++
;
...
...
@@ -95,7 +95,7 @@ int formatCommand(unsigned char *command, unsigned char **formattedCommand) {
return
-
1
;
}
metadata
.
begin_char
=
BEGIN_CHAR
;
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
msg_type
=
registeredCommands
[
cmdIndex
].
ID
;
metadata
.
msg_subtype
=
registeredCommands
[
cmdIndex
].
subID
;
metadata
.
msg_id
=
msgNum
++
;
...
...
@@ -107,7 +107,7 @@ int formatCommand(unsigned char *command, unsigned char **formattedCommand) {
// Validate the string input (doesn't need to happen)
case
stringType
:
metadata
.
begin_char
=
BEGIN_CHAR
;
metadata
.
begin_char
=
(
char
)
BEGIN_CHAR
;
metadata
.
msg_type
=
registeredCommands
[
cmdIndex
].
ID
;
metadata
.
msg_subtype
=
registeredCommands
[
cmdIndex
].
subID
;
metadata
.
msg_id
=
msgNum
++
;
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/microcart_cli.c
+
64
−
9
View file @
22e11921
...
...
@@ -2,6 +2,9 @@
*
* BlueTooth socket program for passing vrpn data to quad.
*/
#define _GNU_SOURCE
//system includes
#include
<err.h>
#include
<stdio.h>
...
...
@@ -53,6 +56,8 @@ static ssize_t get_client_index(int fd);
static
char
*
get_client_buffer
(
int
fd
);
/* Returns -1 on error */
static
int
remove_client
(
int
fd
);
/* Receive data from client */
static
void
client_recv
(
int
fd
);
/* Thread-safe wrappers */
pthread_mutex_t
quadSocketMutex
;
...
...
@@ -76,7 +81,7 @@ unsigned char *respBuf, *commandBuf;
int
newQuadResponse
=
0
,
newCliInput
=
0
;
// Structures to be used throughout
modular_structs_t
structs
=
{}
;
modular_structs_t
structs
;
// Callback to be ran whenever the tracker receives data.
// Currently doing much more than it should. It will be slimmed down
...
...
@@ -207,7 +212,7 @@ int main(int argc, char **argv)
for
(
int
fd
=
0
;
fd
<=
max_fd
;
++
fd
)
{
if
(
FD_ISSET
(
fd
,
&
rfds
))
{
if
(
fd
==
fileno
(
stdin
))
{
unsigned
char
userCommand
[
CMD_MAX_LENGTH
]
=
{}
;
unsigned
char
userCommand
[
CMD_MAX_LENGTH
];
read
(
fileno
(
stdin
),
(
char
*
)
userCommand
,
sizeof
(
userCommand
));
unsigned
int
cmdLen
=
strlen
((
char
*
)
userCommand
);
// if the user simply hit enter then let them try again
...
...
@@ -246,6 +251,8 @@ int main(int argc, char **argv)
safe_fd_set
(
fd
,
&
rfds
,
&
max_fd
);
}
}
}
else
if
(
get_client_index
(
fd
)
>
-
1
)
{
client_recv
(
fd
);
}
}
}
...
...
@@ -281,7 +288,7 @@ void sendStartPacket() {
metadata_t
metadata
=
{
BEGIN_CHAR
,
(
char
)
BEGIN_CHAR
,
0x04
,
0x01
,
0x01
,
...
...
@@ -316,7 +323,7 @@ void sendStartPacket() {
void
sendVrpnPacket
(
struct
ucart_vrpn_TrackerData
*
info
)
{
int
pSize
=
sizeof
(
info
)
+
8
;
int
n
;
char
packet
[
pSize
];
unsigned
char
packet
[
pSize
];
packet
[
0
]
=
0xBE
;
// BEGIN //PACKET_START_BYTE;
packet
[
1
]
=
0x04
;
// UPDATE //'U'; // U for vrpn camera update, C for command
packet
[
2
]
=
0x00
;
// N/A
...
...
@@ -334,7 +341,7 @@ void sendVrpnPacket(struct ucart_vrpn_TrackerData *info) {
packet
[
pSize
-
1
]
=
checksum
;
//PACKET_END_BYTE;
n
=
writeQuad
(
packet
,
pSize
);
n
=
writeQuad
(
(
char
*
)
packet
,
pSize
);
if
(
n
<
0
)
{
perror
(
"vrpnhandler: ERROR writing to socket"
);
keepRunning
=
0
;
...
...
@@ -357,7 +364,7 @@ void printVrpnData(struct ucart_vrpn_TrackerData * td) {
int
connectToZybo
()
{
int
sock
;
struct
sockaddr_rc
addr
=
{
-
1
}
;
struct
sockaddr_rc
addr
;
// allocate a socket
sock
=
socket
(
AF_BLUETOOTH
,
SOCK_STREAM
,
BTPROTO_RFCOMM
);
...
...
@@ -388,8 +395,9 @@ int connectToZybo() {
void
performCommand
(
char
*
cmdName
,
char
*
command
)
{
for
(
int
i
=
0
;
i
<
NUM_COMMANDS
;
++
i
)
{
if
(
startsWith
(
registeredCommands
[
i
].
commandText
,
command
))
;
if
(
startsWith
(
registeredCommands
[
i
].
commandText
,
command
))
{
fprintf
(
stdout
,
"
\r\n
You used cmd '%s'
\n
"
,
registeredCommands
[
i
].
commandText
);
}
}
}
...
...
@@ -482,7 +490,7 @@ static int remove_client(int fd) {
char
*
clientBuffer
=
get_client_buffer
(
fd
);
if
(
clientBuffer
==
NULL
)
return
-
1
;
clientBuffer
=
'\0'
;
clientBuffer
[
0
]
=
'\0'
;
client_fds
[
slot
]
=
-
1
;
return
0
;
}
...
...
@@ -495,4 +503,51 @@ static void safe_close_fd(int fd, pthread_mutex_t *mutexLock) {
if
(
pthread_mutex_unlock
(
mutexLock
))
{
err
(
-
2
,
"pthrtead_mutex_unlock (%s:%d):"
,
__FILE__
,
__LINE__
);
}
}
\ No newline at end of file
}
static
void
client_recv
(
int
fd
)
{
char
*
buffer
;
ssize_t
len_pre
;
buffer
=
get_client_buffer
(
fd
);
len_pre
=
strlen
(
buffer
);
char
*
cursor
;
cursor
=
buffer
+
len_pre
;
ssize_t
r
;
r
=
read
(
fd
,
cursor
,
CLIENT_BUFFER_SIZE
-
len_pre
-
1
);
if
(
r
<
0
)
{
warn
(
"read (fd: %d)"
,
fd
);
}
buffer
[
len_pre
+
r
]
=
'\0'
;
/* Parse buffer and handle commands */
while
(
1
)
{
/* not using strtok because reasons */
size_t
len
=
strlen
(
buffer
);
ssize_t
newline
=
-
1
;
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
if
(
buffer
[
i
]
==
'\n'
)
{
newline
=
i
;
break
;
}
}
/* No newline found. End parsing */
if
(
newline
==
-
1
)
{
break
;
}
buffer
[
newline
]
=
'\0'
;
unsigned
char
*
packet
;
formatCommand
((
unsigned
char
*
)
buffer
,
&
packet
);
writeQuad
((
char
*
)
packet
,
packet
[
6
]
<<
8
);
free
(
packet
);
char
*
rest
=
&
buffer
[
newline
]
+
1
;
/* Delete parsed data and move the rest to the left */
memmove
(
buffer
,
rest
,
strlen
(
rest
));
}
}
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