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
f9af01ab
Commit
f9af01ab
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
Added quick data dumping ability
parent
08a39b42
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
+39
-18
39 additions, 18 deletions
groundStation/src/backend/backend.c
groundStation/src/backend/cmHandler.c
+1
-1
1 addition, 1 deletion
groundStation/src/backend/cmHandler.c
groundStation/src/backend/packet.h
+3
-0
3 additions, 0 deletions
groundStation/src/backend/packet.h
with
43 additions
and
19 deletions
groundStation/src/backend/backend.c
+
39
−
18
View file @
f9af01ab
...
...
@@ -75,6 +75,9 @@ static void client_recv(int fd);
static
void
quad_recv
();
/* Checks to see if socket has disconnected. Returns 1 on disconnect, else returns 0 */
static
int
wasDisconnected
(
int
fd
);
/* handle controller responses from quad to frontend */
static
void
handleRespcontrol
(
struct
metadata
*
m
,
uint8_t
*
data
);
/* Thread-safe wrappers */
pthread_mutex_t
quadSocketMutex
;
...
...
@@ -94,7 +97,6 @@ const char *TRACKER_IP = "UAV@192.168.0.120:3883";
static
int
zyboSocket
;
static
int
backendSocket
;
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";
#define MAX_CLIENTS 32
#define CLIENT_BUFFER_SIZE 1024
...
...
@@ -105,6 +107,8 @@ static int client_pending_responses[MAX_CLIENTS][CLIENT_MAX_PENDING_RESPONSES];
fd_set
rfds_master
;
int
max_fd
=
0
;
static
FILE
*
quadlog_file
;
pthread_mutex_t
quadResponseMutex
,
cliInputMutex
;
unsigned
char
*
commandBuf
;
int
newQuadResponse
=
0
,
newCliInput
=
0
;
...
...
@@ -128,6 +132,7 @@ int main(int argc, char **argv)
{
int
activity
;
FD_ZERO
(
&
rfds_master
);
char
log_file
[
256
]
=
"logs/"
;
/*
* Create backend listening socket
...
...
@@ -195,8 +200,36 @@ int main(int argc, char **argv)
if
(
!
getenv
(
NOQUAD_ENV
))
{
// watch for input from the zybo socket
safe_fd_set
(
zyboSocket
,
&
rfds_master
,
&
max_fd
);
}
if
(
argc
>=
2
)
{
strncat
(
log_file
,
argv
[
1
],
strlen
(
argv
[
1
]));
}
else
{
time_t
rawtime
;
char
timestr
[
30
];
time
(
&
rawtime
);
sprintf
(
timestr
,
"%s"
,
ctime
(
&
rawtime
));
// Lets convert space to _ in
char
*
p
=
timestr
;
size_t
i
=
0
;
while
(
i
<
strlen
(
timestr
))
{
if
(
*
p
==
' '
)
*
p
=
'_'
;
i
++
;
p
++
;
}
// timestr has a weird char at the end of it.
// we will not include it in our file name
strncat
(
log_file
,
timestr
,
strlen
(
timestr
)
-
1
);
strcat
(
log_file
,
".txt"
);
}
printf
(
"Creating log file '%s'...
\n
"
,
log_file
);
quadlog_file
=
fopen
(
log_file
,
"a"
);
// Tell the quad we are ready to send it vrpn data
sendStartPacket
();
...
...
@@ -258,6 +291,7 @@ int main(int argc, char **argv)
ucart_vrpn_tracker_freeInstance
(
tracker
);
safe_close_fd
(
zyboSocket
,
&
quadSocketMutex
);
fclose
(
quadlog_file
);
return
0
;
}
...
...
@@ -633,7 +667,7 @@ static void quad_recv() {
struct
metadata
m
;
uint8_t
data
[
1024
];
size_t
respLen
;
size_t
datalen
;
s
size_t
datalen
;
size_t
packetlen
;
respLen
=
readQuad
((
char
*
)
respBuf
+
respBufLen
,
...
...
@@ -654,19 +688,6 @@ static void quad_recv() {
memmove
(
respBuf
,
respBuf
+
packetlen
,
respBufLen
-
packetlen
);
respBufLen
-=
packetlen
;
/*
DEBUG_ID, // 00
PACKETLOG_ID, // 01
GETPACKETLOGS_ID, // 02
UPDATE_ID, // 03
BEGINUPDATE_ID, // 04
LOG_ID, // 05
RESPONSE_ID, // 06
SETCONTROL_ID, // 07 - Setting controller values. Example: PID constants
GETCONTROL_ID, // 08 - Getting controller values. Example: PID constants
RESPCONTROL_ID, // 09 - Responding with controller values. Example: PID constants
MAX_TYPE_ID
*/
switch
(
m
.
msg_type
)
{
case
DEBUG_ID
:
case
PACKETLOG_ID
:
...
...
@@ -677,7 +698,7 @@ static void quad_recv() {
break
;
case
LOG_ID
:
/* something like this */
log_
write
((
char
*
)
data
,
m
.
data_len
);
f
write
((
char
*
)
data
,
sizeof
(
char
),
m
.
data_len
,
quadlog_file
);
break
;
case
RESPONSE_ID
:
case
SETCONTROL_ID
:
...
...
@@ -696,13 +717,13 @@ static void handleRespcontrol(struct metadata *m, uint8_t * data)
{
struct
controller_message
cm
;
if
(
DecodeRespcontrol
(
&
cm
,
m
,
data
)
<
0
)
{
warnx
(
"DecodeRespcontrol error"
)
warnx
(
"DecodeRespcontrol error"
)
;
return
;
}
char
buffer
[
128
];
char
*
message
=
cmToString
(
RESPCONTROL_ID
,
&
cm
);
const
char
*
message
=
cmToString
(
RESPCONTROL_ID
,
&
cm
);
size_t
len
=
snprintf
(
buffer
,
128
,
"%s %f
\n
"
,
message
,
cm
.
value
);
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/cmHandler.c
+
1
−
1
View file @
f9af01ab
...
...
@@ -70,7 +70,7 @@ const char * respContStrings[MAX_COMMANDS] {
"getheightp"
,
"getheighti"
,
"getheightd"
,
"getheight"
,
"getheight"
}
const
char
*
cmToString
(
int
msgType
,
const
struct
controller_message
*
cm
)
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/packet.h
+
3
−
0
View file @
f9af01ab
...
...
@@ -33,4 +33,7 @@ ssize_t DecodePacket(
/* Compute a checksum. Requires a packet and the entire packet length */
uint8_t
PacketChecksum
(
const
uint8_t
*
packet
,
size_t
);
/* Compute the size of the entire packet */
size_t
PacketSize
(
const
struct
metadata
*
m
);
#endif
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