about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2023-06-08 17:56:26 -0500
committergennyble <gen@nyble.dev>2023-06-08 17:56:26 -0500
commit6dce5cea307301ba96264fe1437c1f7fdd91d6a8 (patch)
tree4a0c7d5c2034e5a1708f06c4f58db3a2acc01a7c
parentaec3f2c27e228155bed768f9490a724de1f9bda3 (diff)
downloadlri-rs-6dce5cea307301ba96264fe1437c1f7fdd91d6a8.tar.gz
lri-rs-6dce5cea307301ba96264fe1437c1f7fdd91d6a8.zip
AHHHHHHHH PROTOBUF PARSING
-rw-r--r--NOTES.md12
-rw-r--r--src/main.rs90
2 files changed, 84 insertions, 18 deletions
diff --git a/NOTES.md b/NOTES.md
index 868a3f3..0fde302 100644
--- a/NOTES.md
+++ b/NOTES.md
@@ -71,4 +71,14 @@ tired, need sleep, bullet point for now.
 - it appears to be 14bpp packed *(for wall.lri at least)*. the `camera_module.proto` has this as one of the raw options. we should make it a priority to find and parse this.
 - yay
 
-[se-dev]: https://github.com/LAK132/SourceExplorer/tree/dev
\ No newline at end of file
+[se-dev]: https://github.com/LAK132/SourceExplorer/tree/dev
+
+# lak's really good at things
+## 2023-06-08 09:02 CST
+I'm on a break from work, lol.
+
+While I was asleep, lak worked for like seven hours! lak improved SourceExplorer while unpacking the data and it's very cool.
+For `wall.lri` and in the 2nd bit of sensor data *(block index 3; the third block)*, the data is likely from the AR1335. lak
+was able to get a debayered, but not colour correct, image reading it as RAW_10BIT_PACKED in the BGGR arrangement.
+
+lak was able to get a usuable image with a width of 2080 in source explorer, but says "also it's croped in to 4160 4208". noteably 4160 is 2 * 2080, so I don't know? curious.
diff --git a/src/main.rs b/src/main.rs
index 1fdb23e..710d3c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
 use std::{fs::File, io::Write, os::unix::prelude::FileExt, path::Path};
 
-use lri_rs::Message;
+use lri_rs::{proto::camera_module::CameraModule, Message};
 use png::{BitDepth, ColorType};
 
 // This code is going to be rough. Just trying to parse this using the technique
@@ -40,6 +40,7 @@ fn main() {
 
 	let ar835 = 3264 * 2448;
 	let ar835_6mp = 3264 * 1836;
+	let ar1335_crop = 4160 * 3120;
 	let ar1335 = 4208 * 3120;
 	let imx386 = 4032 * 3024;
 
@@ -81,9 +82,10 @@ fn main() {
 	}
 
 	println!("\nDumping header info..");
-	heads.iter().for_each(|h| h.header.print_info());
+	heads.iter().for_each(|h| h.header.nice_info());
 
-	println!("\nWriting large ones to disk!");
+	println!("\nWriting large ones to disk and collecting the smalls!");
+	let mut small: Vec<u8> = vec![];
 	for (idx, head) in heads.iter().enumerate() {
 		if head.header.header_length > 1024 * 1024 {
 			// I guess we only care if it's at least a megabyte
@@ -94,27 +96,79 @@ fn main() {
 				"Wrote {:.2}MB to disk as {name}",
 				head.header.combined_length as f32 / (1024.0 * 1024.0)
 			);
+		} else {
+			small.extend(&data[head.start..head.end]);
 		}
+	}
 
-		if idx == 2 {
-			let data = &data[head.start + 32..head.end];
+	let mut file = File::create("small.lri_part").unwrap();
+	file.write_all(&small).unwrap();
+	println!(
+		"Wrote {:.2}MB to disk as small.lri_part",
+		small.len() as f32 / (1024.0 * 1024.0)
+	);
+
+	let stamp = [
+		08, 0xe7, 0x0f, 0x10, 0x06, 0x18, 0x07, 0x20, 0x13, 0x28, 0x0e,
+	];
+	println!("\nLooking for timestamps!");
+	for (idx, head) in find_pattern(&heads, &data, &stamp) {
+		println!("Found stamp in {idx}");
+	}
 
-			let mut first = vec![0; data.len() / 2];
-			let mut second = vec![0; data.len() / 2];
-			for (idx, chnk) in data.chunks(2).enumerate() {
-				first[idx] = chnk[0];
-				second[idx] = chnk[0];
-			}
+	println!("\nAttemtping to parse data after first image in 2");
+	let head = &heads[2];
+	let start = head.start + (ar1335_crop as f32 * 2.5).ceil() as usize;
+	let after_image = &data[start..start + 4352];
+	let proto = match lri_rs::proto::lightheader::LightHeader::parse_from_bytes(after_image) {
+		Ok(_) => println!("Success?!?!?!"),
+		Err(e) => println!("Failed {e}"),
+	};
 
-			let name = format!("{idx}_first.lri_part");
-			let mut file = File::create(&name).unwrap();
-			file.write_all(&first).unwrap();
+	println!("Eight before: {:?}", &data[start - 8..start]);
+	println!("Eight in: {:?}", &data[start..start + 8]);
 
-			let name = format!("{idx}_second.lri_part");
-			let mut file = File::create(&name).unwrap();
-			file.write_all(&second).unwrap();
+	println!("\nDumping the Message of idx 1");
+	dump_body(&heads[4], &data, "msg4.lri_part");
+
+	let msg = body(&heads[4], &data);
+	let proto = match lri_rs::proto::lightheader::LightHeader::parse_from_bytes(msg) {
+		Ok(data) => {
+			println!("Success?!?!?!");
+			println!("{data:?}");
+		}
+		Err(e) => println!("Failed {e}"),
+	};
+}
+
+fn dump_body(head: &HeaderAndOffset, data: &[u8], path: &str) {
+	let msg = body(head, data);
+	let mut file = File::create(&path).unwrap();
+	file.write_all(msg).unwrap();
+	println!("Wrote {:.2}KB to disk as {path}", msg.len() as f32 / 1024.0);
+}
+
+fn body<'a>(head: &HeaderAndOffset, data: &'a [u8]) -> &'a [u8] {
+	&data[head.start + head.header.header_length as usize
+		..head.start + head.header.header_length as usize + head.header.message_length as usize]
+}
+
+fn find_pattern<'a>(
+	heads: &'a [HeaderAndOffset],
+	data: &[u8],
+	pattern: &[u8],
+) -> Vec<(usize, &'a HeaderAndOffset)> {
+	let mut finds = vec![];
+
+	for (head_idx, head) in heads.iter().enumerate() {
+		for idx in head.start..head.end - pattern.len() {
+			if &data[idx..idx + pattern.len()] == pattern {
+				finds.push((head_idx, head));
+			}
 		}
 	}
+
+	finds
 }
 
 fn make_png<P: AsRef<Path>>(
@@ -143,6 +197,7 @@ fn make_png<P: AsRef<Path>>(
 	writer.write_image_data(&data[..pix * bpp]).unwrap();
 }
 
+#[derive(Clone, Debug)]
 struct HeaderAndOffset {
 	header: LightHeader,
 	// Inclusive
@@ -151,6 +206,7 @@ struct HeaderAndOffset {
 	end: usize,
 }
 
+#[derive(Clone, Debug)]
 struct LightHeader {
 	magic_number: String,
 	combined_length: u64,