数据接收
This commit is contained in:
21
main.cpp
21
main.cpp
@@ -93,22 +93,25 @@ void uartReceive(Uart* uart){
|
|||||||
char buffer[100];
|
char buffer[100];
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
while(true){
|
while(true){
|
||||||
unsigned int data;
|
char data;
|
||||||
while(1){
|
while((data=uart->receive()) != '\n'){
|
||||||
cout << (data=uart->receive()) << endl;
|
buffer[cnt++] = data;
|
||||||
// buffer[cnt++] = data;
|
|
||||||
}buffer[cnt] = 0;
|
}buffer[cnt] = 0;
|
||||||
if(cnt==1 && buffer[0]=='e'){
|
if(cnt == 9){
|
||||||
|
if(buffer[8] == 'e'){
|
||||||
state = ENERGY_STATE;
|
state = ENERGY_STATE;
|
||||||
LOGM("State switch to energy!");
|
LOGM("Energy state");
|
||||||
}else if(cnt==1 && buffer[0]=='a'){
|
memcpy(&yaw, buffer, 4);
|
||||||
|
memcpy(&pitch, buffer+4, 4);
|
||||||
|
LOGM("Get yaw:%f pitch:%f", yaw, pitch);
|
||||||
|
}else if(buffer[8] == 'a'){
|
||||||
state = ARMOR_STATE;
|
state = ARMOR_STATE;
|
||||||
LOGM("State switch to armor!");
|
LOGM("Armor state");
|
||||||
}else if(cnt==8){
|
|
||||||
memcpy(&yaw, buffer, 4);
|
memcpy(&yaw, buffer, 4);
|
||||||
memcpy(&pitch, buffer+4, 4);
|
memcpy(&pitch, buffer+4, 4);
|
||||||
LOGM("Get yaw:%f pitch:%f", yaw, pitch);
|
LOGM("Get yaw:%f pitch:%f", yaw, pitch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user