wifly/socket interface for wifly modules
Dependents: PROJET_MATTHIEU_2019 PROJET_MATTHIEU_2019
WiflyInterface.cpp@4:74bfdd00362a, 2012-08-23 (annotated)
- Committer:
- samux
- Date:
- Thu Aug 23 10:32:45 2012 +0000
- Revision:
- 4:74bfdd00362a
- Parent:
- 0:6ffb0aeb3972
- Child:
- 7:a92dbed32890
no reboot needed/add timeout param in send function
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:74bfdd00362a | 35 | if (!sendCommand("get ip a\r", NULL, ip_string)) |
samux | 4:74bfdd00362a | 36 | return NULL; |
samux | 0:6ffb0aeb3972 | 37 | exit(); |
samux | 0:6ffb0aeb3972 | 38 | match = strstr(ip_string, "<"); |
samux | 0:6ffb0aeb3972 | 39 | if (match != NULL) { |
samux | 0:6ffb0aeb3972 | 40 | *match = '\0'; |
samux | 0:6ffb0aeb3972 | 41 | } |
samux | 0:6ffb0aeb3972 | 42 | if (strlen(ip_string) < 6) { |
samux | 0:6ffb0aeb3972 | 43 | match = strstr(ip_string, ">"); |
samux | 0:6ffb0aeb3972 | 44 | if (match != NULL) { |
samux | 0:6ffb0aeb3972 | 45 | int len = strlen(match + 1); |
samux | 0:6ffb0aeb3972 | 46 | memcpy(ip_string, match + 1, len); |
samux | 0:6ffb0aeb3972 | 47 | } |
samux | 0:6ffb0aeb3972 | 48 | } |
samux | 0:6ffb0aeb3972 | 49 | ip_set = true; |
samux | 0:6ffb0aeb3972 | 50 | } |
samux | 0:6ffb0aeb3972 | 51 | return ip_string; |
samux | 0:6ffb0aeb3972 | 52 | } |