1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Add some console commands

This commit is contained in:
Mimmo La Fauci 2012-05-22 17:45:51 +02:00
parent 7791271e8e
commit 5e1624a5e4
6 changed files with 110 additions and 53 deletions

View File

@ -189,6 +189,13 @@ int getSock(void * _ttcp)
return -1; return -1;
} }
void setMapSock(uint8_t sock, void* _ttcp)
{
if (sock < MAX_SOCK_NUM)
mapSockTCP[sock]=_ttcp;
printk("Map [%d, %p]\n", sock, _ttcp);
}
void clearMapSockTcp(uint8_t sock) void clearMapSockTcp(uint8_t sock)
{ {
if (sock < MAX_SOCK_NUM) if (sock < MAX_SOCK_NUM)
@ -197,7 +204,7 @@ void clearMapSockTcp(uint8_t sock)
void initMapSockTcp() void initMapSockTcp()
{ {
memset(mapSockTCP, 0, sizeof(void*)*MAX_SOCK_NUM); memset(mapSockTCP, 0, sizeof(mapSockTCP));
} }
/** /**
@ -222,16 +229,16 @@ void showTTCPstatus()
int i = 0; int i = 0;
for (; i<MAX_SOCK_NUM; i++) for (; i<MAX_SOCK_NUM; i++)
{ {
void* p = mapSockTCP[i]; void* p = getTTCP(i);
if (p) if (p)
{ {
ttcp_t* _ttcp = (ttcp_t* )p; ttcp_t* _ttcp = (ttcp_t* )p;
printk("Socket n.:%d addr:0x%x port:%d\n", i, _ttcp->addr, _ttcp->port); printk("Socket n.:%d addr:0x%x port:%d\n", i, _ttcp->addr, _ttcp->port);
if (_ttcp->tpcb){ if (_ttcp->tpcb){
printk("[tpcp]-Status:%d\n", _ttcp->tpcb->state); printk("[tpcp-%p]-Status:%d\n", _ttcp->tpcb, _ttcp->tpcb->state);
} }
if (_ttcp->lpcb){ if (_ttcp->lpcb){
printk("[tlcp]-Status:%d\n", _ttcp->lpcb->state); printk("[tlcp-%p]-Status:%d\n", _ttcp->lpcb, _ttcp->lpcb->state);
} }
ard_tcp_print_stats(_ttcp); ard_tcp_print_stats(_ttcp);
} }
@ -594,17 +601,14 @@ void set_result_cmd(int err)
extern int ttcp_start(struct ip_addr addr, uint16_t port, void *opaque, extern int ttcp_start(struct ip_addr addr, uint16_t port, void *opaque,
void *done_cb, int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose); void *done_cb, int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose);
int start_server_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
wl_err_t err = WL_FAILURE;
tParam* params = (tParam*) buf;
if (numParam == 2)
{
GET_PARAM_NEXT(INT, params, port);
GET_PARAM_NEXT(BYTE, params, sock);
int start_server_tcp(uint16_t port, uint8_t sock)
{
struct ip_addr addr = { 0 }; struct ip_addr addr = { 0 };
uint16_t buflen = 1024; uint16_t buflen = 1024;
uint16_t nbuf = 1024; uint16_t nbuf = 1024;
wl_err_t err = WL_FAILURE;
#ifdef _APP_DEBUG_ #ifdef _APP_DEBUG_
int verbose = 1; int verbose = 1;
#else #else
@ -617,14 +621,33 @@ int start_server_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
if (sock >= MAX_SOCK_NUM) if (sock >= MAX_SOCK_NUM)
return WIFI_SPI_ERR; return WIFI_SPI_ERR;
INFO_SPI("Start Server [%d, %d]\n", port, sock); if (_connected)
{
printk("Still connected...wait\n");
return WIFI_SPI_ERR;
}
if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose, sock, &_ttcp) == 0) if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose, sock, &_ttcp) == 0)
{ {
if (sock < MAX_SOCK_NUM) INFO_SPI("Start Server [%d, %d] OK!\n", port, sock);
mapSockTCP[sock]=_ttcp; setMapSock(sock, _ttcp);
INFO_SPI("Map [%d, %p]\n", sock, _ttcp);
err = WL_SUCCESS; err = WL_SUCCESS;
}else{
INFO_SPI("Start Server [%d, %d] FAILED!\n", port, sock);
clearMapSockTcp(sock);
} }
return err;
}
int start_server_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
wl_err_t err = WL_FAILURE;
tParam* params = (tParam*) buf;
if (numParam == 2)
{
GET_PARAM_NEXT(INT, params, port);
GET_PARAM_NEXT(BYTE, params, sock);
err = start_server_tcp(port, sock);
} }
return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR; return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR;
} }
@ -655,15 +678,14 @@ int start_client_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
if (sock >= MAX_SOCK_NUM) if (sock >= MAX_SOCK_NUM)
return WIFI_SPI_ERR; return WIFI_SPI_ERR;
INFO_SPI("Start Client [0x%x, %d, %d]\n", addr, port, sock);
if (ard_tcp_start((struct ip_addr)addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose, sock, &_ttcp) == 0) if (ard_tcp_start((struct ip_addr)addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose, sock, &_ttcp) == 0)
{ {
if (sock < MAX_SOCK_NUM) INFO_SPI("Start Client [0x%x, %d, %d] OK!\n", addr, port, sock);
mapSockTCP[sock]=_ttcp; setMapSock(sock, _ttcp);
INFO_SPI("Map [%d, %p]\n", sock, _ttcp);
err = WL_SUCCESS; err = WL_SUCCESS;
}else{ }else{
mapSockTCP[sock]=0; INFO_SPI("Start Client [0x%x, %d, %d] FAILED!\n", addr, port, sock);
clearMapSockTcp(sock);
} }
} }
return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR; return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR;
@ -682,9 +704,8 @@ int stop_client_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
if (sock < MAX_SOCK_NUM) if (sock < MAX_SOCK_NUM)
{ {
_ttcp = mapSockTCP[sock]; _ttcp = getTTCP(sock);
ard_tcp_stop(_ttcp); ard_tcp_stop(_ttcp);
mapSockTCP[sock]=0;
err = WL_SUCCESS; err = WL_SUCCESS;
} }
} }
@ -1032,10 +1053,11 @@ cmd_spi_state_t get_state_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_
uint8_t _state = CLOSED; uint8_t _state = CLOSED;
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM)) if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
{ {
_state = getStateTcp(mapSockTCP[(uint8_t)recv[4]], 0); _state = getStateTcp(getTTCP((uint8_t)recv[4]), 0);
} }
PUT_DATA_BYTE(_state, reply, 3); PUT_DATA_BYTE(_state, reply, 3);
END_HEADER_REPLY(reply, 5, *count); END_HEADER_REPLY(reply, 5, *count);
INFO_SPI("state:%d\n", _state);
return SPI_CMD_DONE; return SPI_CMD_DONE;
} }
@ -1049,7 +1071,7 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx,
uint8_t _state = CLOSED; uint8_t _state = CLOSED;
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM)) if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
{ {
void * p= mapSockTCP[(uint8_t)recv[4]]; void * p= getTTCP((uint8_t)recv[4]);
// get if we are in server or Transmit mode (0) // get if we are in server or Transmit mode (0)
if (getModeTcp(p) == TTCP_MODE_TRANSMIT) if (getModeTcp(p) == TTCP_MODE_TRANSMIT)
{ {
@ -1067,6 +1089,7 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx,
} }
PUT_DATA_BYTE(_state, reply, 3); PUT_DATA_BYTE(_state, reply, 3);
END_HEADER_REPLY(reply, 5, *count); END_HEADER_REPLY(reply, 5, *count);
INFO_SPI("state:%d\n", _state);
return SPI_CMD_DONE; return SPI_CMD_DONE;
} }
@ -1084,6 +1107,9 @@ cmd_spi_state_t avail_data_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16
} }
PUT_DATA_BYTE(dataAvail, reply, 3); PUT_DATA_BYTE(dataAvail, reply, 3);
END_HEADER_REPLY(reply, 5, *count); END_HEADER_REPLY(reply, 5, *count);
INFO_SPI("dataAvail:%d\n", dataAvail);
return SPI_CMD_DONE; return SPI_CMD_DONE;
} }
@ -1128,7 +1154,7 @@ cmd_spi_state_t data_sent_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_
uint8_t dataSent = 0; uint8_t dataSent = 0;
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM)) if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
{ {
dataSent = isDataSent(mapSockTCP[(uint8_t)recv[4]]); dataSent = isDataSent(getTTCP((uint8_t)recv[4]));
} }
PUT_DATA_BYTE(dataSent, reply, 3); PUT_DATA_BYTE(dataSent, reply, 3);
END_HEADER_REPLY(reply, 5, *count); END_HEADER_REPLY(reply, 5, *count);
@ -1509,7 +1535,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi, bool startRecvd)
} }
/* break on buffer overflow */ /* break on buffer overflow */
if (receivedChars > _BUFFERSIZE) { if (receivedChars >= _BUFFERSIZE) {
err = SPI_ERROR_OVERRUN_AND_MODE_FAULT; err = SPI_ERROR_OVERRUN_AND_MODE_FAULT;
break; break;
} }
@ -1683,9 +1709,9 @@ int initSpi()
#endif #endif
init_spi_cmds(); init_spi_cmds();
memset(_receiveBuffer, 0, _BUFFERSIZE); memset(_receiveBuffer, 0, sizeof(_receiveBuffer));
memset(buf, 0, CMD_MAX_LEN); memset(buf, 0, sizeof(buf));
memset(reply, 0, REPLY_MAX_LEN); memset(reply, 0, sizeof(reply));
initMapSockTcp(); initMapSockTcp();

View File

@ -56,18 +56,12 @@ void spi_poll(struct netif* netif);
int spi_slaveReceive(volatile avr32_spi_t *spi); int spi_slaveReceive(volatile avr32_spi_t *spi);
cmd_state_t cmd_statSpi(int argc, char* argv[], void* ctx);
cmd_state_t cmd_resetStatSpi(int argc, char* argv[], void* ctx);
cmd_state_t cmd_gethostbyname(int argc, char* argv[], void* ctx);
cmd_state_t cmd_setDnsServer(int argc, char* argv[], void* ctx);
void showTTCPstatus(); void showTTCPstatus();
int getSock(void * _ttcp); int getSock(void * _ttcp);
void clearMapSockTcp(uint8_t sock); void clearMapSockTcp(uint8_t sock);
int start_server_tcp(uint16_t port, uint8_t sock);
#endif /* ARD_SPI_H_ */ #endif /* ARD_SPI_H_ */

View File

@ -42,6 +42,7 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/dns.h" #include "lwip/dns.h"
#include "debug.h" #include "debug.h"
#include "ard_spi.h"
extern void showTTCPstatus(); extern void showTTCPstatus();
@ -368,6 +369,36 @@ cmd_setDnsServer(int argc, char* argv[], void* ctx)
return CMD_DONE; return CMD_DONE;
} }
/**
*
*/
cmd_state_t
cmd_startTcpSrv(int argc, char* argv[], void* ctx)
{
const char *usage = "usage: startTcpSrv <port> <sock>\n";
int port = 0;
int sock = 0;
if (argc < 3) {
printk(usage);
return CMD_DONE;
}
/* TCP port */
port = atoi(argv[1]);
/* socket index */
sock = atoi(argv[2]);
printk("Start TCP server on port %d sock %d\n", port, sock);
if (start_server_tcp(port, sock) != -1)
{
printk("Start TCP server on port %d sock %d FAILED\n", port, sock);
}
return CMD_DONE;
}
#endif #endif

View File

@ -50,6 +50,11 @@ cmd_state_t cmd_setpass(int argc, char* argv[], void* ctx);
cmd_state_t cmd_delpass(int argc, char* argv[], void* ctx); cmd_state_t cmd_delpass(int argc, char* argv[], void* ctx);
cmd_state_t cmd_debug(int argc, char* argv[], void* ctx); cmd_state_t cmd_debug(int argc, char* argv[], void* ctx);
cmd_state_t cmd_debug_toggle(int argc, char* argv[], void* ctx); cmd_state_t cmd_debug_toggle(int argc, char* argv[], void* ctx);
cmd_state_t cmd_statSpi(int argc, char* argv[], void* ctx);
cmd_state_t cmd_resetStatSpi(int argc, char* argv[], void* ctx);
cmd_state_t cmd_gethostbyname(int argc, char* argv[], void* ctx);
cmd_state_t cmd_setDnsServer(int argc, char* argv[], void* ctx);
cmd_state_t cmd_startTcpSrv(int argc, char* argv[], void* ctx);
#ifdef WFE_6_12 #ifdef WFE_6_12
cmd_state_t cmd_ibss(int argc, char* argv[], void* ctx); cmd_state_t cmd_ibss(int argc, char* argv[], void* ctx);
#endif #endif

View File

@ -424,7 +424,7 @@
#undef DHCP_DOES_ARP_CHECK #undef DHCP_DOES_ARP_CHECK
#if 0 #if 0
//#define LWIP_DEBUG 1 #define LWIP_DEBUG 1
//#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
@ -434,8 +434,8 @@
//#define TCP_CWND_DEBUG LWIP_DBG_ON //#define TCP_CWND_DEBUG LWIP_DBG_ON
//#define ETHARP_DEBUG LWIP_DBG_ON //#define ETHARP_DEBUG LWIP_DBG_ON
//#define PBUF_DEBUG LWIP_DBG_ON //#define PBUF_DEBUG LWIP_DBG_ON
//#define TCP_INPUT_DEBUG LWIP_DBG_ON #define TCP_INPUT_DEBUG LWIP_DBG_ON
//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON #define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#endif #endif
#define ETH_PAD_SIZE WL_HEADER_SIZE /* size of wifiengine header */ #define ETH_PAD_SIZE WL_HEADER_SIZE /* size of wifiengine header */

View File

@ -302,6 +302,7 @@ void initShell()
#ifdef _DNS_CMD_ #ifdef _DNS_CMD_
console_add_cmd("getHost", cmd_gethostbyname, NULL); console_add_cmd("getHost", cmd_gethostbyname, NULL);
console_add_cmd("setDNS", cmd_setDnsServer, NULL); console_add_cmd("setDNS", cmd_setDnsServer, NULL);
console_add_cmd("startTcpSrv", cmd_startTcpSrv, NULL);
#endif #endif
} }