From 31532633bf59fe54a357efd7cf645157abf2ec63 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 2 Feb 2021 05:37:07 -0500 Subject: [PATCH] debugging, starting to pull commands into another module (not done) --- src/main_zeromq.rs | 8 +++--- src/zeromq/message.rs | 67 +++++++++++++++++++++++++++++++++++++++++++ src/zeromq/mod.rs | 1 + 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/zeromq/message.rs diff --git a/src/main_zeromq.rs b/src/main_zeromq.rs index 1f65318d41..1d5d3d4ab3 100644 --- a/src/main_zeromq.rs +++ b/src/main_zeromq.rs @@ -115,7 +115,7 @@ fn main() -> AnyhowResult<()> { packet_number += 1; }, MessagingState::GrabPointCloud => { - println!("Grabbing another frame..."); + //println!("Grabbing another frame..."); color = get_time_based_color(); points = get_point_cloud(&device, &xy_table, color)?; @@ -142,7 +142,7 @@ fn get_point_cloud(device: &Device, xy_table: &Image, color: Color) -> AnyhowRes let mut points = calculate_point_cloud2(&depth_image, &xy_table, color)?; - println!("Points: {}", points.len()); + //println!("Points: {}", points.len()); Ok(points) } @@ -162,10 +162,10 @@ fn encode_point_data(points: &mut Vec, is_beginning: bool) -> Vec { let mut buf = Vec::with_capacity(4 + point_bytes); if is_beginning { - println!("begin"); + //println!("begin"); buf.write_u32::(POINT_DATA_BEGIN_PAYLOAD_COMMAND); // COMMAND # } else { - println!("continue"); + //println!("continue"); buf.write_u32::(POINT_DATA_CONTINUE_PAYLOAD_COMMAND); // COMMAND # } diff --git a/src/zeromq/message.rs b/src/zeromq/message.rs new file mode 100644 index 0000000000..3c7bdde078 --- /dev/null +++ b/src/zeromq/message.rs @@ -0,0 +1,67 @@ +use crate::zeromq::point::Point; +use byteorder::{WriteBytesExt, LittleEndian}; +use std::io::Write; + +/* + + +/// Denotes the command that sends the variable-length data +const POINT_DATA_BEGIN_PAYLOAD_COMMAND : u32 = 2; + +/// Denotes the command that sends the variable-length data +const POINT_DATA_CONTINUE_PAYLOAD_COMMAND : u32 = 3; + +/// The maximum number of points to send per ZeroMQ "packet". +/// This is also defined in C++, so it needs to be adjusted in multiple places. +const MAX_SEND_POINTS_PER_PACKET : usize = 3000; + +/// Streaming points +struct StreamingPointsPacket { + is_first_point_packet: bool, + points: Vec, +} + +impl StreamingPointsPacket { + fn from_all_points(points: Vec) -> Self { + Self { + is_first_point_packet: true, + points, + } + } + + /// Over the wire, this looks like: + /// + /// | command | 4 bytes (u32) | + /// | point_count | 4 bytes (u32) | + /// | points[] ... | [16 bytes] ... | + /// + fn encode(&self) -> Vec { + let point_bytes = Point::size_bytes() * MAX_SEND_POINTS_PER_PACKET; + + let mut buf = Vec::with_capacity(4 + point_bytes); + + if self.is_first_point_packet { + buf.write_u32::(POINT_DATA_BEGIN_PAYLOAD_COMMAND); // COMMAND # + } else { + buf.write_u32::(POINT_DATA_CONTINUE_PAYLOAD_COMMAND); // COMMAND # + } + + //let subset = if points.len() > MAX_SEND_POINTS_PER_PACKET { + // points.drain(0..MAX_SEND_POINTS_PER_PACKET).collect::>() + //} else { + // points.drain(0..points.len()).collect::>() + //}; + + buf.write_u32::(self.points.len() as u32); // LENGTH + + for point in self.points.iter() { + let bytes = point.to_bytes(); + buf.write_all(&bytes); + } + + buf + } +} + + +*/ diff --git a/src/zeromq/mod.rs b/src/zeromq/mod.rs index 546cdf0c57..8a85af929b 100644 --- a/src/zeromq/mod.rs +++ b/src/zeromq/mod.rs @@ -1,5 +1,6 @@ pub mod calculate_point_cloud; pub mod color; pub mod debug; +pub mod message; pub mod point; pub mod xy_table; \ No newline at end of file