MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / thread_worker

Method thread_worker

src/board_controller/plotjuggler_udp_streamer.cpp:81–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void PlotJugglerUDPStreamer::thread_worker ()
82{
83 double *transaction = new double[len];
84 for (int i = 0; i < len; i++)
85 {
86 transaction[i] = 0.0;
87 }
88 std::string name = preset_descr["name"];
89 while (is_streaming)
90 {
91 if (db->get_data_count () >= 1)
92 {
93 db->get_data (1, transaction);
94 json j;
95 j[name] = json::object ();
96 for (auto &el : preset_descr.items ())
97 {
98 std::string key = el.key ();
99 if (key.find ("_channels") != std::string::npos)
100 {
101 std::string prefix = remove_substr (key, "_channels");
102 j[name][prefix] = json::object ();
103 std::vector<int> values = el.value ();
104 for (int i = 0; i < (int)values.size (); i++)
105 {
106 std::string channel_name = "channel " + std::to_string (i);
107 if ((key == "accel_channels") && (i == 0))
108 channel_name = "accel X";
109 if ((key == "accel_channels") && (i == 1))
110 channel_name = "accel Y";
111 if ((key == "accel_channels") && (i == 2))
112 channel_name = "accel Z";
113 if (key == "eeg_channels")
114 {
115 try
116 {
117 std::string eeg_names = preset_descr["eeg_names"];
118 std::vector<std::string> names_vec;
119 std::stringstream ss (eeg_names);
120 while (ss.good ())
121 {
122 std::string substr;
123 std::getline (ss, substr, ',');
124 names_vec.push_back (substr);
125 }
126 channel_name = names_vec[i];
127 }
128 catch (...)
129 {
130 }
131 }
132 if ((values[i] >= 0) && (values[i] <= len))
133 {
134 j[name][prefix][channel_name] = transaction[values[i]];
135 }
136 }
137 }
138 else if (key.find ("_channel") != std::string::npos)

Callers 1

init_streamerMethod · 0.95

Calls 3

get_data_countMethod · 0.80
get_dataMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected