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

Method read_thread

src/board_controller/openbci/cyton_wifi.cpp:44–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void CytonWifi::read_thread ()
45{
46 /*
47 Byte 1: 0xA0
48 Byte 2: Sample Number
49 Bytes 3-5: Data value for EEG channel 1
50 Bytes 6-8: Data value for EEG channel 2
51 Bytes 9-11: Data value for EEG channel 3
52 Bytes 12-14: Data value for EEG channel 4
53 Bytes 15-17: Data value for EEG channel 5
54 Bytes 18-20: Data value for EEG channel 6
55 Bytes 21-23: Data value for EEG channel 6
56 Bytes 24-26: Data value for EEG channel 8
57 Aux Data Bytes 27-32: 6 bytes of data
58 Byte 33: 0xCX where X is 0-F in hex
59 */
60 int res;
61 unsigned char b[OpenBCIWifiShieldBoard::package_size];
62 double accel[3] = {0.};
63 int num_rows = board_descr["default"]["num_rows"];
64 double *package = new double[num_rows];
65 for (int i = 0; i < num_rows; i++)
66 {
67 package[i] = 0.0;
68 }
69 std::vector<int> eeg_channels = board_descr["default"]["eeg_channels"];
70 double accel_scale = (double)(0.002 / (pow (2, 4)));
71
72 while (keep_alive)
73 {
74 // check start byte
75 res = server_socket->recv (b, OpenBCIWifiShieldBoard::package_size);
76 if (res != OpenBCIWifiShieldBoard::package_size)
77 {
78 if (res < 0)
79 {
80#ifdef _WIN32
81 safe_logger (spdlog::level::warn, "WSAGetLastError is {}", WSAGetLastError ());
82#else
83 safe_logger (spdlog::level::warn, "errno {} message {}", errno, strerror (errno));
84#endif
85 }
86
87 continue;
88 }
89
90 if (b[0] != START_BYTE)
91 {
92 continue;
93 }
94 unsigned char *bytes = b + 1; // for better consistency between plain cyton and wifi, in
95 // plain cyton index is shifted by 1
96
97 if ((bytes[31] < END_BYTE_STANDARD) || (bytes[31] > END_BYTE_MAX))
98 {
99 safe_logger (spdlog::level::warn, "Wrong end byte {}", bytes[31]);
100 continue;
101 }

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
recvMethod · 0.45

Tested by

no test coverage detected