![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
Diff: main.cpp
- Revision:
- 80:959151952153
- Parent:
- 79:4e6b53eb678b
- Child:
- 81:996c0a3319b4
diff -r 4e6b53eb678b -r 959151952153 main.cpp --- a/main.cpp Fri Apr 28 17:17:24 2017 +0000 +++ b/main.cpp Wed May 10 10:02:22 2017 +0000 @@ -175,10 +175,14 @@ //Current Command Size int crtChar = 0; logger.SendMessage("\r\nAwaiting command: \n\r"); + //printf("\r\nAwaiting command: \n\r"); while(1) { charCmd = NULL; charCmd = getchar(); + + //uint32_t i = (*consumeThread).used_stack(); + //printf("%d" , i); if(charCmd != NULL) { //If BACKSPACE is pressed, Print "DEL" so it deletes last character typed. @@ -212,17 +216,22 @@ if(CompareCommands(charPos, "all",3) == 1) { logger.SendMessage("\r\nPrinting all measures performed so far: \r\n"); + //printf("\r\nPrinting all measures performed so far: \r\n"); // Changed to use circular buffer rather than list buffer buffer.readAll(); - logger.SendMessage("\r\nD O N E ! \r\n"); + //logger.SendMessage("\r\nD O N E ! \r\n"); + printf("\r\nD O N E ! \r\n"); } //Check if it's a "LIST X" command else if(strtol(charPos,NULL,10) != 0) { + + // PROBLEMATIC (HAVING 2 SEND MESSAGE IN 1 BLOCK) int num = atoi(charPos); sprintf(temp, "\r\nPrinting %i measures: \r\n",num); logger.SendMessage(temp); + //printf(temp); // Changed to use circular buffer rather than list buffer buffer.readX(num); @@ -230,7 +239,8 @@ } else { - logger.SendMessage("\n\rExpected parameters: \"all\" | \"n\", where n is a number."); + logger.SendMessage("\n\rExpected parameters: \"all\" | \"n\", where n is a number."); + //printf("\n\rExpected parameters: \"all\" | \"n\", where n is a number."); } } //Check if it's a "DELETE" command @@ -240,22 +250,26 @@ //Check if it's a "DELETE ALL" command if(CompareCommands(charPos,"all",3) == 1) { - logger.SendMessage("\r\nDeleting all measures performed so far: \r\n"); + //logger.SendMessage("\r\nDeleting all measures performed so far: \r\n"); + printf("\r\nDeleting all measures performed so far: \r\n"); // Changed to use circular buffer rather than list buffer buffer.deleteAll(); - logger.SendMessage("\r\nElements deleted!\r\n"); + //logger.SendMessage("\r\nElements deleted!\r\n"); + printf("\r\nElements deleted!\r\n"); } //Check if it's a "DELETE X" command else if (strtol(charPos,NULL,10) != 0) { // Changed to use circular buffer rather than list buffer buffer.deleteX(atoi(charPos)); - logger.SendMessage("\r\nElements deleted!\r\n"); + //logger.SendMessage("\r\nElements deleted!\r\n"); + printf("\r\nElements deleted!\r\n"); } else { - logger.SendMessage("\n\rExpected parameters: \"all\" | \"n\", where n is a number."); + //logger.SendMessage("\n\rExpected parameters: \"all\" | \"n\", where n is a number."); + printf(temp); } } @@ -273,7 +287,8 @@ { sprintf(temp, "\r\nSTATUS: \r\n # of measures: %i \r\n SAMPLING: OFF \r\n Current Date: %s \r\n Sample Rate(s): %2.2f \r\n", buffer.getSize(), ptr,sampleRate); } - logger.SendMessage(temp); + //logger.SendMessage(temp); + printf(temp); } //Check if it's a "SETTIME" command else if (CompareCommands(charPos,"settime",7) == 1) @@ -305,12 +320,14 @@ localDate->sec = s; char *ptr = localDate->ToString(); sprintf(temp, "\r\nUpdated Date to: %s \r\n", ptr); - logger.SendMessage(temp); + //logger.SendMessage(temp); + printf(temp); } //If not valid, prompt user else { - logger.SendMessage("\r\nWrong format! please use HH-MM-SS separated by spaces. \r\n"); + //logger.SendMessage("\r\nWrong format! please use HH-MM-SS separated by spaces. \r\n"); + printf("\r\nWrong format! please use HH-MM-SS separated by spaces. \r\n"); } } //Check if it's a "SETDATE" command @@ -343,12 +360,14 @@ localDate->year = y; char *ptr = localDate->ToString(); sprintf(temp, "\r\nUpdated Date to: %s \r\n", ptr); - logger.SendMessage(temp); + //logger.SendMessage(temp); + printf(temp); } // Prompt user if they are not. else { - logger.SendMessage("\r\nWrong format! please use DD-MM-YYYY separated by spaces. \r\n"); + //logger.SendMessage("\r\nWrong format! please use DD-MM-YYYY separated by spaces. \r\n"); + printf("\r\nWrong format! please use DD-MM-YYYY separated by spaces. \r\n"); } } // Check if it's a "LOGGING" command @@ -359,12 +378,14 @@ if(CompareCommands(charPos,"on",2) == 1) { logging = true; - logger.SendMessage("\r\nSampling turned ON!\r\n"); + //logger.SendMessage("\r\nSampling turned ON!\r\n"); + printf("\r\nSampling turned ON!\r\n"); } else if (CompareCommands(charPos,"off",3) == 1) { logging = false; - logger.SendMessage("\r\nSampling turned OFF!\r\n"); + //logger.SendMessage("\r\nSampling turned OFF!\r\n"); + printf("\r\nSampling turned OFF!\r\n"); } else { @@ -384,18 +405,21 @@ timer.detach(); timer.attach(&SendSignalDoMeasure, sampleRate); sprintf(temp, "\r\nSuccessfully updated sample rate to: %2.2f .\r\n",sampleRate); - logger.SendMessage(temp); + //logger.SendMessage(temp); + printf(temp); } // if rate is not valid, prompt: else { - logger.SendMessage("\r\n Sample rate must be between 0.1 and 60. \r\n"); + //logger.SendMessage("\r\n Sample rate must be between 0.1 and 60. \r\n"); + printf("\r\n Sample rate must be between 0.1 and 60. \r\n"); } } // Check if it's a "HELP" command else if (CompareCommands(charPos,"help",4) == 1 || CompareCommands(charPos,"?",1) == 1) { - logger.SendMessage("\r\nAvailable Commands:\r\n read <ALL|N> - Read ALL or N first measures.\r\n delete <ALL|N> - Delete ALL or N first measures.\r\n setdate <DD> <MM> <YYYY> Set current date.\r\n settime <HH> <MM> <SS> Set current time.\r\n sett <T> Set sample rate (in seconds).\r\n status - Status report of device.\r\n state - <ON|OFF> - Turn sampling on or OFF.\r\n logging <ON|OFF> - Turn logging on or OFF.\r\n"); + //logger.SendMessage("\r\nAvailable Commands:\r\n read <ALL|N> - Read ALL or N first measures.\r\n delete <ALL|N> - Delete ALL or N first measures.\r\n setdate <DD> <MM> <YYYY> Set current date.\r\n settime <HH> <MM> <SS> Set current time.\r\n sett <T> Set sample rate (in seconds).\r\n status - Status report of device.\r\n state - <ON|OFF> - Turn sampling on or OFF.\r\n logging <ON|OFF> - Turn logging on or OFF.\r\n"); + printf("\r\nAvailable Commands:\r\n read <ALL|N> - Read ALL or N first measures.\r\n delete <ALL|N> - Delete ALL or N first measures.\r\n setdate <DD> <MM> <YYYY> Set current date.\r\n settime <HH> <MM> <SS> Set current time.\r\n sett <T> Set sample rate (in seconds).\r\n status - Status report of device.\r\n state - <ON|OFF> - Turn sampling on or OFF.\r\n logging <ON|OFF> - Turn logging on or OFF.\r\n"); } else if(CompareCommands(charPos, "test", 4) == 1) { @@ -405,22 +429,26 @@ { int i = 1337; sprintf(temp, "DIE YOU %d", i); - logger.SendMessage(temp); + //logger.SendMessage(temp); + printf(temp); } else { int i = 504; sprintf(temp, "DIE YOU %d", i); - logger.SendError(temp); + //logger.SendError(temp); + printf(temp); } } // If command not recognized else { sprintf(temp, "\r\n Command not recognized. Type \"help\" for more info.\r\n"); - logger.SendMessage(temp); + //logger.SendMessage(temp); + printf(temp); } logger.SendMessage("Awaiting command: \n\r"); + //printf("Awaiting command: \n\r"); //Clear command! //* NOTE * Setting first char in array to '\0' WILL NOT RESET IT...for some reason. int i = 0; @@ -449,6 +477,8 @@ while(true) { Thread::signal_wait(SIGNAL_printMessage); + //uint32_t i = (*loggingThread).used_stack(); + //printf("Logging Stack: %d" , i); if(logger.GetError()) { @@ -480,16 +510,18 @@ realTimeDate.attach(&RealTimeDate,1.0); //Run Threads + loggingThread = new Thread(); + loggingThread->start(LoggingThread); + + logger.SetThread(loggingThread); + produceThread = new Thread(); produceThread->start(ProducerThread); measureThread = new Thread(); measureThread->start(MeasureThread); consumeThread = new Thread(); consumeThread->start(ConsumeThread); - loggingThread = new Thread(); - loggingThread->start(LoggingThread); - logger.SetThread(loggingThread); printf("Main Thread\n"); while(true)