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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <bitset>
  14. class LFR_UART
  15. {
  16. int fileDescriptor;
  17. const char* serialPortPath = "/dev/ttyS0";
  18. void openFile(const char *fileName);
  19. int closeFile();
  20. struct termios tty;
  21. void openSerialPort();
  22. void configureSerialPort();
  23. void closeSerialPort();
  24. int writeDataToFile(uint8_t *buff, uint32_t bufferLength);
  25. int readFromFile(uint8_t *buff, uint32_t bufferLength);
  26. public:
  27. uint8_t doubleToByte(double in);
  28. double byteToDouble(uint8_t in);
  29. void sendTelegram(double wheel1, double wheel2, double wheel3, double wheel4);
  30. bool readTelegram(double* buffer);
  31. LFR_UART();
  32. ~LFR_UART();
  33. };
  34. class CommunicatorException: public std::exception
  35. {
  36. const char* msg;
  37. public:
  38. CommunicatorException(const char* msg): msg(msg) {}
  39. virtual const char* what() const throw()
  40. {
  41. return msg;
  42. }
  43. };