int main(int argc, char **argv) { QString role; QString serPort; QString udpPort; QString remoteHost; QString bufferSize; QCoreApplication a(argc, argv); std::cout << "Serial port transmitter/receiver example, Copyright (c) 2010 Inbiza Systems Inc." << std::endl; std::cout << "Created by Inbiza Labs <*****@*****.**>" << std::endl; std::cout << "==========" << std::endl; std::cout << "Connect two networked computers with null-modem cable, run tranceiver with \"--role=transmit\" on one, and with \"--role=receive\" on ther other." << std::endl; std::cout << "==========" << std::endl; std::cout << std::endl; if ( !processArgs(a.arguments(), role, serPort, udpPort, remoteHost, bufferSize) ) return 0; qDebug() << "Mode:" << role << ", Serial Port:" << serPort << ", Port Settings:" << "9600,8,n,1" << ", Listening at port: " << udpPort << ", Testing peer at: " << remoteHost << ", Buffer size: " << (bufferSize == "*" ? "equal to data set size" : bufferSize); TNX::QSerialPort serialPort(serPort, "9600,8,n,1"); TNX::CommTimeouts commTimeouts; commTimeouts.PosixVMIN = 1; commTimeouts.PosixVTIME = 0; commTimeouts.Win32ReadIntervalTimeout = 75; commTimeouts.Win32ReadTotalTimeoutConstant = 250; commTimeouts.Win32ReadTotalTimeoutMultiplier = 25; commTimeouts.Win32WriteTotalTimeoutConstant = 250; commTimeouts.Win32WriteTotalTimeoutMultiplier = 75; if ( !serialPort.setCommTimeouts(commTimeouts) ) qWarning("Cannot set communications timeout values at port %s.", qPrintable(serPort)); Receiver *receiver = NULL; Transmitter *transmitter = NULL; if ( 0 == role.compare("transmit", Qt::CaseInsensitive) ) { transmitter = new Transmitter(serialPort, remoteHost, udpPort.toInt(), &a); if ( !transmitter->start() ) { std::cout << "Cannot start transmitter. Quitting." << std::endl; return 0; } } else if ( 0 == role.compare("receive", Qt::CaseInsensitive) ) { receiver = new Receiver(serialPort, remoteHost, udpPort.toInt(), QString((bufferSize == "*" ? "0" : bufferSize)).toInt(), &a); if ( !receiver->start() ) { std::cout << "Cannot start receiver. Quitting." << std::endl; return 0; } } else { std::cout << "Wrong role defined. Quitting." << std::endl; return 0; } return a.exec(); }
int main(int argc, char* argv[]) { bool createFromFile = false; std::string create_filename = "nothing"; bool backup = false; std::string backup_filename = "no_backup"; for(int i=0;i<argc;i++) { if(strcmp("-B",argv[i]) == 0 || strcmp("-b",argv[i]) == 0) { std::cout << "make continuous backups" << std::endl; if(i+1 < argc) { backup_filename = std::string(argv[i+1]); backup = true; } } if(strcmp("-F",argv[i]) == 0 || strcmp("-f",argv[i]) == 0) { std::cout << "Contruct from saved data" << std::endl; if(i+1 < argc) { create_filename = std::string(argv[i+1]); createFromFile = true; } } } std::cout << "------------------------------------"<< std::endl; std::cout << "---------------START----------------"<< std::endl; std::cout << "------------------------------------"<< std::endl; std::cout << "Main: program started" << std::endl; // (1) Create a mission and a transmitter Mission* mission; if(!createFromFile) { std::vector<std::string> missionPlan; for(std::string line; std::getline(std::cin,line);) { //std::cout << "READING: " << line << std::endl; if(line[0] != '#') missionPlan.push_back(line); } //std::cout << missionPlan.size() << std::endl; mission = new Mission(missionPlan); } else{ mission = new Mission(create_filename); } //return 0; //Mission* mission = new Mission(0); std::cout << "\n---------starting mission-----------\n"<< std::endl; Transmitter* transmitter = new Transmitter(2); transmitter->start(); // (2) Create the navigator, and pass the transmitter to double delta = 15; double tol = 2;//delta / 3.0; int delay_data = 50000; int delay_scanner = 500000; Navigator* navigator = new Navigator(transmitter,delay_data,delay_scanner,delta,tol, backup, backup_filename); // (3) give the navigator a mission navigator->setMission(mission); // (4) start navigator navigator->start(); //navigator.abort(); //transmitter->abort(); delete navigator; delete mission; delete transmitter; std::cout << "Main: program done" << std::endl; std::cout << "------------------------------------"<< std::endl; std::cout << "----------------DONE----------------"<< std::endl; std::cout << "------------------------------------"<< std::endl; }