diff options
author | Mimmo La Fauci <mlafauci@metodo2.it> | 2013-03-10 22:55:21 +0100 |
---|---|---|
committer | Mimmo La Fauci <mlafauci@metodo2.it> | 2013-03-10 22:55:21 +0100 |
commit | 8c5d809280904562aee082e2eab4ceb9f8523d9d (patch) | |
tree | d69ee3969dae33cf29f44832d66d7c112d4e418a /firmwares/wifishield/wifiHD/src/cmd_wl.c | |
parent | fb1abe737ed23c57a3208d603933dd68138ad022 (diff) |
Updates to WiFi shield firmware.
Diffstat (limited to 'firmwares/wifishield/wifiHD/src/cmd_wl.c')
-rw-r--r-- | firmwares/wifishield/wifiHD/src/cmd_wl.c | 165 |
1 files changed, 127 insertions, 38 deletions
diff --git a/firmwares/wifishield/wifiHD/src/cmd_wl.c b/firmwares/wifishield/wifiHD/src/cmd_wl.c index 61634ef..3356931 100644 --- a/firmwares/wifishield/wifiHD/src/cmd_wl.c +++ b/firmwares/wifishield/wifiHD/src/cmd_wl.c @@ -43,24 +43,11 @@ #include "lwip/dns.h" #include "debug.h" #include "ard_spi.h" +#include "ard_tcp.h" +#include "ard_utils.h" 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); - #define _DNS_CMD_ /** @@ -373,14 +360,15 @@ cmd_setDnsServer(int argc, char* argv[], void* ctx) * */ cmd_state_t -cmd_startTcpSrv(int argc, char* argv[], void* ctx) +cmd_startSrv(int argc, char* argv[], void* ctx) { - const char *usage = "usage: startTcpSrv <port> <sock>\n"; + const char *usage = "usage: startSrv <port> <sock> <tcp(0)/udp(1)>\n"; int port = 0; int sock = 0; + int protMode = 0; - if (argc < 3) { + if (argc < 4) { printk(usage); return CMD_DONE; } @@ -389,15 +377,50 @@ cmd_startTcpSrv(int argc, char* argv[], void* ctx) port = atoi(argv[1]); /* socket index */ sock = atoi(argv[2]); + /* Protocol Mode */ + protMode = atoi(argv[3]); - printk("Start TCP server on port %d sock %d\n", port, sock); - if (start_server_tcp(port, sock) != -1) + printk("Start %s server on port %d sock %d\n", ProtMode2Str(protMode), port, sock); + if (start_server_tcp(port, sock, protMode) == -1) { - printk("Start TCP server on port %d sock %d FAILED\n", port, sock); + WARN("Start %s server on port %d sock %d FAILED\n", ProtMode2Str(protMode), port, sock); } return CMD_DONE; } +/** + * + */ +cmd_state_t +cmd_startCli(int argc, char* argv[], void* ctx) +{ + const char *usage = "usage: startCli <ipaddr> <port> <sock> <tcp(0)/udp(1)>\n"; + struct ip_addr addr = {0}; + int port = 0; + int sock = 0; + int protMode = 0; + + if (argc < 5) { + printk(usage); + return CMD_DONE; + } + + /* IP address */ + addr = str2ip(argv[1]); + /* TCP port */ + port = atoi(argv[2]); + /* socket index */ + sock = atoi(argv[3]); + /* Protocol Mode */ + protMode = atoi(argv[4]); + + printk("Start client on addr 0x%x, port %d sock %d mode %d\n", addr, port, sock, protMode); + if (start_client_tcp(addr.addr, port, sock, protMode) == -1) + { + WARN("Start client on port %d sock %d prot %d mode %d FAILED\n", port, sock, protMode); + } + return CMD_DONE; +} #endif @@ -595,16 +618,14 @@ cmd_debug(int argc, char* argv[], void* ctx) if (argc == 2 && strcmp(argv[1], "off") == 0) { printk("Debug OFF\n"); - enableDebug = DEFAULT_INFO_FLAG; - verboseDebug = 0; + INIT_DEBUG_VARIABLES() 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); + PRINT_DEBUG_VARIABLES() return CMD_DONE; }else if (argc == 2 && strcmp(argv[1], "on") == 0) { printk("Debug ON\n"); - enableDebug = 0xff; + TURNON_DEBUG_VARIABLES(); return CMD_DONE; } if (argc < 3) { @@ -613,23 +634,91 @@ cmd_debug(int argc, char* argv[], void* ctx) } level = atoi(argv[2]); if (argc == 3 && strcmp(argv[1], "init") == 0) { - CHECK_ENA_DEBUG(level, INFO_INIT_FLAG); - CHECK_VERB_DEBUG(level, INFO_INIT_FLAG); + CHECK_DEBUG_LEVEL(level, INFO_INIT_FLAG); }else if (argc == 3 && strcmp(argv[1], "spi") == 0) { - CHECK_ENA_DEBUG(level, INFO_SPI_FLAG); - CHECK_VERB_DEBUG(level, INFO_SPI_FLAG); + CHECK_DEBUG_LEVEL(level, INFO_SPI_FLAG); }else if (argc == 3 && strcmp(argv[1], "tcp") == 0) { - CHECK_ENA_DEBUG(level, INFO_TCP_FLAG); - CHECK_VERB_DEBUG(level, INFO_TCP_FLAG); + CHECK_DEBUG_LEVEL(level, INFO_TCP_FLAG); }else if (argc == 3 && strcmp(argv[1], "cm") == 0) { - CHECK_ENA_DEBUG(level, INFO_CM_FLAG); - CHECK_VERB_DEBUG(level, INFO_CM_FLAG); + CHECK_DEBUG_LEVEL(level, INFO_CM_FLAG); }else if (argc == 3 && strcmp(argv[1], "util") == 0) { - CHECK_ENA_DEBUG(level, INFO_UTIL_FLAG); - CHECK_VERB_DEBUG(level, INFO_UTIL_FLAG); + CHECK_DEBUG_LEVEL(level, INFO_UTIL_FLAG); }else if (argc == 3 && strcmp(argv[1], "warn") == 0) { - CHECK_ENA_DEBUG(level, INFO_WARN_FLAG); - CHECK_VERB_DEBUG(level, INFO_WARN_FLAG); + CHECK_DEBUG_LEVEL(level, INFO_WARN_FLAG); } return CMD_DONE; } + +extern void dumpPbuf(uint8_t sock); + +/** + * + */ +cmd_state_t +cmd_dumpBuf(int argc, char* argv[], void* ctx) +{ + const char *usage = "usage: dumpPbuf [sock]\n\t"\ + "sock: socket Number\n"; + + if (argc == 2 && strcmp(argv[1], "all") == 0) { + printk("Dump All Buffers\n"); + int i = 0; + for (; i<MAX_SOCK_NUM; ++i) + { + printk("Socket: %d\n", i); + dumpPbuf(i); + } + }else if (argc == 2) { + uint8_t sock = atoi(argv[1]); + printk("Socket: %d\n", sock); + dumpPbuf(sock); + }else { + printk(usage); + } + return CMD_DONE; +} + + + +/** + * + */ +cmd_state_t +cmd_sendUdpData(int argc, char* argv[], void* ctx) +{ + const char pattern[]={'M', 'I', 'M', 'L', 'F', 'D'}; + const char* pattern2[]={"Prova", "1234567890","FineTest"}; + const char *usage = "usage: sendUdp [sock]\n\t"\ + "sock: socket Number\n"; + + if (argc < 2) + printk(usage); + + if (argc >= 2) { + + uint8_t sock = atoi(argv[1]); + printk("Socket: %d\n", sock); + + if (argc >= 3) { + uint8_t patternType = atoi(argv[2]); + printk("PatternType: %d\n", patternType); + if (patternType == 1) + { + insertBuf(sock, (uint8_t*)pattern2[0], strlen(pattern2[0])); + insertBuf(sock, (uint8_t*)pattern2[1], strlen(pattern2[1])); + insertBuf(sock, (uint8_t*)pattern2[2], strlen(pattern2[2])); + } + if (patternType == 2) + { + mergeBuf(sock, NULL, NULL); + } + }else{ + if (sock < MAX_SOCK_NUM) + { + sendUdpData(getTTCP(sock, TTCP_MODE_TRANSMIT), (uint8_t*)pattern, sizeof(pattern)/sizeof(char)); + } + } + + } + return CMD_DONE; +} |