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