Ftpget merged with the main code
Dependencies: SDFileSystem dspmodified mbed
Revision 29:4f2b3d68aa6b, committed 2015-06-28
- Comitter:
- lalitkumar
- Date:
- Sun Jun 28 13:39:02 2015 +0000
- Parent:
- 28:9d2635dcb8ff
- Commit message:
- minimal version, start bug fixing from here
Changed in this revision
merged_code.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9d2635dcb8ff -r 4f2b3d68aa6b merged_code.cpp --- a/merged_code.cpp Sun Jun 28 06:05:32 2015 +0000 +++ b/merged_code.cpp Sun Jun 28 13:39:02 2015 +0000 @@ -124,9 +124,9 @@ } 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"); + pc.printf("\r\nclock updated\r\n"); sprintf(timestamp,"%.49s",response); - //pc.printf("%s",timestamp); //copies response to timestamp for further processing + pc.printf("%s",timestamp); //copies response to timestamp for further processing } if(clk_flag == 3) { @@ -298,7 +298,7 @@ if((minute!=minuteold)||(second!=secondold)) { sprintf(timestampold,timestamp); - //pc.printf("\r\nold time stamp is%s\r\n",timestampold); + pc.printf("stage 1"); minuteold=minute; secondold=second; sprintf(main_dir,"/sd/%s",sitename); @@ -310,10 +310,12 @@ sprintf(ftpputpathname,"%s/%02d/%02d/%02d/%02d",module_name,year,month,date,hour); // For FTPPUTPATHNAME feature //pc.printf("Ftpputpathname is %s\r\n",ftpputpathname); // For FTPPUTPATHNAME feature gsmerr=0; + pc.printf("stage 2"); mkdir(main_dir,0777); mkdir(month_dir,0777); mkdir(date_dir,0777); mkdir(hour_dir,0777); + pc.printf("stage 3"); } else //timestamp same as previous { @@ -537,6 +539,7 @@ void store() { GetFileDir(); + pc.printf("getfiledir completed"); // AC Sample storage sprintf(filenameAC,"%sAC.txt",filename); sprintf(pathAC,"%sAC.txt",filepath); @@ -545,12 +548,12 @@ if(fp == NULL) { - //pc.printf("Could not open file for write\n\r"); + pc.printf("Could not open file for write\n\r"); //reset_mod(); } else { - //pc.printf("attempting to save file\n\r"); + pc.printf("attempting to save file\n\r"); for(int k=0; k<dataLength; k++) { fprintf(fp, "%d.", ACdata[k]); @@ -561,7 +564,7 @@ // DC Sample storage sprintf(filenameDC,"%sDC.txt",filename); sprintf(pathDC,"%sDC.txt",filepath); - //pc.printf("\r\nFilename-DC\t%s", pathDC); + pc.printf("\r\nFilename-DC\t%s", pathDC); fp = fopen(pathDC, "w"); if(fp == NULL) { @@ -878,143 +881,6 @@ return; } - -//--------------------------------------------------------------------------------------------------// -// FTP GET FUNCTION // -//--------------------------------------------------------------------------------------------------// - -void downloadFTP() - -{ - int x = 0; - char command3[40]; - - wait(10); - ftp_connect(); - - sendATcommand("AT+FTPGETNAME=\"Final.txt\"", "OK", 5,0); - //sendATcommand("AT+FTPGETPATH=\"/\"", "OK", 5,0); - sprintf(command3,"%s/%s/\"", "AT+FTPGETPATH=\"", module_name); - sendATcommand(command3,"OK",5,0); - - if (sendATcommand("AT+FTPGET=1\r", "+FTPGET:1,1", 20,0) == 1) - { - for(int ftp_get_attempt=0; ftp_get_attempt<2; ftp_get_attempt++) { - if (sendATcommand("AT+FTPGET=2,300", "+FTPGET:2,", 10,0) == 1) - { - int previous = time(NULL); - // this loop waits for the answer - do - { - if(gsm.readable() == 1) - { - // if there are data in the UART input buffer, reads it and checks for the asnwer - incoming_data[x] = gsm.getc(); - x++; - } - - // Waits for the asnwer with time out - }while((time(NULL) - previous) < 5); - - pc.printf("Incoming_Data is %s\r\n",incoming_data); - sprintf(dest,"%s",incoming_data); - pc.printf("\r\n Download finished"); - wait(15); - - char *token; - token = strtok(dest, s); - token = strtok(NULL,s); - pc.printf("\r\nToken is %s\r\n",token); - - //NO FTGET REQUIRED Case : 0 - if(atoi(token)==NULL) - { - return; - } - //RESET THE MODULE Case : 1 - else if(atoi(token)==1) - { - pc.printf("\r\nModule reset\r\n"); - reset_mod(); - - } - //Request Particular Path File Case : 2 - else if(atoi(token) == 2) - { - token = strtok(NULL,s); - sprintf(ftpget,"%s",token); - pc.printf("Ftpget is %s\r\n",ftpget); - token = strtok(NULL,s); - sprintf(ftpget1,"%s",token); - pc.printf("Ftpget1 is %s\r\n",ftpget1); - token = strtok(NULL,s); - sprintf(ftpget2,"%s",token); - pc.printf("Ftpget2 is %s\r\n",ftpget2); - ftp_connect(); - wait(5); - ftp_put(1); - } - //Request Timestamp File Case : 3 - else if(atoi(token)==3) - { - pc.printf("\r\n Timestamp Sending\r\n"); - token = strtok(NULL,s); - sprintf(ftpget,"%s",token); - pc.printf("Ftpget is %s\r\n",ftpget); - ftp_connect(); - wait(5); - ftp_put(2); - } - // Delete the particular Folder Case : 4 - /*else if(atoi(token) ==4) - { - //FOR DELETING THE SELECTED FILE - char removefile[100]=""; - token = strtok(NULL,s); - sprintf(removefile,"%s",token); - pc.printf("Folder to be removed is %s",removefile); - - if(removefile==NULL) - { - pc.printf("\r\n NULL Condition\r\n"); - return; - } - else - { - pc.printf("\r\n Deleting requested file\r\n"); - do_remove(removefile); - pc.printf("\r\n File Deleted\r\n"); - } - }*/ - /* - else if(atoi(token)==5) - { - pc.printf("\r\n Remote Configuration\r\n"); - } - // wait(5); - - FILE *fp1 = fopen("/sd/Query.txt","w"); - fprintf(fp1,"%s",ftpget); - fclose(fp1); - */ - - } - else - { - pc.printf("Error getting the file"); - } - - ftp_get_attempt=6; - } - - } - else - { - return; - } - -} - void FTP_Fun() { /*tid6 = osThreadGetId(); @@ -1045,7 +911,7 @@ reset_mod(); //COA for gsm init failure TBD } int old_hour=100,loopcount=0; - sendATcommand("AT+CLTS=1\r", "OK", 15,2); + sendATcommand("AT+CLTS=1\r", "OK", 20,2); //wait(10); GetFileDir(); pc.printf("\r\ngetfiledir complete\r\n"); @@ -1078,7 +944,7 @@ sampling(); store(); FTP_Fun(); - //downloadFTP(); // For testing purpose + loopcount++; if (old_hour!=100 && hour!=old_hour && hour<24) { pc.printf("\r\nhour changed"); @@ -1088,7 +954,6 @@ sprintf(pathfft,"%s",timestamppath_old); ftp_put(2); } - downloadFTP(); // For FTPGET Function } pc.printf("\r\n Complete Done"); old_hour=hour; @@ -1102,43 +967,5 @@ reset_mod(); } } - //wait(10); } -} - - - - - - - - - -//--------------------------------------------------------------------------------------------------// -// Remove File from Directory // -//--------------------------------------------------------------------------------------------------// - -/*void do_remove(const char *fsrc) -{ - pc.printf("\r\n Deleting... \r\n"); - DIR *d = opendir(fsrc); - if(d==NULL) - { - pc.printf("\r\n NULL Condition\r\n"); - return; - } - else - { - struct dirent *p; - char path[100] = {0}; - while((p = readdir(d)) != NULL) - { - strcpy(path, fsrc); - strcat(path, "/"); - strcat(path, p->d_name); - remove(path); - } - } - closedir(d); - remove(fsrc); -}*/ \ No newline at end of file +} \ No newline at end of file