''

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_08012018a by Calvin Kalintra

Committer:
ckalintra
Date:
Mon Jan 08 18:46:57 2018 +0000
Revision:
1:dc21a6fce3af
Parent:
0:7023c3f98f36
Child:
2:c696dfd53eeb
fran;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ckalintra 0:7023c3f98f36 1 #include "mbed.h"
ckalintra 0:7023c3f98f36 2 #include "data.h"
ckalintra 0:7023c3f98f36 3 Serial pc(USBTX, USBRX);
ckalintra 0:7023c3f98f36 4 char user_command[40] = {0};
ckalintra 0:7023c3f98f36 5 char user_command2[40] = {0};
ckalintra 1:dc21a6fce3af 6 int n, datan = 0, datac = 0, counterd = 0, dates, times, interrupt = 0, gather_data = 1;
ckalintra 0:7023c3f98f36 7 float t;
ckalintra 0:7023c3f98f36 8
ckalintra 0:7023c3f98f36 9
ckalintra 0:7023c3f98f36 10 void readall()
ckalintra 0:7023c3f98f36 11 {
ckalintra 0:7023c3f98f36 12 datan = counterw;
ckalintra 0:7023c3f98f36 13 pc.printf("readall selected\n\r");
ckalintra 0:7023c3f98f36 14 if (full == 1)
ckalintra 0:7023c3f98f36 15 {
ckalintra 1:dc21a6fce3af 16 datac = 119;
ckalintra 0:7023c3f98f36 17 }
ckalintra 0:7023c3f98f36 18 else
ckalintra 0:7023c3f98f36 19 {
ckalintra 0:7023c3f98f36 20 datac = counterw;
ckalintra 0:7023c3f98f36 21 }
ckalintra 0:7023c3f98f36 22 pc.printf("printting %i datas\n\r", datac);
ckalintra 0:7023c3f98f36 23 while (counterd < datac)
ckalintra 0:7023c3f98f36 24 {
ckalintra 1:dc21a6fce3af 25 pc.printf("%i%i:%i%i:%i%i, %i%i/%i%i/%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]);
ckalintra 0:7023c3f98f36 26 if (datan == 0)
ckalintra 0:7023c3f98f36 27 {
ckalintra 1:dc21a6fce3af 28 datan = 119;
ckalintra 0:7023c3f98f36 29 }
ckalintra 0:7023c3f98f36 30 datan--;
ckalintra 0:7023c3f98f36 31 counterd++;
ckalintra 0:7023c3f98f36 32 }
ckalintra 0:7023c3f98f36 33 counterd = 0;
ckalintra 0:7023c3f98f36 34 }
ckalintra 0:7023c3f98f36 35
ckalintra 0:7023c3f98f36 36 void readn()
ckalintra 0:7023c3f98f36 37 {
ckalintra 0:7023c3f98f36 38
ckalintra 0:7023c3f98f36 39 counterd = 0;
ckalintra 0:7023c3f98f36 40 n = atoi(user_command2);
ckalintra 0:7023c3f98f36 41 pc.printf("read %i datas\n\r",n);
ckalintra 0:7023c3f98f36 42 if (n > counterw)
ckalintra 0:7023c3f98f36 43 {
ckalintra 0:7023c3f98f36 44 pc.printf("we only have %i datas \n\r", counterw);
ckalintra 0:7023c3f98f36 45 }
ckalintra 0:7023c3f98f36 46 else
ckalintra 0:7023c3f98f36 47 {
ckalintra 0:7023c3f98f36 48 while (counterd < n)
ckalintra 0:7023c3f98f36 49 {
ckalintra 1:dc21a6fce3af 50 pc.printf("%i%i:%i%i:%i%i, %i%i/%i%i/%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], data_temp [datan], data_press[datan]);
ckalintra 0:7023c3f98f36 51 if (datan == 0)
ckalintra 0:7023c3f98f36 52 {
ckalintra 0:7023c3f98f36 53 datan = 121;
ckalintra 0:7023c3f98f36 54 }
ckalintra 0:7023c3f98f36 55 datan--;
ckalintra 0:7023c3f98f36 56 counterd++;
ckalintra 0:7023c3f98f36 57 }
ckalintra 0:7023c3f98f36 58 }
ckalintra 0:7023c3f98f36 59 }
ckalintra 0:7023c3f98f36 60
ckalintra 0:7023c3f98f36 61 void deleteall()
ckalintra 0:7023c3f98f36 62 {
ckalintra 0:7023c3f98f36 63 pc.printf("deleted %i datas \n\r", counterw);
ckalintra 0:7023c3f98f36 64 counterw = 0;
ckalintra 0:7023c3f98f36 65 int counter = 0;
ckalintra 1:dc21a6fce3af 66 while (counter < 120)
ckalintra 0:7023c3f98f36 67 {
ckalintra 0:7023c3f98f36 68 data_light[counter] = 0;
ckalintra 0:7023c3f98f36 69 data_temp [counter] = 0;
ckalintra 0:7023c3f98f36 70 data_press[counter] = 0;
ckalintra 1:dc21a6fce3af 71 date_a[counter] = 0;
ckalintra 1:dc21a6fce3af 72 time_a[counter] = 0;
ckalintra 1:dc21a6fce3af 73 date0_a[counter] = 0;
ckalintra 1:dc21a6fce3af 74 time0_a[counter] = 0;
ckalintra 0:7023c3f98f36 75 counter ++;
ckalintra 0:7023c3f98f36 76 full = 0;
ckalintra 0:7023c3f98f36 77 }
ckalintra 0:7023c3f98f36 78 }
ckalintra 0:7023c3f98f36 79
ckalintra 0:7023c3f98f36 80 void deleten()
ckalintra 0:7023c3f98f36 81 {
ckalintra 0:7023c3f98f36 82 datan = counterw;
ckalintra 0:7023c3f98f36 83 counterd = 0;
ckalintra 0:7023c3f98f36 84 n = atoi(user_command2);
ckalintra 0:7023c3f98f36 85 if (n > counterw && full == 0)
ckalintra 0:7023c3f98f36 86 {
ckalintra 0:7023c3f98f36 87 pc.printf("we only have %i datas \n\r", counterw);
ckalintra 0:7023c3f98f36 88 }
ckalintra 0:7023c3f98f36 89 else if(full == 1 && n> 120)
ckalintra 0:7023c3f98f36 90 {
ckalintra 0:7023c3f98f36 91 pc.printf("we only have 120 datas \n\r");
ckalintra 0:7023c3f98f36 92 }
ckalintra 0:7023c3f98f36 93 else if(full == 0 && n < counterw)
ckalintra 0:7023c3f98f36 94 {
ckalintra 0:7023c3f98f36 95 pc.printf("deleted %i datas \n\r", n);
ckalintra 0:7023c3f98f36 96 counterw = counterw-n;
ckalintra 0:7023c3f98f36 97 while (counterd < n)
ckalintra 0:7023c3f98f36 98 {
ckalintra 0:7023c3f98f36 99 data_light[datan] = 0;
ckalintra 0:7023c3f98f36 100 data_temp [datan] = 0;
ckalintra 0:7023c3f98f36 101 data_press[datan] = 0;
ckalintra 1:dc21a6fce3af 102 date_a[datan] = 0;
ckalintra 1:dc21a6fce3af 103 time_a[datan] = 0;
ckalintra 1:dc21a6fce3af 104 date0_a[datan] = 0;
ckalintra 1:dc21a6fce3af 105 time0_a[datan] = 0;
ckalintra 0:7023c3f98f36 106 counterd ++;
ckalintra 0:7023c3f98f36 107 datan--;
ckalintra 0:7023c3f98f36 108 }
ckalintra 0:7023c3f98f36 109 }
ckalintra 0:7023c3f98f36 110 else if(full == 1 && n < 120)
ckalintra 0:7023c3f98f36 111 {
ckalintra 0:7023c3f98f36 112 pc.printf("deleted %i datas \n\r", n);
ckalintra 0:7023c3f98f36 113 counterw = counterw-n;
ckalintra 0:7023c3f98f36 114 while (counterd < 120)
ckalintra 0:7023c3f98f36 115 {
ckalintra 0:7023c3f98f36 116 data_light[datan] = 0;
ckalintra 0:7023c3f98f36 117 data_temp [datan] = 0;
ckalintra 1:dc21a6fce3af 118 data_press[datan] = 0;
ckalintra 1:dc21a6fce3af 119 date_a[datan] = 0;
ckalintra 1:dc21a6fce3af 120 time_a[datan] = 0;
ckalintra 1:dc21a6fce3af 121 date0_a[datan] = 0;
ckalintra 1:dc21a6fce3af 122 time0_a[datan] = 0;
ckalintra 0:7023c3f98f36 123 counterd ++;
ckalintra 0:7023c3f98f36 124 datan--;
ckalintra 0:7023c3f98f36 125 }
ckalintra 0:7023c3f98f36 126 }
ckalintra 0:7023c3f98f36 127 }
ckalintra 0:7023c3f98f36 128 //void fill(char c[20], char c2[20])
ckalintra 0:7023c3f98f36 129 //{
ckalintra 0:7023c3f98f36 130 // int counterino = 0;
ckalintra 0:7023c3f98f36 131 // while (counterino <21)
ckalintra 0:7023c3f98f36 132 // {
ckalintra 0:7023c3f98f36 133 // user_command[counterino] = c[counterino];
ckalintra 0:7023c3f98f36 134 // user_command2[counterino] = c2[counterino];
ckalintra 0:7023c3f98f36 135 // counterino++;
ckalintra 0:7023c3f98f36 136 // }
ckalintra 0:7023c3f98f36 137
ckalintra 0:7023c3f98f36 138 //}
ckalintra 0:7023c3f98f36 139 void clear()
ckalintra 0:7023c3f98f36 140 {
ckalintra 0:7023c3f98f36 141 int counter = 0;
ckalintra 0:7023c3f98f36 142 while (counter < 40)
ckalintra 0:7023c3f98f36 143 {
ckalintra 0:7023c3f98f36 144 user_command[counter] = 0;
ckalintra 0:7023c3f98f36 145 counter ++;
ckalintra 0:7023c3f98f36 146 }
ckalintra 0:7023c3f98f36 147 }
ckalintra 0:7023c3f98f36 148
ckalintra 0:7023c3f98f36 149
ckalintra 0:7023c3f98f36 150 void clear2()
ckalintra 0:7023c3f98f36 151 {
ckalintra 0:7023c3f98f36 152 int counter = 0;
ckalintra 0:7023c3f98f36 153 while (counter < 40)
ckalintra 0:7023c3f98f36 154 {
ckalintra 0:7023c3f98f36 155 user_command2[counter] = 0;
ckalintra 0:7023c3f98f36 156 counter ++;
ckalintra 0:7023c3f98f36 157 }
ckalintra 0:7023c3f98f36 158 }
ckalintra 0:7023c3f98f36 159
ckalintra 0:7023c3f98f36 160 void selection()
ckalintra 0:7023c3f98f36 161 {
ckalintra 0:7023c3f98f36 162 counterd = 0;
ckalintra 0:7023c3f98f36 163 datan = counterw-1;
ckalintra 0:7023c3f98f36 164 if (user_command[0] == 'R'&& user_command[1] == 'E'&& user_command[2] == 'A'&& user_command[3] == 'D')
ckalintra 0:7023c3f98f36 165 {
ckalintra 0:7023c3f98f36 166 if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
ckalintra 0:7023c3f98f36 167 {
ckalintra 0:7023c3f98f36 168 readall();
ckalintra 0:7023c3f98f36 169 }
ckalintra 0:7023c3f98f36 170
ckalintra 0:7023c3f98f36 171 else
ckalintra 0:7023c3f98f36 172 {
ckalintra 0:7023c3f98f36 173 readn();
ckalintra 0:7023c3f98f36 174 }
ckalintra 0:7023c3f98f36 175 }
ckalintra 0:7023c3f98f36 176
ckalintra 0:7023c3f98f36 177 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')
ckalintra 0:7023c3f98f36 178 {
ckalintra 0:7023c3f98f36 179 if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
ckalintra 0:7023c3f98f36 180 {
ckalintra 0:7023c3f98f36 181 pc.printf("deleteall selected\n\r");
ckalintra 0:7023c3f98f36 182 deleteall();
ckalintra 0:7023c3f98f36 183 }
ckalintra 0:7023c3f98f36 184
ckalintra 0:7023c3f98f36 185 else
ckalintra 0:7023c3f98f36 186 {
ckalintra 0:7023c3f98f36 187 n = atoi(user_command2);
ckalintra 0:7023c3f98f36 188 pc.printf("delete %i\n\r",n);
ckalintra 0:7023c3f98f36 189 deleten();
ckalintra 0:7023c3f98f36 190 }
ckalintra 0:7023c3f98f36 191 }
ckalintra 0:7023c3f98f36 192
ckalintra 0:7023c3f98f36 193 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')
ckalintra 0:7023c3f98f36 194 {
ckalintra 0:7023c3f98f36 195 dates = atoi(user_command2);
ckalintra 0:7023c3f98f36 196 yyyy = dates%10;
ckalintra 0:7023c3f98f36 197 dates /= 10;
ckalintra 0:7023c3f98f36 198 yyy = dates%10;
ckalintra 0:7023c3f98f36 199 dates /= 10;
ckalintra 0:7023c3f98f36 200 yy = dates%10;
ckalintra 0:7023c3f98f36 201 dates /= 10;
ckalintra 0:7023c3f98f36 202 y = dates%10;
ckalintra 0:7023c3f98f36 203 dates /= 10;
ckalintra 0:7023c3f98f36 204 mm = dates%10;
ckalintra 0:7023c3f98f36 205 dates /= 10;
ckalintra 0:7023c3f98f36 206 m = dates%10;
ckalintra 0:7023c3f98f36 207 dates /= 10;
ckalintra 0:7023c3f98f36 208 dd = dates%10;
ckalintra 0:7023c3f98f36 209 dates /= 10;
ckalintra 0:7023c3f98f36 210 d = dates%10;
ckalintra 0:7023c3f98f36 211 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);
ckalintra 0:7023c3f98f36 212 }
ckalintra 0:7023c3f98f36 213 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')
ckalintra 0:7023c3f98f36 214 {
ckalintra 0:7023c3f98f36 215 times = atoi(user_command2);
ckalintra 0:7023c3f98f36 216 ss = times%10;
ckalintra 0:7023c3f98f36 217 times /= 10;
ckalintra 0:7023c3f98f36 218 s = times%10;
ckalintra 0:7023c3f98f36 219 times /= 10;
ckalintra 0:7023c3f98f36 220 mmi = times%10;
ckalintra 0:7023c3f98f36 221 times /= 10;
ckalintra 0:7023c3f98f36 222 mi = times%10;
ckalintra 0:7023c3f98f36 223 times /= 10;
ckalintra 0:7023c3f98f36 224 hh = times%10;
ckalintra 0:7023c3f98f36 225 times /= 10;
ckalintra 0:7023c3f98f36 226 h = times%10;
ckalintra 0:7023c3f98f36 227 pc.printf("you set the time to %i%i:%i%i:%i%i\n\r", h,hh,mi,mmi,s,ss);
ckalintra 0:7023c3f98f36 228 }
ckalintra 0:7023c3f98f36 229 else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T')
ckalintra 0:7023c3f98f36 230 {
ckalintra 0:7023c3f98f36 231 t = atof(user_command2);
ckalintra 1:dc21a6fce3af 232 if (t <=60 && t>=0.1)
ckalintra 1:dc21a6fce3af 233 {
ckalintra 1:dc21a6fce3af 234 pc.printf("you set the period to %2.2f\n\r", t);
ckalintra 1:dc21a6fce3af 235 interrupt = 1;
ckalintra 1:dc21a6fce3af 236 }
ckalintra 1:dc21a6fce3af 237 else
ckalintra 1:dc21a6fce3af 238 {
ckalintra 1:dc21a6fce3af 239 pc.printf("out of range\n\r");
ckalintra 1:dc21a6fce3af 240 }
ckalintra 1:dc21a6fce3af 241 }
ckalintra 1:dc21a6fce3af 242 else if (user_command[0] == 'S'&& user_command[1] == 'T'&& user_command[2] == 'A'&& user_command[3] == 'T'&& user_command[4] == 'E')
ckalintra 1:dc21a6fce3af 243 {
ckalintra 1:dc21a6fce3af 244 if (user_command2[0] == 'O'&& user_command2[1] == 'N')
ckalintra 1:dc21a6fce3af 245 {
ckalintra 1:dc21a6fce3af 246 gather_data = 1;
ckalintra 1:dc21a6fce3af 247 pc.printf("data is on\n\r");
ckalintra 1:dc21a6fce3af 248 }
ckalintra 1:dc21a6fce3af 249 else if (user_command2[0] == 'O'&& user_command2[1] == 'F'&& user_command2[2] == 'F')
ckalintra 1:dc21a6fce3af 250 {
ckalintra 1:dc21a6fce3af 251 gather_data = 0;
ckalintra 1:dc21a6fce3af 252 pc.printf("data is off\n\r");
ckalintra 1:dc21a6fce3af 253 }
ckalintra 0:7023c3f98f36 254 }
ckalintra 0:7023c3f98f36 255 }
ckalintra 0:7023c3f98f36 256 //int main()
ckalintra 0:7023c3f98f36 257 //{
ckalintra 0:7023c3f98f36 258 // pc.printf("putty ready\n\r");
ckalintra 0:7023c3f98f36 259 // while(1)
ckalintra 0:7023c3f98f36 260 // {
ckalintra 0:7023c3f98f36 261 // clear();
ckalintra 0:7023c3f98f36 262 // clear2();
ckalintra 0:7023c3f98f36 263 // while (user_command[0] == 0)
ckalintra 0:7023c3f98f36 264 // {
ckalintra 0:7023c3f98f36 265 // pc.scanf("%s",user_command);
ckalintra 0:7023c3f98f36 266 // pc.scanf("%s",user_command2);
ckalintra 0:7023c3f98f36 267 // pc.printf("you typed: %s %s\n\r",user_command,user_command2);
ckalintra 0:7023c3f98f36 268 // }
ckalintra 0:7023c3f98f36 269 //
ckalintra 0:7023c3f98f36 270 // selection();
ckalintra 0:7023c3f98f36 271 // }
ckalintra 0:7023c3f98f36 272 //}
ckalintra 0:7023c3f98f36 273
ckalintra 0:7023c3f98f36 274
ckalintra 0:7023c3f98f36 275 void putty_write ()
ckalintra 0:7023c3f98f36 276 {
ckalintra 0:7023c3f98f36 277 int count = 0;
ckalintra 0:7023c3f98f36 278 int wcount = 0;
ckalintra 0:7023c3f98f36 279 while (user_command[wcount]!= ' ')
ckalintra 0:7023c3f98f36 280 {
ckalintra 0:7023c3f98f36 281 user_command[count] = pc.getc();
ckalintra 0:7023c3f98f36 282 pc.putc(user_command[count]);
ckalintra 0:7023c3f98f36 283 count++;
ckalintra 0:7023c3f98f36 284 wcount = count -1;
ckalintra 0:7023c3f98f36 285 }
ckalintra 0:7023c3f98f36 286 int count2 = 0;
ckalintra 0:7023c3f98f36 287 int wcount2 = 0;
ckalintra 0:7023c3f98f36 288 while(user_command2[wcount2]!= '\r')
ckalintra 0:7023c3f98f36 289 {
ckalintra 0:7023c3f98f36 290 user_command2[count2] = pc.getc();
ckalintra 0:7023c3f98f36 291 pc.putc(user_command2[count2]);
ckalintra 0:7023c3f98f36 292 count2++;
ckalintra 0:7023c3f98f36 293 wcount2 = count2 -1;
ckalintra 0:7023c3f98f36 294 }
ckalintra 0:7023c3f98f36 295
ckalintra 0:7023c3f98f36 296
ckalintra 0:7023c3f98f36 297 pc.printf("you typed: %s %s\n\r",user_command,user_command2);
ckalintra 0:7023c3f98f36 298 selection();
ckalintra 0:7023c3f98f36 299 clear();
ckalintra 0:7023c3f98f36 300 clear2();
ckalintra 0:7023c3f98f36 301
ckalintra 0:7023c3f98f36 302 }