62 lines
1.1 KiB
C++
62 lines
1.1 KiB
C++
#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>
|
|
#include <iostream>
|
|
#include <chrono>
|
|
|
|
#include <bitset>
|
|
|
|
|
|
class LFR_UART
|
|
{
|
|
public:
|
|
std::chrono::milliseconds last;
|
|
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(int8_t *buff, uint32_t bufferLength);
|
|
int readFromFile(int8_t *buff, uint32_t bufferLength);
|
|
|
|
public:
|
|
|
|
int8_t doubleToByte(double in);
|
|
double byteToDouble(int8_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;
|
|
}
|
|
};
|