Jump to content
  • 0
Yevheniy B

Example code for the WbtVRTFileReadIterator

Question

1 answer to this question

Recommended Posts

  • 0

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <errno.h>

#include <time.h>

#include <sys/types.h>

#include <iostream>

#include "WbtApi/WbtConnection.h"

#include "WbtApi/WbtFft.h"

#include "WbtApi/WbtSweeper.h"

#include "WbtApi/WbtSystem.h"

#include "WbtApi/WbtStatus.h"

#include "WbtApi/WbtVRTFileReadIterator.h"

#include "Poco/Logger.h"

#include "Poco/AsyncChannel.h"

#include "Poco/ConsoleChannel.h"

#include "Poco/AutoPtr.h"

#include "Poco/NumberParser.h"

using namespace std;

using namespace WbtApi;

 

int main(int argc, char *argv[])

{

    string filename = "/tmp/temp.qvrt";

    string tuner = "A";

    string samplesToRead = "-1";

    string samplesToSkip = "0";

 

    long read;

    long skip;

 

    if (argc == 4)

    {

        filename = argv[1];

        tuner = argv[2];

        samplesToRead = argv[3];

    }

    else if (argc == 5)

    {

        filename = argv[1];

        tuner = argv[2];

        samplesToRead = argv[3];

        samplesToSkip = argv[4];

    }

    else

    {

        std::cout  << "Invalid number of arguments: wbt-api-test path [samples to read] [samples to skip]\n";

        return 1;

    }

 

    read = Poco::NumberParser::parse64(samplesToRead);

    skip = Poco::NumberParser::parse64(samplesToSkip);

 

    WbtCommon::Data::RadioSelection_t selectedTunerStream = WbtCommon::Data::Radio_A;

 

    if (tuner == "B" || tuner == "b")

    {

        selectedTunerStream = WbtCommon::Data::Radio_B;

    }

 

    WbtVRTFileReadIterator fileIterator(filename, selectedTunerStream);

 

    if (fileIterator.isValid())

    {

        cout << "Successfully opened file " << filename << "\n";

    }

    else

    {

        cout << "Failed to open file " << filename << "\n";

    }

 

    float tempBuffer[2000000];

 

    if (fileIterator.isValid())

    {

        fileIterator.getCurrentIQDataFloat(NULL, skip*2, WbtVRTFileReadIterator::Wbt_Samples_Skip, false);

    }

    else

    {

        cout << "ERROR: Iterator not valid, failed to skip!!!\n";

        return 1;

    }

 

    cout << "Metadata\n";

    cout << "----------------\n";

    cout << fileIterator.getCurrentMetadataAsJSON() << "\n\n";

 

    while (fileIterator.isValid())

    {

        long readThisLoop = 1000000;

 

        if (read <= 0)

        {

            cout << "Read all samples successfully. \n";

            return 0;

        }

 

        if (readThisLoop > read)

        {

            readThisLoop = read;

        }

 

        read -= readThisLoop;

 

        if (fileIterator.metadataChanged())

        {

            cout << "Metadata Updated\n";

            cout << "----------------\n";

            cout << fileIterator.getCurrentMetadataAsJSON() << "\n\n";

        }

 

        cout << "Reading " << readThisLoop << " Samples...";

 

        int readResult = fileIterator.getCurrentIQDataFloat(tempBuffer, readThisLoop*2, WbtVRTFileReadIterator::Wbt_Samples_Continued_From_Last, true);

 

        cout << " got " << readResult << "\n";

    }

 

    cout << "ERROR; returned from invalid file.\n";

 

    return 2;

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×