Christopher Haster / ESP8266Interface

Dependencies:   ESP8266

Fork of ESP8266Interface by NetworkSocketAPI

Committer:
sam_grove
Date:
Wed Mar 09 06:11:11 2016 +0000
Revision:
53:8ded612adb96
Parent:
51:eb8c3577e22d
Child:
55:c0808849cb89
change ESP8266Socket from struct to class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
geky 49:750ed1b67483 1 /* ESP8266 implementation of NetworkInterfaceAPI
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
Christopher Haster 34:9c26a3dcdc1f 17 #ifndef ESP8266_INTERFACE_H
Christopher Haster 34:9c26a3dcdc1f 18 #define ESP8266_INTERFACE_H
sarahmarshy 18:9fc7976c7b27 19
sarahmarshy 18:9fc7976c7b27 20 #include "WiFiInterface.h"
sarahmarshy 23:fd0f3197c30b 21 #include "ESP8266.h"
Christopher Haster 34:9c26a3dcdc1f 22
Christopher Haster 34:9c26a3dcdc1f 23 #define ESP8266_SOCKET_COUNT 5
sarahmarshy 18:9fc7976c7b27 24
Christopher Haster 34:9c26a3dcdc1f 25 /** ESP8266Interface class
Christopher Haster 34:9c26a3dcdc1f 26 * Implementation of the NetworkInterface for the ESP8266
sarahmarshy 18:9fc7976c7b27 27 */
sarahmarshy 18:9fc7976c7b27 28 class ESP8266Interface : public WiFiInterface
sarahmarshy 18:9fc7976c7b27 29 {
sarahmarshy 18:9fc7976c7b27 30 public:
sam_grove 53:8ded612adb96 31
Christopher Haster 34:9c26a3dcdc1f 32 ESP8266Interface(PinName tx, PinName rx, bool debug = false);
Christopher Haster 40:83c6b4129468 33 virtual ~ESP8266Interface();
Christopher Haster 34:9c26a3dcdc1f 34
Christopher Haster 34:9c26a3dcdc1f 35 // Implementation of WiFiInterface
Christopher Haster 34:9c26a3dcdc1f 36 virtual int32_t connect(
Christopher Haster 34:9c26a3dcdc1f 37 const char *ssid,
Christopher Haster 34:9c26a3dcdc1f 38 const char *pass,
geky 50:2d7f6b97234e 39 ns_security_t security = NS_SECURITY_NONE);
Christopher Haster 34:9c26a3dcdc1f 40
Christopher Haster 34:9c26a3dcdc1f 41 virtual int32_t disconnect();
Christopher Haster 34:9c26a3dcdc1f 42
Christopher Haster 34:9c26a3dcdc1f 43 // Implementation of NetworkInterface
Christopher Haster 34:9c26a3dcdc1f 44 virtual const char *getIPAddress();
Christopher Haster 34:9c26a3dcdc1f 45 virtual const char *getMACAddress();
Christopher Haster 34:9c26a3dcdc1f 46
geky 50:2d7f6b97234e 47 virtual SocketInterface *createSocket(ns_protocol_t proto);
Christopher Haster 34:9c26a3dcdc1f 48 virtual void destroySocket(SocketInterface *socket);
Christopher Haster 34:9c26a3dcdc1f 49
Christopher Haster 34:9c26a3dcdc1f 50 private:
sam_grove 53:8ded612adb96 51
Christopher Haster 34:9c26a3dcdc1f 52 ESP8266 _esp;
Christopher Haster 34:9c26a3dcdc1f 53 bool _ids[ESP8266_SOCKET_COUNT];
geky 51:eb8c3577e22d 54
geky 51:eb8c3577e22d 55 // Implementation of the SocketInterface for the ESP8266
sam_grove 53:8ded612adb96 56 class ESP8266Socket : public SocketInterface
geky 51:eb8c3577e22d 57 {
sam_grove 53:8ded612adb96 58 public:
sam_grove 53:8ded612adb96 59
geky 51:eb8c3577e22d 60 // ESP8266 specific details
geky 51:eb8c3577e22d 61 ESP8266 *_esp;
geky 51:eb8c3577e22d 62 ns_protocol_t _proto;
geky 51:eb8c3577e22d 63 int _id;
geky 51:eb8c3577e22d 64
geky 51:eb8c3577e22d 65 ESP8266Socket(ESP8266 *esp, ns_protocol_t proto, int id)
geky 51:eb8c3577e22d 66 : _esp(esp), _proto(proto), _id(id) {}
geky 51:eb8c3577e22d 67
geky 51:eb8c3577e22d 68 // Implementation of SocketInterface
geky 51:eb8c3577e22d 69 virtual int32_t open(const char *ip, uint16_t port);
geky 51:eb8c3577e22d 70 virtual int32_t close();
geky 51:eb8c3577e22d 71
geky 51:eb8c3577e22d 72 virtual int32_t send(const void *data, uint32_t size);
geky 51:eb8c3577e22d 73 virtual int32_t recv(void *data, uint32_t size);
geky 51:eb8c3577e22d 74 };
sarahmarshy 18:9fc7976c7b27 75 };
sarahmarshy 18:9fc7976c7b27 76
sarahmarshy 18:9fc7976c7b27 77 #endif