// Compile syntax:
// > g++ spectrum_console.cpp -lboost_program_options-mt -loml2 -o spectrum_console
//
// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
#include
#include //gets time
//#include
#include
#include
#include
#include
#include "fcntl.h"
#include "unistd.h"
//#include
namespace po = boost::program_options;
bool xml_getElement(std::string element, std::string str, std::string &element_value)
{
std::string tag;
size_t start_pos, end_pos;
tag = "<"+element+">";
start_pos = str.find(tag);
if (start_pos == std::string::npos)
return false;
start_pos += tag.length();
tag = ""+element+">";
end_pos = str.find(tag);
element_value.assign (str, start_pos, end_pos-start_pos);
return true;
}
int main(int argc, char *argv[]){
//variables to be set by po
std::string ant, subdev, ref, wave_type, freq, rate, oml_format;
std::string gain, rx_node_name, num_bins, time_duration;
double bw, wave_freq;
FILE *fp_txusrp, *fp_rxusrp[20];
char line[8192];
std::string tx_cmd, rx_cmd;
//setup the program options
po::options_description desc("Allowed options");
desc.add_options()
("help", "help message")
("node", po::value(&rx_node_name)->default_value("node18-18"), "specify nodex-y. Use comma-delimited list for multiple nodes (no space): ex. node13-13,node18-18")
("freq", po::value(&freq)->default_value("5e9"), "RF center frequency (CF) in Hz. Use a single value for same CF for all nodes OR a comma-delimited list (no space) to specify unique CF per node: 2.43e9,5.2e9")
("rate", po::value(&rate)->default_value("16e6"), "rate of incoming samples (sps)")
("gain", po::value(&gain)->default_value("15"), "gain for RF gain in dBm")
//("ant", po::value(&ant), "daughterboard antenna selection")
//("subdev", po::value(&subdev), "daughterboard subdevice specification")
//("bw", po::value(&bw), "daughterboard IF filter bandwidth in Hz")
("time", po::value(&time_duration)->default_value("9999999"), "time duration to run for in seconds")
("oml", po::value(&oml_format)->default_value("file"), "file - record values to oml text file on the node, oml:3003 - record values to oml server")
("num-bins", po::value(&num_bins)->default_value("64"), "the number of FFT points")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
//print the help message
if (vm.count("help")){
std::cout << boost::format("%s") % desc << std::endl;
return ~0;
}
// Split rx node names and freq into list
std::vector node_list;
std::vector freq_list;
boost::split(node_list, rx_node_name, boost::is_any_of(",") );
boost::split(freq_list, freq, boost::is_any_of(",") );
// Error check node and freq list
if (freq_list.size() > node_list.size() )
{
std::cout << "ERR: frequency list is greater than node list" << std::endl;
return ~0;
}
if (freq_list.size() == 1)
{
freq_list.resize( node_list.size() );
for (int i = 0 ; i < freq_list.size(); freq_list.at(i) = freq , ++i );
}
//for (int i=0; i < node_list.size(); std::cout << node_list.at(i) << std::endl, i++)
for (int i = 0 ; i < node_list.size() ; i++)
{
rx_node_name = node_list.at(i);
freq = freq_list.at(i);
rx_cmd = " ssh root@" + rx_node_name + " \"/root/uhd/host/build/examples/spectrum";
rx_cmd += " --freq " + freq;
rx_cmd += " --rate " + rate;
rx_cmd += " --num-bins " + num_bins;
rx_cmd += " --gain " + gain;
rx_cmd += " --time " + time_duration;
rx_cmd += " --oml " + oml_format;
rx_cmd += " \"";
//printf("%s\n", rx_cmd.c_str());
/* Open the command for reading. */
fp_rxusrp[i] = popen( rx_cmd.c_str(), "r");
if (fp_rxusrp == NULL) {
std::cout << "Failed to run rx_peakpower\n";
exit;
}
//fcntl(fileno(fp_rxusrp[i]), F_SETFL, O_NONBLOCK);
} // end for-loop
// Give application some time to set up
sleep(3);
/* Read the output a line at a time - output it. */
while ( fgets(line, sizeof(line)-1, fp_rxusrp[0]) != NULL ) {
std::string str(line);
std::cout << "["<