x

Dependencies:   gnss battery-charger-bq24295

Files at this revision

API Documentation at this revision

Comitter:
atwik
Date:
Mon Apr 13 05:27:49 2020 +0000
Parent:
6:4d61a0f32573
Commit message:
\

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
sd-driver.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 4d61a0f32573 -r 8ba0130944d6 main.cpp
--- a/main.cpp	Fri Feb 23 18:28:32 2018 +0500
+++ b/main.cpp	Mon Apr 13 05:27:49 2020 +0000
@@ -18,10 +18,23 @@
 #include "gnss.h"
 #include "battery_charger_bq24295.h"
 #include "onboard_modem_api.h"
+#include <SDBlockDevice.h>
+#include <FATFileSystem.h>
+
+#include <string>
+#include <iostream>
+
+using namespace std;
+using std::string;
+
+#define CHECK_TALKER(s) ((buffer[3] == s[0]) && (buffer[4] == s[1]) && (buffer[5] == s[2]))
 
 // Set the minimum input voltage limit for the BQ24295 to 3.8 Volt
 #define MIN_INPUT_VOLTAGE_LIMIT_MV  3880
 
+SDBlockDevice sd(PE_6, PE_5, PE_2, PE_11);
+FATFileSystem fs("sd");
+
 // User LEDs
 DigitalOut ledRed(LED1, 1);
 DigitalOut ledGreen(LED2, 1);
@@ -71,15 +84,41 @@
     }
 }
 
-/*
-** Out of the Box Demo for C030 variants
-** 
-** Sets the modem then    
-*/
+void SDCardWriter(int time)///////////////////////////////////////////////////////////////////////////////
+{
+    printf("\nWaiting for SD Card initialization\n\n");
+    mkdir("/sd/Amit", 0777);
+    FILE *fp = fopen("/sd/Amit/sdBlockDeviceTest.txt", "a");
+    if(fp == NULL) {
+        printf("\nCould not open file for write\n\n");
+        return  ;
+    }
+    
+    fprintf(fp, "\nGNSS Time: %d", time);
+    printf("\nGNSS Time Recorded\n\n");
+    fclose(fp);
+}////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 int main()
 {
-    printf("u-blox C030 Out-of-the-Box Demo\n\r");
+    printf("\nu-blox C030\n");
+    
+    int count = 30;
+    int i = 1;
+    
+    /////////////////////////////////////////////////////////////////////////////////////SD TEST
+    string timestring = "test";
+    sd.init();
+    fs.mount(&sd);
+    SDCardWriter(i);
+    //fs.unmount();
+    //sd.deinit();
+    //////////////////////////////////////////////////////////////////////////////////////SD TEST
+    
+    GnssSerial gnss;
+    int gnssReturnCode;
+    int length;
+    char buffer[256];
 
     // GNSS initialisation
     if(gnss.init()) {
@@ -114,7 +153,7 @@
     ledGreen = 1;
     ledBlue = 1;
     
-    printf("u-blox C030 Out-of-the-Box Demo: LED loop\n\r");
+    printf("u-blox C030\n\r");
     
     //Main loop
     while(1) {
@@ -124,6 +163,78 @@
         ledBlue = ledRed;
         ledRed = ledGreen;
         ledGreen = carry;
+        
+        //Amittttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
+        
+        SDCardWriter(i);//////////////////////////////////////////////////////////////////////////
+        
+        if(i >= count)
+        {
+            fs.unmount();
+            sd.deinit();
+        }
+        
+        i++;
+        
+        gnssReturnCode = gnss.getMessage(buffer, sizeof(buffer));
+        if (gnssReturnCode > 0) {
+                ledGreen = 0;
+                ledBlue = 1;
+                ledRed = 1;
+                length = LENGTH(gnssReturnCode);
+ 
+                printf("NMEA: %.*s\n", length - 2, buffer);
+ 
+                if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6)) {
+                    // Talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GNSS
+                    if ((buffer[0] == '$') || buffer[1] == 'G') {
+                      if (CHECK_TALKER("GLL")) {
+                            double latitude = 0, longitude = 0;
+                            char ch;
+ 
+                            if (gnss.getNmeaAngle(1, buffer, length, latitude) && 
+                                gnss.getNmeaAngle(3, buffer, length, longitude) && 
+                                gnss.getNmeaItem(6, buffer, length, ch) && (ch == 'A')) {
+                                ledBlue = 0;
+                                ledRed = 0;
+                                ledGreen = 0;
+ 
+                                printf("\nGNSS: location is %.5f %.5f.\n\n", latitude, longitude);
+                                printf("I am here: https://maps.google.com/?q=%.5f,%.5f\n\n",
+                                       latitude, longitude); 
+                            }
+                        } else if (CHECK_TALKER("GGA") || CHECK_TALKER("GNS")) {
+                            double altitude = 0; 
+                            const char *timeString = NULL;
+ 
+                            // Altitude
+                            if (gnss.getNmeaItem(9, buffer, length, altitude)) {
+                                printf("\nGNSS: altitude is %.1f m.\n", altitude); 
+                            }
+ 
+                            // Time
+                            timeString = gnss.findNmeaItemPos(1, buffer, buffer + length);
+                            if (timeString != NULL) {
+                                ledBlue = 0;
+                                ledRed = 1;
+                                ledGreen = 1;
+ 
+                                printf("\nGNSS: time is %.6s.\n\n", timeString);
+                                
+                            }
+                        } else if (CHECK_TALKER("VTG")) {
+                            double speed = 0; 
+ 
+                            // Speed
+                            if (gnss.getNmeaItem(7, buffer, length, speed)) {
+                                printf("\nGNSS: speed is %.1f km/h.\n\n", speed);
+                            }
+                        }
+                    }
+                }
+            }
+        
+        
     }
 }
 
diff -r 4d61a0f32573 -r 8ba0130944d6 sd-driver.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sd-driver.lib	Mon Apr 13 05:27:49 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/coverxit/code/sd-driver/#0df98d0fd2a5