wifly/socket interface for wifly modules

Dependents:   PROJET_MATTHIEU_2019 PROJET_MATTHIEU_2019

Committer:
robin25
Date:
Mon May 20 09:09:10 2019 +0000
Revision:
14:352388da9fa5
Parent:
12:5ffaed1456c8
ok

Who changed what in which revision?

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