start/stop Transmit/Capture return only after transmit/capture has been started/stopped. Removed sleep between startCapture and startTx from example.py

This commit is contained in:
Srivats P. 2014-06-21 19:55:55 +05:30
parent ebab0e62af
commit 4b19d8e1e7
3 changed files with 65 additions and 8 deletions

View File

@ -145,7 +145,6 @@ try:
# start capture and transmit
log.info('starting capture')
drone.startCapture(rx_port)
time.sleep(1)
log.info('starting transmit')
drone.startTx(tx_port)

View File

@ -324,6 +324,7 @@ PcapPort::PortTransmitter::PortTransmitter(const char *device)
Q_ASSERT_X(false, "PortTransmitter::PortTransmitter",
"This Win32 platform does not support performance counter");
#endif
state_ = kNotStarted;
returnToQIdx_ = -1;
loopDelay_ = 0;
stop_ = false;
@ -490,7 +491,7 @@ void PcapPort::PortTransmitter::run()
qDebug("packetSequenceList_.size = %d", packetSequenceList_.size());
if (packetSequenceList_.size() <= 0)
return;
goto _exit;
for(i = 0; i < packetSequenceList_.size(); i++) {
qDebug("sendQ[%d]: rptCnt = %d, rptSz = %d, usecDelay = %ld", i,
@ -502,6 +503,7 @@ void PcapPort::PortTransmitter::run()
packetSequenceList_.at(i)->usecDuration_);
}
state_ = kRunning;
i = 0;
while (i < packetSequenceList_.size())
{
@ -563,7 +565,7 @@ _restart:
qDebug("error %d in sendQueueTransmit()", ret);
qDebug("overHead = %ld", overHead);
stop_ = false;
return;
goto _exit;
}
}
}
@ -587,12 +589,31 @@ _restart:
i = returnToQIdx_;
goto _restart;
}
_exit:
state_ = kFinished;
}
void PcapPort::PortTransmitter::start()
{
// FIXME: return error
if (state_ == kRunning)
return;
state_ = kNotStarted;
QThread::start();
while (state_ == kNotStarted)
QThread::msleep(10);
}
void PcapPort::PortTransmitter::stop()
{
if (isRunning())
if (state_ == kRunning) {
stop_ = true;
while (state_ == kRunning)
QThread::msleep(10);
}
}
int PcapPort::PortTransmitter::sendQueueTransmit(pcap_t *p,
@ -692,6 +713,7 @@ PcapPort::PortCapturer::PortCapturer(const char *device)
{
device_ = QString::fromAscii(device);
stop_ = false;
state_ = kNotStarted;
if (!capFile_.open())
qWarning("Unable to open temp cap file");
@ -717,7 +739,7 @@ void PcapPort::PortCapturer::run()
if (!capFile_.isOpen())
{
qWarning("temp cap file is not open");
return;
goto _exit;
}
_retry:
handle_ = pcap_open_live(device_.toAscii().constData(), 65535,
@ -736,13 +758,13 @@ _retry:
{
qDebug("%s: Error opening port %s: %s\n", __FUNCTION__,
device_.toAscii().constData(), errbuf);
return;
goto _exit;
}
}
dumpHandle_ = pcap_dump_open(handle_,
capFile_.fileName().toAscii().constData());
state_ = kRunning;
while (1)
{
int ret;
@ -778,12 +800,31 @@ _retry:
dumpHandle_ = NULL;
handle_ = NULL;
stop_ = false;
_exit:
state_ = kFinished;
}
void PcapPort::PortCapturer::start()
{
// FIXME: return error
if (state_ == kRunning)
return;
state_ = kNotStarted;
QThread::start();
while (state_ == kNotStarted)
QThread::msleep(10);
}
void PcapPort::PortCapturer::stop()
{
if (isRunning())
if (state_ == kRunning) {
stop_ = true;
while (state_ == kRunning)
QThread::msleep(10);
}
}
QFile* PcapPort::PortCapturer::captureFile()

View File

@ -114,8 +114,15 @@ protected:
void setHandle(pcap_t *handle);
void useExternalStats(AbstractPort::PortStats *stats);
void run();
void start();
void stop();
private:
enum State
{
kNotStarted,
kRunning,
kFinished
};
class PacketSequence
{
@ -183,6 +190,7 @@ protected:
bool usingInternalHandle_;
pcap_t *handle_;
volatile bool stop_;
volatile State state_;
};
class PortCapturer: public QThread
@ -191,15 +199,24 @@ protected:
PortCapturer(const char *device);
~PortCapturer();
void run();
void start();
void stop();
QFile* captureFile();
private:
enum State
{
kNotStarted,
kRunning,
kFinished
};
QString device_;
volatile bool stop_;
QTemporaryFile capFile_;
pcap_t *handle_;
pcap_dumper_t *dumpHandle_;
volatile State state_;
};
PortMonitor *monitorRx_;