-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialCommunication.cpp
More file actions
38 lines (27 loc) · 1.05 KB
/
SerialCommunication.cpp
File metadata and controls
38 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "SerialCommunication.h"
SerialCommunication::SerialCommunication(PinName tx, PinName rx, int baudRate): tx(tx), rx(rx){
serial = new Serial(tx, rx); // tx, rx
serial->baud(baudRate);
messageLength = 4; // tam palavra + 1 ('\n')
debug = new DigitalOut(LED1); // debug send info
}
int SerialCommunication::ReceiveCommand(){ // RECEIVE INFO
char commandReceived[messageLength];
if(serial->readable()){
serial->gets(commandReceived,messageLength);
if (strcmp(commandReceived, "s0b") == 0){ //s0b : ex de palavra q desejo receber"
return 1;
}
}
return 0;
}
void SerialCommunication::SendCommand(string commandSended){ // SEND INFO
// SEND INFO
//while(1){
serial->printf("%s",commandSended);
debug->write(1);
wait(DELAY_COMMAND);
debug->write(0);
wait(DELAY_COMMAND);
//}
}