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
2a85dc87
Commit
2a85dc87
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
vrpn sending works with joe's new command structure
parent
efbc858d
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
+23
-10
23 additions, 10 deletions
groundStation/src/backend/backend.c
groundStation/src/backend/bitwise.h
+1
-1
1 addition, 1 deletion
groundStation/src/backend/bitwise.h
groundStation/src/backend/packet.c
+15
-9
15 additions, 9 deletions
groundStation/src/backend/packet.c
with
39 additions
and
20 deletions
groundStation/src/backend/backend.c
+
23
−
10
View file @
2a85dc87
...
...
@@ -231,9 +231,11 @@ int main(int argc, char **argv)
quadlog_file
=
fopen
(
log_file
,
"a"
);
// Tell the quad we are ready to send it vrpn data
sendStartPacket
();
if
(
!
getenv
(
NOVRPN_ENV
)){
// create vrpnTracker instance
tracker
=
ucart_vrpn_tracker_createInstance
(
TRACKER_IP
);
...
...
@@ -306,11 +308,12 @@ void sendStartPacket() {
ssize_t
psize
;
if
((
psize
=
EncodePacket
(
packet
,
64
,
&
m
,
NULL
))
<
0
)
{
warnx
(
"Big problems"
);
warnx
(
"Big problems
. sendStartPacket
"
);
return
;
}
writeQuad
(
packet
,
psize
);
printf
(
"Start Packet sent...
\n
"
);
}
void
sendVrpnPacket
(
struct
ucart_vrpn_TrackerData
*
info
)
{
...
...
@@ -327,15 +330,15 @@ void sendVrpnPacket(struct ucart_vrpn_TrackerData *info) {
u
.
roll
=
info
->
roll
;
u
.
yaw
=
info
->
yaw
;
if
(
EncodeUpdate
(
&
m
,
data
,
128
,
&
u
))
{
warnx
(
"Big problems"
);
if
(
EncodeUpdate
(
&
m
,
data
,
128
,
&
u
)
<
0
)
{
warnx
(
"Big problems
. sendVrpnPacket . EncodeUpdate
"
);
return
;
}
m
.
msg_id
=
currMessageID
++
;
ssize_t
psize
;
if
((
psize
=
EncodePacket
(
packet
,
64
,
&
m
,
data
))
<
0
)
{
warnx
(
"Big problems"
);
warnx
(
"Big problems
. sendVrpnPacket. EncodePacket
"
);
return
;
}
...
...
@@ -671,28 +674,38 @@ static void client_recv(int fd) {
}
static
void
quad_recv
()
{
static
unsigned
char
respBuf
[
2048
];
static
unsigned
char
respBuf
[
4096
];
static
size_t
respBufLen
;
struct
metadata
m
;
uint8_t
data
[
1024
];
uint8_t
data
[
4096
];
size_t
respLen
;
ssize_t
datalen
;
size_t
packetlen
;
respLen
=
readQuad
((
char
*
)
respBuf
+
respBufLen
,
CMD_MAX_LENGTH
-
respBufLen
);
CMD_MAX_LENGTH
-
respBufLen
);
if
(
respLen
<=
0
)
{
perror
(
"ERROR reading from quad...
\n
"
);
return
;
}
respBufLen
+=
respLen
;
if
((
datalen
=
DecodePacket
(
&
m
,
data
,
1024
,
respBuf
,
respBufLen
))
<
0
)
{
warnx
(
"Packet format error"
);
datalen
=
DecodePacket
(
&
m
,
data
,
2048
,
respBuf
,
respBufLen
);
if
(
datalen
==
-
1
)
{
warnx
(
"No start Byte!
\n
"
);
respBufLen
=
0
;
return
;
}
if
(
datalen
==
-
5
)
{
warnx
(
"Chechsum mismatch!
\n
"
);
respBufLen
=
0
;
return
;
}
if
(
datalen
<
0
){
/* Not enough data yet. We need to wait for more */
return
;
}
packetlen
=
PacketSize
(
&
m
);
memmove
(
respBuf
,
respBuf
+
packetlen
,
respBufLen
-
packetlen
);
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/bitwise.h
+
1
−
1
View file @
2a85dc87
...
...
@@ -9,7 +9,7 @@
#define MSByte16(x) (((x) >> 8) & 0xff)
/* Build a 16-bit integer out of two bytes */
#define BytesTo16(lsb, msb) (((lsb) & 0xff) | (((msb)
<< 8)
& 0xff))
#define BytesTo16(lsb, msb) (((lsb) & 0xff) | (((msb) & 0xff
) << 8
))
/* Same for 32bit */
#define IntByte1(x) ((x) & 0xff)
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/packet.c
+
15
−
9
View file @
2a85dc87
...
...
@@ -61,37 +61,43 @@ ssize_t DecodePacket(
const
uint8_t
*
packet
,
/* Packet to decode */
size_t
packet_size
)
/* Size of packet to decode */
{
uint8_t
checkSum
;
if
(
packet
[
BEGIN
]
!=
BEGIN_CHAR
)
{
return
-
1
;
}
if
(
packet_size
<
((
uint8_t
)
HDR_SIZE
+
CSUM_SIZE
))
{
return
-
1
;
return
-
2
;
}
m
->
msg_type
=
BytesTo16
(
packet
[
MTYPE_L
],
packet
[
MTYPE_H
]);
m
->
msg_id
=
BytesTo16
(
packet
[
ID_L
],
packet
[
ID_H
]);
m
->
data_len
=
BytesTo16
(
packet
[
DLEN_L
],
packet
[
DLEN_H
]);
m
->
data_len
=
BytesTo16
(
packet
[
DLEN_L
],
packet
[
DLEN_H
]);
if
(
packet_size
<
(
HDR_SIZE
+
CSUM_SIZE
+
m
->
data_len
))
{
return
-
1
;
return
-
3
;
}
if
(
data_size
<
m
->
data_len
)
{
return
-
1
;
return
-
4
;
}
memcpy
(
data
,
&
packet
[
HDR_SIZE
],
m
->
data_len
);
checkSum
=
PacketChecksum
(
packet
,
packet_size
);
if
(
checkSum
!=
packet
[
HDR_SIZE
+
m
->
data_len
])
{
return
-
5
;
}
/* Validate checksum */
/* TODO */
memcpy
(
data
,
&
packet
[
HDR_SIZE
],
m
->
data_len
);
return
m
->
data_len
;
}
uint8_t
PacketChecksum
(
const
uint8_t
*
packet
,
size_t
packet_size
)
{
/* TODO implement */
return
42
;
uint8_t
checkSum
=
0
;
for
(
size_t
i
=
0
;
i
<
packet_size
-
CSUM_SIZE
;
i
++
){
checkSum
^=
packet
[
i
];
}
return
checkSum
;
}
size_t
PacketSize
(
const
struct
metadata
*
m
)
...
...
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