cc
SPWFSA01.h@13:f21e4e73bbb6, 2016-08-02 (annotated)
- Committer:
- mridup
- Date:
- Tue Aug 02 07:03:54 2016 +0000
- Revision:
- 13:f21e4e73bbb6
- Parent:
- 5:f17d6351e942
- Child:
- 24:419285201dba
debug_if, sock open time out, sock recv returns "device error" apart from "would block".
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 0:9e5d98ceea74 | 1 | /* SPWFInterface Example |
mridup | 0:9e5d98ceea74 | 2 | * Copyright (c) 2015 ARM Limited |
mridup | 0:9e5d98ceea74 | 3 | * |
mridup | 0:9e5d98ceea74 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mridup | 0:9e5d98ceea74 | 5 | * you may not use this file except in compliance with the License. |
mridup | 0:9e5d98ceea74 | 6 | * You may obtain a copy of the License at |
mridup | 0:9e5d98ceea74 | 7 | * |
mridup | 0:9e5d98ceea74 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mridup | 0:9e5d98ceea74 | 9 | * |
mridup | 0:9e5d98ceea74 | 10 | * Unless required by applicable law or agreed to in writing, software |
mridup | 0:9e5d98ceea74 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mridup | 0:9e5d98ceea74 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mridup | 0:9e5d98ceea74 | 13 | * See the License for the specific language governing permissions and |
mridup | 0:9e5d98ceea74 | 14 | * limitations under the License. |
mridup | 0:9e5d98ceea74 | 15 | */ |
mridup | 0:9e5d98ceea74 | 16 | |
mridup | 0:9e5d98ceea74 | 17 | #ifndef SPWFSA01_H |
mridup | 0:9e5d98ceea74 | 18 | #define SPWFSA01_H |
mridup | 0:9e5d98ceea74 | 19 | |
mridup | 0:9e5d98ceea74 | 20 | #include "ATParser.h" |
mridup | 0:9e5d98ceea74 | 21 | |
mridup | 0:9e5d98ceea74 | 22 | /** SPWFSA01Interface class. |
mridup | 0:9e5d98ceea74 | 23 | This is an interface to a SPWFSA01 module. |
mridup | 0:9e5d98ceea74 | 24 | */ |
mridup | 0:9e5d98ceea74 | 25 | class SPWFSA01 |
mridup | 0:9e5d98ceea74 | 26 | { |
mridup | 0:9e5d98ceea74 | 27 | public: |
mridup | 0:9e5d98ceea74 | 28 | SPWFSA01(PinName tx, PinName rx, bool debug=false); |
mridup | 0:9e5d98ceea74 | 29 | |
mridup | 0:9e5d98ceea74 | 30 | /** |
mridup | 0:9e5d98ceea74 | 31 | * Init the SPWFSA01 |
mridup | 0:9e5d98ceea74 | 32 | * |
mridup | 0:9e5d98ceea74 | 33 | * @param mode mode in which to startup |
mridup | 0:9e5d98ceea74 | 34 | * @return true only if SPWFSA01 has started up correctly |
mridup | 0:9e5d98ceea74 | 35 | */ |
mridup | 0:9e5d98ceea74 | 36 | bool startup(int mode); |
mridup | 0:9e5d98ceea74 | 37 | |
mridup | 0:9e5d98ceea74 | 38 | void waitSPWFReady(void); |
mridup | 0:9e5d98ceea74 | 39 | /** |
mridup | 0:9e5d98ceea74 | 40 | * Reset SPWFSA01 |
mridup | 0:9e5d98ceea74 | 41 | * |
mridup | 0:9e5d98ceea74 | 42 | * @return true only if SPWFSA01 resets successfully |
mridup | 0:9e5d98ceea74 | 43 | */ |
mridup | 0:9e5d98ceea74 | 44 | bool reset(void); |
mridup | 0:9e5d98ceea74 | 45 | |
mridup | 0:9e5d98ceea74 | 46 | bool hw_reset(void); |
mridup | 0:9e5d98ceea74 | 47 | |
mridup | 0:9e5d98ceea74 | 48 | /** |
mridup | 0:9e5d98ceea74 | 49 | * Enable/Disable DHCP |
mridup | 0:9e5d98ceea74 | 50 | * |
mridup | 5:f17d6351e942 | 51 | * @param mode mode of DHCP 2-softAP, 1-on, 0-off |
mridup | 0:9e5d98ceea74 | 52 | * @return true only if SPWFSA01 enables/disables DHCP successfully |
mridup | 0:9e5d98ceea74 | 53 | */ |
mridup | 5:f17d6351e942 | 54 | bool dhcp(int mode); |
mridup | 0:9e5d98ceea74 | 55 | |
mridup | 0:9e5d98ceea74 | 56 | /** |
mridup | 0:9e5d98ceea74 | 57 | * Connect SPWFSA01 to AP |
mridup | 0:9e5d98ceea74 | 58 | * |
mridup | 0:9e5d98ceea74 | 59 | * @param ap the name of the AP |
mridup | 0:9e5d98ceea74 | 60 | * @param passPhrase the password of AP |
mridup | 0:9e5d98ceea74 | 61 | * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open) |
mridup | 0:9e5d98ceea74 | 62 | * @return true only if SPWFSA01 is connected successfully |
mridup | 0:9e5d98ceea74 | 63 | */ |
mridup | 0:9e5d98ceea74 | 64 | bool connect(const char *ap, const char *passPhrase, int securityMode); |
mridup | 0:9e5d98ceea74 | 65 | |
mridup | 0:9e5d98ceea74 | 66 | /** |
mridup | 0:9e5d98ceea74 | 67 | * Disconnect SPWFSA01 from AP |
mridup | 0:9e5d98ceea74 | 68 | * |
mridup | 0:9e5d98ceea74 | 69 | * @return true only if SPWFSA01 is disconnected successfully |
mridup | 0:9e5d98ceea74 | 70 | */ |
mridup | 0:9e5d98ceea74 | 71 | bool disconnect(void); |
mridup | 0:9e5d98ceea74 | 72 | |
mridup | 0:9e5d98ceea74 | 73 | /** |
mridup | 0:9e5d98ceea74 | 74 | * Get the IP address of SPWFSA01 |
mridup | 0:9e5d98ceea74 | 75 | * |
mridup | 0:9e5d98ceea74 | 76 | * @return null-teriminated IP address or null if no IP address is assigned |
mridup | 0:9e5d98ceea74 | 77 | */ |
mridup | 0:9e5d98ceea74 | 78 | const char *getIPAddress(void); |
mridup | 0:9e5d98ceea74 | 79 | |
mridup | 0:9e5d98ceea74 | 80 | /** |
mridup | 0:9e5d98ceea74 | 81 | * Get the MAC address of SPWFSA01 |
mridup | 0:9e5d98ceea74 | 82 | * |
mridup | 0:9e5d98ceea74 | 83 | * @return null-terminated MAC address or null if no MAC address is assigned |
mridup | 0:9e5d98ceea74 | 84 | */ |
mridup | 0:9e5d98ceea74 | 85 | const char *getMACAddress(void); |
mridup | 0:9e5d98ceea74 | 86 | |
mridup | 0:9e5d98ceea74 | 87 | /** |
mridup | 0:9e5d98ceea74 | 88 | * Check if SPWFSA01 is conenected |
mridup | 0:9e5d98ceea74 | 89 | * |
mridup | 0:9e5d98ceea74 | 90 | * @return true only if the chip has an IP address |
mridup | 0:9e5d98ceea74 | 91 | */ |
mridup | 0:9e5d98ceea74 | 92 | bool isConnected(void); |
mridup | 0:9e5d98ceea74 | 93 | |
mridup | 0:9e5d98ceea74 | 94 | /** |
mridup | 0:9e5d98ceea74 | 95 | * Open a socketed connection |
mridup | 0:9e5d98ceea74 | 96 | * |
mridup | 5:f17d6351e942 | 97 | * @param type the type of socket to open "u" (UDP) or "t" (TCP) |
mridup | 5:f17d6351e942 | 98 | * @param id id to get the new socket number, valid 0-7 |
mridup | 0:9e5d98ceea74 | 99 | * @param port port to open connection with |
mridup | 0:9e5d98ceea74 | 100 | * @param addr the IP address of the destination |
mridup | 0:9e5d98ceea74 | 101 | * @return true only if socket opened successfully |
mridup | 0:9e5d98ceea74 | 102 | */ |
mridup | 3:2af9df1068a5 | 103 | bool open(const char *type, int* id, const char* addr, int port); |
mridup | 0:9e5d98ceea74 | 104 | |
mridup | 0:9e5d98ceea74 | 105 | /** |
mridup | 0:9e5d98ceea74 | 106 | * Sends data to an open socket |
mridup | 0:9e5d98ceea74 | 107 | * |
mridup | 0:9e5d98ceea74 | 108 | * @param id id of socket to send to |
mridup | 0:9e5d98ceea74 | 109 | * @param data data to be sent |
mridup | 0:9e5d98ceea74 | 110 | * @param amount amount of data to be sent - max 1024 |
mridup | 0:9e5d98ceea74 | 111 | * @return true only if data sent successfully |
mridup | 0:9e5d98ceea74 | 112 | */ |
mridup | 0:9e5d98ceea74 | 113 | bool send(int id, const void *data, uint32_t amount); |
mridup | 0:9e5d98ceea74 | 114 | |
mridup | 0:9e5d98ceea74 | 115 | /** |
mridup | 0:9e5d98ceea74 | 116 | * Receives data from an open socket |
mridup | 0:9e5d98ceea74 | 117 | * |
mridup | 0:9e5d98ceea74 | 118 | * @param id id to receive from |
mridup | 0:9e5d98ceea74 | 119 | * @param data placeholder for returned information |
mridup | 0:9e5d98ceea74 | 120 | * @param amount number of bytes to be received |
mridup | 0:9e5d98ceea74 | 121 | * @return the number of bytes received |
mridup | 0:9e5d98ceea74 | 122 | */ |
mridup | 0:9e5d98ceea74 | 123 | int32_t recv(int id, void *data, uint32_t amount); |
mridup | 0:9e5d98ceea74 | 124 | |
mridup | 0:9e5d98ceea74 | 125 | /** |
mridup | 0:9e5d98ceea74 | 126 | * Closes a socket |
mridup | 0:9e5d98ceea74 | 127 | * |
mridup | 0:9e5d98ceea74 | 128 | * @param id id of socket to close, valid only 0-4 |
mridup | 0:9e5d98ceea74 | 129 | * @return true only if socket is closed successfully |
mridup | 0:9e5d98ceea74 | 130 | */ |
mridup | 0:9e5d98ceea74 | 131 | bool close(int id); |
mridup | 0:9e5d98ceea74 | 132 | |
mridup | 0:9e5d98ceea74 | 133 | /** |
mridup | 0:9e5d98ceea74 | 134 | * Allows timeout to be changed between commands |
mridup | 0:9e5d98ceea74 | 135 | * |
mridup | 0:9e5d98ceea74 | 136 | * @param timeout_ms timeout of the connection |
mridup | 0:9e5d98ceea74 | 137 | */ |
mridup | 0:9e5d98ceea74 | 138 | void setTimeout(uint32_t timeout_ms); |
mridup | 0:9e5d98ceea74 | 139 | |
mridup | 0:9e5d98ceea74 | 140 | /** |
mridup | 0:9e5d98ceea74 | 141 | * Checks if data is available |
mridup | 0:9e5d98ceea74 | 142 | */ |
mridup | 0:9e5d98ceea74 | 143 | bool readable(); |
mridup | 0:9e5d98ceea74 | 144 | |
mridup | 0:9e5d98ceea74 | 145 | /** |
mridup | 0:9e5d98ceea74 | 146 | * Checks if data can be written |
mridup | 0:9e5d98ceea74 | 147 | */ |
mridup | 0:9e5d98ceea74 | 148 | bool writeable(); |
mridup | 0:9e5d98ceea74 | 149 | |
mridup | 0:9e5d98ceea74 | 150 | private: |
mridup | 0:9e5d98ceea74 | 151 | BufferedSerial _serial; |
mridup | 0:9e5d98ceea74 | 152 | ATParser _parser; |
mridup | 0:9e5d98ceea74 | 153 | DigitalInOut _wakeup; |
mridup | 0:9e5d98ceea74 | 154 | DigitalInOut _reset; |
mridup | 0:9e5d98ceea74 | 155 | |
mridup | 0:9e5d98ceea74 | 156 | char _ip_buffer[16]; |
mridup | 0:9e5d98ceea74 | 157 | char _mac_buffer[18]; |
mridup | 13:f21e4e73bbb6 | 158 | bool dbg_on; |
mridup | 0:9e5d98ceea74 | 159 | }; |
mridup | 0:9e5d98ceea74 | 160 | |
mridup | 0:9e5d98ceea74 | 161 | #endif //SPWFSA01_H |