endpoint C207 radio support

Dependents:   mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular

Committer:
ansond
Date:
Wed Apr 02 18:36:55 2014 +0000
Revision:
13:28340983102c
Parent:
12:29ff8e9e0cbe
Child:
14:5061a0361ab4
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 1:76d2da9e2b84 1 /* Copyright C2013 Doug Anson, MIT License
ansond 1:76d2da9e2b84 2 *
ansond 1:76d2da9e2b84 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 1:76d2da9e2b84 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 1:76d2da9e2b84 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 1:76d2da9e2b84 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 1:76d2da9e2b84 7 * furnished to do so, subject to the following conditions:
ansond 1:76d2da9e2b84 8 *
ansond 1:76d2da9e2b84 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 1:76d2da9e2b84 10 * substantial portions of the Software.
ansond 1:76d2da9e2b84 11 *
ansond 1:76d2da9e2b84 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 1:76d2da9e2b84 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 1:76d2da9e2b84 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 1:76d2da9e2b84 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 1:76d2da9e2b84 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 1:76d2da9e2b84 17 */
ansond 1:76d2da9e2b84 18
ansond 1:76d2da9e2b84 19 // class support
ansond 3:6acc6c8143b7 20 #include "MBEDUbloxCellRadio.h"
ansond 1:76d2da9e2b84 21
ansond 1:76d2da9e2b84 22 // MBEDEndpoint support
ansond 1:76d2da9e2b84 23 #include "MBEDEndpoint.h"
ansond 9:c5db2b63ed05 24
ansond 1:76d2da9e2b84 25 // default constructor
ansond 9:c5db2b63ed05 26 MBEDUbloxCellRadio::MBEDUbloxCellRadio(ErrorHandler *error_handler, void *endpoint,UBLOX_MODEM *modem,C027 *c027) : BaseClass(error_handler,endpoint) {
ansond 9:c5db2b63ed05 27 this->m_modem = modem;
ansond 9:c5db2b63ed05 28 this->m_c027 = c027;
ansond 1:76d2da9e2b84 29 this->m_connected = false;
ansond 1:76d2da9e2b84 30 }
ansond 1:76d2da9e2b84 31
ansond 1:76d2da9e2b84 32 // default destructor
ansond 3:6acc6c8143b7 33 MBEDUbloxCellRadio::~MBEDUbloxCellRadio() {
ansond 1:76d2da9e2b84 34 }
ansond 1:76d2da9e2b84 35
ansond 1:76d2da9e2b84 36 // connect
ansond 3:6acc6c8143b7 37 bool MBEDUbloxCellRadio::connect() {
ansond 1:76d2da9e2b84 38 if (this->m_connected == false) {
ansond 11:9f031bd67811 39 this->logger()->log("applying modem power...");
ansond 12:29ff8e9e0cbe 40 this->m_c027->mdmUsbEnable(true);
ansond 13:28340983102c 41 this->logger()->log("powering modem...");
ansond 11:9f031bd67811 42 this->m_c027->mdmPower(true);
ansond 13:28340983102c 43 //this->logger()->log("resetting modem...");
ansond 13:28340983102c 44 //this->m_c027->mdmReset();
ansond 13:28340983102c 45 //this->logger()->log("waking modem...");
ansond 13:28340983102c 46 //this->m_c027->mdmWakeup();
ansond 13:28340983102c 47 //this->logger()->log("waiting a bit...");
ansond 13:28340983102c 48 //Thread::wait(UBLOX_CDMA_DELAY_MS);
ansond 13:28340983102c 49 //this->logger()->log("powering modem...");
ansond 13:28340983102c 50 //this->m_modem->power(true);
ansond 11:9f031bd67811 51 this->logger()->log("waiting a bit...");
ansond 11:9f031bd67811 52 Thread::wait(UBLOX_CDMA_DELAY_MS);
ansond 10:83baedde4e85 53 this->logger()->log("connecting...");
ansond 10:83baedde4e85 54 int ret = this->m_modem->connect("internet");
ansond 10:83baedde4e85 55 if(ret) this->logger()->log("cellular modem connection FAILED!");
ansond 10:83baedde4e85 56 else this->logger()->log("cellular modem connected!");
ansond 10:83baedde4e85 57 this->m_connected = true;
ansond 13:28340983102c 58 }
ansond 11:9f031bd67811 59 if (this->m_connected == false) this->logger()->log("cell modem connect FAILED");
ansond 11:9f031bd67811 60 return this->m_connected;
ansond 1:76d2da9e2b84 61 }
ansond 1:76d2da9e2b84 62
ansond 1:76d2da9e2b84 63 // disconnect
ansond 3:6acc6c8143b7 64 bool MBEDUbloxCellRadio::disconnect() {
ansond 1:76d2da9e2b84 65 if (this->m_connected == true) {
ansond 1:76d2da9e2b84 66 this->m_modem->disconnect();
ansond 1:76d2da9e2b84 67 this->m_c027->mdmPower(false);
ansond 1:76d2da9e2b84 68 this->m_connected = false;
ansond 1:76d2da9e2b84 69 }
ansond 1:76d2da9e2b84 70 return !this->m_connected;
ansond 5:a8fd1fa0f0d0 71 }