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

Method read_thread

src/board_controller/enophone/enophone.cpp:101–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101void Enophone::read_thread ()
102{
103 int num_rows = board_descr["default"]["num_rows"];
104 double *package = new double[num_rows];
105 for (int i = 0; i < num_rows; i++)
106 {
107 package[i] = 0.0;
108 }
109 constexpr int buf_size = 20;
110 char temp_buffer[buf_size];
111 for (int i = 0; i < buf_size; i++)
112 {
113 temp_buffer[i] = 0;
114 }
115
116 while (keep_alive)
117 {
118 bool is_ready = false;
119 // check first byte is 'b'
120 int res = bluetooth_get_data (temp_buffer, 1);
121 if ((res != 1) || (temp_buffer[0] != 'b'))
122 {
123 continue;
124 }
125 double timestamp = get_timestamp ();
126 // notify main thread that 1st byte received
127 if (state != (int)BrainFlowExitCodes::STATUS_OK)
128 {
129 {
130 std::lock_guard<std::mutex> lk (m);
131 state = (int)BrainFlowExitCodes::STATUS_OK;
132 }
133 cv.notify_one ();
134 safe_logger (spdlog::level::debug, "start streaming");
135 }
136
137 // check second byte is 'S'
138 while ((keep_alive) && (res >= 0))
139 {
140 res = bluetooth_get_data (temp_buffer + 1, 1);
141 if (res == 1)
142 {
143 if (temp_buffer[1] == 'S')
144 {
145 is_ready = true;
146 }
147 break;
148 }
149 }
150
151 // first two bytes received, ready to read data bytes
152 if (is_ready)
153 {
154 while ((keep_alive) && (res >= 0))
155 {
156 res = bluetooth_get_data (temp_buffer + 2, buf_size - 2);
157 if (res == buf_size - 2)
158 {

Callers 1

start_streamMethod · 0.95

Calls 3

bluetooth_get_dataFunction · 0.85
get_timestampFunction · 0.85
swap_endiansFunction · 0.85

Tested by

no test coverage detected