Programa para enviar mensaje GPS solicitando coordenadas, y mensaje PWM para parametrizar a distancia un PWM en klz25 utilizando modem GSM del celular siemens a56i y el satgem como simulador de GPS

Dependencies:   mbed

Committer:
jdlodonog
Date:
Wed Nov 30 03:02:42 2016 +0000
Revision:
0:2baec676c5bf
Envi? palabra  por mensaje de text0 GSM y retorna coordenadas de google maps, envi? de PWM y parametros de salida PWM en kl25z

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jdlodonog 0:2baec676c5bf 1
jdlodonog 0:2baec676c5bf 2 /* mbed EM-406 GPS Module Library
jdlodonog 0:2baec676c5bf 3 * Copyright (c) 2008-2010, sford
jdlodonog 0:2baec676c5bf 4 *
jdlodonog 0:2baec676c5bf 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
jdlodonog 0:2baec676c5bf 6 * of this software and associated documentation files (the "Software"), to deal
jdlodonog 0:2baec676c5bf 7 * in the Software without restriction, including without limitation the rights
jdlodonog 0:2baec676c5bf 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jdlodonog 0:2baec676c5bf 9 * copies of the Software, and to permit persons to whom the Software is
jdlodonog 0:2baec676c5bf 10 * furnished to do so, subject to the following conditions:
jdlodonog 0:2baec676c5bf 11 *
jdlodonog 0:2baec676c5bf 12 * The above copyright notice and this permission notice shall be included in
jdlodonog 0:2baec676c5bf 13 * all copies or substantial portions of the Software.
jdlodonog 0:2baec676c5bf 14 *
jdlodonog 0:2baec676c5bf 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jdlodonog 0:2baec676c5bf 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jdlodonog 0:2baec676c5bf 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jdlodonog 0:2baec676c5bf 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jdlodonog 0:2baec676c5bf 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jdlodonog 0:2baec676c5bf 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jdlodonog 0:2baec676c5bf 21 * THE SOFTWARE.
jdlodonog 0:2baec676c5bf 22 */
jdlodonog 0:2baec676c5bf 23
jdlodonog 0:2baec676c5bf 24 #include "GPS.h"
jdlodonog 0:2baec676c5bf 25
jdlodonog 0:2baec676c5bf 26 GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
jdlodonog 0:2baec676c5bf 27 _gps.baud(9600);
jdlodonog 0:2baec676c5bf 28 longitude = 0.0;
jdlodonog 0:2baec676c5bf 29 latitude = 0.0;
jdlodonog 0:2baec676c5bf 30 }
jdlodonog 0:2baec676c5bf 31
jdlodonog 0:2baec676c5bf 32 int GPS::sample() {
jdlodonog 0:2baec676c5bf 33 float time;
jdlodonog 0:2baec676c5bf 34 char ns, ew;
jdlodonog 0:2baec676c5bf 35 int lock;
jdlodonog 0:2baec676c5bf 36
jdlodonog 0:2baec676c5bf 37 while(1) {
jdlodonog 0:2baec676c5bf 38 getline();
jdlodonog 0:2baec676c5bf 39 //$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
jdlodonog 0:2baec676c5bf 40 // Check if it is a GPGGA msg (matches both locked and non-locked msg)
jdlodonog 0:2baec676c5bf 41 if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) {
jdlodonog 0:2baec676c5bf 42 if(!lock) { //si lock es 1 hay lecturas ok
jdlodonog 0:2baec676c5bf 43 longitude = 0.0;
jdlodonog 0:2baec676c5bf 44 latitude = 0.0;
jdlodonog 0:2baec676c5bf 45 return 0;
jdlodonog 0:2baec676c5bf 46 }
jdlodonog 0:2baec676c5bf 47 else {
jdlodonog 0:2baec676c5bf 48 if(ns == 'S') { latitude *= -1.0; }
jdlodonog 0:2baec676c5bf 49 if(ew == 'W') { longitude *= -1.0; }
jdlodonog 0:2baec676c5bf 50 latitude = (latitude / 100.0f);
jdlodonog 0:2baec676c5bf 51 //float minutes = latitude - (degrees * 100.0f);
jdlodonog 0:2baec676c5bf 52 //latitude = degrees + minutes / 60.0f;
jdlodonog 0:2baec676c5bf 53 longitude = (longitude / 100.0f);
jdlodonog 0:2baec676c5bf 54 //minutes = longitude - (degrees * 100.0f);
jdlodonog 0:2baec676c5bf 55 //longitude = degrees + minutes / 60.0f;
jdlodonog 0:2baec676c5bf 56
jdlodonog 0:2baec676c5bf 57 return 1;
jdlodonog 0:2baec676c5bf 58 }
jdlodonog 0:2baec676c5bf 59 }
jdlodonog 0:2baec676c5bf 60 }
jdlodonog 0:2baec676c5bf 61 }
jdlodonog 0:2baec676c5bf 62
jdlodonog 0:2baec676c5bf 63 /*
jdlodonog 0:2baec676c5bf 64 float GPS::trunc(float v) {
jdlodonog 0:2baec676c5bf 65 if(v < 0.0) {
jdlodonog 0:2baec676c5bf 66 v*= -1.0;
jdlodonog 0:2baec676c5bf 67 v = floor(v);
jdlodonog 0:2baec676c5bf 68 v*=-1.0;
jdlodonog 0:2baec676c5bf 69 } else {
jdlodonog 0:2baec676c5bf 70 v = floor(v);
jdlodonog 0:2baec676c5bf 71 }
jdlodonog 0:2baec676c5bf 72 return v;
jdlodonog 0:2baec676c5bf 73 }
jdlodonog 0:2baec676c5bf 74 */
jdlodonog 0:2baec676c5bf 75 void GPS::getline() {
jdlodonog 0:2baec676c5bf 76 while(_gps.getc() != '$'); // wait for the start of a line
jdlodonog 0:2baec676c5bf 77 for(int i=0; i<512; i++) {
jdlodonog 0:2baec676c5bf 78 msg[i] = _gps.getc();
jdlodonog 0:2baec676c5bf 79 if(msg[i] == '\r') {
jdlodonog 0:2baec676c5bf 80 msg[i] = 0;
jdlodonog 0:2baec676c5bf 81 return;
jdlodonog 0:2baec676c5bf 82 }
jdlodonog 0:2baec676c5bf 83 }
jdlodonog 0:2baec676c5bf 84 error("Overflowed message limit");
jdlodonog 0:2baec676c5bf 85 }
jdlodonog 0:2baec676c5bf 86