| 10 | } |
| 11 | |
| 12 | void Knight::read_thread () |
| 13 | { |
| 14 | /* |
| 15 | [0] 1 Byte: Start byte |
| 16 | [1] 2 Byte: Sample Number |
| 17 | [2-3] 3-4 Bytes: EXG channel 1 |
| 18 | [4-5] 5-6 Bytes: Data value for EXG channel 2 |
| 19 | [6-7] 7-8 Bytes: Data value for EXG channel 3 |
| 20 | [8-9] 9-10 Bytes: Data value for EXG channel 4 |
| 21 | [10-11] 11-12 Bytes: Data value for EXG channel 5 |
| 22 | [12-13] 13-14 Bytes: Data value for EXG channel 6 |
| 23 | [14-15] 15-16 Bytes: Data value for EXG channel 7 |
| 24 | [16-17] 17-18 Bytes: Data value for EXG channel 8 |
| 25 | [18] 19 Byte: Data LOFF STATP |
| 26 | [19] 20 Byte: Data LOFF STATN |
| 27 | [20] 21 Byte: End byte |
| 28 | */ |
| 29 | |
| 30 | int res; |
| 31 | unsigned char b[20] = {0}; |
| 32 | float eeg_scale = 4 / float ((pow (2, 15) - 1)) / 12 * 1000000.; |
| 33 | int num_rows = board_descr["default"]["num_rows"]; |
| 34 | double *package = new double[num_rows]; |
| 35 | for (int i = 0; i < num_rows; i++) |
| 36 | { |
| 37 | package[i] = 0.0; |
| 38 | } |
| 39 | bool first_package_received = false; |
| 40 | |
| 41 | std::vector<int> eeg_channels = board_descr["default"]["eeg_channels"]; |
| 42 | std::vector<int> other_channels = board_descr["default"]["other_channels"]; |
| 43 | |
| 44 | while (keep_alive) |
| 45 | { |
| 46 | // checking the start byte |
| 47 | res = serial->read_from_serial_port (b, 1); |
| 48 | if (res != 1) |
| 49 | { |
| 50 | safe_logger (spdlog::level::debug, "unable to read 1 byte, {}"); |
| 51 | continue; |
| 52 | } |
| 53 | if (b[0] != KnightBase::start_byte) |
| 54 | { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | int remaining_bytes = 20; |
| 59 | int pos = 0; |
| 60 | while ((remaining_bytes > 0) && (keep_alive)) |
| 61 | { |
| 62 | res = serial->read_from_serial_port (b + pos, remaining_bytes); |
| 63 | remaining_bytes -= res; |
| 64 | pos += res; |
| 65 | } |
| 66 | |
| 67 | if (!keep_alive) |
| 68 | { |
| 69 | break; |
no test coverage detected