33 lines
850 B
C
33 lines
850 B
C
|
#ifndef USARTCLASS_H
|
||
|
#define USARTCLASS_H
|
||
|
|
||
|
#include <pthread.h>
|
||
|
#include "../common/baselayer.h"
|
||
|
|
||
|
static constexpr unsigned BUFLEN = 1024u;
|
||
|
// Bottom
|
||
|
class UsartClass : public BaseLayer {
|
||
|
public:
|
||
|
UsartClass (const char* name, const int baudrate);
|
||
|
uint32_t Up (const char* data, uint32_t len);
|
||
|
uint32_t Down(const char* data, uint32_t len);
|
||
|
virtual ~UsartClass ();
|
||
|
protected:
|
||
|
void ReadLoop (void);
|
||
|
static void* UsartHandler (void* p) {
|
||
|
UsartClass* inst = (UsartClass*) p;
|
||
|
inst->ReadLoop();
|
||
|
return nullptr;
|
||
|
};
|
||
|
void setBaud (int baud);
|
||
|
public:
|
||
|
bool running;
|
||
|
private:
|
||
|
const char * id; //!< Identifikátor třídy pro ladění
|
||
|
char rxbuf[BUFLEN];
|
||
|
int fd;
|
||
|
int timeout;
|
||
|
pthread_t rc;
|
||
|
};
|
||
|
#endif // USARTCLASS_H
|