Skip to content
Snippets Groups Projects
Commit 9a6a3a6c authored by burneykb's avatar burneykb
Browse files

Implemented and tested clientRemovePendRespons

parent b26afcdf
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@
#include "cmHandler.h"
#include "getparam.h"
#include "setparam.h"
#include "bitwise.h"
#define QUAD_BT_ADDR "00:06:66:64:61:D6"
#define QUAD_BT_CHANNEL 0x01
......@@ -69,7 +70,9 @@ static char * get_client_buffer(int fd);
/* Return pointer to client pending responses, or -1*/
static int * get_client_pend_responses(int fd);
/* 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 */
static int remove_client(int fd);
/* Receive data from client */
......@@ -535,12 +538,22 @@ static int * get_client_pend_responses(int fd) {
}
}
static int clientAddPendResponses(int fd, unsigned char *packet) {
static int clientAddPendResponses(int fd, uint16_t packet_id) {
int *pendingResponses = get_client_pend_responses(fd);
int packetID = (packet[4] << 8) | (packet[3]);
for(int i = 0; i < CLIENT_MAX_PENDING_RESPONSES; i++) {
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;
}
}
......@@ -679,7 +692,7 @@ static void client_recv(int fd) {
/* Only add the client to the pending responses if it was a getparam command */
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");
}
}
......@@ -700,7 +713,6 @@ static void quad_recv() {
static unsigned char respBuf[4096];
static size_t respBufLen;
int unfinished = 1;
struct metadata m;
uint8_t data[4096];
size_t respLen;
......@@ -721,7 +733,7 @@ static void quad_recv() {
// }
// printf("'\n");
while(unfinished){
while(respBufLen){
datalen = DecodePacket(&m, data, 2048, respBuf, respBufLen);
if (datalen == -1) {
......@@ -770,9 +782,6 @@ static void quad_recv() {
default:
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)
for(int fd = 0; fd <= max_fd; ++fd) {
if (get_client_index(fd) > -1) {
clientRemovePendResponses(fd, m->msg_id);
write(fd, buffer, len);
}
}
......
......@@ -4,21 +4,6 @@
#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.
* Returns the size of the encoded packet
......
......@@ -4,6 +4,21 @@
#include <stdint.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 {
int msg_type;
int msg_id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment