22 #include <QNetworkReply> 53 m_deviceAPI(deviceAPI),
55 m_fileInputThread(
nullptr),
56 m_deviceDescription(),
62 m_startingTimeStamp(0)
64 m_deviceAPI->setNbSourceStreams(1);
65 qDebug(
"FileInput::FileInput: device source engine: %p", m_deviceAPI->getDeviceSourceEngine());
66 qDebug(
"FileInput::FileInput: device source engine message queue: %p", m_deviceAPI->getDeviceEngineInputMessageQueue());
67 qDebug(
"FileInput::FileInput: device source: %p", m_deviceAPI->getDeviceSourceEngine()->getSource());
68 m_networkManager =
new QNetworkAccessManager();
69 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
70 m_masterTimer.setTimerType(Qt::PreciseTimer);
71 m_masterTimer.start(50);
112 QString crcHex = QString(
"%1").arg(header.
crc32 , 0, 16);
116 qDebug(
"FileInput::openFileStream: CRC32 OK for header: %s", qPrintable(crcHex));
121 qCritical(
"FileInput::openFileStream: bad CRC32 for header: %s", qPrintable(crcHex));
135 qDebug() <<
"FileInput::openFileStream: " <<
m_fileName.toStdString().c_str()
136 <<
" fileSize: " << fileSize <<
" bytes" 158 QMutexLocker mutexLocker(&
m_mutex);
180 qWarning(
"FileInput::start: file not open. not starting");
184 QMutexLocker mutexLocker(&
m_mutex);
185 qDebug() <<
"FileInput::start";
187 if (
m_ifstream.tellg() != (std::streampos)0) {
193 qCritical(
"Could not allocate SampleFifo");
202 mutexLocker.unlock();
203 qDebug(
"FileInput::startInput: started");
215 qDebug() <<
"FileInput::stop";
216 QMutexLocker mutexLocker(&
m_mutex);
353 qDebug() <<
"FileInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
375 qDebug() <<
"FileInput::handleMessage: MsgReportEOF";
408 QList<QString> reverseAPIKeys;
416 reverseAPIKeys.append(
"accelerationFactor");
420 QMutexLocker mutexLocker(&
m_mutex);
422 qCritical(
"FileInput::applySettings: could not reallocate sample FIFO size to %lu",
430 reverseAPIKeys.append(
"loop");
433 reverseAPIKeys.append(
"fileName");
451 QString& errorMessage)
462 const QStringList& deviceSettingsKeys,
464 QString& errorMessage)
469 if (deviceSettingsKeys.contains(
"fileName")) {
472 if (deviceSettingsKeys.contains(
"accelerationFactor")) {
475 if (deviceSettingsKeys.contains(
"loop")) {
478 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
481 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
484 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
487 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
506 QString& errorMessage)
516 QString& errorMessage)
534 QString& errorMessage)
565 quint64 samplesCount = 0;
578 t = t.addSecs(t_sec);
579 t = t.addMSecs(t_msec);
583 QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
584 dt = dt.addSecs(t_sec);
585 dt = dt.addMSecs(t_msec);
588 QTime recordLength(0, 0, 0, 0);
608 if (deviceSettingsKeys.contains(
"accelerationFactor") || force) {
611 if (deviceSettingsKeys.contains(
"loop") || force) {
614 if (deviceSettingsKeys.contains(
"fileName") || force) {
618 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
623 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
625 QBuffer *buffer=
new QBuffer();
626 buffer->open((QBuffer::ReadWrite));
627 buffer->write(swgDeviceSettings->
asJson().toUtf8());
633 delete swgDeviceSettings;
643 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
648 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
650 QBuffer *buffer=
new QBuffer();
651 buffer->open((QBuffer::ReadWrite));
652 buffer->write(swgDeviceSettings->
asJson().toUtf8());
661 delete swgDeviceSettings;
666 QNetworkReply::NetworkError replyError = reply->error();
670 qWarning() <<
"FileInput::networkManagerFinished:" 671 <<
" error(" << (int) replyError
672 <<
"): " << replyError
673 <<
": " << reply->errorString();
677 QString answer = reply->readAll();
679 qDebug(
"FileInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
SWGFileInputReport * getFileInputReport()
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
void setOriginatorIndex(qint32 originator_index)
SampleSinkFifo m_sampleFifo
MessageQueue * getMessageQueueToGUI()
int getDeviceSetIndex() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
void setFileInputSettings(SWGFileInputSettings *file_input_settings)
static bool match(const Message *message)
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void setFileInputReport(SWGFileInputReport *file_input_report)
void getDeviceEngineStateStr(QString &state)
SWGFileInputSettings * getFileInputSettings()
static bool readHeader(std::ifstream &samplefile, Header &header)
returns true if CRC checksum is correct else false
void setDirection(qint32 direction)
void setDeviceHwType(QString *device_hw_type)