Skip to content

Commit

Permalink
Buffer, groups and logs (#5)
Browse files Browse the repository at this point in the history
* Finished handling CLI arguments in app/server

* Debugging HyDRA to allow graceful exit. Server side is okay. Issue appers to be in the Hypervisor thread

* Working on graceful exit. Debugging at the autodiscovery thread

* Clean exit <3

* Clean exti working. Leaving Debug compilation.

* Playing with the ring buffer

* Templated circular buffer is looking good

* Cleaned new buffers

* Integrating the new circular buffer in the respective files

* Glueing the new entities in place

* Issue with the read template method. Not suitable for runtime allocation. Will have to use a vector instead of an array.

* Working with vector. Must find a way to pass the window properly.

* Fixed linking issue. Had to move the template implementation to the header file.

* Buffer is now a header only library. Tiddied header imports in source files.

* Midway trough using the new buffer in the RX direction.

* Buffer is now a hpp. Rename 'window' to 'iq_window' and 'iq_stream' to 'sample_stream'. Surprinsingly is compiles. But sockets, buffer and resampler are broken.

* Fixed socket, buffer, and resampler. May be ready to test~~

* Creating buffers with proper capacities, passing them as shared pointers. Fixed all the issues I encountered. Moving to testing.

* Client throws error instead of hanging forever. Server now prints useful information

* Client prints info only with the debug flag

* Removed references to padding

* Fixed GRC block compilation :)

* Fixed sigfault

* Fixed segfault on RX :)

* Sorting GRC issue

* Debugging GRC issue

* Still playing with GRCs

* Fixed exit when a single  chain is defined. Fixed server swig issue.

* Created new 'file' backend. New method to simplify buffer comsumption.

* Sorted out clean exit of active virtual radios.

* Fixed leakage in the TX chain.

* Minor changes, trying to optimise the buffer and the sockets

* Sockets should be faster. Set gain through CLI.

* Adding Gain and File parameters to GRC

* GRC Server  with extra and default parameters works :)

* Implementing the group logic.

* Implemented groups :)

* Implemented logging.

* Added logging to autodiscovery

* Logging works in GNU Radio
  • Loading branch information
santos-j authored and maiconkist committed May 3, 2019
1 parent 63de543 commit d0e815e
Show file tree
Hide file tree
Showing 62 changed files with 3,424 additions and 1,627 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.8.9)
# Define project name
project (HyDRA)

# set(CMAKE_BUILD_TYPE Debug)

# Use C++17
set(CMAKE_CXX_FLAGS "-std=c++17")
# set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -40,7 +42,14 @@ find_library(
)

# Find Boost
find_package(Boost "1.58" COMPONENTS system filesystem REQUIRED)
find_package(Boost "1.58" COMPONENTS
system
filesystem
program_options
log
log_setup REQUIRED)

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)

# Include the project's directories
include_directories(include)
Expand Down
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ link_directories(${HYDRA_SOURCE_DIR}/lib)

# Add the Server executable
add_executable(server server.cc)
target_link_libraries(server hydra)
target_link_libraries(server hydra ${Boost_LIBRARIES})

# Add the Client executable
add_executable(client client.cc)
Expand Down
58 changes: 38 additions & 20 deletions app/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,55 @@ using namespace std;

int main()
{
double cf = 1.1e9;
// Hypervisor's CF
double cf = 2e9;

// VR 1 specs
double vr_1_cf = cf + 200e3;
double vr_1_bw = 200e3;

std::string lalala;
// Request resources
std::cout << boost::format("------------- Requesting %1%, %2%") % (cf+200e3) % 200e3 << std::endl;
hydra::hydra_client s1 = hydra::hydra_client("127.0.0.1", 5000, 90, true);
std::cout<< s1.check_connection() << std::endl;
std::cout<< s1.query_resources() << std::endl;
std::cout << "------------- Requesting" << std::endl;
std::cout << "CF: " << vr_1_cf << "\tBW: " << vr_1_bw << std::endl;

hydra::hydra_client s1 = hydra::hydra_client("127.0.0.1", 5000, 91, "default", true);

s1.check_connection();
s1.query_resources();

hydra::rx_configuration tx1{cf + 200e3, 200e3, false};
std::cout << s1.request_tx_resources(tx1) << std::endl;
hydra::rx_configuration tx1{vr_1_cf, vr_1_bw};
s1.request_tx_resources(tx1);

#if 0
// VR 1 specs
double vr_2_cf = cf - 200e3;
double vr_2_bw = 200e3;

#if 2
// Request resources
std::cout << boost::format("------------- Requesting %1%, %2%") % (cf-200e3) % 100e3 << std::endl;
hydra::hydra_client s2 = hydra::hydra_client("127.0.0.1", 5000, 91, true);
std::cout << "------------- Requesting" << std::endl;
std::cout << "CF: " << vr_2_cf << "\tBW: " << vr_2_bw << std::endl;

hydra::hydra_client s2 = hydra::hydra_client("127.0.0.1", 5000, 92, true);

hydra::rx_configuration tx2{cf - 200e3, 100e3, false};
std::cout << s2.check_connection() << std::endl;
std::cout << s2.request_tx_resources(tx2) << std::endl;
s2.check_connection();
s2.query_resources();

hydra::rx_configuration tx2{vr_2_cf, vr_2_bw, false};
s2.request_tx_resources(tx2);
#endif

// sleep(1);
// Free resources from a given service
sleep(1);
std::cout << s1.free_resources() << std::endl;
std::cout << s1.query_resources() << std::endl;
// s1.free_resources();
// Query available resources
// s1.query_resources();

#if 2
#if 0
sleep(1);
// Free resources from a given service
s2.free_resources();
// Query available resources
std::cout << s2.free_resources() << std::endl;
std::cout << s2.query_resources() << std::endl;
s2.query_resources();
#endif


Expand Down
4 changes: 2 additions & 2 deletions app/iq_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ int main(int argc, char* argv[])

// Request resources
std::string lalala;
hydra::hydra_client s1 = hydra::hydra_client("127.0.0.1", 5000, 1, true);
hydra::hydra_client s1 = hydra::hydra_client("127.0.0.1", 5000, 1, "default", true);

hydra::rx_configuration tx_conf{1.1e9 + 500e3, std::stof(rate), false};
hydra::rx_configuration tx_conf{1.1e9 + 500e3, std::stof(rate)};
lalala = s1.request_tx_resources(tx_conf);
std::cout << lalala << std::endl;

Expand Down
141 changes: 121 additions & 20 deletions app/server.cc
Original file line number Diff line number Diff line change
@@ -1,54 +1,155 @@
#include <boost/program_options.hpp>

#include "hydra/hydra_main.h"
#include "hydra/hydra_uhd_interface.h"

/* Configure the TX radio */
hydra::uhd_hydra_sptr usrp = std::make_shared<hydra::device_loopback>();
using namespace boost::program_options;

// Instantiate the backend object
hydra::uhd_hydra_sptr backend;

// Instantiate the HyDRA object
hydra::HydraMain *hydra_instance;

void
signal_handler(int signum)
{
std::cout << "Closing Application." << std::endl;
usrp->release();
}

backend->release();
hydra_instance->stop();
}

int main()
int
main(int argc, const char *argv[])
{
signal(SIGINT, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGABRT, signal_handler);
signal(SIGHUP, signal_handler);
// signal(SIGQUIT, signal_handler);
// signal(SIGABRT, signal_handler);

// Boost Program Options configuration
try
{
options_description desc{"Options"};
desc.add_options()
("help,h", "Help Message")
("tx_freq", value<double>()->default_value(2e9), "Transmitter Centre Frequency")
("tx_rate", value<double>()->default_value(1e6), "Transmitter Sampling Rate")
("tx_gain", value<double>()->default_value(0.6), "Transmitter Normalized Gain")
("tx_fft", value<unsigned int>()->default_value(1024), "Transmitter FFT Size")
("rx_freq", value<double>()->default_value(2e9), "Receiver Centre Frequency")
("rx_rate", value<double>()->default_value(1e6), "Receiver Sampling Rate")
("rx_gain", value<double>()->default_value(0.0), "Receiver Normalized Gain")
("rx_fft", value<unsigned int>()->default_value(1024), "Receiver FFT Size")
("host", value<std::string>()->default_value("127.0.0.1"), "Server Host")
("port", value<unsigned int>()->default_value(5000), "Server Port")
("group", value<std::string>()->default_value("default"), "Hypervisor Group")
("backend", value<std::string>()->default_value("usrp"), "Backend (usrp, loop, plot, file)");

// Instantiate variables map, store, and notify methods
variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
notify(vm);

// Print help and exit
if (vm.count("help"))
{
std::cout << desc << '\n';
return 0;
}

// Print debug information
std::string delimiter = std::string(20, '-');
std::cout << delimiter << " Transmitter Parameters " << delimiter << std::endl;
std::cout << "Centre Frequency " << vm["tx_freq"].as<double>();
std::cout << "\t"<< "Sampling Rate " << vm["tx_rate"].as<double>();
std::cout << std::setprecision(2) << "\t"<< "Normalized Gain " << vm["tx_gain"].as<double>();
std::cout << "\t"<< "FFT Size " << vm["tx_fft"].as<unsigned int>() << "\n" << std::endl;
std::cout << delimiter << " Receiver Parameters " << delimiter << std::endl;
std::cout << "Centre Frequency " << vm["rx_freq"].as<double>();
std::cout << "\t"<< "Sampling Rate " << vm["rx_rate"].as<double>();
std::cout << std::setprecision(2) << "\t"<< "Normalized Gain " << vm["rx_gain"].as<double>();
std::cout << "\t"<< "FFT Size " << vm["rx_fft"].as<unsigned int>() << "\n" << std::endl;
std::cout << delimiter << " Server Parameters " << delimiter << std::endl;
std::cout << "Host " << vm["host"].as<std::string>();
std::cout << "\t" << "Port " << vm["port"].as<unsigned int>() ;
std::cout << "\t"<< "Group " << vm["group"].as<std::string>() << "\n" << std::endl;

// Extract the backend type
std::string backend_type = vm["backend"].as<std::string>();

/* Configure the backend */
if (backend_type == "usrp")
{
backend = std::make_shared<hydra::device_uhd>();
std::cout << "USRP Backend" <<std::endl;
}
else if (backend_type == "loop")
{
backend = std::make_shared<hydra::device_loopback>();
std::cout << "Loopback Backend" <<std::endl;
}
else if (backend_type == "plot")
{
backend = std::make_shared<hydra::device_image_gen>();
std::cout << "Plot Image Backend" <<std::endl;
}
else if (backend_type == "file")
{
backend = std::make_shared<hydra::device_file>();
std::cout << "File Backend" <<std::endl;
}
else
{
// Throw error if the backend is not valid
throw invalid_option_value("backend = " + backend_type);
}

/* TRANSMITTER */
double d_tx_centre_freq = 1.1e9;
double d_tx_samp_rate = 2e6;
unsigned int u_tx_fft_size = 1024;
double d_tx_centre_freq = vm["tx_freq"].as<double>();
double d_tx_samp_rate = vm["tx_rate"].as<double>();
double d_tx_norm_gain = vm["tx_gain"].as<double>();
unsigned int u_tx_fft_size = vm["tx_fft"].as<unsigned int>();

/* RECEIVER */
double d_rx_centre_freq = 1.1e9;
double d_rx_samp_rate = 2e6;
unsigned int u_rx_fft_size = 1024;
double d_rx_centre_freq = vm["rx_freq"].as<double>();
double d_rx_samp_rate = vm["rx_rate"].as<double>();
double d_rx_norm_gain = vm["rx_gain"].as<double>();
unsigned int u_rx_fft_size = vm["rx_fft"].as<unsigned int>();

/* Control port */
unsigned int u_port = 5000;
unsigned int u_port = vm["port"].as<unsigned int>();
std::string s_host = vm["host"].as<std::string>();
std::string s_group= vm["group"].as<std::string>();

/* Instantiate XVL */
hydra::HydraMain main = hydra::HydraMain("127.0.0.1:5000");
hydra_instance = new hydra::HydraMain(
s_host + ":" + std::to_string(u_port),
s_group);

main.set_tx_config(
usrp,
hydra_instance->set_tx_config(
backend,
d_tx_centre_freq,
d_tx_samp_rate,
d_tx_norm_gain,
u_tx_fft_size);

main.set_rx_config(
usrp,
hydra_instance->set_rx_config(
backend,
d_rx_centre_freq,
d_rx_samp_rate,
d_rx_norm_gain,
u_rx_fft_size);

/* Run server */
main.run();
hydra_instance->run();

}
catch (const error &ex)
{
std::cerr << ex.what() << '\n';
}

/* Run server */
return 0;
Expand Down
6 changes: 4 additions & 2 deletions grc_blocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ set(Boost_ADDITIONAL_VERSIONS
"1.60.0" "1.60" "1.61.0" "1.61" "1.62.0" "1.62" "1.63.0" "1.63" "1.64.0" "1.64"
"1.65.0" "1.65" "1.66.0" "1.66" "1.67.0" "1.67" "1.68.0" "1.68" "1.69.0" "1.69"
)
find_package(Boost "1.35" COMPONENTS filesystem system)
find_package(Boost "1.35" COMPONENTS filesystem system log log_setup REQUIRED)

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)

if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost required to compile hydra")
Expand Down Expand Up @@ -171,7 +173,7 @@ include_directories(
${CMAKE_BINARY_DIR}/include
${Boost_INCLUDE_DIRS}
${CPPUNIT_INCLUDE_DIRS}
${GNURADIO_RUNTIME_INCLUDE_DIRS}
${GNURADIO_RUNTIME_INCLUDE_DIRS}
${GNURADIO_ALL_INCLUDE_DIRS}
${ZMQ_INCLUDE_DIR}
)
Expand Down
Loading

0 comments on commit d0e815e

Please sign in to comment.