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