The driver for the ESP8266 WiFi module - isConnected function added, working and tested with mbed os 5.7.6

Fork of esp8266-driver by ESP8266

Committer:
mareszym
Date:
Sun Nov 04 12:50:49 2018 +0000
Revision:
2:0bc0b654995c
Parent:
0:6946b0b9e323
isConnected function added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-ESP8266 0:6946b0b9e323 1
group-ESP8266 0:6946b0b9e323 2 /**
group-ESP8266 0:6946b0b9e323 3 * @file Buffer.h
group-ESP8266 0:6946b0b9e323 4 * @brief Software Buffer - Templated Ring Buffer for most data types
group-ESP8266 0:6946b0b9e323 5 * @author sam grove
group-ESP8266 0:6946b0b9e323 6 * @version 1.0
group-ESP8266 0:6946b0b9e323 7 * @see
group-ESP8266 0:6946b0b9e323 8 *
group-ESP8266 0:6946b0b9e323 9 * Copyright (c) 2013
group-ESP8266 0:6946b0b9e323 10 *
group-ESP8266 0:6946b0b9e323 11 * Licensed under the Apache License, Version 2.0 (the "License");
group-ESP8266 0:6946b0b9e323 12 * you may not use this file except in compliance with the License.
group-ESP8266 0:6946b0b9e323 13 * You may obtain a copy of the License at
group-ESP8266 0:6946b0b9e323 14 *
group-ESP8266 0:6946b0b9e323 15 * http://www.apache.org/licenses/LICENSE-2.0
group-ESP8266 0:6946b0b9e323 16 *
group-ESP8266 0:6946b0b9e323 17 * Unless required by applicable law or agreed to in writing, software
group-ESP8266 0:6946b0b9e323 18 * distributed under the License is distributed on an "AS IS" BASIS,
group-ESP8266 0:6946b0b9e323 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-ESP8266 0:6946b0b9e323 20 * See the License for the specific language governing permissions and
group-ESP8266 0:6946b0b9e323 21 * limitations under the License.
group-ESP8266 0:6946b0b9e323 22 */
group-ESP8266 0:6946b0b9e323 23
group-ESP8266 0:6946b0b9e323 24 #ifndef MYBUFFER_H
group-ESP8266 0:6946b0b9e323 25 #define MYBUFFER_H
group-ESP8266 0:6946b0b9e323 26
group-ESP8266 0:6946b0b9e323 27 #include <stdint.h>
group-ESP8266 0:6946b0b9e323 28 #include <string.h>
group-ESP8266 0:6946b0b9e323 29
group-ESP8266 0:6946b0b9e323 30 /** A templated software ring buffer
group-ESP8266 0:6946b0b9e323 31 *
group-ESP8266 0:6946b0b9e323 32 * Example:
group-ESP8266 0:6946b0b9e323 33 * @code
group-ESP8266 0:6946b0b9e323 34 * #include "mbed.h"
group-ESP8266 0:6946b0b9e323 35 * #include "MyBuffer.h"
group-ESP8266 0:6946b0b9e323 36 *
group-ESP8266 0:6946b0b9e323 37 * MyBuffer <char> buf;
group-ESP8266 0:6946b0b9e323 38 *
group-ESP8266 0:6946b0b9e323 39 * int main()
group-ESP8266 0:6946b0b9e323 40 * {
group-ESP8266 0:6946b0b9e323 41 * buf = 'a';
group-ESP8266 0:6946b0b9e323 42 * buf.put('b');
group-ESP8266 0:6946b0b9e323 43 * char *head = buf.head();
group-ESP8266 0:6946b0b9e323 44 * puts(head);
group-ESP8266 0:6946b0b9e323 45 *
group-ESP8266 0:6946b0b9e323 46 * char whats_in_there[2] = {0};
group-ESP8266 0:6946b0b9e323 47 * int pos = 0;
group-ESP8266 0:6946b0b9e323 48 *
group-ESP8266 0:6946b0b9e323 49 * while(buf.available())
group-ESP8266 0:6946b0b9e323 50 * {
group-ESP8266 0:6946b0b9e323 51 * whats_in_there[pos++] = buf;
group-ESP8266 0:6946b0b9e323 52 * }
group-ESP8266 0:6946b0b9e323 53 * printf("%c %c\n", whats_in_there[0], whats_in_there[1]);
group-ESP8266 0:6946b0b9e323 54 * buf.clear();
group-ESP8266 0:6946b0b9e323 55 * error("done\n\n\n");
group-ESP8266 0:6946b0b9e323 56 * }
group-ESP8266 0:6946b0b9e323 57 * @endcode
group-ESP8266 0:6946b0b9e323 58 */
group-ESP8266 0:6946b0b9e323 59
group-ESP8266 0:6946b0b9e323 60 template <typename T>
group-ESP8266 0:6946b0b9e323 61 class MyBuffer
group-ESP8266 0:6946b0b9e323 62 {
group-ESP8266 0:6946b0b9e323 63 private:
group-ESP8266 0:6946b0b9e323 64 T *_buf;
group-ESP8266 0:6946b0b9e323 65 volatile uint32_t _wloc;
group-ESP8266 0:6946b0b9e323 66 volatile uint32_t _rloc;
group-ESP8266 0:6946b0b9e323 67 uint32_t _size;
group-ESP8266 0:6946b0b9e323 68
group-ESP8266 0:6946b0b9e323 69 public:
group-ESP8266 0:6946b0b9e323 70 /** Create a Buffer and allocate memory for it
group-ESP8266 0:6946b0b9e323 71 * @param size The size of the buffer
group-ESP8266 0:6946b0b9e323 72 */
group-ESP8266 0:6946b0b9e323 73 MyBuffer(uint32_t size = 0x100);
group-ESP8266 0:6946b0b9e323 74
group-ESP8266 0:6946b0b9e323 75 /** Get the size of the ring buffer
group-ESP8266 0:6946b0b9e323 76 * @return the size of the ring buffer
group-ESP8266 0:6946b0b9e323 77 */
group-ESP8266 0:6946b0b9e323 78 uint32_t getSize();
group-ESP8266 0:6946b0b9e323 79
group-ESP8266 0:6946b0b9e323 80 /** Destry a Buffer and release it's allocated memory
group-ESP8266 0:6946b0b9e323 81 */
group-ESP8266 0:6946b0b9e323 82 ~MyBuffer();
group-ESP8266 0:6946b0b9e323 83
group-ESP8266 0:6946b0b9e323 84 /** Add a data element into the buffer
group-ESP8266 0:6946b0b9e323 85 * @param data Something to add to the buffer
group-ESP8266 0:6946b0b9e323 86 */
group-ESP8266 0:6946b0b9e323 87 void put(T data);
group-ESP8266 0:6946b0b9e323 88
group-ESP8266 0:6946b0b9e323 89 /** Remove a data element from the buffer
group-ESP8266 0:6946b0b9e323 90 * @return Pull the oldest element from the buffer
group-ESP8266 0:6946b0b9e323 91 */
group-ESP8266 0:6946b0b9e323 92 T get(void);
group-ESP8266 0:6946b0b9e323 93
group-ESP8266 0:6946b0b9e323 94 /** Get the address to the head of the buffer
group-ESP8266 0:6946b0b9e323 95 * @return The address of element 0 in the buffer
group-ESP8266 0:6946b0b9e323 96 */
group-ESP8266 0:6946b0b9e323 97 T *head(void);
group-ESP8266 0:6946b0b9e323 98
group-ESP8266 0:6946b0b9e323 99 /** Reset the buffer to 0. Useful if using head() to parse packeted data
group-ESP8266 0:6946b0b9e323 100 */
group-ESP8266 0:6946b0b9e323 101 void clear(void);
group-ESP8266 0:6946b0b9e323 102
group-ESP8266 0:6946b0b9e323 103 /** Determine if anything is readable in the buffer
group-ESP8266 0:6946b0b9e323 104 * @return 1 if something can be read, 0 otherwise
group-ESP8266 0:6946b0b9e323 105 */
group-ESP8266 0:6946b0b9e323 106 uint32_t available(void);
group-ESP8266 0:6946b0b9e323 107
group-ESP8266 0:6946b0b9e323 108 /** Overloaded operator for writing to the buffer
group-ESP8266 0:6946b0b9e323 109 * @param data Something to put in the buffer
group-ESP8266 0:6946b0b9e323 110 * @return
group-ESP8266 0:6946b0b9e323 111 */
group-ESP8266 0:6946b0b9e323 112 MyBuffer &operator= (T data)
group-ESP8266 0:6946b0b9e323 113 {
group-ESP8266 0:6946b0b9e323 114 put(data);
group-ESP8266 0:6946b0b9e323 115 return *this;
group-ESP8266 0:6946b0b9e323 116 }
group-ESP8266 0:6946b0b9e323 117
group-ESP8266 0:6946b0b9e323 118 /** Overloaded operator for reading from the buffer
group-ESP8266 0:6946b0b9e323 119 * @return Pull the oldest element from the buffer
group-ESP8266 0:6946b0b9e323 120 */
group-ESP8266 0:6946b0b9e323 121 operator int(void)
group-ESP8266 0:6946b0b9e323 122 {
group-ESP8266 0:6946b0b9e323 123 return get();
group-ESP8266 0:6946b0b9e323 124 }
group-ESP8266 0:6946b0b9e323 125
group-ESP8266 0:6946b0b9e323 126 uint32_t peek(char c);
group-ESP8266 0:6946b0b9e323 127
group-ESP8266 0:6946b0b9e323 128 };
group-ESP8266 0:6946b0b9e323 129
group-ESP8266 0:6946b0b9e323 130 template <class T>
group-ESP8266 0:6946b0b9e323 131 inline void MyBuffer<T>::put(T data)
group-ESP8266 0:6946b0b9e323 132 {
group-ESP8266 0:6946b0b9e323 133 _buf[_wloc++] = data;
group-ESP8266 0:6946b0b9e323 134 _wloc %= (_size-1);
group-ESP8266 0:6946b0b9e323 135
group-ESP8266 0:6946b0b9e323 136 return;
group-ESP8266 0:6946b0b9e323 137 }
group-ESP8266 0:6946b0b9e323 138
group-ESP8266 0:6946b0b9e323 139 template <class T>
group-ESP8266 0:6946b0b9e323 140 inline T MyBuffer<T>::get(void)
group-ESP8266 0:6946b0b9e323 141 {
group-ESP8266 0:6946b0b9e323 142 T data_pos = _buf[_rloc++];
group-ESP8266 0:6946b0b9e323 143 _rloc %= (_size-1);
group-ESP8266 0:6946b0b9e323 144
group-ESP8266 0:6946b0b9e323 145 return data_pos;
group-ESP8266 0:6946b0b9e323 146 }
group-ESP8266 0:6946b0b9e323 147
group-ESP8266 0:6946b0b9e323 148 template <class T>
group-ESP8266 0:6946b0b9e323 149 inline T *MyBuffer<T>::head(void)
group-ESP8266 0:6946b0b9e323 150 {
group-ESP8266 0:6946b0b9e323 151 T *data_pos = &_buf[0];
group-ESP8266 0:6946b0b9e323 152
group-ESP8266 0:6946b0b9e323 153 return data_pos;
group-ESP8266 0:6946b0b9e323 154 }
group-ESP8266 0:6946b0b9e323 155
group-ESP8266 0:6946b0b9e323 156 template <class T>
group-ESP8266 0:6946b0b9e323 157 inline uint32_t MyBuffer<T>::available(void)
group-ESP8266 0:6946b0b9e323 158 {
group-ESP8266 0:6946b0b9e323 159 return (_wloc == _rloc) ? 0 : 1;
group-ESP8266 0:6946b0b9e323 160 }
group-ESP8266 0:6946b0b9e323 161
group-ESP8266 0:6946b0b9e323 162 #endif
group-ESP8266 0:6946b0b9e323 163