# B15F: drv/usart.h Source File

usart.h
#ifndef USART_H
#define USART_H
#include <iostream>
#include <cstdint>
#include <chrono>
#include <unistd.h>
#include <cstring>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <cmath>
#include "usartexception.h"
#include "timeoutexception.h"
class USART
{
public:
/*************************************************
* Methoden für die Verwaltung der Schnittstelle *
*************************************************/
void openDevice(std::string device);
void closeDevice(void);
void clearInputBuffer(void);
void clearOutputBuffer(void);
void flushOutputBuffer(void);
void printStatistics(void);
/*************************************************/
/*************************************
* Methoden für die Datenübertragung *
*************************************/
void writeByte(uint8_t b);
void writeInt(uint16_t d);
uint8_t readByte(void);
uint16_t readInt(void);
int read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout);
int write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout);
void writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len);
bool readBlock(uint8_t* buffer, uint16_t offset);
/*************************************/
/***************************************
* Methoden für einstellbare Parameter *
***************************************/
uint32_t getBaudrate(void);
uint8_t getTimeout(void);
void setBaudrate(uint32_t baudrate);
void setTimeout(uint8_t timeout);
/***************************************/
constexpr static uint8_t CRC7_POLY = 0x91;
constexpr static uint8_t MAX_BLOCK_SIZE = 64;
constexpr static uint8_t BLOCK_END = 0x80;
private:
int file_desc = -1; // Linux Dateideskriptor
uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden!
int TEST = 0;
uint8_t timeout = 10; // in Dezisekunden
uint8_t block_buffer[MAX_BLOCK_SIZE + 3];
// debug statistics
uint32_t n_blocks_total = 0;
uint32_t n_blocks_failed = 0;
};
#endif // USART_H
USART::getBaudrate
uint32_t getBaudrate(void)
Definition: usart.cpp:306
USART::readByte
uint8_t readByte(void)
Definition: usart.cpp:210
USART::printStatistics
void printStatistics(void)
Definition: usart.cpp:60
USART::closeDevice
void closeDevice(void)
Definition: usart.cpp:32
USART::clearInputBuffer
void clearInputBuffer(void)
Definition: usart.cpp:39
USART::getTimeout
uint8_t getTimeout(void)
Definition: usart.cpp:311
USART
Definition: usart.h:16
USART::clearOutputBuffer
void clearOutputBuffer(void)
Definition: usart.cpp:46
USART::setBaudrate
void setBaudrate(uint32_t baudrate)
Definition: usart.cpp:316
USART::writeByte
void writeByte(uint8_t b)
Definition: usart.cpp:67
USART::openDevice
void openDevice(std::string device)
Definition: usart.cpp:3
USART::readInt
uint16_t readInt(void)
Definition: usart.cpp:229
USART::setTimeout
void setTimeout(uint8_t timeout)
Definition: usart.cpp:321
USART::flushOutputBuffer
void flushOutputBuffer(void)
Definition: usart.cpp:53
USART::writeInt
void writeInt(uint16_t d)
Definition: usart.cpp:81