driver for the WNC M14A2A Cellular Data Module
WNC14A2AInterface/WNC14A2AInterface.h@0:6a2d96c2a520, 2018-02-06 (annotated)
- Committer:
- JMF
- Date:
- Tue Feb 06 16:10:48 2018 +0000
- Revision:
- 0:6a2d96c2a520
Incorporating changes suggested by ARM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:6a2d96c2a520 | 1 | /** |
JMF | 0:6a2d96c2a520 | 2 | * copyright (c) 2017-2018, James Flynn |
JMF | 0:6a2d96c2a520 | 3 | * SPDX-License-Identifier: Apache-2.0 |
JMF | 0:6a2d96c2a520 | 4 | */ |
JMF | 0:6a2d96c2a520 | 5 | |
JMF | 0:6a2d96c2a520 | 6 | /* |
JMF | 0:6a2d96c2a520 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
JMF | 0:6a2d96c2a520 | 8 | * you may not use this file except in compliance with the License. |
JMF | 0:6a2d96c2a520 | 9 | * You may obtain a copy of the License at |
JMF | 0:6a2d96c2a520 | 10 | * |
JMF | 0:6a2d96c2a520 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
JMF | 0:6a2d96c2a520 | 12 | * |
JMF | 0:6a2d96c2a520 | 13 | * Unless required by applicable law or agreed to in writing, software |
JMF | 0:6a2d96c2a520 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
JMF | 0:6a2d96c2a520 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JMF | 0:6a2d96c2a520 | 16 | * |
JMF | 0:6a2d96c2a520 | 17 | * See the License for the specific language governing permissions and |
JMF | 0:6a2d96c2a520 | 18 | * limitations under the License. |
JMF | 0:6a2d96c2a520 | 19 | */ |
JMF | 0:6a2d96c2a520 | 20 | |
JMF | 0:6a2d96c2a520 | 21 | /** |
JMF | 0:6a2d96c2a520 | 22 | * @file WNC14A2AInterface.h |
JMF | 0:6a2d96c2a520 | 23 | * @brief Implements a standard NetworkInterface class for use with WNC M14A2A |
JMF | 0:6a2d96c2a520 | 24 | * data module. |
JMF | 0:6a2d96c2a520 | 25 | * |
JMF | 0:6a2d96c2a520 | 26 | * @author James Flynn |
JMF | 0:6a2d96c2a520 | 27 | * |
JMF | 0:6a2d96c2a520 | 28 | * @date 1-Feb-2018 |
JMF | 0:6a2d96c2a520 | 29 | * |
JMF | 0:6a2d96c2a520 | 30 | */ |
JMF | 0:6a2d96c2a520 | 31 | |
JMF | 0:6a2d96c2a520 | 32 | #ifndef WNC14A2A_INTERFACE_H |
JMF | 0:6a2d96c2a520 | 33 | #define WNC14A2A_INTERFACE_H |
JMF | 0:6a2d96c2a520 | 34 | |
JMF | 0:6a2d96c2a520 | 35 | #include <stdint.h> |
JMF | 0:6a2d96c2a520 | 36 | |
JMF | 0:6a2d96c2a520 | 37 | #include "mbed.h" |
JMF | 0:6a2d96c2a520 | 38 | #include "Callback.h" |
JMF | 0:6a2d96c2a520 | 39 | #include "WNCDebug.h" |
JMF | 0:6a2d96c2a520 | 40 | #include "WncControllerK64F/WncControllerK64F.h" |
JMF | 0:6a2d96c2a520 | 41 | |
JMF | 0:6a2d96c2a520 | 42 | #define WNC14A2A_SOCKET_COUNT 5 |
JMF | 0:6a2d96c2a520 | 43 | |
JMF | 0:6a2d96c2a520 | 44 | typedef struct smsmsg_t { |
JMF | 0:6a2d96c2a520 | 45 | string number; |
JMF | 0:6a2d96c2a520 | 46 | string date; |
JMF | 0:6a2d96c2a520 | 47 | string time; |
JMF | 0:6a2d96c2a520 | 48 | string msg; |
JMF | 0:6a2d96c2a520 | 49 | } IOTSMS; |
JMF | 0:6a2d96c2a520 | 50 | |
JMF | 0:6a2d96c2a520 | 51 | typedef struct socket_t { |
JMF | 0:6a2d96c2a520 | 52 | int socket; //index of this socket |
JMF | 0:6a2d96c2a520 | 53 | string url; |
JMF | 0:6a2d96c2a520 | 54 | SocketAddress addr; //hold info for this socket |
JMF | 0:6a2d96c2a520 | 55 | bool opened; //has the socket been opened |
JMF | 0:6a2d96c2a520 | 56 | bool _wnc_opened; //has the socket been opened |
JMF | 0:6a2d96c2a520 | 57 | int proto; //this is a TCP or UDP socket |
JMF | 0:6a2d96c2a520 | 58 | void (*_callback)(void*); //callback used with attach |
JMF | 0:6a2d96c2a520 | 59 | void *_cb_data; //callback data to be returned |
JMF | 0:6a2d96c2a520 | 60 | } WNCSOCKET; |
JMF | 0:6a2d96c2a520 | 61 | |
JMF | 0:6a2d96c2a520 | 62 | #define WNC_DEBUG 0 //1=enable the WNC startup debug output |
JMF | 0:6a2d96c2a520 | 63 | //0=disable the WNC startup debug output |
JMF | 0:6a2d96c2a520 | 64 | #define STOP_ON_FE 1 //1=hang forever if a fatal error occurs |
JMF | 0:6a2d96c2a520 | 65 | //0=simply return failed response for all socket calls |
JMF | 0:6a2d96c2a520 | 66 | #define DISPLAY_FE 1 //1 to display the fatal error when it occurs |
JMF | 0:6a2d96c2a520 | 67 | //0 to NOT display the fatal error |
JMF | 0:6a2d96c2a520 | 68 | #define RESETON_FE 0 //1 to cause the MCU to reset on fatal error |
JMF | 0:6a2d96c2a520 | 69 | //0 to NOT reset the MCU |
JMF | 0:6a2d96c2a520 | 70 | |
JMF | 0:6a2d96c2a520 | 71 | #define APN_DEFAULT "m2m.com.attz" |
JMF | 0:6a2d96c2a520 | 72 | |
JMF | 0:6a2d96c2a520 | 73 | /** Error Handling macros & data |
JMF | 0:6a2d96c2a520 | 74 | * @brief The macros CHK_WNCFE is used to check if a fatal error has occured. If it has |
JMF | 0:6a2d96c2a520 | 75 | * then execute the action specified: fail, void, null, resume |
JMF | 0:6a2d96c2a520 | 76 | * |
JMF | 0:6a2d96c2a520 | 77 | * CHK_WNCFE( condition-to-check, fail|void|null|resume ) |
JMF | 0:6a2d96c2a520 | 78 | * |
JMF | 0:6a2d96c2a520 | 79 | * 'fail' if you want to FATAL_WNC_ERROR will be called. |
JMF | 0:6a2d96c2a520 | 80 | * 'void' if you want to execute a void return |
JMF | 0:6a2d96c2a520 | 81 | * 'null' if you want to execute a null return |
JMF | 0:6a2d96c2a520 | 82 | * 'resume' if you simply want to resume program execution |
JMF | 0:6a2d96c2a520 | 83 | * |
JMF | 0:6a2d96c2a520 | 84 | * There are several settings that control how FATAL_WNC_ERROR behaves: |
JMF | 0:6a2d96c2a520 | 85 | * 1) RESETON_FE determines if the system will reset or hang. |
JMF | 0:6a2d96c2a520 | 86 | * 2) DISPLAY_FE determine if an error message is generated or not |
JMF | 0:6a2d96c2a520 | 87 | * |
JMF | 0:6a2d96c2a520 | 88 | * The DISPLAY_FE setting determines if a failure message is displayed. |
JMF | 0:6a2d96c2a520 | 89 | * If set to 1, user sees this messageo: |
JMF | 0:6a2d96c2a520 | 90 | * |
JMF | 0:6a2d96c2a520 | 91 | * WNC FAILED @ source-file-name:source-file-line-number |
JMF | 0:6a2d96c2a520 | 92 | * |
JMF | 0:6a2d96c2a520 | 93 | * if not set, nothing is displayed. |
JMF | 0:6a2d96c2a520 | 94 | */ |
JMF | 0:6a2d96c2a520 | 95 | |
JMF | 0:6a2d96c2a520 | 96 | #define FATAL_FLAG WncController::WNC_NO_RESPONSE |
JMF | 0:6a2d96c2a520 | 97 | #define WNC_GOOD WncController::WNC_ON |
JMF | 0:6a2d96c2a520 | 98 | |
JMF | 0:6a2d96c2a520 | 99 | #define RETfail return -1 |
JMF | 0:6a2d96c2a520 | 100 | #define RETvoid return |
JMF | 0:6a2d96c2a520 | 101 | #define RETnull return NULL |
JMF | 0:6a2d96c2a520 | 102 | #define RETresume |
JMF | 0:6a2d96c2a520 | 103 | |
JMF | 0:6a2d96c2a520 | 104 | #define DORET(x) RET##x |
JMF | 0:6a2d96c2a520 | 105 | |
JMF | 0:6a2d96c2a520 | 106 | #define TOSTR(x) #x |
JMF | 0:6a2d96c2a520 | 107 | #define INTSTR(x) TOSTR(x) |
JMF | 0:6a2d96c2a520 | 108 | #define FATAL_STR (char*)(__FILE__ ":" INTSTR(__LINE__)) |
JMF | 0:6a2d96c2a520 | 109 | |
JMF | 0:6a2d96c2a520 | 110 | #if RESETON_FE == 1 //reset on fatal error |
JMF | 0:6a2d96c2a520 | 111 | #define MCURESET ((*((volatile unsigned long *)0xE000ED0CU))=(unsigned long)((0x5fa<<16) | 0x04L)) |
JMF | 0:6a2d96c2a520 | 112 | #define RSTMSG "RESET MCU! " |
JMF | 0:6a2d96c2a520 | 113 | #else |
JMF | 0:6a2d96c2a520 | 114 | #define MCURESET |
JMF | 0:6a2d96c2a520 | 115 | #define RSTMSG "" |
JMF | 0:6a2d96c2a520 | 116 | #endif |
JMF | 0:6a2d96c2a520 | 117 | |
JMF | 0:6a2d96c2a520 | 118 | #if DISPLAY_FE == 1 //display fatal error message |
JMF | 0:6a2d96c2a520 | 119 | #define PFE {if(_debugUart)_debugUart->printf((char*)RSTMSG "\r\n>>WNC FAILED @ %s\r\n", FATAL_STR);} |
JMF | 0:6a2d96c2a520 | 120 | #else |
JMF | 0:6a2d96c2a520 | 121 | #define PFE |
JMF | 0:6a2d96c2a520 | 122 | #endif |
JMF | 0:6a2d96c2a520 | 123 | |
JMF | 0:6a2d96c2a520 | 124 | #if STOP_ON_FE == 1 //halt cpu on fatal error |
JMF | 0:6a2d96c2a520 | 125 | #define FATAL_WNC_ERROR(v) {_fatal_err_loc=FATAL_STR;PFE;MCURESET;while(1);} |
JMF | 0:6a2d96c2a520 | 126 | #else |
JMF | 0:6a2d96c2a520 | 127 | #define FATAL_WNC_ERROR(v) {_fatal_err_loc=FATAL_STR;PFE;DORET(v);} |
JMF | 0:6a2d96c2a520 | 128 | #endif |
JMF | 0:6a2d96c2a520 | 129 | |
JMF | 0:6a2d96c2a520 | 130 | #define CHK_WNCFE(x,y) if( x ){FATAL_WNC_ERROR(y);} |
JMF | 0:6a2d96c2a520 | 131 | |
JMF | 0:6a2d96c2a520 | 132 | #define MAX_SMS_MSGS 3 |
JMF | 0:6a2d96c2a520 | 133 | |
JMF | 0:6a2d96c2a520 | 134 | using namespace WncController_fk; |
JMF | 0:6a2d96c2a520 | 135 | |
JMF | 0:6a2d96c2a520 | 136 | /** WNC14A2AInterface class |
JMF | 0:6a2d96c2a520 | 137 | * Implementation of the NetworkInterface for WNC14A2A |
JMF | 0:6a2d96c2a520 | 138 | */ |
JMF | 0:6a2d96c2a520 | 139 | class WNC14A2AInterface : public NetworkStack, public CellularInterface |
JMF | 0:6a2d96c2a520 | 140 | { |
JMF | 0:6a2d96c2a520 | 141 | public: |
JMF | 0:6a2d96c2a520 | 142 | /** WNC14A2AInterface Constructor. |
JMF | 0:6a2d96c2a520 | 143 | * @param optionally include a pointer to WNCDEBUG object for |
JMF | 0:6a2d96c2a520 | 144 | * debug information to be displayed. |
JMF | 0:6a2d96c2a520 | 145 | */ |
JMF | 0:6a2d96c2a520 | 146 | WNC14A2AInterface(WNCDebug *_dbgUart = NULL); |
JMF | 0:6a2d96c2a520 | 147 | virtual ~WNC14A2AInterface(); |
JMF | 0:6a2d96c2a520 | 148 | |
JMF | 0:6a2d96c2a520 | 149 | /** Set the cellular network credentials |
JMF | 0:6a2d96c2a520 | 150 | * |
JMF | 0:6a2d96c2a520 | 151 | * @param apn Optional, APN of network |
JMF | 0:6a2d96c2a520 | 152 | * @param user Optional, username --not used-- |
JMF | 0:6a2d96c2a520 | 153 | * @param pass Optional, password --not used-- |
JMF | 0:6a2d96c2a520 | 154 | * @return nsapi_error_t |
JMF | 0:6a2d96c2a520 | 155 | */ |
JMF | 0:6a2d96c2a520 | 156 | virtual nsapi_error_t set_credentials(const char *apn = 0, |
JMF | 0:6a2d96c2a520 | 157 | const char *username = 0, const char *password = 0); |
JMF | 0:6a2d96c2a520 | 158 | |
JMF | 0:6a2d96c2a520 | 159 | /** Connect to the network |
JMF | 0:6a2d96c2a520 | 160 | * |
JMF | 0:6a2d96c2a520 | 161 | * @param apn Optional, APN of network |
JMF | 0:6a2d96c2a520 | 162 | * @param user Optional, username --not used-- |
JMF | 0:6a2d96c2a520 | 163 | * @param pass Optional, password --not used-- |
JMF | 0:6a2d96c2a520 | 164 | * @return nsapi_error_t |
JMF | 0:6a2d96c2a520 | 165 | */ |
JMF | 0:6a2d96c2a520 | 166 | virtual nsapi_error_t connect(const char *apn, |
JMF | 0:6a2d96c2a520 | 167 | const char *username = 0, const char *password = 0); |
JMF | 0:6a2d96c2a520 | 168 | |
JMF | 0:6a2d96c2a520 | 169 | /** Connect to the network (no parameters) |
JMF | 0:6a2d96c2a520 | 170 | * |
JMF | 0:6a2d96c2a520 | 171 | * @return nsapi_error_t |
JMF | 0:6a2d96c2a520 | 172 | */ |
JMF | 0:6a2d96c2a520 | 173 | virtual nsapi_error_t connect(); |
JMF | 0:6a2d96c2a520 | 174 | |
JMF | 0:6a2d96c2a520 | 175 | /** disconnect from the network |
JMF | 0:6a2d96c2a520 | 176 | * |
JMF | 0:6a2d96c2a520 | 177 | * provided for completness, but function does nothing becase |
JMF | 0:6a2d96c2a520 | 178 | * WNC part can not disconnect from network once connected. |
JMF | 0:6a2d96c2a520 | 179 | * |
JMF | 0:6a2d96c2a520 | 180 | * @return nsapi_error_t |
JMF | 0:6a2d96c2a520 | 181 | */ |
JMF | 0:6a2d96c2a520 | 182 | virtual nsapi_error_t disconnect(); |
JMF | 0:6a2d96c2a520 | 183 | |
JMF | 0:6a2d96c2a520 | 184 | /** Get the IP address of WNC device. From NetworkStack Class |
JMF | 0:6a2d96c2a520 | 185 | * |
JMF | 0:6a2d96c2a520 | 186 | * @return IP address string or null |
JMF | 0:6a2d96c2a520 | 187 | */ |
JMF | 0:6a2d96c2a520 | 188 | virtual const char *get_ip_address(); |
JMF | 0:6a2d96c2a520 | 189 | |
JMF | 0:6a2d96c2a520 | 190 | /** Get the network assigned IP address. |
JMF | 0:6a2d96c2a520 | 191 | * |
JMF | 0:6a2d96c2a520 | 192 | * @return IP address or null |
JMF | 0:6a2d96c2a520 | 193 | */ |
JMF | 0:6a2d96c2a520 | 194 | const char *get_my_ip_address(); |
JMF | 0:6a2d96c2a520 | 195 | |
JMF | 0:6a2d96c2a520 | 196 | /** Get the MAC address of the WNC device. |
JMF | 0:6a2d96c2a520 | 197 | * |
JMF | 0:6a2d96c2a520 | 198 | * @return MAC address of the interface |
JMF | 0:6a2d96c2a520 | 199 | */ |
JMF | 0:6a2d96c2a520 | 200 | virtual const char *get_mac_address(); |
JMF | 0:6a2d96c2a520 | 201 | |
JMF | 0:6a2d96c2a520 | 202 | /** Attach a callback function for when a SMS is recevied |
JMF | 0:6a2d96c2a520 | 203 | * |
JMF | 0:6a2d96c2a520 | 204 | * @param function pointer to call |
JMF | 0:6a2d96c2a520 | 205 | */ |
JMF | 0:6a2d96c2a520 | 206 | void sms_attach(void (*callback)(IOTSMS *)); |
JMF | 0:6a2d96c2a520 | 207 | |
JMF | 0:6a2d96c2a520 | 208 | /** Set the level of Debug output |
JMF | 0:6a2d96c2a520 | 209 | * |
JMF | 0:6a2d96c2a520 | 210 | * @param bit field |
JMF | 0:6a2d96c2a520 | 211 | * basic AT command info= 0x01 |
JMF | 0:6a2d96c2a520 | 212 | * more AT command info = 0x02 |
JMF | 0:6a2d96c2a520 | 213 | * mbed driver info = 0x04 |
JMF | 0:6a2d96c2a520 | 214 | * dump buffers = 0x08 |
JMF | 0:6a2d96c2a520 | 215 | * all debug = 0x0f |
JMF | 0:6a2d96c2a520 | 216 | */ |
JMF | 0:6a2d96c2a520 | 217 | void doDebug(int v); |
JMF | 0:6a2d96c2a520 | 218 | |
JMF | 0:6a2d96c2a520 | 219 | /** Query registered state of WNC |
JMF | 0:6a2d96c2a520 | 220 | * |
JMF | 0:6a2d96c2a520 | 221 | * @return true if registerd, false if not |
JMF | 0:6a2d96c2a520 | 222 | */ |
JMF | 0:6a2d96c2a520 | 223 | bool registered(); |
JMF | 0:6a2d96c2a520 | 224 | |
JMF | 0:6a2d96c2a520 | 225 | /** Start the SMS monitoring service |
JMF | 0:6a2d96c2a520 | 226 | */ |
JMF | 0:6a2d96c2a520 | 227 | void sms_start(void); |
JMF | 0:6a2d96c2a520 | 228 | |
JMF | 0:6a2d96c2a520 | 229 | /** start listening for incomming SMS messages |
JMF | 0:6a2d96c2a520 | 230 | * |
JMF | 0:6a2d96c2a520 | 231 | * @param time in msec to check |
JMF | 0:6a2d96c2a520 | 232 | */ |
JMF | 0:6a2d96c2a520 | 233 | void sms_listen(uint16_t=1000); // Configure device to listen for text messages |
JMF | 0:6a2d96c2a520 | 234 | |
JMF | 0:6a2d96c2a520 | 235 | /** retrieve a SMS message |
JMF | 0:6a2d96c2a520 | 236 | * |
JMF | 0:6a2d96c2a520 | 237 | * @param pointer to an array of IOTSMS messages |
JMF | 0:6a2d96c2a520 | 238 | */ |
JMF | 0:6a2d96c2a520 | 239 | int getSMS(IOTSMS **msg); |
JMF | 0:6a2d96c2a520 | 240 | |
JMF | 0:6a2d96c2a520 | 241 | /** send a SMS message |
JMF | 0:6a2d96c2a520 | 242 | * |
JMF | 0:6a2d96c2a520 | 243 | * @param a string containing number to send message to |
JMF | 0:6a2d96c2a520 | 244 | * @param a string containing message to send |
JMF | 0:6a2d96c2a520 | 245 | * @return true on success, 0 on failure |
JMF | 0:6a2d96c2a520 | 246 | */ |
JMF | 0:6a2d96c2a520 | 247 | int sendIOTSms(const string&, const string&); |
JMF | 0:6a2d96c2a520 | 248 | |
JMF | 0:6a2d96c2a520 | 249 | /** return this devices SMS number |
JMF | 0:6a2d96c2a520 | 250 | * |
JMF | 0:6a2d96c2a520 | 251 | * @brief The IOTSMS number used, isn't phone number, it is device ICCID. |
JMF | 0:6a2d96c2a520 | 252 | * |
JMF | 0:6a2d96c2a520 | 253 | * @return this devices IOTSMS number |
JMF | 0:6a2d96c2a520 | 254 | */ |
JMF | 0:6a2d96c2a520 | 255 | char* getSMSnbr(); |
JMF | 0:6a2d96c2a520 | 256 | |
JMF | 0:6a2d96c2a520 | 257 | |
JMF | 0:6a2d96c2a520 | 258 | protected: |
JMF | 0:6a2d96c2a520 | 259 | |
JMF | 0:6a2d96c2a520 | 260 | /** Get Host IP by name. |
JMF | 0:6a2d96c2a520 | 261 | * |
JMF | 0:6a2d96c2a520 | 262 | * @return nsapi_error_t |
JMF | 0:6a2d96c2a520 | 263 | */ |
JMF | 0:6a2d96c2a520 | 264 | virtual nsapi_error_t gethostbyname(const char* name, SocketAddress *address, nsapi_version_t version); |
JMF | 0:6a2d96c2a520 | 265 | |
JMF | 0:6a2d96c2a520 | 266 | |
JMF | 0:6a2d96c2a520 | 267 | /** return a pointer to the NetworkStack object |
JMF | 0:6a2d96c2a520 | 268 | * |
JMF | 0:6a2d96c2a520 | 269 | * @return The underlying NetworkStack object |
JMF | 0:6a2d96c2a520 | 270 | */ |
JMF | 0:6a2d96c2a520 | 271 | virtual NetworkStack *get_stack(); |
JMF | 0:6a2d96c2a520 | 272 | |
JMF | 0:6a2d96c2a520 | 273 | /** Open a socket. |
JMF | 0:6a2d96c2a520 | 274 | * |
JMF | 0:6a2d96c2a520 | 275 | * @param handle Handle in which to store new socket |
JMF | 0:6a2d96c2a520 | 276 | * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP |
JMF | 0:6a2d96c2a520 | 277 | * @return 0 on success, negative on failure |
JMF | 0:6a2d96c2a520 | 278 | */ |
JMF | 0:6a2d96c2a520 | 279 | virtual int socket_open(void **handle, nsapi_protocol_t proto); |
JMF | 0:6a2d96c2a520 | 280 | |
JMF | 0:6a2d96c2a520 | 281 | /** Close the socket. |
JMF | 0:6a2d96c2a520 | 282 | * |
JMF | 0:6a2d96c2a520 | 283 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 284 | * @return 0 on success, negative on failure |
JMF | 0:6a2d96c2a520 | 285 | */ |
JMF | 0:6a2d96c2a520 | 286 | virtual int socket_close(void *handle); |
JMF | 0:6a2d96c2a520 | 287 | |
JMF | 0:6a2d96c2a520 | 288 | /** Bind a server socket to a specific port. |
JMF | 0:6a2d96c2a520 | 289 | * |
JMF | 0:6a2d96c2a520 | 290 | * @brief NOT SUPPORTED |
JMF | 0:6a2d96c2a520 | 291 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 292 | * @param address address to listen for incoming connections on |
JMF | 0:6a2d96c2a520 | 293 | * @return NSAPI_ERROR_UNSUPPORTED; |
JMF | 0:6a2d96c2a520 | 294 | */ |
JMF | 0:6a2d96c2a520 | 295 | virtual int socket_bind(void *handle, const SocketAddress &address); |
JMF | 0:6a2d96c2a520 | 296 | |
JMF | 0:6a2d96c2a520 | 297 | /** Start listening for incoming connections. |
JMF | 0:6a2d96c2a520 | 298 | * |
JMF | 0:6a2d96c2a520 | 299 | * @brief NOT SUPPORTED |
JMF | 0:6a2d96c2a520 | 300 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 301 | * @param backlog Number of pending connections that can be queued up at any |
JMF | 0:6a2d96c2a520 | 302 | * one time [Default: 1] |
JMF | 0:6a2d96c2a520 | 303 | * @return NSAPI_ERROR_UNSUPPORTED; |
JMF | 0:6a2d96c2a520 | 304 | */ |
JMF | 0:6a2d96c2a520 | 305 | virtual int socket_listen(void *handle, int backlog); |
JMF | 0:6a2d96c2a520 | 306 | |
JMF | 0:6a2d96c2a520 | 307 | /** Accept a new connection. |
JMF | 0:6a2d96c2a520 | 308 | * |
JMF | 0:6a2d96c2a520 | 309 | * @brief NOT SUPPORTED |
JMF | 0:6a2d96c2a520 | 310 | * @return NSAPI_ERROR_UNSUPPORTED; |
JMF | 0:6a2d96c2a520 | 311 | */ |
JMF | 0:6a2d96c2a520 | 312 | virtual int socket_accept(nsapi_socket_t server, |
JMF | 0:6a2d96c2a520 | 313 | nsapi_socket_t *handle, SocketAddress *address=0); |
JMF | 0:6a2d96c2a520 | 314 | |
JMF | 0:6a2d96c2a520 | 315 | /** Connects this socket to the server. |
JMF | 0:6a2d96c2a520 | 316 | * |
JMF | 0:6a2d96c2a520 | 317 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 318 | * @param address SocketAddress |
JMF | 0:6a2d96c2a520 | 319 | * @return 0 on success, negative on failure |
JMF | 0:6a2d96c2a520 | 320 | */ |
JMF | 0:6a2d96c2a520 | 321 | virtual int socket_connect(void *handle, const SocketAddress &address); |
JMF | 0:6a2d96c2a520 | 322 | |
JMF | 0:6a2d96c2a520 | 323 | /** Send data to the remote host. |
JMF | 0:6a2d96c2a520 | 324 | * |
JMF | 0:6a2d96c2a520 | 325 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 326 | * @param data buffer to send |
JMF | 0:6a2d96c2a520 | 327 | * @param size length of buffer |
JMF | 0:6a2d96c2a520 | 328 | * @return Number of bytes written or negative on failure |
JMF | 0:6a2d96c2a520 | 329 | * |
JMF | 0:6a2d96c2a520 | 330 | * @note This call is blocking. |
JMF | 0:6a2d96c2a520 | 331 | */ |
JMF | 0:6a2d96c2a520 | 332 | virtual int socket_send(void *handle, const void *data, unsigned size); |
JMF | 0:6a2d96c2a520 | 333 | |
JMF | 0:6a2d96c2a520 | 334 | /** Receive data from the remote host. |
JMF | 0:6a2d96c2a520 | 335 | * |
JMF | 0:6a2d96c2a520 | 336 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 337 | * @param data buffer to store the recived data |
JMF | 0:6a2d96c2a520 | 338 | * @param size bytes to receive |
JMF | 0:6a2d96c2a520 | 339 | * @return received bytes received, negative on failure |
JMF | 0:6a2d96c2a520 | 340 | * |
JMF | 0:6a2d96c2a520 | 341 | * @note This call is not-blocking |
JMF | 0:6a2d96c2a520 | 342 | */ |
JMF | 0:6a2d96c2a520 | 343 | virtual int socket_recv(void *handle, void *data, unsigned size); |
JMF | 0:6a2d96c2a520 | 344 | |
JMF | 0:6a2d96c2a520 | 345 | /** Send a packet to a remote endpoint. |
JMF | 0:6a2d96c2a520 | 346 | * |
JMF | 0:6a2d96c2a520 | 347 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 348 | * @param address SocketAddress |
JMF | 0:6a2d96c2a520 | 349 | * @param data data to send |
JMF | 0:6a2d96c2a520 | 350 | * @param size number of bytes to send |
JMF | 0:6a2d96c2a520 | 351 | * @return the number of bytes sent or negative on failure |
JMF | 0:6a2d96c2a520 | 352 | * |
JMF | 0:6a2d96c2a520 | 353 | * @note This call is blocking. |
JMF | 0:6a2d96c2a520 | 354 | */ |
JMF | 0:6a2d96c2a520 | 355 | virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); |
JMF | 0:6a2d96c2a520 | 356 | |
JMF | 0:6a2d96c2a520 | 357 | /** Receive packet remote endpoint |
JMF | 0:6a2d96c2a520 | 358 | * |
JMF | 0:6a2d96c2a520 | 359 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 360 | * @param address SocketAddress |
JMF | 0:6a2d96c2a520 | 361 | * @param buffer buffer to store data to |
JMF | 0:6a2d96c2a520 | 362 | * @param size number of bytes to receive |
JMF | 0:6a2d96c2a520 | 363 | * @return the number bytes received or negative on failure |
JMF | 0:6a2d96c2a520 | 364 | * |
JMF | 0:6a2d96c2a520 | 365 | * @note This call is not-blocking. |
JMF | 0:6a2d96c2a520 | 366 | */ |
JMF | 0:6a2d96c2a520 | 367 | virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); |
JMF | 0:6a2d96c2a520 | 368 | |
JMF | 0:6a2d96c2a520 | 369 | /** Register a callback on state change of the socket |
JMF | 0:6a2d96c2a520 | 370 | * |
JMF | 0:6a2d96c2a520 | 371 | * @param handle Socket handle |
JMF | 0:6a2d96c2a520 | 372 | * @param callback Function to call on state change |
JMF | 0:6a2d96c2a520 | 373 | * @param data Argument to pass to callback |
JMF | 0:6a2d96c2a520 | 374 | * |
JMF | 0:6a2d96c2a520 | 375 | * @note Callback may be called in an interrupt context. |
JMF | 0:6a2d96c2a520 | 376 | */ |
JMF | 0:6a2d96c2a520 | 377 | virtual void socket_attach(void *handle, void (*callback)(void *), void *data); |
JMF | 0:6a2d96c2a520 | 378 | |
JMF | 0:6a2d96c2a520 | 379 | /** get the status of internal errors |
JMF | 0:6a2d96c2a520 | 380 | * |
JMF | 0:6a2d96c2a520 | 381 | * @brief Called after any WNC14A2A operation to determine error specifics |
JMF | 0:6a2d96c2a520 | 382 | * @param none. |
JMF | 0:6a2d96c2a520 | 383 | */ |
JMF | 0:6a2d96c2a520 | 384 | uint16_t wnc14a2a_chk_error(void) { return _errors; } |
JMF | 0:6a2d96c2a520 | 385 | |
JMF | 0:6a2d96c2a520 | 386 | |
JMF | 0:6a2d96c2a520 | 387 | private: |
JMF | 0:6a2d96c2a520 | 388 | //! WncController Class for managing the 14A2a hardware |
JMF | 0:6a2d96c2a520 | 389 | friend class WncControllerK64F; |
JMF | 0:6a2d96c2a520 | 390 | |
JMF | 0:6a2d96c2a520 | 391 | bool m_wncpoweredup; //track if WNC has been power-up |
JMF | 0:6a2d96c2a520 | 392 | unsigned m_debug; |
JMF | 0:6a2d96c2a520 | 393 | |
JMF | 0:6a2d96c2a520 | 394 | WncIpStats myNetStats; //maintaint the network statistics |
JMF | 0:6a2d96c2a520 | 395 | WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance |
JMF | 0:6a2d96c2a520 | 396 | |
JMF | 0:6a2d96c2a520 | 397 | int m_active_socket; // a 'pseudo' global to track the active socket |
JMF | 0:6a2d96c2a520 | 398 | WNCDebug *_debugUart; // Serial object for parser to communicate with radio |
JMF | 0:6a2d96c2a520 | 399 | char *_fatal_err_loc; // holds string containing location of fatal error |
JMF | 0:6a2d96c2a520 | 400 | nsapi_error_t _errors; |
JMF | 0:6a2d96c2a520 | 401 | |
JMF | 0:6a2d96c2a520 | 402 | bool m_smsmoning; // Track if the SMS monitoring thread is running |
JMF | 0:6a2d96c2a520 | 403 | EventQueue sms_queue; // Queue used to schedule for SMS checks |
JMF | 0:6a2d96c2a520 | 404 | EventQueue isr_queue; // Queue used to schedule for receiving data |
JMF | 0:6a2d96c2a520 | 405 | void (*_sms_cb)(IOTSMS *); // Callback when text message is received. User must define this as |
JMF | 0:6a2d96c2a520 | 406 | // a static function because I'm not handling an object offset |
JMF | 0:6a2d96c2a520 | 407 | IOTSMS m_MsgText, m_MsgText_array[MAX_SMS_MSGS]; // Used to pass SMS message to the user |
JMF | 0:6a2d96c2a520 | 408 | struct WncController::WncSmsList m_smsmsgs; //use the WncSmsList structure to hold messages |
JMF | 0:6a2d96c2a520 | 409 | |
JMF | 0:6a2d96c2a520 | 410 | void handle_sms_event(); // SMS tx/rx handler |
JMF | 0:6a2d96c2a520 | 411 | void wnc_isr_event(); // Simulated ISR |
JMF | 0:6a2d96c2a520 | 412 | int rx_event(); // receive data handler |
JMF | 0:6a2d96c2a520 | 413 | int tx_event(); // tx data handler |
JMF | 0:6a2d96c2a520 | 414 | |
JMF | 0:6a2d96c2a520 | 415 | char _mac_address[NSAPI_MAC_SIZE]; // local Mac |
JMF | 0:6a2d96c2a520 | 416 | void _dbOut(const char *format, ...); |
JMF | 0:6a2d96c2a520 | 417 | void _dbDump_arry( const uint8_t* data, unsigned int size ); |
JMF | 0:6a2d96c2a520 | 418 | |
JMF | 0:6a2d96c2a520 | 419 | // Receive Interrupt simulation to enabled non-blocking operation |
JMF | 0:6a2d96c2a520 | 420 | uint8_t *m_recv_dptr; |
JMF | 0:6a2d96c2a520 | 421 | int m_recv_wnc_state; |
JMF | 0:6a2d96c2a520 | 422 | int m_recv_events; |
JMF | 0:6a2d96c2a520 | 423 | int m_recv_socket; |
JMF | 0:6a2d96c2a520 | 424 | int m_recv_timer; |
JMF | 0:6a2d96c2a520 | 425 | unsigned m_recv_orig_size; |
JMF | 0:6a2d96c2a520 | 426 | uint32_t m_recv_req_size, m_recv_total_cnt; |
JMF | 0:6a2d96c2a520 | 427 | uint32_t m_recv_return_cnt; |
JMF | 0:6a2d96c2a520 | 428 | void (*m_recv_callback)(void*); |
JMF | 0:6a2d96c2a520 | 429 | void *m_recv_cb_data; |
JMF | 0:6a2d96c2a520 | 430 | |
JMF | 0:6a2d96c2a520 | 431 | // Transmit Interrupt simulation to enabled non-blocking operation |
JMF | 0:6a2d96c2a520 | 432 | uint8_t *m_tx_dptr; |
JMF | 0:6a2d96c2a520 | 433 | int m_tx_wnc_state; |
JMF | 0:6a2d96c2a520 | 434 | int m_tx_socket; |
JMF | 0:6a2d96c2a520 | 435 | unsigned m_tx_orig_size; |
JMF | 0:6a2d96c2a520 | 436 | uint32_t m_tx_req_size, m_tx_total_sent; |
JMF | 0:6a2d96c2a520 | 437 | void (*m_tx_callback)(void*); |
JMF | 0:6a2d96c2a520 | 438 | void *m_tx_cb_data; |
JMF | 0:6a2d96c2a520 | 439 | |
JMF | 0:6a2d96c2a520 | 440 | }; |
JMF | 0:6a2d96c2a520 | 441 | |
JMF | 0:6a2d96c2a520 | 442 | #endif |
JMF | 0:6a2d96c2a520 | 443 |