Loading system/gd/Android.bp +22 −0 Original line number Original line Diff line number Diff line Loading @@ -448,6 +448,28 @@ genrule { ], ], } } genrule { name: "BluetoothGeneratedPackets_rust", tools: [ "bluetooth_packetgen", ], cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) $(in) --rust", srcs: [ "hci/hci_packets.pdl", ], out: [ "hci/hci_packets.rs", ], } rust_library { name: "libbt_packets", crate_name: "bt_packets", srcs: ["rust/packets/lib.rs", ":BluetoothGeneratedPackets_rust"], edition: "2018", host_supported: true, } // Generates binary schema data to be bundled and source file generated // Generates binary schema data to be bundled and source file generated genrule { genrule { name: "BluetoothGeneratedDumpsysBinarySchema_bfbs", name: "BluetoothGeneratedDumpsysBinarySchema_bfbs", Loading system/gd/hci/hci_packets.pdl +2 −2 Original line number Original line Diff line number Diff line Loading @@ -4622,7 +4622,7 @@ packet VendorSpecificEvent : EventPacket (event_code = VENDOR_SPECIFIC) { _payload_, _payload_, } } enum qualityReportId : 8 { enum QualityReportId : 8 { MONITOR_MODE = 0x01, MONITOR_MODE = 0x01, APPROACH_LSTO = 0x02, APPROACH_LSTO = 0x02, A2DP_AUDIO_CHOPPY = 0x03, A2DP_AUDIO_CHOPPY = 0x03, Loading @@ -4634,7 +4634,7 @@ enum qualityReportId : 8 { } } packet BqrEvent : VendorSpecificEvent (subevent_code = BQR_EVENT) { packet BqrEvent : VendorSpecificEvent (subevent_code = BQR_EVENT) { quality_report_id : qualityReportId, quality_report_id : QualityReportId, _payload_, _payload_, } } Loading system/gd/packet/parser/enum_gen.cc +8 −0 Original line number Original line Diff line number Diff line Loading @@ -59,3 +59,11 @@ void EnumGen::GenLogging(std::ostream& stream) { stream << " return os << " << e_.name_ << "Text(param);"; stream << " return os << " << e_.name_ << "Text(param);"; stream << "}\n"; stream << "}\n"; } } void EnumGen::GenRustDef(std::ostream& stream) { stream << "pub enum " << e_.name_ << " {"; for (const auto& pair : e_.constants_) { stream << util::ConstantCaseToCamelCase(pair.second) << " = 0x" << std::hex << pair.first << std::dec << ","; } stream << "}"; } system/gd/packet/parser/enum_gen.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -31,5 +31,7 @@ class EnumGen { void GenLogging(std::ostream& stream); void GenLogging(std::ostream& stream); void GenRustDef(std::ostream& stream); EnumDef e_; EnumDef e_; }; }; system/gd/packet/parser/gen_rust.cc +11 −2 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,7 @@ #include "declarations.h" #include "declarations.h" bool generate_rust_source_one_file( bool generate_rust_source_one_file( __attribute__((unused)) const Declarations& decls, const Declarations& decls, const std::filesystem::path& input_file, const std::filesystem::path& input_file, const std::filesystem::path& include_dir, const std::filesystem::path& include_dir, const std::filesystem::path& out_dir, const std::filesystem::path& out_dir, Loading @@ -43,7 +43,16 @@ bool generate_rust_source_one_file( return false; return false; } } out_file << "// @generated rust packets from " << input_file.filename().string(); out_file << "// @generated rust packets from " << input_file.filename().string() << "\n\n"; for (const auto& e : decls.type_defs_queue_) { if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) { const auto* enum_def = dynamic_cast<const EnumDef*>(e.second); EnumGen gen(*enum_def); gen.GenRustDef(out_file); out_file << "\n\n"; } } out_file.close(); out_file.close(); return true; return true; Loading Loading
system/gd/Android.bp +22 −0 Original line number Original line Diff line number Diff line Loading @@ -448,6 +448,28 @@ genrule { ], ], } } genrule { name: "BluetoothGeneratedPackets_rust", tools: [ "bluetooth_packetgen", ], cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) $(in) --rust", srcs: [ "hci/hci_packets.pdl", ], out: [ "hci/hci_packets.rs", ], } rust_library { name: "libbt_packets", crate_name: "bt_packets", srcs: ["rust/packets/lib.rs", ":BluetoothGeneratedPackets_rust"], edition: "2018", host_supported: true, } // Generates binary schema data to be bundled and source file generated // Generates binary schema data to be bundled and source file generated genrule { genrule { name: "BluetoothGeneratedDumpsysBinarySchema_bfbs", name: "BluetoothGeneratedDumpsysBinarySchema_bfbs", Loading
system/gd/hci/hci_packets.pdl +2 −2 Original line number Original line Diff line number Diff line Loading @@ -4622,7 +4622,7 @@ packet VendorSpecificEvent : EventPacket (event_code = VENDOR_SPECIFIC) { _payload_, _payload_, } } enum qualityReportId : 8 { enum QualityReportId : 8 { MONITOR_MODE = 0x01, MONITOR_MODE = 0x01, APPROACH_LSTO = 0x02, APPROACH_LSTO = 0x02, A2DP_AUDIO_CHOPPY = 0x03, A2DP_AUDIO_CHOPPY = 0x03, Loading @@ -4634,7 +4634,7 @@ enum qualityReportId : 8 { } } packet BqrEvent : VendorSpecificEvent (subevent_code = BQR_EVENT) { packet BqrEvent : VendorSpecificEvent (subevent_code = BQR_EVENT) { quality_report_id : qualityReportId, quality_report_id : QualityReportId, _payload_, _payload_, } } Loading
system/gd/packet/parser/enum_gen.cc +8 −0 Original line number Original line Diff line number Diff line Loading @@ -59,3 +59,11 @@ void EnumGen::GenLogging(std::ostream& stream) { stream << " return os << " << e_.name_ << "Text(param);"; stream << " return os << " << e_.name_ << "Text(param);"; stream << "}\n"; stream << "}\n"; } } void EnumGen::GenRustDef(std::ostream& stream) { stream << "pub enum " << e_.name_ << " {"; for (const auto& pair : e_.constants_) { stream << util::ConstantCaseToCamelCase(pair.second) << " = 0x" << std::hex << pair.first << std::dec << ","; } stream << "}"; }
system/gd/packet/parser/enum_gen.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -31,5 +31,7 @@ class EnumGen { void GenLogging(std::ostream& stream); void GenLogging(std::ostream& stream); void GenRustDef(std::ostream& stream); EnumDef e_; EnumDef e_; }; };
system/gd/packet/parser/gen_rust.cc +11 −2 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,7 @@ #include "declarations.h" #include "declarations.h" bool generate_rust_source_one_file( bool generate_rust_source_one_file( __attribute__((unused)) const Declarations& decls, const Declarations& decls, const std::filesystem::path& input_file, const std::filesystem::path& input_file, const std::filesystem::path& include_dir, const std::filesystem::path& include_dir, const std::filesystem::path& out_dir, const std::filesystem::path& out_dir, Loading @@ -43,7 +43,16 @@ bool generate_rust_source_one_file( return false; return false; } } out_file << "// @generated rust packets from " << input_file.filename().string(); out_file << "// @generated rust packets from " << input_file.filename().string() << "\n\n"; for (const auto& e : decls.type_defs_queue_) { if (e.second->GetDefinitionType() == TypeDef::Type::ENUM) { const auto* enum_def = dynamic_cast<const EnumDef*>(e.second); EnumGen gen(*enum_def); gen.GenRustDef(out_file); out_file << "\n\n"; } } out_file.close(); out_file.close(); return true; return true; Loading