Francisco Salle / Mbed 2 deprecated cw-watchdog-09012018-copy_copy

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_09012018_copy by Calvin Kalintra

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers putty.h Source File

putty.h

00001 #include "mbed.h"
00002 #include "data.h"
00003 Serial pc(USBTX, USBRX); 
00004 char user_command[40] = {0};
00005 char user_command2[40] = {0};
00006 int n, datan = 0, datac = 0, counterd = 0, dates, times, interrupt = 0, gather_data = 1, putty_enabled = 1;
00007 float t;
00008 
00009 
00010 void readall()
00011 {
00012     datan = counterw;
00013     pc.printf("readall selected\n\r");
00014     if (full == 1)
00015         {
00016             datac = 119;
00017         }
00018     else
00019         {
00020             datac = counterw;
00021         }
00022     pc.printf("printting %i datas\n\r", datac);
00023     while (counterd < datac)  
00024         { 
00025             pc.printf("%i%i, %i%i, light: %2.4f, temp: %3.4f, press: %3.4f\n\r", date0_a[datan-1] ,date_a[datan-1], time0_a[datan-1], time_a[datan-1],data_light[datan-1], data_temp [datan-1], data_press[datan-1]);  
00026             if (datan == 0)
00027                 {
00028                     datan = 119;
00029                 }
00030             datan--;
00031             counterd++;     
00032         }
00033     counterd = 0;
00034 }
00035 
00036 void readn()
00037 {
00038     
00039     counterd = 0; 
00040     n = atoi(user_command2);
00041     pc.printf("read %i datas\n\r",n);
00042     if (n > counterw)
00043         {
00044             pc.printf("we only have %i datas \n\r", counterw);
00045         }
00046     else
00047         {
00048             while (counterd < n)  
00049                 { 
00050                     pc.printf("%i%i, %i%i, light: %2.4f, temp: %3.4f, press: %3.4f\n\r", date0_a[datan-1] ,date_a[datan-1], time0_a[datan-1], time_a[datan-1], data_light[datan-1], data_temp [datan-1], data_press[datan-1]);  
00051                     if (datan == 0)
00052                         {
00053                             datan = 121;
00054                         }
00055                     datan--;
00056                     counterd++;     
00057                 }  
00058          }   
00059 }
00060 
00061 void deleteall()
00062 {
00063     pc.printf("deleted %i datas \n\r", counterw);
00064     counterw = 0;
00065     int counter = 0;
00066     while (counter < 120)
00067         {
00068             data_light[counter] = 0;
00069             data_temp [counter] = 0; 
00070             data_press[counter] = 0; 
00071             date_a[counter] = 0;
00072             time_a[counter] = 0;
00073             date0_a[counter] = 0;
00074             time0_a[counter] = 0;
00075             counter ++;
00076             full = 0;
00077         }  
00078 }
00079 
00080 void deleten()
00081 {
00082     datan = counterw;
00083     counterd = 0;
00084     n = atoi(user_command2);
00085     if (n > counterw && full == 0)
00086     {
00087         pc.printf("we only have %i datas \n\r", counterw);
00088     }
00089     else if(full == 1 && n> 120)
00090     {
00091         pc.printf("we only have 120 datas \n\r");
00092     }
00093     else if(full == 0 && n < counterw)
00094         {
00095             pc.printf("deleted %i datas \n\r", n);
00096             counterw = counterw-n;
00097             while (counterd < n)
00098                 {
00099                     data_light[datan] = 0;
00100                     data_temp [datan] = 0; 
00101                     data_press[datan] = 0; 
00102                     date_a[datan] = 0;
00103                     time_a[datan] = 0;
00104                     date0_a[datan] = 0;
00105                     time0_a[datan] = 0;
00106                     counterd ++;
00107                     datan--;
00108                 }
00109         }
00110    else if(full == 1 && n < 120)
00111         {
00112             pc.printf("deleted %i datas \n\r", n);
00113             counterw = counterw-n;
00114             while (counterd < 120)
00115                 {
00116                     data_light[datan] = 0;
00117                     data_temp [datan] = 0; 
00118                     data_press[datan] = 0;
00119                     date_a[datan] = 0;
00120                     time_a[datan] = 0; 
00121                     date0_a[datan] = 0;
00122                     time0_a[datan] = 0;
00123                     counterd ++;
00124                     datan--;
00125                 }
00126         } 
00127 }
00128 //void fill(char c[20], char c2[20])
00129 //{
00130 //    int counterino = 0;
00131 //    while (counterino <21)
00132 //    {
00133 //    user_command[counterino] = c[counterino];
00134 //    user_command2[counterino] = c2[counterino];
00135 //    counterino++;
00136 //    }
00137       
00138 //}
00139 void clear()
00140 {
00141     int counter = 0;
00142     while (counter < 40)
00143    {
00144         user_command[counter] = 0;
00145         counter ++;
00146     }
00147 }
00148 
00149 
00150 void clear2()
00151 {
00152     int counter = 0;
00153     while (counter < 40)
00154     {
00155         user_command2[counter] = 0;
00156         counter ++;
00157     }
00158 }
00159 
00160 void selection()
00161 {
00162     counterd = 0;
00163     datan = counterw-1;
00164     if (user_command[0] == 'R'&& user_command[1] == 'E'&& user_command[2] == 'A'&& user_command[3] == 'D')
00165     {
00166         if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
00167         {
00168             readall();
00169           }
00170         
00171         else
00172         {
00173             readn();
00174         }
00175     }   
00176     
00177     else if (user_command[0] == 'D'&& user_command[1] == 'E'&& user_command[2] == 'L'&& user_command[3] == 'E' && user_command[4] == 'T' && user_command[5] == 'E')
00178     {
00179         if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
00180         {
00181             pc.printf("deleteall selected\n\r");
00182             deleteall();
00183         }
00184     
00185          else
00186         {
00187             n = atoi(user_command2);
00188             pc.printf("delete %i\n\r",n);
00189             deleten();
00190          }
00191     }
00192     
00193     else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'D' && user_command[4] == 'A' && user_command[5] == 'T' && user_command[6] == 'E')
00194     {
00195           dates = atoi(user_command2); 
00196           yyyy =  dates%10;
00197           dates /= 10;
00198           yyy = dates%10;
00199           dates /= 10; 
00200           yy = dates%10;
00201           dates /= 10;
00202           y = dates%10;
00203           dates /= 10;
00204           mm = dates%10;
00205           dates /= 10;
00206           m = dates%10;
00207           dates /= 10;
00208           dd = dates%10;
00209           dates /= 10;
00210           d = dates%10;
00211           pc.printf("you set the date to %i%i/%i%i/%i%i%i%i\n\r", d,dd,m,mm,y,yy,yyy,yyyy);
00212     }
00213     else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T' && user_command[4] == 'I' && user_command[5] == 'M' && user_command[6] == 'E')
00214     {
00215           times = atoi(user_command2); 
00216           ss =  times%10;
00217           times /= 10;
00218           s = times%10;
00219           times /= 10; 
00220           mmi = times%10;
00221           times /= 10;
00222           mi = times%10;
00223           times /= 10;
00224           hh = times%10;
00225           times /= 10;
00226           h = times%10;
00227           pc.printf("you set the time to %i%i:%i%i:%i%i\n\r", h,hh,mi,mmi,s,ss);
00228     }
00229     else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T')
00230     {
00231         t = atof(user_command2);
00232         if (t <=60 && t>=0.1)
00233         {
00234             pc.printf("you set the period to %2.2f\n\r", t);
00235             interrupt = 1;
00236         }
00237         else 
00238         {
00239             pc.printf("out of range\n\r");
00240         }
00241     }
00242     else if (user_command[0] == 'S'&& user_command[1] == 'T'&& user_command[2] == 'A'&& user_command[3] == 'T'&& user_command[4] == 'E')
00243     {
00244         if (user_command2[0] == 'O'&& user_command2[1] == 'N')
00245         {
00246             gather_data = 1;
00247             pc.printf("data is on\n\r");
00248         }
00249         else if (user_command2[0] == 'O'&& user_command2[1] == 'F'&& user_command2[2] == 'F')
00250         {
00251             gather_data = 0;
00252             pc.printf("data is off\n\r");
00253         }
00254     }
00255     else if (user_command[0] == 'L'&& user_command[1] == 'O'&& user_command[2] == 'G'&& user_command[3] == 'G'&& user_command[4] == 'I'&& user_command[5] == 'N'&& user_command[6] == 'G')
00256     {
00257         if (user_command2[0] == 'O'&& user_command2[1] == 'N')
00258         {
00259             putty_enabled = 1;
00260             pc.printf("logging on\n\r");
00261         }
00262         else if (user_command2[0] == 'O'&& user_command2[1] == 'F'&& user_command2[2] == 'F')
00263         {
00264             putty_enabled = 0;
00265             pc.printf("logging off\n\r");
00266         }
00267     }
00268 }
00269 //int main()
00270 //{
00271 //    pc.printf("putty ready\n\r");
00272 //    while(1)
00273 //        {
00274 //            clear();
00275 //            clear2();
00276 //            while (user_command[0] == 0)
00277 //                {
00278 //                     pc.scanf("%s",user_command);
00279 //                     pc.scanf("%s",user_command2);
00280 //                     pc.printf("you typed: %s %s\n\r",user_command,user_command2);
00281 //                }
00282 //                
00283 //                selection();
00284 //         }
00285 //}
00286 
00287 
00288 void putty_write ()
00289 {
00290     int count = 0;
00291     int wcount = 0;
00292     while (user_command[wcount]!= ' ')
00293     {
00294         user_command[count] = pc.getc();
00295         pc.putc(user_command[count]);
00296         count++;
00297         wcount = count -1;
00298     }
00299     int count2 = 0;
00300     int wcount2 = 0;
00301     while(user_command2[wcount2]!= '\r')
00302     {
00303         user_command2[count2] = pc.getc();
00304         pc.putc(user_command2[count2]);
00305         count2++;
00306         wcount2 = count2 -1;
00307     }
00308     
00309     pc.printf("you typed: %s %s\n\r",user_command,user_command2);
00310     selection();
00311     clear();
00312     clear2();  
00313     
00314 }