Line-Following-Robot/Communication/uart_communication.h

58 lines
1.0 KiB
C
Raw Normal View History

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <iostream>
#include <exception>
2023-01-16 05:38:09 +00:00
#include <iostream>
#include <bitset>
class LFR_UART
{
int fileDescriptor;
const char* serialPortPath = "/dev/ttyS0";
void openFile(const char *fileName);
int closeFile();
struct termios tty;
void openSerialPort();
void configureSerialPort();
void closeSerialPort();
int writeDataToFile(uint8_t *buff, uint32_t bufferLength);
int readFromFile(uint8_t *buff, uint32_t bufferLength);
public:
uint8_t doubleToByte(double in);
double byteToDouble(uint8_t in);
void sendTelegram(double wheel1, double wheel2, double wheel3, double wheel4);
bool readTelegram(double* buffer);
LFR_UART();
~LFR_UART();
};
class CommunicatorException: public std::exception
{
const char* msg;
public:
CommunicatorException(const char* msg): msg(msg) {}
virtual const char* what() const throw()
{
return msg;
}
};