Hiber

Files at this revision

API Documentation at this revision

Comitter:
hmbed
Date:
Thu Dec 19 10:52:48 2019 +0000
Parent:
106:d323dd088ba2
Commit message:
Hiber First Commit

Changed in this revision

GPS/MAXM8.cpp Show annotated file Show diff for this revision Revisions of this file
GPS/MAXM8.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d323dd088ba2 -r fc06d50dacef GPS/MAXM8.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS/MAXM8.cpp	Thu Dec 19 10:52:48 2019 +0000
@@ -0,0 +1,172 @@
+#include "mbed.h"
+#include "MAXM8.h"
+#define NUM_OF_NMEA_SENTENCES 3
+// <editor-fold defaultstate="collapsed" desc="Golbal Variables"> 
+ 
+int BUFFER_Num=0;
+bool Status_SentenceIsReadyToParse;
+bool Status_SentenceParsed;
+ 
+
+// </editor-fold>
+ 
+// <editor-fold defaultstate="collapsed" desc="Prototypes"> 
+ 
+enum minmea_sentence_id MAXM8_NMEA_Id(char *str_id);
+
+ 
+// </editor-fold>
+  
+char uart_first_buffer[MAX_BUFFER_SIZE];
+
+ 
+
+bool MAXM8_NMEA_Putc(char uart_char, char *uart_buffer){
+
+    static int sentence_initialized = FALSE;
+    static char *uart_buffer_prt=0;
+
+    if (uart_char == '$') {
+        uart_buffer_prt=uart_buffer;
+        memset(uart_buffer_prt, '\0', MAX_BUFFER_SIZE); //clears the buffer
+        *uart_buffer_prt = uart_char;
+        uart_buffer_prt++;
+        sentence_initialized = TRUE;
+        
+        return FALSE;//Sentence Not Complete
+
+    } else if (uart_char != '\r' && sentence_initialized == TRUE) {
+        *uart_buffer_prt = uart_char;
+        uart_buffer_prt++;
+        
+        return FALSE; //Sentence Not Complete
+
+    } else if (uart_char == '\r' && sentence_initialized == TRUE) {
+        *uart_buffer_prt = '\0';
+        sentence_initialized = FALSE;
+        
+        return TRUE; //Sentence Complete
+    }
+    else
+        return FALSE;
+}
+ 
+bool MAXM8_NMEA_Parser(struct minmea_sentence *gps_frame, int *isPositionDataValid, char *uart_buffer_prt) {
+
+
+    //GGA - RMC - VTG
+    char *start_decimalpart;
+    char *end_decimalpart;
+    int  GPS_nmea_id;
+    char *field[MAX_FIELDS_NUMBER];
+
+    bool isSentenceParsedValid=FALSE;
+
+    int p = 0;
+
+    // <editor-fold defaultstate="collapsed" desc="Command Splitter">
+    field[0] =(uart_buffer_prt);
+
+    while (*uart_buffer_prt != '\0') {
+        if (*uart_buffer_prt == ',' || *uart_buffer_prt == '*') {
+            *uart_buffer_prt = '\0';
+            field[++p] = uart_buffer_prt + 1;
+        }
+        uart_buffer_prt++;
+    }
+
+
+    // </editor-fold>
+
+    // <editor-fold defaultstate="collapsed" desc="Parser">
+
+
+    GPS_nmea_id = MAXM8_NMEA_Id(field[0]);
+
+
+
+    switch (GPS_nmea_id) {
+
+        case NMEA_SENTENCE_RMC:
+            //$GPRMC,130652.000,A,4038.0868,N,00838.9093,W,0.40,67.63,290316,,,A*49
+            //Valid
+             //FGPMMOPA6H_DisableInterrupts();
+
+
+
+            if (*field[2]== 'A'){ //If the coordenates are valid
+
+
+        //Latitude
+
+                gps_frame->latitude.integer = strtol(field[3], &start_decimalpart, 10);
+
+
+                //printf("%ld ",gps_frame->latitude.integer);
+
+
+                gps_frame->latitude.decimal = strtol(start_decimalpart+1, &end_decimalpart, 10);
+                if (strcmp(field[4], "N") == 0)
+                    gps_frame->latitude.cardeal = 0; //0=North
+
+                if (strcmp(field[4], "S") == 0)
+                    gps_frame->latitude.cardeal = 1; // 1=South
+
+
+
+                //Longitude
+                gps_frame->longitude.integer = strtol(field[5], &start_decimalpart, 10);
+                gps_frame->longitude.decimal = strtol(start_decimalpart+1, &end_decimalpart, 10);
+
+                //Longitude
+                if (strcmp(field[6], "W") == 0)
+                    gps_frame->longitude.cardeal = 0; //0=West
+
+                if (strcmp(field[6], "E") == 0)
+                    gps_frame->longitude.cardeal = 1; // 1=East
+            }
+            else
+                *isPositionDataValid = FALSE;
+
+            break;
+
+      case NMEA_SENTENCE_GGA:
+                isSentenceParsedValid=TRUE;
+            gps_frame->altitude = strtol(field[11], &start_decimalpart, 10);
+
+            gps_frame->num_of_satellites_tracked= strtol(field[7],&start_decimalpart, 10);
+
+            break;
+
+        case NMEA_SENTENCE_VTG:
+                isSentenceParsedValid=TRUE;
+
+            gps_frame->speed = strtol(field[7], &start_decimalpart, 10);
+            break;
+
+        default:
+            isSentenceParsedValid=FALSE;
+            break;
+    }
+
+
+
+    return isSentenceParsedValid;
+}
+ 
+enum minmea_sentence_id MAXM8_NMEA_Id(char *str_id) {
+ 
+    if (strcmp(str_id, "$GPGGA") == 0)
+        return NMEA_SENTENCE_GGA;
+    else if (strcmp(str_id, "$GPRMC") == 0)
+        return NMEA_SENTENCE_RMC;
+     
+    else if (strcmp(str_id,"$GPVTG")==0)
+        return NMEA_SENTENCE_VTG;
+ 
+    else
+        return MINMEA_UNKNOWN;
+ 
+     
+}
+ 
\ No newline at end of file
diff -r d323dd088ba2 -r fc06d50dacef GPS/MAXM8.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS/MAXM8.h	Thu Dec 19 10:52:48 2019 +0000
@@ -0,0 +1,56 @@
+#ifndef MAXM8_H_INCLUDED
+#define MAXM8_H_INCLUDED
+#include <stdbool.h>
+
+#define MAX_BUFFER_SIZE 90
+#define MAX_FIELDS_NUMBER 25
+#define FALSE 0
+#define TRUE  1
+#define UNDEFINED 3
+ 
+ 
+enum minmea_sentence_id {
+    MINMEA_INVALID = -1,
+    MINMEA_UNKNOWN = 0,
+    NMEA_SENTENCE_RMC,
+    NMEA_SENTENCE_GGA,
+    NMEA_SENTENCE_VTG,
+};
+ 
+struct minmea_coord {
+    long integer;
+    long decimal;
+    uint8_t cardeal;
+};
+ 
+struct minmea_date {
+    int day;
+    int month;
+    int year;
+};
+ 
+struct minmea_time {
+    int hours;
+    int minutes;
+    int seconds;
+    int microseconds;
+};
+ 
+struct minmea_sentence {
+    struct minmea_time time;
+    struct minmea_coord latitude;
+    struct minmea_coord longitude;
+    struct minmea_date date;
+     
+    bool valid;
+    int altitude;
+    int speed;
+    int fix_quality;
+    int num_of_satellites_tracked;
+ 
+};
+
+bool MAXM8_NMEA_Putc(char uart_char, char *uart_buffer_prt);
+bool MAXM8_NMEA_Parser(struct minmea_sentence *gps_frame,int *isPositionDataValid,char *uart_buffer_prt);
+
+#endif // MAXM8_H_INCLUDED
\ No newline at end of file
diff -r d323dd088ba2 -r fc06d50dacef main.cpp
--- a/main.cpp	Fri Nov 22 16:00:04 2019 +0000
+++ b/main.cpp	Thu Dec 19 10:52:48 2019 +0000
@@ -5,6 +5,14 @@
 
 #include "mbed.h"
 #include "platform/mbed_thread.h"
+#include "USBSerial.h"
+#include "GPS/MAXM8.h"
+
+#include "stdbool.h"
+#include "string.h"
+#include "stdio.h"
+#include "stdlib.h"
+
 
 
 // Blinking rate in milliseconds
@@ -12,12 +20,36 @@
 
 
 int main()
-{
-    // Initialise the digital pin LED1 as an output
-    DigitalOut led(LED1);
+{   
+    USBSerial serial;
+    Serial gps(P0_23,P0_20,9600);
+    
+    char buffer[MAX_BUFFER_SIZE];
+    bool result;
+    char c;
+    struct minmea_sentence nmeaStruct;
+    int *isPositionDataValid;
+    result=FALSE;
+    
+    
+    
 
-    while (true) {
-        led = !led;
-        thread_sleep_for(BLINKING_RATE_MS);
+    while(result==FALSE){
+            if(gps.readable()){
+            serial.putc(gps.getc());
+            //MAXM8_NMEA_Putc(gps.getc(),buffer);
+            }
     }
+    serial.printf("%s",buffer);
+    
+    MAXM8_NMEA_Parser(&nmeaStruct,isPositionDataValid,buffer);
+   
+    serial.printf("Latitude Integer: %ld",nmeaStruct.latitude.integer);
+    
+    while(1);
 }
+
+
+void Init (){
+    serial.printf("Init_State");
+