![](/media/cache/group/SAM_2404.JPG.50x50_q85.jpg)
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
Diff: Sensor.cpp
- Revision:
- 14:97611177509b
- Parent:
- 10:02e2f8400e87
--- a/Sensor.cpp Sun Apr 12 03:09:47 2015 +0000 +++ b/Sensor.cpp Tue Apr 14 04:05:59 2015 +0000 @@ -11,12 +11,10 @@ DigitalOut led_red(LED_RED); Serial pc(USBTX, USBRX); Timer t; -Timer z; bool run = 0; +bool fil = 0; Serial gsm(D1,D0); -char message[MAX_MSG_SIZE];//MSG_SIZE located at GSMLibrary.h -char num[10]; /************************************************** ** SD FILE SYSTEM ** @@ -80,7 +78,7 @@ void create_sinWave(){ int i = 0; - for(i = 0; i < sinRes; i++){ + for(i = 0; i < SIN_LENGTH; i++){ sinWave[i] = 0.25 * sin(2.0*PI*i/sinRes) + 0.75; } } @@ -112,18 +110,21 @@ float filteredLongRef = 0; float filteredShortRef = 0; + fp = fopen("/sd/data.txt", "w"); + if (fp != NULL){ + fprintf(fp, "--------------- DCS ------------------"); + } + + void gsm_initialize(); sample_tick.attach(&tick, 0.0001); t.start(); - z.start(); - - int buffer = 0; while(1){ - if(takeSample && z.read_ms()>1000){ + if(takeSample){ dac0 = sinWave[sinIndex]; @@ -146,14 +147,14 @@ takeSample = false; sinIndex++; - if((sinIndex+1) > sinRes){ + if((sinIndex+1) > SIN_LENGTH){ sinIndex = 0; } sampleIndex++; if(sampleIndex+1 > SAMPLE_LENGTH){ - sampleIndex--; + fil = 1; } @@ -161,17 +162,22 @@ - if(t.read_ms()>1000){//sampleIndex+2 > SAMPLE_LENGTH){ //0.50 seconds + if(fil==1){ + fil = 0; run = 1; - z.reset(); + sampleIndex = 0; gsm_tick(); - filteredLong = QAM(sLI, sLQ, &pc); - filteredLongRef = QAM(sRefLI, sRefLQ, &pc); - filteredShort = QAM(sSI, sSQ, &pc); - filteredShortRef = QAM(sRefSI, sRefSQ, &pc); + + filteredLong = 10*QAM(sLI, sLQ); + filteredLongRef = QAM(sRefLI, sRefLQ); + filteredShort = 25*QAM(sSI, sSQ); + filteredShortRef = QAM(sRefSI, sRefSQ); + + gsm_tick(); + } c = myGPS.read(); @@ -186,67 +192,37 @@ 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("%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"); + 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, myGPS.minute, myGPS.seconds); + 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); } - - 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, MAX_MSG_SIZE); - buffer = 0; - }else{ - buffer++; //if msgsize is 150, then 150 * 6 = 900 (max SMS length) - if(buffer >= 6){ //Thus only allow 6 data points to be sent at once - buffer = 0; - memset(message, 0, MAX_MSG_SIZE); - } - } - - t.reset(); + + 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); + } }