| 730 | } |
| 731 | |
| 732 | void MuseAthena::parse_sensor_payload ( |
| 733 | uint8_t tag, uint32_t package_num, double host_timestamp, const uint8_t *data, size_t size) |
| 734 | { |
| 735 | SensorConfig config; |
| 736 | if (!get_sensor_config (tag, config)) |
| 737 | { |
| 738 | return; |
| 739 | } |
| 740 | |
| 741 | if (config.type == SensorType::UNKNOWN) |
| 742 | { |
| 743 | safe_logger (spdlog::level::trace, "Skipping unknown Athena payload tag 0x{:02x}", |
| 744 | (unsigned int)tag); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | if (config.type == SensorType::BATTERY) |
| 749 | { |
| 750 | if (size >= 2) |
| 751 | { |
| 752 | last_battery = |
| 753 | (double)cast_16bit_to_uint16_little_endian ((const unsigned char *)data) * |
| 754 | MUSE_ATHENA_BATTERY_PERCENT_SCALE_FACTOR; |
| 755 | } |
| 756 | return; |
| 757 | } |
| 758 | |
| 759 | if ((!config.variable_length) && (size < config.data_len)) |
| 760 | { |
| 761 | safe_logger (spdlog::level::warn, "Short Athena payload for tag 0x{:02x}: {}", |
| 762 | (unsigned int)tag, size); |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | if (config.type == SensorType::EEG) |
| 767 | { |
| 768 | int num_rows = board_descr["default"]["num_rows"].get<int> (); |
| 769 | std::vector<int> eeg_channels = board_descr["default"]["eeg_channels"]; |
| 770 | std::vector<int> other_channels = board_descr["default"]["other_channels"]; |
| 771 | int package_num_channel = board_descr["default"]["package_num_channel"].get<int> (); |
| 772 | int timestamp_channel = board_descr["default"]["timestamp_channel"].get<int> (); |
| 773 | |
| 774 | for (int sample = 0; sample < config.n_samples; sample++) |
| 775 | { |
| 776 | std::vector<double> package ((size_t)num_rows, 0.0); |
| 777 | package[(size_t)package_num_channel] = (double)package_num; |
| 778 | for (int channel = 0; channel < config.n_channels; channel++) |
| 779 | { |
| 780 | size_t bit_start = (size_t)(sample * config.n_channels + channel) * 14; |
| 781 | uint32_t raw = extract_lsb_bits ((const unsigned char *)data, bit_start, 14); |
| 782 | if ((size_t)channel < eeg_channels.size ()) |
| 783 | { |
| 784 | package[(size_t)eeg_channels[(size_t)channel]] = |
| 785 | (double)raw * MUSE_ATHENA_EEG_SCALE_FACTOR; |
| 786 | } |
| 787 | else |
| 788 | { |
| 789 | size_t other_channel = (size_t)channel - eeg_channels.size (); |
nothing calls this directly
no test coverage detected