Skip to content

Commit

Permalink
Deduplicate common messages
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed Oct 17, 2024
1 parent ac7246f commit 281c8d1
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 170 deletions.
21 changes: 5 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,12 @@ 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.
// These protos and any others that are imported by them will get compiled
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])?;
prost_build::Config::default().compile_protos(
&[messages_dir.join("orb.proto")],
&[messages_dir, priv_dir],
)?;

Ok(())
}() {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions messages/mcu_messaging_common.proto → messages/common.proto
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;

// This reply message is sent to acknowledge successful processing of a
// JetsonToMcu message
message Ack
Expand Down
File renamed without changes.
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.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.RebootWithDelay reboot = 3;
orb.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.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.FirmwareImageCheck fw_image_check = 28;
orb.FirmwareActivateSecondary fw_image_secondary_activate = 29;
orb.Heartbeat heartbeat = 30;
MirrorAngleRelative mirror_angle_relative = 32;
ValueGet value_get = 33;
orb.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.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.SyncDiagData sync_diag_data = 46;
orb.DiagTest diag_test = 47;
}
}

message McuToJetson
{
oneof payload
{
Ack ack = 1;
orb.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.Versions versions = 6;
orb.Temperature temperature = 7;
FanStatus fan_status = 8;
IMUData imu_data = 9;
Voltage voltage = 10;
Log log = 11;
orb.Log log = 11;
MotorRange motor_range = 12;
FatalError fatal_error = 13;
orb.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.Hardware hardware = 19;
orb.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.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.FirmwareVersion fw_version = 3;
}

message BatteryInfoMaxValues
Expand Down
71 changes: 0 additions & 71 deletions messages/mcu_messaging_sec.proto

This file was deleted.

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

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

import "main.proto";
import "sec.proto";
import "common.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.sec.private;

// incomplete, private definitions
// to be overwritten by actual definitions
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions messages/sec.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
syntax = "proto3";

package orb.sec;

import "common.proto";
import "sec_priv.proto";

enum Version {
VERSION_0 = 0;
}

message JetsonToSec
{
uint32 ack_number = 1; // monotonically incrementing number. We will
// acknowledge all messages
oneof payload
{
orb.RebootWithDelay reboot = 3;
orb.FirmwareUpdateData dfu_block = 4;
orb.Heartbeat heartbeat = 5;
SERequest se_request = 6;
orb.FirmwareImageCheck fw_image_check = 20;
orb.FirmwareActivateSecondary fw_image_secondary_activate = 21;
orb.ValueGet value_get = 22;
orb.FirmwareConfirmPrimary fw_image_primary_confirm = 23;
orb.SyncDiagData sync_diag_data = 24;
orb.DiagTest diag_test = 25;
}
}

message SecToJetson
{
reserved 6; // used in previous versions

oneof payload
{
orb.Ack ack = 1;
orb.Versions versions = 2;
orb.Log log = 3;
sec.private.SEResponse se_response = 4;
sec.private.Tamper tampered = 5;
orb.BatteryStatus battery_status = 7;
orb.FatalError fatal_error = 8;
sec.private.TamperRaw tamper_raw = 9;
sec.private.TamperStates tamper_states = 10;
orb.Temperature temperature = 11;
orb.MemfaultEvent memfault_event = 12;
orb.HardwareDiagnostic hardware_diag = 13;
}
}

message SERequest
{
enum RequestType {
READ_WRITE = 0;
CLEAR_READ_BUFFER = 1;
POWER_OFF = 2;
};
uint32 id = 1;
bytes data = 2;
uint32 rx_length = 3;
RequestType request_type = 4;
}
2 changes: 2 additions & 0 deletions src/generated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Loading

0 comments on commit 281c8d1

Please sign in to comment.