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

Deduplicate common messages #37

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
30 changes: 6 additions & 24 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ fn main() {
// NOTE: We cannot use `CARGO_MANIFEST_DIR`, because protoc doesn't work well with
// absolute paths.
#[allow(clippy::eq_op)]
let is_public =
env!("CARGO_PKG_REPOSITORY") == "https://github.com/worldcoin/orb-messages";
let is_public = std::env::var("CARGO_PKG_REPOSITORY").unwrap()
== "https://github.com/worldcoin/orb-messages";
let (messages_dir, priv_dir) = if is_public {
println!("cargo:warning=Be aware that private definitions are stubbed out when building the public crate.");

Expand All @@ -22,26 +22,8 @@ fn main() {
println!("cargo:rerun-if-changed={}", messages_dir.display());
println!("cargo:rerun-if-changed={}", priv_dir.display());

let main_proto = messages_dir.join("mcu_messaging_main.proto");
let sec_proto = messages_dir.join("mcu_messaging_sec.proto");
let sec_priv_proto = priv_dir.join("mcu_messaging_sec_priv.proto");

// Codegen with protoc.
if let Err(err) = || -> std::io::Result<()> {
prost_build::Config::default()
.default_package_filename("mcu_messaging_main")
.compile_protos(&[main_proto], &[messages_dir])?;

prost_build::Config::default()
.default_package_filename("mcu_messaging_sec")
.compile_protos(&[sec_proto], &[messages_dir, &priv_dir])?;

prost_build::Config::default()
.default_package_filename("mcu_messaging_sec_priv")
.compile_protos(&[sec_priv_proto], &[priv_dir])?;

Ok(())
}() {
panic!("{err}");
}
// These protos and any others that are imported by them will get compiled
prost_build::Config::default()
.compile_protos(&[messages_dir.join("orb.proto")], &[messages_dir, priv_dir])
.expect("failed to compile protobufs");
}
3 changes: 3 additions & 0 deletions messages/common.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
orb.mcu.FirmwareUpdateData.image_block max_size: 39
orb.mcu.Log.log max_length: 50
orb.mcu.MemfaultEvent.chunk max_size: 50
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
syntax = "proto3";

// Types that are shared by all microcontrollers.
// To avoid cyclic dependencies, we must avoid importing anything else.
package orb.mcu;

// This reply message is sent to acknowledge successful processing of a
// JetsonToMcu message
message Ack
Expand Down
12 changes: 12 additions & 0 deletions messages/main.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
orb.mcu.main.GNSSData.nmea max_length: 82
orb.mcu.main.GNSSDataPartial.nmea_part max_length: 50
orb.mcu.main.UserCenterLEDsSequence.rgb_uncompressed max_size: 192
orb.mcu.main.UserCenterLEDsSequence.argb32_uncompressed max_size: 256
orb.mcu.main.UserRingLEDsSequence.rgb_uncompressed max_size: 672
orb.mcu.main.UserRingLEDsSequence.argb32_uncompressed max_size: 396
orb.mcu.main.DistributorLEDsSequence.rgb_uncompressed max_size: 15
orb.mcu.main.DistributorLEDsSequence.argb32_uncompressed max_size: 20
orb.mcu.main.ConeLEDsSequence.rgb_uncompressed max_size: 192
orb.mcu.main.ConeLEDsSequence.argb32_uncompressed max_size: 256
orb.mcu.main.IREyeCameraFocusSweepLensValues max_size: 600
orb.mcu.main.BatteryInfoHwFw.mcu_id max_size: 12
63 changes: 21 additions & 42 deletions messages/mcu_messaging_main.proto → messages/main.proto
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
syntax = "proto3";

import "mcu_messaging_common.proto";
package orb.mcu.main;

// Any change in version number should be made only if:
// - at least one new field is mandatory for the message to be correctly
// interpreted
// - at least one field has been "renumbered"
// - at least one field type has changed
// Do not change version otherwise.
// ⚠️ Version 0 considered as not stable

//
enum Version {
VERSION_0 = 0;
}

message McuMessage
{
Version version = 1;
oneof message
{
JetsonToMcu j_message = 2;
McuToJetson m_message = 3;
}
}
import "common.proto";

message JetsonToMcu
{
Expand All @@ -36,8 +15,8 @@ message JetsonToMcu
oneof payload
{
ShutdownWithDelay shutdown = 2;
RebootWithDelay reboot = 3;
Temperature temperature = 4;
orb.mcu.RebootWithDelay reboot = 3;
orb.mcu.Temperature temperature = 4;
MirrorAngle mirror_angle = 5;
PerformMirrorHoming do_homing = 6;
InfraredLEDs infrared_leds = 7;
Expand All @@ -47,7 +26,7 @@ message JetsonToMcu
UserLEDsBrightness user_leds_brightness = 11;
DistributorLEDsPattern distributor_leds_pattern = 12;
DistributorLEDsBrightness distributor_leds_brightness = 13;
FirmwareUpdateData dfu_block = 14;
orb.mcu.FirmwareUpdateData dfu_block = 14;
StartTriggeringIrEyeCamera start_triggering_ir_eye_camera = 16;
StopTriggeringIrEyeCamera stop_triggering_ir_eye_camera = 17;
StartTriggeringIrFaceCamera start_triggering_ir_face_camera = 18;
Expand All @@ -59,15 +38,15 @@ message JetsonToMcu
Fps fps = 25;
LiquidLens liquid_lens = 26;
VoltageRequest voltage_request = 27;
FirmwareImageCheck fw_image_check = 28;
FirmwareActivateSecondary fw_image_secondary_activate = 29;
Heartbeat heartbeat = 30;
orb.mcu.FirmwareImageCheck fw_image_check = 28;
orb.mcu.FirmwareActivateSecondary fw_image_secondary_activate = 29;
orb.mcu.Heartbeat heartbeat = 30;
MirrorAngleRelative mirror_angle_relative = 32;
ValueGet value_get = 33;
orb.mcu.ValueGet value_get = 33;
UserRingLEDsSequence ring_leds_sequence = 34;
UserCenterLEDsSequence center_leds_sequence = 35;
DistributorLEDsSequence distributor_leds_sequence = 36;
FirmwareConfirmPrimary fw_image_primary_confirm = 37;
orb.mcu.FirmwareConfirmPrimary fw_image_primary_confirm = 37;
IREyeCameraFocusSweepValuesPolynomial
ir_eye_camera_focus_sweep_values_polynomial = 38;
IREyeCameraFocusSweepLensValues ir_eye_camera_focus_sweep_lens_values =
Expand All @@ -79,43 +58,43 @@ message JetsonToMcu
ConeLEDsSequence cone_leds_sequence = 43;
ConeLEDsPattern cone_leds_pattern = 44;
WhiteLEDsBrightness white_leds_brightness = 45;
SyncDiagData sync_diag_data = 46;
DiagTest diag_test = 47;
orb.mcu.SyncDiagData sync_diag_data = 46;
orb.mcu.DiagTest diag_test = 47;
}
}

message McuToJetson
{
oneof payload
{
Ack ack = 1;
orb.mcu.Ack ack = 1;
PowerButton power_button = 2;
BatteryVoltage battery_voltage = 3;
BatteryCapacity battery_capacity = 4;
GNSSData gnss = 5;
Versions versions = 6;
Temperature temperature = 7;
orb.mcu.Versions versions = 6;
orb.mcu.Temperature temperature = 7;
FanStatus fan_status = 8;
IMUData imu_data = 9;
Voltage voltage = 10;
Log log = 11;
orb.mcu.Log log = 11;
MotorRange motor_range = 12;
FatalError fatal_error = 13;
orb.mcu.FatalError fatal_error = 13;
BatteryIsCharging battery_is_charging = 14;
BatteryDiagnosticCommon battery_diag_common = 15;
ToF_1D tof_1d = 16;
GNSSDataPartial gnss_partial = 17;
AmbientLight front_als = 18;
Hardware hardware = 19;
HardwareDiagnostic hardware_diag = 20;
orb.mcu.Hardware hardware = 19;
orb.mcu.HardwareDiagnostic hardware_diag = 20;
BatteryResetReason battery_reset_reason = 21;
BatteryDiagnosticSafety battery_diag_safety = 22;
BatteryDiagnosticPermanentFail battery_diag_permanent_fail = 23;
BatteryInfoHwFw battery_info_hw_fw = 24;
BatteryInfoMaxValues battery_info_max_values = 25;
BatteryInfoSocAndStatistics battery_info_soc_and_statistics = 26;
ConePresent cone_present = 27;
MemfaultEvent memfault_event = 28;
orb.mcu.MemfaultEvent memfault_event = 28;
BatteryStateOfHealth battery_state_of_health = 29;
ShutdownScheduled shutdown = 30;
}
Expand Down Expand Up @@ -741,7 +720,7 @@ message BatteryInfoHwFw
BATTERY_HW_VERSION_UNDETECTED = 255;
}
HardwareVersion hw_version = 2;
FirmwareVersion fw_version = 3;
orb.mcu.FirmwareVersion fw_version = 3;
}

message BatteryInfoMaxValues
Expand Down
3 changes: 0 additions & 3 deletions messages/mcu_messaging_common.options

This file was deleted.

12 changes: 0 additions & 12 deletions messages/mcu_messaging_main.options

This file was deleted.

1 change: 0 additions & 1 deletion messages/mcu_messaging_sec.options

This file was deleted.

71 changes: 0 additions & 71 deletions messages/mcu_messaging_sec.proto

This file was deleted.

32 changes: 32 additions & 0 deletions messages/orb.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";

// This file is the root of the entire package hierarchy.
package orb.mcu;

import "main.proto";
import "sec.proto";

// Any change in version number should be made only if:
// - at least one new field is mandatory for the message to be correctly
// interpreted
// - at least one field has been "renumbered"
// - at least one field type has changed
// Do not change version otherwise.
// ⚠️ Version 0 considered as not stable

//
enum Version {
VERSION_0 = 0;
}

message McuMessage
{
Version version = 1;
oneof message
{
main.JetsonToMcu j_message = 2;
main.McuToJetson m_message = 3;
sec.JetsonToSec jetson_to_sec_message = 4;
sec.SecToJetson sec_to_jetson_message = 5;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
syntax = "proto3";
package private;

package orb.mcu.sec.private;

// incomplete, private definitions
// to be overwritten by actual definitions
Expand Down
1 change: 1 addition & 0 deletions messages/sec.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
orb.mcu.sec.SERequest.data max_size: 512
Loading
Loading