Sampling, Timestamp storage

Dependencies:   SDFileSystem mbed

Committer:
FahdAnsary
Date:
Sun Nov 16 12:23:22 2014 +0000
Revision:
0:79ed1a99225f
Child:
1:8e8aa4dc0788
code-probably for pune site (Sampling and storing with storing on wrong timestamp)
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
FahdAnsary 0:79ed1a99225f 1 #include "mbed.h"
FahdAnsary 0:79ed1a99225f 2 #include "SDFileSystem.h"
FahdAnsary 0:79ed1a99225f 3
FahdAnsary 0:79ed1a99225f 4 #define freq 1
FahdAnsary 0:79ed1a99225f 5 #define time_interval_sec 30
FahdAnsary 0:79ed1a99225f 6
FahdAnsary 0:79ed1a99225f 7 #define dur_sec 1
FahdAnsary 0:79ed1a99225f 8 Ticker int1;
FahdAnsary 0:79ed1a99225f 9 Ticker int2;
FahdAnsary 0:79ed1a99225f 10 Ticker int3;
FahdAnsary 0:79ed1a99225f 11 Ticker int4;
FahdAnsary 0:79ed1a99225f 12
FahdAnsary 0:79ed1a99225f 13 Serial pc(USBTX, USBRX);
FahdAnsary 0:79ed1a99225f 14 Serial gsm(D1, D0); //tx,rx
FahdAnsary 0:79ed1a99225f 15 DigitalOut dtr(D2);
FahdAnsary 0:79ed1a99225f 16 DigitalOut pwr_key(D3);
FahdAnsary 0:79ed1a99225f 17 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
FahdAnsary 0:79ed1a99225f 18 AnalogIn AC_input(A0);
FahdAnsary 0:79ed1a99225f 19 AnalogIn DC_input(A2);
FahdAnsary 0:79ed1a99225f 20 AnalogIn TC_RLY(A3);
FahdAnsary 0:79ed1a99225f 21 AnalogIn TC_50(A4);
FahdAnsary 0:79ed1a99225f 22 AnalogIn TC_33(A5);
FahdAnsary 0:79ed1a99225f 23
FahdAnsary 0:79ed1a99225f 24
FahdAnsary 0:79ed1a99225f 25 union Data
FahdAnsary 0:79ed1a99225f 26 {
FahdAnsary 0:79ed1a99225f 27 unsigned short datai[50000];
FahdAnsary 0:79ed1a99225f 28 char datac[100000];
FahdAnsary 0:79ed1a99225f 29 };
FahdAnsary 0:79ed1a99225f 30 union Data ACdata;
FahdAnsary 0:79ed1a99225f 31 union Data DCdata;
FahdAnsary 0:79ed1a99225f 32
FahdAnsary 0:79ed1a99225f 33 union Temp
FahdAnsary 0:79ed1a99225f 34 {
FahdAnsary 0:79ed1a99225f 35 unsigned short tempi;
FahdAnsary 0:79ed1a99225f 36 char tempc;
FahdAnsary 0:79ed1a99225f 37 };
FahdAnsary 0:79ed1a99225f 38 char sitename[100] ="MOD2";
FahdAnsary 0:79ed1a99225f 39 char filename[100] = "";
FahdAnsary 0:79ed1a99225f 40 char timestamp[100]="";
FahdAnsary 0:79ed1a99225f 41 char timestampold[100]="";
FahdAnsary 0:79ed1a99225f 42 char main_dir[100] ="";
FahdAnsary 0:79ed1a99225f 43 char month_dir[100]="";
FahdAnsary 0:79ed1a99225f 44 char date_dir[100] ="";
FahdAnsary 0:79ed1a99225f 45 char hour_dir[100] ="";
FahdAnsary 0:79ed1a99225f 46 char pathAC[100] ="";
FahdAnsary 0:79ed1a99225f 47 char pathDC[100] ="";
FahdAnsary 0:79ed1a99225f 48 char pathTC[100] ="";
FahdAnsary 0:79ed1a99225f 49 char response[100] ="";
FahdAnsary 0:79ed1a99225f 50 char command[100] ="";
FahdAnsary 0:79ed1a99225f 51 char result[100] ="";
FahdAnsary 0:79ed1a99225f 52 char FTP_File_Name[100] ="";
FahdAnsary 0:79ed1a99225f 53 char FTPPUT_File_Name[100] ="";
FahdAnsary 0:79ed1a99225f 54 char FTP_Path_Name[100] ="";
FahdAnsary 0:79ed1a99225f 55
FahdAnsary 0:79ed1a99225f 56 int dateu = 0;
FahdAnsary 0:79ed1a99225f 57 int datet = 0;
FahdAnsary 0:79ed1a99225f 58 int monthu = 0;
FahdAnsary 0:79ed1a99225f 59 int montht = 0;
FahdAnsary 0:79ed1a99225f 60 int year = 0;
FahdAnsary 0:79ed1a99225f 61 int houru = 0;
FahdAnsary 0:79ed1a99225f 62 int hourt = 0;
FahdAnsary 0:79ed1a99225f 63 int minuteu = 0;
FahdAnsary 0:79ed1a99225f 64 int minutet = 0;
FahdAnsary 0:79ed1a99225f 65 int secondu = 0;
FahdAnsary 0:79ed1a99225f 66 int secondt = 0;
FahdAnsary 0:79ed1a99225f 67
FahdAnsary 0:79ed1a99225f 68 int time_stamp = 0;
FahdAnsary 0:79ed1a99225f 69 int temp = 0;
FahdAnsary 0:79ed1a99225f 70 int ftp_update_flag = 1;
FahdAnsary 0:79ed1a99225f 71 int data_update_flag = 1;
FahdAnsary 0:79ed1a99225f 72 int name_update_flag = 1;
FahdAnsary 0:79ed1a99225f 73 int c,i;
FahdAnsary 0:79ed1a99225f 74
FahdAnsary 0:79ed1a99225f 75 unsigned long var = 0;
FahdAnsary 0:79ed1a99225f 76 unsigned long currentMillis = 0;
FahdAnsary 0:79ed1a99225f 77 uint8_t x=0,z=0, answer=0;
FahdAnsary 0:79ed1a99225f 78
FahdAnsary 0:79ed1a99225f 79 time_t previous;
FahdAnsary 0:79ed1a99225f 80 float tempC;
FahdAnsary 0:79ed1a99225f 81 uint32_t dataLength = dur_sec*freq*1000;
FahdAnsary 0:79ed1a99225f 82 unsigned long j=0;
FahdAnsary 0:79ed1a99225f 83
FahdAnsary 0:79ed1a99225f 84
FahdAnsary 0:79ed1a99225f 85 //----------------------------------------------------------------------------------------------------------------------------------
FahdAnsary 0:79ed1a99225f 86
FahdAnsary 0:79ed1a99225f 87 int8_t sendATcommandclk(char* ATcommand, char* expected_answer, unsigned int timeout)
FahdAnsary 0:79ed1a99225f 88 {
FahdAnsary 0:79ed1a99225f 89 uint8_t x=0,answer=0;//x=0 and answer=0, if not put, AT+CCLK?\r is not executed
FahdAnsary 0:79ed1a99225f 90 char response[100];
FahdAnsary 0:79ed1a99225f 91 memset(response, '\0', 100); // Initialize the string
FahdAnsary 0:79ed1a99225f 92 wait_ms(100);
FahdAnsary 0:79ed1a99225f 93 while( gsm.readable() > 0) gsm.getc(); // Clean the input buffer
FahdAnsary 0:79ed1a99225f 94 gsm.printf("%s \r", ATcommand); // Send the AT command
FahdAnsary 0:79ed1a99225f 95 pc.printf("..@");
FahdAnsary 0:79ed1a99225f 96 x = 0;
FahdAnsary 0:79ed1a99225f 97 previous = time(NULL);
FahdAnsary 0:79ed1a99225f 98
FahdAnsary 0:79ed1a99225f 99 // this loop waits for the answer
FahdAnsary 0:79ed1a99225f 100 do{
FahdAnsary 0:79ed1a99225f 101 if(gsm.readable() != 0){
FahdAnsary 0:79ed1a99225f 102
FahdAnsary 0:79ed1a99225f 103 // if there are data in the UART input buffer, reads it and checks for the asnwer
FahdAnsary 0:79ed1a99225f 104
FahdAnsary 0:79ed1a99225f 105 response[x] = gsm.getc();
FahdAnsary 0:79ed1a99225f 106 pc.putc(response[x]);
FahdAnsary 0:79ed1a99225f 107 x++;
FahdAnsary 0:79ed1a99225f 108 sprintf(timestamp,response);//copies response to timestamp for further processing
FahdAnsary 0:79ed1a99225f 109
FahdAnsary 0:79ed1a99225f 110 // check if the desired answer is in the response of the module
FahdAnsary 0:79ed1a99225f 111 if (strstr(response, expected_answer) != NULL)
FahdAnsary 0:79ed1a99225f 112 {
FahdAnsary 0:79ed1a99225f 113 answer = 1;
FahdAnsary 0:79ed1a99225f 114 }
FahdAnsary 0:79ed1a99225f 115 }
FahdAnsary 0:79ed1a99225f 116
FahdAnsary 0:79ed1a99225f 117 // Waits for the asnwer with time out
FahdAnsary 0:79ed1a99225f 118 }while((answer == 0) && ((time(NULL) - previous) < timeout));
FahdAnsary 0:79ed1a99225f 119 //pc.printf("%s \r\n",response);
FahdAnsary 0:79ed1a99225f 120 FILE *fp=fopen("/sd/TeraTerm.txt","a");
FahdAnsary 0:79ed1a99225f 121 if(fp == NULL)
FahdAnsary 0:79ed1a99225f 122 {
FahdAnsary 0:79ed1a99225f 123 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 124 }
FahdAnsary 0:79ed1a99225f 125 fprintf(fp,"%s",response);
FahdAnsary 0:79ed1a99225f 126 fclose(fp);
FahdAnsary 0:79ed1a99225f 127 return answer;
FahdAnsary 0:79ed1a99225f 128 }
FahdAnsary 0:79ed1a99225f 129
FahdAnsary 0:79ed1a99225f 130 //----------------------------------------------------------------------------------------------------------------------------------
FahdAnsary 0:79ed1a99225f 131
FahdAnsary 0:79ed1a99225f 132 void GetFileDir()
FahdAnsary 0:79ed1a99225f 133 {
FahdAnsary 0:79ed1a99225f 134
FahdAnsary 0:79ed1a99225f 135 sendATcommandclk("AT+CCLK?\r", "OK", 5);
FahdAnsary 0:79ed1a99225f 136 sprintf(response,timestamp);
FahdAnsary 0:79ed1a99225f 137 x=20;
FahdAnsary 0:79ed1a99225f 138 int gsmerr;
FahdAnsary 0:79ed1a99225f 139 year = 10*(timestamp[x+1]-48) + (timestamp[x+2]-48);
FahdAnsary 0:79ed1a99225f 140 while(year!=14)
FahdAnsary 0:79ed1a99225f 141 {
FahdAnsary 0:79ed1a99225f 142 wait(1);
FahdAnsary 0:79ed1a99225f 143 GetFileDir();
FahdAnsary 0:79ed1a99225f 144 pc.printf("\r\ncurrent timestamp %s\r\n",timestamp);
FahdAnsary 0:79ed1a99225f 145
FahdAnsary 0:79ed1a99225f 146 }
FahdAnsary 0:79ed1a99225f 147 sprintf(timestampold,response);
FahdAnsary 0:79ed1a99225f 148 pc.printf("\r\nold time stamp is%s\r\n",timestampold);
FahdAnsary 0:79ed1a99225f 149 //month onwards all parameters are processed in both 'unit' and 'ten' position separately, else for numbers<10, only unit digit is printed e.g 09 is shown as 9 only
FahdAnsary 0:79ed1a99225f 150 montht = (timestamp[x+4]-48);
FahdAnsary 0:79ed1a99225f 151 monthu = (timestamp[x+5]-48);
FahdAnsary 0:79ed1a99225f 152 datet = (timestamp[x+7]-48);
FahdAnsary 0:79ed1a99225f 153 dateu = (timestamp[x+8]-48);
FahdAnsary 0:79ed1a99225f 154 hourt = (timestamp[x+10]-48);
FahdAnsary 0:79ed1a99225f 155 houru = (timestamp[x+11]-48);
FahdAnsary 0:79ed1a99225f 156 minutet = (timestamp[x+13]-48);
FahdAnsary 0:79ed1a99225f 157 minuteu = (timestamp[x+14]-48);
FahdAnsary 0:79ed1a99225f 158 secondt = (timestamp[x+16]-48);
FahdAnsary 0:79ed1a99225f 159 secondu = (timestamp[x+17]-48);
FahdAnsary 0:79ed1a99225f 160 sprintf(main_dir,"/sd/%s",sitename);
FahdAnsary 0:79ed1a99225f 161 sprintf(month_dir,"%s/%s%d%d%d",main_dir,sitename,year,montht,monthu);
FahdAnsary 0:79ed1a99225f 162 sprintf(date_dir,"%s/%s%d%d%d%d%d",month_dir,sitename,year,montht,monthu,datet,dateu);
FahdAnsary 0:79ed1a99225f 163 sprintf(hour_dir,"%s/%s%d%d%d%d%d%d%d",date_dir,sitename,year,montht,monthu,datet,dateu,hourt,houru);
FahdAnsary 0:79ed1a99225f 164 if(timestamp==timestampold)
FahdAnsary 0:79ed1a99225f 165 {
FahdAnsary 0:79ed1a99225f 166 sprintf(filename,"%s/%s%d%d%d%d%d%d%d%d%d%d%dErr%d",hour_dir,sitename,year,montht,monthu,datet,dateu,hourt,houru,minutet,minuteu,secondt,secondu,gsmerr);
FahdAnsary 0:79ed1a99225f 167 gsmerr++;
FahdAnsary 0:79ed1a99225f 168 }
FahdAnsary 0:79ed1a99225f 169 else
FahdAnsary 0:79ed1a99225f 170 {
FahdAnsary 0:79ed1a99225f 171 sprintf(filename,"%s/%s%d%d%d%d%d%d%d%d%d%d%d",hour_dir,sitename,year,montht,monthu,datet,dateu,hourt,houru,minutet,minuteu,secondt,secondu);
FahdAnsary 0:79ed1a99225f 172 gsmerr=0;
FahdAnsary 0:79ed1a99225f 173 }
FahdAnsary 0:79ed1a99225f 174 mkdir(main_dir,0777);
FahdAnsary 0:79ed1a99225f 175 mkdir(month_dir,0777);
FahdAnsary 0:79ed1a99225f 176 mkdir(date_dir,0777);
FahdAnsary 0:79ed1a99225f 177 mkdir(hour_dir,0777);
FahdAnsary 0:79ed1a99225f 178
FahdAnsary 0:79ed1a99225f 179 //pc.printf("dir are\r\nmain_dir\t%s\r\nmonth_dir\t%s\r\ndate_dir\t%s\r\nhour_dir\t%s\r\nfilename\t%s\r\n",main_dir,month_dir,date_dir,hour_dir,filename);
FahdAnsary 0:79ed1a99225f 180 }
FahdAnsary 0:79ed1a99225f 181
FahdAnsary 0:79ed1a99225f 182 //-------------------------------------------------------------------------------------------------------------------------------------
FahdAnsary 0:79ed1a99225f 183
FahdAnsary 0:79ed1a99225f 184 void temp_val()
FahdAnsary 0:79ed1a99225f 185 {
FahdAnsary 0:79ed1a99225f 186 union Temp TC33temp;
FahdAnsary 0:79ed1a99225f 187 union Temp TC50temp;
FahdAnsary 0:79ed1a99225f 188 union Temp TCRLtemp;
FahdAnsary 0:79ed1a99225f 189
FahdAnsary 0:79ed1a99225f 190 TC33temp.tempi=TC_33.read_u16();
FahdAnsary 0:79ed1a99225f 191 TC50temp.tempi=TC_50.read_u16();
FahdAnsary 0:79ed1a99225f 192 TCRLtemp.tempi=TC_RLY.read_u16();
FahdAnsary 0:79ed1a99225f 193
FahdAnsary 0:79ed1a99225f 194
FahdAnsary 0:79ed1a99225f 195 GetFileDir();
FahdAnsary 0:79ed1a99225f 196
FahdAnsary 0:79ed1a99225f 197 sprintf(pathTC,"%sTC.txt",hour_dir);
FahdAnsary 0:79ed1a99225f 198 pc.printf("\r\nFilename-TC\t%s", pathTC);
FahdAnsary 0:79ed1a99225f 199 FILE *fp = fopen(pathTC, "a");
FahdAnsary 0:79ed1a99225f 200
FahdAnsary 0:79ed1a99225f 201 if(fp == NULL)
FahdAnsary 0:79ed1a99225f 202 {
FahdAnsary 0:79ed1a99225f 203 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 204 }
FahdAnsary 0:79ed1a99225f 205
FahdAnsary 0:79ed1a99225f 206 fprintf(fp, "\r\n20%d/%d%d/%d%d-%d%d:%d%d:%d%d",year,montht,monthu,datet,dateu,hourt,houru,minutet,minuteu,secondt,secondu);
FahdAnsary 0:79ed1a99225f 207 fprintf(fp, "\r\n3.3V-%d C",TC33temp.tempi );
FahdAnsary 0:79ed1a99225f 208 fprintf(fp, "\r\n5.0V-%d C",TC50temp.tempi );
FahdAnsary 0:79ed1a99225f 209 fprintf(fp, "\r\nRlay-%d C",TCRLtemp.tempi );
FahdAnsary 0:79ed1a99225f 210 fprintf(fp, ",");
FahdAnsary 0:79ed1a99225f 211 fclose(fp);
FahdAnsary 0:79ed1a99225f 212 pc.printf("\r\n3.3V temp - %c C\t%d",TC33temp.tempc,TC33temp.tempi );
FahdAnsary 0:79ed1a99225f 213 pc.printf("\r\n5.0V temp - %c C\t%d",TC50temp.tempc,TC50temp.tempi);
FahdAnsary 0:79ed1a99225f 214 pc.printf("\r\nRly temp - %c C\t%d",TCRLtemp.tempc,TCRLtemp.tempi );
FahdAnsary 0:79ed1a99225f 215 FILE *fp1=fopen("/sd/TeraTerm.txt","a");
FahdAnsary 0:79ed1a99225f 216 if(fp1 == NULL)
FahdAnsary 0:79ed1a99225f 217 {
FahdAnsary 0:79ed1a99225f 218 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 219 }
FahdAnsary 0:79ed1a99225f 220 fprintf(fp1,"\r\nTemperature writing Done\n\r");
FahdAnsary 0:79ed1a99225f 221 fclose(fp1);
FahdAnsary 0:79ed1a99225f 222 pc.printf("\n\rWriting Temp done \n \r");
FahdAnsary 0:79ed1a99225f 223
FahdAnsary 0:79ed1a99225f 224 }
FahdAnsary 0:79ed1a99225f 225
FahdAnsary 0:79ed1a99225f 226 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FahdAnsary 0:79ed1a99225f 227
FahdAnsary 0:79ed1a99225f 228 void calculate_ADC()
FahdAnsary 0:79ed1a99225f 229 {
FahdAnsary 0:79ed1a99225f 230
FahdAnsary 0:79ed1a99225f 231 Timer t;
FahdAnsary 0:79ed1a99225f 232
FahdAnsary 0:79ed1a99225f 233 pc.printf("\n\rStarting Reading \n\r");
FahdAnsary 0:79ed1a99225f 234 t.start();
FahdAnsary 0:79ed1a99225f 235 while(j<dataLength)
FahdAnsary 0:79ed1a99225f 236 {
FahdAnsary 0:79ed1a99225f 237 if((int)(t.read()*100*freq*1000)%100 == 0)
FahdAnsary 0:79ed1a99225f 238 {
FahdAnsary 0:79ed1a99225f 239 ACdata.datai[j] = AC_input.read_u16();
FahdAnsary 0:79ed1a99225f 240 DCdata.datai[j] = DC_input.read_u16();
FahdAnsary 0:79ed1a99225f 241 ++j;
FahdAnsary 0:79ed1a99225f 242 }
FahdAnsary 0:79ed1a99225f 243 }
FahdAnsary 0:79ed1a99225f 244
FahdAnsary 0:79ed1a99225f 245 t.stop();
FahdAnsary 0:79ed1a99225f 246 pc.printf("Time Taken %f \n\r", t.read());
FahdAnsary 0:79ed1a99225f 247 t.reset();
FahdAnsary 0:79ed1a99225f 248 pc.printf("Total Samples %d\r\n",j);
FahdAnsary 0:79ed1a99225f 249 j=0;
FahdAnsary 0:79ed1a99225f 250
FahdAnsary 0:79ed1a99225f 251 GetFileDir();
FahdAnsary 0:79ed1a99225f 252
FahdAnsary 0:79ed1a99225f 253 sprintf(pathAC,"%sAC.txt",filename);
FahdAnsary 0:79ed1a99225f 254 pc.printf("\r\nFilename-AC\t%s", pathAC);
FahdAnsary 0:79ed1a99225f 255 FILE *fp = fopen(pathAC, "w");
FahdAnsary 0:79ed1a99225f 256 if(fp == NULL)
FahdAnsary 0:79ed1a99225f 257 {
FahdAnsary 0:79ed1a99225f 258 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 259 }
FahdAnsary 0:79ed1a99225f 260 for(unsigned long k=0; k<dataLength; ++k)
FahdAnsary 0:79ed1a99225f 261 {
FahdAnsary 0:79ed1a99225f 262 if (k%4==0)
FahdAnsary 0:79ed1a99225f 263 {
FahdAnsary 0:79ed1a99225f 264 fprintf(fp,"\n\n");
FahdAnsary 0:79ed1a99225f 265 }
FahdAnsary 0:79ed1a99225f 266 fprintf(fp, "%c%c", ACdata.datac[k]);
FahdAnsary 0:79ed1a99225f 267 }
FahdAnsary 0:79ed1a99225f 268 fprintf(fp, ",");
FahdAnsary 0:79ed1a99225f 269 fclose(fp);
FahdAnsary 0:79ed1a99225f 270
FahdAnsary 0:79ed1a99225f 271 sprintf(pathDC,"%sDC.txt",filename);
FahdAnsary 0:79ed1a99225f 272 FILE *fp1 = fopen(pathDC, "w");
FahdAnsary 0:79ed1a99225f 273 if(fp1 == NULL)
FahdAnsary 0:79ed1a99225f 274 {
FahdAnsary 0:79ed1a99225f 275 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 276 }
FahdAnsary 0:79ed1a99225f 277
FahdAnsary 0:79ed1a99225f 278 for(unsigned long k=0; k<dataLength; ++k)
FahdAnsary 0:79ed1a99225f 279 {
FahdAnsary 0:79ed1a99225f 280 if (k%4==0)
FahdAnsary 0:79ed1a99225f 281 {
FahdAnsary 0:79ed1a99225f 282 fprintf(fp,"\n\n");
FahdAnsary 0:79ed1a99225f 283 }
FahdAnsary 0:79ed1a99225f 284
FahdAnsary 0:79ed1a99225f 285 fprintf(fp1, "%c%c", DCdata.datac[k]);
FahdAnsary 0:79ed1a99225f 286 }
FahdAnsary 0:79ed1a99225f 287 fprintf(fp1, ",");
FahdAnsary 0:79ed1a99225f 288 fclose(fp1);
FahdAnsary 0:79ed1a99225f 289 FILE *fp2=fopen("/sd/TeraTerm.txt","a");
FahdAnsary 0:79ed1a99225f 290 if(fp2 == NULL)
FahdAnsary 0:79ed1a99225f 291 {
FahdAnsary 0:79ed1a99225f 292 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 293 }
FahdAnsary 0:79ed1a99225f 294 fprintf(fp2,"\r\nSamples writing Done\n\r");
FahdAnsary 0:79ed1a99225f 295 fclose(fp2);
FahdAnsary 0:79ed1a99225f 296 pc.printf("Writing Samples done \n \r");
FahdAnsary 0:79ed1a99225f 297
FahdAnsary 0:79ed1a99225f 298 }
FahdAnsary 0:79ed1a99225f 299
FahdAnsary 0:79ed1a99225f 300 //---------------------------------------------------------------------------------------------------------------------------
FahdAnsary 0:79ed1a99225f 301
FahdAnsary 0:79ed1a99225f 302 void reset_mod()
FahdAnsary 0:79ed1a99225f 303 {
FahdAnsary 0:79ed1a99225f 304 pc.printf("\r\nresetting module\n\n\n\r\n");
FahdAnsary 0:79ed1a99225f 305
FahdAnsary 0:79ed1a99225f 306 NVIC_SystemReset();
FahdAnsary 0:79ed1a99225f 307 }
FahdAnsary 0:79ed1a99225f 308
FahdAnsary 0:79ed1a99225f 309 //---------------------------------------------------------------------------------------------------------------------------
FahdAnsary 0:79ed1a99225f 310 int main()
FahdAnsary 0:79ed1a99225f 311 {
FahdAnsary 0:79ed1a99225f 312 mkdir("/sd/strtup", 0777);
FahdAnsary 0:79ed1a99225f 313 FILE *fp=fopen("/sd/TeraTerm.txt","a");
FahdAnsary 0:79ed1a99225f 314 if(fp == NULL)
FahdAnsary 0:79ed1a99225f 315 {
FahdAnsary 0:79ed1a99225f 316 error("Could not open file for write\n\r");
FahdAnsary 0:79ed1a99225f 317 }
FahdAnsary 0:79ed1a99225f 318 fprintf(fp,"\nHello-Module\r\n");
FahdAnsary 0:79ed1a99225f 319 fclose(fp);
FahdAnsary 0:79ed1a99225f 320
FahdAnsary 0:79ed1a99225f 321
FahdAnsary 0:79ed1a99225f 322 pc.printf("Hello\r\n");
FahdAnsary 0:79ed1a99225f 323 wait(2);
FahdAnsary 0:79ed1a99225f 324
FahdAnsary 0:79ed1a99225f 325 int1.attach(&temp_val,10);
FahdAnsary 0:79ed1a99225f 326 int2.attach(&calculate_ADC,179);
FahdAnsary 0:79ed1a99225f 327 int3.attach(&reset_mod,3601);
FahdAnsary 0:79ed1a99225f 328
FahdAnsary 0:79ed1a99225f 329 }