diff --git a/src/include/Djitellowhite.h b/src/include/Djitellowhite.h index bfaa936..62a27a6 100644 --- a/src/include/Djitellowhite.h +++ b/src/include/Djitellowhite.h @@ -72,8 +72,9 @@ public: bool send_message(char* msg,sockaddr_in server_addr,int timeout = RESPONSE_TIMEOUT); static void *udp_response_receiver(void* arg); void get_video(sockaddr_in serveraddr); -}; +}; +// int Telloconnect1(void); diff --git a/src/main/Djitellowhite.cpp b/src/main/Djitellowhite.cpp index 432eef8..e14b657 100644 --- a/src/main/Djitellowhite.cpp +++ b/src/main/Djitellowhite.cpp @@ -12,6 +12,7 @@ using namespace cv; using namespace std; + Tello::Tello(const char* IP) { this->stream_on=false; this->host = inet_addr(IP); @@ -50,6 +51,7 @@ bool Tello::send_message(char* msg,sockaddr_in server_addr,int timeout){ return true; } void* Tello::udp_response_receiver(void* arg){ + //int m_SockServer; //创建socket对象 //sockaddr_in serveraddr; //创建sockaddr_in对象储存自身信息(当有多个端口,可以多个绑定) //sockaddr_in serveraddrfrom; diff --git a/src/main/Triplet.cpp b/src/main/Triplet.cpp index 0343058..f7e319b 100644 --- a/src/main/Triplet.cpp +++ b/src/main/Triplet.cpp @@ -1,9 +1,11 @@ #include "../include/Djitellowhite.h" #include "../include/Hardwarelistener.h" #include -/* + +// This a mod of create a Tello + using namespace std; -int main(void){ +void* Telloconnect1(void){ Tello T("192.168.10.1"); int socket_fd, err; @@ -11,14 +13,16 @@ int main(void){ { cout << "initialized error" << endl; cout << 0; - return -1; + } //cout << 1 << socket_fd; T.set_conf(socket_fd); pthread_t thread_receive; + err = pthread_create(&thread_receive,nullptr,T.udp_response_receiver,&socket_fd); + sleep(3); struct sockaddr_in serveraddr; memset(&serveraddr,0,sizeof(serveraddr)); @@ -44,4 +48,3 @@ int main(void){ listenkeyboard(T,serveraddr); return 0; } -*/ diff --git a/src/main/mainwindow.cpp b/src/main/mainwindow.cpp index 8f9175d..f58703b 100644 --- a/src/main/mainwindow.cpp +++ b/src/main/mainwindow.cpp @@ -2,7 +2,8 @@ #include "../include/Air_Ground_CEC/mainwindow.hpp" #include #include - +#include "../include/Djitellowhite.h" +#include "../include/Hardwarelistener.h" MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : QMainWindow(parent), qnode(argc, argv), ui(new Ui::MainWindow) @@ -399,8 +400,8 @@ void MainWindow::importFrame() void MainWindow::on_Open_receive_clicked() { - capture.open(0); - //capture.open("udp://@0.0.0.0:11111"); + //capture.open(0);//video test + capture.open("udp://@0.0.0.0:11111"); timer->start(30); } @@ -410,6 +411,53 @@ void MainWindow::on_Stop_receive_clicked() capture.release(); } + + + +static void* Telloconnect(void *pt){ + Tello T("192.168.10.1"); + int socket_fd, err; + + if((socket_fd = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP))==-1) + { + cout << "initialized error" << endl; + cout << 0; + + } + + //cout << 1 << socket_fd; + T.set_conf(socket_fd); + + pthread_t thread_receive; + + err = pthread_create(&thread_receive,nullptr,T.udp_response_receiver,&socket_fd); + + sleep(3); + struct sockaddr_in serveraddr; + memset(&serveraddr,0,sizeof(serveraddr)); + serveraddr.sin_family=AF_INET; + serveraddr.sin_addr.s_addr=T.gethost(); + serveraddr.sin_port=htons(CONTROL_UDP_PORT); + + + + if(err!=0) + { + cout << err << " " << "can't create thread"; + } + + T.get_connect(serveraddr); + //sleep(1); + //T.takeoff(serveraddr); + T.get_video(serveraddr); + sleep(5); + //T.land(serveraddr); + + pthread_join(thread_receive,NULL); + listenkeyboard(T,serveraddr); + return 0; +} +\ void MainWindow::on_ConnectTello_clicked() { /* @@ -421,8 +469,14 @@ void MainWindow::on_ConnectTello_clicked() cout << "initialized error" << endl; cout << 0; exit(TELLODISCONNECTION); + } */ + + pthread_t thread_connect; + int con = pthread_create(&thread_connect,NULL,Telloconnect,NULL); + } + diff --git a/src/main/server.cpp b/src/main/server.cpp index 6d4cffc..3b9f934 100644 --- a/src/main/server.cpp +++ b/src/main/server.cpp @@ -8,6 +8,8 @@ #include #define PORT 8890 + +//This is for the test of connection with tello void udp_server(int sockfd) { @@ -40,6 +42,8 @@ void udp_server(int sockfd) close(sockfd); } + + /* int main(int argc, char **argv) { @@ -57,3 +61,5 @@ int main(int argc, char **argv) */ + +