@@ -71,6 +71,8 @@ AntNeuroBoard::AntNeuroBoard (int board_id, struct BrainFlowInputParams params)
7171 }
7272 reference_range = -1.0 ;
7373 bipolar_range = -1.0 ;
74+ impedance_mode = false ;
75+ impedance_package_num = -1 ;
7476}
7577
7678AntNeuroBoard::~AntNeuroBoard ()
@@ -100,6 +102,8 @@ int AntNeuroBoard::prepare_session ()
100102 {
101103 sampling_rate = amp->getSamplingRatesAvailable ()[0 ];
102104 }
105+ impedance_mode = false ;
106+ impedance_package_num = 0 ;
103107 }
104108 catch (const exceptions::notFound &e)
105109 {
@@ -143,10 +147,18 @@ int AntNeuroBoard::start_stream (int buffer_size, const char *streamer_params)
143147
144148 try
145149 {
146- safe_logger (spdlog::level::info,
147- " sampling rate: {}, reference range: {}, bipolar range: {}" , sampling_rate,
148- reference_range, bipolar_range);
149- stream = amp->OpenEegStream (sampling_rate, reference_range, bipolar_range);
150+ if (impedance_mode)
151+ {
152+ safe_logger (spdlog::level::info, " start impedance stream" );
153+ stream = amp->OpenImpedanceStream ();
154+ }
155+ else
156+ {
157+ safe_logger (spdlog::level::info,
158+ " start eeg stream (sampling rate: {}, reference range: {}, bipolar range: {})" ,
159+ sampling_rate, reference_range, bipolar_range);
160+ stream = amp->OpenEegStream (sampling_rate, reference_range, bipolar_range);
161+ }
150162 }
151163 catch (const std::runtime_error &e)
152164 {
@@ -217,6 +229,7 @@ void AntNeuroBoard::read_thread ()
217229 }
218230 std::vector<int > emg_channels;
219231 std::vector<int > eeg_channels;
232+ std::vector<int > resistance_channels;
220233 try
221234 {
222235 emg_channels = board_descr[" default" ][" emg_channels" ].get <std::vector<int >> ();
@@ -233,6 +246,15 @@ void AntNeuroBoard::read_thread ()
233246 {
234247 safe_logger (spdlog::level::trace, " device has no eeg channels" );
235248 }
249+ try
250+ {
251+ resistance_channels =
252+ board_descr[" default" ][" resistance_channels" ].get <std::vector<int >> ();
253+ }
254+ catch (...)
255+ {
256+ safe_logger (spdlog::level::trace, " device has no resistance_channels channels" );
257+ }
236258 std::vector<channel> ant_channels = stream->getChannelList ();
237259
238260 while (keep_alive)
@@ -245,17 +267,26 @@ void AntNeuroBoard::read_thread ()
245267 {
246268 int eeg_counter = 0 ;
247269 int emg_counter = 0 ;
270+ int resistance_counter = 0 ;
248271 for (int j = 0 ; j < buf_channels_len; j++)
249272 {
250273 if ((ant_channels[j].getType () == channel::reference) &&
251274 (eeg_counter < (int )eeg_channels.size ()))
252275 {
253276 package[eeg_channels[eeg_counter++]] = buf.getSample (j, i);
277+ if (impedance_mode)
278+ {
279+ resistance_counter++;
280+ }
254281 }
255282 if ((ant_channels[j].getType () == channel::bipolar) &&
256283 (emg_counter < (int )emg_channels.size ()))
257284 {
258285 package[emg_channels[emg_counter++]] = buf.getSample (j, i);
286+ if (impedance_mode)
287+ {
288+ resistance_counter++;
289+ }
259290 }
260291 if (ant_channels[j].getType () == channel::sample_counter)
261292 {
@@ -267,11 +298,32 @@ void AntNeuroBoard::read_thread ()
267298 package[board_descr[" default" ][" other_channels" ][0 ].get <int > ()] =
268299 buf.getSample (j, i);
269300 }
301+ if ((ant_channels[j].getType () == channel::impedance_reference) &&
302+ (resistance_counter < (int )resistance_channels.size ()))
303+ {
304+ package[resistance_channels[resistance_counter++]] = buf.getSample (j, i);
305+ }
306+ if ((ant_channels[j].getType () == channel::impedance_ground) &&
307+ (resistance_counter < (int )resistance_channels.size ()))
308+ {
309+ package[resistance_channels[resistance_counter++]] = buf.getSample (j, i);
310+ }
270311 }
271312 package[board_descr[" default" ][" timestamp_channel" ].get <int > ()] = get_timestamp ();
313+ if (impedance_mode)
314+ {
315+ package[board_descr[" default" ][" package_num_channel" ].get <int > ()] =
316+ impedance_package_num++;
317+ }
272318 push_package (package);
273319 }
274320 std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
321+ if (impedance_mode)
322+ {
323+ // some more sleep; twice every second should be more than enough
324+ // if left out, it yields impedances at around 64 Hz
325+ std::this_thread::sleep_for (std::chrono::milliseconds (500 ));
326+ }
275327 }
276328 catch (...)
277329 {
@@ -293,6 +345,7 @@ int AntNeuroBoard::config_board (std::string config, std::string &response)
293345 std::string prefix = " sampling_rate:" ;
294346 std::string rv_prefix = " reference_range:" ;
295347 std::string bv_prefix = " bipolar_range:" ;
348+ std::string mode_prefix = " impedance_mode:" ;
296349
297350 if (config.find (prefix) != std::string::npos)
298351 {
@@ -391,6 +444,34 @@ int AntNeuroBoard::config_board (std::string config, std::string &response)
391444
392445 return (int )BrainFlowExitCodes::STATUS_OK;
393446 }
447+ else if (config.find (mode_prefix) != std::string::npos)
448+ {
449+ bool new_impedance_mode;
450+ std::string value = config.substr (mode_prefix.size ());
451+
452+ if (value == " 0" || value == " 1" )
453+ {
454+ try
455+ {
456+ new_impedance_mode = static_cast <bool > (std::stod (value));
457+ }
458+ catch (...)
459+ {
460+ safe_logger (spdlog::level::err, " format is '{}value'" , mode_prefix.c_str ());
461+ return (int )BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
462+ }
463+
464+ impedance_mode = new_impedance_mode;
465+ return (int )BrainFlowExitCodes::STATUS_OK;
466+ }
467+ else
468+ {
469+ safe_logger (spdlog::level::err, " not supported value provided" );
470+ safe_logger (spdlog::level::debug, " supported values: '0' or '1'" );
471+ return (int )BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
472+ }
473+ }
474+
394475 safe_logger (spdlog::level::err, " format is '{}value'" , prefix.c_str ());
395476 return (int )BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
396477}
0 commit comments