Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 29:64b1f95a807c
- Parent:
- 28:09b5c46c8afd
- Child:
- 30:4cde05cc7c4f
diff -r 09b5c46c8afd -r 64b1f95a807c main.cpp --- a/main.cpp Wed Jan 03 21:12:25 2018 +0000 +++ b/main.cpp Wed Jan 03 22:00:07 2018 +0000 @@ -1,22 +1,20 @@ /* ELEC 351 Group T Team Members : Christopher Hills, Thomas Morris -Current Verision 3 -Overiew: Working Tasks 1,5,7 +Current Verision 12 +Overiew: Working Tasks 1,2,4,5,6,7,8,10,11,12,13 Last Revision: Added Mail Box to serial Todo: make a mailbox within SD card, LCD, network so they can be used from within Fix the network so it uses the mail box data. -Place the LCD write functions in their own function */ -//Includes and Definitions #include "SETUP.hpp" -void Network() //Interrupt service routine for handling the timeout +void Network()//Interrupt service routine for handling the timeout { - osEvent evt_network = mail_box.get(); //Get the latest entry from "mail_box" + osEvent evt_network = mail_box.get(); //Get the latest entry from "mail_box" if (evt_network.status == osEventMail) { DATA *Rec_Data_Network = (DATA*)evt_network.value.p; //Create pointer to mailbox @@ -37,9 +35,9 @@ sw1TimeOut.detach(); //Stop the timeout counter firing SW1.fall(&SW1FallingEdge); //Now wait for a falling edge } -void SDWrite()//End of skype chat +void SDWrite() { - osEvent evt_sd = mail_box.get(); //Get the latest entry from "mail_box" + osEvent evt_sd = mail_box.get(); //Get the latest entry from "mail_box" if (evt_sd.status == osEventMail) { DATA *Rec_Data_SD = (DATA*)evt_sd.value.p; //Create pointer to mailbox @@ -67,10 +65,8 @@ } void ModeSelection() { - while(1) { - - //Thread::wait(1000); - + while(1) + { osEvent evt_lcd = mail_box.get(); //Get the latest entry from "mail_box" if (evt_lcd.status == osEventMail) { @@ -86,20 +82,16 @@ if(mode == 0) { //Print values to the LCD //Write new data to LCD (not fast!) - /*LCD_sprintf = */sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",msg_lcd.get_temperature(),msg_lcd.get_pressure(),msg_lcd.get_light());//Used for converting to a sting - - //LCD.Display_Clear(); + sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",msg_lcd.get_temperature(),msg_lcd.get_pressure(),msg_lcd.get_light());//Used for converting to a sting + LCD.DDRAM_Address(0x00); LCD.Write_String("Temp Pres li"); LCD.DDRAM_Address(0x40); + LCD.Write_String(LCD_buffer); - LCD.Write_String(LCD_buffer); - //LCD.Write_String("Temp Pres li\n"); - //LCD.Write_String("%1.1f ", msg_lcd.get_temperature());//Print Temperature to LCD - //LCD.Write_String("%1.1f ", msg_lcd.get_pressure());//Print Pressure to LCD - //LCD.Write_String("%1.1f\n", msg_lcd.get_light()); //Print Light to LCD - - } else if(mode == 1) { //Print the Time to the LCD + } + else if(mode == 1) //Print the Time to the LCD + { time_t msel_time = msg_lcd.get_time(); //Declare local variable for time strftime(scom_time_buffer, 32, "%I:%M %p", localtime(&msel_time)); //Format time as a string LCD.Display_Clear(); @@ -109,13 +101,11 @@ LCD.DDRAM_Address(0x40); LCD.Write_String(LCD_buffer); - } else { - mode = 0; - } + }else{mode = 0;}//Set a default mode } } } -void Serial_Commands() +void Serial_Commands()//Used for getting input from the user to determine the opperations to perform { string Serial_Input; while(1) { @@ -137,7 +127,8 @@ { Sampling_Timer.detach(); Console_Output_Timer.detach(); - for (int x = 0; x < mailsize; x++){ + for (int x = 0; x < mailsize; x++) + { DATA *Delete_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data mail_box.free(Delete_Data); //Puts "Send_Data" into the mailbox } @@ -146,7 +137,12 @@ } else if(Serial_Input == "READ") { - + cout << "Please enter in the number of samples to read" <<endl; + int Loops; cin >> Loops; + for (int x = 0; x < Loops; x++) + { + Serial_Comms_Stealth_Mode(); + } } else if(Serial_Input == "DELETE") { @@ -202,31 +198,32 @@ } } } +void Serial_Comms_Stealth_Mode()//Change this name +{ + osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box" + + DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox + DATA msg_serial; //Create temporary instance of DATA class + + msg_serial.set_time(Rec_Data_Serial->get_time()); //Copy time from mailbox to temporary instance + msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); //Copy teperature from mailbox to temporary instance + msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); //Copy pressure from mailbox to temporary instance + msg_serial.set_light(Rec_Data_Serial->get_light()); //Copy light from mailbox to temporary instance + mail_box.free(Rec_Data_Serial); //Free space in the mailbox (delete earliest sample taken) + time_t scom_time = msg_serial.get_time(); //Declare local variable for time + strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time)); //Format time as a string + pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time + pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature + pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure + pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light + + Green_led.Toggle(); +} void Serial_Comms()//Thread for Serial Communications { while(1) { Thread::signal_wait(SerialCommsTime);//Stupid 0 Bug - osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box" - - if (evt_serial.status == osEventMail) { - DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox - DATA msg_serial; //Create temporary instance of DATA class - - msg_serial.set_time(Rec_Data_Serial->get_time()); //Copy time from mailbox to temporary instance - msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); //Copy teperature from mailbox to temporary instance - msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); //Copy pressure from mailbox to temporary instance - msg_serial.set_light(Rec_Data_Serial->get_light()); //Copy light from mailbox to temporary instance - mail_box.free(Rec_Data_Serial); //Free space in the mailbox (delete earliest sample taken) - - time_t scom_time = msg_serial.get_time(); //Declare local variable for time - strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time)); //Format time as a string - pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time - - pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature - pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure - pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light - } - Green_led.Toggle(); + Serial_Comms_Stealth_Mode(); } } @@ -250,18 +247,20 @@ //pc.printf("Out of memory\n\r"); //Print out of memory warning return; } - Send_Data->set_time(buffer_time); //Pass in Time Send_Data->set_temperature(temp); //Pass in Temp Send_Data->set_pressure(pressure); //Pass in Pres Send_Data->set_light(lux); //Pass in Light osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox + + //if(stat == osErrorNoMemory) + // { + // mail_box.free(Send_Data); + // } if (stat == osErrorResource) { //If mailbox overfills - //pc.printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat); //Print error message mail_box.free(Send_Data); //Free the mail box - return; } Red_led.Toggle(); t1.signal_set(NotSamplingTime); @@ -278,8 +277,7 @@ LCD.Initialise(); LCD.DDRAM_Address(0x00); - - + post(); //Power on Self Test //Initialise the SD card (this needs to move) @@ -289,7 +287,6 @@ LCD.Write_String("CANNOT INIT SD"); //Change me errorCode(FATAL); } - //Create a filing system for SD Card FATFileSystem fs("sd", &sd); @@ -301,11 +298,9 @@ LCD.Write_String("CANNOT OPEN FILE\n\n");//Change me errorCode(FATAL); } - - //Last message before sampling begins LCD.Display_Clear(); - LCD.Write_String("READY\n\n");//change me + LCD.Write_String("READY\n\n"); Sample_Rate = TimerInterval; @@ -319,7 +314,6 @@ //t4.start(Network); t5.start(Serial_Commands); - //Main thread ID idMain = osThreadGetId(); //CMSIS RTOS call @@ -331,8 +325,6 @@ id4 = t4.gettid(); id5 = t5.gettid(); - DigitalIn onBoardSwitch(USER_BUTTON); - while (onBoardSwitch == 0) { } @@ -355,6 +347,3 @@ wait(0.1); } } - - -