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.

61 lines
1.4 KiB

2 years ago
  1. #pragma once
  2. #include <termios.h>
  3. #include <unistd.h>
  4. #include <fstream>
  5. #include <functional>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <memory>
  10. #include <set>
  11. #include <sstream>
  12. #include <string>
  13. #include <vector>
  14. namespace iflytop {
  15. using namespace std;
  16. // ref:https://www.cnblogs.com/electron/p/3451114.html
  17. // ref:https://baike.baidu.com/item/tcflush/6869357?fr=aladdin
  18. class Uart {
  19. private:
  20. /* data */
  21. int m_fd = 0;
  22. string m_name;
  23. string m_rate;
  24. struct termios m_tty;
  25. string m_error;
  26. public:
  27. Uart();
  28. ~Uart();
  29. /**
  30. * @brief
  31. *
  32. * @param path
  33. * @param rate
  34. * "0" "50" "75" "110"
  35. * "134" "150" "200" "300"
  36. * "600" "1200" "1800" "2400"
  37. * "4800" "9600" "19200" "38400"
  38. * "57600" "115200" "230400" "460800"
  39. * "500000" "576000" "921600" "1000000"
  40. * "1152000" "1500000" "2000000" "2500000"
  41. * "3000000" "3500000" "4000000"
  42. *
  43. * @return int
  44. */
  45. int open(string path, string rate);
  46. int send(char *data, int size);
  47. int receive(char *data, int size_max);
  48. int receive(char *data, int size, int overtimems);
  49. int close();
  50. string get_error() { return m_error; }
  51. bool flush_rx();
  52. bool flush_tx();
  53. bool set_rx_overtime(int n100ms);
  54. };
  55. } // namespace iflytop