Skip to content
Snippets Groups Projects
Commit d84e9e67 authored by Stephen D's avatar Stephen D
Browse files

bug fixes

parent 1d82e638
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ dependencies = [
"image",
"serde",
"serial",
"subprocess",
"toml",
]
......@@ -641,6 +642,16 @@ dependencies = [
"lock_api",
]
[[package]]
name = "subprocess"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "syn"
version = "1.0.109"
......@@ -795,6 +806,28 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "winnow"
version = "0.4.1"
......
......@@ -12,4 +12,5 @@ crc = "3.0.1"
image = "0.24.6"
serde = { version = "1.0.160", features = ["derive"] }
serial = "0.4.0"
subprocess = "0.2.9"
toml = "0.7.3"
use std::{fs, path::PathBuf};
use anyhow::{anyhow, bail, Context};
use anyhow::{bail, Context};
use serde::Deserialize;
#[derive(Deserialize, Clone)]
......
......@@ -29,11 +29,14 @@ impl Controller {
thread::spawn(|| Self::tx_thread(rx));
let mut idx = 0;
loop {
while let Some(bytes) = self.manager.next() {
if let Err(e) = self.process_image(&bytes, &tx) {
if let Err(e) = self.process_image(&bytes, idx, &tx) {
eprintln!("Error processing image: {e}");
}
idx = idx.wrapping_add(1);
}
// after we don't find anything, sleep for a bit while
......@@ -42,10 +45,10 @@ impl Controller {
}
}
fn process_image(&self, img: &[u8], tx: &SyncSender<FecPacket>) -> anyhow::Result<()> {
fn process_image(&self, img: &[u8], idx: u8, tx: &SyncSender<FecPacket>) -> anyhow::Result<()> {
println!("Got an image of {} bytes", img.len());
for p in ssdv_encode("VE9QLE", img)? {
for p in ssdv_encode("VE9QLE", img, idx)? {
tx.send(p.into()).context("TX thread died")?;
}
......
use std::{
io::Write,
process::{Command, Stdio},
};
use anyhow::{bail, Context};
use crate::packet::RawPacket;
// TODO eventually rewrite Ssdv in Rust?
// Don't want to use FFI because then segfaults can hurt us
pub fn ssdv_encode(callsign: &str, img: &[u8]) -> anyhow::Result<Vec<RawPacket>> {
let mut cmd = Command::new("ssdv")
.args(["-e", "-c", callsign, "-n"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
cmd.stdin
.as_mut()
.context("Could not open ssdv stdin")?
.write_all(img)?;
let cmd_out = cmd.wait_with_output()?;
if !cmd_out.stderr.is_empty() {
eprintln!("{}", String::from_utf8_lossy(&cmd_out.stderr));
pub fn ssdv_encode(callsign: &str, img: &[u8], img_idx: u8) -> anyhow::Result<Vec<RawPacket>> {
let (stdout, stderr) = subprocess::Exec::cmd("ssdv")
.args(&[
"-e",
"-c",
callsign,
"-n",
"-q",
"6",
"-i",
&format!("{}", img_idx),
])
.stdin(img.to_vec())
.communicate()?
.read()?;
if let Some(stderr) = stderr {
if !stderr.is_empty() {
eprintln!("{}", String::from_utf8_lossy(&stderr));
}
}
if cmd_out.stdout.len() % 256 != 0 {
let stdout = stdout.context("ssdv no stdout")?;
if stdout.len() % 256 != 0 {
bail!("ssdv returned garbage");
}
let mut out = vec![];
let mut cur = [0; 256];
let mut i = 0;
for c in cmd_out.stdout {
for c in stdout {
cur[i] = c;
i += 1;
if i == 256 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment