This commit is contained in:
parent
abe3f4cfc6
commit
f51832ebe9
|
@ -27,7 +27,7 @@ CommandLine=
|
||||||
Folders=Common,Common/Headers,Common/Sources,DigtalHuman,DigtalHuman/Headers,DigtalHuman/Sources,Robot,Robot/Headers,Robot/Sources,Uav,Uav/Headers,Uav/Sources
|
Folders=Common,Common/Headers,Common/Sources,DigtalHuman,DigtalHuman/Headers,DigtalHuman/Sources,Robot,Robot/Headers,Robot/Sources,Uav,Uav/Headers,Uav/Sources
|
||||||
IncludeVersionInfo=0
|
IncludeVersionInfo=0
|
||||||
SupportXPThemes=0
|
SupportXPThemes=0
|
||||||
CompilerSet=3
|
CompilerSet=5
|
||||||
CompilerSettings=0000000100000000100000000
|
CompilerSettings=0000000100000000100000000
|
||||||
UnitCount=13
|
UnitCount=13
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -4,7 +4,7 @@ CursorRow=80
|
||||||
TopLine=1
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editors]
|
[Editors]
|
||||||
Order=5,7,8,6
|
Order=5,2,8,4
|
||||||
Focused=5
|
Focused=5
|
||||||
[Editor_1]
|
[Editor_1]
|
||||||
CursorCol=1
|
CursorCol=1
|
||||||
|
@ -12,8 +12,8 @@ CursorRow=1
|
||||||
TopLine=1
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_2]
|
[Editor_2]
|
||||||
CursorCol=35
|
CursorCol=19
|
||||||
CursorRow=8
|
CursorRow=1
|
||||||
TopLine=1
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_3]
|
[Editor_3]
|
||||||
|
@ -22,14 +22,14 @@ CursorRow=6
|
||||||
TopLine=1
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_4]
|
[Editor_4]
|
||||||
CursorCol=18
|
CursorCol=17
|
||||||
CursorRow=16
|
CursorRow=7
|
||||||
TopLine=2
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_5]
|
[Editor_5]
|
||||||
CursorCol=18
|
CursorCol=38
|
||||||
CursorRow=182
|
CursorRow=245
|
||||||
TopLine=160
|
TopLine=226
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_6]
|
[Editor_6]
|
||||||
CursorCol=8
|
CursorCol=8
|
||||||
|
@ -42,18 +42,18 @@ CursorRow=18
|
||||||
TopLine=10
|
TopLine=10
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_9]
|
[Editor_9]
|
||||||
CursorCol=14
|
CursorCol=23
|
||||||
CursorRow=12
|
CursorRow=4
|
||||||
TopLine=1
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_8]
|
[Editor_8]
|
||||||
CursorCol=2
|
CursorCol=42
|
||||||
CursorRow=148
|
CursorRow=14
|
||||||
TopLine=117
|
TopLine=3
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_10]
|
[Editor_10]
|
||||||
CursorCol=1
|
CursorCol=1
|
||||||
CursorRow=1
|
CursorRow=5
|
||||||
TopLine=1
|
TopLine=1
|
||||||
LeftChar=1
|
LeftChar=1
|
||||||
[Editor_12]
|
[Editor_12]
|
||||||
|
|
|
@ -13,11 +13,11 @@ void uavOperate(int choose) {
|
||||||
case 9: get_current_height(); break;
|
case 9: get_current_height(); break;
|
||||||
case 10: get_current_attitude_angle(); break;
|
case 10: get_current_attitude_angle(); break;
|
||||||
case 11: get_current_distance(); break;
|
case 11: get_current_distance(); break;
|
||||||
case 12: get_current_distance(); break;
|
case 12: get_current_horizontal_speed(); break;
|
||||||
case 13: get_current_distance(); break;
|
case 13: get_current_vertical_speed(); break;
|
||||||
case 14: get_current_distance(); break;
|
case 14: open_hd(); break;
|
||||||
case 15: get_current_distance(); break;
|
case 15: close_hd(); break;
|
||||||
case 16: get_current_distance(); break;
|
case 16: fly_by_3d_direction(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,10 @@ int getChoose() {
|
||||||
printf("14.打开高清图传\n");
|
printf("14.打开高清图传\n");
|
||||||
printf("15.关闭高清图传\n");
|
printf("15.关闭高清图传\n");
|
||||||
printf("16.以给定速度朝方向飞行多长时间\n");
|
printf("16.以给定速度朝方向飞行多长时间\n");
|
||||||
printf("17.在规定时间内飞至指定位置\n");
|
// printf("17.在规定时间内飞至指定位置\n");
|
||||||
printf("18.在固定速度的情况下飞至指定位置\n");
|
// printf("18.在固定速度的情况下飞至指定位置\n");
|
||||||
printf("19.无人机悬停\n");
|
// printf("19.无人机悬停\n");
|
||||||
printf("20.打开无人机飞行轨迹\n");
|
// printf("20.打开无人机飞行轨迹\n");
|
||||||
printf("输入操作项:\n");
|
printf("输入操作项:\n");
|
||||||
scanf("%d", &num);
|
scanf("%d", &num);
|
||||||
printf("你输入的整数是: %d\n", num);
|
printf("你输入的整数是: %d\n", num);
|
||||||
|
@ -53,7 +53,7 @@ int getChoose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init() {
|
bool init() {
|
||||||
if (websocket_connect(&websocket,"ws://127.0.0.1:6003") < 0) {
|
if (websocket_connect(&websocket,"ws://127.0.0.1:10088/cxx") < 0) {
|
||||||
printf("WebSocket连接失败");
|
printf("WebSocket连接失败");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,8 @@ void init_position() {
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"pos\":%s,\"type\":\"%s\",\"commond\":\"%s\"}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"pos\":%s,\"commond\":\"%s\"}"
|
||||||
, uav.number,uav.event_id,"[0,0]", uav.type, uav.commond);
|
, uav.number,uav.event_id, uav.type, "[0,0]", uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ void set_name() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "set_name");
|
strcpy(uav.commond, "set_name");
|
||||||
strcpy(uav.name, name);
|
strcpy(uav.name, name);
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
|
@ -124,20 +123,18 @@ void set_color() {
|
||||||
strcpy(uav.commond, "set_color");
|
strcpy(uav.commond, "set_color");
|
||||||
strcpy(uav.color_1, color_1);
|
strcpy(uav.color_1, color_1);
|
||||||
strcpy(uav.color_2, color_2);
|
strcpy(uav.color_2, color_2);
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"color_1\":\"%s\",\"color_2\":\"%s\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"color_1\":\"%s\",\"color_2\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.number,uav.event_id,color_1,color_2, uav.type, uav.commond);
|
, uav.number,uav.event_id,uav.type,color_1,color_2,uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_engine() {
|
void start_engine() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "start_engine");
|
strcpy(uav.commond, "start_engine");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
|
@ -150,7 +147,6 @@ void start_engine() {
|
||||||
void shut_down_engine() {
|
void shut_down_engine() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "shut_down_engine");
|
strcpy(uav.commond, "shut_down_engine");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
|
@ -161,28 +157,20 @@ void shut_down_engine() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_rotor_power() {
|
void set_rotor_power() {
|
||||||
char rotor[20];
|
char rotor[30];
|
||||||
memset(rotor, 0, sizeof(rotor));
|
memset(rotor, 0, sizeof(rotor));
|
||||||
printf("输入旋翼输出参数(四个参数以,分割 例如:1,2,3,4):");
|
printf("输入旋翼输出参数(四个参数以,分割 例如:1,2,3,4):");
|
||||||
scanf("%s", &rotor);
|
scanf("%s", &rotor);
|
||||||
// char *token = strtok(rotor, ","); // 使用逗号作为分隔符,将字符串分割成子字符串
|
|
||||||
// int i = 0;
|
|
||||||
// while (token != NULL) {
|
|
||||||
// inParams2.rotor_power[i] = atoi(token); // 将子字符串转换为整数并插入到整数数组中
|
|
||||||
// token = strtok(NULL, ","); // 继续分割剩余的子字符串
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "set_rotor_power");
|
strcpy(uav.commond, "set_rotor_power");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char data[30];
|
char *data = (char *)malloc(sizeof(char) * 100);
|
||||||
sprintf(data,"{\"power\":[%s]}",rotor);
|
sprintf(data,"{\"power\":[%s]}",rotor);
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 400); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"parameters\":%s,\"type\":\"%s\",\"commond\":\"%s\"}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"parameters\":%s,\"commond\":\"%s\"}"
|
||||||
, uav.number,uav.event_id,data, uav.type, uav.commond);
|
, uav.number,uav.event_id,uav.type,data,uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,131 +179,123 @@ void open_lighter() {
|
||||||
printf("设置灯光颜色:");
|
printf("设置灯光颜色:");
|
||||||
scanf("%s", &color);
|
scanf("%s", &color);
|
||||||
strcpy(inParams.color, color);
|
strcpy(inParams.color, color);
|
||||||
inParams.intensity = 1;
|
inParams.intensity = 1.0;
|
||||||
inParams.halo = 1;
|
inParams.halo = 1.0;
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "open_lighter");
|
strcpy(uav.commond, "open_lighter");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char data[30];
|
char *data = (char *)malloc(sizeof(char) * 100);
|
||||||
sprintf(data,"{\"intensity\":%f,\"color\":\"%s\",\"halo\":%f}",inParams.intensity,inParams.color,inParams.halo);
|
sprintf(data,"{\"intensity\":%i,\"color\":\"%s\",\"halo\":%i}",inParams.intensity,inParams.color,inParams.halo);
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"parameters\":%s,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"parameters\":%s,\"commond\":\"%s\"}"
|
||||||
, uav.type,uav.commond,uav.number, data, uav.event_id);
|
, uav.number,uav.event_id,uav.type,data,uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_lighter() {
|
void close_lighter() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "close_lighter");
|
strcpy(uav.commond, "close_lighter");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_current_height() {
|
void get_current_height() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "get_current_height");
|
strcpy(uav.commond, "get_current_height");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_current_attitude_angle() {
|
void get_current_attitude_angle() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "get_current_attitude_angle");
|
strcpy(uav.commond, "get_current_attitude_angle");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_current_distance() {
|
void get_current_distance() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "get_current_distance");
|
strcpy(uav.commond, "get_current_distance");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_current_horizontal_speed() {
|
void get_current_horizontal_speed() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "get_current_horizontal_speed");
|
strcpy(uav.commond, "get_current_horizontal_speed");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_current_vertical_speed() {
|
void get_current_vertical_speed() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "get_current_vertical_speed");
|
strcpy(uav.commond, "get_current_vertical_speed");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_hd() {
|
void open_hd() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "open_hd");
|
strcpy(uav.commond, "open_hd");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_hd() {
|
void close_hd() {
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "close_hd");
|
strcpy(uav.commond, "close_hd");
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
, uav.number, uav.event_id,uav.type, uav.commond);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fly_by_3d_direction() {
|
void fly_by_3d_direction() {
|
||||||
char powers[3];
|
char powers[7];
|
||||||
|
memset(powers, 0, sizeof(powers));
|
||||||
printf("设置飞行方向,三个参数[X:前后,Y:左右,Z:上下]以,分割(示例:1,2,3):");
|
printf("设置飞行方向,三个参数[X:前后,Y:左右,Z:上下]以,分割(示例:1,2,3):");
|
||||||
scanf("%s", &powers);
|
scanf("%s", &powers);
|
||||||
if(sizeof(powers) != 3){
|
if(sizeof(powers) != 7){
|
||||||
int code;
|
int code;
|
||||||
printf("输入旋翼参数异常,1:重新输入,0:退出");
|
printf("输入旋翼参数异常,1:重新输入,0:退出");
|
||||||
scanf("%c", &code);
|
scanf("%c", &code);
|
||||||
|
@ -328,26 +308,19 @@ void fly_by_3d_direction() {
|
||||||
}
|
}
|
||||||
strcpy(uav.type, "wrj");
|
strcpy(uav.type, "wrj");
|
||||||
strcpy(uav.commond, "fly_by_3d_direction");
|
strcpy(uav.commond, "fly_by_3d_direction");
|
||||||
int i;
|
int speed;
|
||||||
for (i =0;i<4;i++){
|
|
||||||
float p = powers[i];
|
|
||||||
uav.direction[i] = p;
|
|
||||||
}
|
|
||||||
// memcpy(uav.direction, directionF, sizeof(directionF));
|
|
||||||
float speed;
|
|
||||||
printf("设置飞行速度(米/秒):");
|
printf("设置飞行速度(米/秒):");
|
||||||
scanf("%f", &speed);
|
scanf("%i", &speed);
|
||||||
uav.speed = speed;
|
uav.speed = speed;
|
||||||
float duration;
|
int duration;
|
||||||
printf("飞行时间(秒):");
|
printf("飞行时间(秒):");
|
||||||
scanf("%f", &duration);
|
scanf("%i", &duration);
|
||||||
uav.time = duration;
|
uav.time = duration;
|
||||||
number = number + 1;
|
|
||||||
event_id = event_id + 1;
|
event_id = event_id + 1;
|
||||||
uav.number = number;
|
uav.number = number;
|
||||||
uav.event_id = event_id;
|
uav.event_id = event_id;
|
||||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i,\"direction\":\"%s\",\"speed\":%f,\"duration\":%f}"
|
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"time\":%i,\"type\":\"%s\",\"speed\":%i,\"commond\":\"%s\",\"direction\":[%s]}"
|
||||||
, uav.type, uav.commond, uav.number, uav.event_id,uav.direction,uav.speed,uav.time);
|
, uav.number, uav.event_id,duration,uav.type,speed, uav.commond, powers);
|
||||||
sendMessage(json_str);
|
sendMessage(json_str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include "WebsocketConfig.h"
|
#include "WebsocketConfig.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char color[4];
|
char color[20];
|
||||||
float intensity;
|
int intensity;
|
||||||
float halo;
|
int halo;
|
||||||
}InParam;
|
}InParam;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Binary file not shown.
|
@ -9,11 +9,11 @@ int websocket_connect(Websocket *ws, const char *address){
|
||||||
char host[BUF_SIZE], path[BUF_SIZE];
|
char host[BUF_SIZE], path[BUF_SIZE];
|
||||||
int port = 80;
|
int port = 80;
|
||||||
char *url = (char *)malloc(sizeof(char) * 100);
|
char *url = (char *)malloc(sizeof(char) * 100);
|
||||||
memset(url, 0, strlen(url));
|
memset(url, 0, sizeof(url));
|
||||||
if(strlen(address) == 0) {
|
if(strlen(address) == 0) {
|
||||||
url = (char *)"ws://127.0.0.1:10088/cxx";
|
url = (char *)"ws://127.0.0.1:10088/cxx";
|
||||||
} else {
|
} else {
|
||||||
memcpy(url,address,strlen(address));
|
strcpy(url, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf(url, "ws://%[^:/]:%d/%s", host, &port, path) != 3) {
|
if (sscanf(url, "ws://%[^:/]:%d/%s", host, &port, path) != 3) {
|
||||||
|
@ -21,7 +21,7 @@ int websocket_connect(Websocket *ws, const char *address){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if(WSAStartup(MAKEWORD(2,2),&wsaData) != 0) {
|
if(WSAStartup(MAKEWORD(2,2),&wsaData) != 0) {
|
||||||
printf("winsock连接失败");
|
printf("winsock连接失败");
|
||||||
|
@ -39,7 +39,6 @@ int websocket_connect(Websocket *ws, const char *address){
|
||||||
closesocket(sockfd);
|
closesocket(sockfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送WebSocket握手请求
|
// 发送WebSocket握手请求
|
||||||
sprintf(ws->buf, "GET /%s HTTP/1.1\r\n", path);
|
sprintf(ws->buf, "GET /%s HTTP/1.1\r\n", path);
|
||||||
sprintf(ws->buf + strlen(ws->buf), "Host: %s:%d\r\n", host, port);
|
sprintf(ws->buf + strlen(ws->buf), "Host: %s:%d\r\n", host, port);
|
||||||
|
@ -67,7 +66,7 @@ int websocket_connect(Websocket *ws, const char *address){
|
||||||
}
|
}
|
||||||
|
|
||||||
ws->buf[n] = '\0';
|
ws->buf[n] = '\0';
|
||||||
|
|
||||||
//HTTP/1.1 101 Switching Protocols
|
//HTTP/1.1 101 Switching Protocols
|
||||||
if (strstr(ws->buf, "HTTP/1.1 101") == NULL) {
|
if (strstr(ws->buf, "HTTP/1.1 101") == NULL) {
|
||||||
closesocket(sockfd);
|
closesocket(sockfd);
|
||||||
|
@ -87,19 +86,20 @@ int websocket_connect(Websocket *ws, const char *address){
|
||||||
// return json_str;
|
// return json_str;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
int websocket_recv() {
|
int websocket_recv() {
|
||||||
// 接收响应消息
|
// 接收响应消息
|
||||||
char recvMsg[1024];
|
char recvMsg[1024];
|
||||||
memset(recvMsg, 0, sizeof(recvMsg));
|
memset(recvMsg, 0, sizeof(recvMsg));
|
||||||
int recvLen = recv(websocket.sockfd, recvMsg, sizeof(recvMsg) - 1, 0);
|
int recvLen = recv(websocket.sockfd, recvMsg, sizeof(recvMsg)-1, 0);
|
||||||
|
printf("收到响应消息长度:%i",recvLen);
|
||||||
if (recvLen == SOCKET_ERROR || recvLen == 0) {
|
if (recvLen == SOCKET_ERROR || recvLen == 0) {
|
||||||
printf("接收响应消息失败\n");
|
printf("接收响应消息失败\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
recvMsg[recvLen] = '\0';
|
recvMsg[recvLen] = '\0';
|
||||||
// char* abc = UTF8ToANSI(recvMsg);
|
// char* abc = UTF8ToANSI(recvMsg);
|
||||||
printf("收到响应消息:%s",recvMsg);
|
printf("收到响应消息:%s",recvMsg);
|
||||||
return recvLen;
|
return recvLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int websocket_send(const char *data, int len) {
|
int websocket_send(const char *data, int len) {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue