3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Revision:
79:4e6b53eb678b
Parent:
77:db3384071634
Child:
80:959151952153
--- a/main.cpp	Wed Apr 26 21:58:08 2017 +0000
+++ b/main.cpp	Fri Apr 28 17:17:24 2017 +0000
@@ -54,6 +54,7 @@
 //Mail<>
 bool logging = true;
 float sampleRate = 1;
+char* temp;
 
 // Logging objects
 std::ostringstream oss;
@@ -79,15 +80,18 @@
 //
 //  SIGNALED BY Ticker at a frequency of <T> Hz
 //  Reads values from sensor board, sends over through mail queue
-void MeasureThread() {
+void MeasureThread() 
+{
+    float temperature , humidity,pressure;
 
     while(true)
     {   
+        temperature = 0;
+        humidity = 0;
+        pressure = 0;
         //Await signal from ticker
         Thread::signal_wait(SIGNAL_doMeasure);
         
-        float temperature = 0 , humidity = 0,pressure = 0;
-        
         Measure *measure = mail_box.alloc();
         if (measure == NULL) 
         {
@@ -169,8 +173,8 @@
     //Char array that stores the command after user presses ENTER
     char command[40];
     //Current Command Size
-    int crtChar = 0;
-    printf("\r\nAwaiting command:\r\n");   
+    int crtChar = 0; 
+    logger.SendMessage("\r\nAwaiting command: \n\r");
     while(1)
     {
         charCmd = NULL;
@@ -180,13 +184,17 @@
             //If BACKSPACE is pressed, Print "DEL" so it deletes last character typed.
             if (charCmd == 127 && crtChar > 0 )
             {
+                command[--crtChar] = '\0';
                 printf("%c",charCmd);
-                command[--crtChar] = '\0';   
             }
             //If NOT enter AND NOT Backspace is pressed, SAVE the char
             else if(charCmd != 13 && charCmd != 127) 
             {
                 command[crtChar++] = charCmd;
+                //char *temp;
+                //int i = 1337;
+                //sprintf(temp, "DIE YOU %d", i);
+                //logger.SendMessage(temp); 
                 printf("%c",charCmd);
             }
             //If ENTER is pressed, PROCESS it
@@ -203,25 +211,26 @@
                     //Check if it's a "LIST ALL" command
                     if(CompareCommands(charPos, "all",3) == 1)
                     {
-                        printf("\r\nPrinting all measures performed so far: \r\n");
+                        logger.SendMessage("\r\nPrinting all measures performed so far: \r\n"); 
                         
                         // Changed to use circular buffer rather than list buffer
                         buffer.readAll();
-                        printf("\r\nD O N E ! \r\n");
+                        logger.SendMessage("\r\nD O N E ! \r\n");
                     }
                     //Check if it's a "LIST X" command
                     else if(strtol(charPos,NULL,10) != 0)
                     {
                         int num = atoi(charPos);
-                        printf("\r\nPrinting %i measures: \r\n",num);
+                        sprintf(temp, "\r\nPrinting %i measures: \r\n",num);
+                        logger.SendMessage(temp);
                         
                         // Changed to use circular buffer rather than list buffer
                         buffer.readX(num);
-                        printf("\r\nD O N E ! \r\n");
+                        logger.SendMessage("\r\nD O N E ! \r\n");
                     }
                     else
                     {
-                        printf("\n\rExpected parameters: \"all\" | \"n\", where n is a number.");   
+                        logger.SendMessage("\n\rExpected parameters: \"all\" | \"n\", where n is a number.");   
                     }
                 }
                 //Check if it's a "DELETE" command
@@ -231,22 +240,22 @@
                     //Check if it's a "DELETE ALL" command
                     if(CompareCommands(charPos,"all",3) == 1)
                     {
-                        printf("\r\nDeleting all measures performed so far: \r\n");
+                        logger.SendMessage("\r\nDeleting all measures performed so far: \r\n");
                         
                         // Changed to use circular buffer rather than list buffer
                         buffer.deleteAll();
-                        printf("\r\nElements deleted!\r\n");
+                        logger.SendMessage("\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));
-                        printf("\r\nElements deleted!\r\n");
+                        logger.SendMessage("\r\nElements deleted!\r\n");
                     }
                     else
                     {
-                        printf("\n\rExpected parameters: \"all\" | \"n\", where n is a number.");     
+                        logger.SendMessage("\n\rExpected parameters: \"all\" | \"n\", where n is a number.");     
                     }
                        
                 }
@@ -257,9 +266,14 @@
                     
                     // Changed to use circular buffer rather than list buffer
                     if(logging == true)
-                        printf("\r\nSTATUS: \r\n   # of measures: %i \r\n   SAMPLING: ON \r\n   Current Date: %s \r\n   Sample Rate(s): %2.2f \r\n", buffer.getSize(), ptr,sampleRate);   
+                    {
+                        sprintf(temp, "\r\nSTATUS: \r\n   # of measures: %i \r\n   SAMPLING: ON \r\n   Current Date: %s \r\n   Sample Rate(s): %2.2f \r\n", buffer.getSize(), ptr,sampleRate);   
+                    }
                     else
-                        printf("\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);  
+                    {
+                        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);
                 }
                 //Check if it's a "SETTIME" command
                 else if (CompareCommands(charPos,"settime",7) == 1)
@@ -290,12 +304,13 @@
                         localDate->min = m;   
                         localDate->sec = s;
                         char *ptr = localDate->ToString();
-                        printf("\r\nUpdated Date to: %s \r\n", ptr);
+                        sprintf(temp, "\r\nUpdated Date to: %s \r\n", ptr);
+                        logger.SendMessage(temp);
                     } 
                     //If not valid, prompt user
                     else
                     {
-                        printf("\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");   
                     }
                 }
                 //Check if it's a "SETDATE" command
@@ -327,12 +342,13 @@
                         localDate->month = m;   
                         localDate->year = y;
                         char *ptr = localDate->ToString();
-                        printf("\r\nUpdated Date to: %s \r\n", ptr);
+                        sprintf(temp, "\r\nUpdated Date to: %s \r\n", ptr);
+                        logger.SendMessage(temp);
                     } 
                     // Prompt user if they are not.
                     else
                     {
-                        printf("\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");   
                     }
                 }
                 // Check if it's a "LOGGING" command
@@ -343,12 +359,12 @@
                     if(CompareCommands(charPos,"on",2) == 1)
                     {
                         logging = true;   
-                        printf("\r\nSampling turned ON!\r\n");
+                        logger.SendMessage("\r\nSampling turned ON!\r\n");
                     }
                     else if (CompareCommands(charPos,"off",3) == 1)
                     {
-                        logging = false;   
-                        printf("\r\nSampling turned OFF!\r\n");
+                        logging = false; 
+                        logger.SendMessage("\r\nSampling turned OFF!\r\n");
                     }
                     else
                     {
@@ -367,26 +383,19 @@
                         sampleRate = auxRate;
                         timer.detach();
                         timer.attach(&SendSignalDoMeasure, sampleRate);
-                        printf("\r\nSuccessfully updated sample rate to: %2.2f .\r\n",sampleRate);
+                        sprintf(temp, "\r\nSuccessfully updated sample rate to: %2.2f .\r\n",sampleRate);
+                        logger.SendMessage(temp);
                     }
                     // if rate is not valid, prompt:
                     else
                     {
-                        printf("\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");    
                     }
                 }
                 // Check if it's a "HELP" command
                 else if (CompareCommands(charPos,"help",4) == 1 || CompareCommands(charPos,"?",1) == 1)
                 {
-                    printf("\r\nAvailable Commands:\r\n");
-                    printf("    read <ALL|N> - Read ALL or N first measures.\r\n");
-                    printf("    delete <ALL|N> - Delete ALL or N first measures.\r\n");
-                    printf("    setdate <DD> <MM> <YYYY> Set current date.\r\n");
-                    printf("    settime <HH> <MM> <SS> Set current time.\r\n");
-                    printf("    sett <T> Set sample rate (in seconds).\r\n");
-                    printf("    status - Status report of device.\r\n");
-                    printf("    state - <ON|OFF> - Turn sampling on or OFF.\r\n");
-                    printf("    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");
                 }
                 else if(CompareCommands(charPos, "test", 4) == 1)
                 {
@@ -394,26 +403,24 @@
                     //Check if it should be turned ON / OFF
                     if(CompareCommands(charPos,"1",1) == 1)
                     {
-                        char *temp;
                         int i = 1337;
                         sprintf(temp, "DIE YOU %d", i);
                         logger.SendMessage(temp);                        
                     }
                     else
                     {
-                        char *temp;
-                        int i = 50;
+                        int i = 504;
                         sprintf(temp, "DIE YOU %d", i);
-                        logger.SendError(temp);  
-                        
+                        logger.SendError(temp);                          
                     }
                 }
                 // If command not recognized
                 else
                 {
-                    printf("\r\n Command not recognized. Type \"help\" for more info.\r\n");   
+                    sprintf(temp, "\r\n Command not recognized. Type \"help\" for more info.\r\n"); 
+                    logger.SendMessage(temp);  
                 }
-                printf("\r\nAwaiting command: \r\n");
+                logger.SendMessage("Awaiting command: \n\r");
                 //Clear command!
                 //* NOTE * Setting first char in array to '\0' WILL NOT RESET IT...for some reason.
                 int i = 0;
@@ -442,6 +449,7 @@
      while(true)
      {
         Thread::signal_wait(SIGNAL_printMessage);
+        
             if(logger.GetError())
             {
                 // Kill EVERYTHING