endpoint C207 radio support

Dependents:   mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular

Committer:
ansond
Date:
Fri Sep 26 05:22:50 2014 +0000
Revision:
23:a12a6b3910a9
Parent:
22:dca1bfab3021
updates for new logger

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:d46b1accad7d 1 /* Copyright C2013 Doug Anson, MIT License
ansond 0:d46b1accad7d 2 *
ansond 0:d46b1accad7d 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:d46b1accad7d 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:d46b1accad7d 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:d46b1accad7d 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:d46b1accad7d 7 * furnished to do so, subject to the following conditions:
ansond 0:d46b1accad7d 8 *
ansond 0:d46b1accad7d 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:d46b1accad7d 10 * substantial portions of the Software.
ansond 0:d46b1accad7d 11 *
ansond 0:d46b1accad7d 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:d46b1accad7d 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:d46b1accad7d 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:d46b1accad7d 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:d46b1accad7d 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:d46b1accad7d 17 */
ansond 0:d46b1accad7d 18
ansond 0:d46b1accad7d 19 // class support
ansond 3:6acc6c8143b7 20 #include "MBEDUbloxGPS.h"
ansond 0:d46b1accad7d 21
ansond 0:d46b1accad7d 22 // MBEDEndpoint support
ansond 0:d46b1accad7d 23 #include "MBEDEndpoint.h"
ansond 0:d46b1accad7d 24
ansond 1:76d2da9e2b84 25 // our instance
ansond 5:a8fd1fa0f0d0 26 MBEDUbloxGPS *_ublox_gps_instance = NULL;
ansond 6:cd2d23300f05 27 bool _ublox_gps_loop = true;
ansond 8:ad37c7157d3c 28
ansond 19:0fcc7e5ff8a6 29 #ifdef ENABLE_THREADS
ansond 19:0fcc7e5ff8a6 30 // threaded task
ansond 1:76d2da9e2b84 31 static void read_gps(void const *args) {
ansond 6:cd2d23300f05 32 while (_ublox_gps_loop == true && _ublox_gps_instance != NULL) {
ansond 5:a8fd1fa0f0d0 33 _ublox_gps_instance->update();
ansond 22:dca1bfab3021 34 Thread::wait(UBLOX_GPS_POLL_MS);
ansond 1:76d2da9e2b84 35 }
ansond 8:ad37c7157d3c 36 if (_ublox_gps_instance != NULL) _ublox_gps_instance->logger()->log("GPS update thread stopping...");
ansond 1:76d2da9e2b84 37 }
ansond 19:0fcc7e5ff8a6 38 #endif
ansond 1:76d2da9e2b84 39
ansond 0:d46b1accad7d 40 // default constructor
ansond 23:a12a6b3910a9 41 MBEDUbloxGPS::MBEDUbloxGPS(Logger *error_handler, void *endpoint,void *gps) : BaseClass(error_handler,endpoint) {
ansond 17:c48b03c386fb 42 #ifdef ENABLE_THREADS
ansond 8:ad37c7157d3c 43 this->m_gps_poll_thread = NULL;
ansond 17:c48b03c386fb 44 #endif
ansond 16:19f597d8048f 45 this->m_gps = (GPSParser *)gps;
ansond 1:76d2da9e2b84 46 this->m_latitude = 0;
ansond 1:76d2da9e2b84 47 this->m_longitude = 0;
ansond 5:a8fd1fa0f0d0 48 _ublox_gps_instance = this;
ansond 0:d46b1accad7d 49 }
ansond 0:d46b1accad7d 50
ansond 0:d46b1accad7d 51 // default destructor
ansond 3:6acc6c8143b7 52 MBEDUbloxGPS::~MBEDUbloxGPS() {
ansond 17:c48b03c386fb 53 #ifdef ENABLE_THREADS
ansond 1:76d2da9e2b84 54 if (this->m_gps_poll_thread != NULL) { this->m_gps_poll_thread->terminate(); delete this->m_gps_poll_thread; }
ansond 17:c48b03c386fb 55 #endif
ansond 17:c48b03c386fb 56
ansond 0:d46b1accad7d 57 }
ansond 0:d46b1accad7d 58
ansond 1:76d2da9e2b84 59 // update our GPS info
ansond 3:6acc6c8143b7 60 void MBEDUbloxGPS::update() {
ansond 16:19f597d8048f 61 char out[20];
ansond 16:19f597d8048f 62 memset(out,0,20);
ansond 16:19f597d8048f 63 sprintf(out,"<GPS off>");
ansond 1:76d2da9e2b84 64
ansond 1:76d2da9e2b84 65 // convert the input to latitude/longitude decimal values
ansond 1:76d2da9e2b84 66 this->logger()->log("GPS: Output: %s",out);
ansond 0:d46b1accad7d 67 }
ansond 0:d46b1accad7d 68
ansond 7:948040230536 69 // start the update thread and connect
ansond 7:948040230536 70 bool MBEDUbloxGPS::connect() {
ansond 17:c48b03c386fb 71 #ifdef ENABLE_THREADS
ansond 8:ad37c7157d3c 72 if (this->m_gps_poll_thread == NULL) {
ansond 17:c48b03c386fb 73 this->logger()->log("starting GPS update thread...");
ansond 17:c48b03c386fb 74 this->m_gps_poll_thread = new Thread(read_gps);
ansond 8:ad37c7157d3c 75 }
ansond 17:c48b03c386fb 76 #endif
ansond 7:948040230536 77 return true;
ansond 7:948040230536 78 }
ansond 7:948040230536 79
ansond 6:cd2d23300f05 80 // halt the update thread and disconnect
ansond 7:948040230536 81 bool MBEDUbloxGPS::disconnect() { _ublox_gps_loop = false; return true; }
ansond 6:cd2d23300f05 82
ansond 0:d46b1accad7d 83 // get latitude
ansond 3:6acc6c8143b7 84 float MBEDUbloxGPS::getLatitude() { return this->m_latitude; }
ansond 0:d46b1accad7d 85
ansond 0:d46b1accad7d 86 // get longitude
ansond 5:a8fd1fa0f0d0 87 float MBEDUbloxGPS::getLongitude() { return this->m_longitude; }