fork of what I have been writing

Dependencies:   Crypto

Files at this revision

API Documentation at this revision

Comitter:
kubitz
Date:
Sun Mar 01 12:34:10 2020 +0000
Parent:
4:377264732a24
Child:
6:5f4a954cb8bc
Commit message:
debugged last task - CW1

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	Fri Feb 28 18:05:02 2020 +0000
+++ b/ES_CW2_Starter_STARFISH/main.cpp	Sun Mar 01 12:34:10 2020 +0000
@@ -1,16 +1,9 @@
+
 #include "mbed.h"
 #include "SHA256.h"
-#include "rtos.h"
 
 Timer timer_nonce;
 
-typedef struct {
-  uint8_t hash[32]; /* hash of successful nonce             */
-} mail_t;
-
-Mail<mail_t, 16> mail_box;
-
-Thread thread_crypto;#
 
 uint8_t sequence[] = {0x45,0x6D,0x62,0x65,0x64,0x64,0x65,0x64,
 0x20,0x53,0x79,0x73,0x74,0x65,0x6D,0x73,
@@ -20,15 +13,13 @@
 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];
 uint32_t previous_time;
-
-
 //Photointerrupter input pins
 #define I1pin D3
 #define I2pin D6
@@ -147,24 +138,6 @@
     intStateOld = intState;
 }
 
-void print_crypto_thread() {
-    while (true) {
-        osEvent evt = mail_box.get();
-        if (evt.status == osEventMail) {
-            mail_t *mail = (mail_t*)evt.value.p;
-            for (int i = 0; i < 32; i++)
-                printf("%d", mail->hash[i]);
-            printf("/n");
-            mail_box.free(mail);
-        }
-}
-
-void putMessage(uint8_t hash[32]){
-     mail_t *mail = mail_box.alloc();
-     mail->hash = hash;
-     mail_box.put(mail);
-}
-    
 //Main
 int main() {
 
@@ -187,24 +160,30 @@
     I3.rise(&move);
     I3.fall(&move);
     timer_nonce.start();
-    previous_time = timer_nonce.read();
-    
-    while(1==1){
-        uint8_t hash[32];
-        thread_crypto.start(print_crypto_thread);
-        *nonce ++;
+    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];
+
+    while (1){
+
+        *nonce = *nonce + 1;
+
         SHA256::computeHash(hash, (uint8_t*)sequence, 64);
-        mail_box.put(mail);
-     
+
         if ((hash[0]==0)&&(hash[1]==0)){
             last_nonce_number = successful_nonce;
             successful_nonce++;
-            putMessage(hash);
+            pc.printf("Successful Nonce -- hash: ");
+            for(int i = 0; i < 32; ++i)
+                pc.printf("%02x", hash[i]);
+            pc.printf("\n\r");
             }
-        
-        if ((timer_nonce.read()-previous_time) > 1000){
-            printf("Computation Rate: %d computation /sec", (*nonce-last_nonce_number));
+            
+        if ((timer_nonce.read_ms()-previous_time) > 1000){
+            pc.printf("Computation Rate: %lu computation /sec\n\r" , (*nonce-last_nonce_number));
             last_nonce_number = *nonce;
+            previous_time = timer_nonce.read_ms();
+
             }   
         
         }