Skip to content

Commit

Permalink
Merge remote-tracking branch 'openbci/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey1994 committed Mar 3, 2020
2 parents 80ce88c + 5b7f744 commit 03e720b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/board_controller/openbci/inc/novaxr.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class NovaXR : public Board
std::mutex m;
std::condition_variable cv;
volatile int state;
volatile double start_time;
void read_thread ();

public:
Expand Down
9 changes: 7 additions & 2 deletions src/board_controller/openbci/novaxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "custom_cast.h"
#include "novaxr.h"
#include "openbci_helpers.h"
#include "timestamp.h"

#ifndef _WIN32
#include <errno.h>
Expand All @@ -21,6 +22,7 @@ NovaXR::NovaXR (struct BrainFlowInputParams params) : Board ((int)NOVAXR_BOARD,
this->is_streaming = false;
this->keep_alive = false;
this->initialized = false;
this->start_time = 0.0;
this->state = SYNC_TIMEOUT_ERROR;
}

Expand Down Expand Up @@ -137,6 +139,7 @@ int NovaXR::start_stream (int buffer_size, char *streamer_params)
safe_logger (spdlog::level::err, "Failed to send a command to board");
return BOARD_WRITE_ERROR;
}
start_time = get_timestamp ();

keep_alive = true;
streaming_thread = std::thread ([this] { this->read_thread (); });
Expand Down Expand Up @@ -312,8 +315,10 @@ void NovaXR::read_thread ()
package[19] = temperature / 100.0; // temperature
package[20] = (double)b[53 + offset]; // battery level

double timestamp;
memcpy (&timestamp, b + 64 + offset, 8);
double timestamp_device;
memcpy (&timestamp_device, b + 64 + offset, 8);
timestamp_device /= 1e6; // convert usec to sec
double timestamp = timestamp_device + start_time;
streamer->stream_data (package, NovaXR::num_channels, timestamp);
db->add_data (timestamp, package);
}
Expand Down
12 changes: 10 additions & 2 deletions tests/python/hardware_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,20 @@ def main ():
for ch in emg_channels:
if ch not in total_channels:
total_channels.append (ch)
total_channels.append (timestamp_channel)

columns = list ()
for i in range (len (total_channels) - 1):
columns.append ('channel_%d' % i)
columns.append ('timestamp')

df = pd.DataFrame (np.transpose (data))
df[total_channels].to_csv ('selected_data_%d.csv' % i)
df.to_csv ('all_data_%d.csv' % i)
df[total_channels].plot (subplots = True)

df_to_plot = df[total_channels]
df_to_plot.columns = columns
df_to_plot.to_csv ('selected_data_%d.csv' % i)
df_to_plot.plot (subplots = True, x = 'timestamp', style = '.-')
plt.show ()
finally:
# release session in the end
Expand Down

0 comments on commit 03e720b

Please sign in to comment.