First Commit

Dependencies:   mbed Crypto_light mbed-rtos

Spin it 2 win it

Revision:
7:0d6632fba8d4
Parent:
6:44c53574bf84
Child:
8:e7818c369bd3
--- a/main.cpp	Mon Mar 12 15:00:13 2018 +0000
+++ b/main.cpp	Mon Mar 12 15:31:44 2018 +0000
@@ -23,10 +23,13 @@
 #define MSG_HASHCOUNT 0
 #define MSG_NONCE_OK 1
 #define MSG_OVERFLOW 2
+
 //FIFO constant definitions
 #define MAX_ARRAY_SIZE 19 //Max length of input codes
 
 
+
+
 //Mapping from sequential drive states to motor phase outputs
 /*
 State   L1  L2  L3
@@ -85,6 +88,11 @@
      }
 }
 
+//Global varible for the Bitcoin Key
+volatile uint64_t newKey = 0; //check initialise value? ****
+
+Mutex newKey_mutex //for mutex locking 
+
 //Queue class
 Queue<void, 8> inCharQ;
 //serial port ISR to take individual chars
@@ -92,12 +100,32 @@
  uint8_t newChar = pc.getc();
  inCharQ.put((void*)newChar);
  }
+ 
+
 //decode commands
 Thread decodeT;
 
+//set the global NewKey
+void setNewCmd(char newCmd[MAX_ARRAY_SIZE]){
+    //find prefix ***
+     
+    //K 
+    if newCmd[0] == 'K'{
+        newKey_mutex.lock();
+        sscanf(newCmd, "K%x", &newKey); //Decode the command
+        newKey_mutex.unlock();
+    }
+    //V
+    
+    //R
+     
+        
+}
+
+//decode char's function
 void decodeFn(){
     pc.attach(&serialISR);
-    char charArray[MAX_ARRAY_SIZE] = "";
+    char newCmd[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) { 
@@ -106,29 +134,27 @@
         osEvent newEvent = inCharQ.get();
         uint8_t newChar = (uint8_t)newEvent.value.p;
         
-        
-        
-        
         //check for carriage return "\r"
         if(newChar == 'r'){
             if(bufferPosition != 0){
-                if(charArray[bufferPosition - 1] == '\\'){
+                if(newCmd[bufferPosition - 1] == '\\'){
                     //carriage found 
                     newChar = '0';  //replace character
                     
                     //add to array
-                    charArray[bufferPosition] = newChar; 
+                    newCmd[bufferPosition] = newChar; 
                     
                     //reset buffer
                     bufferPosition = 0;
                     //send char array to decoder ***
+                    setNewCmd(newCmd);
                 }
             }
         }
         //Add new char to array
         else{
             //add character at current position 
-            charArray[bufferPosition] = newChar; 
+            newCmd[bufferPosition] = newChar; 
             bufferPosition ++;
         }