Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem dspmodified mbed
Revision 25:236d7a498f38, committed 2015-06-25
- Comitter:
- lalitkumar
- Date:
- Thu Jun 25 13:44:04 2015 +0000
- Parent:
- 24:45bcaa34bcaa
- Child:
- 26:256bf8284cb6
- Commit message:
- added csq store along with timestamp, improved sendatcommand to accomodate csq
Changed in this revision
| merged_code.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/merged_code.cpp Thu Jun 25 07:18:45 2015 +0000
+++ b/merged_code.cpp Thu Jun 25 13:44:04 2015 +0000
@@ -26,6 +26,8 @@
char filename[100] = "";
char filepath[100] = "";
char timestamp[20]="";
+char csq[20]="";
+char csq_value[2]="";
char time_stamp[20]="";
char timestampold[20]="";
char main_dir[100] ="";
@@ -80,14 +82,10 @@
NVIC_SystemReset();
}
-
-
-
-
//--------------------------------------------------------------------------------------------------//
// Send AT Command (1 response with clk variable) //
//--------------------------------------------------------------------------------------------------//
-int sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout, int clk_flag)
+int sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout, int clk_flag) //clk_flg 0: normal, clk_flg 1: store response in timestamp, clk_flg 2: ensure timeout, clk_flg 3: store response in CSQ
{
int grs=0;
int answer=0; //x=0 and answer=0, if not put, AT+CCLK?\r is not executed
@@ -124,11 +122,17 @@
}
} while((answer !=1) && ((time(NULL) - previous) < timeout)); // Waits for the asnwer with time out
if(clk_flag == 1)
- {
- //pc.printf("\r\nclock updated\r\n");
- sprintf(timestamp,response);
- pc.printf("%s",timestamp); //copies response to timestamp for further processing
- }
+ {
+ //pc.printf("\r\nclock updated\r\n");
+ sprintf(timestamp,response);
+ //pc.printf("%s",timestamp); //copies response to timestamp for further processing
+ }
+ if(clk_flag == 3)
+ {
+ //pc.printf("\r\ncsq updated\r\n");
+ sprintf(csq,response);
+ //pc.printf("%s",csq); //copies response to csq for further processing
+ }
//pc.printf("\r\nanswer %d\r\n",answer);
return answer;
}
@@ -240,23 +244,36 @@
return 0 ;
}
//--------------------------------------------------------------------------------------------------//
-// Getting Timestamp Function //
+// Getting Timestamp & CSQ Function //
//--------------------------------------------------------------------------------------------------//
-void GetTime()
+void GetTime_CSQ()
{
- sendATcommand("AT+CCLK?\r", "OK", 5,1);
- //sprintf(response,timestamp);
- int x=20;
- year = 10*(timestamp[x+1]-48) + (timestamp[x+2]-48);
- month = (timestamp[x+4]-48)*10+(timestamp[x+5]-48);
- date = (timestamp[x+7]-48)*10+(timestamp[x+8]-48);
- hour = (timestamp[x+10]-48)*10+(timestamp[x+11]-48);
- minute = (timestamp[x+13]-48)*10+(timestamp[x+14]-48);
- second = (timestamp[x+16]-48)*10+(timestamp[x+17]-48);
-
- sprintf(time_stamp,"%02d%02d%02d%02d%02d%02d",year,month,date,hour,minute,second);
+ if(sendATcommand("AT+CCLK?\r", "OK", 10,1)){
+ //sprintf(response,timestamp);
+ int x=20;
+ year = 10*(timestamp[x+1]-48) + (timestamp[x+2]-48);
+ month = (timestamp[x+4]-48)*10+(timestamp[x+5]-48);
+ date = (timestamp[x+7]-48)*10+(timestamp[x+8]-48);
+ hour = (timestamp[x+10]-48)*10+(timestamp[x+11]-48);
+ minute = (timestamp[x+13]-48)*10+(timestamp[x+14]-48);
+ second = (timestamp[x+16]-48)*10+(timestamp[x+17]-48);
+
+ sprintf(time_stamp,"%02d%02d%02d%02d%02d%02d",year,month,date,hour,minute,second);
+ }
//pc.printf("Get time result:%s.....",time_stamp);
+ if(sendATcommand("AT+CSQ","OK",5,3)){
+ if(csq[18]==44){
+ int csq_calc=10*(csq[16]-48)+(csq[17]-48);
+ sprintf(csq_value,"%02d",csq_calc);
+ }
+ else if(csq[17]==44){
+ sprintf(csq_value,"0%c", csq[16]);
+ }
+ else sprintf(csq_value,"NA");
+ }
+ //pc.printf("CSQ: %c %c %s",csq[16],csq[17], csq_value);
+
}
//--------------------------------------------------------------------------------------------------//
@@ -267,11 +284,11 @@
int attempt_cnt=0;
char month_dir[100]="";
char date_dir[100] ="";
- GetTime();
+ GetTime_CSQ();
while(year<15||year>20)
{
- //pc.printf("%d\r\n",year);
- GetTime();
+ pc.printf("%d\r\n",year);
+ GetTime_CSQ();
attempt_cnt++;
if(attempt_cnt>4) break;
}
@@ -280,8 +297,7 @@
if((minute!=minuteold)||(second!=secondold))
{
sprintf(timestampold,timestamp);
-
- pc.printf("\r\nold time stamp is%s\r\n",timestampold);
+ //pc.printf("\r\nold time stamp is%s\r\n",timestampold);
minuteold=minute;
secondold=second;
sprintf(main_dir,"/sd/%s",sitename);
@@ -298,14 +314,14 @@
mkdir(date_dir,0777);
mkdir(hour_dir,0777);
}
- else
+ else //timestamp same as previous
{
sprintf(filepath,"%s/%s%02d%02d%02d%02d%02d%02dErr%03d",hour_dir,sitename,year,month,date,hour,minute,second,gsmerr);
sprintf(filename,"%s%02d%02d%02d%02d%02d%02dErr%03d",sitename,year,month,date,hour,minute,second,gsmerr);
gsmerr++;
}
}
- else
+ else //garbage timestamp
{
sprintf(timestamp,timestampold);
//pc.printf("\r\nTimestamp......%s\r\n",timestamp);
@@ -588,26 +604,6 @@
fprintf(fp, "EOF");
fclose(fp);
}
-//Rushabh: DCD storage deemed unnecessary as avg values stored twice
-/* DC Detect storage
- sprintf(pathDCdetect,"%sData.txt",hour_dir);
- //pc.printf("\r\nFilename-DCD\t%s", pathDCdetect);
- fp = fopen(pathDCdetect, "w");
- if(fp == NULL)
- {
- //pc.printf("Could not open file for write\n\r");
- //reset_mod();
- }
- else
- {
- fprintf(fp, "\r\n%s",time_stamp);
- for(int k=0; k<10; k++)
- {
- fprintf(fp, "\r\nDC-%d",DC_Detect_data[k]);
- }
- fclose(fp);
- }
-*/
//FFT starts
//pc.printf("\r\nfftstart");
@@ -651,6 +647,7 @@
else
{
fprintf(fp, "%s",time_stamp);
+ fprintf(fp, " %s",csq_value);
fprintf(fp, " %d",avg_dc_detect[0]);
fprintf(fp, " %d",avg_dc_detect[1]);
fprintf(fp, " %d",avg_temp[0]);
@@ -1072,7 +1069,9 @@
wait(1);
gsm_rst=1;
wait(8);
- if(gsm_init()==0) reset_mod(); //COA for gsm init failure TBD
+ if(gsm_init()==0){
+ reset_mod(); //COA for gsm init failure TBD
+ }
mkdir("/sd/jas",0777);
int old_hour=100,loopcount=0;
pc.printf("\r\nHelloWorld\r\n");
@@ -1127,5 +1126,4 @@
}
//wait(10);
}
-
}