From 307f5d5a31c4717eb5640a3da9606eeae935c082 Mon Sep 17 00:00:00 2001 From: Zach Johnson Date: Thu, 12 Nov 2020 19:52:55 -0800 Subject: [PATCH] Simplify DirectHciTest send_hal_acl_data first step towards more general code Bug: 171749953 Tag: #gd-refactor Test: gd/cert/run --host Change-Id: I4957acd5868f4d079fdffb255df16200e919429b --- gd/hci/cert/direct_hci_test.py | 12 ++++-------- gd/packet/python3_module.cc | 3 +++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gd/hci/cert/direct_hci_test.py b/gd/hci/cert/direct_hci_test.py index 0ef17e56a..8db76a055 100644 --- a/gd/hci/cert/direct_hci_test.py +++ b/gd/hci/cert/direct_hci_test.py @@ -74,6 +74,8 @@ from bluetooth_packets_python3.hci_packets import PacketBoundaryFlag from bluetooth_packets_python3.hci_packets import ResetBuilder from bluetooth_packets_python3.hci_packets import Lap from bluetooth_packets_python3.hci_packets import OpCode +from bluetooth_packets_python3.hci_packets import AclPacketBuilder +from bluetooth_packets_python3 import RawBuilder class DirectHciTest(GdBaseTestClass): @@ -98,14 +100,8 @@ class DirectHciTest(GdBaseTestClass): self.dut.hci.SendAcl(acl_msg) def send_hal_acl_data(self, handle, pb_flag, b_flag, acl): - lower = handle & 0xff - upper = (handle >> 8) & 0xf - upper = upper | int(pb_flag) & 0x3 - upper = upper | ((int(b_flag) & 0x3) << 2) - lower_length = len(acl) & 0xff - upper_length = (len(acl) & 0xff00) >> 8 - concatenated = bytes([lower, upper, lower_length, upper_length] + list(acl)) - self.cert_hal.send_acl(concatenated) + acl_msg = AclPacketBuilder(handle, pb_flag, b_flag, RawBuilder(acl)) + self.cert_hal.send_acl(acl_msg.Serialize()) def test_local_hci_cmd_and_event(self): # Loopback mode responds with ACL and SCO connection complete diff --git a/gd/packet/python3_module.cc b/gd/packet/python3_module.cc index c7f3f5772..11c24c01c 100644 --- a/gd/packet/python3_module.cc +++ b/gd/packet/python3_module.cc @@ -65,6 +65,9 @@ PYBIND11_MODULE(bluetooth_packets_python3, m) { py::class_>(m, "BasePacketBuilder"); py::class_>(m, "RawBuilder") .def(py::init([](std::vector bytes) { return std::make_unique(bytes); })) + .def(py::init([](std::string bytes) { + return std::make_unique(std::vector(bytes.begin(), bytes.end())); + })) .def("Serialize", [](RawBuilder& builder) { std::vector packet; BitInserter it(packet); -- 2.11.0