wifi test

Dependencies:   X_NUCLEO_IKS01A2 mbed-http

Committer:
JMF
Date:
Wed Sep 05 14:28:24 2018 +0000
Revision:
0:24d3eb812fd4
Initial commit

Who changed what in which revision?

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