fork of what I have been writing

Dependencies:   Crypto

Files at this revision

API Documentation at this revision

Comitter:
kubitz
Date:
Sun Mar 01 16:07:53 2020 +0000
Parent:
7:aef5b29d7a7c
Child:
9:4135d0c8dc10
Commit message:
added case for decode function in thread_processor

Changed in this revision

ES_CW2_Starter_STARFISH/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ES_CW2_Starter_STARFISH/main.cpp	Sun Mar 01 15:02:27 2020 +0000
+++ b/ES_CW2_Starter_STARFISH/main.cpp	Sun Mar 01 16:07:53 2020 +0000
@@ -7,6 +7,8 @@
 typedef struct {
   uint8_t hash[32]; /* hash of successful nonce             */
 } mail_t;
+
+
 Timer timer_nonce;
 Mail<mail_t, 16> crypto_mail;
 Mail<uint8_t, 8> inCharQ;
@@ -29,6 +31,9 @@
 uint32_t last_nonce_number = 0;
 
 uint8_t hash[32];
+// Max size of serial input is 49 + Null character
+char serial_input[50]; 
+
 uint32_t previous_time;
 //Photointerrupter input pins
 #define I1pin D3
@@ -164,16 +169,44 @@
 
 // Thread processor raw serial inputs: 
 void thread_processor(){
+    uint8_t index = 0; 
     while(true) {
         osEvent newEvent = inCharQ.get();
         if (evt.status == osEventMail){
             uint8_t* newChar = (uint8_t*)newEvent.value.p;
             //Store the new character
-            
+            serial_input[index] = *newChar; 
             inCharQ.free(newChar);
         }
         //Decode the command if it is complete
-        
+        if (serial_input[index]=='\r'){
+            char command_type;
+            *command_type = serial_input[0]; 
+            
+            switch(command_type){
+                case 'R':
+                    // Rotation command
+                    break; 
+                    
+                case 'V': 
+                    // Speed command
+                    break; 
+                    
+                case 'K':
+                    // Bitcoin key command 
+                    break;   
+                                 
+                case 'T':
+                    // Melody command
+                    break; 
+                    
+                default: 
+                    // Out of format input
+                    printf("Wrong input command - please try again"); 
+                }
+
+            }
+        index++; 
         }
     }
 
@@ -188,9 +221,9 @@
     }
 // ISR routine to get charachter from Serial command
 void serialISR(){
- uint8_t* newChar = inCharQ.alloc();
- *newChar = pc.getc();
- inCharQ.put(newChar);
+     uint8_t* newChar = inCharQ.alloc();
+     *newChar = pc.getc();
+     inCharQ.put(newChar);
  }
 // Attach interrupt routine on received character
 pc.attach(&serialISR);
@@ -219,7 +252,7 @@
     timer_nonce.start();
     pc.printf("time is %d\n\r", timer_nonce.read_ms()); 
     pc.printf("time is %d\n\r", (timer_nonce.read_ms()-previous_time)); 
-    uint8_t hash[32];
+
     thread_crypto.start(thread_crypto_print);
     thread_processor.start(thread_processor); 
     while (1){