diff --git a/CMakeLists.txt b/CMakeLists.txt index 7311294..bb884d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/examples/ctl/main.cpp b/examples/ctl/main.cpp index eddc65e..8de6511 100644 --- a/examples/ctl/main.cpp +++ b/examples/ctl/main.cpp @@ -27,7 +27,7 @@ #include "optionparser.hpp" using namespace std; -using namespace FreeSRP; +//using namespace FreeSRP; bool process_command(const FreeSRP::FreeSRP &srp) { @@ -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; @@ -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; @@ -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; @@ -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; } @@ -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; } diff --git a/examples/io/main.cpp b/examples/io/main.cpp index edde1db..5a81d14 100644 --- a/examples/io/main.cpp +++ b/examples/io/main.cpp @@ -35,7 +35,7 @@ #include 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[] = { @@ -65,7 +65,7 @@ void sigint_callback(int s) _interrupt.notify_all(); } -void rx_callback(const vector &samples) +void rx_callback(const vector &samples) { static vector buf; @@ -77,7 +77,7 @@ void rx_callback(const vector &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); @@ -108,7 +108,7 @@ void rx_callback(const vector &samples) } } -void tx_callback(vector &samples) +void tx_callback(vector &samples) { static vector buf; @@ -122,7 +122,7 @@ void tx_callback(vector &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); @@ -154,7 +154,7 @@ void tx_callback(vector &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!"); @@ -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!"); @@ -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; } @@ -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; @@ -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; @@ -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; @@ -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; } @@ -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; diff --git a/src/freesrp_impl.cpp b/src/freesrp_impl.cpp index c1af9ea..402fad0 100644 --- a/src/freesrp_impl.cpp +++ b/src/freesrp_impl.cpp @@ -26,14 +26,13 @@ #define FREESRP_SERIAL_DSCR_INDEX 3 #define MAX_SERIAL_LENGTH 256 -using namespace FreeSRP; -moodycamel::ReaderWriterQueue FreeSRP::FreeSRP::impl::_rx_buf(FREESRP_RX_TX_QUEUE_SIZE); -moodycamel::ReaderWriterQueue FreeSRP::FreeSRP::impl::_tx_buf(FREESRP_RX_TX_QUEUE_SIZE); -std::vector FreeSRP::FreeSRP::impl::_rx_decoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE); -std::function &)> FreeSRP::FreeSRP::impl::_rx_custom_callback; -std::vector FreeSRP::FreeSRP::impl::_tx_encoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE); -std::function &)> FreeSRP::FreeSRP::impl::_tx_custom_callback; +moodycamel::ReaderWriterQueue FreeSRP::FreeSRP::impl::_rx_buf(FREESRP_RX_TX_QUEUE_SIZE); +moodycamel::ReaderWriterQueue FreeSRP::FreeSRP::impl::_tx_buf(FREESRP_RX_TX_QUEUE_SIZE); +std::vector FreeSRP::FreeSRP::impl::_rx_decoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE); +std::function &)> FreeSRP::FreeSRP::impl::_rx_custom_callback; +std::vector FreeSRP::FreeSRP::impl::_tx_encoder_buf(FREESRP_RX_TX_BUF_SIZE / FREESRP_BYTES_PER_SAMPLE); +std::function &)> FreeSRP::FreeSRP::impl::_tx_custom_callback; FreeSRP::FreeSRP::impl::impl(std::string serial_number) { @@ -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()) { @@ -331,7 +330,7 @@ fpga_status FreeSRP::FreeSRP::impl::load_fpga(std::string filename) } } -std::shared_ptr FreeSRP::FreeSRP::impl::rx() +std::shared_ptr FreeSRP::FreeSRP::impl::rx() { int transferred; std::shared_ptr rx_buf = std::make_shared(); @@ -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; @@ -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(cmd.cmd), 1}; memcpy(tx_buf.data() + 2, &cmd.param, sizeof(cmd.param)); // Interrupt OUT transfer @@ -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]; diff --git a/src/util.cpp b/src/util.cpp index d9d0a40..cdf3060 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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