The official code that runs on the FRDM board for the chlorine sensor.

Dependencies:   MBed_Adafruit-GPS-Library SDFileSystem mbed GSM_Library

Fork of DCS by Brandon Crofts

Revision:
8:6b4a6bcd7694
Parent:
1:8614e190908b
Child:
10:02e2f8400e87
diff -r 8614e190908b -r 6b4a6bcd7694 Sensor.cpp
--- a/Sensor.cpp	Fri Mar 06 22:36:44 2015 +0000
+++ b/Sensor.cpp	Tue Mar 24 17:04:31 2015 +0000
@@ -5,10 +5,18 @@
 #include "SDFileSystem.h"
 #include "QAM.h"
 #include "param.h"
+#include "GSMLibrary.h"
+#include "stdlib.h"
 
 DigitalOut led_red(LED_RED);
 Serial pc(USBTX, USBRX);
 Timer t;
+Timer z;
+bool run = 0;
+Serial gsm(D1,D0);
+
+char message[5000];
+char num[10];
 
 /**************************************************
  **          SD FILE SYSTEM                       **
@@ -80,10 +88,14 @@
 int main () {
     
     pc.baud(115200);
+    gsm.baud(115200);
     pc.printf("hello\r\n");
     
+    //GSM INITIALIZATION ///////////////////////////////
+    gsm_initialize();
+    
     // GPS INITIALIZATION //////////////////////////////
-    gps_Serial = new Serial(D1,D0);
+    gps_Serial = new Serial(PTC4,PTC3); ////Serial gsm(D1,D0);
     Adafruit_GPS myGPS(gps_Serial);
     char c;
     myGPS.begin(9600);
@@ -100,21 +112,20 @@
     float filteredLongRef = 0;
     float filteredShortRef = 0;
     
+    void gsm_initialize();
+    
     sample_tick.attach(&tick, 0.0001);
     
     t.start();
+    z.start();
+    
+    int buffer = 0;
     
     while(1){
         
-        if(takeSample){ //3.46 us per loop
+        if(takeSample  && z.read_ms()>1000){
             
-            takeSample = false;
             dac0 = sinWave[sinIndex];
-            sinIndex++;
-            if((sinIndex+1) > sinRes){
-                sinIndex = 0;
-            }
-        
             
             lon = AnLong.read();
             lonRef = AnRefLong.read();
@@ -132,17 +143,31 @@
             sRefSI[sampleIndex] = shorRef*I;
             sRefSQ[sampleIndex] = shorRef*Q;
             
+            takeSample = false;
+            
+            sinIndex++;
+            if((sinIndex+1) > sinRes){
+                sinIndex = 0;
+            }
+            
+            
             sampleIndex++;
             if(sampleIndex+1 > SAMPLE_LENGTH){
                 sampleIndex--;
             }
+            
+        
         }
         
         
-        
-        if(sampleIndex+2 > SAMPLE_LENGTH){ //0.50 seconds
+
+        if(t.read_ms()>1000){//sampleIndex+2 > SAMPLE_LENGTH){ //0.50 seconds
             
+            run = 1;
+            z.reset();
             sampleIndex = 0;
+            
+            gsm_tick();
             filteredLong = QAM(sLI, sLQ, &pc);
             filteredLongRef = QAM(sRefLI, sRefLQ, &pc);
             filteredShort = QAM(sSI, sSQ, &pc);
@@ -157,65 +182,72 @@
         }
 
 
-        if(t.read_ms()>1000){
+        if(run){
             led_red = !led_red;
-            
-            pc.printf("Long = %f\r\n", filteredLong);
-            pc.printf("LongRef = %f\r\n", filteredLongRef);
-            pc.printf("Short = %f\r\n", filteredShort);
-            pc.printf("ShortRef = %f\r\n", filteredShortRef);
-            pc.printf("Time: %d:%d:%d \r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
+            run = 0;
             
             
-            if (myGPS.fix) pc.printf("Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+            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);
+            
+            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");
             
+            
+            
             fp = fopen("/sd/data.txt", "w");
             if (fp != NULL){
                 
-                fprintf(fp, "Long = %f\r\n", filteredLong);
-                fprintf(fp, "LongRef = %f\r\n", filteredLongRef);
-                fprintf(fp, "Short = %f\r\n", filteredShort);
-                fprintf(fp, "ShortRef = %f\r\n", filteredShortRef);
-                fprintf(fp, "Time: %d:%d:%d \r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
-                if (myGPS.fix) fprintf(fp, "Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                else           fprintf(fp, "No GPS fix\r\n");
+                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, 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);    
             }
             
+            snprintf(num,10,"%f, ",filteredLong);
+            strcat(message, num);
+            snprintf(num,10,"%f, ",filteredLongRef);
+            strcat(message, num);
+            snprintf(num,10,"%f, ",filteredShort);
+            strcat(message, num);
+            snprintf(num,10,"%f = ",filteredShortRef);
+            strcat(message, num);
+            
+            snprintf(num,10,"%d:%d:%d = ", myGPS.hour, myGPS.minute, myGPS.seconds);
+            strcat(message, num);
+            if (myGPS.fix){ 
+                snprintf(num,10,"%5.2f%c, %5.2f%c. ", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+                strcat(message, num);
+            }
+            else strcat(message, "NO_GPS_FIX. ");
+            
+            //pc.printf("%s\r\n", message);
+            
+            if(gsm_ready()){
+                gsm_send_sms(message); 
+                memset(message, 0, 5000);
+                buffer = 0; 
+            }else{
+                buffer++;
+                if(buffer > 12){
+                    buffer = 0;
+                    memset(message, 0, 5000);    
+                }
+            }
+            
             t.reset();
         }
         
-        
-        
-        
-        
-        /*
-        if (sampleIndex+2 > SAMPLE_LENGTH) { // 0.25 seconds
-            
-            sampleIndex = 0;
-            pc.printf("Time: %d:%d:%d \r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
-            fp = fopen("/sd/data.txt", "w");
-            if (fp != NULL){
-                fprintf(fp,"Time: %d:%d:%d.%u \r\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
-                fclose(fp);
-            }
-
-            if (myGPS.fix) {
-                pc.printf("Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                led_red = !led_red;
-                fp = fopen("/sd/data.txt", "w");
-                if (fp != NULL){
-                    fprintf(fp,"Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                    fclose(fp);
-                }
-            }else{
-                fprintf(fp,"no gps fix\r\n");
-                fclose(fp);
-            }    
-        }
-        */
     }
 }
\ No newline at end of file