ser.h
Go to the documentation of this file.
1 /* Copyright 2017 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jimy Zhang <jimy92@163.com>
6  ============================================================================*/
7 #ifndef CORE_PORT_SERIAL_H_
8 #define CORE_PORT_SERIAL_H_
9 
10 #include <iostream>
11 #include <thread>
12 
13 #include "serial/serial.h"
16 
17 class SerialPort {
18 public:
19  SerialPort(const char *port, int baud, int que_num, int que_maxlen);
20  ~SerialPort(void);
22  int is_ok(void);
23  void flush(void);
24  void recv_proc(void);
25  int write_frame(unsigned char *data, int len);
26  int read_frame(unsigned char *data);
27  void close_port(void);
29  int que_num_;
30 
31 private:
32  int fp_;
33  int state_;
34  std::thread thread_id_;
35 
37  int init_serial(const char *port, int baud);
38  int read_char(unsigned char *ch);
39  int write_char(unsigned char ch);
40  void parse_put(unsigned char *data, int len);
41 
42  typedef enum _UXBUS_RECV_STATE {
50 
51  unsigned char UXBUS_PROT_FROMID_;
52  unsigned char UXBUS_PROT_TOID_;
53 
55  int rx_state_;
56  unsigned char rx_buf_[128];
58 };
59 
60 #endif
void close_port(void)
Definition: ser.cc:141
int fp_
Definition: ser.h:32
int read_frame(unsigned char *data)
Definition: ser.cc:105
unsigned char UXBUS_PROT_FROMID_
Definition: ser.h:51
int write_char(unsigned char ch)
Definition: ser.cc:114
int write_frame(unsigned char *data, int len)
Definition: ser.cc:125
void parse_put(unsigned char *data, int len)
Definition: ser.cc:149
void flush(void)
Definition: ser.cc:87
enum SerialPort::_UXBUS_RECV_STATE UXBUS_RECV_STATE
unsigned char UXBUS_PROT_TOID_
Definition: ser.h:52
unsigned char rx_buf_[128]
Definition: ser.h:56
int rx_state_
Definition: ser.h:55
int read_char(unsigned char *ch)
Definition: ser.cc:93
int state_
Definition: ser.h:33
int rx_length_
Definition: ser.h:57
QueueMemcpy * rx_que_
Definition: ser.h:36
SerialPort(const char *port, int baud, int que_num, int que_maxlen)
Definition: ser.cc:52
int rx_data_idx_
Definition: ser.h:54
~SerialPort(void)
Definition: ser.cc:80
int init_serial(const char *port, int baud)
Definition: ser.cc:220
_UXBUS_RECV_STATE
Definition: ser.h:42
serial::Serial ser
Definition: ser.h:21
int que_maxlen_
Definition: ser.h:28
std::thread thread_id_
Definition: ser.h:34
int que_num_
Definition: ser.h:29
int is_ok(void)
Definition: ser.cc:85
Definition: ser.h:17
void recv_proc(void)
Definition: ser.cc:26


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23