Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ set_target_properties(freesrp PROPERTIES VERSION ${VERSION} SOVERSION ${VERSION_
target_link_libraries(freesrp ${LIBUSB_1_LIBRARIES})

# Examples
FIND_PACKAGE(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)

# freesrp-io, using callbacks instead of busy waiting
Expand Down
16 changes: 8 additions & 8 deletions examples/ctl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "optionparser.hpp"

using namespace std;
using namespace FreeSRP;
//using namespace FreeSRP;

bool process_command(const FreeSRP::FreeSRP &srp)
{
Expand Down Expand Up @@ -76,7 +76,7 @@ bool process_command(const FreeSRP::FreeSRP &srp)
{
cmd.func(srp, params);
}
catch(ConnectionError e)
catch(FreeSRP::ConnectionError e)
{
cerr << "Error sending command to FreeSRP, " << e.what() << endl;
exit = true;
Expand Down Expand Up @@ -126,7 +126,7 @@ void list_devices()
void check_fx3()
{
// Check for FX3
if(Util::find_fx3())
if(FreeSRP::Util::find_fx3())
{
cout << "NOTE: Found a Cypress EZ-USB FX3 device. This could be a FreeSRP in bootloader mode.\n"
"You can upload the FreeSRP firmware to it by running 'freesrp-ctl --fx3=/path/to/firmware.img'" << endl;
Expand Down Expand Up @@ -206,7 +206,7 @@ int main(int argc, char *argv[])
// Upload firmware to FX3.
try
{
if(Util::find_fx3(true, fx3_firmware))
if(FreeSRP::Util::find_fx3(true, fx3_firmware))
{
// Firmware upload succeeded, continue
cout << "Sucessfully uploaded FreeSRP firmware to FX3" << endl;
Expand Down Expand Up @@ -237,13 +237,13 @@ int main(int argc, char *argv[])
cout << "Loading FPGA with '" << fpgaconfig_filename << "'" << endl;
switch(srp.load_fpga(fpgaconfig_filename))
{
case FPGA_CONFIG_DONE:
case FreeSRP::FPGA_CONFIG_DONE:
cout << "FPGA configured successfully" << endl;
break;
case FPGA_CONFIG_ERROR:
case FreeSRP::FPGA_CONFIG_ERROR:
cout << "Error configuring FPGA!" << endl;
break;
case FPGA_CONFIG_SKIPPED:
case FreeSRP::FPGA_CONFIG_SKIPPED:
cout << "FPGA already configured. To re-configure, please restart the FreeSRP." << endl;
break;
}
Expand All @@ -266,7 +266,7 @@ int main(int argc, char *argv[])
while(process_command(srp)) {}
}
}
catch(const ConnectionError &e)
catch(const FreeSRP::ConnectionError &e)
{
cerr << "Could not connect to FreeSRP: " << e.what() << endl;
}
Expand Down
48 changes: 24 additions & 24 deletions examples/io/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <iomanip>

using namespace std;
using namespace FreeSRP;
//using namespace FreeSRP;

enum optionIndex {NONE, HELP, OUTFILE, INFILE, FPGA, TX, LOOPBACK, CENTER_FREQ, BANDWIDTH, GAIN};
const option::Descriptor usage[] = {
Expand Down Expand Up @@ -65,7 +65,7 @@ void sigint_callback(int s)
_interrupt.notify_all();
}

void rx_callback(const vector<sample> &samples)
void rx_callback(const vector<FreeSRP::sample> &samples)
{
static vector<int16_t> buf;

Expand All @@ -77,7 +77,7 @@ void rx_callback(const vector<sample> &samples)
buf.resize(samples.size() * 2);

int buf_index = 0;
for(const sample &s : samples)
for(const FreeSRP::sample &s : samples)
{
// Convert from 12-bit to full scale 16-bit and copy to output buffer
buf[buf_index++] = (int16_t) (s.i * 16);
Expand Down Expand Up @@ -108,7 +108,7 @@ void rx_callback(const vector<sample> &samples)
}
}

void tx_callback(vector<sample> &samples)
void tx_callback(vector<FreeSRP::sample> &samples)
{
static vector<int16_t> buf;

Expand All @@ -122,7 +122,7 @@ void tx_callback(vector<sample> &samples)
_in->read((char *) buf.data(), sizeof(int16_t) * 2 * samples.size());

int buf_index = 0;
for(sample &s : samples)
for(FreeSRP::sample &s : samples)
{
// Convert from full scale 16-bit to 12 bit and copy to output buffer
s.i = (int16_t) (buf[buf_index++] / 16);
Expand Down Expand Up @@ -154,7 +154,7 @@ void tx_callback(vector<sample> &samples)
void start(FreeSRP::FreeSRP &srp)
{
// Enable datapath and start receiver
FreeSRP::response res = srp.send_cmd({SET_DATAPATH_EN, 1});
FreeSRP::response res = srp.send_cmd({FreeSRP::SET_DATAPATH_EN, 1});
if(res.error != FreeSRP::CMD_OK)
{
throw runtime_error("Error enabling FreeSRP datapath!");
Expand All @@ -167,7 +167,7 @@ void stop(FreeSRP::FreeSRP &srp)
{
srp.stop_rx();

FreeSRP::response res = srp.send_cmd({SET_DATAPATH_EN, 0});
FreeSRP::response res = srp.send_cmd({FreeSRP::SET_DATAPATH_EN, 0});
if(res.error != FreeSRP::CMD_OK)
{
throw runtime_error("Error disabling FreeSRP datapath!");
Expand Down Expand Up @@ -305,13 +305,13 @@ int main(int argc, char *argv[])
cerr << "Loading FPGA with '" << fpgaconfig_filename << "'" << endl;
switch(srp.load_fpga(fpgaconfig_filename))
{
case FPGA_CONFIG_DONE:
case FreeSRP::FPGA_CONFIG_DONE:
cerr << "FPGA configured successfully" << endl;
break;
case FPGA_CONFIG_ERROR:
case FreeSRP::FPGA_CONFIG_ERROR:
cerr << "Error configuring FPGA!" << endl;
break;
case FPGA_CONFIG_SKIPPED:
case FreeSRP::FPGA_CONFIG_SKIPPED:
cerr << "FPGA already configured. To re-configure, please restart the FreeSRP." << endl;
break;
}
Expand All @@ -329,31 +329,31 @@ int main(int argc, char *argv[])
cerr << "Version: " << srp.version() << endl;

// Set center frequency
response r = srp.send_cmd(srp.make_command(SET_RX_LO_FREQ, center_freq));
if(r.error != CMD_OK)
FreeSRP::response r = srp.send_cmd(srp.make_command(FreeSRP::SET_RX_LO_FREQ, center_freq));
if(r.error != FreeSRP::CMD_OK)
{
std::cerr << "Could not set RX LO frequency, error: " << r.error << endl;
return 1;
}

// Set bandwidth and sample rate
r = srp.send_cmd(srp.make_command(SET_RX_RF_BANDWIDTH, bandwidth));
if(r.error != CMD_OK)
r = srp.send_cmd(srp.make_command(FreeSRP::SET_RX_RF_BANDWIDTH, bandwidth));
if(r.error != FreeSRP::CMD_OK)
{
std::cerr << "Could not set RX bandwidth, error: " << r.error << endl;
return 1;
}

r = srp.send_cmd(srp.make_command(SET_RX_SAMP_FREQ, bandwidth));
if(r.error != CMD_OK)
r = srp.send_cmd(srp.make_command(FreeSRP::SET_RX_SAMP_FREQ, bandwidth));
if(r.error != FreeSRP::CMD_OK)
{
std::cerr << "Could not set RX sample frequency, error: " << r.error << endl;
return 1;
}

// Set gain
r = srp.send_cmd(srp.make_command(SET_RX_RF_GAIN, gain));
if(r.error != CMD_OK)
r = srp.send_cmd(srp.make_command(FreeSRP::SET_RX_RF_GAIN, gain));
if(r.error != FreeSRP::CMD_OK)
{
std::cerr << "Could not set RX gain, error: " << r.error << endl;
return 1;
Expand All @@ -362,8 +362,8 @@ int main(int argc, char *argv[])
if(loopback)
{
// Enable loopback
r = srp.send_cmd(srp.make_command(SET_LOOPBACK_EN, 1));
if(r.error != CMD_OK)
r = srp.send_cmd(srp.make_command(FreeSRP::SET_LOOPBACK_EN, 1));
if(r.error != FreeSRP::CMD_OK)
{
std::cerr << "Could not enable loopback mode, error: " << r.error << endl;
return 1;
Expand Down Expand Up @@ -409,8 +409,8 @@ int main(int argc, char *argv[])
if(loopback)
{
// Disable loopback
r = srp.send_cmd(srp.make_command(SET_LOOPBACK_EN, 0));
if(r.error != CMD_OK)
r = srp.send_cmd(srp.make_command(FreeSRP::SET_LOOPBACK_EN, 0));
if(r.error != FreeSRP::CMD_OK)
{
std::cerr << "Could not disable loopback mode, error: " << r.error << endl;
return 1;
Expand All @@ -421,7 +421,7 @@ int main(int argc, char *argv[])

return 0;
}
catch(const ConnectionError &e)
catch(const FreeSRP::ConnectionError &e)
{
cerr << "Could not connect to FreeSRP: " << e.what() << endl;
}
Expand All @@ -431,7 +431,7 @@ int main(int argc, char *argv[])
}

// Check for FX3
if(Util::find_fx3())
if(FreeSRP::Util::find_fx3())
{
cerr << "NOTE: Found a Cypress EZ-USB FX3 device. This could be a FreeSRP in bootloader mode.\n"
"You can upload the FreeSRP firmware to it by running 'freesrp-ctl --fx3=/path/to/firmware.img'" << endl;
Expand Down
25 changes: 12 additions & 13 deletions src/freesrp_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
#define FREESRP_SERIAL_DSCR_INDEX 3
#define MAX_SERIAL_LENGTH 256

using namespace FreeSRP;

moodycamel::ReaderWriterQueue<sample> FreeSRP::FreeSRP::impl::_rx_buf(FREESRP_RX_TX_QUEUE_SIZE);
moodycamel::ReaderWriterQueue<sample> FreeSRP::FreeSRP::impl::_tx_buf(FREESRP_RX_TX_QUEUE_SIZE);
std::vector<sample> FreeSRP::FreeSRP::impl::_rx_decoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE);
std::function<void(const std::vector<sample> &)> FreeSRP::FreeSRP::impl::_rx_custom_callback;
std::vector<sample> FreeSRP::FreeSRP::impl::_tx_encoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE);
std::function<void(std::vector<sample> &)> FreeSRP::FreeSRP::impl::_tx_custom_callback;
moodycamel::ReaderWriterQueue<FreeSRP::sample> FreeSRP::FreeSRP::impl::_rx_buf(FREESRP_RX_TX_QUEUE_SIZE);
moodycamel::ReaderWriterQueue<FreeSRP::sample> FreeSRP::FreeSRP::impl::_tx_buf(FREESRP_RX_TX_QUEUE_SIZE);
std::vector<FreeSRP::sample> FreeSRP::FreeSRP::impl::_rx_decoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE);
std::function<void(const std::vector<FreeSRP::sample> &)> FreeSRP::FreeSRP::impl::_rx_custom_callback;
std::vector<FreeSRP::sample> FreeSRP::FreeSRP::impl::_tx_encoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE);
std::function<void(std::vector<FreeSRP::sample> &)> FreeSRP::FreeSRP::impl::_tx_custom_callback;

FreeSRP::FreeSRP::impl::impl(std::string serial_number)
{
Expand Down Expand Up @@ -264,7 +263,7 @@ bool FreeSRP::FreeSRP::impl::fpga_loaded()
return fpga_load_success;
}

fpga_status FreeSRP::FreeSRP::impl::load_fpga(std::string filename)
FreeSRP::fpga_status FreeSRP::FreeSRP::impl::load_fpga(std::string filename)
{
if(fpga_loaded())
{
Expand Down Expand Up @@ -331,7 +330,7 @@ fpga_status FreeSRP::FreeSRP::impl::load_fpga(std::string filename)
}
}

std::shared_ptr<rx_tx_buf> FreeSRP::FreeSRP::impl::rx()
std::shared_ptr<FreeSRP::rx_tx_buf> FreeSRP::FreeSRP::impl::rx()
{
int transferred;
std::shared_ptr<rx_tx_buf> rx_buf = std::make_shared<rx_tx_buf>();
Expand Down Expand Up @@ -648,7 +647,7 @@ bool FreeSRP::FreeSRP::impl::submit_tx_sample(sample &s)
return _tx_buf.try_enqueue(s);
}

command FreeSRP::FreeSRP::impl::make_command(command_id id, double param) const
FreeSRP::command FreeSRP::FreeSRP::impl::make_command(command_id id, double param) const
{
command cmd;

Expand Down Expand Up @@ -740,9 +739,9 @@ command FreeSRP::FreeSRP::impl::make_command(command_id id, double param) const
return cmd;
}

response FreeSRP::FreeSRP::impl::send_cmd(command cmd) const
FreeSRP::response FreeSRP::FreeSRP::impl::send_cmd(command cmd) const
{
cmd_buf tx_buf{cmd.cmd, 1};
cmd_buf tx_buf{static_cast<unsigned char>(cmd.cmd), 1};
memcpy(tx_buf.data() + 2, &cmd.param, sizeof(cmd.param));

// Interrupt OUT transfer
Expand Down Expand Up @@ -770,7 +769,7 @@ response FreeSRP::FreeSRP::impl::send_cmd(command cmd) const
return res;
}

freesrp_version FreeSRP::FreeSRP::impl::version()
FreeSRP::freesrp_version FreeSRP::FreeSRP::impl::version()
{
response res = send_cmd({GET_FPGA_VERSION});
uint8_t fpga_major_version = ((uint8_t*) &res.param)[0];
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void ram_write(libusb_device_handle *fx3_handle, unsigned char *buf, unsigned in
}
}

bool FreeSRP::Util::find_fx3(bool upload_firmware, std::string filename)
bool Util::find_fx3(bool upload_firmware, std::string filename)
{
// TODO: This is UGLY! Clean up

Expand Down