An embedded device
Dependencies: Crypto
Diff: main.cpp
- Revision:
- 17:ff5300ba5442
- Parent:
- 16:10d53b056b17
- Child:
- 18:e48c0910c71e
diff -r 10d53b056b17 -r ff5300ba5442 main.cpp --- a/main.cpp Tue Mar 12 16:27:30 2019 +0000 +++ b/main.cpp Sat Mar 16 15:53:32 2019 +0000 @@ -61,10 +61,12 @@ DigitalOut L2H(L2Hpin); DigitalOut L3L(L3Lpin); DigitalOut L3H(L3Hpin); +PwmOut PWM(PWMpin); int8_t orState = 0; int8_t intState = 0; int8_t intStateOld = 0; +int32_t revoCounter = 0; //Counts the number of revolutions typedef struct { uint64_t nonce; @@ -91,7 +93,8 @@ void commandProcessor() { pc.attach(&serialISR); - char command[18]; + char command[19]; + char* number; //char k; uint64_t receivedKey; uint8_t index = 0; @@ -100,22 +103,43 @@ uint8_t newChar = (uint8_t) newEvent.value.p; command[index] = newChar; index++; - if (newChar == '\r') { + if (newChar == '\r') { command[17] = '\0'; - receivedKey = strtoull(command, NULL, 16); - //receivedKey = 2147483648; - //sscanf(command, "%d", &receivedKey); - pc.printf("Received key: %016llx\n\r", receivedKey); + + if (command[0] == 'R') { + pc.printf("Rotation command\n"); + pc.printf("%s", command); + } + else if (command[0] == 'V') { + pc.printf("Max speed command\n"); + pc.printf("%s", command); + } + else if (command[0] == 'K') { + if (index == 18){ // when index is 18 means you entered K and 16 digits + number = command +1; //super bad solution, but I don't know how to work with strings in C + receivedKey = strtoull(number, NULL, 16); + //receivedKey = 2147483648; + //sscanf(command, "%d", &receivedKey); + pc.printf("Received key: %016llx\n\r", receivedKey); + newKey_mutex.lock(); + newKey = receivedKey; + newKey_mutex.unlock(); + } else { + pc.printf("Not a valid key!"); + }; + } + else if (command[0] == 'T') { + pc.printf("Melody command\n"); + pc.printf("%s", command); + } memset(command, 0, sizeof(command)); - newKey_mutex.lock(); - newKey = receivedKey; - newKey_mutex.unlock(); index = 0; } else { pc.printf("Current command: %s\n\r", command); } } } + void bitcoin(){ while(1) { SHA256 sha; @@ -201,11 +225,14 @@ int main() { //Serial pc(SERIAL_TX, SERIAL_RX); + //Initialise bincoin mining and communication bitcointhread.set_priority(osPriorityNormal); commandProcessorthread.set_priority(osPriorityHigh); - commandProcessorthread.start(commandProcessor); bitcointhread.start(bitcoin); + + PWM.period(0.002f); //Set PWM period in seconds + PWM.write(0.5); //Set PWM duty in % pc.printf("Hello Pete\n\r");