mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-03 14:24:15 +01:00
Less print msgs on wifishield
This commit is contained in:
parent
5778170fa6
commit
7c2934a91b
@ -78,10 +78,15 @@
|
|||||||
<type>2</type>
|
<type>2</type>
|
||||||
<locationURI>framework:/com.atmel.avr32.sf.uc3</locationURI>
|
<locationURI>framework:/com.atmel.avr32.sf.uc3</locationURI>
|
||||||
</link>
|
</link>
|
||||||
|
<link>
|
||||||
|
<name>arduino</name>
|
||||||
|
<type>2</type>
|
||||||
|
<location>/media/WindowsNTFS/Projects/Arduino/Arduino-git</location>
|
||||||
|
</link>
|
||||||
<link>
|
<link>
|
||||||
<name>include</name>
|
<name>include</name>
|
||||||
<type>2</type>
|
<type>2</type>
|
||||||
<location>C:/usr/avr32/include</location>
|
<location>/home/dlafauci/C::/usr/avr32/include</location>
|
||||||
</link>
|
</link>
|
||||||
</linkedResources>
|
</linkedResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
BIN
wifiHD/Release/wifiHD.elf
Normal file
BIN
wifiHD/Release/wifiHD.elf
Normal file
Binary file not shown.
@ -30,113 +30,100 @@
|
|||||||
#define TTCP_MODE_TRANSMIT 0
|
#define TTCP_MODE_TRANSMIT 0
|
||||||
#define TTCP_MODE_RECEIVE 1
|
#define TTCP_MODE_RECEIVE 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct ttcp {
|
struct ttcp {
|
||||||
|
|
||||||
/* options */
|
/* options */
|
||||||
struct ip_addr addr; /* host */
|
struct ip_addr addr; /* host */
|
||||||
uint16_t port; /* -p */
|
uint16_t port; /* -p */
|
||||||
uint16_t nbuf; /* -n */
|
uint16_t nbuf; /* -n */
|
||||||
int mode; /* -t */
|
int mode; /* -t */
|
||||||
int verbose; /* -v */
|
int verbose; /* -v */
|
||||||
int udp; /* -u */
|
int udp; /* -u */
|
||||||
uint8_t sock;
|
uint8_t sock;
|
||||||
uint8_t buff_sent;
|
uint8_t buff_sent;
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
uint16_t print_cnt;
|
uint16_t print_cnt;
|
||||||
uint32_t start_time;
|
uint32_t start_time;
|
||||||
uint32_t left;
|
uint32_t left;
|
||||||
uint32_t recved;
|
uint32_t recved;
|
||||||
ard_tcp_done_cb_t* done_cb;
|
ard_tcp_done_cb_t* done_cb;
|
||||||
void* opaque;
|
void* opaque;
|
||||||
uint32_t buflen; /* -l */
|
uint32_t buflen; /* -l */
|
||||||
uint32_t tid;
|
uint32_t tid;
|
||||||
|
|
||||||
/* TCP specific */
|
/* TCP specific */
|
||||||
struct tcp_pcb* tpcb;
|
struct tcp_pcb* tpcb;
|
||||||
struct tcp_pcb* lpcb;
|
struct tcp_pcb* lpcb;
|
||||||
char* payload;
|
char* payload;
|
||||||
|
|
||||||
/* UDP specific */
|
/* UDP specific */
|
||||||
int udp_started;
|
int udp_started;
|
||||||
uint16_t udp_end_marker_left;
|
uint16_t udp_end_marker_left;
|
||||||
struct udp_pcb* upcb;
|
struct udp_pcb* upcb;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int startTime = 0;
|
unsigned int startTime = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate bitrate based on number of bytes transmitted and elapsed time
|
* Calculate bitrate based on number of bytes transmitted and elapsed time
|
||||||
*/
|
*/
|
||||||
static void
|
static void ard_tcp_print_stats(struct ttcp *ttcp) {
|
||||||
ard_tcp_print_stats(struct ttcp *ttcp)
|
uint32_t ms = timer_get_ms() - ttcp->start_time;
|
||||||
{
|
uint32_t bytes = ttcp->mode == TTCP_MODE_TRANSMIT ? ttcp->nbuf
|
||||||
uint32_t ms = timer_get_ms() - ttcp->start_time;
|
* ttcp->buflen : ttcp->recved;
|
||||||
uint32_t bytes = ttcp->mode == TTCP_MODE_TRANSMIT ?
|
|
||||||
ttcp->nbuf * ttcp->buflen : ttcp->recved;
|
|
||||||
|
|
||||||
if (ttcp->verbose)
|
if (ttcp->verbose)
|
||||||
printk("\n");
|
printk("\n");
|
||||||
|
|
||||||
printk("TTCP [%p]: %d bytes processed, %d.%d KB/s (%s/%s)\n",
|
printk("TTCP [%p]: %d bytes processed, %d.%d KB/s (%s/%s)\n", ttcp, bytes,
|
||||||
ttcp, bytes, bytes / ms, bytes % ms, ttcp->udp ? "udp" : "tcp",
|
bytes / ms, bytes % ms, ttcp->udp ? "udp" : "tcp", ttcp->mode
|
||||||
ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx");
|
== TTCP_MODE_TRANSMIT ? "tx" : "rx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up and free the ttcp structure
|
* Clean up and free the ttcp structure
|
||||||
*/
|
*/
|
||||||
static void
|
static void ard_tcp_destroy(struct ttcp* ttcp) {
|
||||||
ard_tcp_destroy(struct ttcp* ttcp)
|
|
||||||
{
|
|
||||||
err_t err = ERR_OK;
|
err_t err = ERR_OK;
|
||||||
if (ttcp->tpcb) {
|
if (ttcp->tpcb) {
|
||||||
tcp_arg(ttcp->tpcb, NULL);
|
tcp_arg(ttcp->tpcb, NULL);
|
||||||
tcp_sent(ttcp->tpcb, NULL);
|
tcp_sent(ttcp->tpcb, NULL);
|
||||||
tcp_recv(ttcp->tpcb, NULL);
|
tcp_recv(ttcp->tpcb, NULL);
|
||||||
tcp_err(ttcp->tpcb, NULL);
|
tcp_err(ttcp->tpcb, NULL);
|
||||||
err = tcp_close(ttcp->tpcb);
|
err = tcp_close(ttcp->tpcb);
|
||||||
printk("Closing tpcb: state:0x%x err:%d\n",
|
printk("Closing tpcb: state:0x%x err:%d\n", ttcp->tpcb->state, err);
|
||||||
ttcp->tpcb->state, err);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ttcp->lpcb) {
|
if (ttcp->lpcb) {
|
||||||
tcp_arg(ttcp->lpcb, NULL);
|
tcp_arg(ttcp->lpcb, NULL);
|
||||||
tcp_accept(ttcp->lpcb, NULL);
|
tcp_accept(ttcp->lpcb, NULL);
|
||||||
tcp_close(ttcp->lpcb);
|
tcp_close(ttcp->lpcb);
|
||||||
printk("Closing lpcb: state:0x%x err:%d\n",
|
printk("Closing lpcb: state:0x%x err:%d\n", ttcp->lpcb->state, err);
|
||||||
ttcp->lpcb->state, err);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ttcp->upcb) {
|
if (ttcp->upcb) {
|
||||||
udp_disconnect(ttcp->upcb);
|
udp_disconnect(ttcp->upcb);
|
||||||
udp_remove(ttcp->upcb);
|
udp_remove(ttcp->upcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ttcp->payload)
|
if (ttcp->payload)
|
||||||
free(ttcp->payload);
|
free(ttcp->payload);
|
||||||
|
|
||||||
free(ttcp);
|
free(ttcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when transfer is done or aborted (non-zero result).
|
* Invoked when transfer is done or aborted (non-zero result).
|
||||||
*/
|
*/
|
||||||
static void
|
static void ard_tcp_done(struct ttcp* ttcp, int result) {
|
||||||
ard_tcp_done(struct ttcp* ttcp, int result)
|
if (result == 0)
|
||||||
{
|
ard_tcp_print_stats(ttcp);
|
||||||
if (result == 0)
|
|
||||||
ard_tcp_print_stats(ttcp);
|
|
||||||
|
|
||||||
if (ttcp->done_cb)
|
if (ttcp->done_cb)
|
||||||
ttcp->done_cb(ttcp->opaque, result);
|
ttcp->done_cb(ttcp->opaque, result);
|
||||||
|
|
||||||
ard_tcp_destroy(ttcp);
|
ard_tcp_destroy(ttcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -148,69 +135,63 @@ tcp_timeout_cb(void *ctx);
|
|||||||
* Called upon connect and when there's space available in the TCP send window
|
* Called upon connect and when there's space available in the TCP send window
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void
|
static void tcp_send_data(struct ttcp *ttcp) {
|
||||||
tcp_send_data(struct ttcp *ttcp)
|
err_t err;
|
||||||
{
|
uint32_t len;
|
||||||
err_t err;
|
|
||||||
uint32_t len;
|
|
||||||
|
|
||||||
len = ttcp->left;
|
|
||||||
|
|
||||||
/* don't send more than we have in the payload */
|
len = ttcp->left;
|
||||||
if (len > ttcp->buflen)
|
|
||||||
len = ttcp->buflen;
|
|
||||||
|
|
||||||
/* We cannot send more data than space available in the send
|
/* don't send more than we have in the payload */
|
||||||
buffer. */
|
if (len > ttcp->buflen)
|
||||||
if (len > tcp_sndbuf(ttcp->tpcb))
|
len = ttcp->buflen;
|
||||||
len = tcp_sndbuf(ttcp->tpcb);
|
|
||||||
|
|
||||||
do {
|
/* We cannot send more data than space available in the send
|
||||||
err = tcp_write(ttcp->tpcb, ttcp->payload, len, 0);
|
buffer. */
|
||||||
if (err == ERR_MEM)
|
if (len > tcp_sndbuf(ttcp->tpcb))
|
||||||
len /= 2;
|
len = tcp_sndbuf(ttcp->tpcb);
|
||||||
} while (err == ERR_MEM && len > 1);
|
|
||||||
|
|
||||||
tcp_output(ttcp->tpcb);
|
do {
|
||||||
if (err == ERR_OK)
|
err = tcp_write(ttcp->tpcb, ttcp->payload, len, 0);
|
||||||
ttcp->left -= len;
|
if (err == ERR_MEM)
|
||||||
else
|
len /= 2;
|
||||||
printk("TTCP [%p]: tcp_write failed\n", ttcp);
|
} while (err == ERR_MEM && len > 1);
|
||||||
//
|
|
||||||
// ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
|
tcp_output(ttcp->tpcb);
|
||||||
// tcp_timeout_cb, ttcp);
|
if (err == ERR_OK)
|
||||||
|
ttcp->left -= len;
|
||||||
|
else
|
||||||
|
printk("TTCP [%p]: tcp_write failed\n", ttcp);
|
||||||
|
//
|
||||||
|
// ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
|
||||||
|
// tcp_timeout_cb, ttcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
* Scheduled by tcp_send_data(). tcp_sent() is not used for performance reasons.
|
* Scheduled by tcp_send_data(). tcp_sent() is not used for performance reasons.
|
||||||
*/
|
*/
|
||||||
static void
|
static void tcp_timeout_cb(void *ctx) {
|
||||||
tcp_timeout_cb(void *ctx)
|
struct ttcp *ttcp = ctx;
|
||||||
{
|
|
||||||
struct ttcp *ttcp = ctx;
|
|
||||||
|
|
||||||
if (ttcp->left > 0) {
|
if (ttcp->left > 0) {
|
||||||
tcp_send_data(ttcp);
|
tcp_send_data(ttcp);
|
||||||
if (ttcp->verbose) {
|
if (ttcp->verbose) {
|
||||||
printk(".");
|
printk(".");
|
||||||
if (ttcp->print_cnt % 80 == 0)
|
if (ttcp->print_cnt % 80 == 0)
|
||||||
printk("\n");
|
printk("\n");
|
||||||
ttcp->print_cnt++;
|
ttcp->print_cnt++;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* all sent - empty queue */
|
/* all sent - empty queue */
|
||||||
if (ttcp->tpcb->snd_queuelen)
|
if (ttcp->tpcb->snd_queuelen)
|
||||||
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
|
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT, tcp_timeout_cb,
|
||||||
tcp_timeout_cb, ttcp);
|
ttcp);
|
||||||
else
|
else
|
||||||
ard_tcp_done(ttcp, 0);
|
ard_tcp_done(ttcp, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
@ -219,171 +200,159 @@ tcp_timeout_cb(void *ctx)
|
|||||||
static err_t
|
static err_t
|
||||||
tcp_sent_cb(void *arg, struct tcp_pcb *pcb, u16_t len)
|
tcp_sent_cb(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||||
{
|
{
|
||||||
struct ttcp *ttcp = arg;
|
struct ttcp *ttcp = arg;
|
||||||
|
|
||||||
if (ttcp->left > 0) {
|
if (ttcp->left > 0) {
|
||||||
tcp_send_data(ttcp);
|
tcp_send_data(ttcp);
|
||||||
if (ttcp->verbose) {
|
if (ttcp->verbose) {
|
||||||
printk(".");
|
printk(".");
|
||||||
if (ttcp->print_cnt % 80 == 0)
|
if (ttcp->print_cnt % 80 == 0)
|
||||||
printk("\n");
|
printk("\n");
|
||||||
ttcp->print_cnt++;
|
ttcp->print_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pcb->snd_queuelen == 0) {
|
} else if (pcb->snd_queuelen == 0) {
|
||||||
ard_tcp_done(ttcp, 0);
|
ard_tcp_done(ttcp, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
*/
|
*/
|
||||||
static err_t
|
static err_t tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err) {
|
||||||
tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err)
|
struct ttcp* ttcp = arg;
|
||||||
{
|
|
||||||
struct ttcp* ttcp = arg;
|
|
||||||
|
|
||||||
printk("TTCP [%p]: connect\n", ttcp);
|
printk("TTCP [%p]: connect\n", ttcp);
|
||||||
|
|
||||||
ttcp->start_time = timer_get_ms();
|
ttcp->start_time = timer_get_ms();
|
||||||
#if 0
|
#if 0
|
||||||
tcp_sent(tpcb, tcp_sent_cb);
|
tcp_sent(tpcb, tcp_sent_cb);
|
||||||
|
|
||||||
tcp_send_data(ttcp);
|
tcp_send_data(ttcp);
|
||||||
#endif
|
#endif
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
*/
|
*/
|
||||||
static void
|
static void atcp_conn_err_cb(void *arg, err_t err) {
|
||||||
atcp_conn_err_cb(void *arg, err_t err)
|
struct ttcp* ttcp = arg;
|
||||||
{
|
|
||||||
struct ttcp* ttcp = arg;
|
|
||||||
|
|
||||||
printk("TTCP [%p]: connection error:0x%x\n", ttcp,err);
|
printk("TTCP [%p]: connection error:0x%x\n", ttcp, err);
|
||||||
|
|
||||||
ttcp->tpcb = NULL; /* free'd by lwip upon return */
|
ttcp->tpcb = NULL; /* free'd by lwip upon return */
|
||||||
ard_tcp_done(ttcp, err);
|
ard_tcp_done(ttcp, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
*/
|
*/
|
||||||
static err_t
|
static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
||||||
atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
err_t err) {
|
||||||
{
|
struct ttcp* ttcp = arg;
|
||||||
struct ttcp* ttcp = arg;
|
/* p will be NULL when remote end is done */
|
||||||
/* p will be NULL when remote end is done */
|
if (p == NULL) {
|
||||||
if (p == NULL) {
|
ard_tcp_print_stats(ttcp);
|
||||||
ard_tcp_print_stats(ttcp);
|
ard_tcp_done(ttcp, 0);
|
||||||
ard_tcp_done(ttcp, 0);
|
return ERR_OK;
|
||||||
return ERR_OK;
|
}
|
||||||
}
|
DATA_LED_ON();
|
||||||
DATA_LED_ON();
|
/* for print_stats() */
|
||||||
/* for print_stats() */
|
ttcp->recved += p->tot_len;
|
||||||
ttcp->recved += p->tot_len;
|
|
||||||
|
|
||||||
if (ttcp->verbose) {
|
if (ttcp->verbose) {
|
||||||
INFO("Recv:%d\n",p->tot_len);
|
INFO("Recv:%d\n",p->tot_len);
|
||||||
DUMP(p->payload, p->tot_len);
|
DUMP(p->payload, p->tot_len);
|
||||||
ttcp->print_cnt++;
|
ttcp->print_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_pBuf(p, ttcp->sock, (void*)pcb);
|
insert_pBuf(p, ttcp->sock, (void*) pcb);
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
tcp_recved(pcb, p->tot_len);
|
tcp_recved(pcb, p->tot_len);
|
||||||
DATA_LED_OFF();
|
DATA_LED_OFF();
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ack_recved(void* pcb, int len)
|
void ack_recved(void* pcb, int len) {
|
||||||
{
|
|
||||||
// Comment the call because it is activated on atcp_recv_cb
|
// Comment the call because it is activated on atcp_recv_cb
|
||||||
//tcp_recved(pcb, len);
|
//tcp_recved(pcb, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static err_t
|
static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
|
||||||
atcp_poll(void *arg, struct tcp_pcb *pcb)
|
return ERR_OK;
|
||||||
{
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
*/
|
*/
|
||||||
static err_t
|
static err_t atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
||||||
atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err)
|
struct ttcp* ttcp = arg;
|
||||||
{
|
|
||||||
struct ttcp* ttcp = arg;
|
|
||||||
|
|
||||||
ttcp->tpcb = newpcb;
|
ttcp->tpcb = newpcb;
|
||||||
tcp_recv(ttcp->tpcb, atcp_recv_cb);
|
tcp_recv(ttcp->tpcb, atcp_recv_cb);
|
||||||
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
||||||
tcp_poll(ttcp->tpcb, atcp_poll, 4);
|
tcp_poll(ttcp->tpcb, atcp_poll, 4);
|
||||||
|
|
||||||
printk("ARD TCP [%p]: accept new [%p]\n", ttcp, newpcb);
|
printk("ARD TCP [%p]: accept new [%p]\n", ttcp, newpcb);
|
||||||
INFO("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
|
INFO("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
|
||||||
ttcp->start_time = timer_get_ms();
|
ttcp->start_time = timer_get_ms();
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start TCP transfer.
|
* Start TCP transfer.
|
||||||
*/
|
*/
|
||||||
static int
|
static int atcp_start(struct ttcp* ttcp) {
|
||||||
atcp_start(struct ttcp* ttcp)
|
err_t err = ERR_OK;
|
||||||
{
|
ttcp->tpcb = tcp_new();
|
||||||
ttcp->tpcb = tcp_new();
|
if (ttcp->tpcb == NULL) {
|
||||||
if (ttcp->tpcb == NULL) {
|
printk("TTCP [%p]: could not allocate pcb\n", ttcp);
|
||||||
printk("TTCP [%p]: could not allocate pcb\n", ttcp);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ttcp->payload = malloc(ttcp->buflen);
|
ttcp->payload = malloc(ttcp->buflen);
|
||||||
if (ttcp->payload == NULL) {
|
if (ttcp->payload == NULL) {
|
||||||
printk("TTCP [%p]: could not allocate payload\n", ttcp);
|
printk("TTCP [%p]: could not allocate payload\n", ttcp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tcp_arg(ttcp->tpcb, ttcp);
|
|
||||||
|
|
||||||
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
tcp_arg(ttcp->tpcb, ttcp);
|
||||||
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
|
||||||
tcp_recv(ttcp->tpcb, atcp_recv_cb);
|
|
||||||
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port,
|
|
||||||
tcp_connect_cb) != ERR_OK) {
|
|
||||||
printk("TTCP [%p]: tcp connect failed\n", ttcp);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
||||||
tcp_bind(ttcp->tpcb, IP_ADDR_ANY, ttcp->port);
|
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
||||||
ttcp->lpcb = tcp_listen(ttcp->tpcb);
|
tcp_recv(ttcp->tpcb, atcp_recv_cb);
|
||||||
if (ttcp->lpcb == NULL) {
|
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
|
||||||
printk("TTCP [%p]: listen failed\n", ttcp);
|
!= ERR_OK) {
|
||||||
return -1;
|
printk("TTCP [%p]: tcp connect failed\n", ttcp);
|
||||||
}
|
atcp_conn_err_cb(ttcp, err);
|
||||||
printk("ttcp:%p lpcb:%p pcb:%p\n", ttcp, ttcp->lpcb, ttcp->tpcb);
|
return -1;
|
||||||
printk("local:%d remote:%d state:%d\n", ttcp->lpcb->local_port,
|
}
|
||||||
ttcp->lpcb->remote_port, ttcp->lpcb->state);
|
|
||||||
tcp_accept(ttcp->lpcb, atcp_accept_cb);
|
} else {
|
||||||
}
|
err = tcp_bind(ttcp->tpcb, IP_ADDR_ANY, ttcp->port);
|
||||||
|
if (err != ERR_OK){
|
||||||
return 0;
|
printk("TTCP [%p]: bind failed err=%d\n", ttcp, err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ttcp->lpcb = tcp_listen(ttcp->tpcb);
|
||||||
|
if (ttcp->lpcb == NULL) {
|
||||||
|
printk("TTCP [%p]: listen failed\n", ttcp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printk("ttcp:%p lpcb:%p pcb:%p\n", ttcp, ttcp->lpcb, ttcp->tpcb);
|
||||||
|
printk("local:%d remote:%d state:%d\n", ttcp->lpcb->local_port,
|
||||||
|
ttcp->lpcb->remote_port, ttcp->lpcb->state);
|
||||||
|
tcp_accept(ttcp->lpcb, atcp_accept_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
udp_send_data(struct ttcp* ttcp);
|
udp_send_data(struct ttcp* ttcp);
|
||||||
|
|
||||||
@ -391,30 +360,26 @@ udp_send_data(struct ttcp* ttcp);
|
|||||||
* Only used in UDP mode. Scheduled after data has been sent in udp_send_data()
|
* Only used in UDP mode. Scheduled after data has been sent in udp_send_data()
|
||||||
* if we have more data to send.
|
* if we have more data to send.
|
||||||
*/
|
*/
|
||||||
static void udp_timeout_cb(void *ctx)
|
static void udp_timeout_cb(void *ctx) {
|
||||||
{
|
struct ttcp* ttcp = ctx;
|
||||||
struct ttcp* ttcp = ctx;
|
udp_send_data(ttcp);
|
||||||
udp_send_data(ttcp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int udp_send_bytes(struct ttcp* ttcp, uint32_t len) {
|
||||||
|
struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||||
|
if (p == NULL) {
|
||||||
|
printk("TTCP [%p]: could not allocate pbuf\n", ttcp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
if (udp_send(ttcp->upcb, p) != ERR_OK) {
|
||||||
udp_send_bytes(struct ttcp* ttcp, uint32_t len)
|
printk("TTCP [%p]: udp_send() failed\n", ttcp);
|
||||||
{
|
pbuf_free(p);
|
||||||
struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
return -1;
|
||||||
if (p == NULL) {
|
}
|
||||||
printk("TTCP [%p]: could not allocate pbuf\n", ttcp);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (udp_send(ttcp->upcb, p) != ERR_OK) {
|
pbuf_free(p);
|
||||||
printk("TTCP [%p]: udp_send() failed\n", ttcp);
|
return 0;
|
||||||
pbuf_free(p);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pbuf_free(p);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -422,259 +387,230 @@ udp_send_bytes(struct ttcp* ttcp, uint32_t len)
|
|||||||
* ttcp data has been sent, a number of end markers will be sent. After
|
* ttcp data has been sent, a number of end markers will be sent. After
|
||||||
* end marker transmission, this function will complete the ttcp process.
|
* end marker transmission, this function will complete the ttcp process.
|
||||||
*/
|
*/
|
||||||
static void
|
static void udp_send_data(struct ttcp* ttcp) {
|
||||||
udp_send_data(struct ttcp* ttcp)
|
/* send start marker first time */
|
||||||
{
|
if (!ttcp->udp_started) {
|
||||||
/* send start marker first time */
|
if (udp_send_bytes(ttcp, 4) == 0) {
|
||||||
if (!ttcp->udp_started) {
|
ttcp->udp_started = 1;
|
||||||
if (udp_send_bytes(ttcp, 4) == 0) {
|
ttcp->start_time = timer_get_ms();
|
||||||
ttcp->udp_started = 1;
|
}
|
||||||
ttcp->start_time = timer_get_ms();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* normal case */
|
/* normal case */
|
||||||
else if (ttcp->left) {
|
else if (ttcp->left) {
|
||||||
/* send data */
|
/* send data */
|
||||||
if (udp_send_bytes(ttcp, ttcp->buflen) == 0)
|
if (udp_send_bytes(ttcp, ttcp->buflen) == 0)
|
||||||
ttcp->left -= ttcp->buflen;
|
ttcp->left -= ttcp->buflen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end marker? */
|
/* end marker? */
|
||||||
else if (ttcp->left == 0 && ttcp->udp_end_marker_left) {
|
else if (ttcp->left == 0 && ttcp->udp_end_marker_left) {
|
||||||
if (udp_send_bytes(ttcp, 4) == 0)
|
if (udp_send_bytes(ttcp, 4) == 0)
|
||||||
ttcp->udp_end_marker_left--;
|
ttcp->udp_end_marker_left--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* all end markers sent */
|
/* all end markers sent */
|
||||||
else if (ttcp->left == 0) {
|
else if (ttcp->left == 0) {
|
||||||
ard_tcp_done(ttcp, 0);
|
ard_tcp_done(ttcp, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
|
ttcp->tid
|
||||||
udp_timeout_cb, ttcp);
|
= timer_sched_timeout_cb(0, TIMEOUT_ONESHOT, udp_timeout_cb, ttcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in UDP mode. Will finalize the ttcp process when an end marker
|
* Only used in UDP mode. Will finalize the ttcp process when an end marker
|
||||||
* is seen.
|
* is seen.
|
||||||
*/
|
*/
|
||||||
static void
|
static void udp_recv_cb(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||||
udp_recv_cb(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
struct ip_addr *addr, u16_t port) {
|
||||||
struct ip_addr *addr, u16_t port)
|
struct ttcp* ttcp = arg;
|
||||||
{
|
|
||||||
struct ttcp* ttcp = arg;
|
|
||||||
|
|
||||||
/* got start marker? we might lose this so if we get it just reset
|
/* got start marker? we might lose this so if we get it just reset
|
||||||
* the timer
|
* the timer
|
||||||
*/
|
*/
|
||||||
if (!ttcp->udp_started && p->tot_len <= 4) {
|
if (!ttcp->udp_started && p->tot_len <= 4) {
|
||||||
ttcp->start_time = timer_get_ms();
|
ttcp->start_time = timer_get_ms();
|
||||||
ttcp->udp_started = 1;
|
ttcp->udp_started = 1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* after receiving at least 1 byte, check end marker
|
/* after receiving at least 1 byte, check end marker
|
||||||
* don't check udp_started since we might have lost the start marker
|
* don't check udp_started since we might have lost the start marker
|
||||||
*/
|
*/
|
||||||
if (ttcp->recved && p->tot_len <= 4) {
|
if (ttcp->recved && p->tot_len <= 4) {
|
||||||
ard_tcp_done(ttcp, 0);
|
ard_tcp_done(ttcp, 0);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for print_stats() */
|
/* for print_stats() */
|
||||||
ttcp->recved += p->tot_len;
|
ttcp->recved += p->tot_len;
|
||||||
if (ttcp->verbose) {
|
if (ttcp->verbose) {
|
||||||
printk(".");
|
printk(".");
|
||||||
if (ttcp->print_cnt % 80 == 0)
|
if (ttcp->print_cnt % 80 == 0)
|
||||||
printk("\n");
|
printk("\n");
|
||||||
ttcp->print_cnt++;
|
ttcp->print_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out: pbuf_free(p);
|
||||||
pbuf_free(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start UDP transfer.
|
* Start UDP transfer.
|
||||||
*/
|
*/
|
||||||
static int
|
static int udp_start(struct ttcp* ttcp) {
|
||||||
udp_start(struct ttcp* ttcp)
|
|
||||||
{
|
|
||||||
ttcp->udp_end_marker_left = 5;
|
ttcp->udp_end_marker_left = 5;
|
||||||
ttcp->upcb = udp_new();
|
ttcp->upcb = udp_new();
|
||||||
if (ttcp->upcb == NULL) {
|
if (ttcp->upcb == NULL) {
|
||||||
printk("TTCP [%p]: could not allocate pcb\n", ttcp);
|
printk("TTCP [%p]: could not allocate pcb\n", ttcp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
||||||
if (udp_connect(ttcp->upcb, &ttcp->addr, ttcp->port) !=
|
if (udp_connect(ttcp->upcb, &ttcp->addr, ttcp->port) != ERR_OK) {
|
||||||
ERR_OK) {
|
printk("TTCP [%p]: udp connect failed\n", ttcp);
|
||||||
printk("TTCP [%p]: udp connect failed\n", ttcp);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
udp_send_data(ttcp);
|
||||||
udp_send_data(ttcp);
|
} else {
|
||||||
} else {
|
udp_recv(ttcp->upcb, udp_recv_cb, ttcp);
|
||||||
udp_recv(ttcp->upcb, udp_recv_cb, ttcp);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a new ttcp transfer. It should be possible to call this function
|
* Start a new ttcp transfer. It should be possible to call this function
|
||||||
* multiple times in order to get multiple ttcp streams. done_cb() will be
|
* multiple times in order to get multiple ttcp streams. done_cb() will be
|
||||||
* invoked upon completion.
|
* invoked upon completion.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int
|
int ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
|
||||||
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,
|
||||||
ard_tcp_done_cb_t *done_cb,
|
int udp, int verbose, uint8_t sock, void** _ttcp) {
|
||||||
int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose, uint8_t sock, void** _ttcp)
|
struct ttcp* ttcp;
|
||||||
{
|
int status;
|
||||||
struct ttcp* ttcp;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
if (mode != TTCP_MODE_TRANSMIT && mode != TTCP_MODE_RECEIVE) {
|
|
||||||
printk("TTCP [-]: invalid mode\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nbuf == 0) {
|
if (mode != TTCP_MODE_TRANSMIT && mode != TTCP_MODE_RECEIVE) {
|
||||||
printk("TTCP [-]: invalid nbuf\n");
|
printk("TTCP [-]: invalid mode\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buflen == 0) {
|
|
||||||
printk("TTCP [-]: invalid buflen\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ttcp = calloc(1, sizeof(struct ttcp));
|
if (nbuf == 0) {
|
||||||
if (ttcp == NULL) {
|
printk("TTCP [-]: invalid nbuf\n");
|
||||||
printk("TTCP [-]: could not allocate memory for ttcp\n");
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ttcp->addr = addr;
|
if (buflen == 0) {
|
||||||
ttcp->port = port;
|
printk("TTCP [-]: invalid buflen\n");
|
||||||
ttcp->nbuf = nbuf;
|
return -1;
|
||||||
ttcp->mode = mode;
|
}
|
||||||
ttcp->left = nbuf * buflen;
|
|
||||||
ttcp->done_cb = done_cb;
|
|
||||||
ttcp->opaque = opaque;
|
|
||||||
ttcp->udp = udp;
|
|
||||||
ttcp->verbose = verbose;
|
|
||||||
ttcp->buflen = buflen;
|
|
||||||
|
|
||||||
if (ttcp->udp)
|
|
||||||
status = udp_start(ttcp);
|
|
||||||
else
|
|
||||||
status = atcp_start(ttcp);
|
|
||||||
|
|
||||||
if (status)
|
ttcp = calloc(1, sizeof(struct ttcp));
|
||||||
{
|
if (ttcp == NULL) {
|
||||||
WARN("Start server FAILED!");
|
printk("TTCP [-]: could not allocate memory for ttcp\n");
|
||||||
goto fail;
|
return -1;
|
||||||
}
|
}
|
||||||
printk("TTCP [%p-%p]: nbuf=%d, buflen=%d, port=%d (%s/%s)\n",
|
|
||||||
ttcp, ttcp->tpcb, ttcp->nbuf, ttcp->buflen, ttcp->port,
|
|
||||||
ttcp->udp ? "udp" : "tcp",
|
|
||||||
ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx");
|
|
||||||
|
|
||||||
*_ttcp = (void*)ttcp;
|
ttcp->addr = addr;
|
||||||
ttcp->sock = sock;
|
ttcp->port = port;
|
||||||
ttcp->buff_sent = 1;
|
ttcp->nbuf = nbuf;
|
||||||
|
ttcp->mode = mode;
|
||||||
|
ttcp->left = nbuf * buflen;
|
||||||
|
ttcp->done_cb = done_cb;
|
||||||
|
ttcp->opaque = opaque;
|
||||||
|
ttcp->udp = udp;
|
||||||
|
ttcp->verbose = verbose;
|
||||||
|
ttcp->buflen = buflen;
|
||||||
|
|
||||||
return 0;
|
if (ttcp->udp)
|
||||||
|
status = udp_start(ttcp);
|
||||||
|
else
|
||||||
|
status = atcp_start(ttcp);
|
||||||
|
|
||||||
fail:
|
if (status) {
|
||||||
ard_tcp_destroy(ttcp);
|
WARN("Start server FAILED!");
|
||||||
return -1;
|
goto fail;
|
||||||
|
}
|
||||||
|
printk("TTCP [%p-%p]: nbuf=%d, buflen=%d, port=%d (%s/%s)\n", ttcp,
|
||||||
|
ttcp->tpcb, ttcp->nbuf, ttcp->buflen, ttcp->port, ttcp->udp ? "udp"
|
||||||
|
: "tcp", ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx");
|
||||||
|
|
||||||
|
*_ttcp = (void*) ttcp;
|
||||||
|
ttcp->sock = sock;
|
||||||
|
ttcp->buff_sent = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail: ard_tcp_destroy(ttcp);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void close_conn(struct ttcp *_ttcp) {
|
||||||
close_conn(struct ttcp *_ttcp)
|
|
||||||
{
|
|
||||||
ard_tcp_done(_ttcp, 0);
|
ard_tcp_done(_ttcp, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ard_tcp_stop(void* ttcp) {
|
||||||
void ard_tcp_stop(void* ttcp)
|
struct ttcp* _ttcp = (struct ttcp*) ttcp;
|
||||||
{
|
|
||||||
struct ttcp* _ttcp = (struct ttcp*)ttcp;
|
|
||||||
printk("Stop client %p-%p-%p\n", _ttcp, _ttcp->tpcb, _ttcp->lpcb);
|
printk("Stop client %p-%p-%p\n", _ttcp, _ttcp->tpcb, _ttcp->lpcb);
|
||||||
close_conn(_ttcp);
|
close_conn(_ttcp);
|
||||||
asm("nop");
|
//asm("nop");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getStateTcp(void* p, bool client)
|
uint8_t getStateTcp(void* p, bool client) {
|
||||||
{
|
struct ttcp* _ttcp = (struct ttcp*) p;
|
||||||
struct ttcp* _ttcp = (struct ttcp*)p;
|
|
||||||
|
|
||||||
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL))
|
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL)) {
|
||||||
{
|
// INFO("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d\n",
|
||||||
// INFO("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d\n",
|
// p, _ttcp->tpcb, _ttcp->tpcb->state,
|
||||||
// p, _ttcp->tpcb, _ttcp->tpcb->state,
|
// _ttcp->lpcb, _ttcp->lpcb->state);
|
||||||
// _ttcp->lpcb, _ttcp->lpcb->state);
|
|
||||||
if (client)
|
if (client)
|
||||||
return _ttcp->tpcb->state;
|
return _ttcp->tpcb->state;
|
||||||
else
|
else
|
||||||
return _ttcp->lpcb->state;
|
return _ttcp->lpcb->state;
|
||||||
}else{
|
} else {
|
||||||
WARN("TCP not initialized ttcp:%p tpcb:%p lpcb:%p\n",
|
WARN("TCP not initialized ttcp:%p tpcb:%p lpcb:%p\n",
|
||||||
_ttcp, ((_ttcp)?_ttcp->tpcb:0), ((_ttcp)?_ttcp->lpcb:0));
|
_ttcp, ((_ttcp)?_ttcp->tpcb:0), ((_ttcp)?_ttcp->lpcb:0));
|
||||||
}
|
}
|
||||||
return CLOSED;
|
return CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isDataSent(void* p )
|
uint8_t isDataSent(void* p) {
|
||||||
{
|
struct ttcp* _ttcp = (struct ttcp*) p;
|
||||||
struct ttcp* _ttcp = (struct ttcp*)p;
|
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL)) {
|
||||||
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL))
|
|
||||||
{
|
|
||||||
//INFO("ttcp:%p tpcb:%p sent:%d\n",p, _ttcp->tpcb, _ttcp->buff_sent);
|
//INFO("ttcp:%p tpcb:%p sent:%d\n",p, _ttcp->tpcb, _ttcp->buff_sent);
|
||||||
return _ttcp->buff_sent;
|
return _ttcp->buff_sent;
|
||||||
}else{
|
} else {
|
||||||
WARN("TCP null!\n");
|
WARN("TCP null!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len) {
|
||||||
|
struct ttcp *_ttcp;
|
||||||
|
|
||||||
static err_t
|
LWIP_UNUSED_ARG(len);
|
||||||
tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
|
|
||||||
{
|
|
||||||
struct ttcp *_ttcp;
|
|
||||||
|
|
||||||
LWIP_UNUSED_ARG(len);
|
_ttcp = arg;
|
||||||
|
|
||||||
_ttcp = arg;
|
if (_ttcp->left > 0) {
|
||||||
|
//send_data(pcb, hs);
|
||||||
if (_ttcp->left > 0) {
|
INFO("data left: %d", _ttcp->left );
|
||||||
//send_data(pcb, hs);
|
}
|
||||||
INFO("data left: %d", _ttcp->left );
|
_ttcp->buff_sent = 1;
|
||||||
}
|
//INFO("%s: duration: %d\n", __FUNCTION__, timer_get_ms() - startTime);
|
||||||
_ttcp->buff_sent = 1;
|
return ERR_OK;
|
||||||
//INFO("%s: duration: %d\n", __FUNCTION__, timer_get_ms() - startTime);
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sendTcpData(void* p, uint8_t* buf, uint16_t len)
|
int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
|
||||||
{
|
|
||||||
//INFO("buf:%p len:%d\n", buf, len);
|
//INFO("buf:%p len:%d\n", buf, len);
|
||||||
//DUMP(buf,len);
|
//DUMP(buf,len);
|
||||||
|
|
||||||
startTime = timer_get_ms();
|
startTime = timer_get_ms();
|
||||||
struct ttcp* _ttcp = (struct ttcp*)p;
|
struct ttcp* _ttcp = (struct ttcp*) p;
|
||||||
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL)&&(buf!=NULL)&&(len!=0))
|
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL) && (buf != NULL) && (len != 0)) {
|
||||||
{
|
|
||||||
_ttcp->buff_sent = 0;
|
_ttcp->buff_sent = 0;
|
||||||
//pbuf_take(buf, len, _ttcp->);
|
//pbuf_take(buf, len, _ttcp->);
|
||||||
memcpy(_ttcp->payload, buf, len);
|
memcpy(_ttcp->payload, buf, len);
|
||||||
@ -687,7 +623,9 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len)
|
|||||||
return WL_FAILURE;
|
return WL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char usage[] = "Usage: ttcp -t/-r [-options] host\n\
|
char
|
||||||
|
usage[] =
|
||||||
|
"Usage: ttcp -t/-r [-options] host\n\
|
||||||
-l length of bufs written to network (default 1024)\n\
|
-l length of bufs written to network (default 1024)\n\
|
||||||
-n number of bufs written to network (default 1024)\n\
|
-n number of bufs written to network (default 1024)\n\
|
||||||
-p port number to send to (default 2000)\n\
|
-p port number to send to (default 2000)\n\
|
||||||
@ -697,67 +635,64 @@ char usage[] = "Usage: ttcp -t/-r [-options] host\n\
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cmd_state_t
|
cmd_state_t cmd_ttcp(int argc, char* argv[], void* ctx) {
|
||||||
cmd_ttcp(int argc, char* argv[], void* ctx)
|
|
||||||
{
|
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
int mode = TTCP_MODE_TRANSMIT;
|
int mode = TTCP_MODE_TRANSMIT;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
uint16_t buflen = 1024;
|
uint16_t buflen = 1024;
|
||||||
uint16_t nbuf = 1024;
|
uint16_t nbuf = 1024;
|
||||||
uint16_t port = 2000;
|
uint16_t port = 2000;
|
||||||
int udp = 0;
|
int udp = 0;
|
||||||
struct ip_addr addr = { 0 };
|
struct ip_addr addr = { 0 };
|
||||||
|
|
||||||
optind = 1;
|
optind = 1;
|
||||||
while ((c = getopt(argc, argv, "utrl:n:p:v")) != -1) {
|
while ((c = getopt(argc, argv, "utrl:n:p:v")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 't':
|
case 't':
|
||||||
mode = TTCP_MODE_TRANSMIT;
|
mode = TTCP_MODE_TRANSMIT;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
mode = TTCP_MODE_RECEIVE;
|
mode = TTCP_MODE_RECEIVE;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
buflen = atoi(optarg);
|
buflen = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nbuf = atoi(optarg);
|
nbuf = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
udp = 1;
|
udp = 1;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
port = atoi(optarg);
|
port = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == TTCP_MODE_TRANSMIT) {
|
if (mode == TTCP_MODE_TRANSMIT) {
|
||||||
if (optind >= argc) {
|
if (optind >= argc) {
|
||||||
printk("%s", usage);
|
printk("%s", usage);
|
||||||
return CMD_DONE;
|
return CMD_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = str2ip(argv[optind]);
|
addr = str2ip(argv[optind]);
|
||||||
if (!addr.addr) {
|
if (!addr.addr) {
|
||||||
printk("%s", usage);
|
printk("%s", usage);
|
||||||
return CMD_DONE;
|
return CMD_DONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void* _ttcp = NULL;
|
void* _ttcp = NULL;
|
||||||
if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp,
|
if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose,
|
||||||
verbose,0,&_ttcp))
|
0, &_ttcp))
|
||||||
return CMD_DONE;
|
return CMD_DONE;
|
||||||
|
|
||||||
return CMD_DONE;
|
return CMD_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#include "lwip/sockets.h"
|
#include "lwip/sockets.h"
|
||||||
|
|
||||||
@ -765,13 +700,13 @@ void testlwip()
|
|||||||
{
|
{
|
||||||
int Sock;
|
int Sock;
|
||||||
fd_set fdsetR;
|
fd_set fdsetR;
|
||||||
FD_ZERO(&fdsetR);
|
FD_ZERO(&fdsetR);
|
||||||
FD_SET(Sock, &fdsetR);
|
FD_SET(Sock, &fdsetR);
|
||||||
fd_set fdsetE = fdsetR;
|
fd_set fdsetE = fdsetR;
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
const int cMillies = 10000;
|
const int cMillies = 10000;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
timeout.tv_sec = cMillies / 1000;
|
timeout.tv_sec = cMillies / 1000;
|
||||||
timeout.tv_usec = (cMillies % 1000) * 1000;
|
timeout.tv_usec = (cMillies % 1000) * 1000;
|
||||||
//rc = lwip_select(Sock + 1, &fdsetR, NULL, &fdsetE, &timeout);
|
//rc = lwip_select(Sock + 1, &fdsetR, NULL, &fdsetE, &timeout);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#define ARD_UTILS_H_
|
#define ARD_UTILS_H_
|
||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "arduino/arduino.h"
|
#include "ARDUINO/arduino.h"
|
||||||
#define INIT_SIGNAL_FOR_SPI() gpio_enable_pin_pull_up(ARDUINO_HANDSHAKE_PIN)
|
#define INIT_SIGNAL_FOR_SPI() gpio_enable_pin_pull_up(ARDUINO_HANDSHAKE_PIN)
|
||||||
#define BUSY_FOR_SPI() gpio_set_gpio_pin(ARDUINO_HANDSHAKE_PIN)
|
#define BUSY_FOR_SPI() gpio_set_gpio_pin(ARDUINO_HANDSHAKE_PIN)
|
||||||
#define AVAIL_FOR_SPI() gpio_clr_gpio_pin(ARDUINO_HANDSHAKE_PIN)
|
#define AVAIL_FOR_SPI() gpio_clr_gpio_pin(ARDUINO_HANDSHAKE_PIN)
|
||||||
|
@ -423,8 +423,8 @@
|
|||||||
|
|
||||||
#undef DHCP_DOES_ARP_CHECK
|
#undef DHCP_DOES_ARP_CHECK
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
#define LWIP_DEBUG 1
|
#define LWIP_DEBUG 0
|
||||||
//#define NETIF_DEBUG LWIP_DBG_ON
|
//#define NETIF_DEBUG LWIP_DBG_ON
|
||||||
//#define DHCP_DEBUG LWIP_DBG_ON
|
//#define DHCP_DEBUG LWIP_DBG_ON
|
||||||
//#define ICMP_DEBUG LWIP_DBG_ON
|
//#define ICMP_DEBUG LWIP_DBG_ON
|
||||||
|
Loading…
Reference in New Issue
Block a user