gehongbo_branch
hackii 2 years ago
parent 16f7cec4dd
commit 0e7846f5e8

@ -72,8 +72,9 @@ public:
bool send_message(char* msg,sockaddr_in server_addr,int timeout = RESPONSE_TIMEOUT); bool send_message(char* msg,sockaddr_in server_addr,int timeout = RESPONSE_TIMEOUT);
static void *udp_response_receiver(void* arg); static void *udp_response_receiver(void* arg);
void get_video(sockaddr_in serveraddr); void get_video(sockaddr_in serveraddr);
};
};
// int Telloconnect1(void);

@ -12,6 +12,7 @@
using namespace cv; using namespace cv;
using namespace std; using namespace std;
Tello::Tello(const char* IP) { Tello::Tello(const char* IP) {
this->stream_on=false; this->stream_on=false;
this->host = inet_addr(IP); this->host = inet_addr(IP);
@ -50,6 +51,7 @@ bool Tello::send_message(char* msg,sockaddr_in server_addr,int timeout){
return true; return true;
} }
void* Tello::udp_response_receiver(void* arg){ void* Tello::udp_response_receiver(void* arg){
//int m_SockServer; //创建socket对象 //int m_SockServer; //创建socket对象
//sockaddr_in serveraddr; //创建sockaddr_in对象储存自身信息(当有多个端口,可以多个绑定) //sockaddr_in serveraddr; //创建sockaddr_in对象储存自身信息(当有多个端口,可以多个绑定)
//sockaddr_in serveraddrfrom; //sockaddr_in serveraddrfrom;

@ -1,9 +1,11 @@
#include "../include/Djitellowhite.h" #include "../include/Djitellowhite.h"
#include "../include/Hardwarelistener.h" #include "../include/Hardwarelistener.h"
#include <iostream> #include <iostream>
/*
// This a mod of create a Tello
using namespace std; using namespace std;
int main(void){ void* Telloconnect1(void){
Tello T("192.168.10.1"); Tello T("192.168.10.1");
int socket_fd, err; int socket_fd, err;
@ -11,14 +13,16 @@ int main(void){
{ {
cout << "initialized error" << endl; cout << "initialized error" << endl;
cout << 0; cout << 0;
return -1;
} }
//cout << 1 << socket_fd; //cout << 1 << socket_fd;
T.set_conf(socket_fd); T.set_conf(socket_fd);
pthread_t thread_receive; pthread_t thread_receive;
err = pthread_create(&thread_receive,nullptr,T.udp_response_receiver,&socket_fd); err = pthread_create(&thread_receive,nullptr,T.udp_response_receiver,&socket_fd);
sleep(3); sleep(3);
struct sockaddr_in serveraddr; struct sockaddr_in serveraddr;
memset(&serveraddr,0,sizeof(serveraddr)); memset(&serveraddr,0,sizeof(serveraddr));
@ -44,4 +48,3 @@ int main(void){
listenkeyboard(T,serveraddr); listenkeyboard(T,serveraddr);
return 0; return 0;
} }
*/

@ -2,7 +2,8 @@
#include "../include/Air_Ground_CEC/mainwindow.hpp" #include "../include/Air_Ground_CEC/mainwindow.hpp"
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
#include <iostream> #include <iostream>
#include "../include/Djitellowhite.h"
#include "../include/Hardwarelistener.h"
MainWindow::MainWindow(int argc, char **argv, QWidget *parent) : MainWindow::MainWindow(int argc, char **argv, QWidget *parent) :
QMainWindow(parent), qnode(argc, argv), QMainWindow(parent), qnode(argc, argv),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
@ -399,8 +400,8 @@ void MainWindow::importFrame()
void MainWindow::on_Open_receive_clicked() void MainWindow::on_Open_receive_clicked()
{ {
capture.open(0); //capture.open(0);//video test
//capture.open("udp://@0.0.0.0:11111"); capture.open("udp://@0.0.0.0:11111");
timer->start(30); timer->start(30);
} }
@ -410,6 +411,53 @@ void MainWindow::on_Stop_receive_clicked()
capture.release(); 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() void MainWindow::on_ConnectTello_clicked()
{ {
/* /*
@ -421,8 +469,14 @@ void MainWindow::on_ConnectTello_clicked()
cout << "initialized error" << endl; cout << "initialized error" << endl;
cout << 0; cout << 0;
exit(TELLODISCONNECTION); exit(TELLODISCONNECTION);
} }
*/ */
pthread_t thread_connect;
int con = pthread_create(&thread_connect,NULL,Telloconnect,NULL);
} }

@ -8,6 +8,8 @@
#include <string.h> #include <string.h>
#define PORT 8890 #define PORT 8890
//This is for the test of connection with tello
void udp_server(int sockfd) void udp_server(int sockfd)
{ {
@ -40,6 +42,8 @@ void udp_server(int sockfd)
close(sockfd); close(sockfd);
} }
/* /*
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -57,3 +61,5 @@ int main(int argc, char **argv)
*/ */

Loading…
Cancel
Save