about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2023-06-12 20:30:36 -0500
committergennyble <gen@nyble.dev>2023-06-12 20:30:36 -0500
commit70187683361d97a8b5a251567323c323c90302f2 (patch)
treea9e0f5a3ad3af87e211a1f3436901c33fb302afc /src/main.rs
parente47f278ec2958404b610ea997f8b2ddcb97bc9bb (diff)
downloadlri-rs-70187683361d97a8b5a251567323c323c90302f2.tar.gz
lri-rs-70187683361d97a8b5a251567323c323c90302f2.zip
dump LightHeader proto as text file
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 7a2634b..0c1842e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,9 @@
 use std::{fs::File, io::Write, os::unix::prelude::FileExt, path::Path};
 
-use lri_rs::{proto::camera_module::CameraModule, Message};
+use lri_rs::{
+	proto::{self, camera_module::CameraModule},
+	Message,
+};
 use nalgebra::Matrix3;
 use png::{BitDepth, ColorType};
 use rawloader::CFA;
@@ -42,6 +45,7 @@ fn main() {
 			fuckwithsensordata(block, idx);
 		} else {
 			block.header.nice_info();
+			dump_lightheader(block, idx);
 		}
 	}
 
@@ -246,6 +250,25 @@ fn fuckwithsensordata(block: &Block, idx: usize) {
 	println!("===================================\n");
 }
 
+fn dump_lightheader(block: &Block, idx: usize) {
+	let fname = format!("block{idx}_lightheader.protodump");
+
+	if !block.is_lightheader() {
+		return;
+	}
+
+	match lri_rs::proto::lightheader::LightHeader::parse_from_bytes(block.body()) {
+		Err(_e) => {
+			println!("Failed parse I'm so toried to write mote");
+		}
+		Ok(lh) => {
+			let proto = protobuf::text_format::print_to_string_pretty(&lh);
+			std::fs::write(&fname, proto).unwrap();
+			println!("Write protobuf data to {fname}");
+		}
+	}
+}
+
 fn dump(data: &[u8], path: &str) {
 	let mut file = File::create(&path).unwrap();
 	file.write_all(data).unwrap();
@@ -296,6 +319,10 @@ impl Block {
 	pub fn is_sensor(&self) -> bool {
 		self.header.header_length != 32
 	}
+
+	pub fn is_lightheader(&self) -> bool {
+		!self.is_sensor() && self.header.kind == 0
+	}
 }
 
 #[derive(Clone, Debug)]