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

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