FINAL PROJECT isn't it

Fork of ELEC351 by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Sun Jan 07 13:32:54 2018 +0000
Revision:
35:26b0a9b55d82
Parent:
34:c0b8705f183d
Child:
36:a0098306fc58
Working Networking

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 6:97f586597310 1 /*
thomasmorris 6:97f586597310 2 ELEC 351 Group T
thomasmorris 6:97f586597310 3 Team Members : Christopher Hills, Thomas Morris
thomasmorris 32:8f2795716e97 4 Current Verision 15
thomasmorris 29:64b1f95a807c 5 Overiew: Working Tasks 1,2,4,5,6,7,8,10,11,12,13
thomasmorris 8:0e4481b64353 6
thomasmorris 12:536eca338ae8 7 Last Revision: Added Mail Box to serial
thomasmorris 8:0e4481b64353 8 Todo:
thomasmorris 12:536eca338ae8 9 make a mailbox within SD card, LCD, network so they can be used from within
thomasmorris 12:536eca338ae8 10 Fix the network so it uses the mail box data.
thomasmorris 6:97f586597310 11 */
thomasmorris 6:97f586597310 12
thomasmorris 25:36699ed589ab 13 #include "SETUP.hpp"
thomasmorris 35:26b0a9b55d82 14 #include "NETWORK.hpp"
chills 24:7d2da96e05ad 15
chills 33:3b5096f0126a 16 Mutex Time_Lock_Main;
thomasmorris 35:26b0a9b55d82 17
thomasmorris 35:26b0a9b55d82 18 void Network()
thomasmorris 8:0e4481b64353 19 {
thomasmorris 35:26b0a9b55d82 20 while(1)
thomasmorris 35:26b0a9b55d82 21 {
thomasmorris 35:26b0a9b55d82 22 Thread::wait(5000);//Waits 5 seconds
thomasmorris 35:26b0a9b55d82 23 cout << "In Network Thread" << endl;
thomasmorris 35:26b0a9b55d82 24 Networking();//Prints the network data
thomasmorris 35:26b0a9b55d82 25 }
chills 13:db857b3744c6 26 }
thomasmorris 31:4a88bf97b53e 27 void LCD_Write_Year()
thomasmorris 12:536eca338ae8 28 {
chills 33:3b5096f0126a 29 Time_Lock_Main.lock();
chills 33:3b5096f0126a 30 time_t Time = time(NULL);
chills 33:3b5096f0126a 31 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 32 int Years = 1900 + Time_Pointer->tm_year;
chills 33:3b5096f0126a 33 Time_Lock_Main.unlock();
thomasmorris 31:4a88bf97b53e 34 stringstream ss;
thomasmorris 31:4a88bf97b53e 35 ss << Years;
thomasmorris 31:4a88bf97b53e 36 string Year_String = ss.str();
thomasmorris 31:4a88bf97b53e 37 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 38 LCD.Write_String("Set Year");
thomasmorris 31:4a88bf97b53e 39 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 40 LCD.Write_String(Year_String);
thomasmorris 30:4cde05cc7c4f 41 }
thomasmorris 25:36699ed589ab 42
thomasmorris 31:4a88bf97b53e 43 void LCD_Write_Month()
thomasmorris 31:4a88bf97b53e 44 {
chills 33:3b5096f0126a 45 Time_Lock_Main.lock();
chills 33:3b5096f0126a 46 time_t Time = time(NULL);
chills 33:3b5096f0126a 47 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 48 int Months = 1 + Time_Pointer->tm_mon;
chills 33:3b5096f0126a 49 Time_Lock_Main.unlock();
thomasmorris 31:4a88bf97b53e 50 stringstream ss;
thomasmorris 31:4a88bf97b53e 51 ss << Months;
thomasmorris 31:4a88bf97b53e 52 string Month_String = ss.str();
thomasmorris 31:4a88bf97b53e 53 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 54 LCD.Write_String("Set Month");
thomasmorris 31:4a88bf97b53e 55 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 56 LCD.Write_String(Month_String);
thomasmorris 31:4a88bf97b53e 57 }
thomasmorris 31:4a88bf97b53e 58 void LCD_Write_Day()
thomasmorris 31:4a88bf97b53e 59 {
chills 33:3b5096f0126a 60 Time_Lock_Main.lock();
chills 33:3b5096f0126a 61 time_t Time = time(NULL);
chills 33:3b5096f0126a 62 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 63 int Days = Time_Pointer->tm_mday;
chills 33:3b5096f0126a 64 Time_Lock_Main.unlock();
thomasmorris 31:4a88bf97b53e 65 stringstream ss;
thomasmorris 31:4a88bf97b53e 66 ss << Days;
thomasmorris 31:4a88bf97b53e 67 string Day_String = ss.str();
thomasmorris 31:4a88bf97b53e 68 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 69 LCD.Write_String("Set Day");
thomasmorris 31:4a88bf97b53e 70 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 71 LCD.Write_String(Day_String);
thomasmorris 31:4a88bf97b53e 72 }
thomasmorris 31:4a88bf97b53e 73
thomasmorris 31:4a88bf97b53e 74
thomasmorris 31:4a88bf97b53e 75 void LCD_Write_Hour()
thomasmorris 30:4cde05cc7c4f 76 {
chills 33:3b5096f0126a 77 Time_Lock_Main.lock();
chills 33:3b5096f0126a 78 time_t Time = time(NULL);
chills 33:3b5096f0126a 79 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 80 int Hours = Time_Pointer->tm_hour;
chills 33:3b5096f0126a 81 Time_Lock_Main.unlock();
thomasmorris 31:4a88bf97b53e 82 stringstream ss;
thomasmorris 31:4a88bf97b53e 83 ss << Hours;
thomasmorris 31:4a88bf97b53e 84 string Hour_String = ss.str();
thomasmorris 31:4a88bf97b53e 85 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 86 LCD.Write_String("Set Hour");
thomasmorris 31:4a88bf97b53e 87 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 88 LCD.Write_String(Hour_String);
thomasmorris 31:4a88bf97b53e 89 }
thomasmorris 31:4a88bf97b53e 90 void LCD_Write_Minute()
thomasmorris 31:4a88bf97b53e 91 {
chills 33:3b5096f0126a 92 Time_Lock_Main.lock();
chills 33:3b5096f0126a 93 time_t Time = time(NULL);
chills 33:3b5096f0126a 94 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 95 int Minutes = Time_Pointer->tm_min;
chills 33:3b5096f0126a 96 Time_Lock_Main.unlock();
thomasmorris 31:4a88bf97b53e 97 stringstream ss;
thomasmorris 31:4a88bf97b53e 98 ss << Minutes;
thomasmorris 31:4a88bf97b53e 99 string Minute_String = ss.str();
thomasmorris 31:4a88bf97b53e 100 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 101 LCD.Write_String("Set Minute");
thomasmorris 31:4a88bf97b53e 102 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 103 LCD.Write_String(Minute_String);
thomasmorris 31:4a88bf97b53e 104 }
thomasmorris 31:4a88bf97b53e 105 void LCD_Write_Seconds()
thomasmorris 31:4a88bf97b53e 106 {
chills 33:3b5096f0126a 107 Time_Lock_Main.lock();
chills 33:3b5096f0126a 108 time_t Time = time(NULL);
chills 33:3b5096f0126a 109 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 110 int Seconds = Time_Pointer->tm_sec;
chills 33:3b5096f0126a 111 Time_Lock_Main.unlock();
thomasmorris 31:4a88bf97b53e 112 stringstream ss;
thomasmorris 31:4a88bf97b53e 113 ss << Seconds;
thomasmorris 31:4a88bf97b53e 114 string Second_String = ss.str();
thomasmorris 31:4a88bf97b53e 115 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 116 LCD.Write_String("Set Second");
thomasmorris 31:4a88bf97b53e 117 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 118 LCD.Write_String(Second_String);
thomasmorris 7:dfe19413fdc2 119 }
thomasmorris 30:4cde05cc7c4f 120
thomasmorris 30:4cde05cc7c4f 121 void LCD_Output()
chills 34:c0b8705f183d 122 {
thomasmorris 30:4cde05cc7c4f 123 while(1)
thomasmorris 29:64b1f95a807c 124 {
thomasmorris 30:4cde05cc7c4f 125 Thread::wait(10);//Dont Delete
thomasmorris 30:4cde05cc7c4f 126 if(mode == 0)//Default mode
thomasmorris 30:4cde05cc7c4f 127 {
chills 34:c0b8705f183d 128 if(Log_Value == 1){cout << "In mode 0 " << endl;}
chills 33:3b5096f0126a 129
thomasmorris 35:26b0a9b55d82 130 Thread::wait(Default_Mode_Toggle_Time);
chills 33:3b5096f0126a 131
chills 34:c0b8705f183d 132 sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting
chills 33:3b5096f0126a 133
thomasmorris 30:4cde05cc7c4f 134 LCD.DDRAM_Address(0x00);
thomasmorris 30:4cde05cc7c4f 135 LCD.Write_String("Temp Pres li");
thomasmorris 30:4cde05cc7c4f 136 LCD.DDRAM_Address(0x40);
thomasmorris 30:4cde05cc7c4f 137 LCD.Write_String(LCD_buffer);
thomasmorris 25:36699ed589ab 138
thomasmorris 35:26b0a9b55d82 139 Thread::wait(Default_Mode_Toggle_Time);
chills 33:3b5096f0126a 140
chills 33:3b5096f0126a 141 Time_Lock_Main.lock();
chills 34:c0b8705f183d 142 time_t Time = Data_Active.get_time();
chills 34:c0b8705f183d 143 tm* Time_Pointer = localtime(&Time);
thomasmorris 30:4cde05cc7c4f 144 LCD.Display_Clear();
chills 33:3b5096f0126a 145 sprintf (LCD_buffer, "%d:%d %d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting
chills 33:3b5096f0126a 146 Time_Lock_Main.unlock();
chills 33:3b5096f0126a 147
thomasmorris 30:4cde05cc7c4f 148 LCD.DDRAM_Address(0x00);
thomasmorris 30:4cde05cc7c4f 149 LCD.Write_String("Current Time:");
thomasmorris 30:4cde05cc7c4f 150 LCD.DDRAM_Address(0x40);
thomasmorris 30:4cde05cc7c4f 151 LCD.Write_String(LCD_buffer);
thomasmorris 31:4a88bf97b53e 152
thomasmorris 31:4a88bf97b53e 153 if(SW1.read() & SW2.read() == 1)
thomasmorris 31:4a88bf97b53e 154 {
thomasmorris 31:4a88bf97b53e 155 mode = 1;
thomasmorris 31:4a88bf97b53e 156 }
thomasmorris 30:4cde05cc7c4f 157 }
thomasmorris 30:4cde05cc7c4f 158 else if(mode == 1)//Choose either date setting or time setting
thomasmorris 30:4cde05cc7c4f 159 {
chills 34:c0b8705f183d 160 if(Log_Value == 1){cout << "In Mode 1" << endl;}
thomasmorris 30:4cde05cc7c4f 161 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 162 while(1)
thomasmorris 31:4a88bf97b53e 163 {
thomasmorris 31:4a88bf97b53e 164 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 165 LCD.Write_String("Date Time");
thomasmorris 31:4a88bf97b53e 166 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 167 LCD.Write_String("< >");
thomasmorris 31:4a88bf97b53e 168 Thread::wait(1000);
thomasmorris 31:4a88bf97b53e 169 if(SW1.read() == 1)
thomasmorris 31:4a88bf97b53e 170 {
thomasmorris 31:4a88bf97b53e 171 mode = 2;
thomasmorris 31:4a88bf97b53e 172 break;
thomasmorris 31:4a88bf97b53e 173 }
thomasmorris 31:4a88bf97b53e 174 if(SW2.read() == 1)
thomasmorris 31:4a88bf97b53e 175 {
thomasmorris 31:4a88bf97b53e 176 mode = 5;
thomasmorris 31:4a88bf97b53e 177 break;
thomasmorris 31:4a88bf97b53e 178 }
thomasmorris 31:4a88bf97b53e 179 }
thomasmorris 30:4cde05cc7c4f 180 }
thomasmorris 30:4cde05cc7c4f 181 else if(mode == 2)//Set the Year
thomasmorris 30:4cde05cc7c4f 182 {
chills 34:c0b8705f183d 183 if(Log_Value == 1){cout << "In Mode 2" << endl;}
thomasmorris 31:4a88bf97b53e 184 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 185 while(1)
thomasmorris 31:4a88bf97b53e 186 {
thomasmorris 32:8f2795716e97 187 LCD_Write_Year();
thomasmorris 31:4a88bf97b53e 188 Thread::wait(1000);
chills 33:3b5096f0126a 189 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 190 {
chills 33:3b5096f0126a 191 mode = 3;
chills 33:3b5096f0126a 192 break;
chills 33:3b5096f0126a 193 }
thomasmorris 31:4a88bf97b53e 194 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 195 {
thomasmorris 31:4a88bf97b53e 196 Add_Year();
thomasmorris 31:4a88bf97b53e 197 }
thomasmorris 31:4a88bf97b53e 198 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 199 {
thomasmorris 31:4a88bf97b53e 200 Subtract_Year();
thomasmorris 31:4a88bf97b53e 201 }
thomasmorris 31:4a88bf97b53e 202 LCD_Write_Year();
thomasmorris 31:4a88bf97b53e 203 }
thomasmorris 30:4cde05cc7c4f 204 }
thomasmorris 30:4cde05cc7c4f 205 else if(mode == 3)//Set the Month
thomasmorris 30:4cde05cc7c4f 206 {
chills 34:c0b8705f183d 207 if(Log_Value == 1){cout << "In Mode 3" << endl;}
thomasmorris 31:4a88bf97b53e 208 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 209 while(1)
thomasmorris 32:8f2795716e97 210 {
thomasmorris 32:8f2795716e97 211 LCD_Write_Month();
thomasmorris 31:4a88bf97b53e 212 Thread::wait(1000);
chills 33:3b5096f0126a 213 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 214 {
chills 33:3b5096f0126a 215 mode = 4;
chills 33:3b5096f0126a 216 break;
chills 33:3b5096f0126a 217 }
thomasmorris 31:4a88bf97b53e 218 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 219 {
thomasmorris 31:4a88bf97b53e 220 Add_Month();
thomasmorris 31:4a88bf97b53e 221 }
thomasmorris 31:4a88bf97b53e 222 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 223 {
thomasmorris 31:4a88bf97b53e 224 Subtract_Month();
thomasmorris 32:8f2795716e97 225 }
chills 33:3b5096f0126a 226
thomasmorris 31:4a88bf97b53e 227 }
thomasmorris 30:4cde05cc7c4f 228 }
thomasmorris 30:4cde05cc7c4f 229 else if(mode == 4)//Set the Day
thomasmorris 30:4cde05cc7c4f 230 {
chills 34:c0b8705f183d 231 if(Log_Value == 1){cout << "In Mode 4" << endl;}
thomasmorris 31:4a88bf97b53e 232 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 233 while(1)
thomasmorris 32:8f2795716e97 234 {
thomasmorris 32:8f2795716e97 235 LCD_Write_Day();
thomasmorris 31:4a88bf97b53e 236 Thread::wait(1000);
chills 33:3b5096f0126a 237 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 238 {
chills 33:3b5096f0126a 239 mode = 0;
chills 33:3b5096f0126a 240 break;
chills 33:3b5096f0126a 241 }
thomasmorris 31:4a88bf97b53e 242 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 243 {
thomasmorris 31:4a88bf97b53e 244 Add_Day();
thomasmorris 31:4a88bf97b53e 245 }
thomasmorris 31:4a88bf97b53e 246 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 247 {
thomasmorris 31:4a88bf97b53e 248 Subtract_Day();
thomasmorris 32:8f2795716e97 249 }
thomasmorris 31:4a88bf97b53e 250 }
thomasmorris 30:4cde05cc7c4f 251 }
thomasmorris 30:4cde05cc7c4f 252 else if(mode == 5)//Set the Hour
thomasmorris 30:4cde05cc7c4f 253 {
chills 34:c0b8705f183d 254 if(Log_Value == 1){cout << "In Mode 5" << endl;}
thomasmorris 31:4a88bf97b53e 255 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 256 while(1)
thomasmorris 31:4a88bf97b53e 257 {
thomasmorris 32:8f2795716e97 258 LCD_Write_Hour();
thomasmorris 32:8f2795716e97 259 Thread::wait(1000);
chills 33:3b5096f0126a 260 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 261 {
chills 33:3b5096f0126a 262 mode = 6;
chills 33:3b5096f0126a 263 break;
chills 33:3b5096f0126a 264 }
thomasmorris 31:4a88bf97b53e 265 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 266 {
thomasmorris 31:4a88bf97b53e 267 Add_Hour();
thomasmorris 31:4a88bf97b53e 268 }
thomasmorris 31:4a88bf97b53e 269 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 270 {
thomasmorris 31:4a88bf97b53e 271 Subtract_Hour();
thomasmorris 31:4a88bf97b53e 272 }
thomasmorris 31:4a88bf97b53e 273 }
thomasmorris 30:4cde05cc7c4f 274 }
thomasmorris 30:4cde05cc7c4f 275 else if(mode == 6)//Set the Minute
thomasmorris 30:4cde05cc7c4f 276 {
chills 34:c0b8705f183d 277 if(Log_Value == 1){cout << "In Mode 6" << endl;}
thomasmorris 31:4a88bf97b53e 278 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 279 while(1)
thomasmorris 31:4a88bf97b53e 280 {
thomasmorris 32:8f2795716e97 281 LCD_Write_Minute();
thomasmorris 32:8f2795716e97 282 Thread::wait(1000);
chills 33:3b5096f0126a 283 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 284 {
chills 33:3b5096f0126a 285 mode = 7;
chills 33:3b5096f0126a 286 break;
chills 33:3b5096f0126a 287 }
thomasmorris 31:4a88bf97b53e 288 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 289 {
thomasmorris 31:4a88bf97b53e 290 Add_Minute();
thomasmorris 31:4a88bf97b53e 291 }
thomasmorris 31:4a88bf97b53e 292 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 293 {
thomasmorris 31:4a88bf97b53e 294 Subtract_Minute();
thomasmorris 32:8f2795716e97 295 }
thomasmorris 31:4a88bf97b53e 296 }
thomasmorris 30:4cde05cc7c4f 297 }
thomasmorris 30:4cde05cc7c4f 298 else if(mode == 7)//Set the Seconds
thomasmorris 30:4cde05cc7c4f 299 {
chills 34:c0b8705f183d 300 if(Log_Value == 1){cout << "In Mode 7" << endl;}
thomasmorris 31:4a88bf97b53e 301 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 302 while(1)
thomasmorris 31:4a88bf97b53e 303 {
thomasmorris 32:8f2795716e97 304 LCD_Write_Seconds();
thomasmorris 32:8f2795716e97 305 Thread::wait(1000);
chills 33:3b5096f0126a 306 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 307 {
chills 33:3b5096f0126a 308 mode = 0;
chills 33:3b5096f0126a 309 break;
chills 33:3b5096f0126a 310 }
thomasmorris 31:4a88bf97b53e 311 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 312 {
thomasmorris 31:4a88bf97b53e 313 Add_Second();
thomasmorris 31:4a88bf97b53e 314 }
thomasmorris 31:4a88bf97b53e 315 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 316 {
thomasmorris 31:4a88bf97b53e 317 Subtract_Second();
thomasmorris 32:8f2795716e97 318 }
thomasmorris 31:4a88bf97b53e 319 }
thomasmorris 30:4cde05cc7c4f 320 }
thomasmorris 30:4cde05cc7c4f 321 else
thomasmorris 30:4cde05cc7c4f 322 {
thomasmorris 35:26b0a9b55d82 323 mode = 0;
thomasmorris 7:dfe19413fdc2 324 }
thomasmorris 7:dfe19413fdc2 325 }
thomasmorris 7:dfe19413fdc2 326 }
thomasmorris 29:64b1f95a807c 327 void Serial_Commands()//Used for getting input from the user to determine the opperations to perform
thomasmorris 22:eb4cc12087b2 328 {
chills 24:7d2da96e05ad 329 string Serial_Input;
chills 34:c0b8705f183d 330 int A,B,C;
thomasmorris 25:36699ed589ab 331 while(1) {
thomasmorris 25:36699ed589ab 332 Serial_Input = "Blank";
chills 24:7d2da96e05ad 333 cout << "Please type in a command" << endl;
chills 34:c0b8705f183d 334
chills 34:c0b8705f183d 335 cin >> Serial_Input >> A >> B >> C;
thomasmorris 25:36699ed589ab 336
thomasmorris 22:eb4cc12087b2 337 if (Serial_Input == "Test")
thomasmorris 22:eb4cc12087b2 338 {
chills 24:7d2da96e05ad 339 cout << "Test Confirmed" << endl;
chills 34:c0b8705f183d 340 cout << A << " " << B << " " << C << endl;
thomasmorris 30:4cde05cc7c4f 341 cout << "This is the time " << get_current_time() << endl;
thomasmorris 25:36699ed589ab 342 }
thomasmorris 25:36699ed589ab 343 else if(Serial_Input == "READALL")
thomasmorris 22:eb4cc12087b2 344 {
chills 26:78f5e454e59f 345 cout << "Read All Confirmed " << Sample_Rate << endl;
chills 26:78f5e454e59f 346 Console_Output_Timer.attach(&Console_Output_ISR,Sample_Rate);
thomasmorris 25:36699ed589ab 347 }
chills 26:78f5e454e59f 348 else if(Serial_Input == "DELETEALL")
chills 26:78f5e454e59f 349 {
thomasmorris 35:26b0a9b55d82 350 Sampling_Timer.detach();
thomasmorris 35:26b0a9b55d82 351 Console_Output_Timer.detach();
thomasmorris 35:26b0a9b55d82 352 for (int x = 0; x < mailsize; x++)
thomasmorris 35:26b0a9b55d82 353 {
thomasmorris 35:26b0a9b55d82 354
thomasmorris 35:26b0a9b55d82 355 }
chills 27:807dd5660c4b 356 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 27:807dd5660c4b 357 cout << "Sampling Restarted" << endl;
thomasmorris 25:36699ed589ab 358 }
chills 27:807dd5660c4b 359 else if(Serial_Input == "READ")
thomasmorris 22:eb4cc12087b2 360 {
chills 34:c0b8705f183d 361 for (int x = 0; x < A; x++)
thomasmorris 29:64b1f95a807c 362 {
thomasmorris 29:64b1f95a807c 363 Serial_Comms_Stealth_Mode();
chills 34:c0b8705f183d 364 if(Log_Value == 1){cout << "Read " << x << " samples" << endl;}
thomasmorris 29:64b1f95a807c 365 }
thomasmorris 25:36699ed589ab 366 }
chills 26:78f5e454e59f 367 else if(Serial_Input == "DELETE")
thomasmorris 22:eb4cc12087b2 368 {
chills 26:78f5e454e59f 369 Sampling_Timer.detach();
chills 26:78f5e454e59f 370 Console_Output_Timer.detach();
chills 34:c0b8705f183d 371 for (int x = 0; x < A; x++){
chills 34:c0b8705f183d 372 if(Log_Value == 1){cout << "Deleted " << x << " samples" << endl;}
chills 26:78f5e454e59f 373 }
chills 26:78f5e454e59f 374 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 26:78f5e454e59f 375 cout << "Sampling Restarted" << endl;
thomasmorris 25:36699ed589ab 376 }
thomasmorris 25:36699ed589ab 377 else if(Serial_Input == "SETDATE")
chills 26:78f5e454e59f 378 {
chills 34:c0b8705f183d 379 set_new_date(A,B,C);
chills 34:c0b8705f183d 380 }
chills 34:c0b8705f183d 381 else if(Serial_Input == "SETTIME")
chills 34:c0b8705f183d 382 {
chills 34:c0b8705f183d 383 set_new_time(A,B,C);
chills 26:78f5e454e59f 384 }
thomasmorris 25:36699ed589ab 385 else if(Serial_Input == "SETT")
thomasmorris 22:eb4cc12087b2 386 {
chills 34:c0b8705f183d 387 if(A >= 1){Sample_Rate = A;}
chills 26:78f5e454e59f 388
chills 26:78f5e454e59f 389 Sampling_Timer.detach();
chills 26:78f5e454e59f 390 Console_Output_Timer.detach();
chills 26:78f5e454e59f 391 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
thomasmorris 25:36699ed589ab 392 }
chills 27:807dd5660c4b 393 else if(Serial_Input == "STATE")
chills 27:807dd5660c4b 394 {
chills 34:c0b8705f183d 395 if(A==0){Sampling_Timer.detach(); Console_Output_Timer.detach();}
chills 34:c0b8705f183d 396 if(A==1){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);}
thomasmorris 25:36699ed589ab 397 }
chills 34:c0b8705f183d 398 else if(Serial_Input == "LOGGING")
chills 26:78f5e454e59f 399 {
chills 34:c0b8705f183d 400 Log_Value = A;
thomasmorris 25:36699ed589ab 401 }
thomasmorris 25:36699ed589ab 402 else if(Serial_Input == "HELP")// Use this to display all of the availble commands
thomasmorris 25:36699ed589ab 403 {
thomasmorris 25:36699ed589ab 404 HELP();
thomasmorris 22:eb4cc12087b2 405 }
chills 26:78f5e454e59f 406 else if(Serial_Input == "STOP")
chills 26:78f5e454e59f 407 {
thomasmorris 28:09b5c46c8afd 408 Console_Output_Timer.detach(); //Stops Sampling
chills 26:78f5e454e59f 409 }
thomasmorris 30:4cde05cc7c4f 410 else if(Serial_Input == "Blank Blank")
thomasmorris 30:4cde05cc7c4f 411 {
thomasmorris 30:4cde05cc7c4f 412 cout << "Blank Blank complete" << endl;
thomasmorris 30:4cde05cc7c4f 413 }
thomasmorris 25:36699ed589ab 414 else
thomasmorris 22:eb4cc12087b2 415 {
chills 26:78f5e454e59f 416 cout << "Please enter an acceptable command" << endl;
thomasmorris 22:eb4cc12087b2 417 }
thomasmorris 22:eb4cc12087b2 418 }
thomasmorris 22:eb4cc12087b2 419 }
chills 34:c0b8705f183d 420 void Serial_Comms_Stealth_Mode() //Change this name
thomasmorris 29:64b1f95a807c 421 {
chills 34:c0b8705f183d 422 time_t Time = Data_Active.get_time();
chills 34:c0b8705f183d 423 tm* Time_Pointer = localtime(&Time);
chills 34:c0b8705f183d 424 strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string
chills 34:c0b8705f183d 425 pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));
chills 34:c0b8705f183d 426 pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time
chills 34:c0b8705f183d 427 pc.printf("Temperature = %f\t", Data_Active.get_temperature()); //Print Temperature
chills 34:c0b8705f183d 428 pc.printf("Pressure = %f\t", Data_Active.get_pressure()); //Print Pressure
chills 34:c0b8705f183d 429 pc.printf("Light = %f\n\r", Data_Active.get_light()); //Print Light
thomasmorris 29:64b1f95a807c 430
thomasmorris 29:64b1f95a807c 431 Green_led.Toggle();
chills 34:c0b8705f183d 432
thomasmorris 29:64b1f95a807c 433 }
chills 24:7d2da96e05ad 434 void Serial_Comms()//Thread for Serial Communications
thomasmorris 5:2594b953f111 435 {
thomasmorris 25:36699ed589ab 436 while(1) {
thomasmorris 28:09b5c46c8afd 437 Thread::signal_wait(SerialCommsTime);//Stupid 0 Bug
thomasmorris 29:64b1f95a807c 438 Serial_Comms_Stealth_Mode();
thomasmorris 5:2594b953f111 439 }
thomasmorris 5:2594b953f111 440 }
thomasmorris 5:2594b953f111 441
thomasmorris 28:09b5c46c8afd 442 void Console_Output_ISR() {t2.signal_set(SerialCommsTime);}
chills 26:78f5e454e59f 443 void Sampling_ISR() {t1.signal_set(SamplingTime);}
chills 26:78f5e454e59f 444
chills 26:78f5e454e59f 445
thomasmorris 5:2594b953f111 446 void Sample()//Samples the hardware and prints the result to the LCD
thomasmorris 5:2594b953f111 447 {
thomasmorris 30:4cde05cc7c4f 448 while(1)
thomasmorris 30:4cde05cc7c4f 449 {
chills 10:46946784326d 450 Thread::signal_wait(SamplingTime); //Set the time between samples
thomasmorris 25:36699ed589ab 451
chills 34:c0b8705f183d 452 Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature
chills 34:c0b8705f183d 453 Data_Active.set_pressure(sensor.getPressure()); //Read Pressure
chills 34:c0b8705f183d 454 Data_Active.set_light(adcIn.read()); //Read Light
chills 33:3b5096f0126a 455
chills 33:3b5096f0126a 456 Time_Lock_Main.lock();
chills 34:c0b8705f183d 457 time_t buffer_time = time(NULL);
chills 33:3b5096f0126a 458 Time_Lock_Main.unlock();
thomasmorris 25:36699ed589ab 459
chills 34:c0b8705f183d 460 Data_Active.set_time(buffer_time);
thomasmorris 25:36699ed589ab 461
thomasmorris 5:2594b953f111 462 Red_led.Toggle();
thomasmorris 5:2594b953f111 463 t1.signal_set(NotSamplingTime);
thomasmorris 5:2594b953f111 464 }
thomasmorris 25:36699ed589ab 465 }
thomasmorris 25:36699ed589ab 466 int main()
thomasmorris 25:36699ed589ab 467 {
noutram 1:e1cf7663f5ff 468 //Greeting
chills 16:067916791a25 469 pc.printf("Test Start");
chills 16:067916791a25 470 pc.printf("\n\r");
thomasmorris 25:36699ed589ab 471
chills 10:46946784326d 472 set_time(1512940530); //Set RTC time to December 10 2017
thomasmorris 30:4cde05cc7c4f 473
chills 10:46946784326d 474 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 25:36699ed589ab 475
chills 20:cbb71f84cff9 476 LCD.Initialise();
thomasmorris 28:09b5c46c8afd 477 LCD.DDRAM_Address(0x00);
thomasmorris 29:64b1f95a807c 478
thomasmorris 25:36699ed589ab 479 post(); //Power on Self Test
thomasmorris 25:36699ed589ab 480
noutram 3:a88838ff33e7 481 //Initialise the SD card (this needs to move)
noutram 1:e1cf7663f5ff 482 if ( sd.init() != 0) {
noutram 1:e1cf7663f5ff 483 printf("Init failed \n");
thomasmorris 28:09b5c46c8afd 484 LCD.Display_Clear();
thomasmorris 28:09b5c46c8afd 485 LCD.Write_String("CANNOT INIT SD"); //Change me
noutram 1:e1cf7663f5ff 486 errorCode(FATAL);
thomasmorris 25:36699ed589ab 487 }
noutram 1:e1cf7663f5ff 488 //Create a filing system for SD Card
thomasmorris 25:36699ed589ab 489 FATFileSystem fs("sd", &sd);
noutram 0:36e89e3ed7c4 490
noutram 1:e1cf7663f5ff 491 //Open to WRITE
noutram 1:e1cf7663f5ff 492 FILE* fp = fopen("/sd/test.csv","a");
noutram 1:e1cf7663f5ff 493 if (fp == NULL) {
noutram 1:e1cf7663f5ff 494 error("Could not open file for write\n");
thomasmorris 28:09b5c46c8afd 495 LCD.Display_Clear();
thomasmorris 28:09b5c46c8afd 496 LCD.Write_String("CANNOT OPEN FILE\n\n");//Change me
noutram 1:e1cf7663f5ff 497 errorCode(FATAL);
noutram 1:e1cf7663f5ff 498 }
noutram 3:a88838ff33e7 499 //Last message before sampling begins
thomasmorris 28:09b5c46c8afd 500 LCD.Display_Clear();
thomasmorris 35:26b0a9b55d82 501 LCD.Write_String("READY PLAYER");
thomasmorris 31:4a88bf97b53e 502 LCD.DDRAM_Address(0x40);
thomasmorris 35:26b0a9b55d82 503 LCD.Write_String(" One ");
thomasmorris 31:4a88bf97b53e 504 LCD.DDRAM_Address(0x00);
thomasmorris 25:36699ed589ab 505
thomasmorris 35:26b0a9b55d82 506 Network_Init();//Sets up the network
thomasmorris 25:36699ed589ab 507 Sample_Rate = TimerInterval;
chills 24:7d2da96e05ad 508 //Run interrupt
chills 26:78f5e454e59f 509 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 24:7d2da96e05ad 510
thomasmorris 5:2594b953f111 511 t1.start(Sample);
chills 26:78f5e454e59f 512 t2.start(Serial_Comms);
thomasmorris 30:4cde05cc7c4f 513 t3.start(LCD_Output);
thomasmorris 35:26b0a9b55d82 514 t4.start(Network);
thomasmorris 23:3c85d7f657a2 515 t5.start(Serial_Commands);
thomasmorris 25:36699ed589ab 516
thomasmorris 5:2594b953f111 517 //Main thread ID
thomasmorris 25:36699ed589ab 518
thomasmorris 5:2594b953f111 519 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 25:36699ed589ab 520
thomasmorris 5:2594b953f111 521 //Thread ID
thomasmorris 5:2594b953f111 522 id1 = t1.gettid();
thomasmorris 5:2594b953f111 523 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 524 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 525 id4 = t4.gettid();
chills 24:7d2da96e05ad 526 id5 = t5.gettid();
thomasmorris 25:36699ed589ab 527
thomasmorris 25:36699ed589ab 528 while (onBoardSwitch == 0) {
thomasmorris 25:36699ed589ab 529
noutram 1:e1cf7663f5ff 530 }
thomasmorris 25:36699ed589ab 531
noutram 1:e1cf7663f5ff 532 //Close File
chills 15:c1592fc1a501 533 /*
noutram 1:e1cf7663f5ff 534 fclose(fp);
thomasmorris 25:36699ed589ab 535
noutram 1:e1cf7663f5ff 536 //Close down
noutram 1:e1cf7663f5ff 537 sd.deinit();
noutram 1:e1cf7663f5ff 538 printf("Unmounted...\n");
noutram 1:e1cf7663f5ff 539 lcd.cls();
noutram 1:e1cf7663f5ff 540 lcd.printf("Unmounted...\n\n");
chills 15:c1592fc1a501 541 */
thomasmorris 25:36699ed589ab 542
noutram 1:e1cf7663f5ff 543 while(true) {
noutram 1:e1cf7663f5ff 544 greenLED = 1;
noutram 1:e1cf7663f5ff 545 wait(0.5);
noutram 1:e1cf7663f5ff 546 greenLED = 0;
thomasmorris 25:36699ed589ab 547 wait(0.1);
noutram 0:36e89e3ed7c4 548 }
noutram 0:36e89e3ed7c4 549 }