kopia lustrzana https://github.com/cariboulabs/cariboulite
example fixed
rodzic
1b34c568ff
commit
ffbd7afee8
|
@ -12,4 +12,4 @@ add_executable(test_app main.cpp)
|
||||||
target_include_directories(test_app PRIVATE ${CARIBOULITE_INCLUDE_DIRS})
|
target_include_directories(test_app PRIVATE ${CARIBOULITE_INCLUDE_DIRS})
|
||||||
|
|
||||||
# Link against the cariboulite library
|
# Link against the cariboulite library
|
||||||
target_link_libraries(test_app PRIVATE ${CARIBOULITE_LIBRARIES} -lcariboulite)
|
target_link_libraries(test_app PRIVATE ${CARIBOULITE_LIBRARIES} -lcariboulite pthread)
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
return size() >= length;
|
return size() >= length;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (size() < length)
|
if (size() == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ typedef enum
|
||||||
{
|
{
|
||||||
app_state_setup = 0,
|
app_state_setup = 0,
|
||||||
app_state_sampling = 1,
|
app_state_sampling = 1,
|
||||||
app_state_sleaping = 2,
|
app_state_sleeping = 2,
|
||||||
} appState_en;
|
} appState_en;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -42,8 +42,8 @@ typedef struct
|
||||||
bool requested_to_quit;
|
bool requested_to_quit;
|
||||||
|
|
||||||
// buffers & threads
|
// buffers & threads
|
||||||
circular_buffer<std::complex<float>> rx_fifo;
|
circular_buffer<std::complex<float>> *rx_fifo;
|
||||||
thread *dsp_thread;
|
std::thread *dsp_thread;
|
||||||
} appContext_st;
|
} appContext_st;
|
||||||
|
|
||||||
static appContext_st app = {0};
|
static appContext_st app = {0};
|
||||||
|
@ -116,7 +116,7 @@ float RSSI(const std::complex<float>* signal, size_t num_of_samples)
|
||||||
return 10 * log10(mean_of_squares);
|
return 10 * log10(mean_of_squares);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consumer thread
|
// Consumer (parallel DSP) thread
|
||||||
void dataConsumerThread(appContext_st* app)
|
void dataConsumerThread(appContext_st* app)
|
||||||
{
|
{
|
||||||
std::cout << "Data consumer thread started" << std::endl;
|
std::cout << "Data consumer thread started" << std::endl;
|
||||||
|
@ -126,14 +126,21 @@ void dataConsumerThread(appContext_st* app)
|
||||||
while (app->running)
|
while (app->running)
|
||||||
{
|
{
|
||||||
// get the number of elements in the fifo
|
// get the number of elements in the fifo
|
||||||
size_t num_lements = app.rx_fifo.size();
|
size_t num_lements = app->rx_fifo->size();
|
||||||
if (num_lements == 0)
|
if (num_lements == 0)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50))
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.rx_fifo.get(local_dsp_buffer, (num_lements>(RX_CHUNK_SAMPLES*4)) ? (RX_CHUNK_SAMPLES * 4) : num_lements);
|
size_t actual_read = app->rx_fifo->get(local_dsp_buffer, (num_lements>(RX_CHUNK_SAMPLES*4)) ? (RX_CHUNK_SAMPLES * 4) : num_lements);
|
||||||
|
if (actual_read)
|
||||||
|
{
|
||||||
|
// here goes the DSP
|
||||||
|
app->num_samples_read_so_far += actual_read;
|
||||||
|
float rssi = RSSI(local_dsp_buffer, actual_read);
|
||||||
|
printf("DSP EPOCH: %ld, NUM_READ: %ld, RSSI: %.3f\n", app->epoch, app->num_samples_read_so_far, rssi);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Data consumer thread exitting" << std::endl;
|
std::cout << "Data consumer thread exitting" << std::endl;
|
||||||
|
@ -152,11 +159,12 @@ void receivedSamples(CaribouLiteRadio* radio, const std::complex<float>* samples
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
// push the received samples in the fifo
|
// push the received samples in the fifo
|
||||||
app.rx_fifo.put(samples, num_samples);
|
app.rx_fifo->put(samples, num_samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==========================================================================================
|
||||||
// Main entry
|
// A simple asynchronous DSP flow
|
||||||
|
// ==========================================================================================
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
// try detecting the board before getting the instance
|
// try detecting the board before getting the instance
|
||||||
|
@ -188,6 +196,7 @@ int main ()
|
||||||
{
|
{
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
case app_state_setup:
|
case app_state_setup:
|
||||||
|
std::cout << "Starting Epoch " << app.epoch << std::endl;
|
||||||
// an example periodic radio setup stage
|
// an example periodic radio setup stage
|
||||||
app.radio->SetRxGain(app.gain);
|
app.radio->SetRxGain(app.gain);
|
||||||
app.radio->SetFrequency(app.freq);
|
app.radio->SetFrequency(app.freq);
|
||||||
|
@ -212,7 +221,10 @@ int main ()
|
||||||
case app_state_sleeping:
|
case app_state_sleeping:
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_BETWEEN_EPOCHS * 1000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_BETWEEN_EPOCHS * 1000));
|
||||||
app.epoch ++;
|
app.epoch ++;
|
||||||
|
|
||||||
|
// reset the fifo
|
||||||
|
app.rx_fifo->reset();
|
||||||
|
|
||||||
// either go the next epoch or quit the program
|
// either go the next epoch or quit the program
|
||||||
// this is an example flow but other possibilities exist
|
// this is an example flow but other possibilities exist
|
||||||
if (!app.requested_to_quit) app.state = app_state_setup;
|
if (!app.requested_to_quit) app.state = app_state_setup;
|
||||||
|
|
Ładowanie…
Reference in New Issue