diff --git a/examples/cpp/.gitignore b/examples/adsb_soapy/.gitignore similarity index 100% rename from examples/cpp/.gitignore rename to examples/adsb_soapy/.gitignore diff --git a/examples/cpp/CMakeLists.txt b/examples/adsb_soapy/CMakeLists.txt similarity index 100% rename from examples/cpp/CMakeLists.txt rename to examples/adsb_soapy/CMakeLists.txt diff --git a/examples/cpp/cpr.c b/examples/adsb_soapy/cpr.c similarity index 100% rename from examples/cpp/cpr.c rename to examples/adsb_soapy/cpr.c diff --git a/examples/cpp/cpr.h b/examples/adsb_soapy/cpr.h similarity index 100% rename from examples/cpp/cpr.h rename to examples/adsb_soapy/cpr.h diff --git a/examples/cpp/dump1090.cpp b/examples/adsb_soapy/dump1090.cpp similarity index 100% rename from examples/cpp/dump1090.cpp rename to examples/adsb_soapy/dump1090.cpp diff --git a/examples/cpp/modes.c b/examples/adsb_soapy/modes.c similarity index 100% rename from examples/cpp/modes.c rename to examples/adsb_soapy/modes.c diff --git a/examples/cpp/modes.h b/examples/adsb_soapy/modes.h similarity index 100% rename from examples/cpp/modes.h rename to examples/adsb_soapy/modes.h diff --git a/examples/c/CMakeLists.txt b/examples/c_api/CMakeLists.txt similarity index 100% rename from examples/c/CMakeLists.txt rename to examples/c_api/CMakeLists.txt diff --git a/examples/c/main.c b/examples/c_api/main.c similarity index 93% rename from examples/c/main.c rename to examples/c_api/main.c index c7d0d05..81f5dfa 100644 --- a/examples/c/main.c +++ b/examples/c_api/main.c @@ -12,30 +12,30 @@ int main () // board detection bool detected = cariboulite_detect_connected_board(&hw_ver, hw_name, hw_uuid); if (detected) printf("Detection: %d, HWVer: %d, HWName: %s, UUID: %s\n", detected, hw_ver, hw_name, hw_uuid); - else + else { printf("No board detection, Exiting\n"); return 0; } - + // library version cariboulite_get_lib_version(&version); printf("Version: %02d.%02d.%02d\n", version.major_version, version.minor_version, version.revision); - + // init - cariboulite_init(false, cariboulite_log_level_none); - + cariboulite_init(false, cariboulite_log_level_none); + // board serial number serial_number = cariboulite_get_sn(); printf("Serial Number: %08X\n", serial_number); - + // channels names and freqs char ch_name[64]; int ch_num_ranges; float low_freq_vec[3]; // the actual size determined by ch_num_ranges but here we just statically allocated float high_freq_vec[3]; int channels[2] = {cariboulite_channel_s1g, cariboulite_channel_hif}; - + for (int ch_ind = 0; ch_ind < 2; ch_ind ++) { cariboulite_get_channel_name(channels[ch_ind], ch_name, sizeof(ch_name)); @@ -43,11 +43,10 @@ int main () printf("Channel: %d, Name: %s, Num. Freq. Ranges: %d\n", channels[ch_ind], ch_name, ch_num_ranges); cariboulite_get_frequency_limits(channels[ch_ind], low_freq_vec, high_freq_vec, NULL); for (int i = 0; i < ch_num_ranges; i++) - { + { printf(" Range %d: [%.2f, %.2f]\n", i, low_freq_vec[i], high_freq_vec[i]); } } - cariboulite_close(); - return 0; + return 0; } diff --git a/examples/cpp_api/CMakeLists.txt b/examples/cpp_api/async_rx_api/CMakeLists.txt similarity index 100% rename from examples/cpp_api/CMakeLists.txt rename to examples/cpp_api/async_rx_api/CMakeLists.txt diff --git a/examples/cpp_api/main.cpp b/examples/cpp_api/async_rx_api/main.cpp similarity index 95% rename from examples/cpp_api/main.cpp rename to examples/cpp_api/async_rx_api/main.cpp index 4e22558..7a72bf8 100644 --- a/examples/cpp_api/main.cpp +++ b/examples/cpp_api/async_rx_api/main.cpp @@ -21,7 +21,7 @@ void detectBoard() CaribouLite::SysVersion ver; std::string name; std::string guid; - + if (CaribouLite::DetectBoard(&ver, name, guid)) { std::cout << "Detected Version: " << CaribouLite::GetSystemVersionStr(ver) << ", Name: " << name << ", GUID: " << guid << std::endl; @@ -29,21 +29,21 @@ void detectBoard() else { std::cout << "Undetected CaribouLite!" << std::endl; - } + } } // Calculate the RSSI float RSSI(const std::complex* signal, size_t num_of_samples) { - if (num_of_samples == 0) + if (num_of_samples == 0) { return 0.0f; } float sum_of_squares = 0.0f; - for (size_t i = 0; i < num_of_samples && i < num_of_samples; ++i) + for (size_t i = 0; i < num_of_samples && i < num_of_samples; ++i) { - float vrms = std::norm(signal[i]); + float vrms = std::norm(signal[i]); sum_of_squares += vrms * vrms / 100.0; } @@ -61,10 +61,9 @@ void receivedSamples(CaribouLiteRadio* radio, const std::complex* samples std::cout << "[" << samples[i].real() << ", " << samples[i].imag() << "]"; } std::cout << std::endl;*/ - + std::cout << "Radio: " << radio->GetRadioName() << " Received " << std::dec << num_samples << " samples" << "RSSI: " << RSSI(samples, num_samples) << " dBm" << std::endl; - } @@ -73,21 +72,21 @@ int main () { // try detecting the board before getting the instance detectBoard(); - + // get driver instance - use "CaribouLite&" rather than "CaribouLite" (ref) CaribouLite &cl = CaribouLite::GetInstance(); - + // print the info after connecting printInfo(cl); - + // get the radios CaribouLiteRadio *s1g = cl.GetRadioChannel(CaribouLiteRadio::RadioType::S1G); CaribouLiteRadio *hif = cl.GetRadioChannel(CaribouLiteRadio::RadioType::HiF); - + // write radio information std::cout << "First Radio Name: " << s1g->GetRadioName() << " MtuSize: " << std::dec << s1g->GetNativeMtuSample() << " Samples" << std::endl; std::cout << "First Radio Name: " << hif->GetRadioName() << " MtuSize: " << std::dec << hif->GetNativeMtuSample() << " Samples" << std::endl; - + std::vector range_s1g = s1g->GetFrequencyRange(); std::vector range_hif = hif->GetFrequencyRange(); std::cout << "S1G Frequency Regions:" << std::endl; @@ -95,13 +94,13 @@ int main () { std::cout << " " << i << ": " << range_s1g[i] << std::endl; } - + std::cout << "HiF Frequency Regions:" << std::endl; for (int i = 0; i < range_hif.size(); i++) { std::cout << " " << i << ": " << range_hif[i] << std::endl; } - + // start receiving until enter pressed on 900MHz int num = 2; while (num --) @@ -115,13 +114,12 @@ int main () { std::cout << "The specified freq couldn't be used" << std::endl; } - s1g->SetRxGain(0); s1g->SetAgc(false); s1g->StartReceiving(receivedSamples); getchar(); - + try { hif->SetFrequency(2400000000); @@ -134,11 +132,10 @@ int main () hif->SetRxGain(0); hif->SetAgc(false); hif->StartReceiving(receivedSamples); - + getchar(); } - hif->StopReceiving(); - + return 0; } diff --git a/examples/cpp_api/sync_rx_api/CMakeLists.txt b/examples/cpp_api/sync_rx_api/CMakeLists.txt new file mode 100644 index 0000000..7562635 --- /dev/null +++ b/examples/cpp_api/sync_rx_api/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.2) +project(test_app) + +# Find the package using pkg-config +find_package(PkgConfig REQUIRED) +pkg_check_modules(CARIBOULITE REQUIRED cariboulite) + +# Add the executable +add_executable(test_app main.cpp) + +# Include directories from the cariboulite package +target_include_directories(test_app PRIVATE ${CARIBOULITE_INCLUDE_DIRS}) + +# Link against the cariboulite library +target_link_libraries(test_app PRIVATE ${CARIBOULITE_LIBRARIES} -lcariboulite) diff --git a/examples/cpp_api/sync_rx_api/main.cpp b/examples/cpp_api/sync_rx_api/main.cpp new file mode 100644 index 0000000..267ecc0 --- /dev/null +++ b/examples/cpp_api/sync_rx_api/main.cpp @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include +#include + +// Print Board Information +void printInfo(CaribouLite& cl) +{ + std::cout << "Initialized CaribouLite: " << cl.IsInitialized() << std::endl; + std::cout << "API Versions: " << cl.GetApiVersion() << std::endl; + std::cout << "Hardware Serial Number: " << std::hex << cl.GetHwSerialNumber() << std::endl; + std::cout << "System Type: " << cl.GetSystemVersionStr() << std::endl; + std::cout << "Hardware Unique ID: " << cl.GetHwGuid() << std::endl; +} + +// Detect the board before instantiating it +void detectBoard() +{ + CaribouLite::SysVersion ver; + std::string name; + std::string guid; + + if (CaribouLite::DetectBoard(&ver, name, guid)) + { + std::cout << "Detected Version: " << CaribouLite::GetSystemVersionStr(ver) << ", Name: " << name << ", GUID: " << guid << std::endl; + } + else + { + std::cout << "Undetected CaribouLite!" << std::endl; + } +} + +// Calculate the RSSI +float RSSI(const std::complex* signal, size_t num_of_samples) +{ + if (num_of_samples == 0) + { + return 0.0f; + } + + float sum_of_squares = 0.0f; + for (size_t i = 0; i < num_of_samples; ++i) + { + float vrmsp2 = (signal[i].real() * signal[i].real()) + (signal[i].imag() * signal[i].imag()); + sum_of_squares += vrmsp2 / 100.0; + } + + float mean_of_squares = sum_of_squares / num_of_samples; + + // Convert RMS value to dBm + return 10 * log10(mean_of_squares); +} + +// Rx Callback (async) +void receivedSamples(CaribouLiteRadio* radio, const std::complex* samples, CaribouLiteMeta* sync, size_t num_samples) +{ + std::cout << "Radio: " << radio->GetRadioName() << " Received " << std::dec << num_samples << " samples" + << "RSSI: " << RSSI(samples, num_samples) << " dBm" << std::endl; + +} + + +// Main entry +int main () +{ + std::complex* samples = new std::complex[128*1024]; + + // try detecting the board before getting the instance + detectBoard(); + + // get driver instance - use "CaribouLite&" rather than "CaribouLite" (ref) + // get a "synchronous" api instance + CaribouLite &cl = CaribouLite::GetInstance(false); + + // print the info after connecting + printInfo(cl); + + // get the radios + CaribouLiteRadio *s1g = cl.GetRadioChannel(CaribouLiteRadio::RadioType::S1G); + CaribouLiteRadio *hif = cl.GetRadioChannel(CaribouLiteRadio::RadioType::HiF); + + // write radio information + std::cout << "First Radio Name: " << s1g->GetRadioName() << " MtuSize: " << std::dec << s1g->GetNativeMtuSample() << " Samples" << std::endl; + std::cout << "First Radio Name: " << hif->GetRadioName() << " MtuSize: " << std::dec << hif->GetNativeMtuSample() << " Samples" << std::endl; + + std::vector range_s1g = s1g->GetFrequencyRange(); + std::vector range_hif = hif->GetFrequencyRange(); + std::cout << "S1G Frequency Regions:" << std::endl; + for (int i = 0; i < range_s1g.size(); i++) + { + std::cout << " " << i << ": " << range_s1g[i] << std::endl; + } + + std::cout << "HiF Frequency Regions:" << std::endl; + for (int i = 0; i < range_hif.size(); i++) + { + std::cout << " " << i << ": " << range_hif[i] << std::endl; + } + + // Receive Synchrnonously + try + { + hif->SetFrequency(2490000000); + } + catch (...) + { + std::cout << "The specified freq couldn't be used" << std::endl; + } + hif->SetRxGain(69); + hif->SetAgc(false); + hif->SetRxSampleRate(4000000); + //hif->StartReceiving(); + + s1g->SetRxGain(69); + s1g->SetAgc(false); + s1g->SetRxSampleRate(2000000); + s1g->StartReceiving(); + + int num_buffers = 10; + while (num_buffers--) + { + //s1g->FlushBuffers(); + int ret = s1g->ReadSamples(samples, (1<<16)); + if (ret > 0) + { + std::cout << "Radio: " << hif->GetRadioName() << " Received " << std::dec << ret << " samples" + << "RSSI: " << RSSI(samples, ret) << " dBm" << std::endl; + std::cout << "Radio: " << s1g->GetRadioName() << " Received " << std::dec << ret << " samples" << std::endl; + } + } + + /*try + { + s1g->SetFrequency(900100000); + } + catch (...) + { + std::cout << "The specified freq couldn't be used" << std::endl; + } + s1g->SetRxGain(69); + s1g->SetRxBandwidth(2500e3); + s1g->SetAgc(false); + s1g->StartReceiving(receivedSamples);*/ + + delete []samples; + + return 0; +} diff --git a/examples/lora_receiver/CMakeLists.txt b/examples/gr_lora_receiver/CMakeLists.txt similarity index 100% rename from examples/lora_receiver/CMakeLists.txt rename to examples/gr_lora_receiver/CMakeLists.txt diff --git a/examples/lora_receiver/main.cpp b/examples/gr_lora_receiver/main.cpp similarity index 97% rename from examples/lora_receiver/main.cpp rename to examples/gr_lora_receiver/main.cpp index c14c07a..7c8cffe 100644 --- a/examples/lora_receiver/main.cpp +++ b/examples/gr_lora_receiver/main.cpp @@ -20,7 +20,7 @@ void detectBoard() CaribouLite::SysVersion ver; std::string name; std::string guid; - + if (CaribouLite::DetectBoard(&ver, name, guid)) { std::cout << "Detected Version: " << CaribouLite::GetSystemVersionStr(ver) << ", Name: " << name << ", GUID: " << guid << std::endl; @@ -28,14 +28,13 @@ void detectBoard() else { std::cout << "Undetected CaribouLite!" << std::endl; - } + } } // Rx Callback (async) void receivedSamples(CaribouLiteRadio* radio, const std::complex* samples, CaribouLiteMeta* sync, size_t num_samples) { std::cout << "Radio: " << radio->GetRadioName() << " Received " << std::dec << num_samples << " samples" << std::endl; - } @@ -44,21 +43,21 @@ int main () { // try detecting the board before getting the instance detectBoard(); - + // get driver instance - use "CaribouLite&" rather than "CaribouLite" (ref) CaribouLite &cl = CaribouLite::GetInstance(); - + // print the info after connecting printInfo(cl); - + // get the radios CaribouLiteRadio *s1g = cl.GetRadioChannel(CaribouLiteRadio::RadioType::S1G); CaribouLiteRadio *hif = cl.GetRadioChannel(CaribouLiteRadio::RadioType::HiF); - + // write radio information std::cout << "First Radio Name: " << s1g->GetRadioName() << " MtuSize: " << std::dec << s1g->GetNativeMtuSample() << " Samples" << std::endl; std::cout << "First Radio Name: " << hif->GetRadioName() << " MtuSize: " << std::dec << hif->GetNativeMtuSample() << " Samples" << std::endl; - + // start receiving until enter pressed on 900MHz s1g->SetFrequency(900000000); s1g->SetRxGain(50); @@ -66,11 +65,11 @@ int main () s1g->StartReceiving(receivedSamples); getchar(); - + hif->SetFrequency(900000000); hif->StartReceiving(receivedSamples, 20000); - + getchar(); - + return 0; } diff --git a/software/libcariboulite/src/cariboulite_util.c b/software/libcariboulite/src/cariboulite_util.c index 4b96f54..699d8dd 100644 --- a/software/libcariboulite/src/cariboulite_util.c +++ b/software/libcariboulite/src/cariboulite_util.c @@ -122,11 +122,13 @@ static void usage(void) "\t[-F force fpga reprogramming (default: '0')]\n" "\t[-M write metadata (default: '0')]\n" "\tfilename ('-' dumps samples to stdout)\n\n" - "Example:\n" - "\t1. Sample S1G channel at 905MHz into filename capture.bin\n" - "\t\tcariboulite_util -c 0 -f 905000000 capture.bin\n" - "\t2. Sample S1G channel at 905MHz into filename capture.bin, only 30000 samples\n" - "\t\tcariboulite_util -c 0 -f 905000000 -n 30000 capture.bin\n\n"); + "Example (CS16 files readable by 'inspectrum' analyzer):\n" + "\t1. Sample S1G channel at 905MHz into filename capture.cs16\n" + "\t\tcariboulite_util -c 0 -f 905000000 capture.cs16\n" + "\t2. Sample HiF channel at 2410MHz into filename capture_hif.cs16\n" + "\t\tcariboulite_util -c 1 -f 2410000000 capture_hif.cs16\n" + "\t3. Sample S1G channel at 905MHz into filename capture.cs16, only 30000 samples\n" + "\t\tcariboulite_util -c 0 -f 905000000 -n 30000 capture.cs16\n\n"); exit(1); }