fork of what I have been writing

Dependencies:   Crypto

Revision:
11:038d3ba0d720
Parent:
10:3669e3d832ed
Child:
12:38afe92e67d0
--- a/ES_CW2_Starter_STARFISH/main.cpp	Wed Mar 04 15:56:19 2020 +0000
+++ b/ES_CW2_Starter_STARFISH/main.cpp	Fri Mar 06 14:27:16 2020 +0000
@@ -1,56 +1,16 @@
 
-#include "mbed.h"
-#include "SHA256.h"
-#include "rtos.h"
-#include <stdlib.h>
-#include <string>
-
-// Mail variables to pass data to threads
-
-Mail<uint64_t, 16> crypto_mail;
-Mail<uint8_t, 8> inCharQ;
+#include "import.h"
 
 // Declaration of threads
 Thread thread_crypto;
 Thread thread_processor;
 
-Mutex NewKey_mutex;
-Mutex Speed_mutex; 
-Mutex Music_mutex; 
-Mutex Rotation_mutex; 
-
-// Crypto mining variables
-uint8_t sequence[] = {0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
-                      0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x73,
-                      0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x75, 0x6E,
-                      0x20, 0x61, 0x6E, 0x64, 0x20, 0x64, 0x6F, 0x20,
-                      0x61, 0x77, 0x65, 0x73, 0x6F, 0x6D, 0x65, 0x20,
-                      0x74, 0x68, 0x69, 0x6E, 0x67, 0x73, 0x21, 0x20,
-                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-uint64_t *key = (uint64_t *)&sequence[48];
-uint64_t *nonce = (uint64_t *)&sequence[56];
-uint32_t successful_nonce = 0;
-uint32_t last_nonce_number = 0;
-uint8_t hash[32];
-uint64_t NewKey;
-
-float NewRotation; 
-float NewSpeed; 
 
 // Timing variables for printing calculation rate
 Timer timer_nonce;
 uint32_t previous_time;
 
-// Serial port variables
-// Max size of serial input is 49 + Null character
-char serial_buffer[50];
-std::string buffer_serial = ""; 
-RawSerial pc(USBTX, USBRX);
-char command_category;
-char *trimmed_serial_buffer;
-uint64_t extracted_value_serial_hex;
-uint8_t idx;
+
 //Photointerrupter input pins
 #define I1pin D3
 #define I2pin D6
@@ -184,100 +144,6 @@
     intStateOld = intState;
 }
 
-// Thread to print successful Hashes
-void thread_crypto_print()
-{
-    while (true)
-    {
-        osEvent evt = crypto_mail.get();
-        if (evt.status == osEventMail)
-        {
-            uint64_t *matching_nonce = (uint64_t *)evt.value.p;
-            pc.printf("Matching nonce found: %llu \n\r",(long long) *matching_nonce); 
-            crypto_mail.free(matching_nonce);
-        }
-    }
-}
-
-void decode_serial_buffer(std::string serial_buffer)
-{   
-    command_category = serial_buffer[0]; 
-    switch (command_category)
-    {
-    case 'R':
-        // Rotation command - R-?\d{1,s4}(\.\d)?
-        Rotation_mutex.lock(); 
-        sscanf(serial_buffer.c_str(), "%c-%f", &command_category, &NewRotation); 
-        pc.printf("You have a new rotation: %f \r\n", NewRotation);
-        Rotation_mutex.unlock(); 
-
-        break;
-    case 'V':
-        // Speed command - V\d{1,3}(\.\d)?
-        Speed_mutex.lock();
-        sscanf(serial_buffer.c_str(), "%c %f", &command_category, &NewSpeed); 
-        pc.printf("You have a new speed: %f \r\n", NewSpeed);
-        Speed_mutex.unlock(); 
-        // to implement !
-        break;
-
-    case 'K':
-        // Bitcoin key command - K[0-9a-fA-F]{16}
-        NewKey_mutex.lock();
-        sscanf(serial_buffer.c_str(), "%c %llx", &command_category, &NewKey); 
-        pc.printf("You have entered a new bitcoin key: %llu \r\n",(long long) NewKey);
-        NewKey_mutex.unlock();
-        break;
-
-    case 'T':
-        // Melody command - T([A-G][#^]?[1-8]){1,16}
-        Music_mutex.lock();
-        pc.printf("You have entered a new melody: --> TO IMPLEMENT <--- \r\n");
-        Music_mutex.unlock(); 
-        // to implement !
-
-    default:
-        printf("Input value out of format - please try again! \r\n");
-    }
-}
-
-// Thread processor raw serial inputs:
-void thread_processor_callback()
-{
-    while (true)
-    {
-        osEvent evt = inCharQ.get();
-        uint8_t *newChar = (uint8_t *)evt.value.p;
-        buffer_serial += (*newChar); 
-        //Store the new character
-        if (buffer_serial.back() == '\r')
-          {
-            buffer_serial += '\0';
-            decode_serial_buffer(buffer_serial);
-            buffer_serial = ""; 
-            }
-        inCharQ.free(newChar);
-    }
-}
-
-
-// Put message in Mail box for Crypto printing
-void putMessageCrypto(uint64_t nonce)
-{
-    uint64_t *mail = crypto_mail.alloc();
-    *mail = nonce; 
-    crypto_mail.put(mail);
-}
-
-// ISR routine to get charachter from Serial command
-void serialISR()
-{   
-    uint8_t *newChar = inCharQ.alloc();
-    *newChar = pc.getc();
-    inCharQ.put(newChar);
-}
-
-// Attach interrupt routine on serial port
 
 //Main
 int main()