uses pushing box to write to google spreadsheets

Dependencies:   GSM_PUSHING_BOX_STATE_MACHINE MBed_Adafruit-GPS-Library SDFileSystem mbed

Fork of DCS by DCS_TEAM

Revision:
19:404594768414
Parent:
14:97611177509b
--- a/Sensor.cpp	Tue Apr 28 03:04:48 2015 +0000
+++ b/Sensor.cpp	Wed Oct 21 19:44:47 2015 +0000
@@ -7,21 +7,20 @@
 #include "param.h"
 #include "GSMLibrary.h"
 #include "stdlib.h"
+#include "GPRSInterface.h"
 
 DigitalOut led_red(LED_RED);
 Serial pc(USBTX, USBRX);
 Timer t;
 bool run = 0;
 bool fil = 0;
-Serial gsm(D1,D0);
-
 
 /**************************************************
  **          SD FILE SYSTEM                       **
  **************************************************/
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
-FILE *fp;
-
+FILE *fpLog;
+FILE *fpData;
 /**************************************************
  **          GPS                                 **
  **************************************************/
@@ -31,12 +30,13 @@
  **          SENSOR INPUTS                       **
  **************************************************/
 AnalogIn AnLong(A0);
-AnalogIn AnShort(A1);
 AnalogIn AnRefLong(A2);
-AnalogIn AnRefShort(A3);
 Ticker sample_tick;
 bool takeSample = false;
-void tick(){takeSample = true;}
+void tick()
+{
+    takeSample = true;
+}
 
 /**************************************************
  **          SIN OUTPUT                          **
@@ -52,12 +52,8 @@
  **************************************************/
 float sLQ[SAMPLE_LENGTH] = {};
 float sLI[SAMPLE_LENGTH] = {};
-float sSQ[SAMPLE_LENGTH] = {};
-float sSI[SAMPLE_LENGTH] = {};
 float sRefLQ[SAMPLE_LENGTH] = {};
 float sRefLI[SAMPLE_LENGTH] = {};
-float sRefSQ[SAMPLE_LENGTH] = {};
-float sRefSI[SAMPLE_LENGTH] = {};
 
 float Iarray[SAMPLE_LENGTH] = {};
 float Qarray[SAMPLE_LENGTH] = {};
@@ -66,32 +62,32 @@
 float Q = 0;
 float lon = 0;
 float lonRef = 0;
-float shor = 0;
-float shorRef = 0;
+
+/*Global Variables*/
+extern GPRSInterface eth;
 
-void buildIQ(){
-    for(int i = 0; i < SAMPLE_LENGTH; i++){
+/*End Global Variables*/
+void buildIQ()
+{
+    for(int i = 0; i < SAMPLE_LENGTH; i++) {
         Iarray[i] = cos(2*PI*CARRIER_FREQ*i*TIME_CONST);
         Qarray[i] = -sin(2*PI*CARRIER_FREQ*i*TIME_CONST);
     }
 }
 
-void create_sinWave(){
+void create_sinWave()
+{
     int i = 0;
-    for(i = 0; i < SIN_LENGTH; i++){
+    for(i = 0; i < SIN_LENGTH; i++) {
         sinWave[i] = 0.25 * sin(2.0*PI*i/sinRes) + 0.75;
     }
 }
 
-int main () {
-    
-    pc.baud(115200);
-    gsm.baud(115200);
+int main ()
+{   
     pc.printf("hello\r\n");
-    
-    //GSM INITIALIZATION ///////////////////////////////
-    gsm_initialize();
-    
+    //Initilialize the GSM
+    //gsm_initialize();
     // GPS INITIALIZATION //////////////////////////////
     gps_Serial = new Serial(PTC4,PTC3); ////Serial gsm(D1,D0);
     Adafruit_GPS myGPS(gps_Serial);
@@ -101,129 +97,106 @@
     myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
     myGPS.sendCommand(PGCMD_ANTENNA);
     ////////////////////////////////////////////////////
-    
+
     buildIQ();
     create_sinWave();
-    
+
     float filteredLong = 0;
-    float filteredShort = 0;
     float filteredLongRef = 0;
-    float filteredShortRef = 0;
-    
-    fp = fopen("/sd/data.txt", "w");
-    if (fp != NULL){
-        fprintf(fp, "--------------- DCS ------------------");
+
+    fpData = fopen("/sd/data.txt", "a");
+    if (fpData != NULL) {
+        fprintf(fpData, "--------------- DCS ------------------");
     }
-    
-    
+
+
     void gsm_initialize();
-    
+
     sample_tick.attach(&tick, 0.0001);
-    
+
     t.start();
-    
-    while(1){
-        
-        if(takeSample){
-            
+
+    while(1) {
+
+        if(takeSample) {
+
             dac0 = sinWave[sinIndex];
-            
+
             lon = AnLong.read();
             lonRef = AnRefLong.read();
-            shor = AnShort.read();
-            shorRef = AnRefShort.read();
-            
+
             I = Iarray[sampleIndex];
             Q = Qarray[sampleIndex];
             sLI[sampleIndex] = lon*I;
             sLQ[sampleIndex] = lon*Q;
-            sSI[sampleIndex] = shor*I;
-            sSQ[sampleIndex] = shor*Q;
             sRefLI[sampleIndex] = lonRef*I;
             sRefLQ[sampleIndex] = lonRef*Q;
-            sRefSI[sampleIndex] = shorRef*I;
-            sRefSQ[sampleIndex] = shorRef*Q;
-            
+
             takeSample = false;
-            
+
             sinIndex++;
-            if((sinIndex+1) > SIN_LENGTH){
+            if((sinIndex+1) > SIN_LENGTH) {
                 sinIndex = 0;
             }
-            
-            
+
+
             sampleIndex++;
-            if(sampleIndex+1 > SAMPLE_LENGTH){
+            if(sampleIndex+1 > SAMPLE_LENGTH) {
                 fil = 1;
             }
-            
-        
+
+
         }
-        
-        
 
-        if(fil==1){
-            
+        if(fil==1) {
+
             fil = 0;
             run = 1;
-            
+
             sampleIndex = 0;
-            
+
             gsm_tick();
-            
-            filteredLong = 10*QAM(sLI, sLQ);
+
+            filteredLong = 15*QAM(sLI, sLQ);
             filteredLongRef = QAM(sRefLI, sRefLQ);
-            filteredShort = 25*QAM(sSI, sSQ);
-            filteredShortRef = QAM(sRefSI, sRefSQ);
-            
+
             gsm_tick();
-            
-        }  
-        
+
+        }
         c = myGPS.read();
         if ( myGPS.newNMEAreceived() ) {
             if ( !myGPS.parse(myGPS.lastNMEA()) ) {
-                continue;
+                //continue;
             }
         }
 
-
-        if(run){
+        if(run) {
             led_red = !led_red;
             run = 0;
-            
+
             pc.printf("%f, ", filteredLong);
             pc.printf("%f, ", filteredLongRef);
-            pc.printf("%f, ", filteredShort);
-            pc.printf("%f\r\n", filteredShortRef);
-            pc.printf("%f, ", filteredLong/filteredLongRef);
-            pc.printf("%f\r\n", filteredShort/filteredShortRef);
-            pc.printf("%d:%d:%d \r\n", myGPS.hour+6, myGPS.minute, myGPS.seconds);
-            
+            pc.printf("%f\r\n", filteredLong/filteredLongRef);
+            pc.printf("%02d:%02d:%02d \r\n", myGPS.hour-6, myGPS.minute, myGPS.seconds);
+
             if (myGPS.fix) pc.printf("%5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
             else           pc.printf("No GPS fix\r\n");
             pc.printf("--------------------------------\r\n");
+
+            fpData = fopen("/sd/data.txt", "a");
+            if (fpData != NULL) {
+                fprintf(fpData, "%f, ", filteredLong);
+                fprintf(fpData, "%f\r\n", filteredLongRef);
+                fprintf(fpData, "%02d:%02d:%02d\r\n", myGPS.hour-6, myGPS.minute, myGPS.seconds);
+                if (myGPS.fix) fprintf(fpData, "%5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+                fclose(fpData);
+            }
+            if(myGPS.fix)
+                gsm_send_data(filteredLong, filteredLongRef, myGPS.hour-6, myGPS.minute, myGPS.seconds, myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+            else
+                gsm_send_data(filteredLong, filteredLongRef,myGPS.hour-6, myGPS.minute, myGPS.seconds, 0, 0, 0, 0);
             
-            fp = fopen("/sd/data.txt", "a");
-            if (fp != NULL){
-                
-                fprintf(fp, "%f, ", filteredLong);
-                fprintf(fp, "%f, ", filteredLongRef);
-                fprintf(fp, "%f, ", filteredShort);
-                fprintf(fp, "%f\r\n", filteredShortRef);
-                fprintf(fp, "%d:%d:%d\r\n", myGPS.hour+6, myGPS.minute, myGPS.seconds);
-                if (myGPS.fix) fprintf(fp, "%5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                else           fprintf(fp, "No_GPS_fix\r\n");
-                
-                fclose(fp);    
-            }
-        
-            if(myGPS.fix)
-                gsm_send_data(filteredLong, filteredLongRef, filteredShort, filteredShortRef, myGPS.hour+6, myGPS.minute, myGPS.seconds, myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-            else
-                gsm_send_data(filteredLong, filteredLongRef, filteredShort, filteredShortRef, 0, 0, 0, 0, 0, 0, 0);
+        }
 
-        }
-        
     }
 }
\ No newline at end of file