diff --git a/cpp/a.out b/cpp/a.out index c69e1f3..52c5bcd 100755 Binary files a/cpp/a.out and b/cpp/a.out differ diff --git a/cpp/main.cpp b/cpp/main.cpp index f32fc57..c332876 100644 --- a/cpp/main.cpp +++ b/cpp/main.cpp @@ -17,17 +17,16 @@ using namespace iflytop; class Uart g_uart; int main(int argc, char *argv[]) { - pthread_t pid1, pid2; - pthread_attr_t *pthread_arr1, *pthread_arr2; - pthread_arr1 = NULL; - pthread_arr2 = NULL; + int rec_len; + char buffer[128]; g_uart.open(argv[1]); - char buffer[128]; - while (1) { - g_uart.receive(buffer, sizeof(buffer)); + rec_len = g_uart.receive(buffer, sizeof(buffer)); + if (rec_len > 0) { + g_uart.send(buffer, rec_len); + } usleep(1000); } return 0; diff --git a/cpp/uart.cpp b/cpp/uart.cpp index 8007cb7..eadbdfb 100644 --- a/cpp/uart.cpp +++ b/cpp/uart.cpp @@ -68,8 +68,6 @@ int Uart::send(char *data, int size) { sent = write(m_fd, data, size); if (sent > 0) { printf("send success, data is %s\r\n", data); - } else { - printf("send error!\r\n"); } return sent; } @@ -79,7 +77,6 @@ int Uart::receive(char *data, int size_max) { received = read(m_fd, data, size_max); if (received > 0) { printf("recv success,recv size is %d,data is %s\r\n", received, data); - Uart::send(data, received); } return received; }