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 1020B

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