First Commit
Dependencies: mbed Crypto_light mbed-rtos
Spin it 2 win it
Diff: main.cpp
- Revision:
- 14:66746291017c
- Parent:
- 13:ecccfc611025
- Child:
- 15:bd303ab8a21f
--- a/main.cpp Tue Mar 20 13:17:10 2018 +0000 +++ b/main.cpp Tue Mar 20 13:53:28 2018 +0000 @@ -48,7 +48,7 @@ enum MSG {MSG_RESET, MSG_HASHCOUNT, MSG_NONCE_OK, - MSG_OVERFLOW, MSG_NEW_KEY, MSG_ASSIGN_KEY, MSG_TEST}; + MSG_OVERFLOW, MSG_ROT_PEN, MSG_MAX_SPD, MSG_NEW_KEY, MSG_INP_ERR, MSG_TEST}; //Instantiate the serial port RawSerial pc(SERIAL_TX, SERIAL_RX); @@ -100,10 +100,13 @@ -//Global varible for the Bitcoin Key +//Global varible for the Bitcoin Key,maxspeed and rotations_pending volatile uint64_t newKey = 0; //check initialise value? **** - -Mutex newKey_mutex; //for mutex locking +volatile float maxspeed = 0, rotations_pending = 0; +//mutex variables +Mutex newKey_mutex; +Mutex maxspeed_mutex; +Mutex rotations_pending_mutex; //Instantiate a Queue to buffer incoming characters Queue<void, 8> inCharQ; @@ -118,28 +121,33 @@ Thread decodeT; -void setNewCmd(char newCmd[CHAR_ARR_SIZE]){ - //regex error checking **** - - //K - if(newCmd[0] == 'K'){ - newKey_mutex.lock(); - sscanf(newCmd, "K%x", &newKey); //Decode the command - newKey_mutex.unlock(); - putMessage(MSG_NEW_KEY, newKey); - } +void setNewCmd(char s[CHAR_ARR_SIZE]) +{ + uint64_t newKey_; + float maxspeed_, rotations_pending_; + //R + if (sscanf(s, "R%f", &rotations_pending_)) { + rotations_pending_mutex.lock(); + rotations_pending = rotations_pending_; + rotations_pending_mutex.unlock(); + putMessage(MSG_ROT_PEN,rotations_pending); + //V + } else if (sscanf(s, "V%f", &maxspeed_)) { + maxspeed_mutex.lock(); + maxspeed = maxspeed_; + maxspeed_mutex.unlock(); + putMessage(MSG_MAX_SPD, maxspeed); + //K + } else if (sscanf(s, "K%llx", &newKey_)) { + newKey_mutex.lock(); + newKey = newKey_; + newKey_mutex.unlock(); + putMessage(MSG_NEW_KEY, newKey); + //ERROR + } else + putMessage(MSG_INP_ERR, 0x404); +} - //V - if(newCmd[0] == 'V'){ - //set new velocity*** - } - - //R - if(newCmd[0] == 'R'){ - //set new rotation*** - } - -} void decodeFn() { @@ -277,7 +285,8 @@ *key = newKey; - //putMessage(MSG_ASSIGN_KEY, newKey); + + sha256.computeHash(hash, sequence, 64);