//
|
// Created by YY on 2017/9/5.
|
//
|
|
#ifndef JNICALLBACK_SERIAL_PORT_H
|
#define JNICALLBACK_SERIAL_PORT_H
|
|
#include <stdint.h>
|
#include <mutex>
|
|
struct serial_config {
|
char name[64];
|
int baud;
|
int data_bit;
|
char verify_bit;
|
int stop_bit;
|
int flow_ctrl;
|
};
|
|
class SerialPort {
|
private:
|
int fd = -1;
|
std::mutex mtx;
|
struct serial_config cfg;
|
int setRTS(int level);
|
int SetSerialPort(int fd, int speed, int databits, char parity, int stopbits, int flowctrl);
|
int OpenSerialPort(const char *name);
|
void CloseSerialPort(int fd);
|
void UninitSerialPort(void);
|
public:
|
SerialPort(struct serial_config cfg);
|
virtual ~SerialPort();
|
int InitSerialPort(void);
|
int WriteSerialPort(const void *buf, int len);
|
int ReadSerialPort(uint8_t *out, uint16_t length);
|
};
|
|
typedef int (SerialPort::*pSerialPortClassFun)(const void *buf, int len);
|
|
#endif //JNICALLBACK_SERIAL_PORT_H
|