| | |
| | | #define JNICALLBACK_SERIAL_PORT_H |
| | | |
| | | #include <stdint.h> |
| | | |
| | | #define UART_0 0 |
| | | #define UART_1 1 |
| | | #include <mutex> |
| | | |
| | | struct serial_config { |
| | | char name[32]; |
| | | char name[64]; |
| | | int baud; |
| | | int data_bit; |
| | | char verify_bit; |
| | |
| | | int flow_ctrl; |
| | | }; |
| | | |
| | | int InitSerialPort(int id, int baud, int dataBits, char parity, int stopBits, int flowctrl); |
| | | void UninitSerialPort(int id); |
| | | 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); |
| | | }; |
| | | |
| | | int GetSerialPort(int id); |
| | | int ReadSerialPort(int id, uint8_t *out, uint16_t length); |
| | | int WriteSerialPort(int id, const void *buf, int len); |
| | | int setRTS(int fd, int level); |
| | | typedef int (SerialPort::*pSerialPortClassFun)(const void *buf, int len); |
| | | |
| | | #endif //JNICALLBACK_SERIAL_PORT_H |