Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ESP8266
Fork of ESP8266Interface by
WiFiRadioInterface.h@16:b2f781416464, 2015-07-15 (annotated)
- Committer:
- bridadan
- Date:
- Wed Jul 15 23:22:31 2015 +0000
- Revision:
- 16:b2f781416464
- Parent:
- 15:d29439d50306
- Child:
- 17:c3f4095337b8
Moved some underscored_functions to camelCase, added functions and data structures to prepare for multiple sockets, added ATParser dependency
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sam_grove | 12:8db9b116cf76 | 1 | /* WiFiRadioInterface Example |
| sam_grove | 11:288c15b80a26 | 2 | * Copyright (c) 2015 ARM Limited |
| sam_grove | 11:288c15b80a26 | 3 | * |
| sam_grove | 11:288c15b80a26 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| sam_grove | 11:288c15b80a26 | 5 | * you may not use this file except in compliance with the License. |
| sam_grove | 11:288c15b80a26 | 6 | * You may obtain a copy of the License at |
| sam_grove | 11:288c15b80a26 | 7 | * |
| sam_grove | 11:288c15b80a26 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| sam_grove | 11:288c15b80a26 | 9 | * |
| sam_grove | 11:288c15b80a26 | 10 | * Unless required by applicable law or agreed to in writing, software |
| sam_grove | 11:288c15b80a26 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| sam_grove | 11:288c15b80a26 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| sam_grove | 11:288c15b80a26 | 13 | * See the License for the specific language governing permissions and |
| sam_grove | 11:288c15b80a26 | 14 | * limitations under the License. |
| sam_grove | 11:288c15b80a26 | 15 | */ |
| sam_grove | 11:288c15b80a26 | 16 | |
| sam_grove | 11:288c15b80a26 | 17 | #ifndef WIFIRADIOINTERFACE_H |
| sam_grove | 11:288c15b80a26 | 18 | #define WIFIRADIOINTERFACE_H |
| sam_grove | 11:288c15b80a26 | 19 | |
| sam_grove | 11:288c15b80a26 | 20 | #include "WiFiInterface.h" |
| sam_grove | 13:0186e9e35a24 | 21 | #include "SocketInterface.h" |
| bridadan | 16:b2f781416464 | 22 | #include "ATParser.h" |
| bridadan | 16:b2f781416464 | 23 | |
| bridadan | 16:b2f781416464 | 24 | /** WiFiSocket class. |
| bridadan | 16:b2f781416464 | 25 | This is a WiFi implementation of a socket that implements the SocketInterface class. |
| bridadan | 16:b2f781416464 | 26 | This mock WiFi hardware uses AT commands, so an ATParser is used to communicate with the hardware over serial. |
| bridadan | 16:b2f781416464 | 27 | In a non-AT command set, ATParser could be replaced by RawSerial or another hardware communication interface. |
| bridadan | 16:b2f781416464 | 28 | */ |
| bridadan | 16:b2f781416464 | 29 | |
| bridadan | 16:b2f781416464 | 30 | class WiFiSocket : public SocketInterface |
| bridadan | 16:b2f781416464 | 31 | { |
| bridadan | 16:b2f781416464 | 32 | public: |
| bridadan | 16:b2f781416464 | 33 | WiFiSocket(uint32_t handle, ATParser* atParser); |
| bridadan | 16:b2f781416464 | 34 | virtual const char *getHostByName(const char *name) const; |
| bridadan | 16:b2f781416464 | 35 | virtual int32_t setAddress(const char* addr) const; |
| bridadan | 16:b2f781416464 | 36 | virtual int32_t setPort(uint16_t port) const; |
| bridadan | 16:b2f781416464 | 37 | virtual int32_t setAddressPort(const char* addr, uint16_t port) const; |
| bridadan | 16:b2f781416464 | 38 | virtual const char *getAddress(void) const; |
| bridadan | 16:b2f781416464 | 39 | virtual uint16_t getPort(void) const; |
| bridadan | 16:b2f781416464 | 40 | virtual int32_t bind(uint16_t port) const; |
| bridadan | 16:b2f781416464 | 41 | virtual int32_t listen(void) const; |
| bridadan | 16:b2f781416464 | 42 | virtual int32_t accept() const; |
| bridadan | 16:b2f781416464 | 43 | virtual int32_t open() const; |
| bridadan | 16:b2f781416464 | 44 | virtual int32_t send(const void *data, uint32_t amount, uint32_t timeout_ms = 15000) const; |
| bridadan | 16:b2f781416464 | 45 | virtual uint32_t recv(const void *data, uint32_t amount, uint32_t timeout_ms = 15000) const; |
| bridadan | 16:b2f781416464 | 46 | virtual int32_t close() const; |
| bridadan | 16:b2f781416464 | 47 | |
| bridadan | 16:b2f781416464 | 48 | protected: |
| bridadan | 16:b2f781416464 | 49 | uint32_t handle; |
| bridadan | 16:b2f781416464 | 50 | |
| bridadan | 16:b2f781416464 | 51 | private: |
| bridadan | 16:b2f781416464 | 52 | ATParser *atParser; |
| bridadan | 16:b2f781416464 | 53 | |
| bridadan | 16:b2f781416464 | 54 | }; |
| sam_grove | 11:288c15b80a26 | 55 | |
| sam_grove | 12:8db9b116cf76 | 56 | /** WiFiRadioInterface class. |
| bridadan | 16:b2f781416464 | 57 | This is an interface to a WiFi radio. |
| sam_grove | 11:288c15b80a26 | 58 | */ |
| bridadan | 16:b2f781416464 | 59 | class WiFiRadioInterface : public WiFiInterface |
| sam_grove | 11:288c15b80a26 | 60 | { |
| sam_grove | 11:288c15b80a26 | 61 | public: |
| bridadan | 16:b2f781416464 | 62 | WiFiRadioInterface(PinName tx, PinName rx); |
| bridadan | 16:b2f781416464 | 63 | WiFiRadioInterface(PinName tx, PinName rx, const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000); |
| sam_grove | 11:288c15b80a26 | 64 | virtual int32_t init(void) const; |
| sam_grove | 11:288c15b80a26 | 65 | virtual int32_t init(const char *ip, const char *mask, const char *gateway) const; |
| sam_grove | 11:288c15b80a26 | 66 | virtual int32_t connect(uint32_t timeout_ms) const; |
| sam_grove | 11:288c15b80a26 | 67 | virtual int32_t connect(const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000) const; |
| sam_grove | 11:288c15b80a26 | 68 | virtual int32_t disconnect(void) const; |
| sam_grove | 11:288c15b80a26 | 69 | virtual char *getIPAddress(void) const; |
| sam_grove | 11:288c15b80a26 | 70 | virtual char *getGateway(void) const; |
| sam_grove | 11:288c15b80a26 | 71 | virtual char *getNetworkMask(void) const; |
| sam_grove | 11:288c15b80a26 | 72 | virtual char *getMACAddress(void) const; |
| sam_grove | 11:288c15b80a26 | 73 | virtual int32_t isConnected(void) const; |
| bridadan | 16:b2f781416464 | 74 | virtual SocketInterface *allocateSocket(socket_protocol_t socketProtocol) const; |
| bridadan | 16:b2f781416464 | 75 | virtual int deallocateSocket(SocketInterface *socket) const; |
| sam_grove | 13:0186e9e35a24 | 76 | |
| bridadan | 16:b2f781416464 | 77 | private: |
| bridadan | 16:b2f781416464 | 78 | RawSerial serial; |
| bridadan | 16:b2f781416464 | 79 | ATParser atParser; |
| sam_grove | 11:288c15b80a26 | 80 | }; |
| sam_grove | 11:288c15b80a26 | 81 | |
| sam_grove | 11:288c15b80a26 | 82 | #endif |
