Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 309852e4 authored by Myles Watson's avatar Myles Watson Committed by Automerger Merge Worker
Browse files

Merge changes I1cbc553f,I879f6b4f into main am: 241cab2a am: 16f12739

parents a1c92a0c 16f12739
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "module.h"
#include "os/handler.h"
#include "os/log.h"
#include "packet/packet_view.h"

namespace bluetooth {
namespace hci {
@@ -695,25 +696,24 @@ struct DistanceMeasurementManager::impl {
          step_channel,
          (uint16_t)result_data_structure.step_data_.size());

      // Parse data as packetView
      std::vector<uint8_t> packet_bytes = {};
      // Parse data into structs from an iterator
      auto bytes = std::make_shared<std::vector<uint8_t>>();
      if (mode == 0x02 || mode == 0x03) {
        // Add one byte for the length of Tone_PCT[k], Tone_Quality_Indicator[k]
        packet_bytes.emplace_back(num_antenna_paths + 1);
        bytes->emplace_back(num_antenna_paths + 1);
      }
      packet_bytes.reserve(packet_bytes.size() + result_data_structure.step_data_.size());
      packet_bytes.insert(
          packet_bytes.end(),
      bytes->reserve(bytes->size() + result_data_structure.step_data_.size());
      bytes->insert(
          bytes->end(),
          result_data_structure.step_data_.begin(),
          result_data_structure.step_data_.end());
      PacketView<kLittleEndian> packet_bytes_view(
          std::make_shared<std::vector<uint8_t>>(packet_bytes));
      Iterator<packet::kLittleEndian> iterator(bytes);
      switch (mode) {
        case 0: {
          if (role == CsRole::INITIATOR) {
            LeCsMode0InitatorData tone_data_view;
            auto after = LeCsMode0InitatorData::Parse(&tone_data_view, packet_bytes_view.begin());
            if (after == packet_bytes_view.begin()) {
            auto after = LeCsMode0InitatorData::Parse(&tone_data_view, iterator);
            if (after == iterator) {
              LOG_WARN("Received invalid mode %d data, role:%s", mode, CsRoleText(role).c_str());
              print_raw_data(result_data_structure.step_data_);
              continue;
@@ -722,8 +722,8 @@ struct DistanceMeasurementManager::impl {
            procedure_data.measured_freq_offset.push_back(tone_data_view.measured_freq_offset_);
          } else {
            LeCsMode0ReflectorData tone_data_view;
            auto after = LeCsMode0ReflectorData::Parse(&tone_data_view, packet_bytes_view.begin());
            if (after == packet_bytes_view.begin()) {
            auto after = LeCsMode0ReflectorData::Parse(&tone_data_view, iterator);
            if (after == iterator) {
              LOG_WARN("Received invalid mode %d data, role:%s", mode, CsRoleText(role).c_str());
              print_raw_data(result_data_structure.step_data_);
              continue;
@@ -733,8 +733,8 @@ struct DistanceMeasurementManager::impl {
        } break;
        case 2: {
          LeCsMode2Data tone_data_view;
          auto after = LeCsMode2Data::Parse(&tone_data_view, packet_bytes_view.begin());
          if (after == packet_bytes_view.begin()) {
          auto after = LeCsMode2Data::Parse(&tone_data_view, iterator);
          if (after == iterator) {
            LOG_WARN("Received invalid mode %d data, role:%s", mode, CsRoleText(role).c_str());
            print_raw_data(result_data_structure.step_data_);
            continue;
+8 −0
Original line number Diff line number Diff line
@@ -32,6 +32,14 @@ Iterator<little_endian>::Iterator(const std::forward_list<View>& data, size_t of
  }
}

template <bool little_endian>
Iterator<little_endian>::Iterator(std::shared_ptr<std::vector<uint8_t>> data) {
  data_.emplace_front(data, 0, data->size());
  index_ = 0;
  begin_ = 0;
  end_ = data_.front().size();
}

template <bool little_endian>
Iterator<little_endian> Iterator<little_endian>::operator+(int offset) const {
  auto itr(*this);
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ template <bool little_endian>
class Iterator : public IteratorTraits {
 public:
  Iterator(const std::forward_list<View>& data, size_t offset);
  Iterator(std::shared_ptr<std::vector<uint8_t>> data);
  Iterator(const Iterator& itr) = default;
  virtual ~Iterator() = default;

+11 −0
Original line number Diff line number Diff line
@@ -17,10 +17,12 @@
#include "packet/packet_view.h"

#include <gtest/gtest.h>

#include <forward_list>
#include <memory>

#include "hci/address.h"
#include "packet/iterator.h"

using bluetooth::hci::Address;
using bluetooth::packet::PacketView;
@@ -399,6 +401,15 @@ TYPED_TEST(IteratorTest, subrangeTest) {
  ASSERT_EQ(*(subrange), this->packet->size() - 1);
}

TYPED_TEST(IteratorTest, constructor_from_shared_vector_test) {
  auto iterator = this->packet->begin();
  Iterator<kLittleEndian> another(std::make_shared<std::vector<uint8_t>>(count_all));
  ASSERT_EQ(iterator.NumBytesRemaining(), another.NumBytesRemaining());
  for (size_t i = 0; i < count_all.size(); i++) {
    ASSERT_EQ(iterator.template extract<uint8_t>(), another.extract<uint8_t>());
  }
}

using SubviewTestParam = std::pair<size_t, size_t>;
class SubviewBaseTest : public ::testing::TestWithParam<SubviewTestParam> {
 public: