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
9a6a3a6c
Commit
9a6a3a6c
authored
8 years ago
by
burneykb
Browse files
Options
Downloads
Patches
Plain Diff
Implemented and tested clientRemovePendRespons
parent
b26afcdf
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
+20
-10
20 additions, 10 deletions
groundStation/src/backend/backend.c
groundStation/src/backend/packet.c
+0
-15
0 additions, 15 deletions
groundStation/src/backend/packet.c
groundStation/src/backend/packet.h
+15
-0
15 additions, 0 deletions
groundStation/src/backend/packet.h
with
35 additions
and
25 deletions
groundStation/src/backend/backend.c
+
20
−
10
View file @
9a6a3a6c
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include
"cmHandler.h"
#include
"cmHandler.h"
#include
"getparam.h"
#include
"getparam.h"
#include
"setparam.h"
#include
"setparam.h"
#include
"bitwise.h"
#define QUAD_BT_ADDR "00:06:66:64:61:D6"
#define QUAD_BT_ADDR "00:06:66:64:61:D6"
#define QUAD_BT_CHANNEL 0x01
#define QUAD_BT_CHANNEL 0x01
...
@@ -69,7 +70,9 @@ static char * get_client_buffer(int fd);
...
@@ -69,7 +70,9 @@ static char * get_client_buffer(int fd);
/* Return pointer to client pending responses, or -1*/
/* Return pointer to client pending responses, or -1*/
static
int
*
get_client_pend_responses
(
int
fd
);
static
int
*
get_client_pend_responses
(
int
fd
);
/* Return positive integer if successful, -1 otherwise */
/* Return positive integer if successful, -1 otherwise */
static
int
clientAddPendResponses
(
int
fd
,
unsigned
char
*
packet
);
static
int
clientAddPendResponses
(
int
fd
,
uint16_t
packet_id
);
/* Return positive integer if successful, -1 otherwise */
static
int
clientRemovePendResponses
(
int
fd
,
uint16_t
packet_id
);
/* Returns -1 on error */
/* Returns -1 on error */
static
int
remove_client
(
int
fd
);
static
int
remove_client
(
int
fd
);
/* Receive data from client */
/* Receive data from client */
...
@@ -535,12 +538,22 @@ static int * get_client_pend_responses(int fd) {
...
@@ -535,12 +538,22 @@ static int * get_client_pend_responses(int fd) {
}
}
}
}
static
int
clientAddPendResponses
(
int
fd
,
u
nsigned
char
*
packet
)
{
static
int
clientAddPendResponses
(
int
fd
,
u
int16_t
packet
_id
)
{
int
*
pendingResponses
=
get_client_pend_responses
(
fd
);
int
*
pendingResponses
=
get_client_pend_responses
(
fd
);
int
packetID
=
(
packet
[
4
]
<<
8
)
|
(
packet
[
3
]);
for
(
int
i
=
0
;
i
<
CLIENT_MAX_PENDING_RESPONSES
;
i
++
)
{
for
(
int
i
=
0
;
i
<
CLIENT_MAX_PENDING_RESPONSES
;
i
++
)
{
if
(
pendingResponses
[
i
]
==
-
1
)
{
if
(
pendingResponses
[
i
]
==
-
1
)
{
pendingResponses
[
i
]
=
packetID
;
pendingResponses
[
i
]
=
packet_id
;
return
i
;
}
}
return
-
1
;
}
static
int
clientRemovePendResponses
(
int
fd
,
uint16_t
packet_id
)
{
int
*
pendingResponses
=
get_client_pend_responses
(
fd
);
for
(
int
i
=
0
;
i
<
CLIENT_MAX_PENDING_RESPONSES
;
i
++
)
{
if
(
pendingResponses
[
i
]
==
packet_id
)
{
pendingResponses
[
i
]
=
-
1
;
return
i
;
return
i
;
}
}
}
}
...
@@ -679,7 +692,7 @@ static void client_recv(int fd) {
...
@@ -679,7 +692,7 @@ static void client_recv(int fd) {
/* Only add the client to the pending responses if it was a getparam command */
/* Only add the client to the pending responses if it was a getparam command */
if
(
m
.
msg_type
==
GETPARAM_ID
)
{
if
(
m
.
msg_type
==
GETPARAM_ID
)
{
if
(
clientAddPendResponses
(
fd
,
packet
)
==
-
1
)
{
if
(
clientAddPendResponses
(
fd
,
BytesTo16
(
packet
[
ID_L
],
packet
[
ID_H
])
)
==
-
1
)
{
warnx
(
"Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!
\n
"
);
warnx
(
"Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!
\n
"
);
}
}
}
}
...
@@ -700,7 +713,6 @@ static void quad_recv() {
...
@@ -700,7 +713,6 @@ static void quad_recv() {
static
unsigned
char
respBuf
[
4096
];
static
unsigned
char
respBuf
[
4096
];
static
size_t
respBufLen
;
static
size_t
respBufLen
;
int
unfinished
=
1
;
struct
metadata
m
;
struct
metadata
m
;
uint8_t
data
[
4096
];
uint8_t
data
[
4096
];
size_t
respLen
;
size_t
respLen
;
...
@@ -721,7 +733,7 @@ static void quad_recv() {
...
@@ -721,7 +733,7 @@ static void quad_recv() {
// }
// }
// printf("'\n");
// printf("'\n");
while
(
unfinished
){
while
(
respBufLen
){
datalen
=
DecodePacket
(
&
m
,
data
,
2048
,
respBuf
,
respBufLen
);
datalen
=
DecodePacket
(
&
m
,
data
,
2048
,
respBuf
,
respBufLen
);
if
(
datalen
==
-
1
)
{
if
(
datalen
==
-
1
)
{
...
@@ -770,9 +782,6 @@ static void quad_recv() {
...
@@ -770,9 +782,6 @@ static void quad_recv() {
default:
default:
printf
(
"(Backend): message type %d unrecognized
\n
"
,
m
.
msg_type
);
printf
(
"(Backend): message type %d unrecognized
\n
"
,
m
.
msg_type
);
}
}
if
(
respBufLen
==
0
)
{
unfinished
=
0
;
}
}
}
}
}
...
@@ -793,6 +802,7 @@ static void handleResponseParam(struct metadata *m, uint8_t * data)
...
@@ -793,6 +802,7 @@ static void handleResponseParam(struct metadata *m, uint8_t * data)
for
(
int
fd
=
0
;
fd
<=
max_fd
;
++
fd
)
{
for
(
int
fd
=
0
;
fd
<=
max_fd
;
++
fd
)
{
if
(
get_client_index
(
fd
)
>
-
1
)
{
if
(
get_client_index
(
fd
)
>
-
1
)
{
clientRemovePendResponses
(
fd
,
m
->
msg_id
);
write
(
fd
,
buffer
,
len
);
write
(
fd
,
buffer
,
len
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/packet.c
+
0
−
15
View file @
9a6a3a6c
...
@@ -4,21 +4,6 @@
...
@@ -4,21 +4,6 @@
#include
<string.h>
#include
<string.h>
enum
PacketHeader
{
BEGIN
,
MTYPE_L
,
MTYPE_H
,
ID_L
,
ID_H
,
DLEN_L
,
DLEN_H
,
HDR_SIZE
};
enum
ChecksumFormat
{
CSUM_L
,
CSUM_SIZE
};
/* Combine metadata and data to form a wire-sendable packet.
/* Combine metadata and data to form a wire-sendable packet.
* Returns the size of the encoded packet
* Returns the size of the encoded packet
...
...
This diff is collapsed.
Click to expand it.
groundStation/src/backend/packet.h
+
15
−
0
View file @
9a6a3a6c
...
@@ -4,6 +4,21 @@
...
@@ -4,6 +4,21 @@
#include
<stdint.h>
#include
<stdint.h>
#include
<sys/types.h>
#include
<sys/types.h>
enum
PacketHeader
{
BEGIN
,
MTYPE_L
,
MTYPE_H
,
ID_L
,
ID_H
,
DLEN_L
,
DLEN_H
,
HDR_SIZE
};
enum
ChecksumFormat
{
CSUM_L
,
CSUM_SIZE
};
struct
metadata
{
struct
metadata
{
int
msg_type
;
int
msg_type
;
int
msg_id
;
int
msg_id
;
...
...
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