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:
- 9:ff3ccba5dc16
- Parent:
- 5:ee474e3133eb
- Child:
- 10:5f1fa331d07c
--- a/CLI_Source/wifi_cli.cpp Thu Jan 21 11:32:23 2016 +0000
+++ b/CLI_Source/wifi_cli.cpp Mon Jan 25 11:19:12 2016 +0000
@@ -6,14 +6,7 @@
* Author: Lester Lee
*/
-
-#include <stdlib.h>
-#include <string.h>
-#include "mbed.h"
#include "wifi_cli.h"
-#include "command-interpreter.h"
-#include "WIFIDevice.h"
-#include "EthernetInterface.h"
#define AP_SSID_MAX_LEN 33
#define AP_PW_MAX_LEN 64
@@ -26,33 +19,31 @@
#define MAX_MEM_WRITE_LENGTH 0x3FFFF
#define MAX_MEM_ERASE_ADDR 0x3F000
#define MAX_DATA_LENGTH 256
-extern uint8_t isValidGPIO; // from ble_cli.cpp
-uint8_t static_ip[STATIC_IP_MAX_LEN] = "192.168.1.100";
-
+// General configuration parameters
WIFIDevice wifiDevice;
-extern Serial console;
-//Serial console(p25,p23);
-extern const char* cyntecCommandErrorNames[];
-
-typedef struct deviceNetwork_s {
- char ap_ssid[AP_SSID_MAX_LEN+1];
- char ap_pw[AP_PW_MAX_LEN+1];
-} deviceNetwork_t;
-
-deviceNetwork_t devNetwork[4]; // 0-2 for setNetwork, 3 for set_ap
-
TCPSocketConnection tcpConnect;
UDPSocket udpSocket;
Endpoint cliEndpoint;
TCPSocketServer tcpServer;
+//extern uint8_t isValidGPIO(uint8_t); // from ble_cli.cpp
+uint8_t static_ip[STATIC_IP_MAX_LEN] = "192.168.1.100";
+extern Serial console;
+//Serial console(p25,p23);
+extern const char* cyntecCommandErrorNames[];
static uint8_t is_Listen = false;
static uint8_t apInd;
static unsigned char *preSSID;
static unsigned char *newSSID;
static scanApInfo saveAP[WIFI_MAX_AP_NUMBER];
-static bool wifi_init = false;
+static bool wifiIniState = false;
+
+typedef struct deviceNetwork_s {
+ char ap_ssid[AP_SSID_MAX_LEN+1];
+ char ap_pw[AP_PW_MAX_LEN+1];
+} deviceNetwork_t;
+deviceNetwork_t devNetwork[4]; // 0-2 for setNetwork, 3 for set_ap
static uint8_t cyntecIsValidIP(uint8_t *startIdx, uint8_t totalLen)
{
@@ -61,7 +52,6 @@
uint8_t IPAddr[3];
//uint8_t IPTokenLen = 0;
int16_t ipToken;
-
while ( (tempIdx - startIdx) <= totalLen ) {
if (*tempIdx == '.' || ((tempIdx - startIdx) == totalLen)) {
memset( IPAddr, 0, 3);
@@ -75,8 +65,6 @@
}
tempIdx++;
}
-
-
return 0;
}
@@ -123,7 +111,7 @@
static void cyn_wifi_device_network()
{
- if (wifi_init== true) {
+ if (wifiIniState== true) {
cyntecPrintError(CYNTEC_CMD_ERR_WRONG_CMD_ORDER);
return;
}
@@ -210,7 +198,7 @@
static void cyn_wifi_device_ap_scan()
{
- if (wifi_init== false) {
+ if (wifiIniState== false) {
cyntecPrintError(CYNTEC_CMD_ERR_WRONG_CMD_ORDER);
return;
}
@@ -426,7 +414,7 @@
/* use DHCP to get IP */
if ( ethInterface.init() == 0 ) {
cyntecPrintOk();
- wifi_init = true;
+ wifiIniState = true;
} else
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
@@ -443,7 +431,7 @@
memcpy( static_ip, argIP, argLen);
if ( ethInterface.init((const char *)static_ip, NULL, NULL) == 0) {
cyntecPrintOk();
- wifi_init = true;
+ wifiIniState = true;
} else
cyntecPrintError(CYNTEC_CMD_ERR_CALL_FAIL);
} else {
@@ -541,6 +529,9 @@
} else if (cyntecGetCommandTokenCnt() == 3) {
port = atoi((const char*)(cyntecGetCommandArgument(0, NULL)));
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("port:%i\r\n",port);
+#endif
if (port < 0) {
cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
return;
@@ -1090,12 +1081,28 @@
}
}
//static void cyn_wifi_udp_endpoint_get_address(){}
-static void cyn_wifi_udp_endpoint_port()
+static void cyn_wifi_udp_endpoint_port() // 2015/1/20: Lester add
{
console.printf("\r\nOK;%d\r\n\r\n",cliEndpoint.get_port());
}
-// 2015/1/20: Lester add
+int wifi_receive_UDP_callback(uint8_t *data, int size, char* ipaddr, int port)
+{
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("wifi_receive_UDP_callback:");
+#endif
+ console.printf("rTCP;%s,%i,%s,%d;\r\n",data, size, ipaddr, port);
+ // Gill note: port number may different from original
+}
+
+int wifi_receive_TCP_callback(uint8_t *data, int size, char* ipaddr, int port)
+{
+#ifdef DELTA_WIFI_DEBUG
+ console.printf("wifi_receive_TCP_callback\r\n");
+#endif
+ console.printf("rUDP;%s,%i,%s,%d\r\n",data, size, ipaddr, port);
+ // Gill note: port number may different from original
+}
CyntecCommandEntry wifiCommandSets[] = {
#if SIMPLE_CMD_NAME
@@ -1148,7 +1155,6 @@
{"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 ****//////////
