Compare commits
No commits in common. "6bcc541c869c4e4280375a77a87e7e4dba9f0d5a" and "bba0e3a09329bc722f27e6c518c72fb9ae651357" have entirely different histories.
6bcc541c86
...
bba0e3a093
123
Cargo.lock
generated
123
Cargo.lock
generated
|
@ -469,29 +469,6 @@ dependencies = [
|
|||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.65.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"log",
|
||||
"peeking_take_while",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 2.0.48",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.5.3"
|
||||
|
@ -668,15 +645,6 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
@ -704,17 +672,6 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fc239e0f6cb375d2402d48afb92f76f5404fd1df208a41930ec81eda078bea"
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
"libloading 0.8.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clipboard-win"
|
||||
version = "5.1.0"
|
||||
|
@ -1008,12 +965,6 @@ 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"
|
||||
|
@ -1127,12 +1078,6 @@ dependencies = [
|
|||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
||||
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.26.2"
|
||||
|
@ -1522,12 +1467,6 @@ dependencies = [
|
|||
"xml-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "glow"
|
||||
version = "0.13.1"
|
||||
|
@ -1861,12 +1800,6 @@ version = "1.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "lazycell"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
|
@ -2350,12 +2283,6 @@ dependencies = [
|
|||
"rusticata-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peeking_take_while"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
|
@ -2452,16 +2379,6 @@ version = "0.3.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
|
@ -2794,12 +2711,6 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
|
@ -2981,7 +2892,6 @@ dependencies = [
|
|||
"anyhow",
|
||||
"crossbeam",
|
||||
"crossbeam-channel",
|
||||
"dotenv",
|
||||
"eframe",
|
||||
"egui",
|
||||
"indicatif",
|
||||
|
@ -2990,7 +2900,6 @@ dependencies = [
|
|||
"png",
|
||||
"pyo3",
|
||||
"serde",
|
||||
"v4l",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3227,26 +3136,6 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "v4l"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8fbfea44a46799d62c55323f3c55d06df722fbe577851d848d328a1041c3403"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"libc",
|
||||
"v4l2-sys-mit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "v4l2-sys-mit"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6779878362b9bacadc7893eac76abe69612e8837ef746573c4a5239daf11990b"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
|
@ -3588,18 +3477,6 @@ dependencies = [
|
|||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"once_cell",
|
||||
"rustix 0.38.31",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
version = "1.0.2"
|
||||
|
|
|
@ -13,7 +13,6 @@ 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"
|
||||
|
@ -22,4 +21,3 @@ pcap-parser = { version = "0.14.1", features = ["data"] }
|
|||
png = "0.17.10"
|
||||
pyo3 = { version = "0.20.0", "features" = ["extension-module"] }
|
||||
serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] }
|
||||
v4l = { version = "0.14.0", features = ["v4l2"], default-features = false }
|
||||
|
|
111
examples/live.rs
111
examples/live.rs
|
@ -1,45 +1,47 @@
|
|||
use dotenv::dotenv;
|
||||
use indicatif::ProgressBar;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use thermaldecoder::{Header, HDR_SIZE};
|
||||
use v4l::video::Output;
|
||||
use thermaldecoder::{Frame, Header, HDR_SIZE};
|
||||
|
||||
// fn main() -> Result<(), eframe::Error> {
|
||||
// env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
// let options = eframe::NativeOptions {
|
||||
// viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 800.0]),
|
||||
// ..Default::default()
|
||||
// };
|
||||
// let (sender, receiver) = crossbeam::channel::unbounded();
|
||||
// eframe::run_native(
|
||||
// "Image Viewer",
|
||||
// options,
|
||||
// Box::new(|cc| {
|
||||
// // This gives us image support:
|
||||
// egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
// Box::<MyApp>::default()
|
||||
// }),
|
||||
// )
|
||||
// }
|
||||
|
||||
// #[derive(Default)]
|
||||
// struct MyApp {}
|
||||
|
||||
// impl eframe::App for MyApp {
|
||||
// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
// egui::CentralPanel::default().show(ctx, |ui| {
|
||||
// egui::ScrollArea::both().show(ui, |ui| {
|
||||
// ui.add(egui::Image::new().rounding(10.0));
|
||||
|
||||
// ui.image(egui::include_image!("ferris.svg"));
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
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 v4l2loopback device {}", output);
|
||||
|
||||
const WIDTH: usize = 288;
|
||||
const HEIGHT: usize = 384;
|
||||
let fourcc_repr = [
|
||||
b'Y', // | 0b10000000
|
||||
b'1', b'6',
|
||||
b' ', // Note: not using b' ' | 0x80, (V4L2_PIX_FMT_Y16_BE)
|
||||
// because VID_S_FMT ioctl returns EINVAL, so just swap the bytes here
|
||||
];
|
||||
let fourcc = v4l::format::FourCC { repr: fourcc_repr };
|
||||
let mut out = v4l::Device::with_path(output)?;
|
||||
// To find the fourcc code, use v4l2-ctl --list-formats-out /dev/video0
|
||||
// (or read the source :)
|
||||
let format = v4l::Format::new(WIDTH as u32, HEIGHT as u32, fourcc);
|
||||
Output::set_format(&out, &format)?;
|
||||
|
||||
// Setup Capture
|
||||
let mut cap = pcap::Capture::from_device(device)
|
||||
|
@ -49,13 +51,12 @@ fn main() -> anyhow::Result<()> {
|
|||
.unwrap();
|
||||
|
||||
// get a packet and print its bytes
|
||||
const PACKET_LEN: usize = 6972;
|
||||
const FRAME_LEN: usize = WIDTH * HEIGHT * 2;
|
||||
let mut frame = [0u8; FRAME_LEN];
|
||||
let mut len = 0;
|
||||
let mut parts = vec![];
|
||||
let pb = ProgressBar::new(1024);
|
||||
let mut out = File::create("output.raw")?;
|
||||
while let Ok(p) = cap.next_packet() {
|
||||
let data = p.data;
|
||||
if data.len() != PACKET_LEN {
|
||||
if data.len() != 6972 {
|
||||
continue;
|
||||
}
|
||||
let data = &data[0x2a..];
|
||||
|
@ -64,24 +65,18 @@ fn main() -> anyhow::Result<()> {
|
|||
Err(_) => continue,
|
||||
};
|
||||
let data = &data[HDR_SIZE..];
|
||||
if (header.part == 0 && len > 0)
|
||||
// do not write out of bounds - would panic, instead just skip
|
||||
|| (data.len() + len > FRAME_LEN)
|
||||
{
|
||||
if len == FRAME_LEN {
|
||||
// swap the bytes, we are using LE, not BE, 16 bit grayscale
|
||||
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
||||
let mut swapped = [0u8; FRAME_LEN];
|
||||
for i in 0..FRAME_LEN / 2 {
|
||||
swapped[i * 2] = frame[i * 2 + 1];
|
||||
swapped[i * 2 + 1] = frame[i * 2];
|
||||
if header.part == 0 && parts.len() > 0 {
|
||||
let frame = Frame {
|
||||
header,
|
||||
raw: parts.concat(),
|
||||
};
|
||||
if frame.raw.len() == 384 * 288 * 2 {
|
||||
out.write_all(&frame.raw)?;
|
||||
pb.inc(1);
|
||||
}
|
||||
out.write_all(&swapped[..])?;
|
||||
parts.clear();
|
||||
}
|
||||
len = 0;
|
||||
}
|
||||
frame[len..len + data.len()].copy_from_slice(data);
|
||||
len += data.len();
|
||||
parts.push(data.to_vec());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
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"
|
||||
|
@ -20,8 +16,5 @@ 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=iface)
|
||||
sendp(packet, iface="enp1s0f0")
|
12
run_live.sh
12
run_live.sh
|
@ -1,13 +1,3 @@
|
|||
#!/bin/bash
|
||||
cd $(dirname $0)
|
||||
|
||||
set -e
|
||||
|
||||
# Python works but stutters
|
||||
#sudo ./venv/bin/python ./decode.py --live
|
||||
cargo build --release --example live
|
||||
TARGET=./target/release/examples/live
|
||||
# setcap does not work yet (EPERM on socket AF_PACKET)
|
||||
# sudo setcap cap_net_raw,cap_net_admin=eip $TARGET
|
||||
#sudo strace -f -o live.strace $TARGET /dev/video0
|
||||
sudo $TARGET /dev/video0
|
||||
sudo ./venv/bin/python ./decode.py --live
|
||||
|
|
12
start.sh
12
start.sh
|
@ -1,12 +0,0 @@
|
|||
#!/bin/bash
|
||||
. .env
|
||||
IFACE=$THERMALCAM_IFACE
|
||||
echo "using iface $IFACE"
|
||||
echo "checking mtu"
|
||||
mtu=$(ip link show ${IFACE} | grep -o 'mtu [0-9]*' | gawk '{print $2}')
|
||||
echo "mtu = $mtu"
|
||||
if [ $mtu -lt 9000 ]; then
|
||||
echo "setting mtu to 9000"
|
||||
sudo ip link set $IFACE mtu 9000
|
||||
fi
|
||||
sudo venv/bin/python ./replay.py
|
Loading…
Reference in New Issue
Block a user