Library for controlling the WNC 14A2A from the K64F Freedom Board. It fulfills platform specific pure virtual methods from the WncControllerLibrary.

Dependencies:   WncControllerLibrary

Dependents:   WNC14A2AInterface

Fork of WncControllerK64F by Fred Kellerman

Use this interface to connect to and interact with the WNC M14A2A LTE Cellular Data Module which is provided by Wistron NeWeb Corporation (WNC) when using ARMmbed v5. The interface provides a Networking interface that can be used with the AT&T Cellular IoT Starter Kit that is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

To demonstrate the use of the Interface, a series of example programs have been provided. Links to these examples are provided below. All examples can be compiled using both the on-line compiler and the ARMmbed CLI (command line interface, see https://github.com/ARMmbed/mbed-cli)

NOTE: This library/class is specific to the AT&T Cellular IoT Starter Kit which uses a FRDM-K64F. The users mbed.org compiler should be configured to use the FRDM-K64F platform.

Example Programs

Import the example programs below and follow the README.md in each to run the example program.

  • several examples of the interface using easy_connect.
  • SMS demonstration program that demonstrates SMS usage
  • Sockets demonstration program demonstrating using TCP sockets to interact with others
  • As new example program are developed, this README will be updated

WNC FIRWARE VERSION

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

  • MPSS: M14A2A_v11.21.162331 APSS: M14A2A_v11.27.162331

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:
fkellermavnet
Date:
Fri Sep 02 16:37:29 2016 +0000
Revision:
0:98d149685c95
Child:
13:ef379cdd57aa
Separate library for platform specific WNC controlling.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fkellermavnet 0:98d149685c95 1 /*
fkellermavnet 0:98d149685c95 2 Copyright (c) 2016 Fred Kellerman
fkellermavnet 0:98d149685c95 3
fkellermavnet 0:98d149685c95 4 Permission is hereby granted, free of charge, to any person obtaining a copy
fkellermavnet 0:98d149685c95 5 of this software and associated documentation files (the "Software"), to deal
fkellermavnet 0:98d149685c95 6 in the Software without restriction, including without limitation the rights
fkellermavnet 0:98d149685c95 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fkellermavnet 0:98d149685c95 8 copies of the Software, and to permit persons to whom the Software is
fkellermavnet 0:98d149685c95 9 furnished to do so, subject to the following conditions:
fkellermavnet 0:98d149685c95 10
fkellermavnet 0:98d149685c95 11 The above copyright notice and this permission notice shall be included in
fkellermavnet 0:98d149685c95 12 all copies or substantial portions of the Software.
fkellermavnet 0:98d149685c95 13
fkellermavnet 0:98d149685c95 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fkellermavnet 0:98d149685c95 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fkellermavnet 0:98d149685c95 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fkellermavnet 0:98d149685c95 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fkellermavnet 0:98d149685c95 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fkellermavnet 0:98d149685c95 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
fkellermavnet 0:98d149685c95 20 THE SOFTWARE.
fkellermavnet 0:98d149685c95 21
fkellermavnet 0:98d149685c95 22 @file WncController.cpp
fkellermavnet 0:98d149685c95 23 @purpose Controls WNC Cellular Modem
fkellermavnet 0:98d149685c95 24 @version 1.0
fkellermavnet 0:98d149685c95 25 @date July 2016
fkellermavnet 0:98d149685c95 26 @author Fred Kellerman
fkellermavnet 0:98d149685c95 27 */
fkellermavnet 0:98d149685c95 28
fkellermavnet 0:98d149685c95 29 #include "WncControllerK64F.h"
fkellermavnet 0:98d149685c95 30
fkellermavnet 0:98d149685c95 31 using namespace WncControllerK64F_fk;
fkellermavnet 0:98d149685c95 32
fkellermavnet 0:98d149685c95 33 WncControllerK64F::WncControllerK64F(struct WncGpioPinListK64F * pPins, MODSERIAL * wnc_uart, MODSERIAL * debug_uart)
fkellermavnet 0:98d149685c95 34 {
fkellermavnet 0:98d149685c95 35 m_logTimer.start(); // Start the log timer now!
fkellermavnet 0:98d149685c95 36 m_pDbgUart = debug_uart;
fkellermavnet 0:98d149685c95 37 m_pWncUart = wnc_uart;
fkellermavnet 0:98d149685c95 38 m_gpioPinList = *pPins;
fkellermavnet 0:98d149685c95 39 }
fkellermavnet 0:98d149685c95 40
fkellermavnet 0:98d149685c95 41 bool WncControllerK64F::enterWncTerminalMode(bool echoOn)
fkellermavnet 0:98d149685c95 42 {
fkellermavnet 0:98d149685c95 43 string * resp;
fkellermavnet 0:98d149685c95 44 AtCmdErr_e r = sendWncCmd("AT", &resp, 500);
fkellermavnet 0:98d149685c95 45 if (r == WNC_AT_CMD_TIMEOUT)
fkellermavnet 0:98d149685c95 46 return (false);
fkellermavnet 0:98d149685c95 47
fkellermavnet 0:98d149685c95 48 m_pDbgUart->puts("\r\nEntering WNC Terminal Mode - press <CTRL>-Q to exit!\r\n");
fkellermavnet 0:98d149685c95 49
fkellermavnet 0:98d149685c95 50 while (1) {
fkellermavnet 0:98d149685c95 51 if (m_pDbgUart->readable()) {
fkellermavnet 0:98d149685c95 52 char c = m_pDbgUart->getc();
fkellermavnet 0:98d149685c95 53 if (c == '\x11') {
fkellermavnet 0:98d149685c95 54 m_pDbgUart->puts("\r\nExiting WNC Terminal Mode!\r\n");
fkellermavnet 0:98d149685c95 55 // Cleanup in case user doesn't finish command:
fkellermavnet 0:98d149685c95 56 sendWncCmd("AT", &resp, 300);
fkellermavnet 0:98d149685c95 57 // Above AT may fail but should get WNC back in sync
fkellermavnet 0:98d149685c95 58 return (sendWncCmd("AT", &resp, 500) == WNC_AT_CMD_OK);
fkellermavnet 0:98d149685c95 59 }
fkellermavnet 0:98d149685c95 60 if (echoOn == true) {
fkellermavnet 0:98d149685c95 61 m_pDbgUart->putc(c);
fkellermavnet 0:98d149685c95 62 }
fkellermavnet 0:98d149685c95 63 m_pWncUart->putc(c);
fkellermavnet 0:98d149685c95 64 }
fkellermavnet 0:98d149685c95 65 if (m_pWncUart->readable())
fkellermavnet 0:98d149685c95 66 m_pDbgUart->putc(m_pWncUart->getc());
fkellermavnet 0:98d149685c95 67 }
fkellermavnet 0:98d149685c95 68 }
fkellermavnet 0:98d149685c95 69
fkellermavnet 0:98d149685c95 70
fkellermavnet 0:98d149685c95 71 int WncControllerK64F::putc(char c)
fkellermavnet 0:98d149685c95 72 {
fkellermavnet 0:98d149685c95 73 return (m_pWncUart->putc(c));
fkellermavnet 0:98d149685c95 74 }
fkellermavnet 0:98d149685c95 75
fkellermavnet 0:98d149685c95 76 int WncControllerK64F::puts(const char * s)
fkellermavnet 0:98d149685c95 77 {
fkellermavnet 0:98d149685c95 78 return (m_pWncUart->puts(s));
fkellermavnet 0:98d149685c95 79 }
fkellermavnet 0:98d149685c95 80
fkellermavnet 0:98d149685c95 81 char WncControllerK64F::getc(void)
fkellermavnet 0:98d149685c95 82 {
fkellermavnet 0:98d149685c95 83 return (m_pWncUart->getc());
fkellermavnet 0:98d149685c95 84 }
fkellermavnet 0:98d149685c95 85
fkellermavnet 0:98d149685c95 86 int WncControllerK64F::charReady(void)
fkellermavnet 0:98d149685c95 87 {
fkellermavnet 0:98d149685c95 88 return (m_pWncUart->readable());
fkellermavnet 0:98d149685c95 89 }
fkellermavnet 0:98d149685c95 90
fkellermavnet 0:98d149685c95 91 int WncControllerK64F::dbgWriteChar(char b)
fkellermavnet 0:98d149685c95 92 {
fkellermavnet 0:98d149685c95 93 if (m_pDbgUart != NULL)
fkellermavnet 0:98d149685c95 94 return (m_pDbgUart->putc(b));
fkellermavnet 0:98d149685c95 95 else
fkellermavnet 0:98d149685c95 96 return (0);
fkellermavnet 0:98d149685c95 97 }
fkellermavnet 0:98d149685c95 98
fkellermavnet 0:98d149685c95 99 int WncControllerK64F::dbgWriteChars(const char * b)
fkellermavnet 0:98d149685c95 100 {
fkellermavnet 0:98d149685c95 101 if (m_pDbgUart != NULL)
fkellermavnet 0:98d149685c95 102 return (m_pDbgUart->puts(b));
fkellermavnet 0:98d149685c95 103 else
fkellermavnet 0:98d149685c95 104 return (0);
fkellermavnet 0:98d149685c95 105 }
fkellermavnet 0:98d149685c95 106
fkellermavnet 0:98d149685c95 107 bool WncControllerK64F::initWncModem(uint8_t powerUpTimeoutSecs)
fkellermavnet 0:98d149685c95 108 {
fkellermavnet 0:98d149685c95 109 // Hard reset the modem (doesn't go through
fkellermavnet 0:98d149685c95 110 // the signal level translator)
fkellermavnet 0:98d149685c95 111 *m_gpioPinList.mdm_reset = 0;
fkellermavnet 0:98d149685c95 112
fkellermavnet 0:98d149685c95 113 // disable signal level translator (necessary
fkellermavnet 0:98d149685c95 114 // for the modem to boot properly). All signals
fkellermavnet 0:98d149685c95 115 // except mdm_reset go through the level translator
fkellermavnet 0:98d149685c95 116 // and have internal pull-up/down in the module. While
fkellermavnet 0:98d149685c95 117 // the level translator is disabled, these pins will
fkellermavnet 0:98d149685c95 118 // be in the correct state.
fkellermavnet 0:98d149685c95 119 *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 0;
fkellermavnet 0:98d149685c95 120
fkellermavnet 0:98d149685c95 121 // While the level translator is disabled and ouptut pins
fkellermavnet 0:98d149685c95 122 // are tristated, make sure the inputs are in the same state
fkellermavnet 0:98d149685c95 123 // as the WNC Module pins so that when the level translator is
fkellermavnet 0:98d149685c95 124 // enabled, there are no differences.
fkellermavnet 0:98d149685c95 125 *m_gpioPinList.mdm_uart2_rx_boot_mode_sel = 1; // UART2_RX should be high
fkellermavnet 0:98d149685c95 126 *m_gpioPinList.mdm_power_on = 0; // powr_on should be low
fkellermavnet 0:98d149685c95 127 *m_gpioPinList.mdm_wakeup_in = 1; // wake-up should be high
fkellermavnet 0:98d149685c95 128 *m_gpioPinList.mdm_uart1_cts = 0; // indicate that it is ok to send
fkellermavnet 0:98d149685c95 129
fkellermavnet 0:98d149685c95 130 // Now, wait for the WNC Module to perform its initial boot correctly
fkellermavnet 0:98d149685c95 131 waitMs(1000);
fkellermavnet 0:98d149685c95 132
fkellermavnet 0:98d149685c95 133 // The WNC module initializes comms at 115200 8N1 so set it up
fkellermavnet 0:98d149685c95 134 m_pWncUart->baud(115200);
fkellermavnet 0:98d149685c95 135
fkellermavnet 0:98d149685c95 136 //Now, enable the level translator, the input pins should now be the
fkellermavnet 0:98d149685c95 137 //same as how the M14A module is driving them with internal pull ups/downs.
fkellermavnet 0:98d149685c95 138 //When enabled, there will be no changes in these 4 pins...
fkellermavnet 0:98d149685c95 139 *m_gpioPinList.shield_3v3_1v8_sig_trans_ena = 1;
fkellermavnet 0:98d149685c95 140
fkellermavnet 0:98d149685c95 141 return (waitForPowerOnModemToRespond(powerUpTimeoutSecs));
fkellermavnet 0:98d149685c95 142 }
fkellermavnet 0:98d149685c95 143
fkellermavnet 0:98d149685c95 144 void WncControllerK64F::waitMs(int t)
fkellermavnet 0:98d149685c95 145 {
fkellermavnet 0:98d149685c95 146 wait_ms(t);
fkellermavnet 0:98d149685c95 147 }
fkellermavnet 0:98d149685c95 148
fkellermavnet 0:98d149685c95 149 void WncControllerK64F::waitUs(int t)
fkellermavnet 0:98d149685c95 150 {
fkellermavnet 0:98d149685c95 151 wait_ms(t);
fkellermavnet 0:98d149685c95 152 }
fkellermavnet 0:98d149685c95 153
fkellermavnet 0:98d149685c95 154 int WncControllerK64F::getLogTimerTicks(void)
fkellermavnet 0:98d149685c95 155 {
fkellermavnet 0:98d149685c95 156 return (m_logTimer.read_us());
fkellermavnet 0:98d149685c95 157 }
fkellermavnet 0:98d149685c95 158
fkellermavnet 0:98d149685c95 159 void WncControllerK64F::startTimerA(void)
fkellermavnet 0:98d149685c95 160 {
fkellermavnet 0:98d149685c95 161 m_timerA.start();
fkellermavnet 0:98d149685c95 162 m_timerA.reset();
fkellermavnet 0:98d149685c95 163 }
fkellermavnet 0:98d149685c95 164
fkellermavnet 0:98d149685c95 165 void WncControllerK64F::stopTimerA(void)
fkellermavnet 0:98d149685c95 166 {
fkellermavnet 0:98d149685c95 167 m_timerA.stop();
fkellermavnet 0:98d149685c95 168 }
fkellermavnet 0:98d149685c95 169
fkellermavnet 0:98d149685c95 170 int WncControllerK64F::getTimerTicksA_mS(void)
fkellermavnet 0:98d149685c95 171 {
fkellermavnet 0:98d149685c95 172 return (m_timerA.read_ms());
fkellermavnet 0:98d149685c95 173 }
fkellermavnet 0:98d149685c95 174
fkellermavnet 0:98d149685c95 175 void WncControllerK64F::startTimerB(void)
fkellermavnet 0:98d149685c95 176 {
fkellermavnet 0:98d149685c95 177 m_timerB.start();
fkellermavnet 0:98d149685c95 178 m_timerB.reset();
fkellermavnet 0:98d149685c95 179 }
fkellermavnet 0:98d149685c95 180
fkellermavnet 0:98d149685c95 181 void WncControllerK64F::stopTimerB(void)
fkellermavnet 0:98d149685c95 182 {
fkellermavnet 0:98d149685c95 183 m_timerB.stop();
fkellermavnet 0:98d149685c95 184 }
fkellermavnet 0:98d149685c95 185
fkellermavnet 0:98d149685c95 186 int WncControllerK64F::getTimerTicksB_mS(void)
fkellermavnet 0:98d149685c95 187 {
fkellermavnet 0:98d149685c95 188 return (m_timerB.read_ms());
fkellermavnet 0:98d149685c95 189 }