void ncopy(const char* port, int studentNo, int nfiles, char* file[]) { SerialPort serialPort(port); PacketSender packetSender(&serialPort); if (serialPort.Setup() != ERR_NONE) { eggog("Error: cannot open %s\n", port); } for (int i = 0; i < nfiles; i++) { sendFile(file[i], packetSender, studentNo); } info("ncopy done\n"); }
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(); }