Added support for the WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Easy Connect

Easily add all supported connectivity methods to your mbed OS project

This project is derived from https://developer.mbed.org/teams/sandbox/code/simple-mbed-client-example/file/dd6231df71bb/easy-connect.lib. It give user the ability to switch between connectivity methods and includes support for the WNC14A2A Data Module. The `NetworkInterface` API makes this easy, but you still need a mechanism for the user to select the connection method, The selection is made by modifying the `mbed_app.json` file and using `easy_connect()` from your application.

Specifying connectivity method

To add support for the WNC14A2A, add the following to your ``mbed_app.json`` file:

mbed_app.json

{
    "config": {
        "network-interface":{
            "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD,WNC14A2A",
            "value": "WNC14A2A"
        }
    },
}

After you choose `WNC14A2A` you'll also need to indicate if you want debug output or not by Enabling (true) or Disabling (false) WNC_DEBUG.

If WNC_DEBUG is enabled, there are 3 different levels of debug output (selected via bit settings). These debug levels are set using the following values:

ValueDescription
1Basic WNC driver debug output
2Comprehensive WNC driver debug output
4Network Layer debug output

You can have any combination of these three bit values for a total value of 0 – 7.

WNC Debug Settings

    "config": {
        "WNC_DEBUG": {
            "value": false
        },
        "WNC_DEBUG_SETTING": {
            "value": 4
        },
    }

Using Easy Connect from your application

Easy Connect has just one function which will either return a `NetworkInterface`-pointer or `NULL`:

Sample Code

#include "easy-connect.h"

int main(int, char**) {
    NetworkInterface* network = easy_connect(true); /* has 1 argument, enable_logging (pass in true to log to serial port) */
    if (!network) {
        printf("Connecting to the network failed... See serial output.\r\n");
        return 1;
    }
 
    // Rest of your program
}

Tested on

  • K64F with Ethernet.
  • AT&T Cellular IoT Starter Kit with WNC M14A2A Cellular Data Module

The WNCInterface class currently supports the following version(s):

  • MPSS: M14A2A_v11.50.164451 APSS: M14A2A_v11.53.164451

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
group-Avnet
Date:
Wed Apr 19 01:08:11 2017 +0000
Revision:
0:478cfd88041f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-Avnet 0:478cfd88041f 1 /* Copyright (c) 2015 ARM Limited
group-Avnet 0:478cfd88041f 2 *
group-Avnet 0:478cfd88041f 3 * Licensed under the Apache License, Version 2.0 (the "License");
group-Avnet 0:478cfd88041f 4 * you may not use this file except in compliance with the License.
group-Avnet 0:478cfd88041f 5 * You may obtain a copy of the License at
group-Avnet 0:478cfd88041f 6 *
group-Avnet 0:478cfd88041f 7 * http://www.apache.org/licenses/LICENSE-2.0
group-Avnet 0:478cfd88041f 8 *
group-Avnet 0:478cfd88041f 9 * Unless required by applicable law or agreed to in writing, software
group-Avnet 0:478cfd88041f 10 * distributed under the License is distributed on an "AS IS" BASIS,
group-Avnet 0:478cfd88041f 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-Avnet 0:478cfd88041f 12 * See the License for the specific language governing permissions and
group-Avnet 0:478cfd88041f 13 * limitations under the License.
group-Avnet 0:478cfd88041f 14 *
group-Avnet 0:478cfd88041f 15 * @section DESCRIPTION
group-Avnet 0:478cfd88041f 16 *
group-Avnet 0:478cfd88041f 17 * Parser for the AT command syntax
group-Avnet 0:478cfd88041f 18 *
group-Avnet 0:478cfd88041f 19 */
group-Avnet 0:478cfd88041f 20 #ifndef AT_PARSER_H
group-Avnet 0:478cfd88041f 21 #define AT_PARSER_H
group-Avnet 0:478cfd88041f 22
group-Avnet 0:478cfd88041f 23 #include "mbed.h"
group-Avnet 0:478cfd88041f 24 #include <cstdarg>
group-Avnet 0:478cfd88041f 25 #include <vector>
group-Avnet 0:478cfd88041f 26 #include "BufferedSerial.h"
group-Avnet 0:478cfd88041f 27 #include "Callback.h"
group-Avnet 0:478cfd88041f 28
group-Avnet 0:478cfd88041f 29
group-Avnet 0:478cfd88041f 30 /**
group-Avnet 0:478cfd88041f 31 * Parser class for parsing AT commands
group-Avnet 0:478cfd88041f 32 *
group-Avnet 0:478cfd88041f 33 * Here are some examples:
group-Avnet 0:478cfd88041f 34 * @code
group-Avnet 0:478cfd88041f 35 * ATParser at = ATParser(serial, "\r\n");
group-Avnet 0:478cfd88041f 36 * int value;
group-Avnet 0:478cfd88041f 37 * char buffer[100];
group-Avnet 0:478cfd88041f 38 *
group-Avnet 0:478cfd88041f 39 * at.send("AT") && at.recv("OK");
group-Avnet 0:478cfd88041f 40 * at.send("AT+CWMODE=%d", 3) && at.recv("OK");
group-Avnet 0:478cfd88041f 41 * at.send("AT+CWMODE?") && at.recv("+CWMODE:%d\r\nOK", &value);
group-Avnet 0:478cfd88041f 42 * at.recv("+IPD,%d:", &value);
group-Avnet 0:478cfd88041f 43 * at.read(buffer, value);
group-Avnet 0:478cfd88041f 44 * at.recv("OK");
group-Avnet 0:478cfd88041f 45 * @endcode
group-Avnet 0:478cfd88041f 46 */
group-Avnet 0:478cfd88041f 47 class ATParser
group-Avnet 0:478cfd88041f 48 {
group-Avnet 0:478cfd88041f 49 private:
group-Avnet 0:478cfd88041f 50 // Serial information
group-Avnet 0:478cfd88041f 51 BufferedSerial *_serial;
group-Avnet 0:478cfd88041f 52 int _buffer_size;
group-Avnet 0:478cfd88041f 53 char *_buffer;
group-Avnet 0:478cfd88041f 54 int _timeout;
group-Avnet 0:478cfd88041f 55
group-Avnet 0:478cfd88041f 56 // Parsing information
group-Avnet 0:478cfd88041f 57 const char *_delimiter;
group-Avnet 0:478cfd88041f 58 int _delim_size;
group-Avnet 0:478cfd88041f 59 bool dbg_on;
group-Avnet 0:478cfd88041f 60
group-Avnet 0:478cfd88041f 61 struct oob {
group-Avnet 0:478cfd88041f 62 unsigned len;
group-Avnet 0:478cfd88041f 63 const char *prefix;
group-Avnet 0:478cfd88041f 64 mbed::Callback<void()> cb;
group-Avnet 0:478cfd88041f 65 };
group-Avnet 0:478cfd88041f 66 std::vector<oob> _oobs;
group-Avnet 0:478cfd88041f 67
group-Avnet 0:478cfd88041f 68 public:
group-Avnet 0:478cfd88041f 69 /**
group-Avnet 0:478cfd88041f 70 * Constructor
group-Avnet 0:478cfd88041f 71 *
group-Avnet 0:478cfd88041f 72 * @param serial serial interface to use for AT commands
group-Avnet 0:478cfd88041f 73 * @param buffer_size size of internal buffer for transaction
group-Avnet 0:478cfd88041f 74 * @param timeout timeout of the connection
group-Avnet 0:478cfd88041f 75 * @param delimiter string of characters to use as line delimiters
group-Avnet 0:478cfd88041f 76 */
group-Avnet 0:478cfd88041f 77 ATParser(BufferedSerial &serial, const char *delimiter = "\r\n", int buffer_size = 256, int timeout = 8000, bool debug = false) :
group-Avnet 0:478cfd88041f 78 _serial(&serial),
group-Avnet 0:478cfd88041f 79 _buffer_size(buffer_size) {
group-Avnet 0:478cfd88041f 80 _buffer = new char[buffer_size];
group-Avnet 0:478cfd88041f 81 setTimeout(timeout);
group-Avnet 0:478cfd88041f 82 setDelimiter(delimiter);
group-Avnet 0:478cfd88041f 83 debugOn(debug);
group-Avnet 0:478cfd88041f 84 }
group-Avnet 0:478cfd88041f 85
group-Avnet 0:478cfd88041f 86 /**
group-Avnet 0:478cfd88041f 87 * Destructor
group-Avnet 0:478cfd88041f 88 */
group-Avnet 0:478cfd88041f 89 ~ATParser() {
group-Avnet 0:478cfd88041f 90 delete [] _buffer;
group-Avnet 0:478cfd88041f 91 }
group-Avnet 0:478cfd88041f 92
group-Avnet 0:478cfd88041f 93 /**
group-Avnet 0:478cfd88041f 94 * Allows timeout to be changed between commands
group-Avnet 0:478cfd88041f 95 *
group-Avnet 0:478cfd88041f 96 * @param timeout timeout of the connection
group-Avnet 0:478cfd88041f 97 */
group-Avnet 0:478cfd88041f 98 void setTimeout(int timeout) {
group-Avnet 0:478cfd88041f 99 _timeout = timeout;
group-Avnet 0:478cfd88041f 100 }
group-Avnet 0:478cfd88041f 101
group-Avnet 0:478cfd88041f 102 /**
group-Avnet 0:478cfd88041f 103 * Sets string of characters to use as line delimiters
group-Avnet 0:478cfd88041f 104 *
group-Avnet 0:478cfd88041f 105 * @param delimiter string of characters to use as line delimiters
group-Avnet 0:478cfd88041f 106 */
group-Avnet 0:478cfd88041f 107 void setDelimiter(const char *delimiter) {
group-Avnet 0:478cfd88041f 108 _delimiter = delimiter;
group-Avnet 0:478cfd88041f 109 _delim_size = strlen(delimiter);
group-Avnet 0:478cfd88041f 110 }
group-Avnet 0:478cfd88041f 111
group-Avnet 0:478cfd88041f 112 /**
group-Avnet 0:478cfd88041f 113 * Allows echo to be on or off
group-Avnet 0:478cfd88041f 114 *
group-Avnet 0:478cfd88041f 115 * @param echo 1 for echo and 0 turns it off
group-Avnet 0:478cfd88041f 116 */
group-Avnet 0:478cfd88041f 117 void debugOn(uint8_t on) {
group-Avnet 0:478cfd88041f 118 dbg_on = (on) ? 1 : 0;
group-Avnet 0:478cfd88041f 119 }
group-Avnet 0:478cfd88041f 120
group-Avnet 0:478cfd88041f 121 /**
group-Avnet 0:478cfd88041f 122 * Sends an AT command
group-Avnet 0:478cfd88041f 123 *
group-Avnet 0:478cfd88041f 124 * Sends a formatted command using printf style formatting
group-Avnet 0:478cfd88041f 125 * @see ::printf
group-Avnet 0:478cfd88041f 126 *
group-Avnet 0:478cfd88041f 127 * @param command printf-like format string of command to send which
group-Avnet 0:478cfd88041f 128 * is appended with the specified delimiter
group-Avnet 0:478cfd88041f 129 * @param ... all printf-like arguments to insert into command
group-Avnet 0:478cfd88041f 130 * @return true only if command is successfully sent
group-Avnet 0:478cfd88041f 131 */
group-Avnet 0:478cfd88041f 132 bool send(const char *command, ...);
group-Avnet 0:478cfd88041f 133 bool vsend(const char *command, va_list args);
group-Avnet 0:478cfd88041f 134
group-Avnet 0:478cfd88041f 135 /**
group-Avnet 0:478cfd88041f 136 * Recieve an AT response
group-Avnet 0:478cfd88041f 137 *
group-Avnet 0:478cfd88041f 138 * Recieves a formatted response using scanf style formatting
group-Avnet 0:478cfd88041f 139 * @see ::scanf
group-Avnet 0:478cfd88041f 140 *
group-Avnet 0:478cfd88041f 141 * Responses are parsed line at a time using the specified delimiter.
group-Avnet 0:478cfd88041f 142 * Any recieved data that does not match the response is ignored until
group-Avnet 0:478cfd88041f 143 * a timeout occurs.
group-Avnet 0:478cfd88041f 144 *
group-Avnet 0:478cfd88041f 145 * @param response scanf-like format string of response to expect
group-Avnet 0:478cfd88041f 146 * @param ... all scanf-like arguments to extract from response
group-Avnet 0:478cfd88041f 147 * @return true only if response is successfully matched
group-Avnet 0:478cfd88041f 148 */
group-Avnet 0:478cfd88041f 149 bool recv(const char *response, ...);
group-Avnet 0:478cfd88041f 150 bool vrecv(const char *response, va_list args);
group-Avnet 0:478cfd88041f 151
group-Avnet 0:478cfd88041f 152 /**
group-Avnet 0:478cfd88041f 153 * Write a single byte to the underlying stream
group-Avnet 0:478cfd88041f 154 *
group-Avnet 0:478cfd88041f 155 * @param c The byte to write
group-Avnet 0:478cfd88041f 156 * @return The byte that was written or -1 during a timeout
group-Avnet 0:478cfd88041f 157 */
group-Avnet 0:478cfd88041f 158 int putc(char c);
group-Avnet 0:478cfd88041f 159
group-Avnet 0:478cfd88041f 160 /**
group-Avnet 0:478cfd88041f 161 * Get a single byte from the underlying stream
group-Avnet 0:478cfd88041f 162 *
group-Avnet 0:478cfd88041f 163 * @return The byte that was read or -1 during a timeout
group-Avnet 0:478cfd88041f 164 */
group-Avnet 0:478cfd88041f 165 int getc();
group-Avnet 0:478cfd88041f 166
group-Avnet 0:478cfd88041f 167 /**
group-Avnet 0:478cfd88041f 168 * Write an array of bytes to the underlying stream
group-Avnet 0:478cfd88041f 169 *
group-Avnet 0:478cfd88041f 170 * @param data the array of bytes to write
group-Avnet 0:478cfd88041f 171 * @param size number of bytes to write
group-Avnet 0:478cfd88041f 172 * @return number of bytes written or -1 on failure
group-Avnet 0:478cfd88041f 173 */
group-Avnet 0:478cfd88041f 174 int write(const char *data, int size);
group-Avnet 0:478cfd88041f 175
group-Avnet 0:478cfd88041f 176 /**
group-Avnet 0:478cfd88041f 177 * Read an array of bytes from the underlying stream
group-Avnet 0:478cfd88041f 178 *
group-Avnet 0:478cfd88041f 179 * @param data the destination for the read bytes
group-Avnet 0:478cfd88041f 180 * @param size number of bytes to read
group-Avnet 0:478cfd88041f 181 * @return number of bytes read or -1 on failure
group-Avnet 0:478cfd88041f 182 */
group-Avnet 0:478cfd88041f 183 int read(char *data, int size);
group-Avnet 0:478cfd88041f 184
group-Avnet 0:478cfd88041f 185 /**
group-Avnet 0:478cfd88041f 186 * Direct printf to underlying stream
group-Avnet 0:478cfd88041f 187 * @see ::printf
group-Avnet 0:478cfd88041f 188 *
group-Avnet 0:478cfd88041f 189 * @param format format string to pass to printf
group-Avnet 0:478cfd88041f 190 * @param ... arguments to printf
group-Avnet 0:478cfd88041f 191 * @return number of bytes written or -1 on failure
group-Avnet 0:478cfd88041f 192 */
group-Avnet 0:478cfd88041f 193 int printf(const char *format, ...);
group-Avnet 0:478cfd88041f 194 int vprintf(const char *format, va_list args);
group-Avnet 0:478cfd88041f 195
group-Avnet 0:478cfd88041f 196 /**
group-Avnet 0:478cfd88041f 197 * Direct scanf on underlying stream
group-Avnet 0:478cfd88041f 198 * @see ::scanf
group-Avnet 0:478cfd88041f 199 *
group-Avnet 0:478cfd88041f 200 * @param format format string to pass to scanf
group-Avnet 0:478cfd88041f 201 * @param ... arguments to scanf
group-Avnet 0:478cfd88041f 202 * @return number of bytes read or -1 on failure
group-Avnet 0:478cfd88041f 203 */
group-Avnet 0:478cfd88041f 204 int scanf(const char *format, ...);
group-Avnet 0:478cfd88041f 205 int vscanf(const char *format, va_list args);
group-Avnet 0:478cfd88041f 206
group-Avnet 0:478cfd88041f 207 /**
group-Avnet 0:478cfd88041f 208 * Attach a callback for out-of-band data
group-Avnet 0:478cfd88041f 209 *
group-Avnet 0:478cfd88041f 210 * @param prefix string on when to initiate callback
group-Avnet 0:478cfd88041f 211 * @param func callback to call when string is read
group-Avnet 0:478cfd88041f 212 * @note out-of-band data is only processed during a scanf call
group-Avnet 0:478cfd88041f 213 */
group-Avnet 0:478cfd88041f 214 void oob(const char *prefix, mbed::Callback<void()> func);
group-Avnet 0:478cfd88041f 215
group-Avnet 0:478cfd88041f 216 /**
group-Avnet 0:478cfd88041f 217 * Attach a callback for out-of-band data
group-Avnet 0:478cfd88041f 218 *
group-Avnet 0:478cfd88041f 219 * @param prefix string on when to initiate callback
group-Avnet 0:478cfd88041f 220 * @param obj pointer to object to call member function on
group-Avnet 0:478cfd88041f 221 * @param method callback to call when string is read
group-Avnet 0:478cfd88041f 222 * @note out-of-band data is only processed during a scanf call
group-Avnet 0:478cfd88041f 223 */
group-Avnet 0:478cfd88041f 224 template <typename T, typename M>
group-Avnet 0:478cfd88041f 225 void oob(const char *prefix, T *obj, M method) {
group-Avnet 0:478cfd88041f 226 return oob(prefix, mbed::Callback<void()>(obj, method));
group-Avnet 0:478cfd88041f 227 }
group-Avnet 0:478cfd88041f 228
group-Avnet 0:478cfd88041f 229 /**
group-Avnet 0:478cfd88041f 230 * Flushes the underlying stream
group-Avnet 0:478cfd88041f 231 */
group-Avnet 0:478cfd88041f 232 void flush();
group-Avnet 0:478cfd88041f 233 };
group-Avnet 0:478cfd88041f 234 #endif