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
a2a41819
Commit
a2a41819
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
first go at the local socket virt-quad test system
parent
38e74b24
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
groundStation/src/backend/backend.c
+35
-15
35 additions, 15 deletions
groundStation/src/backend/backend.c
groundStation/src/backend/config.h
+4
-1
4 additions, 1 deletion
groundStation/src/backend/config.h
quad/src/virt_quad/hw_impl_unix_uart.c
+52
-2
52 additions, 2 deletions
quad/src/virt_quad/hw_impl_unix_uart.c
with
91 additions
and
18 deletions
groundStation/src/backend/backend.c
+
35
−
15
View file @
a2a41819
...
...
@@ -341,28 +341,48 @@ void printVrpnData(struct ucart_vrpn_TrackerData * td) {
int
connectToZybo
()
{
int
sock
;
int
status
=
0
;
int
status
=
-
1
;
if
(
getenv
(
NOQUAD_ENV
))
{
return
0
;
}
/* Use bluetooth by default */
if
(
!
getenv
(
QUAD_WIFI_ENV
))
{
printf
(
"Using BT Settings
\n
"
);
struct
sockaddr_rc
addr
;
/* Use wifi by default */
if
(
getenv
(
QUAD_COMM_ENV
))
{
/* Determine if we are using bluetooth or local */
if
(
strcmp
(
getenv
(
QUAD_COMM_ENV
),
"local"
)
==
0
)
{
printf
(
"Using Local Socket Settings
\n
"
);
struct
sockaddr_un
remote
;
char
str
[
100
];
if
((
sock
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
))
==
-
1
)
{
perror
(
"socket"
);
exit
(
1
);
}
// allocate a socket
sock
=
socket
(
AF_BLUETOOTH
,
SOCK_STREAM
,
BTPROTO_RFCOMM
);
remote
.
sun_family
=
AF_UNIX
;
char
*
sock_env
=
getenv
(
QUAD_LOCAL_SOCKET
);
strcpy
(
remote
.
sun_path
,
sock_env
?
sock_env
:
QUAD_DEFAULT_LOCAL_SOCKET
);
printf
(
"Attempting to connect to local socket at '%s'. please be patiend.
\n
"
,
remote
.
sun_path
);
//set the connection params ie. who to connect to
addr
.
rc_family
=
AF_BLUETOOTH
;
addr
.
rc_channel
=
(
uint8_t
)
QUAD_BT_CHANNEL
;
str2ba
(
QUAD_BT_ADDR
,
&
addr
.
rc_bdaddr
);
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
));
status
=
connect
(
sock
,
(
struct
sockaddr
*
)
&
remote
,
sizeof
(
remote
));
}
else
if
(
strcmp
(
getenv
(
QUAD_COMM_ENV
),
"bluetooth"
)
==
0
)
{
printf
(
"Using BT Settings
\n
"
);
struct
sockaddr_rc
addr
;
// allocate a socket
sock
=
socket
(
AF_BLUETOOTH
,
SOCK_STREAM
,
BTPROTO_RFCOMM
);
//set the connection params ie. who to connect to
addr
.
rc_family
=
AF_BLUETOOTH
;
addr
.
rc_channel
=
(
uint8_t
)
QUAD_BT_CHANNEL
;
str2ba
(
QUAD_BT_ADDR
,
&
addr
.
rc_bdaddr
);
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
));
}
}
else
{
printf
(
"Using WIFI settings
\n
"
);
struct
sockaddr_in
addr
;
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/config.h
+
4
−
1
View file @
a2a41819
...
...
@@ -11,7 +11,10 @@
// If you are planning on using any of these env vars and you have
// exported them with normal user rights. You will need to run the
// backend with sudo elevation and with the --preserve-env flag or -E
#define QUAD_WIFI_ENV "UCART_USE_WIFI"
#define QUAD_COMM_ENV "UCART_COMM_CHANNEL"
#define QUAD_DEFAULT_LOCAL_SOCKET "./virtquad.socket"
#define QUAD_LOCAL_SOCKET "UCART_LOCAL_SOCKET"
#define QUAD_IP_ENV "UCART_QUAD_IP"
#define QUAD_IP_DEFAULT "192.168.1.1"
#define QUAD_PORT_ENV "UCART_QUAD_PORT"
...
...
This diff is collapsed.
Click to expand it.
quad/src/virt_quad/hw_impl_unix_uart.c
+
52
−
2
View file @
a2a41819
#include
"hw_impl_unix.h"
#include
<sys/types.h>
#include
<sys/socket.h>
#include
<stdio.h>
#include
<sys/un.h>
#include
<err.h>
#include
<netinet/in.h>
#define DEFAULT_SOCKET "../../groundStation/virtquad.socket"
#define SOCKET_ENV "VIRT_QUAD_SOCKET"
static
int
backendSocket
;
static
int
sendSocket
;
int
unix_uart_reset
(
struct
UARTDriver
*
self
)
{
char
*
backend_socket_path
=
DEFAULT_SOCKET
;
if
(
getenv
(
SOCKET_ENV
))
{
backend_socket_path
=
getenv
(
SOCKET_ENV
);
}
/* Unlink if it exists */
unlink
(
backend_socket_path
);
printf
(
"using socket at '%s'
\n
"
,
backend_socket_path
);
/* Create socket */
backendSocket
=
socket
(
AF_UNIX
,
SOCK_STREAM
|
SOCK_NONBLOCK
,
0
);
/* Create sockaddr and bind */
struct
sockaddr_un
sa
;
sa
.
sun_family
=
AF_UNIX
;
strncpy
(
sa
.
sun_path
,
backend_socket_path
,
107
);
sa
.
sun_path
[
107
]
=
'\0'
;
if
(
bind
(
backendSocket
,
(
struct
sockaddr
*
)
&
sa
,
sizeof
(
sa
)))
{
err
(
-
1
,
"bind"
);
}
/* Listen */
if
(
listen
(
backendSocket
,
1
))
{
err
(
-
1
,
"listen"
);
}
while
(
1
)
{
sendSocket
=
accept
(
backendSocket
,
NULL
,
NULL
);
if
(
sendSocket
>
0
)
break
;
}
printf
(
" accpet() returned with %d
\n
"
,
sendSocket
);
return
0
;
}
int
unix_uart_write
(
struct
UARTDriver
*
self
,
unsigned
char
c
)
{
return
0
;
printf
(
"sending %c
\n
"
,
c
);
return
send
(
sendSocket
,
&
c
,
1
,
0
);
}
int
unix_uart_read
(
struct
UARTDriver
*
self
,
unsigned
char
*
c
)
{
return
0
;
int
bytes
=
read
(
sendSocket
,
c
,
1
);
printf
(
"read in %d byte [%x], msg=%d
\n
"
,
bytes
,
*
c
,
self
->
msg
);
return
bytes
;
}
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