9 int main(
int argc,
char** argv){
12 std::string serialNumber_;
13 serialNumber_ =
"/dev/ttyUSB0";
14 int baudRate_ = 115200;
16 std::stringstream ostream;
24 memset(buf, 0xba,
sizeof(buf));
25 memset(temp_buf, 0xba,
sizeof(temp_buf));
26 memset(result_buf, 0xba,
sizeof(result_buf));
28 fd = open(serialNumber_.c_str(), O_RDWR | O_NOCTTY | O_NDELAY );
30 std::cout<<
"Open Serial: "<<serialNumber_.c_str()<<
" Error!";
34 cht10driver_.
UART0_Init(fd,baudRate_,0,8,1,
'N');
38 for(
int i = 0; i < len; i++){
40 result_buf[rcv_cnt++] = buf[i];
56 for(
int count = 0; count < 4; count++){
57 data_buf[count] = result_buf[9+count];
59 sscanf(data_buf,
"%x", &laser_data);
60 std::cout<<
"sensor data:"<<laser_data<<
", Distance: "<<(double)laser_data/1000<<std::endl;
66 result_buf[rcv_cnt++] = buf[i];
int UART0_Recv(int fd, char *rcv_buf, int data_len)
int main(int argc, char **argv)
int UART0_Init(int fd, int speed, int flow_ctrl, int databits, int stopbits, int parity)