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

Method read_thread

src/board_controller/openbci/cyton_daisy.cpp:29–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29void CytonDaisy::read_thread ()
30{
31 // format is the same as for cyton but need to join two packages together
32 /*
33 Byte 1: 0xA0
34 Byte 2: Sample Number
35 Bytes 3-5: Data value for EEG channel 1
36 Bytes 6-8: Data value for EEG channel 2
37 Bytes 9-11: Data value for EEG channel 3
38 Bytes 12-14: Data value for EEG channel 4
39 Bytes 15-17: Data value for EEG channel 5
40 Bytes 18-20: Data value for EEG channel 6
41 Bytes 21-23: Data value for EEG channel 6
42 Bytes 24-26: Data value for EEG channel 8
43 Aux Data Bytes 27-32: 6 bytes of data
44 Byte 33: 0xCX where X is 0-F in hex
45 */
46 int res;
47 unsigned char b[32];
48 bool first_sample = true;
49 double accel[3] = {0.};
50 double *package = new double[board_descr["default"]["num_rows"].get<int> ()];
51 for (int i = 0; i < board_descr["default"]["num_rows"].get<int> (); i++)
52 {
53 package[i] = 0.0;
54 }
55 double accel_scale = (double)(0.002 / (pow (2, 4)));
56
57 while (keep_alive)
58 {
59 // check start byte
60 res = serial->read_from_serial_port (b, 1);
61 if (res != 1)
62 {
63 safe_logger (spdlog::level::debug, "unable to read 1 byte");
64 continue;
65 }
66 if (b[0] != START_BYTE)
67 {
68 continue;
69 }
70
71 int remaining_bytes = 32;
72 int pos = 0;
73 while ((remaining_bytes > 0) && (keep_alive))
74 {
75 res = serial->read_from_serial_port (b + pos, remaining_bytes);
76 remaining_bytes -= res;
77 pos += res;
78 }
79 if (!keep_alive)
80 {
81 break;
82 }
83
84 if ((b[31] < END_BYTE_STANDARD) || (b[31] > END_BYTE_MAX))
85 {
86 safe_logger (spdlog::level::warn, "Wrong end byte {}", b[31]);

Callers

nothing calls this directly

Calls 5

cast_24bit_to_int32Function · 0.85
cast_16bit_to_int32Function · 0.85
get_timestampFunction · 0.85
get_gain_for_channelMethod · 0.80
read_from_serial_portMethod · 0.45

Tested by

no test coverage detected