Callum and Adel's changes on 12/02/19
Dependencies: Crypto
Diff: main.cpp
- Revision:
- 32:fc5e00d9f74d
- Parent:
- 31:b10ca6cf39bf
- Child:
- 33:f1dc3b160eac
diff -r b10ca6cf39bf -r fc5e00d9f74d main.cpp --- a/main.cpp Mon Mar 18 17:00:11 2019 +0000 +++ b/main.cpp Mon Mar 18 18:04:29 2019 +0000 @@ -486,23 +486,21 @@ void motorCtrlTick(){ t_motor_ctrl.signal_set(0x1); } - }; - - -//Main int main() { - // std::ios::sync_with_stdio(false); - Comm comm_plz; + // Declare Objects + Comm comm_port; + SHA256 miner; + Motor motor; + + // Start Motor and Comm Port + motor.motorStart(&comm_port); + comm_port.start_comm(); - // comm_plz.pc.printf("%s\n", "do i work bruh" ); // using printf of class is calm - SHA256 Miner; - - Motor motor; - + // Declare Hash 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, @@ -516,43 +514,34 @@ uint8_t hash[32]; uint32_t length64 = 64; uint32_t hashCounter = 0; + + // Begin Main Timer Timer timer; - - motor.motorStart(&comm_plz); - comm_plz.start_comm(); - - // Motor States - - // pc.printf("Rotor origin: %x\n\r",orState); - // orState is subtracted from future rotor state inputs to align rotor and motor states - // intState = readRotorState(); - //if (intState != intStateOld) { - // pc.printf("old:%d \t new:%d \t next:%d \n\r",intStateOld, intState, (intState-orState+lead+6)%6); - // intStateOld = intState; - // motorOut((intState-orState+lead+6)%6); //+6 to make sure the remainder is positive - // } - - // Keep the program running indefinitely - timer.start(); // start timer + timer.start(); + // Loop Program while (1) { - // pc.printf("Current:%d \t Next:%d \n\r", currentState, (currentState-orState+lead+6)%6); - comm_plz.newKey_mutex.lock(); - *key = comm_plz.newKey; - comm_plz.newKey_mutex.unlock(); - Miner.computeHash(hash, sequence, length64); + + // Mutex For Access Control + comm_port.newKey_mutex.lock(); + *key = comm_port.newKey; + comm_port.newKey_mutex.unlock(); + + // Compute Hash and Counter + miner.computeHash(hash, sequence, length64); hashCounter++; + + // Enum Casting and Condition if ((hash[0]==0) && (hash[1]==0)){ - comm_plz.putMessage((Comm::msgType)7, *nonce); + comm_port.putMessage((Comm::msgType)7, *nonce); } - // Try a new nonce + // Try Nonce (*nonce)++; - - // Per Second i.e. when greater or equal to 1 + + // Display via Comm Port if (timer.read() >= 1){ - comm_plz.putMessage((Comm::msgType)5, hashCounter); - //pc.printf("HashRate = %02u \n\r",hashCounter); + comm_port.putMessage((Comm::msgType)5, hashCounter); hashCounter=0; timer.reset(); }