wifly/socket interface for wifly modules

Dependents:   WiFi neurGAI_WIFI thingspeak thingspeak2

Revision:
0:6ffb0aeb3972
Child:
4:74bfdd00362a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiflyInterface.cpp	Fri Aug 17 08:28:04 2012 +0000
@@ -0,0 +1,51 @@
+#include "WiflyInterface.h"
+
+WiflyInterface::WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, bool wpa) : 
+    Wifly(tx, rx, reset, tcp_status, ssid, phrase, wpa) {ip_set = false;}
+    
+int WiflyInterface::init() {
+    dhcp = true;
+    reset();
+    return 0;
+}
+
+int WiflyInterface::init(const char* ip, const char* mask, const char* gateway) {
+    dhcp = false;
+    this->ip = ip;
+    strcpy(ip_string, ip);
+    ip_set = true;
+    this->netmask = mask;
+    this->gateway = gateway;
+    
+    reset();
+    return 0;
+}
+
+int WiflyInterface::connect() {
+    return join();
+}
+
+int WiflyInterface::disconnect() {
+    return leave();
+}
+
+char * WiflyInterface::getIPAddress() {
+    char * match = 0;
+    if (!ip_set) {
+        sendCommand("get ip a\r", NULL, ip_string);
+        exit();
+        match = strstr(ip_string, "<");
+        if (match != NULL) {
+            *match = '\0';
+        }
+        if (strlen(ip_string) < 6) {
+            match = strstr(ip_string, ">");
+            if (match != NULL) {
+                int len = strlen(match + 1);
+                memcpy(ip_string, match + 1, len);
+            }
+        }
+        ip_set = true;
+    }
+    return ip_string;
+}
\ No newline at end of file