#include "../include/Djitellowhite.h"
#include "../include/Hardwarelistener.h"
#include <iostream>

// This a mod of create a Tello

using namespace std;
void* Telloconnect1(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;

	}
	
	//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;
}
