First Commit

Dependencies:   mbed Crypto_light mbed-rtos

Spin it 2 win it

Revision:
5:fe9b21ba2e33
Parent:
4:e1141c1d8b19
Child:
6:44c53574bf84
--- a/main.cpp	Mon Mar 12 14:41:46 2018 +0000
+++ b/main.cpp	Mon Mar 12 14:54:18 2018 +0000
@@ -53,90 +53,7 @@
 //serial's undocumented buffering behaviour 
 RawSerial pc(SERIAL_TX, SERIAL_RX); 
 
-//serial port ISR to take individual chars
-void serialISR(){
- uint8_t newChar = pc.getc();
- inCharQ.put((void*)newChar);
- }
-//decode commands
-Thread decodeT;
 
-void decodeFn(){
-    pc.attach(&serialISR);
-    char charArray[MAX_ARRAY_SIZE] = "";
-    uint32_t bufferPosition = 0;                //change this variable type if the max buffer/fifio size is found to be different
-    bool exit = false;
-    while(!exit) { 
-    
-        //get new char
-        osEvent newEvent = inCharQ.get();
-        uint8_t newChar = (uint8_t)newEvent.value.p;
-        
-        //------error for overflow-------------------------// 
-        if(bufferPosition >= MAX_ARRAY_SIZE - 1){ 
-            exit = true; 
-            putMessage(MSG_OVERFLOW, bufferPositon); //
-        } 
-        //-------------------------------------------------//
-        
-        
-        
-        //check for carriage return "\r"
-        if(newChar == 'r'){
-            if(bufferpostion != 0){
-                if(charArray[bufferposition - 1] == '\\'){
-                    //carriage found 
-                    newChar = '0';  //replace character
-                    
-                    //add to array
-                    charArray[bufferPosition] = newChar; 
-                    
-                    //reset buffer
-                    bufferPosition = 0;
-                    //send char array to decoder ***
-                }
-            }
-        }
-        //Add new char to array
-        else{
-            //add character at current position 
-            charArray[bufferPosition] = newChar; 
-            bufferPosition ++;
-        }
-      
-     }//end of : while(!exit){} 
-        
-        
-        
-    //Place it on the end of a char[] array. Make the array large enough to contain the
-    //longest possible command. You will need to keep an index of the current buffer
-    //position. This would be easier with the C++ std::string class but there is not
-    //enough memory available for this. Using a C-style array is also faster and does not
-    //involve the uncertainty of dynamic memory allocation.
-    
-    //Include a test to make sure you do not write past the end of the buffer if the
-    //incoming string is too long. Buffer overflows have historically been the source of
-    //many software crashes and vulnerabilities since you may be able to alter the return
-    //address of a function if you write past the end of a buffer.
-    
-    
-    
-    
-    //If the incoming character is a carriage return ‘\r’ it indicates the end of a
-    //command. At this point:
-        //i. Place a string termination character ‘\0’ at the end of the command. This
-        //is used by functions like printf() and sscanf() to detect the end of the
-        //string.
-        //ii. Reset the buffer position index back to 0 ready to record the next command.
-        //iii. Test the first character to determine which command was sent.
-        //iv. Decode the rest of the command
-
-        
-
-    
-    
-    
-} 
 //structure for Mail Class
 typedef struct {
      uint8_t code;
@@ -168,6 +85,66 @@
      }
 }
 
+//Queue class
+Queue<void, 8> inCharQ;
+//serial port ISR to take individual chars
+void serialISR(){
+ uint8_t newChar = pc.getc();
+ inCharQ.put((void*)newChar);
+ }
+//decode commands
+Thread decodeT;
+
+void decodeFn(){
+    pc.attach(&serialISR);
+    char charArray[MAX_ARRAY_SIZE] = "";
+    uint32_t bufferPosition = 0;                //change this variable type if the max buffer/fifio size is found to be different
+    bool exit = false;
+    while(!exit) { 
+    
+        //get new char
+        osEvent newEvent = inCharQ.get();
+        uint8_t newChar = (uint8_t)newEvent.value.p;
+        
+        //------error for overflow-------------------------// 
+        if(bufferPosition >= MAX_ARRAY_SIZE - 1){ 
+            exit = true; 
+            putMessage(MSG_OVERFLOW, bufferPosition); //
+        } 
+        //-------------------------------------------------//
+        
+        
+        
+        //check for carriage return "\r"
+        if(newChar == 'r'){
+            if(bufferPosition != 0){
+                if(charArray[bufferPosition - 1] == '\\'){
+                    //carriage found 
+                    newChar = '0';  //replace character
+                    
+                    //add to array
+                    charArray[bufferPosition] = newChar; 
+                    
+                    //reset buffer
+                    bufferPosition = 0;
+                    //send char array to decoder ***
+                }
+            }
+        }
+        //Add new char to array
+        else{
+            //add character at current position 
+            charArray[bufferPosition] = newChar; 
+            bufferPosition ++;
+        }
+      
+     }//end of : while(!exit){} 
+        
+        //iii. Test the first character to determine which command was sent.
+        //iv. Decode the rest of the command
+    
+} 
+
  
 //Status LED
 DigitalOut led1(LED1);
@@ -257,7 +234,7 @@
     
     commOutT.start(&commOutFn);
     
-    decodeT.start(&decodeFN); 
+    decodeT.start(&decodeFn); 
     
     uint8_t sequence[] = {0x45,0x6D,0x62,0x65,0x64,0x64,0x65,0x64,
                             0x20,0x53,0x79,0x73,0x74,0x65,0x6D,0x73,