Étape 2: Code
#includegpsSentenceInfoStruct info ;
buff de char [256] ;
public static unsigned char getComma (unsigned char num, const char * str)
{
unsigned char i, j = 0 ;
int len=strlen(str) ;
pour (i = 0; i < len ; j’ai ++)
{
Si (str [i] == «, »)
j ++ ;
if(j == num)
retour i + 1 ;
}
return 0 ;
}
public static double getDoubleNumber (const char * s)
{
char buf [10] ;
unsigned char i ;
double rev ;
J’ai = getComma (1 s) ;
i = i - 1 ;
strncpy (buf, s, i) ;
buf [i] = 0 ;
Rev=atof(BUF) ;
retour rev ;
}
public static double getIntNumber (const char * s)
{
char buf [10] ;
unsigned char i ;
double rev ;
J’ai = getComma (1 s) ;
i = i - 1 ;
strncpy (buf, s, i) ;
buf [i] = 0 ;
Rev=atoi(BUF) ;
retour rev ;
}
void parseGPGGA (const char * GPGGAstr)
{
/ * Se référer à http://www.gpsinformation.org/dale/nmea.htm#GGA
Exemple de données: $GPGGA, 123519, 4807.038, N, 01131.000, E, 1, 08, 0,9 545,4, M, 46,9, M,, * 47
* Où :
* Système de positionnement Global GGA Difficulté données
* 123519 fix prise à 12:35:19 UTC
* 4807.038, N Latitude 48 deg 07.038' N
* 01131.000, E Longitude 11 deg 31,000' E
* 1 fix qualité: 0 = non valide
* 1 = Coordonnées GPS (SPS)
* 2 = correction DGPS
* 3 = PPS fix
* 4 = cinématique en temps réel
* 5 = float RTK
* 6 = estimée (dead reckoning) (article 2.3)
* 7 = mode de saisie manuelle
* 8 = mode de simulation
* 08 nombre de satellites étant l’objet d’un suivi
* 0,9 horizontale dilution de position
* 545,4, M d’Altitude, mètres, au-dessus du niveau de mer
* 46,9, M hauteur du géoïde (niveau moyen de la mer) au dessus de WGS84
* ellipsoïde
* (temps champ vide) en secondes depuis DGPS dernières mise à jour
* (numéro d’identification du station DGPS champ vide)
* * 47 les données de checksum, commence toujours par *
*/
double latitude ;
double longitude ;
heure, minute, seconde, int tmp, num ;
Si (GPGGAstr [0] == « $»)
{
tmp = getComma (1, GPGGAstr) ;
heure = (GPGGAstr [tmp + 0] - « 0 ») * 10 + (GPGGAstr [tmp + 1] - « 0 ») ;
minute = (GPGGAstr [tmp + 2] - « 0 ») * 10 + (GPGGAstr [tmp + 3] - « 0 ») ;
deuxième = (GPGGAstr [tmp + 4] - « 0 ») * 10 + (GPGGAstr [tmp + 5] - « 0 ») ;
sprintf (chamois, "UTC minuterie 2d-2d-% 2d", heure, minute, seconde) ;
Serial.println(buff) ;
tmp = getComma (2, GPGGAstr) ;
Latitude = getDoubleNumber (& GPGGAstr[tmp]) ;
tmp = getComma (4, GPGGAstr) ;
Longitude = getDoubleNumber (& GPGGAstr[tmp]) ;
sprintf (chamois, "latitude = % 10 .4f, longitude = %10.4f", latitude, longitude) ;
Serial.println(buff) ;
tmp = getComma (7, GPGGAstr) ;
num = getIntNumber (& GPGGAstr[tmp]) ;
sprintf (chamois, "nombre de satellites = %d", num) ;
Serial.println(buff) ;
}
d’autre
{
Serial.println ("pas get data") ;
}
}
void setup() {}
Mettez votre code de programme d’installation ici, pour exécuter une fois :
Serial.Begin(115200) ;
LGPS.powerOn() ;
Serial.println ("LGPS allumez et en attendant...") ;
Delay(3000) ;
while (!. LSMS.ready) {}
Delay(1000) ;
}
}
void loop() {}
Mettez votre code principal ici, pour exécuter à plusieurs reprises :
Serial.println ("LGPS loop") ;
LGPS.getData(&info) ;
LSMS.beginSMS ("Entrez no") ;
LSMS.print ((char*) info. GPGGA) ;
parseGPGGA ((const char*) info. GPGGA) ;
Delay(2000) ;
LSMS.endSMS() ;
}