fork of what I have been writing

Dependencies:   Crypto

Files at this revision

API Documentation at this revision

Comitter:
kubitz
Date:
Fri Feb 28 18:00:01 2020 +0000
Parent:
1:e9be8b2c8c69
Child:
3:8443825642d1
Commit message:
added rtos and email

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 17:40:23 2020 +0000
+++ b/ES_CW2_Starter_STARFISH/main.cpp	Fri Feb 28 18:00:01 2020 +0000
@@ -1,10 +1,11 @@
 #include "mbed.h"
 #include "SHA256.h"
+#include "rtos.h"
 
 Timer timer_nonce;
 
 typedef struct {
-  uint32_t counter; /* A counter value               */
+  uint8_t hash[32]; /* hash of successful nonce             */
 } mail_t;
 
 Mail<mail_t, 16> mail_box;
@@ -22,7 +23,6 @@
 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;
 
@@ -150,10 +150,17 @@
         osEvent evt = mail_box.get();
         if (evt.status == osEventMail) {
             mail_t *mail = (mail_t*)evt.value.p;
-            printf("Number of cycles: %u\n\r", mail->counter);
+            
+            printf("Number of cycles: %u\n\r", mail->hash);
             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() {
@@ -184,14 +191,12 @@
 
         *nonce ++;
         SHA256::computeHash(hash, (uint8_t*)sequence, 64);
-           mail_box.put(mail);
+        mail_box.put(mail);
      
         if ((hash[0]==0)&&(hash[1]==0)){
             last_nonce_number = successful_nonce;
             successful_nonce++;
-            printf("Successful Nonce -- hash: ");
-            for(int i = 0; i < 32; ++i)
-            printf("\n");
+            putMessage(hash);
             }
         
         if ((timer_nonce.read()-previous_time) > 1000){