modified by ohneta
Dependents: HelloESP8266Interface_mine
Fork of ESP8266Interface by
ESP8266Interface.h@22:312453862371, 2015-07-22 (annotated)
- Committer:
- sarahmarshy
- Date:
- Wed Jul 22 20:53:09 2015 +0000
- Revision:
- 22:312453862371
- Parent:
- 20:5d0762aa4680
- Child:
- 23:fd0f3197c30b
Updated socket internals. Implemented getHandle function in ESP8266.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sarahmarshy | 18:9fc7976c7b27 | 1 | /* ESP8266Interface Example |
sarahmarshy | 18:9fc7976c7b27 | 2 | * Copyright (c) 2015 ARM Limited |
sarahmarshy | 18:9fc7976c7b27 | 3 | * |
sarahmarshy | 18:9fc7976c7b27 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sarahmarshy | 18:9fc7976c7b27 | 5 | * you may not use this file except in compliance with the License. |
sarahmarshy | 18:9fc7976c7b27 | 6 | * You may obtain a copy of the License at |
sarahmarshy | 18:9fc7976c7b27 | 7 | * |
sarahmarshy | 18:9fc7976c7b27 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sarahmarshy | 18:9fc7976c7b27 | 9 | * |
sarahmarshy | 18:9fc7976c7b27 | 10 | * Unless required by applicable law or agreed to in writing, software |
sarahmarshy | 18:9fc7976c7b27 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sarahmarshy | 18:9fc7976c7b27 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sarahmarshy | 18:9fc7976c7b27 | 13 | * See the License for the specific language governing permissions and |
sarahmarshy | 18:9fc7976c7b27 | 14 | * limitations under the License. |
sarahmarshy | 18:9fc7976c7b27 | 15 | */ |
sarahmarshy | 18:9fc7976c7b27 | 16 | |
sarahmarshy | 18:9fc7976c7b27 | 17 | #ifndef ESP8266INTERFACE_H |
sarahmarshy | 18:9fc7976c7b27 | 18 | #define ESP8266INTERFACE_H |
sarahmarshy | 18:9fc7976c7b27 | 19 | |
sarahmarshy | 18:9fc7976c7b27 | 20 | #include "WiFiInterface.h" |
sarahmarshy | 18:9fc7976c7b27 | 21 | #include "ATParser.h" |
sarahmarshy | 18:9fc7976c7b27 | 22 | |
sarahmarshy | 18:9fc7976c7b27 | 23 | /** ESP8266Socket class. |
sarahmarshy | 18:9fc7976c7b27 | 24 | This is a ESP8266 implementation of a socket that implements the SocketInterface class. |
sarahmarshy | 18:9fc7976c7b27 | 25 | This mock ESP8266 hardware uses AT commands, so an ATParser is used to communicate with the hardware over serial. |
sarahmarshy | 18:9fc7976c7b27 | 26 | In a non-AT command set, ATParser could be replaced by RawSerial or another hardware communication interface. |
sarahmarshy | 18:9fc7976c7b27 | 27 | */ |
sarahmarshy | 18:9fc7976c7b27 | 28 | |
sarahmarshy | 18:9fc7976c7b27 | 29 | class ESP8266Socket : public SocketInterface |
sarahmarshy | 18:9fc7976c7b27 | 30 | { |
sarahmarshy | 18:9fc7976c7b27 | 31 | public: |
sarahmarshy | 18:9fc7976c7b27 | 32 | ESP8266Socket(uint32_t handle, ATParser* atParser, socket_protocol_t type, uint8_t id); |
sarahmarshy | 18:9fc7976c7b27 | 33 | virtual const char *getHostByName(const char *name) const; |
sarahmarshy | 18:9fc7976c7b27 | 34 | virtual void setAddress(const char* addr) ; |
sarahmarshy | 18:9fc7976c7b27 | 35 | virtual void setPort(uint16_t port) ; |
sarahmarshy | 18:9fc7976c7b27 | 36 | virtual void setAddressPort(const char* addr, uint16_t port); |
sarahmarshy | 18:9fc7976c7b27 | 37 | virtual const char *getAddress(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 38 | virtual uint16_t getPort(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 39 | virtual int32_t bind(uint16_t port) const; |
sarahmarshy | 18:9fc7976c7b27 | 40 | virtual int32_t listen(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 41 | virtual int32_t accept() const; |
sarahmarshy | 18:9fc7976c7b27 | 42 | virtual int32_t open() ; |
sarahmarshy | 18:9fc7976c7b27 | 43 | virtual int32_t send(const void *data, uint32_t amount, uint32_t timeout_ms = 15000) ; |
sarahmarshy | 18:9fc7976c7b27 | 44 | virtual uint32_t recv(void *data, uint32_t amount, uint32_t timeout_ms = 15000) ; |
sarahmarshy | 18:9fc7976c7b27 | 45 | virtual int32_t close() const; |
sarahmarshy | 22:312453862371 | 46 | uint32_t getHandle() const; |
sarahmarshy | 18:9fc7976c7b27 | 47 | uint8_t getID(); |
sarahmarshy | 18:9fc7976c7b27 | 48 | void handleRecieve(); |
sarahmarshy | 18:9fc7976c7b27 | 49 | protected: |
sarahmarshy | 18:9fc7976c7b27 | 50 | uint8_t _id; |
sarahmarshy | 18:9fc7976c7b27 | 51 | private: |
sarahmarshy | 18:9fc7976c7b27 | 52 | ATParser *atParser; |
sarahmarshy | 18:9fc7976c7b27 | 53 | }; |
sarahmarshy | 18:9fc7976c7b27 | 54 | |
sarahmarshy | 18:9fc7976c7b27 | 55 | /** ESP8266Interface class. |
sarahmarshy | 18:9fc7976c7b27 | 56 | This is an interface to a ESP8266 radio. |
sarahmarshy | 18:9fc7976c7b27 | 57 | */ |
sarahmarshy | 18:9fc7976c7b27 | 58 | class ESP8266Interface : public WiFiInterface |
sarahmarshy | 18:9fc7976c7b27 | 59 | { |
sarahmarshy | 18:9fc7976c7b27 | 60 | public: |
sarahmarshy | 18:9fc7976c7b27 | 61 | ESP8266Interface(PinName tx, PinName rx); |
sarahmarshy | 18:9fc7976c7b27 | 62 | ESP8266Interface(PinName tx, PinName rx, const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000); |
sarahmarshy | 18:9fc7976c7b27 | 63 | virtual int32_t init(void); |
sarahmarshy | 18:9fc7976c7b27 | 64 | virtual int32_t init(const char *ip, const char *mask, const char *gateway); |
sarahmarshy | 18:9fc7976c7b27 | 65 | virtual int32_t connect(uint32_t timeout_ms) ; |
sarahmarshy | 18:9fc7976c7b27 | 66 | virtual int32_t connect(const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000); |
sarahmarshy | 22:312453862371 | 67 | virtual int32_t disconnect(void) ; |
sarahmarshy | 18:9fc7976c7b27 | 68 | virtual char *getIPAddress(void) ; |
sarahmarshy | 18:9fc7976c7b27 | 69 | virtual char *getGateway(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 70 | virtual char *getNetworkMask(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 71 | virtual char *getMACAddress(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 72 | virtual int32_t isConnected(void) ; |
sarahmarshy | 18:9fc7976c7b27 | 73 | virtual SocketInterface *allocateSocket(socket_protocol_t socketProtocol) ; |
sarahmarshy | 18:9fc7976c7b27 | 74 | virtual int deallocateSocket(SocketInterface *socket) ; |
sarahmarshy | 18:9fc7976c7b27 | 75 | |
sarahmarshy | 18:9fc7976c7b27 | 76 | private: |
sarahmarshy | 18:9fc7976c7b27 | 77 | BufferedSerial serial; |
sarahmarshy | 18:9fc7976c7b27 | 78 | ATParser atParser; |
sarahmarshy | 22:312453862371 | 79 | const int numSockets = 5; |
sarahmarshy | 22:312453862371 | 80 | int availableID[numSockets]; |
sarahmarshy | 20:5d0762aa4680 | 81 | char ip[100]; |
sarahmarshy | 18:9fc7976c7b27 | 82 | }; |
sarahmarshy | 18:9fc7976c7b27 | 83 | |
sarahmarshy | 18:9fc7976c7b27 | 84 | #endif |