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:
parent
ebab0e62af
commit
4b19d8e1e7
@ -145,7 +145,6 @@ try:
|
|||||||
# start capture and transmit
|
# start capture and transmit
|
||||||
log.info('starting capture')
|
log.info('starting capture')
|
||||||
drone.startCapture(rx_port)
|
drone.startCapture(rx_port)
|
||||||
time.sleep(1)
|
|
||||||
log.info('starting transmit')
|
log.info('starting transmit')
|
||||||
drone.startTx(tx_port)
|
drone.startTx(tx_port)
|
||||||
|
|
||||||
|
@ -324,6 +324,7 @@ PcapPort::PortTransmitter::PortTransmitter(const char *device)
|
|||||||
Q_ASSERT_X(false, "PortTransmitter::PortTransmitter",
|
Q_ASSERT_X(false, "PortTransmitter::PortTransmitter",
|
||||||
"This Win32 platform does not support performance counter");
|
"This Win32 platform does not support performance counter");
|
||||||
#endif
|
#endif
|
||||||
|
state_ = kNotStarted;
|
||||||
returnToQIdx_ = -1;
|
returnToQIdx_ = -1;
|
||||||
loopDelay_ = 0;
|
loopDelay_ = 0;
|
||||||
stop_ = false;
|
stop_ = false;
|
||||||
@ -490,7 +491,7 @@ void PcapPort::PortTransmitter::run()
|
|||||||
|
|
||||||
qDebug("packetSequenceList_.size = %d", packetSequenceList_.size());
|
qDebug("packetSequenceList_.size = %d", packetSequenceList_.size());
|
||||||
if (packetSequenceList_.size() <= 0)
|
if (packetSequenceList_.size() <= 0)
|
||||||
return;
|
goto _exit;
|
||||||
|
|
||||||
for(i = 0; i < packetSequenceList_.size(); i++) {
|
for(i = 0; i < packetSequenceList_.size(); i++) {
|
||||||
qDebug("sendQ[%d]: rptCnt = %d, rptSz = %d, usecDelay = %ld", i,
|
qDebug("sendQ[%d]: rptCnt = %d, rptSz = %d, usecDelay = %ld", i,
|
||||||
@ -502,6 +503,7 @@ void PcapPort::PortTransmitter::run()
|
|||||||
packetSequenceList_.at(i)->usecDuration_);
|
packetSequenceList_.at(i)->usecDuration_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state_ = kRunning;
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < packetSequenceList_.size())
|
while (i < packetSequenceList_.size())
|
||||||
{
|
{
|
||||||
@ -563,7 +565,7 @@ _restart:
|
|||||||
qDebug("error %d in sendQueueTransmit()", ret);
|
qDebug("error %d in sendQueueTransmit()", ret);
|
||||||
qDebug("overHead = %ld", overHead);
|
qDebug("overHead = %ld", overHead);
|
||||||
stop_ = false;
|
stop_ = false;
|
||||||
return;
|
goto _exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -587,12 +589,31 @@ _restart:
|
|||||||
i = returnToQIdx_;
|
i = returnToQIdx_;
|
||||||
goto _restart;
|
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()
|
void PcapPort::PortTransmitter::stop()
|
||||||
{
|
{
|
||||||
if (isRunning())
|
if (state_ == kRunning) {
|
||||||
stop_ = true;
|
stop_ = true;
|
||||||
|
while (state_ == kRunning)
|
||||||
|
QThread::msleep(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PcapPort::PortTransmitter::sendQueueTransmit(pcap_t *p,
|
int PcapPort::PortTransmitter::sendQueueTransmit(pcap_t *p,
|
||||||
@ -692,6 +713,7 @@ PcapPort::PortCapturer::PortCapturer(const char *device)
|
|||||||
{
|
{
|
||||||
device_ = QString::fromAscii(device);
|
device_ = QString::fromAscii(device);
|
||||||
stop_ = false;
|
stop_ = false;
|
||||||
|
state_ = kNotStarted;
|
||||||
|
|
||||||
if (!capFile_.open())
|
if (!capFile_.open())
|
||||||
qWarning("Unable to open temp cap file");
|
qWarning("Unable to open temp cap file");
|
||||||
@ -717,7 +739,7 @@ void PcapPort::PortCapturer::run()
|
|||||||
if (!capFile_.isOpen())
|
if (!capFile_.isOpen())
|
||||||
{
|
{
|
||||||
qWarning("temp cap file is not open");
|
qWarning("temp cap file is not open");
|
||||||
return;
|
goto _exit;
|
||||||
}
|
}
|
||||||
_retry:
|
_retry:
|
||||||
handle_ = pcap_open_live(device_.toAscii().constData(), 65535,
|
handle_ = pcap_open_live(device_.toAscii().constData(), 65535,
|
||||||
@ -736,13 +758,13 @@ _retry:
|
|||||||
{
|
{
|
||||||
qDebug("%s: Error opening port %s: %s\n", __FUNCTION__,
|
qDebug("%s: Error opening port %s: %s\n", __FUNCTION__,
|
||||||
device_.toAscii().constData(), errbuf);
|
device_.toAscii().constData(), errbuf);
|
||||||
return;
|
goto _exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dumpHandle_ = pcap_dump_open(handle_,
|
dumpHandle_ = pcap_dump_open(handle_,
|
||||||
capFile_.fileName().toAscii().constData());
|
capFile_.fileName().toAscii().constData());
|
||||||
|
state_ = kRunning;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -778,12 +800,31 @@ _retry:
|
|||||||
dumpHandle_ = NULL;
|
dumpHandle_ = NULL;
|
||||||
handle_ = NULL;
|
handle_ = NULL;
|
||||||
stop_ = false;
|
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()
|
void PcapPort::PortCapturer::stop()
|
||||||
{
|
{
|
||||||
if (isRunning())
|
if (state_ == kRunning) {
|
||||||
stop_ = true;
|
stop_ = true;
|
||||||
|
while (state_ == kRunning)
|
||||||
|
QThread::msleep(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile* PcapPort::PortCapturer::captureFile()
|
QFile* PcapPort::PortCapturer::captureFile()
|
||||||
|
@ -114,8 +114,15 @@ protected:
|
|||||||
void setHandle(pcap_t *handle);
|
void setHandle(pcap_t *handle);
|
||||||
void useExternalStats(AbstractPort::PortStats *stats);
|
void useExternalStats(AbstractPort::PortStats *stats);
|
||||||
void run();
|
void run();
|
||||||
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
private:
|
private:
|
||||||
|
enum State
|
||||||
|
{
|
||||||
|
kNotStarted,
|
||||||
|
kRunning,
|
||||||
|
kFinished
|
||||||
|
};
|
||||||
|
|
||||||
class PacketSequence
|
class PacketSequence
|
||||||
{
|
{
|
||||||
@ -183,6 +190,7 @@ protected:
|
|||||||
bool usingInternalHandle_;
|
bool usingInternalHandle_;
|
||||||
pcap_t *handle_;
|
pcap_t *handle_;
|
||||||
volatile bool stop_;
|
volatile bool stop_;
|
||||||
|
volatile State state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PortCapturer: public QThread
|
class PortCapturer: public QThread
|
||||||
@ -191,15 +199,24 @@ protected:
|
|||||||
PortCapturer(const char *device);
|
PortCapturer(const char *device);
|
||||||
~PortCapturer();
|
~PortCapturer();
|
||||||
void run();
|
void run();
|
||||||
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
QFile* captureFile();
|
QFile* captureFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum State
|
||||||
|
{
|
||||||
|
kNotStarted,
|
||||||
|
kRunning,
|
||||||
|
kFinished
|
||||||
|
};
|
||||||
|
|
||||||
QString device_;
|
QString device_;
|
||||||
volatile bool stop_;
|
volatile bool stop_;
|
||||||
QTemporaryFile capFile_;
|
QTemporaryFile capFile_;
|
||||||
pcap_t *handle_;
|
pcap_t *handle_;
|
||||||
pcap_dumper_t *dumpHandle_;
|
pcap_dumper_t *dumpHandle_;
|
||||||
|
volatile State state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
PortMonitor *monitorRx_;
|
PortMonitor *monitorRx_;
|
||||||
|
Loading…
Reference in New Issue
Block a user