Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of NNN40_CLI by
Diff: CLI_Source/wifi_cli.cpp
- Revision:
- 12:a91455702763
- Parent:
- 10:5f1fa331d07c
- Child:
- 13:7eaec228ad23
diff -r ea5ed0d37456 -r a91455702763 CLI_Source/wifi_cli.cpp
--- a/CLI_Source/wifi_cli.cpp Tue Jan 26 09:36:28 2016 +0000
+++ b/CLI_Source/wifi_cli.cpp Thu Feb 18 07:59:26 2016 +0000
@@ -45,7 +45,7 @@
char ap_pw[AP_PW_MAX_LEN+1];
} deviceNetwork_t;
deviceNetwork_t devNetwork[4]; // 0-2 for setNetwork, 3 for set_ap
-DigitalOut wifiWriteInt(p30);
+DigitalOut wifiWriteInt(p30);
static uint8_t cyntecIsValidIP(uint8_t *startIdx, uint8_t totalLen)
{
@@ -182,6 +182,7 @@
void scanCallback(scanApInfo result)
{
newSSID = result.ssid.ssid;
+ // Check if SSID repeated
if (memcmp(newSSID,preSSID,result.ssid.ssid_len)) {
#ifdef DELTA_WIFI_DEBUG
console.printf("SSID repeat\r\n");
@@ -205,12 +206,18 @@
return;
}
memset(saveAP,0,sizeof(saveAP));
- cyntecPrintOk();
apInd = 1;
int scanResult = wifiDevice.apScan(scanCallback);
- if (scanResult<0)
+ if (scanResult >= 0) {
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("scan AP number:%d\r\n",scanResult);
+#endif
+ cyntecPrintOk();
+ return;
+ } else {
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
- return;
+ return;
+ }
}
static void cyn_wifi_set_ap()
@@ -411,14 +418,17 @@
uint8_t argLen = 0;
uint8_t *argIP;
EthernetInterface ethInterface;
-
+ uint8_t result;
if (cyntecGetCommandTokenCnt() == 2) {
/* use DHCP to get IP */
- if ( ethInterface.init() == 0 ) {
+ result = ethInterface.init();
+ if ( result == 0 ) {
cyntecPrintOk();
wifiIniState = true;
- } else
+ } else {
+ console.printf("function err:%d\r\n",result);
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
+ }
} else if ( cyntecGetCommandTokenCnt() == 3 ) {
/* use static to get IP */
@@ -681,69 +691,91 @@
else
console.printf("\r\nOK;FALSE\r\n\r\n");
}
+
static void cyn_wifi_tcp_connection_send()
{
char msg[TCP_SEND_MAX_LEN+1];
-
- uint8_t *arg;
- int argLen = 0;
int sendData;
-
- if (cyntecGetCommandTokenCnt() == 3) {
+ uint8_t * argAllBuf = cyntecGetCommandTotalBuffer();
+ uint8_t sendLen = 0;
+ uint8_t sendLenCharNum = 0;
+ uint8_t *sendLeng = cyntecGetCommandArgument(0,&sendLenCharNum);
+ sendLen = cyntecAtoi(sendLeng,sendLenCharNum);
+ if (sendLen > TCP_SEND_MAX_LEN) {
+ cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
+ return;
+ }
+ if (cyntecGetCommandTokenCnt() <4 ) {
+ cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
+ return;
+ }
+ if (cyntecGetCommandTokenCnt() >= 4) {
if ( tcpConnect.is_connected() == false ) {
cyntecPrintError(CYNTEC_CMD_ERR_INVALID_STATE_TO_PERFORM_OPERATION);
return;
}
/* handle Message arg */
- arg = cyntecGetCommandArgument(0, (uint8_t *)&argLen);
-
- if (argLen > TCP_SEND_MAX_LEN) {
- cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
- return;
- }
-
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("sendLen:%i,Buf:%s,Index:%i\r\n",sendLen,&argAllBuf[26+sendLenCharNum],cyntecGetTotalIndex());
+#endif
memset( msg, 0, TCP_SEND_MAX_LEN+1);
- memcpy( msg, arg, argLen);
- sendData = tcpConnect.send(msg, argLen);
+ for (uint8_t i=0; i<sendLen; i++)
+ msg[i] = argAllBuf[26+sendLenCharNum+i];
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("msg:%s\r\n",msg);
+#endif
+ sendData = tcpConnect.send(msg, sendLen);
if ( sendData >= 0 ) {
console.printf("\r\nOK;");
console.printf("%i\r\n\r\n",sendData);
} else
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
-
- } else {
- cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
}
}
+
static void cyn_wifi_tcp_connection_send_all()
{
char msg[TCP_SEND_MAX_LEN+1];
-
- uint8_t *arg;
- int argLen = 0;
-
- if (cyntecGetCommandTokenCnt() == 3) {
- /* handle Message arg */
- arg = cyntecGetCommandArgument(0, (uint8_t *)&argLen);
-
- if (argLen > TCP_SEND_MAX_LEN) {
- cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
+ int sendData;
+ uint8_t * argAllBuf = cyntecGetCommandTotalBuffer();
+ uint8_t sendLen = 0;
+ uint8_t sendLenCharNum = 0;
+ uint8_t *sendLeng = cyntecGetCommandArgument(0,&sendLenCharNum);
+ sendLen = cyntecAtoi(sendLeng,sendLenCharNum);
+ if (sendLen > TCP_SEND_MAX_LEN) {
+ cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
+ return;
+ }
+ if (cyntecGetCommandTokenCnt() <4 ) {
+ cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
+ return;
+ }
+ if (cyntecGetCommandTokenCnt() >= 4) {
+ if ( tcpConnect.is_connected() == false ) {
+ cyntecPrintError(CYNTEC_CMD_ERR_INVALID_STATE_TO_PERFORM_OPERATION);
return;
}
+ /* handle Message arg */
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("sendLen:%i,Buf:%s,Index:%i\r\n",sendLen,&argAllBuf[30+sendLenCharNum],cyntecGetTotalIndex());
+#endif
memset( msg, 0, TCP_SEND_MAX_LEN+1);
- memcpy( msg, arg, argLen);
-
- if ( tcpConnect.send_all(msg, argLen) >= 0 )
- cyntecPrintOk();
- else
+ for (uint8_t i=0; i<sendLen; i++)
+ msg[i] = argAllBuf[30+sendLenCharNum+i];
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("msg:%s\r\n",msg);
+#endif
+ sendData = tcpConnect.send_all(msg, sendLen);
+ if ( sendData >= 0 ) {
+ console.printf("\r\nOK;");
+ console.printf("%i\r\n\r\n",sendData);
+ } else
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
-
- } else {
- cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
}
}
+
static void cyn_wifi_tcp_connection_receive()
{
char msg[TCP_SEND_MAX_LEN+1];
@@ -752,7 +784,7 @@
if (cyntecGetCommandTokenCnt() == 3) {
/* handle Message arg */
argLen = atoi((const char *)cyntecGetCommandArgument(0, NULL));
- //console.printf("argLen:%d\r\n",argLen);
+ //console.printf("argLen:%d\r\n",argLen);
if (argLen > TCP_SEND_MAX_LEN || argLen < 0) {
cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
return;
@@ -794,6 +826,7 @@
cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
}
}
+
static void cyn_wifi_tcp_connection_blocking()
{
bool blocking = false;
@@ -825,6 +858,7 @@
cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
}
}
+
static void cyn_wifi_tcp_connection_close()
{
bool shutdown = true;
@@ -925,34 +959,72 @@
cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
}
}
+//static void cyn_wifi_udp_send_to()
+//{
+// char msg[UDP_SEND_MAX_LEN+1];
+//
+// uint8_t *arg;
+// int argLen = 0;
+//
+// if (cyntecGetCommandTokenCnt() == 3) {
+// /* handle Message arg */
+// arg = cyntecGetCommandArgument(0, (uint8_t *)&argLen);
+//
+// if (argLen > UDP_SEND_MAX_LEN || argLen < 0) {
+// cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
+// return;
+// }
+//
+// memset( msg, 0, UDP_SEND_MAX_LEN+1);
+// memcpy( msg, arg, argLen);
+//
+// if ( udpSocket.sendTo(cliEndpoint, msg, argLen) >= 0 )
+// cyntecPrintOk();
+// else
+// cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
+//
+// } else {
+// cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
+// }
+//}
static void cyn_wifi_udp_send_to()
{
char msg[UDP_SEND_MAX_LEN+1];
-
- uint8_t *arg;
- int argLen = 0;
-
- if (cyntecGetCommandTokenCnt() == 3) {
- /* handle Message arg */
- arg = cyntecGetCommandArgument(0, (uint8_t *)&argLen);
+ int sendData;
+ uint8_t * argAllBuf = cyntecGetCommandTotalBuffer();
+ uint8_t sendLen = 0;
+ uint8_t sendLenCharNum = 0;
+ uint8_t *sendLeng = cyntecGetCommandArgument(0,&sendLenCharNum);
+ sendLen = cyntecAtoi(sendLeng,sendLenCharNum);
+ if (sendLen > UDP_SEND_MAX_LEN) {
+ cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
+ return;
+ }
+ if (cyntecGetCommandTokenCnt() <4 ) {
+ cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
+ return;
+ }
+ if (cyntecGetCommandTokenCnt() >= 4) {
- if (argLen > UDP_SEND_MAX_LEN || argLen < 0) {
- cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
- return;
- }
-
+ /* handle Message arg */
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("sendLen:%i,Buf:%s,Index:%i\r\n",sendLen,&argAllBuf[18+sendLenCharNum],cyntecGetTotalIndex());
+#endif
memset( msg, 0, UDP_SEND_MAX_LEN+1);
- memcpy( msg, arg, argLen);
-
- if ( udpSocket.sendTo(cliEndpoint, msg, argLen) >= 0 )
- cyntecPrintOk();
- else
+ for (uint8_t i=0; i<sendLen; i++)
+ msg[i] = argAllBuf[18+sendLenCharNum+i];
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("msg:%s\r\n",msg);
+#endif
+ sendData = udpSocket.sendTo(cliEndpoint, msg, sendLen);
+ if ( sendData >= 0 ) {
+ console.printf("\r\nOK;");
+ console.printf("%i\r\n\r\n",sendData);
+ } else
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
-
- } else {
- cyntecPrintError(CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS);
}
}
+
static void cyn_wifi_udp_received_from()
{
char msg[UDP_SEND_MAX_LEN+1];
@@ -1083,7 +1155,7 @@
}
}
//static void cyn_wifi_udp_endpoint_get_address(){}
-static void cyn_wifi_udp_endpoint_port() // 2015/1/20: Lester add
+static void cyn_wifi_udp_endpoint_port() // 2015/1/20: Lester add
{
console.printf("\r\nOK;%d\r\n\r\n",cliEndpoint.get_port());
}
@@ -1105,8 +1177,8 @@
{
// Do nothing until flag on
if(wifiDataInt) {
- wifiWriteInt = !wifiWriteInt;
- wifiWriteInt = !wifiWriteInt;
+ wifiWriteInt = !wifiWriteInt;
+ wifiWriteInt = !wifiWriteInt;
#ifdef DELTA_WIFI_DEBUG
console.printf("wifi_receive_UDP_callback:");
#endif
@@ -1119,13 +1191,13 @@
{
// Do nothing until flag on
if(wifiDataInt) {
- wifiWriteInt = !wifiWriteInt;
- wifiWriteInt = !wifiWriteInt;
+ wifiWriteInt = !wifiWriteInt;
+ wifiWriteInt = !wifiWriteInt;
#ifdef DELTA_WIFI_DEBUG
console.printf("wifi_receive_TCP_callback\r\n");
#endif
console.printf("rTCP;%s,%i,%s,%d;\r\n",data, size, ipaddr, port);
- }
+ }
}
// Gill note: port number may different from original
@@ -1144,7 +1216,7 @@
{"DMWT",cyn_wifi_mem_write, NULL, " <MEMADDR> <DATA> Write data into embeeded flash"},
{"DEDI",cyn_wifi_enint, NULL, " Enable Wifi data interrupt, print data whenever received."},
{"DDDI",cyn_wifi_disint, NULL, " Disable Wifi interrupt."},
-
+
/////////**** WIFI Ethernet ****//////////
{"EINT", cyn_wifi_ethernet_init, NULL, " <STATIC IP> Initialize the interface to use DHCP"},
{"ECON", cyn_wifi_ethernet_connect, NULL, "<TIMEOUT MS> Bring up the WiFi connection"},
@@ -1182,7 +1254,7 @@
{"UERS", cyn_wifi_udp_endpoint_reset_address, NULL, "Reset the address of this endpoint"},
{"UEAD", cyn_wifi_udp_endpoint_address, NULL, " <IPADDR> <PORT> Set/Get the address of this endpoint"},
{"UEPT", cyn_wifi_udp_endpoint_port, NULL, "Get the port of this endpoint"},
-
+
{NULL, NULL, NULL, NULL},
#else
/////////**** WIFI Device ****//////////
@@ -1198,7 +1270,7 @@
{"device_mem_write",cyn_wifi_mem_write, NULL, " <MEMADDR> <DATA> Write data into embeeded flash"},
{"device_enint",cyn_wifi_enint, NULL, " Enable Wifi data interrupt, print data whenever received."},
{"device_disint",cyn_wifi_disint, NULL, " Disable Wifi interrupt."},
-
+
/////////**** WIFI Ethernet ****//////////
{"ethernet_init", cyn_wifi_ethernet_init, NULL, " <STATIC IP> Initialize the interface to use DHCP"},
