-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart.cpp
executable file
·100 lines (72 loc) · 2.56 KB
/
uart.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "uart.h"
#include <stdio.h>
#include <unistd.h> // Used for UART
#include <sys/fcntl.h> // Used for UART
#include <termios.h> // Used for UART
#include <string>
#include <iostream>
using namespace std;
ModeSetting MS;
int main(int argc, char *argv[]) {
/*
* ELAI 目标跟踪上位机示例程序 : 读取跟踪器数据输出流
*
* [ uart.h ] -> 串口配置:
* fid = open(uart_target, O_RDWR | O_NOCTTY ); // 阻塞式接收模式
* ...
* port_options.c_cc[VMIN] = VMINX; // Read at least 1 character
* port_options.c_cc[VTIME] = 0; // Wait indefinetly
*
*/
Uart u;
int i;
/*
* 每条发送指令由字节 '@' 开始, '#' 结束
* 包含起始结束符号一共12字节
*/
unsigned char m[20] = "@0000000000#";
OutputPack OP;
ModeSetting MS;
bool exit_ = false;
system("clear");
while (!exit_)
{
/// 编码一个空指令并且发送 (使用空指令进行数据查询)
MS.reset_command();
MS.encode();
for(int i=0;i<10;i++)m[i+1] = MS.IP.pack_field[i];
m[0] = '@';
m[11] = '#';
usleep(1000);
u.sendUart(m);
cout<<"================= 指令已发送 ================="<<endl;
/*
* 每条接收指令由字节数据位开始, '#' 结束
* 包含起始结束符号一共15字节
*/
u.readUart();
for(int i=0;i<14 && u.serial_message[i]!='#';i++) {
OP.pack_field[i] = u.serial_message[i];
}
/*
* 一般输出以及物理意义:
* Message Received:x y width height 1 confidence
* - 其中, (x,y)代表目标在画面中的包围框的左上角坐标, (width,height)代表包围框的尺寸, 最后一位0/1分别代表跟踪器的[丢失/锁定]状态
* - 我们使用图像左上角为原点的坐标系, 水平向右为X轴正方向, 垂直向下为Y轴正方向
* - 最后一位浮点数据代表信心度
* 例如:
* Message Received:288 218 100 100 1 0.98
*/
for(int i=0;i<5;i++) {
cout<<OP.data_field[i]<<" ";
}
std::cout<<std::endl;
ConfidencePack confidence_;
confidence_.pack_field[0] = OP.data_field[5];
confidence_.pack_field[1] = OP.data_field[6];
std::cout<<"tracker confidence : "<<confidence_.confidence<<std::endl;
cout<<endl<<"================= 数据已接收 ================="<<endl;
}
u.closeUart();
return 0;
}