Skip to content

Commit e477d8c

Browse files
committed
Fixed issu con client.available to return the correct number of bytes
1 parent cc8291e commit e477d8c

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

firmwares/wifishield/wifiHD/src/ard_spi.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,8 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
326326
{
327327
uint16_t _len = 0;
328328
unsigned short dummy=0;
329-
bool streamExit = false;
330329

331330
do {
332-
if (*stream == END_CMD)
333-
streamExit = true;
334-
335331
//SIGN1_DN();
336332
if (spi_write(spi, *stream) == SPI_ERROR_TIMEOUT)
337333
{
@@ -350,16 +346,7 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
350346
spi_read(spi,&dummy);
351347
}
352348
//SIGN1_UP();
353-
}while ((!streamExit)&&(_len <= len));
354-
355-
if (!streamExit)
356-
{
357-
#ifdef _SPI_STATS_
358-
statSpi.wrongFrame++;
359-
statSpi.lastError = SPI_ERROR_ARGUMENT;
360-
#endif
361-
return SPI_ERROR_ARGUMENT;
362-
}
349+
}while (_len < len);
363350
return SPI_OK;
364351
}
365352

@@ -1640,6 +1627,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
16401627
int index = 0;
16411628
int err = SPI_OK;
16421629
state = SPI_CMD_INPUT;
1630+
bool endOfFrame = false;
16431631

16441632
do {
16451633
unsigned int timeout = SPI_TIMEOUT;
@@ -1680,7 +1668,31 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
16801668
err = SPI_ERROR_OVERRUN_AND_MODE_FAULT;
16811669
break;
16821670
}
1683-
} while (_receiveBuffer[index - 1] != END_CMD);
1671+
1672+
if (_receiveBuffer[index - 1] == END_CMD)
1673+
{
1674+
int8_t numParams = 0;
1675+
int idx = PARAM_LEN_POS+1;
1676+
bool islen16bit = _receiveBuffer[CMD_POS] & DATA_FLAG;
1677+
if (index >= idx)
1678+
{
1679+
numParams = _receiveBuffer[PARAM_LEN_POS];
1680+
while (((index-1) > idx)&&(numParams>0))
1681+
{
1682+
if (islen16bit)
1683+
idx += (_receiveBuffer[idx]<<8) + _receiveBuffer[idx+1]+2;
1684+
else
1685+
idx += _receiveBuffer[idx]+1;
1686+
--numParams;
1687+
}
1688+
if (((index-1) == idx) && (numParams == 0))
1689+
endOfFrame = true;
1690+
}
1691+
if (!endOfFrame){
1692+
WARN("Wrong termination index:%d nParam:%d idx:%d 16bit:%d\n", index, numParams, idx, islen16bit);
1693+
}
1694+
}
1695+
} while (!endOfFrame);
16841696
return err;
16851697
}
16861698

firmwares/wifishield/wifiHD/src/ard_utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ uint16_t calcMergeLen(uint8_t sock)
7878
if (pBufStore[index][sock].data != NULL)
7979
{
8080
len += pBufStore[index][sock].len;
81+
len -= pBufStore[index][sock].idx;
82+
INFO_UTIL_VER(" [%d]: len:%d idx:%d tot:%d\n", sock, pBufStore[index][sock].len, pBufStore[index][sock].idx, len);
8183
}
8284
++index;
8385
if (index == MAX_PBUF_STORED)

firmwares/wifishield/wifiHD/src/wifi_spi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define START_CMD 0xE0
2525
#define END_CMD 0xEE
2626
#define ERR_CMD 0xEF
27+
#define CMD_POS 1 // Position of Command OpCode on SPI stream
28+
#define PARAM_LEN_POS 2 // Position of Param len on SPI stream
2729

2830
enum {
2931
SET_NET_CMD = 0x10,

0 commit comments

Comments
 (0)