diff --git a/Cargo.lock b/Cargo.lock index 3e345a3..b8c2982 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -965,6 +965,12 @@ dependencies = [ "litrs", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "downcast-rs" version = "1.2.0" @@ -2892,6 +2898,7 @@ dependencies = [ "anyhow", "crossbeam", "crossbeam-channel", + "dotenv", "eframe", "egui", "indicatif", diff --git a/Cargo.toml b/Cargo.toml index 07fc41b..49dabc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ crate-type = ["rlib", "cdylib"] anyhow = "1.0.77" crossbeam = "0.8.4" crossbeam-channel = "0.5.11" +dotenv = "0.15.0" eframe = "0.26.2" egui = "0.26.2" indicatif = "0.17.7" diff --git a/examples/live.rs b/examples/live.rs index b936e10..a0d6701 100644 --- a/examples/live.rs +++ b/examples/live.rs @@ -1,4 +1,4 @@ -use indicatif::ProgressBar; +use dotenv::dotenv; use std::fs::File; use std::io::Write; use thermaldecoder::{Frame, Header, HDR_SIZE}; @@ -37,11 +37,27 @@ use thermaldecoder::{Frame, Header, HDR_SIZE}; // } fn main() -> anyhow::Result<()> { + dotenv().ok(); + let device = match std::env::var("THERMALCAM_IFACE=enp1s0f0") { + Ok(d) => { + let device = pcap::Device::list() + .expect("device list failed") + .into_iter() + .find(|x| x.name == d) + .expect(&format!("could not find device {}", d)); + device + } + Err(_) => pcap::Device::lookup() + .expect("device lookup failed") + .expect("no device available"), + }; // get the default Device - let device = pcap::Device::lookup() - .expect("device lookup failed") - .expect("no device available"); + println!("Using device {}", device.name); + let output = std::env::args() + .nth(1) + .expect("required output file argument"); + println!("Using output {}", output); // Setup Capture let mut cap = pcap::Capture::from_device(device) @@ -52,8 +68,7 @@ fn main() -> anyhow::Result<()> { // get a packet and print its bytes let mut parts = vec![]; - let pb = ProgressBar::new(1024); - let mut out = File::create("output.raw")?; + let mut out = File::create(&output)?; while let Ok(p) = cap.next_packet() { let data = p.data; if data.len() != 6972 { @@ -72,7 +87,6 @@ fn main() -> anyhow::Result<()> { }; if frame.raw.len() == 384 * 288 * 2 { out.write_all(&frame.raw)?; - pb.inc(1); } parts.clear(); } diff --git a/replay.py b/replay.py index a45f57e..995d4c4 100755 --- a/replay.py +++ b/replay.py @@ -4,6 +4,10 @@ import base64 from scapy.all import * +from dotenv import load_dotenv +import os + +load_dotenv() # Base64 encoded packet data encoded_packet = "////////AAFsWfAKCABFAAA4KB0AAIARkEfAqAABwKgA/x+bH5wA2QAAASABgBtAACAAAAAAAAAADwAAAAEAAAEAACArAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////////////////////////////////////AAAAAAAAAAIBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" @@ -16,5 +20,8 @@ decoded_packet = base64.b64decode(encoded_packet) packet = Ether(decoded_packet) #print(packet.show(dump=True)) +iface = os.environ.get('THERMALCAM_IFACE', 'enp1s0f0') +print(f'using interface {iface}') + # (packet) -sendp(packet, iface="enp1s0f0") \ No newline at end of file +sendp(packet, iface=iface) diff --git a/run_live.sh b/run_live.sh index 5974e66..495575d 100755 --- a/run_live.sh +++ b/run_live.sh @@ -1,3 +1,14 @@ #!/bin/bash cd $(dirname $0) -sudo ./venv/bin/python ./decode.py --live + +set -e + +# Python works but stutters +#sudo ./venv/bin/python ./decode.py --live +cargo build --release --example live +sudo ./target/release/examples/live /dev/stdout | gst-launch-1.0 filesrc location=/dev/stdin \ + ! rawvideoparse use_sink_caps=false height=384 width=288 format=gray16-le \ + ! videoconvertscale \ + ! v4l2sink device=/dev/video0 +# ! videoconvertscale +