From 34ba7df66f9e336873e8530de2f6b593b877dda6 Mon Sep 17 00:00:00 2001 From: xinyang Date: Sun, 14 Apr 2019 20:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/uart/uart.h | 2 +- main.cpp | 7 ++++--- src/uart/uart.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/uart/uart.h b/include/uart/uart.h index 05f856d..c0a452e 100644 --- a/include/uart/uart.h +++ b/include/uart/uart.h @@ -34,7 +34,7 @@ public: Uart(); void sendTarget(float x, float y ,float z); - char receive(); + uint8_t receive(); void receive_data(); }; diff --git a/main.cpp b/main.cpp index 8a9a067..4508782 100644 --- a/main.cpp +++ b/main.cpp @@ -93,9 +93,10 @@ void uartReceive(Uart* uart){ char buffer[100]; int cnt=0; while(true){ - char data; - while((data=uart->receive()) != '\n'){ - buffer[cnt++] = data; + unsigned int data; + while(1){ + cout << (data=uart->receive()) << endl; +// buffer[cnt++] = data; }buffer[cnt] = 0; if(cnt==1 && buffer[0]=='e'){ state = ENERGY_STATE; diff --git a/src/uart/uart.cpp b/src/uart/uart.cpp index 50c2a0b..faa8054 100644 --- a/src/uart/uart.cpp +++ b/src/uart/uart.cpp @@ -153,8 +153,8 @@ void Uart::sendTarget(float x, float y, float z) { // 's' + (x) ( 8bit + 8bit ) + (y) ( 8bit + 8bit ) + (z) ( 8bit + 8bit ) + 'e' -char Uart::receive() { - char data; +uint8_t Uart::receive() { + uint8_t data; while(read(fd, &data, 1) < 1); return data; }