1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-15 12:29:26 +01:00

Fixed issue with WiFiWebClient, WiFiPachubeClient, WiFiTwitterClient

This commit is contained in:
Mimmo La Fauci 2012-03-13 12:21:54 +01:00
parent c487d387ce
commit f8817eec89
11 changed files with 112 additions and 32 deletions

Binary file not shown.

Binary file not shown.

View File

@ -89,7 +89,7 @@ bool end_write = false; //TODO only for debug
// Signal indicating a new command is coming from SPI interface
static volatile Bool startRecvCmdSignal = FALSE;
#define MAX_CMD_NUM 25
#define MAX_CMD_NUM 30
typedef struct sCmd_spi_list{
cmd_spi_cb_t cb;
char cmd_id;
@ -361,8 +361,27 @@ void dump(char* _buf, uint16_t _count) {
#endif
}
#ifdef _APP_DEBUG_
#define DUMP_SPI_DATA(BUF, COUNT) do { \
if (verboseDebug & INFO_SPI_FLAG) { \
int i = 0; \
for (; i < COUNT; ++i) \
{ \
printk("0x%x ", BUF[i]); \
if (i % 20 == 0) \
printk("\n"); \
} \
printk("\n"); \
} \
}while(0);
#else
#define DUMP_SPI_DATA(BUF, COUNT) do {}while(0);
#endif
#ifdef _APP_DEBUG_
#define DUMP_SPI_CMD(BUF) do { \
if (verboseDebug & INFO_SPI_FLAG) { \
int i = 0; \
for (; i < CMD_MAX_LEN; ++i) \
{ \
@ -371,6 +390,7 @@ void dump(char* _buf, uint16_t _count) {
break; \
} \
printk("\n"); \
} \
}while(0);
#else
#define DUMP_SPI_CMD(BUF) do {}while(0);
@ -944,7 +964,13 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx,
uint8_t _state = CLOSED;
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
{
_state = getStateTcp(mapSockTCP[(uint8_t)recv[4]], 1);
// get if we are in server or Transmit mode (0)
if (getModeTcp(mapSockTCP[(uint8_t)recv[4]]) == TTCP_MODE_TRANSMIT)
{
_state = _connected ? ESTABLISHED : CLOSED;
}else {
_state = getStateTcp(mapSockTCP[(uint8_t)recv[4]], 1);
}
}
PUT_DATA_BYTE(_state, reply, 3);
END_HEADER_REPLY(reply, 5, *count);
@ -1272,7 +1298,7 @@ bool checkMsgFormat(uint8_t* _recv, int len, int* offset)
paramLenTot = checkMsgParam8(recv);
else
{
//DUMP(_recv, len);
DUMP_SPI_DATA(_recv, len);
paramLenTot = checkMsgParam16(recv);
}
@ -1313,8 +1339,8 @@ void spi_poll(struct netif* netif) {
{
//LED_On(LED1);
//INFO_SPI("[E(0x%x):%d spiStatus:%d]\n", statSpi.lastCmd, err, statSpi.status);
DUMP(buf, count);
DUMP(reply, replyCount);
DUMP_SPI_DATA(buf, count);
DUMP_SPI_DATA(reply, replyCount);
//LED_Off(LED1);
}
receivedChars = 0;
@ -1334,7 +1360,7 @@ void spi_poll(struct netif* netif) {
{
sendError();
WARN("Check format msg failed!\n");
//dump((char*)_receiveBuffer, receivedChars);
dump((char*)_receiveBuffer, receivedChars);
state = SPI_CMD_IDLE;
count=0;
}
@ -1563,6 +1589,8 @@ int initSpi()
memset(_receiveBuffer, 0, _BUFFERSIZE);
init_pBuf();
return 0;
}

View File

@ -134,13 +134,15 @@ static void tcp_send_data(struct ttcp *ttcp) {
len = tcp_sndbuf(ttcp->tpcb);
do {
err = tcp_write(ttcp->tpcb, ttcp->payload, len, 0);
err = tcp_write(ttcp->tpcb, ttcp->payload, len, TCP_WRITE_FLAG_COPY);
if (err == ERR_MEM)
len /= 2;
} while (err == ERR_MEM && len > 1);
if (err == ERR_OK){
tcp_output(ttcp->tpcb);
INFO_TCP("tcp_output: left=%d new left:%d\n",
ttcp->left, ttcp->left-len);
ttcp->left -= len;
}
else
@ -209,14 +211,12 @@ tcp_sent_cb(void *arg, struct tcp_pcb *pcb, u16_t len)
static err_t tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err) {
struct ttcp* ttcp = arg;
printk("TTCP [%p]: connect\n", ttcp);
INFO_TCP("TTCP [%p]: connect %d %d\n", ttcp, err, ttcp->tpcb->state);
_connected = true;
ttcp->start_time = timer_get_ms();
#if 0
tcp_sent(tpcb, tcp_sent_cb);
tcp_send_data(ttcp);
#endif
return ERR_OK;
}
@ -251,9 +251,10 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
/* for print_stats() */
ttcp->recved += p->tot_len;
if (ttcp->verbose) {
if ((ttcp->verbose)||(verboseDebug & INFO_TCP_FLAG)) {
INFO_TCP("Recv:%d\n",p->tot_len);
DUMP(p->payload, p->tot_len);
//INFO_TCP("%s\n",(char*)p->payload);
DUMP_TCP(p->payload, p->tot_len);
ttcp->print_cnt++;
}
@ -312,6 +313,7 @@ static int atcp_start(struct ttcp* ttcp) {
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
tcp_recv(ttcp->tpcb, atcp_recv_cb);
_connected = false;
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
!= ERR_OK) {
WARN("TTCP [%p]: tcp connect failed\n", ttcp);
@ -569,6 +571,15 @@ uint8_t getStateTcp(void* p, bool client) {
return CLOSED;
}
uint8_t getModeTcp(void* p) {
struct ttcp* _ttcp = (struct ttcp*) p;
if (_ttcp != NULL)
return _ttcp->mode;
return 0;
}
uint8_t isDataSent(void* p) {
static int isDataSentCount = 0;
struct ttcp* _ttcp = (struct ttcp*) p;
@ -601,15 +612,16 @@ static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len) {
if (_ttcp->buff_sent == 1)
WARN("Previous packet already\n");
_ttcp->buff_sent = 1;
INFO_TCP("Packet sent len:%d dur:%d\n", len, timer_get_ms() - startTime);
//INFO_TCP("%s: duration: %d\n", __FUNCTION__, timer_get_ms() - startTime);
return ERR_OK;
}
int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
//INFO_TCP("buf:%p len:%d\n", buf, len);
//DUMP(buf,len);
INFO_TCP("buf:%p len:%d\n", buf, len);
DUMP_TCP(buf,len);
//startTime = timer_get_ms();
startTime = timer_get_ms();
struct ttcp* _ttcp = (struct ttcp*) p;
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL) &&
(buf != NULL) && (len != 0) && (_ttcp->payload != NULL)) {
@ -620,6 +632,8 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
_ttcp->buff_sent = 0;
//pbuf_take(buf, len, _ttcp->);
memcpy(_ttcp->payload, buf, len);
_ttcp->payload[len]='\0';
INFO_TCP("%s\n", _ttcp->payload);
_ttcp->left = len;
tcp_sent(_ttcp->tpcb, tcp_data_sent);
tcp_send_data(_ttcp);

View File

@ -49,6 +49,7 @@ typedef struct ttcp {
struct udp_pcb* upcb;
}ttcp_t;
bool _connected;
int ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
ard_tcp_done_cb_t *done_cb, int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose, uint8_t sock, void** _ttcp);
@ -57,6 +58,8 @@ void ard_tcp_stop(void* ttcp);
uint8_t getStateTcp(void* p, bool client );
uint8_t getModeTcp(void* p);
int sendTcpData(void* p, uint8_t* buf, uint16_t len);
uint8_t isDataSent(void* p );

View File

@ -21,6 +21,11 @@ unsigned char tailBuf = 0;
#define IS_BUF_AVAIL() (tailBuf!=headBuf)
#define IS_BUF_EMPTY() ((tailBuf == 0) && (headBuf == 0))
void init_pBuf()
{
memset(pBufStore, 0, sizeof(pBufStore));
}
void insert_pBuf(struct pbuf* q, uint8_t sock, void* _pcb)
{
if (q == NULL)

View File

@ -216,6 +216,8 @@ typedef struct sData
struct pbuf;
void init_pBuf();
void insert_pBuf(struct pbuf* q, uint8_t sock, void* _pcb);
tData* get_pBuf(uint8_t sock);

View File

@ -40,6 +40,21 @@
extern void showTTCPstatus();
#define ENABLE_DEBUG_LEVEL 1
#define VERBOSE_DEBUG_LEVEL 2
#define CHECK_ENA_DEBUG(LEVEL, FLAG) \
do{ \
if (LEVEL >= ENABLE_DEBUG_LEVEL) enableDebug |= FLAG; \
else enableDebug &= ~FLAG; \
}while(0);
#define CHECK_VERB_DEBUG(LEVEL, FLAG) \
do{ \
if (LEVEL >= VERBOSE_DEBUG_LEVEL) verboseDebug |= FLAG; \
else verboseDebug &= ~FLAG; \
}while(0);
/**
*
*/
@ -357,15 +372,17 @@ cmd_debug(int argc, char* argv[], void* ctx)
int level;
const char *usage = "usage: debug <section> <level>\n\t"\
"section: init, cm, spi, tcp , util, warn\n\t"
"level : 0 (off), 1 (on)\n\t"
"level : 0 (off), 1 (on), 2 (verbose)\n\t"
"or: debug print/on/off\n";
if (argc == 2 && strcmp(argv[1], "off") == 0) {
printk("Debug OFF\n");
enableDebug = 0;
verboseDebug = 0;
return CMD_DONE;
}else if (argc == 2 && strcmp(argv[1], "print") == 0) {
printk("Debug enabled: 0x%x\n", enableDebug);
printk("Verbose enabled: 0x%x\n", verboseDebug);
return CMD_DONE;
}else if (argc == 2 && strcmp(argv[1], "on") == 0) {
printk("Debug ON\n");
@ -378,23 +395,23 @@ cmd_debug(int argc, char* argv[], void* ctx)
}
level = atoi(argv[2]);
if (argc == 3 && strcmp(argv[1], "init") == 0) {
if (level) enableDebug |= INFO_INIT_FLAG;
else enableDebug &= ~INFO_INIT_FLAG;
CHECK_ENA_DEBUG(level, INFO_INIT_FLAG);
CHECK_VERB_DEBUG(level, INFO_INIT_FLAG);
}else if (argc == 3 && strcmp(argv[1], "spi") == 0) {
if (level) enableDebug |= INFO_SPI_FLAG;
else enableDebug &= ~INFO_SPI_FLAG;
CHECK_ENA_DEBUG(level, INFO_SPI_FLAG);
CHECK_VERB_DEBUG(level, INFO_SPI_FLAG);
}else if (argc == 3 && strcmp(argv[1], "tcp") == 0) {
if (level) enableDebug |= INFO_TCP_FLAG;
else enableDebug &= ~INFO_TCP_FLAG;
CHECK_ENA_DEBUG(level, INFO_TCP_FLAG);
CHECK_VERB_DEBUG(level, INFO_TCP_FLAG);
}else if (argc == 3 && strcmp(argv[1], "cm") == 0) {
if (level) enableDebug |= INFO_CM_FLAG;
else enableDebug &= ~INFO_CM_FLAG;
CHECK_ENA_DEBUG(level, INFO_CM_FLAG);
CHECK_VERB_DEBUG(level, INFO_CM_FLAG);
}else if (argc == 3 && strcmp(argv[1], "util") == 0) {
if (level) enableDebug |= INFO_UTIL_FLAG;
else enableDebug &= ~INFO_UTIL_FLAG;
CHECK_ENA_DEBUG(level, INFO_UTIL_FLAG);
CHECK_VERB_DEBUG(level, INFO_UTIL_FLAG);
}else if (argc == 3 && strcmp(argv[1], "warn") == 0) {
if (level) enableDebug |= INFO_WARN_FLAG;
else enableDebug &= ~INFO_WARN_FLAG;
CHECK_ENA_DEBUG(level, INFO_WARN_FLAG);
CHECK_VERB_DEBUG(level, INFO_WARN_FLAG);
}
return CMD_DONE;
}

View File

@ -25,6 +25,8 @@
extern uint16_t enableDebug;
extern uint16_t verboseDebug;
#define INFO_INIT(msg, args...) do { \
if (enableDebug & INFO_INIT_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \
} while (0)
@ -70,3 +72,10 @@ extern void dump(char* _buf, uint16_t _count);
#define DUMP(BUF, COUNT) do {} while (0)
#endif
#endif
#define DUMP_TCP(BUF, COUNT) do { \
if (verboseDebug & INFO_TCP_FLAG) { \
printk("[%s]\n", __func__); \
dump((char*)BUF, COUNT); \
}} while (0)

View File

@ -88,6 +88,7 @@ static bool initSpiComplete = false;
// variable used as enable flag for debug prints
uint16_t enableDebug = 0;
uint16_t verboseDebug = 0;
/**
*

View File

@ -66,11 +66,12 @@ static void init_interrupts(void)
void startup_init(void)
{
INIT_SIGNAL_FOR_SPI();
BUSY_FOR_SPI();
init_exceptions();
init_hmatrix();
init_sys_clocks();
init_interrupts();
init_dbg_rs232(FPBA_HZ);
INIT_SIGNAL_FOR_SPI();
BUSY_FOR_SPI();
}