mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
fixups and debug
This commit is contained in:
parent
8553aea95e
commit
116015dff8
6 changed files with 69 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1949,7 +1949,6 @@ name = "modals"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field 0.9.0",
|
"bit_field 0.9.0",
|
||||||
"dither",
|
|
||||||
"fast_image_resize",
|
"fast_image_resize",
|
||||||
"gam",
|
"gam",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ qrcode = { version = "0.12", default-features = false }
|
||||||
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
|
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
|
||||||
dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
||||||
# note: image version is matched to version used by dither
|
# note: image version is matched to version used by dither
|
||||||
image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true }
|
image = { version = "0.23", default-features = false, features = ["png"], optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = {path = "../../utralib"}
|
utralib = {path = "../../utralib"}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@ locales = {path = "../../locales"}
|
||||||
bit_field = "0.9.0"
|
bit_field = "0.9.0"
|
||||||
|
|
||||||
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
|
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
|
||||||
dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
#dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
||||||
# note: image version is matched to version used by dither
|
# note: image version is matched to version used by dither
|
||||||
image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true }
|
image = { version = "0.23", default-features = false, features = ["png"], optional = true }
|
||||||
fast_image_resize = {version = "0.9.2", optional = true}
|
fast_image_resize = {version = "0.9.2", optional = true}
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
|
|
@ -33,5 +33,5 @@ utralib = { path = "../../utralib"}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tts = []
|
tts = []
|
||||||
ditherpunk = ["image", "dither", "fast_image_resize"]
|
ditherpunk = ["image", "fast_image_resize"]
|
||||||
default = []
|
default = []
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,63 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature="ditherpunk")]
|
||||||
|
"image" => {
|
||||||
|
const MAX_IMAGE_LEN: usize = 256 * 1024; // includes HTTP headers
|
||||||
|
if let Some(url) = tokens.next() {
|
||||||
|
match url.split_once('/') {
|
||||||
|
Some((host, path)) => {
|
||||||
|
match TcpStream::connect((host, 80)) {
|
||||||
|
Ok(mut stream) => {
|
||||||
|
let mut heap_image = match xous::syscall::map_memory(
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
MAX_IMAGE_LEN,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
) {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("couldn't allocate data for image, aborting");
|
||||||
|
write!(ret, "Couldn't allocate memory for image, aborting: {:?}", e).unwrap();
|
||||||
|
return Ok(Some(ret));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
stream.set_read_timeout(Some(Duration::from_millis(10_000))).unwrap();
|
||||||
|
stream.set_write_timeout(Some(Duration::from_millis(10_000))).unwrap();
|
||||||
|
match write!(stream, "GET /{} HTTP/1.1\r\n", path) {
|
||||||
|
Ok(_) => log::trace!("sent GET"),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("GET err {:?}", e);
|
||||||
|
write!(ret, "Error sending GET: {:?}", e).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write!(stream, "Host: {}\r\nAccept: */*\r\nUser-Agent: Precursor/0.9.6\r\n", host).expect("stream error");
|
||||||
|
write!(stream, "Connection: close\r\n").expect("stream error");
|
||||||
|
write!(stream, "\r\n").expect("stream error");
|
||||||
|
log::info!("fetching response....");
|
||||||
|
match stream.read(heap_image.as_slice_mut()) {
|
||||||
|
Ok(len) => {
|
||||||
|
log::info!("fetched {} bytes of http data", len);
|
||||||
|
}
|
||||||
|
Err(e) => write!(ret, "Didn't get response from host: {:?}", e).unwrap(),
|
||||||
|
}
|
||||||
|
if let Some(start) = find_subsequence(
|
||||||
|
heap_image.as_slice::<u8>(),
|
||||||
|
&[0x0d, 0x0a, 0x0d, 0x0a], // this is \r\n\r\n, which indicates end of header.
|
||||||
|
) {
|
||||||
|
log::info!("image data is {} bytes long", heap_image.len() - start);
|
||||||
|
}
|
||||||
|
xous::syscall::unmap_memory(heap_image).expect("couldn't de-allocate image memory");
|
||||||
|
}
|
||||||
|
Err(e) => write!(ret, "Couldn't connect to {}:80: {:?}", host, e).unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => write!(ret, "Usage: image bunniefoo.com/bunnie/bunny.png").unwrap(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write!(ret, "Usage: image bunniefoo.com/bunnie/bunny.png").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
"tls" => {
|
"tls" => {
|
||||||
write!(ret, "Work in progress. Please check back later!").unwrap();
|
write!(ret, "Work in progress. Please check back later!").unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -417,6 +474,12 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// yep. this is from stackoverflow copypasta
|
||||||
|
#[cfg(feature="ditherpunk")]
|
||||||
|
fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Option<usize> {
|
||||||
|
haystack.windows(needle.len()).position(|window| window == needle)
|
||||||
|
}
|
||||||
|
|
||||||
enum Responses {
|
enum Responses {
|
||||||
Uptime,
|
Uptime,
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue