1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Fix issue with peek function

This commit is contained in:
Mimmo La Fauci 2012-06-05 14:20:22 +02:00
parent f213e69e73
commit fd1b1b29bc
9 changed files with 83 additions and 33 deletions

View File

@ -27,7 +27,7 @@
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value>${workspace_loc:/wifiHD/Release}</value>
<value>${workspace_loc:/wifiHD/Debug}</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>

Binary file not shown.

View File

@ -199,6 +199,7 @@
/* Pin related to shield communication */
#define ARDUINO_HANDSHAKE_PIN AVR32_PIN_PA25
#define ARDUINO_EXTINT_PIN AVR32_PIN_PA04 //not used
#define AVR32_PDCA_PID_TX AVR32_PDCA_PID_SPI1_TX
#define AVR32_PDCA_PID_RX AVR32_PDCA_PID_SPI1_RX

View File

@ -57,7 +57,7 @@
#include "lwip/snmp.h"
#include <string.h>
#define _TEST_HD_
/* Forward declarations.*/
static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb);
@ -699,6 +699,19 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
}
#endif
#ifdef _TEST_HD_
/* ANGR: set rtime this _before_ checking ip_route(). Otherwise TCP_SYN will
* not be retransmitted in case the interface was down and tcp_connect()
* will not return any error. Since we still want the err_cb() (or maybe
* the wifi link comes up), make sure that we fulfill the retransmissions in
* tcp_slowtmr()
*/
/* Set retransmission timer running if it is not currently enabled */
if(pcb->rtime == -1)
pcb->rtime = 0;
#endif
/* If we don't have a local IP address, we get one by
calling ip_route(). */
if (ip_addr_isany(&(pcb->local_ip))) {
@ -709,9 +722,11 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
ip_addr_set(&(pcb->local_ip), &(netif->ip_addr));
}
/* Set retransmission timer running if it is not currently enabled */
#ifndef _TEST_HD_
//Set retransmission timer running if it is not currently enabled
if(pcb->rtime == -1)
pcb->rtime = 0;
#endif
if (pcb->rttest == 0) {
pcb->rttest = tcp_ticks;

View File

@ -204,7 +204,11 @@ void setMapSock(uint8_t sock, void* _ttcp)
void clearMapSockTcp(uint8_t sock)
{
if (sock < MAX_SOCK_NUM)
{
//printk("UnMap [%d, %p]\n", sock, mapSockTCP[sock]);
mapSockTCP[sock] = NULL;
}
}
void initMapSockTcp()
@ -649,7 +653,7 @@ int start_server_tcp(uint16_t port, uint8_t sock)
err = WL_SUCCESS;
}else{
INFO_SPI("Start Server [%d, %d] FAILED!\n", port, sock);
WARN("Start Server [%d, %d] FAILED!\n", port, sock);
clearMapSockTcp(sock);
}
return err;
@ -1140,7 +1144,6 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx,
((struct ttcp*) p)->tpcb->state,
((struct ttcp*) p)->lpcb->state,
_state);
}
}
}
@ -1226,10 +1229,16 @@ cmd_spi_state_t get_data_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_t
CHECK_ARD_NETIF(recv, reply, count);
tParam* params = (tParam*)&recv[3];
GET_PARAM_NEXT(BYTE, params, _sock);
GET_PARAM_NEXT(INT, params, _peek);
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
{
SIGN2_DN();
if (getTcpDataByte((uint8_t)recv[4], &data))
if (getTcpDataByte((uint8_t)recv[4], &data, _peek))
{
CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_1);
PUT_DATA_BYTE(data, reply, 3);

View File

@ -36,6 +36,8 @@ static int isDataSentCount = 0;
bool pending_close = false;
bool pending_accept = false;
static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len);
static void atcp_init()
{
pending_close = false;
@ -48,12 +50,16 @@ static void ard_tcp_destroy(struct ttcp* ttcp) {
err_t err = ERR_OK;
DUMP_TCP_STATE(ttcp);
if (getSock(ttcp)==-1)
WARN("ttcp already deallocated!\n");
if (ttcp->tpcb) {
tcp_arg(ttcp->tpcb, NULL);
tcp_sent(ttcp->tpcb, NULL);
tcp_recv(ttcp->tpcb, NULL);
tcp_err(ttcp->tpcb, NULL);
err = tcp_close(ttcp->tpcb);
//TEMPORAQARY
//err = tcp_close(ttcp->tpcb);
INFO_TCP("Closing tpcb: state:0x%x err:%d\n", ttcp->tpcb->state, err);
}
@ -118,6 +124,7 @@ static void ard_tcp_done(struct ttcp* ttcp, int result) {
ttcp->done_cb(ttcp->opaque, result);
ard_tcp_destroy(ttcp);
clearMapSockTcp(getSock(ttcp));
}
static void
@ -233,8 +240,16 @@ static void atcp_conn_cli_err_cb(void *arg, err_t err) {
if (ifStatus == false)
printk("Abort connection\n");
ard_tcp_destroy(_ttcp);
if ((_ttcp)&&(err == ERR_ABRT))
{
WARN("TTCP [%p]: free memory\n", _ttcp);
tcp_poll_retries = 0;
cleanSockState_cb(_ttcp);
if (_ttcp->payload)
free(_ttcp->payload);
free(_ttcp);
}
pending_close = false;
}
@ -269,7 +284,7 @@ void closeConnections()
_ttcp->tpcb, _ttcp->tpcb->state, _ttcp->lpcb, _ttcp->lpcb->state);
//tcp_close(_ttcp->tpcb);
ard_tcp_destroy(_ttcp);
cleanSockState_cb(_ttcp);
clearMapSockTcp(getSock(_ttcp));
}
}
}
@ -305,6 +320,8 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
close_conn(ttcp);
}
if (err!=ERR_OK)
WARN("err=%d p=%p\n", err, p);
return ERR_OK;
}
@ -352,21 +369,18 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
struct ttcp* _ttcp = arg;
++tcp_poll_retries;
if (tcp_poll_retries > 4) {
WARN("ARD TCP [%p] arg=%p retries=%d\n",
pcb, arg, tcp_poll_retries);
if (tcp_poll_retries > 8) {
WARN("ARD TCP [%p-%p] arg=%p retries=%d\n",
pcb, _ttcp->tpcb, arg, tcp_poll_retries);
tcp_poll_retries = 0;
tcp_abort(pcb);
ard_tcp_destroy(_ttcp);
cleanSockState_cb(_ttcp);
pending_close = false;
return ERR_ABRT;
}
WARN("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg,
tcp_poll_retries, pending_close);
WARN("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d conn:%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg,
tcp_poll_retries, pending_close, _connected);
if (_ttcp) tcp_send_data(_ttcp);
if ((_ttcp)&&(_connected)) tcp_send_data(_ttcp);
if (pending_close)
{
@ -377,7 +391,12 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
}
else
{
cleanSockState_cb(_ttcp);
if (_ttcp->payload)
free(_ttcp->payload);
free(_ttcp);
pending_close = false;
}
INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, (_ttcp)?_ttcp->tpcb:0, pending_close);
@ -423,7 +442,7 @@ static int atcp_start(struct ttcp* ttcp) {
WARN("TTCP [%p]: could not allocate pcb\n", ttcp);
return -1;
}
INFO_TCP("tcp:%x\n", ttcp->tpcb);
ttcp->payload = malloc(ttcp->buflen);
if (ttcp->payload == NULL) {
WARN("TTCP [%p]: could not allocate payload\n", ttcp);
@ -436,14 +455,14 @@ static int atcp_start(struct ttcp* ttcp) {
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
tcp_err(ttcp->tpcb, atcp_conn_cli_err_cb);
tcp_recv(ttcp->tpcb, atcp_recv_cb);
tcp_poll(ttcp->tpcb, atcp_poll, 4);
tcp_sent(ttcp->tpcb, tcp_data_sent);
tcp_poll(ttcp->tpcb, atcp_poll_conn, 4);
_connected = false;
INFO_TCP("[tpcb]- %p\n", ttcp->tpcb);
INFO_TCP("[tpcb]-%p payload:%p\n", ttcp->tpcb, ttcp->payload);
DUMP_TCP_STATE(ttcp);
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
!= ERR_OK) {
WARN("TTCP [%p]: tcp connect failed\n", ttcp);
atcp_conn_err_cb(ttcp, err);
return -1;
}
@ -681,6 +700,7 @@ void ard_tcp_stop(void* ttcp) {
INFO_TCP("Destroy TCP connection...state:%d\n", _ttcp->tpcb->state);
ard_tcp_destroy(_ttcp);
clearMapSockTcp(getSock(_ttcp));
tcp_poll_retries = 0;
}else{
INFO_TCP("Closing connection...state:%d\n", _ttcp->tpcb->state);
DUMP_TCP_STATE(_ttcp);
@ -688,6 +708,7 @@ void ard_tcp_stop(void* ttcp) {
{
close_conn(_ttcp);
}
pending_accept = false;
}
}
@ -756,7 +777,7 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
if (_ttcp==NULL)
{
WARN("ttcp == NULL!");
WARN("ttcp == NULL!\n");
return WL_FAILURE;
}

View File

@ -88,9 +88,10 @@ bool isAvailTcpDataByte(uint8_t sock)
INFO_UTIL("check:%d %d %p\n",p->idx, p->len, p->data);
if (p->idx == p->len)
{
INFO_UTIL("Free %p other buf %d\n", p->data, IS_BUF_AVAIL());
freetData(p->data);
ack_recved(p->pcb, p->len);
INFO_UTIL("Free %p other buf %d tail:%d head:%d\n",
p->data, IS_BUF_AVAIL(), tailBuf, headBuf);
return (IS_BUF_AVAIL());
}else{
return true;
@ -101,7 +102,7 @@ bool isAvailTcpDataByte(uint8_t sock)
bool getTcpDataByte(uint8_t sock, uint8_t* payload)
bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek)
{
// ref field in struct pbuf has been used as index pointer for byte data
tData* p = get_pBuf(sock);
@ -111,6 +112,9 @@ bool getTcpDataByte(uint8_t sock, uint8_t* payload)
if (p->idx < p->len)
{
uint8_t* buf = (uint8_t*)p->data;
if (peek)
*payload = buf[p->idx];
else
*payload = buf[p->idx++];
INFO_UTIL("get:%d %p %d\n",p->idx, p->data, *payload);
return true;

View File

@ -25,7 +25,7 @@
#define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO)
#define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO)
#define _DEBUG_
#ifdef _DEBUG_
#define SIGN0_UP LED0_UP
#define SIGN0_DN LED0_DN
@ -238,7 +238,7 @@ bool isBufAvail();
bool getTcpData(uint8_t sock, void** payload, uint16_t* len);
bool getTcpDataByte(uint8_t sock, uint8_t* payload);
bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek);
bool isAvailTcpDataByte(uint8_t sock);

View File

@ -433,9 +433,9 @@
//#define IP_DEBUG LWIP_DBG_ON
//#define TCP_CWND_DEBUG LWIP_DBG_ON
//#define ETHARP_DEBUG LWIP_DBG_ON
//#define PBUF_DEBUG LWIP_DBG_ON
#define TCP_INPUT_DEBUG LWIP_DBG_ON
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#define PBUF_DEBUG LWIP_DBG_ON
//#define TCP_INPUT_DEBUG LWIP_DBG_ON
//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#endif
#define ETH_PAD_SIZE WL_HEADER_SIZE /* size of wifiengine header */