SOFT253 ASSIGNMENT

Dependencies:   LPS25H hts221

Fork of SOFT253_Assignment_V4 by lucas kovaci

Revision:
48:f7487eb2c82a
Parent:
47:5f364311bc45
Child:
49:0dfef3825422
diff -r 5f364311bc45 -r f7487eb2c82a main.cpp
--- a/main.cpp	Mon May 15 03:57:27 2017 +0000
+++ b/main.cpp	Mon May 15 04:49:16 2017 +0000
@@ -32,16 +32,6 @@
 char inputState2[20];
 char inputStateOFF1[20];
 char inputStateOFF2[20];
-char stringToCompare1[20];
-char stringToCompare2[20];
-char stringToCompareSet1[20];
-char stringToCompareSet2[20];
-char stringToCompareDel1[20];
-char stringToCompareDel2[20];
-char stringToCompareState1[20];
-char stringToCompareState2[20];
-char stringToCompareStateOFF1[20];
-char stringToCompareStateOFF2[20];
 float tempArray[N];
 float humArray[N];
 float pressArray[N];
@@ -58,7 +48,7 @@
 
 LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
 HTS221 humidity(I2C_SDA, I2C_SCL);
-time_t timeNow;
+
 
 void adcISR();
 void thread1 (void const *args );
@@ -79,9 +69,9 @@
     
 Mail<message_t, 16> mail_box;
 
+
 void adcISR()
 {
-      
        message_t *message = mail_box.alloc();
        message->tempVal = tempCelsius;
        message->humVal = humi;
@@ -145,10 +135,9 @@
             strcpy (input1,cmd);   //INPUT 1
             pc.printf("you entered: %s\n\r",input1);
             strcpy (input2,cmd2);
-            strcpy (stringToCompare1,"READ"); //STRING TO COMPARE 1
-            strcpy (stringToCompare2,input2); //STRING TO COMPARE 2
-            res = strncmp(input1,stringToCompare1,20);
-            res2 = strncmp(input2,stringToCompare2,20);
+          
+            res = strncmp(input1,"READ",20);
+            res2 = strncmp(input2,input2,20);
             int val = atoi(input2);
             if (val <=10 && val >=1)
                 {
@@ -157,16 +146,15 @@
                         for (unsigned int n=0; n<val; n++)
                             {  
                                pc.printf("the element of %d is %4.2f ,%3.1f, %6.1f \n\r",n,tempArray[n],humArray[n],pressArray[n]);
-                               //printf("the temperature is: %4.2fC\n\r The humidity is: %3.1f\n\r", tempCelsius, humi);
+                             
                             }
                      }
                  } 
                   else //1
                      {
-                       strcpy (stringToCompare1,"READ"); //STRING TO COMPARE 1
-                       strcpy (stringToCompare2,"ALL"); //STRING TO COMPARE 2
-                       res = strncmp(input1,stringToCompare1,20);
-                       res2 = strncmp(input2,stringToCompare2,20);
+                      
+                       res = strncmp(input1,"READ",20);
+                       res2 = strncmp(input2,"ALL",20);
                        if (res==0 && res2==0)
                         {
                            for (unsigned int n=0; n<N; n++)
@@ -177,10 +165,9 @@
                          }
                         else //2
                          {   
-                           strcpy (stringToCompare1,"DELETE");
-                           strcpy (stringToCompare2,"ALL");
-                           res = strncmp(input1,stringToCompare1,20);
-                           res2 = strncmp(input2,stringToCompare2,20);
+                           
+                           res = strncmp(input1,"DELETE",20);
+                           res2 = strncmp(input2,"ALL",20);
                            if(res==0 && res2==0)
                              {
                                 //Delete every element.
@@ -197,10 +184,8 @@
                     } //1    
                  strcpy (inputDel1,cmd);   
                  strcpy (inputDel2,cmd2); 
-                 strcpy (stringToCompareDel1,"DELETE"); //STRING TO COMPARE 1
-                 strcpy (stringToCompareDel2,inputDel2);    
-                 resSet1 = strncmp(input1,stringToCompareDel1,20);
-                 resSet2 = strncmp(input2,stringToCompareDel2,20); 
+                 resSet1 = strncmp(input1,"DELETE",20);
+                 resSet2 = strncmp(input2,inputDel2,20); 
                  int valDel = atoi(inputDel2);      
                  int startDel=(counters - valDel);
                  if (valDel <=10 && valDel >=1)
@@ -219,10 +204,8 @@
                    } 
                      strcpy (inputSet1,cmd);   //INPUT 1
                      strcpy (inputSet2,cmd2);
-                     strcpy (stringToCompareSet1,"SETT"); //STRING TO COMPARE 1
-                     strcpy (stringToCompareSet2,inputSet2); //STRING TO COMPARE 2
-                     resSet1 = strncmp(inputSet1,stringToCompareSet1,20);
-                     resSet2 = strncmp(inputSet2,stringToCompareSet2,20);
+                     resSet1 = strncmp(inputSet1,"SETT",20);
+                     resSet2 = strncmp(inputSet2,inputSet2,20);
                      int inputSpeed = atoi(inputSet2);
                      if (inputSpeed <=60 && inputSpeed >=0.1)
                         {
@@ -237,16 +220,13 @@
                         }
                      strcpy (inputState1,cmd);   //INPUT 1
                      strcpy (inputState2,cmd2);
-                     strcpy (stringToCompareState1,"STATE"); //STRING TO COMPARE 1
-                     strcpy (stringToCompareState2,"ON"); //STRING TO COMPARE 2
-                     resSet1 = strncmp(inputState1,stringToCompareState1,20);
-                     resSet2 = strncmp(inputState2,stringToCompareState2,20);
+                     resSet1 = strncmp(inputState1,"STATE",20);
+                     resSet2 = strncmp(inputState2,"ON",20);
                     
                             if (resSet1==0 && resSet2==0)
                                 {   
                                 
-                                      //t.detach();
-                                     // LPC_TIM3->TC = 0;
+                                     
                                       t.attach(&adcISR, sampleSpeed);  
                                       pc.printf("Sampling: ON\n"); 
                                            
@@ -289,8 +269,12 @@
     t2 = new Thread(threadComun);
   
     t.attach(&adcISR,sampleSpeed); // timer of measurements 
-     time(&timeNow);
-       pc.printf(" current time is : %s\n",ctime(&timeNow));
+
+    
+   
+    
+   
+      
     while(1) 
     {
        humidity.init();