Skip to content

Commit

Permalink
Fix bug on client.available() to retrun the number of bytes available…
Browse files Browse the repository at this point in the history
… on client connection
  • Loading branch information
mlafauci committed Mar 10, 2013
1 parent c308efc commit bbc40ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions firmware/wifiHD/src/ard_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,13 +1204,13 @@ cmd_spi_state_t avail_data_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16
CHECK_ARD_NETIF(recv, reply, count);

CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_1);
uint8_t dataAvail = 0;
uint16_t dataAvail = 0;
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
{
dataAvail = isAvailTcpDataByte((uint8_t)recv[4]) ? 1 : 0;
dataAvail = getAvailTcpDataByte((uint8_t)recv[4]);
}
PUT_DATA_BYTE(dataAvail, reply, 3);
END_HEADER_REPLY(reply, 5, *count);
PUT_DATA_INT_NO(dataAvail, reply, 3);
END_HEADER_REPLY(reply, 6, *count);

INFO_SPI_POLL("dataAvail:%d\n", dataAvail);

Expand Down
6 changes: 6 additions & 0 deletions firmware/wifiHD/src/ard_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ bool isAvailTcpDataByte(uint8_t sock)
return false;
}

uint16_t getAvailTcpDataByte(uint8_t sock)
{
uint16_t len = calcMergeLen(sock);
INFO_UTIL("Availabled data: %d\n", len);
return len;
}


bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek)
Expand Down
14 changes: 12 additions & 2 deletions firmware/wifiHD/src/ard_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@
BYTE[IDX+2] = (uint8_t)(_int & 0xff); \
}

#define PUT_DATA_INT_NO(INT, BYTE, IDX) { \
uint16_t _int = INT; \
BYTE[IDX] = 2; \
BYTE[IDX+2] = (uint8_t)((_int & 0xff00)>>8); \
BYTE[IDX+1] = (uint8_t)(_int & 0xff); \
}

#define PUT_DATA_BYTE(DATA, BYTE, IDX) { \
BYTE[IDX] = 1; \
BYTE[IDX+1] = (uint8_t)DATA; \
Expand Down Expand Up @@ -235,9 +242,10 @@
#endif

#define DUMP_TCP_STATE(TTCP) do {\
INFO_TCP("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d\n", \
INFO_TCP("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d left:%d sent:%d\n", \
TTCP, TTCP->tpcb[0], (TTCP->tpcb[0])?TTCP->tpcb[0]->state:0, \
TTCP->lpcb, (TTCP->lpcb)?TTCP->lpcb->state:0); \
TTCP->lpcb, (TTCP->lpcb)?TTCP->lpcb->state:0, \
(TTCP)?TTCP->left:0, (TTCP)?TTCP->buff_sent:0); \
} while(0);

#define Mode2Str(_Mode) ((_Mode==0)?"TRANSMIT":"RECEIVE")
Expand Down Expand Up @@ -275,6 +283,8 @@ bool getTcpData(uint8_t sock, void** payload, uint16_t* len);

bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek);

uint16_t getAvailTcpDataByte(uint8_t sock);

bool isAvailTcpDataByte(uint8_t sock);

uint8_t freeTcpData(uint8_t sock);
Expand Down

1 comment on commit bbc40ea

@salanki
Copy link

@salanki salanki commented on bbc40ea Jun 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be causing issues using this firmware with the default libraries in 1.0.5 (or the library from this branch). When using this in a server it will always return a string end '\0' at the end of each data segment, which is not what came in over the wire.

Please sign in to comment.