Skip to content

Commit

Permalink
[WIP] Solving Issue #516 (#550)
Browse files Browse the repository at this point in the history
* add multiple streamers per preset

Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
Co-authored-by: Romain Chaumontet <romain.chaumontet@unikie.com>
Co-authored-by: Andrey Parfenov <a1994ndrey@gmail.com>
  • Loading branch information
3 people committed Oct 9, 2022
1 parent 7f32586 commit e826aa8
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ jobs:
run: valgrind --error-exitcode=1 --track-origins=yes --leak-check=full $GITHUB_WORKSPACE/cpp_package/examples/signal_processing/build/band_power
env:
LD_LIBRARY_PATH: $GITHUB_WORKSPACE/installed/lib
- name: Multiple Streamers
run: valgrind --error-exitcode=1 --track-origins=yes --leak-check=full $GITHUB_WORKSPACE/cpp_package/examples/get_data/build/multiple_streamers
env:
LD_LIBRARY_PATH: $GITHUB_WORKSPACE/installed/lib
22 changes: 21 additions & 1 deletion cpp_package/examples/get_data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,24 @@ target_link_libraries (
${MLModulePath}
${DataHandlerPath}
${BoardControllerPath}
)
)


add_executable (
multiple_streamers
src/multiple_streamers.cpp
)

target_include_directories (
multiple_streamers PUBLIC
${brainflow_INCLUDE_DIRS}
)

target_link_libraries (
multiple_streamers PUBLIC
# for some systems(ubuntu for example) order matters
${BrainflowPath}
${MLModulePath}
${DataHandlerPath}
${BoardControllerPath}
)
57 changes: 57 additions & 0 deletions cpp_package/examples/get_data/src/multiple_streamers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <iostream>
#include <stdlib.h>
#include <string>

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

#include "board_shim.h"


int main (int argc, char *argv[])
{
BoardShim::enable_dev_board_logger ();

struct BrainFlowInputParams params;
int board_id = (int)BoardIds::SYNTHETIC_BOARD;
int res = 0;

BoardShim *board = new BoardShim (board_id, params);

try
{
board->prepare_session ();
board->add_streamer ("file://streamer_default_1.csv:w");
board->add_streamer ("file://streamer_default_2.csv:w");
board->add_streamer (
"file://streamer_aux_1.csv:w", (int)BrainFlowPresets::AUXILIARY_PRESET);
board->add_streamer (
"file://streamer_aux_2.csv:w", (int)BrainFlowPresets::AUXILIARY_PRESET);
board->start_stream ();

#ifdef _WIN32
Sleep (5000);
#else
sleep (5);
#endif

board->stop_stream ();
board->release_session ();
}
catch (const BrainFlowException &err)
{
BoardShim::log_message ((int)LogLevels::LEVEL_ERROR, err.what ());
res = err.exit_code;
if (board->is_prepared ())
{
board->release_session ();
}
}

delete board;

return res;
}
18 changes: 10 additions & 8 deletions src/board_controller/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ void Board::push_package (double *package, int preset)
}
if (streamers.find (preset) != streamers.end ())
{
streamers[preset]->stream_data (package);
for (auto &streamer : streamers[preset])
{
streamer->stream_data (package);
}
}
lock.unlock ();
}
Expand Down Expand Up @@ -233,7 +236,10 @@ void Board::free_packages ()
for (auto it = streamers.begin (), next_it = it; it != streamers.end (); it = next_it)
{
++next_it;
delete it->second;
for (auto &streamer : it->second)
{
delete streamer;
}
streamers.erase (it);
}
}
Expand All @@ -251,11 +257,7 @@ int Board::add_streamer (const char *streamer_params, int preset)
safe_logger (spdlog::level::err, "invalid preset");
return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
}
if (streamers.find (preset) != streamers.end ())
{
safe_logger (spdlog::level::err, "only one streamer per preset is currently supported");
return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR;
}

int num_rows = (int)board_descr[preset_str]["num_rows"];

Streamer *streamer = NULL;
Expand Down Expand Up @@ -317,7 +319,7 @@ int Board::add_streamer (const char *streamer_params, int preset)
else
{
lock.lock ();
streamers[preset] = streamer;
streamers[preset].push_back (streamer);
lock.unlock ();
}

Expand Down
2 changes: 1 addition & 1 deletion src/board_controller/inc/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Board

protected:
std::map<int, DataBuffer *> dbs;
std::map<int, Streamer *> streamers; // todo convert to map<int, vector>
std::map<int, std::vector<Streamer *>> streamers;
bool skip_logs;
int board_id;
struct BrainFlowInputParams params;
Expand Down
1 change: 1 addition & 0 deletions src/board_controller/inc/streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Streamer
{
this->len = len;
}

virtual ~Streamer ()
{
}
Expand Down

0 comments on commit e826aa8

Please sign in to comment.