Toyomasa Watarai
/
Mbed-example-WS-W27
Mbed Cloud example program for workshop in W27 2018.
easy-connect/wifi-x-nucleo-idw01m1/SPWFSAxx.h@0:119624335925, 2018-06-30 (annotated)
- Committer:
- MACRUM
- Date:
- Sat Jun 30 01:40:30 2018 +0000
- Revision:
- 0:119624335925
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:119624335925 | 1 | /* SPWFSAxx Devices |
MACRUM | 0:119624335925 | 2 | * Copyright (c) 2015 ARM Limited |
MACRUM | 0:119624335925 | 3 | * |
MACRUM | 0:119624335925 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MACRUM | 0:119624335925 | 5 | * you may not use this file except in compliance with the License. |
MACRUM | 0:119624335925 | 6 | * You may obtain a copy of the License at |
MACRUM | 0:119624335925 | 7 | * |
MACRUM | 0:119624335925 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MACRUM | 0:119624335925 | 9 | * |
MACRUM | 0:119624335925 | 10 | * Unless required by applicable law or agreed to in writing, software |
MACRUM | 0:119624335925 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MACRUM | 0:119624335925 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MACRUM | 0:119624335925 | 13 | * See the License for the specific language governing permissions and |
MACRUM | 0:119624335925 | 14 | * limitations under the License. |
MACRUM | 0:119624335925 | 15 | */ |
MACRUM | 0:119624335925 | 16 | |
MACRUM | 0:119624335925 | 17 | #ifndef SPWFSAXX_H |
MACRUM | 0:119624335925 | 18 | #define SPWFSAXX_H |
MACRUM | 0:119624335925 | 19 | |
MACRUM | 0:119624335925 | 20 | #include "mbed.h" |
MACRUM | 0:119624335925 | 21 | #include "ATCmdParser.h" |
MACRUM | 0:119624335925 | 22 | #include "BlockExecuter.h" |
MACRUM | 0:119624335925 | 23 | |
MACRUM | 0:119624335925 | 24 | /* Common SPWFSAxx macros */ |
MACRUM | 0:119624335925 | 25 | #define SPWFXX_WINDS_LOW_ON "0x00000000" |
MACRUM | 0:119624335925 | 26 | #define SPWFXX_DEFAULT_BAUD_RATE 115200 |
MACRUM | 0:119624335925 | 27 | #define SPWFXX_MAX_TRIALS 3 |
MACRUM | 0:119624335925 | 28 | |
MACRUM | 0:119624335925 | 29 | #if !defined(SPWFSAXX_RTS_PIN) |
MACRUM | 0:119624335925 | 30 | #define SPWFSAXX_RTS_PIN NC |
MACRUM | 0:119624335925 | 31 | #endif // !defined(SPWFSAXX_RTS_PIN) |
MACRUM | 0:119624335925 | 32 | #if !defined(SPWFSAXX_CTS_PIN) |
MACRUM | 0:119624335925 | 33 | #define SPWFSAXX_CTS_PIN NC |
MACRUM | 0:119624335925 | 34 | #endif // !defined(SPWFSAXX_CTS_PIN) |
MACRUM | 0:119624335925 | 35 | |
MACRUM | 0:119624335925 | 36 | #define SPWFXX_ERR_OK (+1) |
MACRUM | 0:119624335925 | 37 | #define SPWFXX_ERR_OOM (-1) |
MACRUM | 0:119624335925 | 38 | #define SPWFXX_ERR_READ (-2) |
MACRUM | 0:119624335925 | 39 | #define SPWFXX_ERR_LEN (-3) |
MACRUM | 0:119624335925 | 40 | |
MACRUM | 0:119624335925 | 41 | |
MACRUM | 0:119624335925 | 42 | /* Max number of sockets & packets */ |
MACRUM | 0:119624335925 | 43 | #define SPWFSA_SOCKET_COUNT (8) |
MACRUM | 0:119624335925 | 44 | #define SPWFSA_MAX_PACKETS (4) |
MACRUM | 0:119624335925 | 45 | |
MACRUM | 0:119624335925 | 46 | #define PENDING_DATA_SLOTS (13) |
MACRUM | 0:119624335925 | 47 | |
MACRUM | 0:119624335925 | 48 | /* Pending data packets size buffer */ |
MACRUM | 0:119624335925 | 49 | class SpwfRealPendingPackets { |
MACRUM | 0:119624335925 | 50 | public: |
MACRUM | 0:119624335925 | 51 | SpwfRealPendingPackets() { |
MACRUM | 0:119624335925 | 52 | reset(); |
MACRUM | 0:119624335925 | 53 | } |
MACRUM | 0:119624335925 | 54 | |
MACRUM | 0:119624335925 | 55 | void add(uint32_t new_cum_size) { |
MACRUM | 0:119624335925 | 56 | MBED_ASSERT(new_cum_size >= cumulative_size); |
MACRUM | 0:119624335925 | 57 | |
MACRUM | 0:119624335925 | 58 | if(new_cum_size == cumulative_size) { |
MACRUM | 0:119624335925 | 59 | /* nothing to do */ |
MACRUM | 0:119624335925 | 60 | return; |
MACRUM | 0:119624335925 | 61 | } |
MACRUM | 0:119624335925 | 62 | |
MACRUM | 0:119624335925 | 63 | /* => `new_cum_size > cumulative_size` */ |
MACRUM | 0:119624335925 | 64 | real_pkt_sizes[last_pkt_ptr] = (uint16_t)(new_cum_size - cumulative_size); |
MACRUM | 0:119624335925 | 65 | cumulative_size = new_cum_size; |
MACRUM | 0:119624335925 | 66 | |
MACRUM | 0:119624335925 | 67 | last_pkt_ptr = (last_pkt_ptr + 1) % PENDING_DATA_SLOTS; |
MACRUM | 0:119624335925 | 68 | |
MACRUM | 0:119624335925 | 69 | MBED_ASSERT(first_pkt_ptr != last_pkt_ptr); |
MACRUM | 0:119624335925 | 70 | } |
MACRUM | 0:119624335925 | 71 | |
MACRUM | 0:119624335925 | 72 | uint32_t get(void) { |
MACRUM | 0:119624335925 | 73 | if(empty()) return 0; |
MACRUM | 0:119624335925 | 74 | |
MACRUM | 0:119624335925 | 75 | return real_pkt_sizes[first_pkt_ptr]; |
MACRUM | 0:119624335925 | 76 | } |
MACRUM | 0:119624335925 | 77 | |
MACRUM | 0:119624335925 | 78 | uint32_t cumulative(void) { |
MACRUM | 0:119624335925 | 79 | return cumulative_size; |
MACRUM | 0:119624335925 | 80 | } |
MACRUM | 0:119624335925 | 81 | |
MACRUM | 0:119624335925 | 82 | uint32_t remove(uint32_t size) { |
MACRUM | 0:119624335925 | 83 | MBED_ASSERT(!empty()); |
MACRUM | 0:119624335925 | 84 | |
MACRUM | 0:119624335925 | 85 | uint32_t ret = real_pkt_sizes[first_pkt_ptr]; |
MACRUM | 0:119624335925 | 86 | first_pkt_ptr = (first_pkt_ptr + 1) % PENDING_DATA_SLOTS; |
MACRUM | 0:119624335925 | 87 | |
MACRUM | 0:119624335925 | 88 | MBED_ASSERT(ret == size); |
MACRUM | 0:119624335925 | 89 | MBED_ASSERT(ret <= cumulative_size); |
MACRUM | 0:119624335925 | 90 | cumulative_size -= ret; |
MACRUM | 0:119624335925 | 91 | |
MACRUM | 0:119624335925 | 92 | return ret; |
MACRUM | 0:119624335925 | 93 | } |
MACRUM | 0:119624335925 | 94 | |
MACRUM | 0:119624335925 | 95 | void reset(void) { |
MACRUM | 0:119624335925 | 96 | memset(this, 0, sizeof(*this)); |
MACRUM | 0:119624335925 | 97 | } |
MACRUM | 0:119624335925 | 98 | |
MACRUM | 0:119624335925 | 99 | private: |
MACRUM | 0:119624335925 | 100 | bool empty(void) { |
MACRUM | 0:119624335925 | 101 | if(first_pkt_ptr == last_pkt_ptr) { |
MACRUM | 0:119624335925 | 102 | MBED_ASSERT(cumulative_size == 0); |
MACRUM | 0:119624335925 | 103 | return true; |
MACRUM | 0:119624335925 | 104 | } |
MACRUM | 0:119624335925 | 105 | return false; |
MACRUM | 0:119624335925 | 106 | } |
MACRUM | 0:119624335925 | 107 | |
MACRUM | 0:119624335925 | 108 | uint16_t real_pkt_sizes[PENDING_DATA_SLOTS]; |
MACRUM | 0:119624335925 | 109 | uint8_t first_pkt_ptr; |
MACRUM | 0:119624335925 | 110 | uint8_t last_pkt_ptr; |
MACRUM | 0:119624335925 | 111 | uint32_t cumulative_size; |
MACRUM | 0:119624335925 | 112 | }; |
MACRUM | 0:119624335925 | 113 | |
MACRUM | 0:119624335925 | 114 | class SpwfSAInterface; |
MACRUM | 0:119624335925 | 115 | |
MACRUM | 0:119624335925 | 116 | /** SPWFSAxx Interface class. |
MACRUM | 0:119624335925 | 117 | This is an interface to a SPWFSAxx module. |
MACRUM | 0:119624335925 | 118 | */ |
MACRUM | 0:119624335925 | 119 | class SPWFSAxx |
MACRUM | 0:119624335925 | 120 | { |
MACRUM | 0:119624335925 | 121 | private: |
MACRUM | 0:119624335925 | 122 | /* abstract class*/ |
MACRUM | 0:119624335925 | 123 | SPWFSAxx(PinName tx, PinName rx, PinName rts, PinName cts, |
MACRUM | 0:119624335925 | 124 | SpwfSAInterface &ifce, bool debug, |
MACRUM | 0:119624335925 | 125 | PinName wakeup, PinName reset); |
MACRUM | 0:119624335925 | 126 | |
MACRUM | 0:119624335925 | 127 | public: |
MACRUM | 0:119624335925 | 128 | /** |
MACRUM | 0:119624335925 | 129 | * Init the SPWFSAxx |
MACRUM | 0:119624335925 | 130 | * |
MACRUM | 0:119624335925 | 131 | * @param mode mode in which to startup |
MACRUM | 0:119624335925 | 132 | * @return true only if SPWFSAxx has started up correctly |
MACRUM | 0:119624335925 | 133 | */ |
MACRUM | 0:119624335925 | 134 | bool startup(int mode); |
MACRUM | 0:119624335925 | 135 | |
MACRUM | 0:119624335925 | 136 | /** |
MACRUM | 0:119624335925 | 137 | * Connect SPWFSAxx to AP |
MACRUM | 0:119624335925 | 138 | * |
MACRUM | 0:119624335925 | 139 | * @param ap the name of the AP |
MACRUM | 0:119624335925 | 140 | * @param passPhrase the password of AP |
MACRUM | 0:119624335925 | 141 | * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open) |
MACRUM | 0:119624335925 | 142 | * @return true only if SPWFSAxx is connected successfully |
MACRUM | 0:119624335925 | 143 | */ |
MACRUM | 0:119624335925 | 144 | bool connect(const char *ap, const char *passPhrase, int securityMode); |
MACRUM | 0:119624335925 | 145 | |
MACRUM | 0:119624335925 | 146 | /** |
MACRUM | 0:119624335925 | 147 | * Disconnect SPWFSAxx from AP |
MACRUM | 0:119624335925 | 148 | * |
MACRUM | 0:119624335925 | 149 | * @return true only if SPWFSAxx is disconnected successfully |
MACRUM | 0:119624335925 | 150 | */ |
MACRUM | 0:119624335925 | 151 | bool disconnect(void); |
MACRUM | 0:119624335925 | 152 | |
MACRUM | 0:119624335925 | 153 | /** |
MACRUM | 0:119624335925 | 154 | * Get the IP address of SPWFSAxx |
MACRUM | 0:119624335925 | 155 | * |
MACRUM | 0:119624335925 | 156 | * @return null-terminated IP address or null if no IP address is assigned |
MACRUM | 0:119624335925 | 157 | */ |
MACRUM | 0:119624335925 | 158 | const char *getIPAddress(void); |
MACRUM | 0:119624335925 | 159 | |
MACRUM | 0:119624335925 | 160 | /** |
MACRUM | 0:119624335925 | 161 | * Get the MAC address of SPWFSAxx |
MACRUM | 0:119624335925 | 162 | * |
MACRUM | 0:119624335925 | 163 | * @return null-terminated MAC address or null if no MAC address is assigned |
MACRUM | 0:119624335925 | 164 | */ |
MACRUM | 0:119624335925 | 165 | const char *getMACAddress(void); |
MACRUM | 0:119624335925 | 166 | |
MACRUM | 0:119624335925 | 167 | /** Get the local gateway |
MACRUM | 0:119624335925 | 168 | * |
MACRUM | 0:119624335925 | 169 | * @return Null-terminated representation of the local gateway |
MACRUM | 0:119624335925 | 170 | * or null if no network mask has been received |
MACRUM | 0:119624335925 | 171 | */ |
MACRUM | 0:119624335925 | 172 | const char *getGateway(void); |
MACRUM | 0:119624335925 | 173 | |
MACRUM | 0:119624335925 | 174 | /** Get the local network mask |
MACRUM | 0:119624335925 | 175 | * |
MACRUM | 0:119624335925 | 176 | * @return Null-terminated representation of the local network mask |
MACRUM | 0:119624335925 | 177 | * or null if no network mask has been received |
MACRUM | 0:119624335925 | 178 | */ |
MACRUM | 0:119624335925 | 179 | const char *getNetmask(void); |
MACRUM | 0:119624335925 | 180 | |
MACRUM | 0:119624335925 | 181 | /** Gets the current radio signal strength for active connection |
MACRUM | 0:119624335925 | 182 | * |
MACRUM | 0:119624335925 | 183 | * @return Connection strength in dBm (negative value) |
MACRUM | 0:119624335925 | 184 | */ |
MACRUM | 0:119624335925 | 185 | int8_t getRssi(); |
MACRUM | 0:119624335925 | 186 | |
MACRUM | 0:119624335925 | 187 | /** |
MACRUM | 0:119624335925 | 188 | * Sends data to an open socket |
MACRUM | 0:119624335925 | 189 | * |
MACRUM | 0:119624335925 | 190 | * @param spwf_id module id of socket to send to |
MACRUM | 0:119624335925 | 191 | * @param data data to be sent |
MACRUM | 0:119624335925 | 192 | * @param amount amount of data to be sent - max 1024 |
MACRUM | 0:119624335925 | 193 | * @param internal_id driver id of socket to send to |
MACRUM | 0:119624335925 | 194 | * @return number of written bytes on success, negative on failure |
MACRUM | 0:119624335925 | 195 | */ |
MACRUM | 0:119624335925 | 196 | nsapi_size_or_error_t send(int spwf_id, const void *data, uint32_t amount, int internal_id); |
MACRUM | 0:119624335925 | 197 | |
MACRUM | 0:119624335925 | 198 | /** |
MACRUM | 0:119624335925 | 199 | * Receives data from an open socket |
MACRUM | 0:119624335925 | 200 | * |
MACRUM | 0:119624335925 | 201 | * @param id id to receive from |
MACRUM | 0:119624335925 | 202 | * @param data placeholder for returned information |
MACRUM | 0:119624335925 | 203 | * @param amount number of bytes to be received |
MACRUM | 0:119624335925 | 204 | * @param datagram receive a datagram packet |
MACRUM | 0:119624335925 | 205 | * @return the number of bytes received |
MACRUM | 0:119624335925 | 206 | */ |
MACRUM | 0:119624335925 | 207 | int32_t recv(int id, void *data, uint32_t amount, bool datagram); |
MACRUM | 0:119624335925 | 208 | |
MACRUM | 0:119624335925 | 209 | /** |
MACRUM | 0:119624335925 | 210 | * Closes a socket |
MACRUM | 0:119624335925 | 211 | * |
MACRUM | 0:119624335925 | 212 | * @param id id of socket to close, valid only 0-4 |
MACRUM | 0:119624335925 | 213 | * @return true only if socket is closed successfully |
MACRUM | 0:119624335925 | 214 | */ |
MACRUM | 0:119624335925 | 215 | bool close(int id); |
MACRUM | 0:119624335925 | 216 | |
MACRUM | 0:119624335925 | 217 | /** |
MACRUM | 0:119624335925 | 218 | * Allows timeout to be changed between commands |
MACRUM | 0:119624335925 | 219 | * |
MACRUM | 0:119624335925 | 220 | * @param timeout_ms timeout of the connection |
MACRUM | 0:119624335925 | 221 | */ |
MACRUM | 0:119624335925 | 222 | void setTimeout(uint32_t timeout_ms); |
MACRUM | 0:119624335925 | 223 | |
MACRUM | 0:119624335925 | 224 | /** |
MACRUM | 0:119624335925 | 225 | * Attach a function to call whenever network state has changed |
MACRUM | 0:119624335925 | 226 | * |
MACRUM | 0:119624335925 | 227 | * @param func A pointer to a void function, or 0 to set as none |
MACRUM | 0:119624335925 | 228 | */ |
MACRUM | 0:119624335925 | 229 | void attach(Callback<void()> func); |
MACRUM | 0:119624335925 | 230 | |
MACRUM | 0:119624335925 | 231 | /** |
MACRUM | 0:119624335925 | 232 | * Attach a function to call whenever network state has changed |
MACRUM | 0:119624335925 | 233 | * |
MACRUM | 0:119624335925 | 234 | * @param obj pointer to the object to call the member function on |
MACRUM | 0:119624335925 | 235 | * @param method pointer to the member function to call |
MACRUM | 0:119624335925 | 236 | */ |
MACRUM | 0:119624335925 | 237 | template <typename T, typename M> |
MACRUM | 0:119624335925 | 238 | void attach(T *obj, M method) { |
MACRUM | 0:119624335925 | 239 | attach(Callback<void()>(obj, method)); |
MACRUM | 0:119624335925 | 240 | } |
MACRUM | 0:119624335925 | 241 | |
MACRUM | 0:119624335925 | 242 | static const char _cr_ = '\x0d'; // '\r' carriage return |
MACRUM | 0:119624335925 | 243 | static const char _lf_ = '\x0a'; // '\n' line feed |
MACRUM | 0:119624335925 | 244 | |
MACRUM | 0:119624335925 | 245 | private: |
MACRUM | 0:119624335925 | 246 | UARTSerial _serial; |
MACRUM | 0:119624335925 | 247 | ATCmdParser _parser; |
MACRUM | 0:119624335925 | 248 | |
MACRUM | 0:119624335925 | 249 | DigitalOut _wakeup; |
MACRUM | 0:119624335925 | 250 | DigitalOut _reset; |
MACRUM | 0:119624335925 | 251 | PinName _rts; |
MACRUM | 0:119624335925 | 252 | PinName _cts; |
MACRUM | 0:119624335925 | 253 | |
MACRUM | 0:119624335925 | 254 | int _timeout; |
MACRUM | 0:119624335925 | 255 | bool _dbg_on; |
MACRUM | 0:119624335925 | 256 | |
MACRUM | 0:119624335925 | 257 | int _pending_sockets_bitmap; |
MACRUM | 0:119624335925 | 258 | SpwfRealPendingPackets _pending_pkt_sizes[SPWFSA_SOCKET_COUNT]; |
MACRUM | 0:119624335925 | 259 | |
MACRUM | 0:119624335925 | 260 | bool _network_lost_flag; |
MACRUM | 0:119624335925 | 261 | SpwfSAInterface &_associated_interface; |
MACRUM | 0:119624335925 | 262 | |
MACRUM | 0:119624335925 | 263 | /** |
MACRUM | 0:119624335925 | 264 | * Reset SPWFSAxx |
MACRUM | 0:119624335925 | 265 | * |
MACRUM | 0:119624335925 | 266 | * @return true only if SPWFSAxx resets successfully |
MACRUM | 0:119624335925 | 267 | */ |
MACRUM | 0:119624335925 | 268 | bool hw_reset(void); |
MACRUM | 0:119624335925 | 269 | bool reset(void); |
MACRUM | 0:119624335925 | 270 | |
MACRUM | 0:119624335925 | 271 | /** |
MACRUM | 0:119624335925 | 272 | * Check if SPWFSAxx is connected |
MACRUM | 0:119624335925 | 273 | * |
MACRUM | 0:119624335925 | 274 | * @return true only if the chip has an IP address |
MACRUM | 0:119624335925 | 275 | */ |
MACRUM | 0:119624335925 | 276 | bool isConnected(void); |
MACRUM | 0:119624335925 | 277 | |
MACRUM | 0:119624335925 | 278 | /** |
MACRUM | 0:119624335925 | 279 | * Checks if data is available |
MACRUM | 0:119624335925 | 280 | */ |
MACRUM | 0:119624335925 | 281 | bool readable(void) { |
MACRUM | 0:119624335925 | 282 | return _serial.FileHandle::readable(); |
MACRUM | 0:119624335925 | 283 | } |
MACRUM | 0:119624335925 | 284 | |
MACRUM | 0:119624335925 | 285 | /** |
MACRUM | 0:119624335925 | 286 | * Checks if data can be written |
MACRUM | 0:119624335925 | 287 | */ |
MACRUM | 0:119624335925 | 288 | bool writeable(void) { |
MACRUM | 0:119624335925 | 289 | return _serial.FileHandle::writable(); |
MACRUM | 0:119624335925 | 290 | } |
MACRUM | 0:119624335925 | 291 | |
MACRUM | 0:119624335925 | 292 | /** |
MACRUM | 0:119624335925 | 293 | * Try to empty RX buffer |
MACRUM | 0:119624335925 | 294 | * Can be used when commands fail receiving expected response to try to recover situation |
MACRUM | 0:119624335925 | 295 | * @note Gives no guarantee that situation improves |
MACRUM | 0:119624335925 | 296 | */ |
MACRUM | 0:119624335925 | 297 | void empty_rx_buffer(void) { |
MACRUM | 0:119624335925 | 298 | while(readable()) _parser.getc(); |
MACRUM | 0:119624335925 | 299 | } |
MACRUM | 0:119624335925 | 300 | |
MACRUM | 0:119624335925 | 301 | /* block calling (external) callback */ |
MACRUM | 0:119624335925 | 302 | volatile unsigned int _call_event_callback_blocked; |
MACRUM | 0:119624335925 | 303 | Callback<void()> _callback_func; |
MACRUM | 0:119624335925 | 304 | |
MACRUM | 0:119624335925 | 305 | struct packet { |
MACRUM | 0:119624335925 | 306 | struct packet *next; |
MACRUM | 0:119624335925 | 307 | int id; |
MACRUM | 0:119624335925 | 308 | uint32_t len; |
MACRUM | 0:119624335925 | 309 | // data follows |
MACRUM | 0:119624335925 | 310 | } *_packets, **_packets_end; |
MACRUM | 0:119624335925 | 311 | |
MACRUM | 0:119624335925 | 312 | void _packet_handler_th(void); |
MACRUM | 0:119624335925 | 313 | void _execute_bottom_halves(void); |
MACRUM | 0:119624335925 | 314 | void _network_lost_handler_th(void); |
MACRUM | 0:119624335925 | 315 | void _network_lost_handler_bh(void); |
MACRUM | 0:119624335925 | 316 | void _hard_fault_handler(void); |
MACRUM | 0:119624335925 | 317 | void _wifi_hwfault_handler(void); |
MACRUM | 0:119624335925 | 318 | void _server_gone_handler(void); |
MACRUM | 0:119624335925 | 319 | #if MBED_CONF_IDW0XX1_EXPANSION_BOARD == IDW04A1 |
MACRUM | 0:119624335925 | 320 | void _skip_oob(void); |
MACRUM | 0:119624335925 | 321 | #endif |
MACRUM | 0:119624335925 | 322 | bool _wait_wifi_hw_started(void); |
MACRUM | 0:119624335925 | 323 | bool _wait_console_active(void); |
MACRUM | 0:119624335925 | 324 | int _read_len(int); |
MACRUM | 0:119624335925 | 325 | int _flush_in(char*, int); |
MACRUM | 0:119624335925 | 326 | bool _winds_off(void); |
MACRUM | 0:119624335925 | 327 | void _winds_on(void); |
MACRUM | 0:119624335925 | 328 | void _read_in_pending(void); |
MACRUM | 0:119624335925 | 329 | int _read_in_pkt(int spwf_id, bool close); |
MACRUM | 0:119624335925 | 330 | int _read_in_packet(int spwf_id, uint32_t amount); |
MACRUM | 0:119624335925 | 331 | void _recover_from_hard_faults(void); |
MACRUM | 0:119624335925 | 332 | void _free_packets(int spwf_id); |
MACRUM | 0:119624335925 | 333 | void _free_all_packets(void); |
MACRUM | 0:119624335925 | 334 | void _process_winds(); |
MACRUM | 0:119624335925 | 335 | |
MACRUM | 0:119624335925 | 336 | virtual int _read_in(char*, int, uint32_t) = 0; |
MACRUM | 0:119624335925 | 337 | |
MACRUM | 0:119624335925 | 338 | bool _recv_delim_lf(void) { |
MACRUM | 0:119624335925 | 339 | return (_parser.getc() == _lf_); |
MACRUM | 0:119624335925 | 340 | } |
MACRUM | 0:119624335925 | 341 | |
MACRUM | 0:119624335925 | 342 | bool _recv_delim_cr(void) { |
MACRUM | 0:119624335925 | 343 | return (_parser.getc() == _cr_); |
MACRUM | 0:119624335925 | 344 | } |
MACRUM | 0:119624335925 | 345 | |
MACRUM | 0:119624335925 | 346 | bool _recv_delim_cr_lf(void) { |
MACRUM | 0:119624335925 | 347 | return _recv_delim_cr() && _recv_delim_lf(); |
MACRUM | 0:119624335925 | 348 | } |
MACRUM | 0:119624335925 | 349 | |
MACRUM | 0:119624335925 | 350 | bool _recv_ok(void) { |
MACRUM | 0:119624335925 | 351 | return _parser.recv(SPWFXX_RECV_OK) && _recv_delim_lf(); |
MACRUM | 0:119624335925 | 352 | } |
MACRUM | 0:119624335925 | 353 | |
MACRUM | 0:119624335925 | 354 | void _add_pending_packet_sz(int spwf_id, uint32_t size); |
MACRUM | 0:119624335925 | 355 | void _add_pending_pkt_size(int spwf_id, uint32_t size) { |
MACRUM | 0:119624335925 | 356 | _pending_pkt_sizes[spwf_id].add(size); |
MACRUM | 0:119624335925 | 357 | } |
MACRUM | 0:119624335925 | 358 | |
MACRUM | 0:119624335925 | 359 | uint32_t _get_cumulative_size(int spwf_id) { |
MACRUM | 0:119624335925 | 360 | return _pending_pkt_sizes[spwf_id].cumulative(); |
MACRUM | 0:119624335925 | 361 | } |
MACRUM | 0:119624335925 | 362 | |
MACRUM | 0:119624335925 | 363 | uint32_t _remove_pending_pkt_size(int spwf_id, uint32_t size) { |
MACRUM | 0:119624335925 | 364 | return _pending_pkt_sizes[spwf_id].remove(size); |
MACRUM | 0:119624335925 | 365 | } |
MACRUM | 0:119624335925 | 366 | |
MACRUM | 0:119624335925 | 367 | uint32_t _get_pending_pkt_size(int spwf_id) { |
MACRUM | 0:119624335925 | 368 | return _pending_pkt_sizes[spwf_id].get(); |
MACRUM | 0:119624335925 | 369 | } |
MACRUM | 0:119624335925 | 370 | |
MACRUM | 0:119624335925 | 371 | void _reset_pending_pkt_sizes(int spwf_id) { |
MACRUM | 0:119624335925 | 372 | _pending_pkt_sizes[spwf_id].reset(); |
MACRUM | 0:119624335925 | 373 | } |
MACRUM | 0:119624335925 | 374 | |
MACRUM | 0:119624335925 | 375 | void _set_pending_data(int spwf_id) { |
MACRUM | 0:119624335925 | 376 | _pending_sockets_bitmap |= (1 << spwf_id); |
MACRUM | 0:119624335925 | 377 | } |
MACRUM | 0:119624335925 | 378 | |
MACRUM | 0:119624335925 | 379 | void _clear_pending_data(int spwf_id) { |
MACRUM | 0:119624335925 | 380 | _pending_sockets_bitmap &= ~(1 << spwf_id); |
MACRUM | 0:119624335925 | 381 | } |
MACRUM | 0:119624335925 | 382 | |
MACRUM | 0:119624335925 | 383 | bool _is_data_pending(int spwf_id) { |
MACRUM | 0:119624335925 | 384 | return (_pending_sockets_bitmap & (1 << spwf_id)) ? true : false; |
MACRUM | 0:119624335925 | 385 | } |
MACRUM | 0:119624335925 | 386 | |
MACRUM | 0:119624335925 | 387 | bool _is_data_pending(void) { |
MACRUM | 0:119624335925 | 388 | if(_pending_sockets_bitmap != 0) return true; |
MACRUM | 0:119624335925 | 389 | else return false; |
MACRUM | 0:119624335925 | 390 | } |
MACRUM | 0:119624335925 | 391 | |
MACRUM | 0:119624335925 | 392 | void _packet_handler_bh(void) { |
MACRUM | 0:119624335925 | 393 | /* read in other eventually pending packages */ |
MACRUM | 0:119624335925 | 394 | _read_in_pending(); |
MACRUM | 0:119624335925 | 395 | } |
MACRUM | 0:119624335925 | 396 | |
MACRUM | 0:119624335925 | 397 | /* Do not call the (external) callback in IRQ context while performing critical module operations */ |
MACRUM | 0:119624335925 | 398 | void _event_handler(void); |
MACRUM | 0:119624335925 | 399 | |
MACRUM | 0:119624335925 | 400 | void _error_handler(void); |
MACRUM | 0:119624335925 | 401 | |
MACRUM | 0:119624335925 | 402 | void _call_callback(void) { |
MACRUM | 0:119624335925 | 403 | if((bool)_callback_func) { |
MACRUM | 0:119624335925 | 404 | _callback_func(); |
MACRUM | 0:119624335925 | 405 | } |
MACRUM | 0:119624335925 | 406 | } |
MACRUM | 0:119624335925 | 407 | |
MACRUM | 0:119624335925 | 408 | bool _is_event_callback_blocked(void) { |
MACRUM | 0:119624335925 | 409 | return (_call_event_callback_blocked != 0); |
MACRUM | 0:119624335925 | 410 | } |
MACRUM | 0:119624335925 | 411 | |
MACRUM | 0:119624335925 | 412 | void _block_event_callback(void) { |
MACRUM | 0:119624335925 | 413 | _call_event_callback_blocked++; |
MACRUM | 0:119624335925 | 414 | } |
MACRUM | 0:119624335925 | 415 | |
MACRUM | 0:119624335925 | 416 | void _unblock_event_callback(void) { |
MACRUM | 0:119624335925 | 417 | MBED_ASSERT(_call_event_callback_blocked > 0); |
MACRUM | 0:119624335925 | 418 | _call_event_callback_blocked--; |
MACRUM | 0:119624335925 | 419 | if(_call_event_callback_blocked == 0) { |
MACRUM | 0:119624335925 | 420 | _trigger_event_callback(); |
MACRUM | 0:119624335925 | 421 | } |
MACRUM | 0:119624335925 | 422 | } |
MACRUM | 0:119624335925 | 423 | |
MACRUM | 0:119624335925 | 424 | /* trigger call of (external) callback in case there is still data */ |
MACRUM | 0:119624335925 | 425 | void _trigger_event_callback(void) { |
MACRUM | 0:119624335925 | 426 | MBED_ASSERT(_call_event_callback_blocked == 0); |
MACRUM | 0:119624335925 | 427 | /* if still data available */ |
MACRUM | 0:119624335925 | 428 | if(readable()) { |
MACRUM | 0:119624335925 | 429 | _call_callback(); |
MACRUM | 0:119624335925 | 430 | } |
MACRUM | 0:119624335925 | 431 | } |
MACRUM | 0:119624335925 | 432 | |
MACRUM | 0:119624335925 | 433 | char _ip_buffer[16]; |
MACRUM | 0:119624335925 | 434 | char _gateway_buffer[16]; |
MACRUM | 0:119624335925 | 435 | char _netmask_buffer[16]; |
MACRUM | 0:119624335925 | 436 | char _mac_buffer[18]; |
MACRUM | 0:119624335925 | 437 | |
MACRUM | 0:119624335925 | 438 | char _msg_buffer[256]; |
MACRUM | 0:119624335925 | 439 | |
MACRUM | 0:119624335925 | 440 | private: |
MACRUM | 0:119624335925 | 441 | friend class SPWFSA01; |
MACRUM | 0:119624335925 | 442 | friend class SPWFSA04; |
MACRUM | 0:119624335925 | 443 | friend class SpwfSAInterface; |
MACRUM | 0:119624335925 | 444 | }; |
MACRUM | 0:119624335925 | 445 | |
MACRUM | 0:119624335925 | 446 | #endif // SPWFSAXX_H |