This commit is contained in:
parent
e7a0c523ef
commit
abe3f4cfc6
|
@ -0,0 +1,45 @@
|
|||
//#include "DigtalWork.h"
|
||||
//
|
||||
//bool init3() {
|
||||
// if (websocket_connect(&websocket,"ws://172.16.1.131:10088/cxx") < 0) {
|
||||
// printf("WebSocket连接失败");
|
||||
// return false;
|
||||
// }
|
||||
// printf("websocket连接成功");
|
||||
// createPthread();
|
||||
// initRobot();
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//void initHuman() {
|
||||
//
|
||||
// char sex;
|
||||
// printf("初始化,输入数字人性别Male/Female:\n");
|
||||
// scanf("%s", &sex);
|
||||
// if(sex == ""){
|
||||
// strcpy(sex, "male");
|
||||
// }
|
||||
//
|
||||
// printf("操作结果:");
|
||||
//}
|
||||
//
|
||||
//void setName() {
|
||||
// char name;
|
||||
// printf("设置数字人名字:\n");
|
||||
// scanf("%s", &name);
|
||||
//}
|
||||
//
|
||||
//void setAge() {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//void getHandAction() {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//void setHandAction() {
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
//#ifndef _ROBOTWORK_H_
|
||||
//#define _ROBOTWORK_H_
|
||||
//
|
||||
//#include "WebsocketConfig.h"
|
||||
//
|
||||
// typedef struct {
|
||||
//
|
||||
// }Digtal;
|
||||
//
|
||||
// bool init3(); /*³õʼ»¯Á¬½Ó*/
|
||||
// void initHuman();
|
||||
// void setName();
|
||||
// void setAge();
|
||||
// void getHandAction();
|
||||
// void setHandAction();
|
||||
// Digtal digtal;
|
||||
// int number3 = 0; /*񅧏*/
|
||||
// int event_id3 = 0;
|
||||
//#endif
|
Binary file not shown.
|
@ -0,0 +1,43 @@
|
|||
# Project: Project0
|
||||
# Makefile created by Dev-C++ 5.11
|
||||
|
||||
CPP = g++.exe
|
||||
CC = gcc.exe
|
||||
WINDRES = windres.exe
|
||||
OBJ = Transcoding.o WebsocketClient.o UavWork.o RobotWork.o WebsocketConfig.o DigtalWork.o
|
||||
LINKOBJ = Transcoding.o WebsocketClient.o UavWork.o RobotWork.o WebsocketConfig.o DigtalWork.o
|
||||
LIBS = -L"F:/devCpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc -lwsock32 -Ldll -lws2_32 -lwsock32 -lmswsock -m32 -pg
|
||||
INCS = -I"F:/devCpp/MinGW64/include" -I"F:/devCpp/MinGW64/x86_64-w64-mingw32/include" -I"F:/devCpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
|
||||
CXXINCS = -I"F:/devCpp/MinGW64/include" -I"F:/devCpp/MinGW64/x86_64-w64-mingw32/include" -I"F:/devCpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"F:/devCpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
|
||||
BIN = Project0.exe
|
||||
CXXFLAGS = $(CXXINCS) -m32 -pg
|
||||
CFLAGS = $(INCS) -m32 -pg
|
||||
RM = rm.exe -f
|
||||
|
||||
.PHONY: all all-before all-after clean clean-custom
|
||||
|
||||
all: all-before $(BIN) all-after
|
||||
|
||||
clean: clean-custom
|
||||
${RM} $(OBJ) $(BIN)
|
||||
|
||||
$(BIN): $(OBJ)
|
||||
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)
|
||||
|
||||
Transcoding.o: Transcoding.c
|
||||
$(CC) -c Transcoding.c -o Transcoding.o $(CFLAGS)
|
||||
|
||||
WebsocketClient.o: WebsocketClient.c
|
||||
$(CC) -c WebsocketClient.c -o WebsocketClient.o $(CFLAGS)
|
||||
|
||||
UavWork.o: UavWork.c
|
||||
$(CC) -c UavWork.c -o UavWork.o $(CFLAGS)
|
||||
|
||||
RobotWork.o: RobotWork.c
|
||||
$(CC) -c RobotWork.c -o RobotWork.o $(CFLAGS)
|
||||
|
||||
WebsocketConfig.o: WebsocketConfig.c
|
||||
$(CC) -c WebsocketConfig.c -o WebsocketConfig.o $(CFLAGS)
|
||||
|
||||
DigtalWork.o: DigtalWork.c
|
||||
$(CC) -c DigtalWork.c -o DigtalWork.o $(CFLAGS)
|
|
@ -0,0 +1,182 @@
|
|||
[Project]
|
||||
FileName=Project0.dev
|
||||
Name=Project0
|
||||
Type=1
|
||||
Ver=2
|
||||
ObjFiles=
|
||||
Includes=
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=0
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
LogOutput=
|
||||
LogOutputEnabled=0
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=
|
||||
HostApplication=
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
CommandLine=
|
||||
Folders=Common,Common/Headers,Common/Sources,DigtalHuman,DigtalHuman/Headers,DigtalHuman/Sources,Robot,Robot/Headers,Robot/Sources,Uav,Uav/Headers,Uav/Sources
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=3
|
||||
CompilerSettings=0000000100000000100000000
|
||||
UnitCount=13
|
||||
|
||||
[VersionInfo]
|
||||
Major=1
|
||||
Minor=0
|
||||
Release=0
|
||||
Build=0
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
SyncProduct=1
|
||||
|
||||
[Unit2]
|
||||
FileName=Transcoding.h
|
||||
CompileCpp=0
|
||||
Folder=Common/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=WebsocketClient.c
|
||||
CompileCpp=0
|
||||
Folder=Common/Sources
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit4]
|
||||
FileName=WebsocketClient.h
|
||||
CompileCpp=0
|
||||
Folder=Common/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit5]
|
||||
FileName=UavWork.h
|
||||
CompileCpp=0
|
||||
Folder=Uav/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit6]
|
||||
FileName=UavWork.c
|
||||
CompileCpp=0
|
||||
Folder=Uav/Sources
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit7]
|
||||
FileName=RobotWork.h
|
||||
CompileCpp=0
|
||||
Folder=Robot/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit1]
|
||||
FileName=Transcoding.c
|
||||
CompileCpp=0
|
||||
Folder=Common/Sources
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit8]
|
||||
FileName=RobotWork.c
|
||||
CompileCpp=0
|
||||
Folder=Robot/Sources
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit9]
|
||||
FileName=WebsocketConfig.c
|
||||
CompileCpp=0
|
||||
Folder=Common/Sources
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit10]
|
||||
FileName=WebsocketConfig.h
|
||||
CompileCpp=0
|
||||
Folder=Common/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit11]
|
||||
FileName=WebsocketModel.h
|
||||
CompileCpp=0
|
||||
Folder=Common/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit12]
|
||||
FileName=DigtalWork.h
|
||||
CompileCpp=0
|
||||
Folder=DigtalHuman/Headers
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit13]
|
||||
FileName=DigtalWork.c
|
||||
CompileCpp=0
|
||||
Folder=DigtalHuman/Sources
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
Binary file not shown.
|
@ -0,0 +1,68 @@
|
|||
[Editor_0]
|
||||
CursorCol=17
|
||||
CursorRow=80
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editors]
|
||||
Order=5,7,8,6
|
||||
Focused=5
|
||||
[Editor_1]
|
||||
CursorCol=1
|
||||
CursorRow=1
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_2]
|
||||
CursorCol=35
|
||||
CursorRow=8
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_3]
|
||||
CursorCol=13
|
||||
CursorRow=6
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_4]
|
||||
CursorCol=18
|
||||
CursorRow=16
|
||||
TopLine=2
|
||||
LeftChar=1
|
||||
[Editor_5]
|
||||
CursorCol=18
|
||||
CursorRow=182
|
||||
TopLine=160
|
||||
LeftChar=1
|
||||
[Editor_6]
|
||||
CursorCol=8
|
||||
CursorRow=26
|
||||
TopLine=11
|
||||
LeftChar=1
|
||||
[Editor_7]
|
||||
CursorCol=32
|
||||
CursorRow=18
|
||||
TopLine=10
|
||||
LeftChar=1
|
||||
[Editor_9]
|
||||
CursorCol=14
|
||||
CursorRow=12
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_8]
|
||||
CursorCol=2
|
||||
CursorRow=148
|
||||
TopLine=117
|
||||
LeftChar=1
|
||||
[Editor_10]
|
||||
CursorCol=1
|
||||
CursorRow=1
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_12]
|
||||
CursorCol=16
|
||||
CursorRow=11
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_11]
|
||||
CursorCol=21
|
||||
CursorRow=1
|
||||
TopLine=1
|
||||
LeftChar=1
|
|
@ -0,0 +1,202 @@
|
|||
#include "RobotWork.h"
|
||||
|
||||
bool init2() {
|
||||
if (websocket_connect(&websocket,"ws://172.16.1.131:10088/cxx") < 0) {
|
||||
printf("WebSocket连接失败");
|
||||
return false;
|
||||
}
|
||||
printf("websocket连接成功");
|
||||
createPthread();
|
||||
initRobot();
|
||||
return true;
|
||||
}
|
||||
|
||||
//初始化机器人场景
|
||||
void initRobot() {
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.event_id = 1;
|
||||
strcpy(robot.type, "other");
|
||||
strcpy(robot.commond, "init_scene");
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"event_id\":\"%i\",\"type\":%s,\"commond\":%s}"
|
||||
, robot.event_id, robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void initPosition() {
|
||||
// 为结构体成员变量赋值
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "init_position");
|
||||
robot.rotate = 0;
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"point\":\"%s\",\"type\":%s,\"commond\":%s}"
|
||||
, robot.number,robot.event_id,"[0.0,0.0]", robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void setName() {
|
||||
char name;
|
||||
printf("输入机器人名称:\n");
|
||||
scanf("%s", &name);
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "set_name");
|
||||
robot.name = name;
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"name\":\"%s\",\"type\":%s,\"commond\":%s}"
|
||||
, robot.number,robot.event_id,name, robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void setColor() {
|
||||
char color[8];
|
||||
printf("设置机器人颜色:");
|
||||
scanf("%s", &color);
|
||||
if(color == ""){
|
||||
strcpy(color, "#FFFFFF");
|
||||
}
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "set_color");
|
||||
strcpy(robot.color, color);
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"color\":\"%s\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, robot.number,robot.event_id,color, robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void servoMotorControl() {
|
||||
int servoId;
|
||||
printf("设置舵机id:");
|
||||
scanf("%i", &servoId);
|
||||
|
||||
int value;
|
||||
printf("设置舵机值:");
|
||||
scanf("%i", &value);
|
||||
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "servo_motor_control");
|
||||
robot.servoId = servoId;
|
||||
robot.value = value;
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"servo_id\":\"%i\",\"value\":\"%i\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, robot.number,robot.event_id,robot.servoId,robot.value, robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void getActionLab() {
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "get_action_lab");
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, robot.number,robot.event_id,robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void playAction() {
|
||||
char action[20];
|
||||
printf("设置动作名称:");
|
||||
scanf("%s", &action);
|
||||
|
||||
float duration;
|
||||
printf("设置持续时间:");
|
||||
scanf("%f", &duration);
|
||||
|
||||
float loopTimes;
|
||||
printf("设置循环次数:");
|
||||
scanf("%f", &loopTimes);
|
||||
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "play_action");
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
strcpy(robot.action, action);
|
||||
robot.duration = duration;
|
||||
robot.loopTimes = loopTimes;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"type\":\"%s\",\"commond\":\"%s\",\"action\":\"%s\",\"duration\":%f,\"loopTimes\":%f}"
|
||||
, robot.number,robot.event_id,robot.type, robot.commond,robot.action,robot.duration,robot.loopTimes);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void getSpeechText() {
|
||||
printf("设置动作名称:");
|
||||
}
|
||||
|
||||
void speak() {
|
||||
char txt[20];
|
||||
printf("请输入文本内容:");
|
||||
scanf("%s", &txt);
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "speak");
|
||||
strcpy(robot.txt, txt);
|
||||
strcpy(robot.tone, "机器人");
|
||||
robot.speed = 0;
|
||||
robot.save = false;
|
||||
strcpy(robot.fileName, "");
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"type\":\"%s\",\"commond\":\"%s\",\"txt\":\"%s\",\"tone\":%s,\"speed\":%i,\"save\":%s}"
|
||||
, robot.number,robot.event_id,robot.type, robot.commond,robot.txt,robot.tone,robot.speed,robot.save);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void defineAction() {
|
||||
printf("打开动作编辑面板...\n");
|
||||
printf("动作编辑面板:");
|
||||
}
|
||||
|
||||
void openColorDetect() {
|
||||
printf("打开图像识别...");
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "openColorDetect");
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, robot.number,robot.event_id,robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void stopColorDetect() {
|
||||
printf("停止图像识别...");
|
||||
number2 = number2 + 1;
|
||||
event_id2 = event_id2 + 1;
|
||||
strcpy(robot.type, "jqr");
|
||||
strcpy(robot.commond, "stopColorDetect");
|
||||
robot.number = number2;
|
||||
robot.event_id = event_id2;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, robot.number,robot.event_id,robot.type, robot.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef _ROBOTWORK_H_
|
||||
#define _ROBOTWORK_H_
|
||||
|
||||
#include "WebsocketConfig.h"
|
||||
|
||||
typedef struct {
|
||||
int event_id;
|
||||
char name;
|
||||
int number;
|
||||
char breastPieceInfo;
|
||||
char color[8];
|
||||
char type[10];
|
||||
char commond[20];
|
||||
float point[2];
|
||||
float rotate;
|
||||
int servoId;
|
||||
int value;
|
||||
char tone[10];
|
||||
char action[20];
|
||||
float duration;
|
||||
float loopTimes;
|
||||
int speed;
|
||||
bool save;
|
||||
char fileName[10];
|
||||
char txt[20];
|
||||
}Robot;
|
||||
bool init2(); /*³õʼ»¯Á¬½Ó*/
|
||||
void initRobot();
|
||||
void initPosition();
|
||||
void setName();
|
||||
void setColor();
|
||||
void servoMotorControl();
|
||||
void getActionLab();
|
||||
void playAction();
|
||||
void getSpeechText();
|
||||
void speak();
|
||||
void defineAction();
|
||||
void openColorDetect();
|
||||
void stopColorDetect();
|
||||
Robot robot;
|
||||
int number2 = 0; /*񅧏*/
|
||||
int event_id2 = 0;
|
||||
|
||||
#endif
|
||||
|
Binary file not shown.
|
@ -0,0 +1,84 @@
|
|||
#include "Transcoding.h"
|
||||
|
||||
|
||||
wchar_t * ANSIToUnicode(const char* str) {
|
||||
int textlen;
|
||||
wchar_t * result;
|
||||
textlen = MultiByteToWideChar( CP_ACP, 0, str,-1, NULL,0 );
|
||||
result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));
|
||||
memset(result,0,(textlen+1)*sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_ACP, 0,str,-1,(LPWSTR)result,textlen );
|
||||
return result;
|
||||
}
|
||||
|
||||
char * UnicodeToANSI( const wchar_t* str )
|
||||
{
|
||||
char* result;
|
||||
int textlen;
|
||||
textlen = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
|
||||
result =(char *)malloc((textlen+1)*sizeof(char));
|
||||
memset( result, 0, sizeof(char) * ( textlen + 1 ) );
|
||||
WideCharToMultiByte( CP_ACP, 0, str, -1, result, textlen, NULL, NULL );
|
||||
return result;
|
||||
}
|
||||
|
||||
wchar_t * UTF8ToUnicode( const char* str )
|
||||
{
|
||||
int textlen;
|
||||
wchar_t * result;
|
||||
textlen = MultiByteToWideChar( CP_UTF8, 0, str,-1, NULL,0 );
|
||||
result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));
|
||||
memset(result,0,(textlen+1)*sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0,str,-1,(LPWSTR)result,textlen );
|
||||
return result;
|
||||
}
|
||||
|
||||
char * UnicodeToUTF8( const wchar_t* str )
|
||||
{
|
||||
char* result;
|
||||
int textlen;
|
||||
textlen = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
|
||||
result =(char *)malloc((textlen+1)*sizeof(char));
|
||||
memset(result, 0, sizeof(char) * ( textlen + 1 ) );
|
||||
WideCharToMultiByte( CP_UTF8, 0, str, -1, result, textlen, NULL, NULL );
|
||||
return result;
|
||||
}
|
||||
|
||||
/*??????????????Unicode - ANSI*/
|
||||
char* w2m(const wchar_t* wcs)
|
||||
{
|
||||
int len;
|
||||
char* buf;
|
||||
len =wcstombs(NULL,wcs,0);
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
buf = (char *)malloc(sizeof(char)*(len+1));
|
||||
memset(buf, 0, sizeof(char) *(len+1));
|
||||
len =wcstombs(buf,wcs,len+1);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*??????????????ANSI - Unicode*/
|
||||
wchar_t* m2w(const char* mbs)
|
||||
{
|
||||
int len;
|
||||
wchar_t* buf;
|
||||
len =mbstowcs(NULL,mbs,0);
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
buf = (wchar_t *)malloc(sizeof(wchar_t)*(len+1));
|
||||
memset(buf, 0, sizeof(wchar_t) *(len+1));
|
||||
len =mbstowcs(buf,mbs,len+1);
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* ANSIToUTF8(const char* str)
|
||||
{
|
||||
return UnicodeToUTF8(ANSIToUnicode(str));
|
||||
}
|
||||
|
||||
char* UTF8ToANSI(const char* str)
|
||||
{
|
||||
return UnicodeToANSI(UTF8ToUnicode(str));
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef _TRANSCODING_H_
|
||||
#define _TRANSCODING_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
#define BUF_SIZE 1024
|
||||
|
||||
wchar_t * ANSIToUnicode(const char* str);
|
||||
|
||||
char * UnicodeToANSI( const wchar_t* str );
|
||||
|
||||
wchar_t * UTF8ToUnicode( const char* str );
|
||||
|
||||
char * UnicodeToUTF8( const wchar_t* str );
|
||||
|
||||
char* w2m(const wchar_t* wcs);
|
||||
|
||||
wchar_t* m2w(const char* mbs);
|
||||
|
||||
char* ANSIToUTF8(const char* str);
|
||||
|
||||
char* UTF8ToANSI(const char* str);
|
||||
|
||||
#endif
|
||||
|
Binary file not shown.
|
@ -0,0 +1,353 @@
|
|||
#include "UavWork.h"
|
||||
|
||||
void uavOperate(int choose) {
|
||||
switch(choose){
|
||||
case 1: init_position(); break;
|
||||
case 2: set_name(); break;
|
||||
case 3: set_color(); break;
|
||||
case 4: start_engine(); break;
|
||||
case 5: shut_down_engine(); break;
|
||||
case 6: set_rotor_power(); break;
|
||||
case 7: open_lighter(); break;
|
||||
case 8: close_lighter(); break;
|
||||
case 9: get_current_height(); break;
|
||||
case 10: get_current_attitude_angle(); break;
|
||||
case 11: get_current_distance(); break;
|
||||
case 12: get_current_distance(); break;
|
||||
case 13: get_current_distance(); break;
|
||||
case 14: get_current_distance(); break;
|
||||
case 15: get_current_distance(); break;
|
||||
case 16: get_current_distance(); break;
|
||||
}
|
||||
}
|
||||
|
||||
int getChoose() {
|
||||
int num;
|
||||
printf("请选择需要操作:----------------------\n");
|
||||
printf("0.退出操作\n");
|
||||
printf("1.初始化无人机坐标\n");
|
||||
printf("2.设置无人机名称\n");
|
||||
printf("3.设置无人机颜色\n");
|
||||
printf("4.启动引擎\n");
|
||||
printf("5.关闭引擎\n");
|
||||
printf("6.设置无人机各旋翼输出\n");
|
||||
printf("7.打开无人机灯光\n");
|
||||
printf("8.关闭无人机灯光\n");
|
||||
printf("9.获取无人机当前高度\n");
|
||||
printf("10.获取无人机当前姿态角\n");
|
||||
printf("11.获取无人机与返航点的水平方向距离\n");
|
||||
printf("12.获取无人机的水平方向速度\n");
|
||||
printf("13.获取无人机的垂直速度\n");
|
||||
printf("14.打开高清图传\n");
|
||||
printf("15.关闭高清图传\n");
|
||||
printf("16.以给定速度朝方向飞行多长时间\n");
|
||||
printf("17.在规定时间内飞至指定位置\n");
|
||||
printf("18.在固定速度的情况下飞至指定位置\n");
|
||||
printf("19.无人机悬停\n");
|
||||
printf("20.打开无人机飞行轨迹\n");
|
||||
printf("输入操作项:\n");
|
||||
scanf("%d", &num);
|
||||
printf("你输入的整数是: %d\n", num);
|
||||
createPthread();
|
||||
uavOperate(num);
|
||||
}
|
||||
|
||||
bool init() {
|
||||
if (websocket_connect(&websocket,"ws://127.0.0.1:6003") < 0) {
|
||||
printf("WebSocket连接失败");
|
||||
return false;
|
||||
}
|
||||
printf("websocket连接成功");
|
||||
createPthread();
|
||||
initUav();
|
||||
return true;
|
||||
}
|
||||
|
||||
//初始化无人机场景
|
||||
void initUav() {
|
||||
event_id = event_id + 1;
|
||||
uav.event_id = 1;
|
||||
strcpy(uav.type, "other");
|
||||
strcpy(uav.commond, "init_scene");
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, uav.event_id, uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
//初始化返航点
|
||||
void init_position() {
|
||||
// 为结构体成员变量赋值
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "init_position");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"pos\":%s,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, uav.number,uav.event_id,"[0,0]", uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
};
|
||||
|
||||
void set_name() {
|
||||
char name[100];
|
||||
printf("输入无人机名称:\n");
|
||||
scanf("%s", &name);
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "set_name");
|
||||
strcpy(uav.name, name);
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"name\":\"%s\",\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, uav.number,uav.event_id,name, uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void set_color() {
|
||||
char color_1[8];
|
||||
printf("无人机模型区域1颜色(默认 #FFFFFF):");
|
||||
scanf("%s", &color_1);
|
||||
if(color_1 == ""){
|
||||
strcpy(color_1, "#FFFFFF");
|
||||
}
|
||||
char color_2[8];
|
||||
printf("无人机模型区域2颜色(默认 #000000):");
|
||||
scanf("%s", &color_2);
|
||||
if(color_2 == ""){
|
||||
strcpy(color_2, "#000000");
|
||||
}
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "set_color");
|
||||
strcpy(uav.color_1, color_1);
|
||||
strcpy(uav.color_2, color_2);
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
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\"}"
|
||||
, uav.number,uav.event_id,color_1,color_2, uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void start_engine() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "start_engine");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, uav.number,uav.event_id, uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void shut_down_engine() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "shut_down_engine");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, uav.number,uav.event_id, uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void set_rotor_power() {
|
||||
char rotor[20];
|
||||
memset(rotor, 0, sizeof(rotor));
|
||||
printf("输入旋翼输出参数(四个参数以,分割 例如:1,2,3,4):");
|
||||
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.commond, "set_rotor_power");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char data[30];
|
||||
sprintf(data,"{\"power\":[%s]}",rotor);
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"number\":%i,\"event_id\":%i,\"parameters\":%s,\"type\":\"%s\",\"commond\":\"%s\"}"
|
||||
, uav.number,uav.event_id,data, uav.type, uav.commond);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void open_lighter() {
|
||||
char color[20];
|
||||
printf("设置灯光颜色:");
|
||||
scanf("%s", &color);
|
||||
strcpy(inParams.color, color);
|
||||
inParams.intensity = 1;
|
||||
inParams.halo = 1;
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "open_lighter");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char data[30];
|
||||
sprintf(data,"{\"intensity\":%f,\"color\":\"%s\",\"halo\":%f}",inParams.intensity,inParams.color,inParams.halo);
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"parameters\":%s,\"event_id\":%i}"
|
||||
, uav.type,uav.commond,uav.number, data, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void close_lighter() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "close_lighter");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void get_current_height() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "get_current_height");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void get_current_attitude_angle() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "get_current_attitude_angle");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void get_current_distance() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "get_current_distance");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void get_current_horizontal_speed() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "get_current_horizontal_speed");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void get_current_vertical_speed() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "get_current_vertical_speed");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void open_hd() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "open_hd");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void close_hd() {
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "close_hd");
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
sprintf(json_str, "{\"type\":\"%s\",\"commond\":\"%s\",\"number\":%i,\"event_id\":%i}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id);
|
||||
sendMessage(json_str);
|
||||
}
|
||||
|
||||
void fly_by_3d_direction() {
|
||||
char powers[3];
|
||||
printf("设置飞行方向,三个参数[X:前后,Y:左右,Z:上下]以,分割(示例:1,2,3):");
|
||||
scanf("%s", &powers);
|
||||
if(sizeof(powers) != 3){
|
||||
int code;
|
||||
printf("输入旋翼参数异常,1:重新输入,0:退出");
|
||||
scanf("%c", &code);
|
||||
if(code == 0){
|
||||
return;
|
||||
}else if(code == 1){
|
||||
setRotorPower();
|
||||
return;
|
||||
}
|
||||
}
|
||||
strcpy(uav.type, "wrj");
|
||||
strcpy(uav.commond, "fly_by_3d_direction");
|
||||
int i;
|
||||
for (i =0;i<4;i++){
|
||||
float p = powers[i];
|
||||
uav.direction[i] = p;
|
||||
}
|
||||
// memcpy(uav.direction, directionF, sizeof(directionF));
|
||||
float speed;
|
||||
printf("设置飞行速度(米/秒):");
|
||||
scanf("%f", &speed);
|
||||
uav.speed = speed;
|
||||
float duration;
|
||||
printf("飞行时间(秒):");
|
||||
scanf("%f", &duration);
|
||||
uav.time = duration;
|
||||
number = number + 1;
|
||||
event_id = event_id + 1;
|
||||
uav.number = number;
|
||||
uav.event_id = event_id;
|
||||
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}"
|
||||
, uav.type, uav.commond, uav.number, uav.event_id,uav.direction,uav.speed,uav.time);
|
||||
sendMessage(json_str);
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef _WEBSOCKETCLIENT_H_
|
||||
#define _WEBSOCKETCLIENT_H_
|
||||
|
||||
#include "WebsocketConfig.h"
|
||||
|
||||
typedef struct {
|
||||
char color[4];
|
||||
float intensity;
|
||||
float halo;
|
||||
}InParam;
|
||||
|
||||
typedef struct {
|
||||
int rotor_power[4]; /*旋翼输出y*/
|
||||
}InParam2;
|
||||
|
||||
typedef struct {
|
||||
int event_id;
|
||||
int number; /*编号*/
|
||||
char name[100]; /*名称*/
|
||||
char color_1[8]; /*颜色1*/
|
||||
char color_2[8]; /*颜色2*/
|
||||
char color;
|
||||
float pos[2];
|
||||
char type[10];
|
||||
char commond[20];
|
||||
int rotor_power[4]; /*旋翼输出y*/
|
||||
char ligter_color; /*灯光颜色*/
|
||||
double height; /*高度*/
|
||||
double distance; /*水平距离*/
|
||||
float direction[3]; /*姿态角*/
|
||||
double horizontal_speed; /*水平速度*/
|
||||
double vertical_speed; /*垂直速度*/
|
||||
float speed; /*设置飞行速度(米/秒)*/
|
||||
float time; /*飞行时间*/
|
||||
float duration; /*固定时间*/
|
||||
InParam parameters;
|
||||
InParam2 parameters2;
|
||||
}UAV;
|
||||
bool init(); /*初始化连接*/
|
||||
void initUav();
|
||||
void init_position(); //初始化返航点
|
||||
void set_name(); //设置名称
|
||||
void set_color(); //设置颜色
|
||||
void start_engine(); //启动无人机
|
||||
void shut_down_engine(); //关闭无人机
|
||||
void set_rotor_power(); //设置各旋翼动力
|
||||
void open_lighter();
|
||||
void close_lighter();
|
||||
void get_current_height();
|
||||
void get_current_attitude_angle();
|
||||
void get_current_distance();
|
||||
void get_current_horizontal_speed();
|
||||
void get_current_vertical_speed();
|
||||
void open_hd();
|
||||
void close_hd();
|
||||
void fly_by_3d_direction(); //7.控制无人机飞行方向与速度 speed速度 flyTime飞行时间
|
||||
UAV uav;
|
||||
InParam inParams;
|
||||
InParam2 inParams2;
|
||||
int number = 0; /*编号*/
|
||||
int event_id = 0;
|
||||
#endif
|
||||
|
Binary file not shown.
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "WebsocketClient.h"
|
||||
#include "UavWork.h"
|
||||
#pragma comment(lib,"ws2_32.lib")
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int num;
|
||||
printf("请选择需要操作的组件类型:\n");
|
||||
printf("1.无人机\n");
|
||||
printf("2.机器人\n");
|
||||
printf("3.数字人\n");
|
||||
scanf("%d", &num);
|
||||
printf("你输入的整数是: %d\n", num);
|
||||
operate(num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void operate(int choose) {
|
||||
switch(choose) {
|
||||
case 1: init(); break;
|
||||
case 2:break;
|
||||
case 3:break;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _WEBSOCKETCLIENT_H_
|
||||
#define _WEBSOCKETCLIENT_H_
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
|
||||
void operate(int choose);
|
||||
|
||||
#endif
|
||||
|
Binary file not shown.
|
@ -0,0 +1,151 @@
|
|||
#include "WebsocketConfig.h"
|
||||
#include <Winsock2.h>
|
||||
#include "Transcoding.h"
|
||||
|
||||
|
||||
|
||||
int websocket_connect(Websocket *ws, const char *address){
|
||||
// 解析URL
|
||||
char host[BUF_SIZE], path[BUF_SIZE];
|
||||
int port = 80;
|
||||
char *url = (char *)malloc(sizeof(char) * 100);
|
||||
memset(url, 0, strlen(url));
|
||||
if(strlen(address) == 0) {
|
||||
url = (char *)"ws://127.0.0.1:10088/cxx";
|
||||
} else {
|
||||
memcpy(url,address,strlen(address));
|
||||
}
|
||||
|
||||
if (sscanf(url, "ws://%[^:/]:%d/%s", host, &port, path) != 3) {
|
||||
if (sscanf(url, "ws://%[^:/]:%d", host, &port) != 2) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
WSADATA wsaData;
|
||||
if(WSAStartup(MAKEWORD(2,2),&wsaData) != 0) {
|
||||
printf("winsock连接失败");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 建立TCP连接
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
SOCKADDR_IN addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.S_un.S_addr = inet_addr(host);
|
||||
int result = connect(sockfd, (SOCKADDR*)&addr, sizeof(SOCKADDR));
|
||||
if (result < 0) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 发送WebSocket握手请求
|
||||
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), "Connection: Upgrade\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Pragma: no-cache\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Cache-Control: no-cache\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Upgrade: websocket\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Sec-WebSocket-Version: 13\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Accept-Encoding: gzip, deflate\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Accept-Language: zh-CN,zh;q=0.9\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Sec-WebSocket-Version: 13\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n");
|
||||
sprintf(ws->buf + strlen(ws->buf), "\r\n");
|
||||
if (send(sockfd, ws->buf, strlen(ws->buf), 0) < 0) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 接收WebSocket握手响应
|
||||
int n = recv(sockfd, ws->buf, BUF_SIZE, 0);
|
||||
if (n < 0) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ws->buf[n] = '\0';
|
||||
|
||||
//HTTP/1.1 101 Switching Protocols
|
||||
if (strstr(ws->buf, "HTTP/1.1 101") == NULL) {
|
||||
closesocket(sockfd);
|
||||
return -1;
|
||||
}
|
||||
// WebSocket连接建立成功
|
||||
ws->sockfd = sockfd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//const char* parseObject(UAV uav) {
|
||||
// char *json_str = (char *)malloc(sizeof(char) * 100); // 假设 JSON 字符串最大长
|
||||
//// sprintf(json_str, "{\"number\":\"%i\",\"event_id\":\"%i\",\"pos\":%s,\"type\":%s,\"commond\":%s}"
|
||||
//// ,uav.number, uav.event_id,"[0.0,0.0]", uav.type, uav.commond);
|
||||
// sprintf(json_str, "{\"event_id\":\"%i\",\"type\":%s,\"commond\":%s}"
|
||||
// , uav.event_id, uav.type, uav.commond);
|
||||
// return json_str;
|
||||
//}
|
||||
|
||||
int websocket_recv() {
|
||||
// 接收响应消息
|
||||
char recvMsg[1024];
|
||||
memset(recvMsg, 0, sizeof(recvMsg));
|
||||
int recvLen = recv(websocket.sockfd, recvMsg, sizeof(recvMsg) - 1, 0);
|
||||
if (recvLen == SOCKET_ERROR || recvLen == 0) {
|
||||
printf("接收响应消息失败\n");
|
||||
return -1;
|
||||
}
|
||||
recvMsg[recvLen] = '\0';
|
||||
// char* abc = UTF8ToANSI(recvMsg);
|
||||
printf("收到响应消息:%s",recvMsg);
|
||||
return recvLen;
|
||||
}
|
||||
|
||||
int websocket_send(const char *data, int len) {
|
||||
// 构造WebSocket数据帧
|
||||
char frame[BUF_SIZE];
|
||||
frame[0] = 0x81;
|
||||
frame[1] = (0x80 | len);
|
||||
frame[2] = 0x12;
|
||||
frame[3] = 0x34;
|
||||
frame[4] = 0x56;
|
||||
frame[5] = 0x78;
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
frame[i + 6] = data[i] ^ frame[i%4+2];
|
||||
}
|
||||
if (send(websocket.sockfd, frame, strlen(frame), 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sendMessage(const char *data) {
|
||||
printf(data);
|
||||
if (websocket_send(data,strlen(data)) < 0) {
|
||||
printf("WebSocket发送数据失败\n");
|
||||
websocket_close();
|
||||
}else{
|
||||
printf("WebSocket发送数据成功呢\n");
|
||||
getChoose();
|
||||
}
|
||||
}
|
||||
|
||||
void websocket_close() {
|
||||
closesocket(websocket.sockfd);
|
||||
printf("子线程已销毁,通信已关闭");
|
||||
}
|
||||
|
||||
void createPthread() {
|
||||
// 创建接收消息的线程
|
||||
if (pthread_create(&reply_thread, NULL, websocket_recv, NULL) != 0) {
|
||||
// printf("创建接收消息线程失败");
|
||||
exit(1);
|
||||
}else {
|
||||
// printf("创建接收消息线程成功");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef _WEBSOCKETCONFIG_H_
|
||||
#define _WEBSOCKETCONFIG_H_
|
||||
|
||||
#include "WebsocketModel.h"
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
pthread_t send_thread, reply_thread;
|
||||
|
||||
int websocket_connect(Websocket *ws, const char *address);
|
||||
|
||||
int websocket_recv();
|
||||
|
||||
int websocket_send(const char *data, int len);
|
||||
|
||||
void websocket_close();
|
||||
|
||||
void createPthread();
|
||||
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
#define BUF_SIZE 1024
|
||||
|
||||
typedef struct {
|
||||
int sockfd;
|
||||
char buf[BUF_SIZE];
|
||||
} Websocket;
|
||||
|
||||
Websocket websocket;
|
Binary file not shown.
Loading…
Reference in New Issue