Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
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.

uart_communication.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <termios.h>
  10. #include <iostream>
  11. #include <exception>
  12. #include <iostream>
  13. #include <chrono>
  14. #include <bitset>
  15. class LFR_UART
  16. {
  17. public:
  18. std::chrono::milliseconds last;
  19. int fileDescriptor;
  20. const char* serialPortPath = "/dev/ttyS0";
  21. void openFile(const char *fileName);
  22. int closeFile();
  23. struct termios tty;
  24. void openSerialPort();
  25. void configureSerialPort();
  26. void closeSerialPort();
  27. int writeDataToFile(int8_t *buff, uint32_t bufferLength);
  28. int readFromFile(int8_t *buff, uint32_t bufferLength);
  29. public:
  30. int8_t doubleToByte(double in);
  31. double byteToDouble(int8_t in);
  32. void sendTelegram(double wheel1, double wheel2, double wheel3, double wheel4);
  33. bool readTelegram(double* buffer);
  34. LFR_UART();
  35. ~LFR_UART();
  36. };
  37. class CommunicatorException: public std::exception
  38. {
  39. const char* msg;
  40. public:
  41. CommunicatorException(const char* msg): msg(msg) {}
  42. virtual const char* what() const throw()
  43. {
  44. return msg;
  45. }
  46. };