Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Protobuf Messages #170

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autogen/
46 changes: 46 additions & 0 deletions bridge/GenerateBridgeSources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import subprocess

def generate_protobuf_code(proto_dir, autogen_dir):
"""Generates Python, Java, and C++ code from protobuf files.

Args:
proto_dir: The directory containing the .proto files.
autogen_dir: The directory to output the generated code.
"""

# Create the autogen directory if it doesn't exist
os.makedirs(autogen_dir, exist_ok=True)

# Find all .proto files in the proto directory
proto_files = [f for f in os.listdir(proto_dir) if f.endswith(".proto")]

# Generate code for each .proto file
for proto_file in proto_files:
proto_path = os.path.join(proto_dir, proto_file)

# Generate Python code
subprocess.run([
"protoc",
f"--python_out={autogen_dir}",
proto_path
])

# Generate Java code
subprocess.run([
"protoc",
f"--java_out={autogen_dir}",
proto_path
])

# Generate C++ code
subprocess.run([
"protoc",
f"--cpp_out={autogen_dir}",
proto_path
])

if __name__ == "__main__":
proto_dir = "./protobuf"
autogen_dir = "./autogen"
generate_protobuf_code(proto_dir, autogen_dir)
37 changes: 37 additions & 0 deletions bridge/protobuf/bridge.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
syntax = "proto3";

message AudioCommand {
fixed32 bitrate = 1;
sfixed64 length = 2;
}

message SetSquelchCommand {
fixed32 level = 1;
}

message GetSquelchCommand {
fixed32 level = 1;
}

message SetFrequency {
fixed32 freq_hz = 1;
}

message GetFrequency {
}

message AppToEmbedded {
oneof command {
AudioCommand audio = 1;
SetSquelchCommand set_squelch = 2;
GetSquelchCommand get_squelch = 3;
SetFrequency set_frequency = 4;
GetFrequency get_frequency = 5;
}
}

message embeddedToApp {
oneof command {
AudioCommand audio = 1;
}
}
Loading