see http://mbed.org/users/okini3939/notebook/wattmeter-shield-on-mbed/
Fork of GSwifi_xively by
GSwifiInterface/GSwifiInterface.cpp@4:9a2415f2ab07, 2013-11-27 (annotated)
- Committer:
- okini3939
- Date:
- Wed Nov 27 08:18:45 2013 +0000
- Revision:
- 4:9a2415f2ab07
update GSwifiInterface library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 4:9a2415f2ab07 | 1 | /* Copyright (C) 2013 gsfan, MIT License |
okini3939 | 4:9a2415f2ab07 | 2 | * port to the GainSpan Wi-FI module GS1011 |
okini3939 | 4:9a2415f2ab07 | 3 | */ |
okini3939 | 4:9a2415f2ab07 | 4 | |
okini3939 | 4:9a2415f2ab07 | 5 | #include "GSwifiInterface.h" |
okini3939 | 4:9a2415f2ab07 | 6 | |
okini3939 | 4:9a2415f2ab07 | 7 | GSwifiInterface::GSwifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud) : |
okini3939 | 4:9a2415f2ab07 | 8 | GSwifi(tx, rx, cts, rts, reset, alarm, baud) |
okini3939 | 4:9a2415f2ab07 | 9 | { |
okini3939 | 4:9a2415f2ab07 | 10 | } |
okini3939 | 4:9a2415f2ab07 | 11 | |
okini3939 | 4:9a2415f2ab07 | 12 | int GSwifiInterface::init(const char* name) |
okini3939 | 4:9a2415f2ab07 | 13 | { |
okini3939 | 4:9a2415f2ab07 | 14 | return setAddress(name); |
okini3939 | 4:9a2415f2ab07 | 15 | } |
okini3939 | 4:9a2415f2ab07 | 16 | |
okini3939 | 4:9a2415f2ab07 | 17 | int GSwifiInterface::init(const char* ip, const char* netmask, const char* gateway, const char* name) |
okini3939 | 4:9a2415f2ab07 | 18 | { |
okini3939 | 4:9a2415f2ab07 | 19 | return setAddress(ip, netmask, gateway, name); |
okini3939 | 4:9a2415f2ab07 | 20 | } |
okini3939 | 4:9a2415f2ab07 | 21 | |
okini3939 | 4:9a2415f2ab07 | 22 | int GSwifiInterface::connect(Security sec, const char* ssid, const char* phrase, WiFiMode mode) |
okini3939 | 4:9a2415f2ab07 | 23 | { |
okini3939 | 4:9a2415f2ab07 | 24 | setSsid(sec, ssid, phrase); |
okini3939 | 4:9a2415f2ab07 | 25 | switch (mode) { |
okini3939 | 4:9a2415f2ab07 | 26 | case WM_INFRASTRUCTURE: |
okini3939 | 4:9a2415f2ab07 | 27 | return join(); |
okini3939 | 4:9a2415f2ab07 | 28 | case WM_ADHOCK: |
okini3939 | 4:9a2415f2ab07 | 29 | return adhock(); |
okini3939 | 4:9a2415f2ab07 | 30 | case WM_LIMITEDAP: |
okini3939 | 4:9a2415f2ab07 | 31 | return limitedap(); |
okini3939 | 4:9a2415f2ab07 | 32 | } |
okini3939 | 4:9a2415f2ab07 | 33 | return -1; |
okini3939 | 4:9a2415f2ab07 | 34 | } |
okini3939 | 4:9a2415f2ab07 | 35 | |
okini3939 | 4:9a2415f2ab07 | 36 | int GSwifiInterface::disconnect() |
okini3939 | 4:9a2415f2ab07 | 37 | { |
okini3939 | 4:9a2415f2ab07 | 38 | return GSwifi::dissociate(); |
okini3939 | 4:9a2415f2ab07 | 39 | } |
okini3939 | 4:9a2415f2ab07 | 40 | |
okini3939 | 4:9a2415f2ab07 | 41 | char * GSwifiInterface::getMACAddress() |
okini3939 | 4:9a2415f2ab07 | 42 | { |
okini3939 | 4:9a2415f2ab07 | 43 | return _state.mac; |
okini3939 | 4:9a2415f2ab07 | 44 | } |
okini3939 | 4:9a2415f2ab07 | 45 | |
okini3939 | 4:9a2415f2ab07 | 46 | char * GSwifiInterface::getIPAddress() |
okini3939 | 4:9a2415f2ab07 | 47 | { |
okini3939 | 4:9a2415f2ab07 | 48 | return _state.ip; |
okini3939 | 4:9a2415f2ab07 | 49 | } |
okini3939 | 4:9a2415f2ab07 | 50 | |
okini3939 | 4:9a2415f2ab07 | 51 | char * GSwifiInterface::getGateway() |
okini3939 | 4:9a2415f2ab07 | 52 | { |
okini3939 | 4:9a2415f2ab07 | 53 | return _state.gateway; |
okini3939 | 4:9a2415f2ab07 | 54 | } |
okini3939 | 4:9a2415f2ab07 | 55 | |
okini3939 | 4:9a2415f2ab07 | 56 | char * GSwifiInterface::getNetworkMask() |
okini3939 | 4:9a2415f2ab07 | 57 | { |
okini3939 | 4:9a2415f2ab07 | 58 | return _state.netmask; |
okini3939 | 4:9a2415f2ab07 | 59 | } |