From 997fd8c5d0843d1761107d585b5e24449b7679ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=9B=E5=AE=8F=E6=B3=A2?= <10191750+hackii@user.noreply.gitee.com> Date: Thu, 28 Apr 2022 06:05:15 -0700 Subject: [PATCH] src update --- doc/version.txt | 1 + model/model.txt | 1 + src/Djitellowhite/Djitellowhite.cpp | 106 ++++++++++++++++++++++++++ src/Djitellowhite/Djitellowhite.h | 72 +++++++++++++++++ src/Djitellowhite/Hardwarelistener.h | 6 ++ src/Djitellowhite/Triplet | Bin 0 -> 19720 bytes src/Djitellowhite/Triplet.cpp | 45 +++++++++++ src/Djitellowhite/keyboard | Bin 0 -> 17408 bytes src/Djitellowhite/keyboard.cpp | 52 +++++++++++++ src/Djitellowhite/libDjitellowhite.so | Bin 0 -> 18152 bytes src/Djitellowhite/server | Bin 0 -> 17176 bytes src/Djitellowhite/server.cpp | 58 ++++++++++++++ 12 files changed, 341 insertions(+) create mode 100644 doc/version.txt create mode 100644 model/model.txt create mode 100644 src/Djitellowhite/Djitellowhite.cpp create mode 100644 src/Djitellowhite/Djitellowhite.h create mode 100644 src/Djitellowhite/Hardwarelistener.h create mode 100755 src/Djitellowhite/Triplet create mode 100644 src/Djitellowhite/Triplet.cpp create mode 100755 src/Djitellowhite/keyboard create mode 100644 src/Djitellowhite/keyboard.cpp create mode 100755 src/Djitellowhite/libDjitellowhite.so create mode 100755 src/Djitellowhite/server create mode 100644 src/Djitellowhite/server.cpp diff --git a/doc/version.txt b/doc/version.txt new file mode 100644 index 0000000..626799f --- /dev/null +++ b/doc/version.txt @@ -0,0 +1 @@ +v1 diff --git a/model/model.txt b/model/model.txt new file mode 100644 index 0000000..359af40 --- /dev/null +++ b/model/model.txt @@ -0,0 +1 @@ +create diff --git a/src/Djitellowhite/Djitellowhite.cpp b/src/Djitellowhite/Djitellowhite.cpp new file mode 100644 index 0000000..12ad5ed --- /dev/null +++ b/src/Djitellowhite/Djitellowhite.cpp @@ -0,0 +1,106 @@ +#include"Djitellowhite.h" +#include +#include + + +#include +#include +#include + +#include +#include + +using namespace cv; +using namespace std; +Tello::Tello(const char* IP) { + this->stream_on=false; + this->host = inet_addr(IP); + cout << "create successfully!" << endl; + +} +Tello::~Tello() {} +void Tello::set_conf(int socket){ + this->sock = socket; +} +void Tello::get_connect(sockaddr_in serveraddr) { + char tmp[10] = {"command"}; + send_message(tmp,serveraddr,0);// 0 -> timeout + cout << "connect successfully!" <host; +} +void Tello::takeoff(sockaddr_in serveraddr) { + char tmp[10] = {"takeoff"}; + send_message(tmp,serveraddr,0);// 0 -> timeout + cout << "takeoff successfully!" < timeout + cout << "land successfully!" <sock,buffer,strlen(buffer),0,(struct sockaddr *)&server_addr, sizeof(server_addr)); + return true; +} +void* Tello::udp_response_receiver(void* arg){ + //int m_SockServer; //创建socket对象 + //sockaddr_in serveraddr; //创建sockaddr_in对象储存自身信息(当有多个端口,可以多个绑定) + //sockaddr_in serveraddrfrom; + + //serveraddr.sin_family = AF_INET; //设置服务器地址家族 + //serveraddr.sin_port = htons(8889); //设置服务器端口号 + //serveraddr.sin_addr.s_addr = inet_addr("0.0.0.0"); + //m_SockServer = socket(AF_INET, SOCK_DGRAM, 0); //创建一个临时变量并赋值给m_SockServer + //int i = bind(m_SockServer, (sockaddr*)&serveraddr, sizeof(serveraddr)); //把名字和套接字绑定 + //std::cout << "bind:" << i << std::endl; + + int socket = *(int *)arg; + + cout << "receive start" << endl; + while(1){ + char buffer[20]; + int iret; + memset(buffer,0,sizeof(buffer)); + + iret = recv(socket, buffer,20,MSG_WAITALL); + if(iret > 0 && iret <10){ + printf("Message from tello: %s\n", buffer); + } + } +} +void Tello::get_video(sockaddr_in serveraddr){ + + char tmp[10] = {"streamon"}; + send_message(tmp,serveraddr,0);// 0 -> timeout +// cout << "stream_on successfully!" <stream_on = true; +// +// cout << "vid"; +// VideoCapture cap("udp://@0.0.0.0:11111"); +// cout << "cap"; +// if(!cap.isOpened()){ +// cout << "fuck off"; +// return; +// } + +// Mat frame; +// cout << "continue!"; +// while(1){ +// cap>>frame; +// if(frame.empty()) +// break; +// imshow("video",frame); +// waitKey(20); +// +// } +// cap.release(); + + +} diff --git a/src/Djitellowhite/Djitellowhite.h b/src/Djitellowhite/Djitellowhite.h new file mode 100644 index 0000000..b311e46 --- /dev/null +++ b/src/Djitellowhite/Djitellowhite.h @@ -0,0 +1,72 @@ +#ifndef _DJITELLOWHITE_H +#define _DJITELLOWHITE_H +#include +#include +#include +#include +#include +#include +/*Library for interacting with DJI Ryze Tello drones.*/ + + +//coding = utf - 8 + +/* """C++ wrapper to interact with the Ryze Tello drone using the official Tello api. + Tello API documentation: + [1.3](https://dl-cdn.ryzerobotics.com/downloads/tello/20180910/Tello%20SDK%20Documentation%20EN_1.3.pdf) +*/ + +#define RESPONSE_TIMEOUT 7 //in seconds +#define TAKEOFF_TIMEOUT 20 //in seconds +#define FRAME_GRAB_TIMEOUT 3 +#define TIME_BTW_COMMANDS 0.1 //in seconds +#define TIME_BTW_RC_CONTROL_COMMANDS 0.001 //in seconds +#define RETRY_COUNT 3 //number of retries after a failed command + + +//Video stream, server socket +#define VS_UDP_IP "0.0.0.0" +#define VS_UDP_PORT 11111 + +#define CONTROL_UDP_PORT 8889 +#define STATE_UDP_PORT 8890 + +#define BUFFER_SIZE 1024 +//Constants for video settings +#define BITRATE_AUTO 0 +#define BITRATE_1MBPS 1 +#define BITRATE_2MBPS 2 +#define BITRATE_3MBPS 3 +#define BITRATE_4MBPS 4 +#define BITRATE_5MBPS 5 +#define RESOLUTION_480P "low" +#define RESOLUTION_720P "high" +#define FPS_5 "low" +#define FPS_15 "middle" +#define FPS_30 "high" +#define CAMERA_FORWARD 0 +#define CAMERA_DOWNWARD 1 +//日志模块暂时不写 + +class Tello { +private: + int sock; + bool stream_on; + unsigned long host; +public: + Tello(const char* IP); + ~Tello(); + void set_conf(int socket); + unsigned long gethost(); + void get_connect(sockaddr_in serveraddr); + void takeoff(sockaddr_in serveraddr); + void land(sockaddr_in serveraddr); + 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); +}; + + + + +#endif diff --git a/src/Djitellowhite/Hardwarelistener.h b/src/Djitellowhite/Hardwarelistener.h new file mode 100644 index 0000000..176cde8 --- /dev/null +++ b/src/Djitellowhite/Hardwarelistener.h @@ -0,0 +1,6 @@ +#ifndef _HARDWARELISTENER_H +#define _HARDWARELISTENER_H + +int listenkeyboard(); +int scanKeyboard(); +#endif diff --git a/src/Djitellowhite/Triplet b/src/Djitellowhite/Triplet new file mode 100755 index 0000000000000000000000000000000000000000..b514f9136a8bd367183adecad580a66f3f0cb1c7 GIT binary patch literal 19720 zcmeHPe{@vEy`TJosE`B&P0`A#U_oTfh6IC^x`8a*)F3HIDz(zfX7`4yYuMc}pkNtT{t?fbE3W^1Mr}bgAmA2ZZRohKPiz(VXi|+e;=g#-; z-OH}Uo}Tmmcudaj_kKU$AM>5LGjnHW?qqwQV`X_+nc!3*J|rY}fra>$pgO=BLik0C zn2v9cm?NeDuEfW$#BO@5+!8RYR(chnWLHlYMd&3KESPeHM9HpH+A-adFcozcPj*#w zsdzViL)kH9xt*VfjFCL@+om^4r$R7w+ELx?yV}yLR-_WjChm zn0i!wGUfUtH}q*ye%;gq86}VW7Q$_}PT9F>o6=`Wc~I(l*$n?Z`E@G0lOE|txaqSN zESPeBAAud!%b6y=&1+SDrS5~K%FUGSH>GQ$k=`Xu*F?jMqLEl?Xwgv1l0{3Jyvew? zQOYSU%7bqIs+)QQZp#6}lskDZW-6ZK58SpXF?YfC7rxhc&(@#6`sROhZ8!*fvzQ%6SE}}PwLPxn%ZL# zv&|RSY&-8zh%0WE@SlpIN4%Ze-c4citG1-d(w_ zuyRE~Lh+PIMc)_-=}9WNPv||dEs?5V95ra516x31GLlIL97z0VzZ!}D*G+~Co1x+&{A~D0% zgW)h?kV-5WHH<-J-xr};_!RE4PSL2FG7!WKUA1C`z8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POV9Dd;qDL&}MhQ=cA)-bN~&33f%|?&7iPOyA}GR^MZwl-o6I+Cmf0C zsiZ*#qw{WjUae5oIucii*+DL)cs57EM%*0@8rt7?+)(ADPQvlYM>+;sB8Ij`RFQQ^ z&!wS)t#pUT@r4&@_Zy}4kr%X8h_Vm zNaaLTihc0V?OXMmYt@Snr`;3lFesnbEOhEV5}Ehilt15?2kB^{-3(fAB$AqCA00H+ zal(~*7uQFlFBKlt6Gn0nL!5yN`MyOW(78E(p3?1G9rJWYNv+&EN{Re^O;I{j8{;8h zGau7*JL3_>Cr1=r?@cCcCpUE!IcMt5R-WJtB~x-t$d??W3l7!l1J)}efzD7tr=;3A z{Yb3e?>P2}I=)kfa12>k6i0KVWHSyT;}KK9=#V9hXpjul)nL>VUip~y z;?lb@4wf#GMo4&Z1Q@KWF>fL+M_8}Xub%Y%IQnaI$R-rhjiHc%rzXmXF-Ll}CIOZY zzDDN3fe74N4$&BemyQ)+Qc+|E^xhzvPM6_>X{$`U-pQ2L{gqhi@-@*b@WIr|w&!(G zrXI+giGK$%wgeYW`*ryJMTzNLi?zS;^P?cOgLB&RIxAC8fp&gKiu{V@Ns z%bxcGn7Wp;WnOGc^e_0(+B#>$>wo-zdpwXi6X(yg0>RVT6WjCt!m+C@E7oHl%rmWp zJ+*zd=Y0tNKTIA~vDAMlu^qRcuLGm{V|#m@k{5_b=tykOv>x&Td%sd{uqgL)cENVc zUkYQwIDfz2lGL-kD}N=nl<<9p%3rD5INL9@5$l58IVrb2r>e#dX+s5x_J;%baQs{@ n+V17pacL**dh7D@T=7c6`LZH)_hR +using namespace std; +int main(void){ + 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; + 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)); + 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(); + return 0; +} diff --git a/src/Djitellowhite/keyboard b/src/Djitellowhite/keyboard new file mode 100755 index 0000000000000000000000000000000000000000..fb6acf5aeb95432ce1b005b8eb71520f42b7d83b GIT binary patch literal 17408 zcmeHPZE#f889tj$AQV^vLPe;uDq1LJNg&XmMRt=c+-SfEi6Vm6&F&`IA=!<)cO^J} zL?hIlm^M27U>twMA5O8>DcY$6 zftUooSYl?m*CZ%4)A6EgTB>j-DCy0mOb+@T6BbOlhD1p(Um8>nn2It}lJrU_t9Uz2 zDx*xfJmb$z%1CZ`&d^~JKw@guqu8{U%VN>KI-BlQaXG2l&w2!tUXRl2QF=^;(qqc; zr0UaAt?b#U8)cN-@+^d1Z?n>~(>f*3lzdRy^o|kwI{q4!p4%=mGH+D=@?D2LDxOT$*;E(3P7XWwT zu%~%>{8H@Qc46>Wl*57YBz7zmwT$ryuQqmTjp7TfEJ<07voHS z<9*+$IO_NGXWnaWP-F3f7`mL|GIc#1kbFs%gNWIY2yTsHQH^ryBguJ@DdeR_$@4hO z;~#g5E;Y_F{_;6wO^9wAKBRsZOTDrGW_2!8}~D4RVfc z(9QTK{gE9gq)apPw7WkTgoTjSSA5ALY05uVIi&Ub_i3ra&jS#{dtp%P1JKvJUrX)k zg0`0WX*ZER{}9k4TFT#}rJC;pe-!+2@B`rYfIor!V4r_D<=@-4>vrh$o;Z_|nZy3w zh?~Wa7k&==f9TNqm5&#mBmZV4mQ$;)#3{9_gFH(`tH3Oj^_gXT>&HUc@@cX?M#=E; zGwJlphq%GRMO2Bg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/src/Djitellowhite/keyboard.cpp new file mode 100644 index 0000000..3006537 --- /dev/null +++ b/src/Djitellowhite/keyboard.cpp @@ -0,0 +1,52 @@ +#include +#include +#include "Hardwarelistener.h" +#include +using namespace std; +int scanKeyboard() +{ + + int in; + + struct termios new_settings; + struct termios stored_settings; + //设置终端参数 + tcgetattr(0,&stored_settings); + new_settings = stored_settings; + new_settings.c_lflag &= (~ICANON); + new_settings.c_cc[VTIME] = 0; + tcgetattr(0,&stored_settings); + new_settings.c_cc[VMIN] = 1; + tcsetattr(0,TCSANOW,&new_settings); + in = getchar(); + tcsetattr(0,TCSANOW,&stored_settings); + + return in; + +} + +//测试函数 +int listenkeyboard(){ + while(1){ + switch(scanKeyboard()) + { + case (int)'w': + cout << "forward"<< endl; + break; + case (int)'s': + cout << "back" << endl; + break; + case (int)'a': + cout << "left" <N+|;A>n7Zw_KW;il z+cA}~0Ji=ED|998HE6p%x+8A-lx~kHw|5`xC@z;<_%yH6?G-x@b9KC!>hQ{Vk`Ed) zcdcy{P&-0>(WhI=r)Zw!iSX0keRkm0>5pXkPXFrRe|c_A)%m#)Oa0G*QZrW*;1Nel z_FwxA;agYvm>5@1vK#R?6Mq{%d~?FmzQJ9G9{Sm?>9@?8`{jn(7oXq!?&I0VQ(tTN z=INf7zLEOcq2|E%f7JQGb^HJ7J0Ji1(^c=otYCQ*4eCoOPrjfCeijE_NT1^2$@8F? z#YOylsR$k{g5OgFr`Q*2w+ncoel94YzY6$l{JBdEz;$jA{MU>0=P!!jj~0pBM@8^6 zXroa7Un+uMEaE3zME?${Um)Uzlb~TddtoSb?}@n!>E#u*M99jz(iE7x^3R35rO2*fIm5P#lu=R!uOL zv}7%ss9$eYR|i`Ianp(iB37b4==ZM!wzw&fhy=}8!it9jZS}zorhk2{Nxr0qaC<0P zAG|!<4d#X_Sl^0cyMOKaSTx~pSha3_Y`y6xK=-p+_S5F;7Wuc0Nb9Pd+|mRNCKzjP z_D4oks;gTR+8z#C{_5&PEVz{p*o?G0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f)ruM!J|33~qPFbJr znf@CDlO6WFe>1dDS+HI)`wt~%Pl z5`M=4AWW;P Y&h4@;JrftQZ@fck(En@TEG}03A3X&HVE_OC literal 0 HcmV?d00001 diff --git a/src/Djitellowhite/server b/src/Djitellowhite/server new file mode 100755 index 0000000000000000000000000000000000000000..09df8ae37f8fe70c170159a9790f2614f1457879 GIT binary patch literal 17176 zcmeHOe{dAl9e+vq5fm=Lf*@2_QAezkBcXr+8_k6zY-|vOL~RwWQ?N8W0syF1r(-EJIYOWl@yEaIyc>?^0Hr1wj-A8`jlOtvST`~ z;xXlXQcmbwtMcik8e~*7c@)BHcbl^F(nh7vlwwfX{H_)Hcj9eScDpp`MtEtf4GX3m z?`GIhUjEs_-MmS~E7T8rRQ{Q&^onIY;f_@+mi2_Hdcx6UUsYf2s;X5h{E3)dfmleP_6u`{_ z_>X~W__y78IfQ(D%Q2OG^{n2`qSa-!7$?57m6e^Ur`vX0HdYS9p27 zZOHn}pSr=u>6)N;Tt*x?0%yyp1HT}P3Nh}$eGdGL1LwJf!~+VSj=J+YeaM0H96ZgZbvDbk+=evCloMLm?@4z`nBzwkz)0pKl?7(L-2zuOs&vM`=9C(ET zFII~gC}yCTfno-V87OAp|2G34S1kIQK6tuZ-#PVnxHs2_hON@f34QQ|@+0!3GAnNc zJdwHb>mU`21?hK_WMb^COeV8i@^k|>F?KS`(~Z%@*x@WsH$)R-PiJ|$5tG! z(8SooS)OiuCdMAf@^r&9F?M&BryHG#v0#>`8@-9Ko3lLK;7yDLm`Cep$<{Xt*?#at zema{Rf1ig>diaQkH$D6o58v+L*L(OT4`1iuS33EcKewb#-l?bF)(77i-`Ligp1KVg z)zh;wNVJ}=OM_(QUIdd*c7t7wik_ajoXF}k)?9S$2UVz}YiDFeDi#kQJK~6<(4Qgo zSC$gF`n;YR*AIVigMRo-nO<^KKY8Ao0|zfE2j!WOE}1vBr~V(PBe6(c)2RoH5zO(LUU`G4TXELK9bjH!CKLTH}1-9AvWIwhYLaMaGPJ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sb%!{RaM;kN1nNcraobp=2b|4-*GxK+|%mCd~LYGw$!~?S*FZroj3p zqv@tb16x4cx*=gSe&eRV`j)kBiQH=f2>X_dCS7^Z8#f7KUF(L1K&!E#xp{L_o6#0% zXl){|a)(N1A}L!fjBnOdCquo4-Hh-*+@nJKW9sXjJ6du(W8Ao5(!&OOTa8;{Z?AD< zau1FhvbW#3F?-968=JJ@#w(_F*t=?Q>h3KzMko<8x`WXWZNF*R0Ig6sY9tdTQk}~Z zby#-WkJo!gBB7ki%|7(Z#;rnojNFJ}VBZgSF>MISyUWMDugLAeeputigg?ox-gvCnj9dK+7`TaWEb3wm$l_*CkPK9neGt0F=zX*FCN>1>j)K$gyGCKN3RG!F5Cz%#>w-*zlhMC45mcpLZux?CrEIli=}Vtc;dW~xEvEWD0ljP}bp?Qc`@nbPwzXW`!i##&Hu+VlN8Q;iiB z_1fPG{4ZFOar^l`pDD*z%eU-0m)!wUMfP{=B{n1EW)BdtNs% zJr0?(D0f-tZq#Va$@aXyV7f$Ua{F12>HUz?8kTuphcMNYy|?`e7HL!{r)V zk>h*M{|CyxLFw^2ohh&D$)0lNwSOEK<%Ip?N8B!odhgV|{r^Lcy{7D#4l8#|JnqHM zJ@z9?fhp@3vfuBq=XDoTk~<6gV|oBW=lSz~dZv%6>xq4^9rN_MtJ9v>aZLIDA=dZi z??q+L{Vz17spxkV%Y^%n`BzY(_-wyRvn5PhZ8m%K#(x76r~N6-R%NP@&{4ec--V3U zVw@&kZ}2{DuRilkY28ubu;>59daD4Uu%6B3c*f5`Kx3EV^SYJy<@5e~y8fuJ9rxpt zz~~g&p4YeC>c*DVb +#include +#include +#include +#include +#include +#include +#include +#define PORT 8890 + +void udp_server(int sockfd) +{ + + socklen_t len; + char buf[1024] = {0}; + struct sockaddr_in server_addr; + int n; + int opt = 1; + len = sizeof(server_addr); + memset(&buf, 0, sizeof(buf)); + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = htonl(INADDR_ANY); + server_addr.sin_port = htons(PORT); + + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); //当服务器非正常断开的时候重启服务器,不会进入TIME_WAIT状态 + + if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { + printf("can not bind\n"); + exit(1); + } + + while (1) { + printf("========wait for client's request========\n"); + n = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&server_addr, &len); + buf[n] = '\0'; + printf("receive client's data: %s\n", buf); + sendto(sockfd, buf, n, 0, (struct sockaddr *)&server_addr, len); + printf("send data to client: %s\n", buf); + } + + close(sockfd); +} + +int main(int argc, char **argv) +{ + int sockfd; + + if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + printf("create socket false\n"); + exit(1); + } + + udp_server(sockfd); + + exit(0); +} + +