You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
729 B

2 years ago
  1. #include <string.h>
  2. #include <fstream>
  3. #include <functional>
  4. #include <iostream>
  5. #include <list>
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <sstream>
  10. #include <string>
  11. #include <thread>
  12. #include <vector>
  13. #include "uart.hpp"
  14. using namespace std;
  15. using namespace iflytop;
  16. #define UART_NAME "/dev/ttyUSB0"
  17. int main(int argc, char const* argv[]) {
  18. Uart uart;
  19. uart.open(UART_NAME, "115200");
  20. thread th([&]() {
  21. //
  22. while (true) {
  23. char buf[1024];
  24. memset(buf, 0, 1024);
  25. int size = uart.receive(buf, 1024, 10);
  26. if (size > 0) {
  27. cout << "receive:" << buf << endl;
  28. }
  29. }
  30. });
  31. while (true) {
  32. printf("tx hello\n");
  33. uart.send("hello", 5);
  34. sleep(1);
  35. }
  36. }