test to establish how we can share the project on MBED

Dependencies:   BME280 BMP280 ELEC350-Coursework-2017 TextLCD

Fork of ELEC350-CWTEMPLATE-2017 by University of Plymouth - Stages 1, 2 and 3

Files at this revision

API Documentation at this revision

Comitter:
bdarling
Date:
Thu Dec 14 16:44:07 2017 +0000
Parent:
7:83d2d9087972
Child:
9:6fb498cf6156
Commit message:
modified serial_protocol.cpp, SETDATE is now functioning correctly

Changed in this revision

serial_protocol/serial_protocol.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/serial_protocol/serial_protocol.cpp	Thu Dec 14 12:39:15 2017 +0000
+++ b/serial_protocol/serial_protocol.cpp	Thu Dec 14 16:44:07 2017 +0000
@@ -1,20 +1,14 @@
 #include "serial_protocol.hpp"
 #include "sample_hardware.hpp"
-//#include <iostream>
 #include <string>
+#include <ctype.h>
 Serial pc(SERIAL_TX, SERIAL_RX);
 
-using namespace std;
-
 
 char string1[128];
 char string2[128];
 
-
-//std::string string1;
-//std::string string2;
 int number;
-//string dayStr;
 char dayStr[3];
 char monthStr[3];
 char yearStr[5];
@@ -23,27 +17,26 @@
 int year;
 
 
+
 void getData(){
     pc.scanf("%s %s", string1, string2);
-    //pc.printf("%s %s", string1, string2);
-    
-        
+    //pc.printf("%s %s\n",string1, string2); \\for debugging 
 }
 
 void readSerial(){
     if((strcmp(string1,"READ")==0) && (strcmp(string2,"ALL")==0)){
-    //if((string1.compare("READ") == 0) && (string2.compare("ALL") == 0)){
         pc.printf("reading all\n");
     }
     
     else if((strcmp(string1,"DELETE")==0) && (strcmp(string2,"ALL")==0)){
-        //else if((string1.compare("DELETE")==0) && (string2.compare("ALL")==0)){
         pc.printf("deleting all\n");
     }
     
     else if(strcmp(string1,"READ")==0){
-    //else if(string1.compare("READ")==0){
-        if(sscanf(string2,"%d")>0){
+        int test=0;
+        sscanf(string2,"%d",&test);
+        
+        if(test>0){
             number = atoi(string2);
             if(number > 0){
                 pc.printf("reading <%d>\n",number);
@@ -57,8 +50,13 @@
         }
     }
     
+
+    
     else if(strcmp(string1,"DELETE")==0){
-        if(sscanf(string2,"%d")>0){
+        int test=0;
+        sscanf(string2,"%d",&test);
+        
+        if(test>0){
             number = atoi(string2);
             if(number > 0){
                 pc.printf("deleting <%d>\n",number);
@@ -69,16 +67,25 @@
         }
         else{
             pc.printf("invalid command\n");
-        }
-        
+        }        
     }
     
-    else if(strcmp(string1,"SETDATE")==0)
+    else if(strcmp(string1,"SETDATE")==0) 
     {
-        pc.printf("Setdate started\n\r");
-        if(sscanf(string2,"%8s") > 0)
-        {
-           pc.printf("date string is %s\n\r", string2);
+        int validDigit=0;        
+        int i;
+        for(i=0;i<8;i++){ //check first 8 elements of array are digits
+            if(isdigit(string2[i])){
+                validDigit++;
+            }
+        }
+        if(string2[8] == NULL){ //check element 8 of array is NULL, where the string terminates
+            validDigit++;
+        }               
+            
+        if(validDigit==9){
+           pc.printf("**********SETTING DATE**********\n");
+           pc.printf("date string: %s\n", string2);
            
            dayStr[0] = string2[0];
            dayStr[1] = string2[1];
@@ -92,11 +99,14 @@
            yearStr[3] = string2[7];
            yearStr[4] = NULL;         
             
-           pc.printf("Day = %s Month = %s Year = %s\n\r", dayStr, monthStr, yearStr);
+           pc.printf("Day = %s\n", dayStr);
+           pc.printf("Month = %s\n",monthStr);
+           pc.printf("Year = %s\n",yearStr);
+           pc.printf("**********DATE SET**********\n");
         }
         else{
             pc.printf("invalid value\n");
-            }
+        }
     }
             
     else{