Olaf Sikorski
/
motor-mining
This is probably never gonna get done
Diff: main.cpp
- Revision:
- 16:10d53b056b17
- Parent:
- 15:f43d1d4e4260
- Child:
- 17:ff5300ba5442
--- a/main.cpp Tue Mar 12 15:42:01 2019 +0000 +++ b/main.cpp Tue Mar 12 16:27:30 2019 +0000 @@ -72,6 +72,7 @@ Mail<mail_t, 16> mail_box; Thread commandProcessorthread; +Thread bitcointhread; RawSerial pc(SERIAL_TX, SERIAL_RX); Queue<void, 8> inCharQ; Mutex newKey_mutex; @@ -115,7 +116,46 @@ } } } - +void bitcoin(){ + while(1) { + SHA256 sha; + 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*) ((int) sequence + 48); + uint64_t* nonce = (uint64_t*) ((int) sequence + 56); + uint8_t hash[32]; + + Timer t; + t.start(); + unsigned currentTime = 0; + unsigned currentCount = 0; + + for (unsigned i = 0; i <= UINT_MAX; i++) { + (*nonce)++; + newKey_mutex.lock(); + *key = newKey; + newKey_mutex.unlock(); + sha.computeHash(hash, sequence, 64); + if (hash[0] == 0 && hash[1] == 0) { + //putMessage(nonce); + pc.printf("Successful nonce: %016x\n\r", *nonce); + } + if ((unsigned) t.read() == currentTime) { + //pc.printf("Hash rate: %d\n\r", i - currentCount); + pc.printf("Current key: %016llx\n\r", *key); + currentTime++; + currentCount = i; + } + } + t.stop(); + } + } //Set a given drive state void motorOut(int8_t driveState){ @@ -161,7 +201,11 @@ int main() { //Serial pc(SERIAL_TX, SERIAL_RX); + bitcointhread.set_priority(osPriorityNormal); + commandProcessorthread.set_priority(osPriorityHigh); + commandProcessorthread.start(commandProcessor); + bitcointhread.start(bitcoin); pc.printf("Hello Pete\n\r"); @@ -176,42 +220,5 @@ I2.fall(&push); I3.fall(&push); - while(1) { - SHA256 sha; - 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*) ((int) sequence + 48); - uint64_t* nonce = (uint64_t*) ((int) sequence + 56); - uint8_t hash[32]; - - Timer t; - t.start(); - unsigned currentTime = 0; - unsigned currentCount = 0; - - for (unsigned i = 0; i <= UINT_MAX; i++) { - (*nonce)++; - newKey_mutex.lock(); - *key = newKey; - newKey_mutex.unlock(); - sha.computeHash(hash, sequence, 64); - if (hash[0] == 0 && hash[1] == 0) { - //putMessage(nonce); - pc.printf("Successful nonce: %016x\n\r", *nonce); - } - if ((unsigned) t.read() == currentTime) { - //pc.printf("Hash rate: %d\n\r", i - currentCount); - pc.printf("Current key: %016llx\n\r", *key); - currentTime++; - currentCount = i; - } - } - t.stop(); - } + }