Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Sun Jan 07 23:01:38 2018 +0000
Revision:
39:5c499989d2b9
Parent:
38:8d86e0d8a816
Child:
40:d04aec00504f
Child:
41:859b5e1e3d9a
Read and Read All Working;

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 37:7c4d7f206039 4 Current Verision 18
thomasmorris 36:a0098306fc58 5 Overiew: Working Tasks 1,2,3,5,6,7,8,9,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"
thomasmorris 38:8d86e0d8a816 15 #include "FIFO.hpp"
thomasmorris 38:8d86e0d8a816 16
thomasmorris 38:8d86e0d8a816 17 #define Do_Read_Data 1
thomasmorris 38:8d86e0d8a816 18 #define Dont_Read_Data 0
thomasmorris 38:8d86e0d8a816 19 #define Do_Delete_Data 1
thomasmorris 38:8d86e0d8a816 20 #define Dont_Delete_Data 0
chills 24:7d2da96e05ad 21
chills 33:3b5096f0126a 22 Mutex Time_Lock_Main;
thomasmorris 38:8d86e0d8a816 23 Mutex Data_Buffer_Lock;
thomasmorris 38:8d86e0d8a816 24
thomasmorris 38:8d86e0d8a816 25 int Write_Data(DATA Data_Store, int Write_Pointer)
thomasmorris 38:8d86e0d8a816 26 {
thomasmorris 38:8d86e0d8a816 27 Data_Buffer_Lock.lock();//Mutex Lock
thomasmorris 38:8d86e0d8a816 28
thomasmorris 38:8d86e0d8a816 29 Data_Buffer[Write_Pointer] = Data_Store;
thomasmorris 38:8d86e0d8a816 30 if(Write_Pointer < mailsize - 1)
thomasmorris 38:8d86e0d8a816 31 {
thomasmorris 38:8d86e0d8a816 32 Write_Pointer = Write_Pointer + 1;
thomasmorris 38:8d86e0d8a816 33 }
thomasmorris 38:8d86e0d8a816 34 else
thomasmorris 38:8d86e0d8a816 35 {
thomasmorris 38:8d86e0d8a816 36 Write_Pointer = 0;
thomasmorris 38:8d86e0d8a816 37 }
thomasmorris 38:8d86e0d8a816 38 Data_Buffer_Lock.unlock();
thomasmorris 38:8d86e0d8a816 39 return Write_Pointer;
thomasmorris 38:8d86e0d8a816 40
thomasmorris 38:8d86e0d8a816 41 }
thomasmorris 38:8d86e0d8a816 42 DATA Read_Data(int Read_Pointer)
thomasmorris 38:8d86e0d8a816 43 {
thomasmorris 38:8d86e0d8a816 44 Data_Buffer_Lock.lock();
thomasmorris 38:8d86e0d8a816 45 DATA Temp_Data = Data_Buffer[Read_Pointer];
thomasmorris 38:8d86e0d8a816 46 Data_Buffer_Lock.unlock();
thomasmorris 38:8d86e0d8a816 47
thomasmorris 38:8d86e0d8a816 48 return Temp_Data;
thomasmorris 38:8d86e0d8a816 49 }
thomasmorris 38:8d86e0d8a816 50 void Delete_Data(int Delete_Pointer)
thomasmorris 38:8d86e0d8a816 51 {
thomasmorris 38:8d86e0d8a816 52 Thread::signal_wait(Do_Delete_Data);
thomasmorris 38:8d86e0d8a816 53 Data_Buffer_Lock.lock();
thomasmorris 38:8d86e0d8a816 54 Data_Buffer[Delete_Pointer].set_all_zero();
thomasmorris 38:8d86e0d8a816 55 Data_Buffer_Lock.unlock();
thomasmorris 38:8d86e0d8a816 56 }
thomasmorris 35:26b0a9b55d82 57 void Network()
thomasmorris 8:0e4481b64353 58 {
thomasmorris 35:26b0a9b55d82 59 while(1)
thomasmorris 35:26b0a9b55d82 60 {
thomasmorris 35:26b0a9b55d82 61 Thread::wait(5000);//Waits 5 seconds
thomasmorris 37:7c4d7f206039 62 if(Log_Value==1){cout << "In Network Thread" << endl;} //Log this
thomasmorris 36:a0098306fc58 63
thomasmorris 36:a0098306fc58 64 time_t Time = Data_Active.get_time();
thomasmorris 36:a0098306fc58 65 tm* Time_Pointer = localtime(&Time);
thomasmorris 36:a0098306fc58 66 int temp_day = Time_Pointer->tm_mday;
thomasmorris 36:a0098306fc58 67 int temp_month = (Time_Pointer->tm_mon+1);
thomasmorris 36:a0098306fc58 68 int temp_year = (Time_Pointer->tm_year+1900);
thomasmorris 36:a0098306fc58 69
thomasmorris 36:a0098306fc58 70 int temp_hours = Time_Pointer->tm_hour;
thomasmorris 36:a0098306fc58 71 int temp_minute = Time_Pointer->tm_min;
thomasmorris 36:a0098306fc58 72
thomasmorris 36:a0098306fc58 73 float temp_temperature = Data_Active.get_temperature();
thomasmorris 36:a0098306fc58 74 float temp_pressure = Data_Active.get_pressure();
thomasmorris 36:a0098306fc58 75 float temp_light = Data_Active.get_light();
thomasmorris 36:a0098306fc58 76
thomasmorris 36:a0098306fc58 77
thomasmorris 36:a0098306fc58 78 Networking(temp_day,temp_month,temp_year,temp_hours,temp_minute,temp_temperature,temp_pressure,temp_light);
thomasmorris 35:26b0a9b55d82 79 }
chills 13:db857b3744c6 80 }
thomasmorris 31:4a88bf97b53e 81 void LCD_Write_Year()
thomasmorris 12:536eca338ae8 82 {
chills 33:3b5096f0126a 83 Time_Lock_Main.lock();
thomasmorris 37:7c4d7f206039 84 if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock taken"<<endl;}
chills 33:3b5096f0126a 85 time_t Time = time(NULL);
chills 33:3b5096f0126a 86 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 87 int Years = 1900 + Time_Pointer->tm_year;
chills 33:3b5096f0126a 88 Time_Lock_Main.unlock();
thomasmorris 37:7c4d7f206039 89 if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock released"<<endl;}
thomasmorris 31:4a88bf97b53e 90 stringstream ss;
thomasmorris 31:4a88bf97b53e 91 ss << Years;
thomasmorris 31:4a88bf97b53e 92 string Year_String = ss.str();
thomasmorris 31:4a88bf97b53e 93 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 94 LCD.Write_String("Set Year");
thomasmorris 31:4a88bf97b53e 95 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 96 LCD.Write_String(Year_String);
thomasmorris 30:4cde05cc7c4f 97 }
thomasmorris 25:36699ed589ab 98
thomasmorris 31:4a88bf97b53e 99 void LCD_Write_Month()
thomasmorris 31:4a88bf97b53e 100 {
chills 33:3b5096f0126a 101 Time_Lock_Main.lock();
thomasmorris 37:7c4d7f206039 102 if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock taken"<<endl;}
chills 33:3b5096f0126a 103 time_t Time = time(NULL);
chills 33:3b5096f0126a 104 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 105 int Months = 1 + Time_Pointer->tm_mon;
chills 33:3b5096f0126a 106 Time_Lock_Main.unlock();
thomasmorris 37:7c4d7f206039 107 if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock released"<<endl;}
thomasmorris 31:4a88bf97b53e 108 stringstream ss;
thomasmorris 31:4a88bf97b53e 109 ss << Months;
thomasmorris 31:4a88bf97b53e 110 string Month_String = ss.str();
thomasmorris 31:4a88bf97b53e 111 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 112 LCD.Write_String("Set Month");
thomasmorris 31:4a88bf97b53e 113 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 114 LCD.Write_String(Month_String);
thomasmorris 31:4a88bf97b53e 115 }
thomasmorris 31:4a88bf97b53e 116 void LCD_Write_Day()
thomasmorris 31:4a88bf97b53e 117 {
chills 33:3b5096f0126a 118 Time_Lock_Main.lock();
thomasmorris 37:7c4d7f206039 119 if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock taken"<<endl;}
chills 33:3b5096f0126a 120 time_t Time = time(NULL);
chills 33:3b5096f0126a 121 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 122 int Days = Time_Pointer->tm_mday;
chills 33:3b5096f0126a 123 Time_Lock_Main.unlock();
thomasmorris 37:7c4d7f206039 124 if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock released"<<endl;}
thomasmorris 31:4a88bf97b53e 125 stringstream ss;
thomasmorris 31:4a88bf97b53e 126 ss << Days;
thomasmorris 31:4a88bf97b53e 127 string Day_String = ss.str();
thomasmorris 31:4a88bf97b53e 128 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 129 LCD.Write_String("Set Day");
thomasmorris 31:4a88bf97b53e 130 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 131 LCD.Write_String(Day_String);
thomasmorris 31:4a88bf97b53e 132 }
thomasmorris 31:4a88bf97b53e 133
thomasmorris 31:4a88bf97b53e 134
thomasmorris 31:4a88bf97b53e 135 void LCD_Write_Hour()
thomasmorris 30:4cde05cc7c4f 136 {
chills 33:3b5096f0126a 137 Time_Lock_Main.lock();
thomasmorris 37:7c4d7f206039 138 if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock taken"<<endl;}
chills 33:3b5096f0126a 139 time_t Time = time(NULL);
chills 33:3b5096f0126a 140 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 141 int Hours = Time_Pointer->tm_hour;
chills 33:3b5096f0126a 142 Time_Lock_Main.unlock();
thomasmorris 37:7c4d7f206039 143 if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock released"<<endl;}
thomasmorris 31:4a88bf97b53e 144 stringstream ss;
thomasmorris 31:4a88bf97b53e 145 ss << Hours;
thomasmorris 31:4a88bf97b53e 146 string Hour_String = ss.str();
thomasmorris 31:4a88bf97b53e 147 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 148 LCD.Write_String("Set Hour");
thomasmorris 31:4a88bf97b53e 149 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 150 LCD.Write_String(Hour_String);
thomasmorris 31:4a88bf97b53e 151 }
thomasmorris 31:4a88bf97b53e 152 void LCD_Write_Minute()
thomasmorris 31:4a88bf97b53e 153 {
chills 33:3b5096f0126a 154 Time_Lock_Main.lock();
thomasmorris 37:7c4d7f206039 155 if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock taken"<<endl;}
chills 33:3b5096f0126a 156 time_t Time = time(NULL);
chills 33:3b5096f0126a 157 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 158 int Minutes = Time_Pointer->tm_min;
chills 33:3b5096f0126a 159 Time_Lock_Main.unlock();
thomasmorris 37:7c4d7f206039 160 if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock released"<<endl;}
thomasmorris 31:4a88bf97b53e 161 stringstream ss;
thomasmorris 31:4a88bf97b53e 162 ss << Minutes;
thomasmorris 31:4a88bf97b53e 163 string Minute_String = ss.str();
thomasmorris 31:4a88bf97b53e 164 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 165 LCD.Write_String("Set Minute");
thomasmorris 31:4a88bf97b53e 166 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 167 LCD.Write_String(Minute_String);
thomasmorris 31:4a88bf97b53e 168 }
thomasmorris 31:4a88bf97b53e 169 void LCD_Write_Seconds()
thomasmorris 31:4a88bf97b53e 170 {
chills 33:3b5096f0126a 171 Time_Lock_Main.lock();
thomasmorris 37:7c4d7f206039 172 if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock taken"<<endl;}
chills 33:3b5096f0126a 173 time_t Time = time(NULL);
chills 33:3b5096f0126a 174 tm* Time_Pointer = localtime(&Time);
chills 33:3b5096f0126a 175 int Seconds = Time_Pointer->tm_sec;
chills 33:3b5096f0126a 176 Time_Lock_Main.unlock();
thomasmorris 37:7c4d7f206039 177 if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock released"<<endl;}
thomasmorris 31:4a88bf97b53e 178 stringstream ss;
thomasmorris 31:4a88bf97b53e 179 ss << Seconds;
thomasmorris 31:4a88bf97b53e 180 string Second_String = ss.str();
thomasmorris 31:4a88bf97b53e 181 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 182 LCD.Write_String("Set Second");
thomasmorris 31:4a88bf97b53e 183 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 184 LCD.Write_String(Second_String);
thomasmorris 7:dfe19413fdc2 185 }
thomasmorris 30:4cde05cc7c4f 186
thomasmorris 30:4cde05cc7c4f 187 void LCD_Output()
chills 34:c0b8705f183d 188 {
thomasmorris 30:4cde05cc7c4f 189 while(1)
thomasmorris 29:64b1f95a807c 190 {
thomasmorris 30:4cde05cc7c4f 191 Thread::wait(10);//Dont Delete
thomasmorris 30:4cde05cc7c4f 192 if(mode == 0)//Default mode
thomasmorris 30:4cde05cc7c4f 193 {
thomasmorris 37:7c4d7f206039 194 if(Log_Value == 1){cout << "In mode 0 " << endl;}//Log this
chills 33:3b5096f0126a 195
thomasmorris 35:26b0a9b55d82 196 Thread::wait(Default_Mode_Toggle_Time);
thomasmorris 37:7c4d7f206039 197 if(Log_Value == 1){cout<<"Writing Data to LCD"<<endl;}
chills 34:c0b8705f183d 198 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 199
thomasmorris 30:4cde05cc7c4f 200 LCD.DDRAM_Address(0x00);
thomasmorris 30:4cde05cc7c4f 201 LCD.Write_String("Temp Pres li");
thomasmorris 30:4cde05cc7c4f 202 LCD.DDRAM_Address(0x40);
thomasmorris 30:4cde05cc7c4f 203 LCD.Write_String(LCD_buffer);
thomasmorris 25:36699ed589ab 204
thomasmorris 35:26b0a9b55d82 205 Thread::wait(Default_Mode_Toggle_Time);
thomasmorris 37:7c4d7f206039 206 if(Log_Value == 1){cout<<"Writing Time and Date to LCD"<<endl;}
chills 33:3b5096f0126a 207 Time_Lock_Main.lock();
chills 34:c0b8705f183d 208 time_t Time = Data_Active.get_time();
chills 34:c0b8705f183d 209 tm* Time_Pointer = localtime(&Time);
thomasmorris 30:4cde05cc7c4f 210 LCD.Display_Clear();
chills 33:3b5096f0126a 211 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 212 Time_Lock_Main.unlock();
chills 33:3b5096f0126a 213
thomasmorris 30:4cde05cc7c4f 214 LCD.DDRAM_Address(0x00);
thomasmorris 30:4cde05cc7c4f 215 LCD.Write_String("Current Time:");
thomasmorris 30:4cde05cc7c4f 216 LCD.DDRAM_Address(0x40);
thomasmorris 30:4cde05cc7c4f 217 LCD.Write_String(LCD_buffer);
thomasmorris 31:4a88bf97b53e 218
thomasmorris 37:7c4d7f206039 219 if(Log_Value == 1){cout<<"Checking Switches for next mode"<<endl;}
thomasmorris 31:4a88bf97b53e 220 if(SW1.read() & SW2.read() == 1)
thomasmorris 31:4a88bf97b53e 221 {
thomasmorris 31:4a88bf97b53e 222 mode = 1;
thomasmorris 31:4a88bf97b53e 223 }
thomasmorris 30:4cde05cc7c4f 224 }
thomasmorris 30:4cde05cc7c4f 225 else if(mode == 1)//Choose either date setting or time setting
thomasmorris 30:4cde05cc7c4f 226 {
chills 34:c0b8705f183d 227 if(Log_Value == 1){cout << "In Mode 1" << endl;}
thomasmorris 30:4cde05cc7c4f 228 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 229 while(1)
thomasmorris 31:4a88bf97b53e 230 {
thomasmorris 31:4a88bf97b53e 231 LCD.DDRAM_Address(0x00);
thomasmorris 31:4a88bf97b53e 232 LCD.Write_String("Date Time");
thomasmorris 31:4a88bf97b53e 233 LCD.DDRAM_Address(0x40);
thomasmorris 31:4a88bf97b53e 234 LCD.Write_String("< >");
thomasmorris 31:4a88bf97b53e 235 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 236 if(Log_Value == 1){cout<<"Checking SW1 to go to Date setting"<<endl;}
thomasmorris 37:7c4d7f206039 237 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 238 {
thomasmorris 37:7c4d7f206039 239 mode = 2;//Date Setting
thomasmorris 31:4a88bf97b53e 240 break;
thomasmorris 31:4a88bf97b53e 241 }
thomasmorris 37:7c4d7f206039 242 if(Log_Value == 1){cout<<"Checking SW2 to go to Time setting"<<endl;}
thomasmorris 37:7c4d7f206039 243 if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 244 {
thomasmorris 37:7c4d7f206039 245 mode = 5;//Time Setting
thomasmorris 31:4a88bf97b53e 246 break;
thomasmorris 31:4a88bf97b53e 247 }
thomasmorris 31:4a88bf97b53e 248 }
thomasmorris 30:4cde05cc7c4f 249 }
thomasmorris 30:4cde05cc7c4f 250 else if(mode == 2)//Set the Year
thomasmorris 30:4cde05cc7c4f 251 {
chills 34:c0b8705f183d 252 if(Log_Value == 1){cout << "In Mode 2" << endl;}
thomasmorris 31:4a88bf97b53e 253 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 254 while(1)
thomasmorris 31:4a88bf97b53e 255 {
thomasmorris 32:8f2795716e97 256 LCD_Write_Year();
thomasmorris 31:4a88bf97b53e 257 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 258 if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Month setting"<<endl;}
chills 33:3b5096f0126a 259 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 260 {
chills 33:3b5096f0126a 261 mode = 3;
chills 33:3b5096f0126a 262 break;
chills 33:3b5096f0126a 263 }
thomasmorris 37:7c4d7f206039 264 if(Log_Value == 1){cout<<"Checking SW1 to add Year"<<endl;}
thomasmorris 31:4a88bf97b53e 265 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 266 {
thomasmorris 31:4a88bf97b53e 267 Add_Year();
thomasmorris 31:4a88bf97b53e 268 }
thomasmorris 37:7c4d7f206039 269 if(Log_Value == 1){cout<<"Checking SW2 to subtract Year"<<endl;}
thomasmorris 31:4a88bf97b53e 270 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 271 {
thomasmorris 31:4a88bf97b53e 272 Subtract_Year();
thomasmorris 31:4a88bf97b53e 273 }
thomasmorris 31:4a88bf97b53e 274 LCD_Write_Year();
thomasmorris 31:4a88bf97b53e 275 }
thomasmorris 30:4cde05cc7c4f 276 }
thomasmorris 30:4cde05cc7c4f 277 else if(mode == 3)//Set the Month
thomasmorris 30:4cde05cc7c4f 278 {
chills 34:c0b8705f183d 279 if(Log_Value == 1){cout << "In Mode 3" << endl;}
thomasmorris 31:4a88bf97b53e 280 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 281 while(1)
thomasmorris 32:8f2795716e97 282 {
thomasmorris 32:8f2795716e97 283 LCD_Write_Month();
thomasmorris 31:4a88bf97b53e 284 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 285 if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Day setting"<<endl;}
chills 33:3b5096f0126a 286 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 287 {
chills 33:3b5096f0126a 288 mode = 4;
chills 33:3b5096f0126a 289 break;
thomasmorris 37:7c4d7f206039 290 }
thomasmorris 37:7c4d7f206039 291 if(Log_Value == 1){cout<<"Checking SW1 to add Month"<<endl;}
thomasmorris 31:4a88bf97b53e 292 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 293 {
thomasmorris 31:4a88bf97b53e 294 Add_Month();
thomasmorris 31:4a88bf97b53e 295 }
thomasmorris 37:7c4d7f206039 296 if(Log_Value == 1){cout<<"Checking SW2 to subtract Month"<<endl;}
thomasmorris 31:4a88bf97b53e 297 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 298 {
thomasmorris 31:4a88bf97b53e 299 Subtract_Month();
thomasmorris 32:8f2795716e97 300 }
chills 33:3b5096f0126a 301
thomasmorris 31:4a88bf97b53e 302 }
thomasmorris 30:4cde05cc7c4f 303 }
thomasmorris 30:4cde05cc7c4f 304 else if(mode == 4)//Set the Day
thomasmorris 30:4cde05cc7c4f 305 {
chills 34:c0b8705f183d 306 if(Log_Value == 1){cout << "In Mode 4" << endl;}
thomasmorris 31:4a88bf97b53e 307 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 308 while(1)
thomasmorris 32:8f2795716e97 309 {
thomasmorris 32:8f2795716e97 310 LCD_Write_Day();
thomasmorris 31:4a88bf97b53e 311 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 312 if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;}
chills 33:3b5096f0126a 313 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 314 {
chills 33:3b5096f0126a 315 mode = 0;
chills 33:3b5096f0126a 316 break;
chills 33:3b5096f0126a 317 }
thomasmorris 37:7c4d7f206039 318 if(Log_Value == 1){cout<<"Checking SW1 to add Day"<<endl;}
thomasmorris 31:4a88bf97b53e 319 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 320 {
thomasmorris 31:4a88bf97b53e 321 Add_Day();
thomasmorris 31:4a88bf97b53e 322 }
thomasmorris 37:7c4d7f206039 323 if(Log_Value == 1){cout<<"Checking SW2 to subtract Day"<<endl;}
thomasmorris 31:4a88bf97b53e 324 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 325 {
thomasmorris 31:4a88bf97b53e 326 Subtract_Day();
thomasmorris 32:8f2795716e97 327 }
thomasmorris 31:4a88bf97b53e 328 }
thomasmorris 30:4cde05cc7c4f 329 }
thomasmorris 30:4cde05cc7c4f 330 else if(mode == 5)//Set the Hour
thomasmorris 30:4cde05cc7c4f 331 {
chills 34:c0b8705f183d 332 if(Log_Value == 1){cout << "In Mode 5" << endl;}
thomasmorris 31:4a88bf97b53e 333 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 334 while(1)
thomasmorris 31:4a88bf97b53e 335 {
thomasmorris 32:8f2795716e97 336 LCD_Write_Hour();
thomasmorris 32:8f2795716e97 337 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 338 if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Minute setting"<<endl;}
chills 33:3b5096f0126a 339 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 340 {
chills 33:3b5096f0126a 341 mode = 6;
chills 33:3b5096f0126a 342 break;
thomasmorris 37:7c4d7f206039 343 }
thomasmorris 37:7c4d7f206039 344 if(Log_Value == 1){cout<<"Checking SW1 to add Hour"<<endl;}
thomasmorris 31:4a88bf97b53e 345 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 346 {
thomasmorris 31:4a88bf97b53e 347 Add_Hour();
thomasmorris 31:4a88bf97b53e 348 }
thomasmorris 37:7c4d7f206039 349 if(Log_Value == 1){cout<<"Checking SW2 to subtract Hour"<<endl;}
thomasmorris 31:4a88bf97b53e 350 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 351 {
thomasmorris 31:4a88bf97b53e 352 Subtract_Hour();
thomasmorris 31:4a88bf97b53e 353 }
thomasmorris 31:4a88bf97b53e 354 }
thomasmorris 30:4cde05cc7c4f 355 }
thomasmorris 30:4cde05cc7c4f 356 else if(mode == 6)//Set the Minute
thomasmorris 30:4cde05cc7c4f 357 {
chills 34:c0b8705f183d 358 if(Log_Value == 1){cout << "In Mode 6" << endl;}
thomasmorris 31:4a88bf97b53e 359 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 360 while(1)
thomasmorris 31:4a88bf97b53e 361 {
thomasmorris 32:8f2795716e97 362 LCD_Write_Minute();
thomasmorris 32:8f2795716e97 363 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 364 if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Seconds setting"<<endl;}
chills 33:3b5096f0126a 365 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 366 {
chills 33:3b5096f0126a 367 mode = 7;
chills 33:3b5096f0126a 368 break;
chills 33:3b5096f0126a 369 }
thomasmorris 37:7c4d7f206039 370 if(Log_Value == 1){cout<<"Checking SW1 to add Minute"<<endl;}
thomasmorris 31:4a88bf97b53e 371 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 372 {
thomasmorris 31:4a88bf97b53e 373 Add_Minute();
thomasmorris 31:4a88bf97b53e 374 }
thomasmorris 37:7c4d7f206039 375 if(Log_Value == 1){cout<<"Checking SW2 to subtract Minute"<<endl;}
thomasmorris 31:4a88bf97b53e 376 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 377 {
thomasmorris 31:4a88bf97b53e 378 Subtract_Minute();
thomasmorris 32:8f2795716e97 379 }
thomasmorris 31:4a88bf97b53e 380 }
thomasmorris 30:4cde05cc7c4f 381 }
thomasmorris 30:4cde05cc7c4f 382 else if(mode == 7)//Set the Seconds
thomasmorris 30:4cde05cc7c4f 383 {
chills 34:c0b8705f183d 384 if(Log_Value == 1){cout << "In Mode 7" << endl;}
thomasmorris 31:4a88bf97b53e 385 LCD.Display_Clear();
thomasmorris 31:4a88bf97b53e 386 while(1)
thomasmorris 31:4a88bf97b53e 387 {
thomasmorris 32:8f2795716e97 388 LCD_Write_Seconds();
thomasmorris 32:8f2795716e97 389 Thread::wait(1000);
thomasmorris 37:7c4d7f206039 390 if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;}
chills 33:3b5096f0126a 391 if(SW1.read() & SW2.read() == 1)
chills 33:3b5096f0126a 392 {
chills 33:3b5096f0126a 393 mode = 0;
chills 33:3b5096f0126a 394 break;
thomasmorris 37:7c4d7f206039 395 }
thomasmorris 37:7c4d7f206039 396 if(Log_Value == 1){cout<<"Checking SW1 to add Second"<<endl;}
thomasmorris 31:4a88bf97b53e 397 if(SW1.read() == 1 & SW2.read() == 0)
thomasmorris 31:4a88bf97b53e 398 {
thomasmorris 31:4a88bf97b53e 399 Add_Second();
thomasmorris 31:4a88bf97b53e 400 }
thomasmorris 37:7c4d7f206039 401 if(Log_Value == 1){cout<<"Checking SW1 to subtract Second"<<endl;}
thomasmorris 31:4a88bf97b53e 402 else if(SW2.read() == 1 & SW1.read() == 0)
thomasmorris 31:4a88bf97b53e 403 {
thomasmorris 31:4a88bf97b53e 404 Subtract_Second();
thomasmorris 32:8f2795716e97 405 }
thomasmorris 31:4a88bf97b53e 406 }
thomasmorris 30:4cde05cc7c4f 407 }
thomasmorris 30:4cde05cc7c4f 408 else
thomasmorris 30:4cde05cc7c4f 409 {
thomasmorris 37:7c4d7f206039 410 if(Log_Value == 1){cout<<"Mode Error occured mode now set to 0"<<endl;}
thomasmorris 35:26b0a9b55d82 411 mode = 0;
thomasmorris 7:dfe19413fdc2 412 }
thomasmorris 7:dfe19413fdc2 413 }
thomasmorris 7:dfe19413fdc2 414 }
thomasmorris 29:64b1f95a807c 415 void Serial_Commands()//Used for getting input from the user to determine the opperations to perform
thomasmorris 22:eb4cc12087b2 416 {
thomasmorris 37:7c4d7f206039 417
thomasmorris 38:8d86e0d8a816 418 char input[100];
thomasmorris 25:36699ed589ab 419 while(1) {
thomasmorris 38:8d86e0d8a816 420
thomasmorris 37:7c4d7f206039 421 if(Log_Value == 1){cout<<"In Serial_Commands"<<endl;}
thomasmorris 38:8d86e0d8a816 422 for (int x = 0; x < 100; x++){input[x] = ' ';};
thomasmorris 38:8d86e0d8a816 423
thomasmorris 37:7c4d7f206039 424 cout << "Please type in a command" << endl;//Log this
chills 34:c0b8705f183d 425
thomasmorris 38:8d86e0d8a816 426 cin.getline(input,sizeof(input),'\r');
thomasmorris 38:8d86e0d8a816 427
thomasmorris 38:8d86e0d8a816 428 //READ ALL FIX THIS
thomasmorris 39:5c499989d2b9 429 if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L')
thomasmorris 22:eb4cc12087b2 430 {
thomasmorris 39:5c499989d2b9 431
thomasmorris 38:8d86e0d8a816 432 if(Log_Value == 1){cout<<"READ ALL Confirmed"<<endl;}
thomasmorris 39:5c499989d2b9 433
thomasmorris 39:5c499989d2b9 434 Data_Buffer_Lock.lock();
thomasmorris 39:5c499989d2b9 435 int Start_Address_Read_All = Write_Pointer;
thomasmorris 39:5c499989d2b9 436 Data_Buffer_Lock.unlock();
thomasmorris 39:5c499989d2b9 437
thomasmorris 39:5c499989d2b9 438 for(int x_Read_All = (Start_Address_Read_All - mailsize); x_Read_All != Start_Address_Read_All; x_Read_All = x_Read_All )
thomasmorris 39:5c499989d2b9 439 {
thomasmorris 39:5c499989d2b9 440 if(x_Read_All < 0){x_Read_All = x_Read_All + mailsize;}
thomasmorris 39:5c499989d2b9 441 else {x_Read_All = x_Read_All;}
thomasmorris 39:5c499989d2b9 442
thomasmorris 39:5c499989d2b9 443 DATA Serial_Read_Data = Read_Data(x_Read_All);
thomasmorris 39:5c499989d2b9 444
thomasmorris 39:5c499989d2b9 445 time_t Time = Serial_Read_Data.get_time();
thomasmorris 39:5c499989d2b9 446 tm* Time_Pointer = localtime(&Time);
thomasmorris 39:5c499989d2b9 447
thomasmorris 39:5c499989d2b9 448 strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string
thomasmorris 39:5c499989d2b9 449 pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));
thomasmorris 39:5c499989d2b9 450 pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time
thomasmorris 39:5c499989d2b9 451 pc.printf("Temperature = %f\t", Serial_Read_Data.get_temperature()); //Print Temperature
thomasmorris 39:5c499989d2b9 452 pc.printf("Pressure = %f\t", Serial_Read_Data.get_pressure()); //Print Pressure
thomasmorris 39:5c499989d2b9 453 pc.printf("Light = %f\n\r", Serial_Read_Data.get_light()); //Print Light
thomasmorris 39:5c499989d2b9 454
thomasmorris 39:5c499989d2b9 455 if(x_Read_All == mailsize - 1){x_Read_All = 0;}
thomasmorris 39:5c499989d2b9 456 else {x_Read_All = x_Read_All + 1;}
thomasmorris 39:5c499989d2b9 457 }
thomasmorris 38:8d86e0d8a816 458 }
thomasmorris 38:8d86e0d8a816 459
thomasmorris 38:8d86e0d8a816 460 //DELETE ALL FIX THIS
thomasmorris 38:8d86e0d8a816 461 else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ' & input[7] == 'A' & input[8] == 'L' & input[9] == 'L' & input[10] == ' ')
chills 26:78f5e454e59f 462 {
thomasmorris 35:26b0a9b55d82 463 Sampling_Timer.detach();
thomasmorris 35:26b0a9b55d82 464 Console_Output_Timer.detach();
thomasmorris 38:8d86e0d8a816 465 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
thomasmorris 38:8d86e0d8a816 466 cout << "Sampling Restarted" << endl;
thomasmorris 38:8d86e0d8a816 467 if(Log_Value == 1){cout<<"DELETE ALL Confirmed"<<endl;}
thomasmorris 38:8d86e0d8a816 468 }
thomasmorris 38:8d86e0d8a816 469
thomasmorris 38:8d86e0d8a816 470 //READ look into this
thomasmorris 38:8d86e0d8a816 471 else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ')
thomasmorris 38:8d86e0d8a816 472 {
thomasmorris 38:8d86e0d8a816 473 int NumberOfChars = 0; int ArrayAddress = 0; string ReadNumber; int NumberToRead;
thomasmorris 38:8d86e0d8a816 474 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;}
thomasmorris 38:8d86e0d8a816 475 for(int x=5; x < NumberOfChars; x++){ReadNumber += input[x];}
thomasmorris 38:8d86e0d8a816 476 stringstream Number(ReadNumber);
thomasmorris 38:8d86e0d8a816 477 Number >> NumberToRead;
thomasmorris 38:8d86e0d8a816 478
thomasmorris 39:5c499989d2b9 479
thomasmorris 39:5c499989d2b9 480 if(Log_Value == 1){cout<<"Getting Data"<<endl;}
thomasmorris 39:5c499989d2b9 481
thomasmorris 39:5c499989d2b9 482 Data_Buffer_Lock.lock();
thomasmorris 39:5c499989d2b9 483 int Start_Address = Write_Pointer;
thomasmorris 39:5c499989d2b9 484 Data_Buffer_Lock.unlock();
thomasmorris 39:5c499989d2b9 485
thomasmorris 39:5c499989d2b9 486 for(int x = (Start_Address - NumberToRead); x != Start_Address; x = x )
thomasmorris 39:5c499989d2b9 487 {
thomasmorris 39:5c499989d2b9 488 if(x < 0){x = x + mailsize;}
thomasmorris 39:5c499989d2b9 489 else {x = x;}
thomasmorris 39:5c499989d2b9 490
thomasmorris 39:5c499989d2b9 491 DATA Serial_Read_Data = Read_Data(x);
thomasmorris 39:5c499989d2b9 492
thomasmorris 39:5c499989d2b9 493 time_t Time = Serial_Read_Data.get_time();
thomasmorris 39:5c499989d2b9 494 tm* Time_Pointer = localtime(&Time);
thomasmorris 39:5c499989d2b9 495
thomasmorris 39:5c499989d2b9 496 strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string
thomasmorris 39:5c499989d2b9 497 pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));
thomasmorris 39:5c499989d2b9 498 pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time
thomasmorris 39:5c499989d2b9 499 pc.printf("Temperature = %f\t", Serial_Read_Data.get_temperature()); //Print Temperature
thomasmorris 39:5c499989d2b9 500 pc.printf("Pressure = %f\t", Serial_Read_Data.get_pressure()); //Print Pressure
thomasmorris 39:5c499989d2b9 501 pc.printf("Light = %f\n\r", Serial_Read_Data.get_light()); //Print Light
thomasmorris 39:5c499989d2b9 502
thomasmorris 39:5c499989d2b9 503 if(x == mailsize - 1){x = 0;}
thomasmorris 39:5c499989d2b9 504 else {x = x + 1;}
thomasmorris 39:5c499989d2b9 505
thomasmorris 39:5c499989d2b9 506 Green_led.Toggle();
thomasmorris 39:5c499989d2b9 507 }
thomasmorris 39:5c499989d2b9 508 //Serial_Comms_Data_Get();
thomasmorris 38:8d86e0d8a816 509 if(Log_Value == 1){cout << "Read " << NumberToRead << " samples" << endl;}
thomasmorris 38:8d86e0d8a816 510
thomasmorris 25:36699ed589ab 511 }
thomasmorris 38:8d86e0d8a816 512
thomasmorris 38:8d86e0d8a816 513 //DELETE look into this
thomasmorris 38:8d86e0d8a816 514 else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ')
thomasmorris 22:eb4cc12087b2 515 {
chills 26:78f5e454e59f 516 Sampling_Timer.detach();
chills 26:78f5e454e59f 517 Console_Output_Timer.detach();
thomasmorris 38:8d86e0d8a816 518
thomasmorris 38:8d86e0d8a816 519
thomasmorris 38:8d86e0d8a816 520 int NumberOfChars = 0; int ArrayAddress = 0; string DeleteNumber; int NumberToDelete;
thomasmorris 38:8d86e0d8a816 521 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;}
thomasmorris 38:8d86e0d8a816 522 for(int x=7; x < NumberOfChars; x++){DeleteNumber += input[x];}
thomasmorris 38:8d86e0d8a816 523 stringstream Number(DeleteNumber);
thomasmorris 38:8d86e0d8a816 524 Number >> NumberToDelete;
thomasmorris 38:8d86e0d8a816 525
thomasmorris 38:8d86e0d8a816 526 if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;}
thomasmorris 38:8d86e0d8a816 527
chills 26:78f5e454e59f 528 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 26:78f5e454e59f 529 cout << "Sampling Restarted" << endl;
chills 34:c0b8705f183d 530 }
thomasmorris 38:8d86e0d8a816 531
thomasmorris 38:8d86e0d8a816 532 //STATE
thomasmorris 38:8d86e0d8a816 533 else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'A' & input[3] == 'T' & input[4] == 'E' & input[5] == ' ')
chills 34:c0b8705f183d 534 {
thomasmorris 38:8d86e0d8a816 535 int NumberOfChars = 0; int ArrayAddress = 0; string StateNumber; int NumberToState;
thomasmorris 38:8d86e0d8a816 536 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;}
thomasmorris 38:8d86e0d8a816 537 for(int x=6; x < NumberOfChars; x++){StateNumber += input[x];}
thomasmorris 38:8d86e0d8a816 538 stringstream Number(StateNumber);
thomasmorris 38:8d86e0d8a816 539 Number >> NumberToState;
thomasmorris 38:8d86e0d8a816 540
thomasmorris 38:8d86e0d8a816 541 if(NumberToState==0){Sampling_Timer.detach(); Console_Output_Timer.detach();}
thomasmorris 38:8d86e0d8a816 542 if(NumberToState==1){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);}
chills 26:78f5e454e59f 543 }
thomasmorris 38:8d86e0d8a816 544
thomasmorris 38:8d86e0d8a816 545 //SETDATE
thomasmorris 38:8d86e0d8a816 546 else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'D' & input[4] == 'A' & input[5] == 'T' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ')
thomasmorris 38:8d86e0d8a816 547 {
thomasmorris 38:8d86e0d8a816 548 int NumberOfChars = 0; int ArrayAddress = 0;
thomasmorris 38:8d86e0d8a816 549 string DayNumber, MonthNumber, YearNumber;
thomasmorris 38:8d86e0d8a816 550 int NumberToDay, NumberToMonth, NumberToYear;
thomasmorris 38:8d86e0d8a816 551
thomasmorris 38:8d86e0d8a816 552 for(int x=8; x < 10; x++){DayNumber += input[x];}
thomasmorris 38:8d86e0d8a816 553 stringstream Number_1(DayNumber);
thomasmorris 38:8d86e0d8a816 554 Number_1 >> NumberToDay;
thomasmorris 38:8d86e0d8a816 555
thomasmorris 38:8d86e0d8a816 556 for(int x=11; x < 13; x++){MonthNumber += input[x];}
thomasmorris 38:8d86e0d8a816 557 stringstream Number_2(MonthNumber);
thomasmorris 38:8d86e0d8a816 558 Number_2 >> NumberToMonth;
thomasmorris 38:8d86e0d8a816 559
thomasmorris 38:8d86e0d8a816 560 for(int x=14; x < 18; x++){YearNumber += input[x];}
thomasmorris 38:8d86e0d8a816 561 stringstream Number_3(YearNumber);
thomasmorris 38:8d86e0d8a816 562 Number_3 >> NumberToYear;
thomasmorris 38:8d86e0d8a816 563
thomasmorris 38:8d86e0d8a816 564 set_new_date(NumberToDay,NumberToMonth,NumberToYear);
thomasmorris 38:8d86e0d8a816 565 }
thomasmorris 38:8d86e0d8a816 566
thomasmorris 38:8d86e0d8a816 567 //SETTIME
thomasmorris 38:8d86e0d8a816 568 else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == 'I' & input[5] == 'M' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ')
thomasmorris 22:eb4cc12087b2 569 {
thomasmorris 38:8d86e0d8a816 570 int NumberOfChars = 0; int ArrayAddress = 0;
thomasmorris 38:8d86e0d8a816 571 string HourNumber, MinuteNumber, SecondNumber;
thomasmorris 38:8d86e0d8a816 572 int NumberToHour, NumberToMinute, NumberToSecond;
thomasmorris 38:8d86e0d8a816 573
thomasmorris 38:8d86e0d8a816 574 for(int x=8; x < 10; x++){HourNumber += input[x];}
thomasmorris 38:8d86e0d8a816 575 stringstream Number_1(HourNumber);
thomasmorris 38:8d86e0d8a816 576 Number_1 >> NumberToHour;
thomasmorris 38:8d86e0d8a816 577
thomasmorris 38:8d86e0d8a816 578 for(int x=11; x < 13; x++){MinuteNumber += input[x];}
thomasmorris 38:8d86e0d8a816 579 stringstream Number_2(MinuteNumber);
thomasmorris 38:8d86e0d8a816 580 Number_2 >> NumberToMinute;
thomasmorris 38:8d86e0d8a816 581
thomasmorris 38:8d86e0d8a816 582 for(int x=14; x < 16; x++){SecondNumber += input[x];}
thomasmorris 38:8d86e0d8a816 583 stringstream Number_3(SecondNumber);
thomasmorris 38:8d86e0d8a816 584 Number_3 >> NumberToSecond;
thomasmorris 38:8d86e0d8a816 585
thomasmorris 38:8d86e0d8a816 586 set_new_time(NumberToHour,NumberToMinute,NumberToSecond);
thomasmorris 38:8d86e0d8a816 587 }
thomasmorris 38:8d86e0d8a816 588
thomasmorris 38:8d86e0d8a816 589 //SETT
thomasmorris 38:8d86e0d8a816 590 else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ')
thomasmorris 38:8d86e0d8a816 591 {
thomasmorris 38:8d86e0d8a816 592
thomasmorris 38:8d86e0d8a816 593 int NumberOfChars = 0; int ArrayAddress = 0; string SettNumber; int NumberToSett;
thomasmorris 38:8d86e0d8a816 594 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;}
thomasmorris 38:8d86e0d8a816 595 for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];}
thomasmorris 38:8d86e0d8a816 596 stringstream Number(SettNumber);
thomasmorris 38:8d86e0d8a816 597 Number >> NumberToSett;
thomasmorris 38:8d86e0d8a816 598
thomasmorris 38:8d86e0d8a816 599 if(NumberToSett >= 1){Sample_Rate = NumberToSett;}
chills 26:78f5e454e59f 600
chills 26:78f5e454e59f 601 Sampling_Timer.detach();
chills 26:78f5e454e59f 602 Console_Output_Timer.detach();
chills 26:78f5e454e59f 603 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
thomasmorris 38:8d86e0d8a816 604 }
thomasmorris 38:8d86e0d8a816 605
thomasmorris 38:8d86e0d8a816 606 //LOGGING
thomasmorris 38:8d86e0d8a816 607 else if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G' & input[7] == ' ')
thomasmorris 38:8d86e0d8a816 608 {
thomasmorris 38:8d86e0d8a816 609 int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging;
thomasmorris 38:8d86e0d8a816 610 while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;}
thomasmorris 38:8d86e0d8a816 611 for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];}
thomasmorris 38:8d86e0d8a816 612 stringstream Number(LoggingNumber);
thomasmorris 38:8d86e0d8a816 613 Number >> NumberToLogging;
thomasmorris 38:8d86e0d8a816 614
thomasmorris 38:8d86e0d8a816 615 cout << "Successfully entered logging" << endl;
thomasmorris 38:8d86e0d8a816 616 cout << NumberToLogging << endl;
thomasmorris 38:8d86e0d8a816 617 Log_Value = NumberToLogging;
thomasmorris 25:36699ed589ab 618 }
thomasmorris 38:8d86e0d8a816 619
thomasmorris 38:8d86e0d8a816 620 //HELP
thomasmorris 38:8d86e0d8a816 621 else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P')// Use this to display all of the availble commands
thomasmorris 25:36699ed589ab 622 {
thomasmorris 25:36699ed589ab 623 HELP();
thomasmorris 22:eb4cc12087b2 624 }
thomasmorris 38:8d86e0d8a816 625
thomasmorris 38:8d86e0d8a816 626 //STOP
thomasmorris 38:8d86e0d8a816 627 else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'O' & input[3] == 'P')
chills 26:78f5e454e59f 628 {
thomasmorris 28:09b5c46c8afd 629 Console_Output_Timer.detach(); //Stops Sampling
chills 26:78f5e454e59f 630 }
thomasmorris 25:36699ed589ab 631 else
thomasmorris 22:eb4cc12087b2 632 {
chills 26:78f5e454e59f 633 cout << "Please enter an acceptable command" << endl;
thomasmorris 22:eb4cc12087b2 634 }
thomasmorris 22:eb4cc12087b2 635 }
thomasmorris 22:eb4cc12087b2 636 }
thomasmorris 38:8d86e0d8a816 637 void Serial_Comms_Data_Get()
thomasmorris 29:64b1f95a807c 638 {
thomasmorris 37:7c4d7f206039 639 if(Log_Value == 1){cout<<"Getting Data"<<endl;}
chills 34:c0b8705f183d 640 time_t Time = Data_Active.get_time();
chills 34:c0b8705f183d 641 tm* Time_Pointer = localtime(&Time);
chills 34:c0b8705f183d 642 strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string
chills 34:c0b8705f183d 643 pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));
chills 34:c0b8705f183d 644 pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time
chills 34:c0b8705f183d 645 pc.printf("Temperature = %f\t", Data_Active.get_temperature()); //Print Temperature
chills 34:c0b8705f183d 646 pc.printf("Pressure = %f\t", Data_Active.get_pressure()); //Print Pressure
chills 34:c0b8705f183d 647 pc.printf("Light = %f\n\r", Data_Active.get_light()); //Print Light
thomasmorris 29:64b1f95a807c 648
thomasmorris 29:64b1f95a807c 649 Green_led.Toggle();
chills 34:c0b8705f183d 650
thomasmorris 29:64b1f95a807c 651 }
thomasmorris 5:2594b953f111 652
chills 26:78f5e454e59f 653 void Sampling_ISR() {t1.signal_set(SamplingTime);}
chills 26:78f5e454e59f 654
chills 26:78f5e454e59f 655
thomasmorris 5:2594b953f111 656 void Sample()//Samples the hardware and prints the result to the LCD
thomasmorris 5:2594b953f111 657 {
thomasmorris 30:4cde05cc7c4f 658 while(1)
thomasmorris 30:4cde05cc7c4f 659 {
chills 10:46946784326d 660 Thread::signal_wait(SamplingTime); //Set the time between samples
thomasmorris 37:7c4d7f206039 661 if(Log_Value == 1){cout<<"Sample Time"<<endl;}
chills 34:c0b8705f183d 662 Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature
chills 34:c0b8705f183d 663 Data_Active.set_pressure(sensor.getPressure()); //Read Pressure
chills 34:c0b8705f183d 664 Data_Active.set_light(adcIn.read()); //Read Light
chills 33:3b5096f0126a 665
chills 33:3b5096f0126a 666 Time_Lock_Main.lock();
chills 34:c0b8705f183d 667 time_t buffer_time = time(NULL);
chills 33:3b5096f0126a 668 Time_Lock_Main.unlock();
thomasmorris 25:36699ed589ab 669
chills 34:c0b8705f183d 670 Data_Active.set_time(buffer_time);
thomasmorris 25:36699ed589ab 671
thomasmorris 5:2594b953f111 672 Red_led.Toggle();
thomasmorris 39:5c499989d2b9 673 Write_Pointer = Write_Data(Data_Active,Write_Pointer);
thomasmorris 5:2594b953f111 674 t1.signal_set(NotSamplingTime);
thomasmorris 37:7c4d7f206039 675 if(Log_Value == 1){cout<<"New Sample avaliable"<<endl;}
thomasmorris 5:2594b953f111 676 }
thomasmorris 25:36699ed589ab 677 }
thomasmorris 25:36699ed589ab 678 int main()
thomasmorris 25:36699ed589ab 679 {
thomasmorris 37:7c4d7f206039 680 set_time(1515352584); //Set RTC time to December 10 2017
thomasmorris 30:4cde05cc7c4f 681
chills 10:46946784326d 682 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 25:36699ed589ab 683
chills 20:cbb71f84cff9 684 LCD.Initialise();
thomasmorris 28:09b5c46c8afd 685 LCD.DDRAM_Address(0x00);
thomasmorris 29:64b1f95a807c 686
thomasmorris 25:36699ed589ab 687 post(); //Power on Self Test
thomasmorris 25:36699ed589ab 688
noutram 3:a88838ff33e7 689 //Initialise the SD card (this needs to move)
noutram 1:e1cf7663f5ff 690 if ( sd.init() != 0) {
noutram 1:e1cf7663f5ff 691 printf("Init failed \n");
thomasmorris 28:09b5c46c8afd 692 LCD.Display_Clear();
thomasmorris 28:09b5c46c8afd 693 LCD.Write_String("CANNOT INIT SD"); //Change me
noutram 1:e1cf7663f5ff 694 errorCode(FATAL);
thomasmorris 25:36699ed589ab 695 }
noutram 1:e1cf7663f5ff 696 //Create a filing system for SD Card
thomasmorris 25:36699ed589ab 697 FATFileSystem fs("sd", &sd);
noutram 0:36e89e3ed7c4 698
noutram 1:e1cf7663f5ff 699 //Open to WRITE
noutram 1:e1cf7663f5ff 700 FILE* fp = fopen("/sd/test.csv","a");
noutram 1:e1cf7663f5ff 701 if (fp == NULL) {
noutram 1:e1cf7663f5ff 702 error("Could not open file for write\n");
thomasmorris 28:09b5c46c8afd 703 LCD.Display_Clear();
thomasmorris 37:7c4d7f206039 704 LCD.Write_String("CANNOT OPEN FILE");
noutram 1:e1cf7663f5ff 705 errorCode(FATAL);
noutram 1:e1cf7663f5ff 706 }
thomasmorris 37:7c4d7f206039 707 int network_temp;
thomasmorris 37:7c4d7f206039 708 network_temp = Network_Init();
thomasmorris 37:7c4d7f206039 709 if(network_temp == 1)//Sets up the network and checks if the network cable is not pluged in
thomasmorris 37:7c4d7f206039 710 {
thomasmorris 37:7c4d7f206039 711 error("Could not access network");
thomasmorris 37:7c4d7f206039 712 LCD.Display_Clear();
thomasmorris 37:7c4d7f206039 713 LCD.Write_String("Could not access network");
thomasmorris 37:7c4d7f206039 714 errorCode(FATAL);
thomasmorris 37:7c4d7f206039 715 }
noutram 3:a88838ff33e7 716 //Last message before sampling begins
thomasmorris 28:09b5c46c8afd 717 LCD.Display_Clear();
thomasmorris 35:26b0a9b55d82 718 LCD.Write_String("READY PLAYER");
thomasmorris 31:4a88bf97b53e 719 LCD.DDRAM_Address(0x40);
thomasmorris 35:26b0a9b55d82 720 LCD.Write_String(" One ");
thomasmorris 31:4a88bf97b53e 721 LCD.DDRAM_Address(0x00);
thomasmorris 25:36699ed589ab 722
thomasmorris 25:36699ed589ab 723 Sample_Rate = TimerInterval;
chills 24:7d2da96e05ad 724 //Run interrupt
chills 26:78f5e454e59f 725 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 24:7d2da96e05ad 726
thomasmorris 5:2594b953f111 727 t1.start(Sample);
thomasmorris 30:4cde05cc7c4f 728 t3.start(LCD_Output);
thomasmorris 35:26b0a9b55d82 729 t4.start(Network);
thomasmorris 23:3c85d7f657a2 730 t5.start(Serial_Commands);
thomasmorris 25:36699ed589ab 731
thomasmorris 5:2594b953f111 732 //Main thread ID
thomasmorris 25:36699ed589ab 733
thomasmorris 5:2594b953f111 734 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 25:36699ed589ab 735
thomasmorris 5:2594b953f111 736 //Thread ID
thomasmorris 5:2594b953f111 737 id1 = t1.gettid();
thomasmorris 5:2594b953f111 738 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 739 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 740 id4 = t4.gettid();
chills 24:7d2da96e05ad 741 id5 = t5.gettid();
thomasmorris 25:36699ed589ab 742
thomasmorris 25:36699ed589ab 743 while (onBoardSwitch == 0) {
thomasmorris 25:36699ed589ab 744
noutram 1:e1cf7663f5ff 745 }
thomasmorris 25:36699ed589ab 746
noutram 1:e1cf7663f5ff 747 //Close File
chills 15:c1592fc1a501 748 /*
noutram 1:e1cf7663f5ff 749 fclose(fp);
thomasmorris 25:36699ed589ab 750
noutram 1:e1cf7663f5ff 751 //Close down
noutram 1:e1cf7663f5ff 752 sd.deinit();
noutram 1:e1cf7663f5ff 753 printf("Unmounted...\n");
noutram 1:e1cf7663f5ff 754 lcd.cls();
noutram 1:e1cf7663f5ff 755 lcd.printf("Unmounted...\n\n");
chills 15:c1592fc1a501 756 */
thomasmorris 25:36699ed589ab 757
noutram 1:e1cf7663f5ff 758 while(true) {
noutram 1:e1cf7663f5ff 759 greenLED = 1;
noutram 1:e1cf7663f5ff 760 wait(0.5);
noutram 1:e1cf7663f5ff 761 greenLED = 0;
thomasmorris 25:36699ed589ab 762 wait(0.1);
noutram 0:36e89e3ed7c4 763 }
noutram 0:36e89e3ed7c4 764 }