wifly/socket interface for wifly modules

Dependents:   PROJET_MATTHIEU_2019 PROJET_MATTHIEU_2019

Committer:
samux
Date:
Fri Aug 17 08:28:04 2012 +0000
Revision:
0:6ffb0aeb3972
Child:
4:74bfdd00362a
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:6ffb0aeb3972 1 #include "WiflyInterface.h"
samux 0:6ffb0aeb3972 2
samux 0:6ffb0aeb3972 3 WiflyInterface::WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, bool wpa) :
samux 0:6ffb0aeb3972 4 Wifly(tx, rx, reset, tcp_status, ssid, phrase, wpa) {ip_set = false;}
samux 0:6ffb0aeb3972 5
samux 0:6ffb0aeb3972 6 int WiflyInterface::init() {
samux 0:6ffb0aeb3972 7 dhcp = true;
samux 0:6ffb0aeb3972 8 reset();
samux 0:6ffb0aeb3972 9 return 0;
samux 0:6ffb0aeb3972 10 }
samux 0:6ffb0aeb3972 11
samux 0:6ffb0aeb3972 12 int WiflyInterface::init(const char* ip, const char* mask, const char* gateway) {
samux 0:6ffb0aeb3972 13 dhcp = false;
samux 0:6ffb0aeb3972 14 this->ip = ip;
samux 0:6ffb0aeb3972 15 strcpy(ip_string, ip);
samux 0:6ffb0aeb3972 16 ip_set = true;
samux 0:6ffb0aeb3972 17 this->netmask = mask;
samux 0:6ffb0aeb3972 18 this->gateway = gateway;
samux 0:6ffb0aeb3972 19
samux 0:6ffb0aeb3972 20 reset();
samux 0:6ffb0aeb3972 21 return 0;
samux 0:6ffb0aeb3972 22 }
samux 0:6ffb0aeb3972 23
samux 0:6ffb0aeb3972 24 int WiflyInterface::connect() {
samux 0:6ffb0aeb3972 25 return join();
samux 0:6ffb0aeb3972 26 }
samux 0:6ffb0aeb3972 27
samux 0:6ffb0aeb3972 28 int WiflyInterface::disconnect() {
samux 0:6ffb0aeb3972 29 return leave();
samux 0:6ffb0aeb3972 30 }
samux 0:6ffb0aeb3972 31
samux 0:6ffb0aeb3972 32 char * WiflyInterface::getIPAddress() {
samux 0:6ffb0aeb3972 33 char * match = 0;
samux 0:6ffb0aeb3972 34 if (!ip_set) {
samux 0:6ffb0aeb3972 35 sendCommand("get ip a\r", NULL, ip_string);
samux 0:6ffb0aeb3972 36 exit();
samux 0:6ffb0aeb3972 37 match = strstr(ip_string, "<");
samux 0:6ffb0aeb3972 38 if (match != NULL) {
samux 0:6ffb0aeb3972 39 *match = '\0';
samux 0:6ffb0aeb3972 40 }
samux 0:6ffb0aeb3972 41 if (strlen(ip_string) < 6) {
samux 0:6ffb0aeb3972 42 match = strstr(ip_string, ">");
samux 0:6ffb0aeb3972 43 if (match != NULL) {
samux 0:6ffb0aeb3972 44 int len = strlen(match + 1);
samux 0:6ffb0aeb3972 45 memcpy(ip_string, match + 1, len);
samux 0:6ffb0aeb3972 46 }
samux 0:6ffb0aeb3972 47 }
samux 0:6ffb0aeb3972 48 ip_set = true;
samux 0:6ffb0aeb3972 49 }
samux 0:6ffb0aeb3972 50 return ip_string;
samux 0:6ffb0aeb3972 51 }