use buffer::Buffer;
use storage::Storage;
+use yencode::Yencode;
+use systick;
pub struct Shell<'a> {
tx_buf: &'a mut Buffer,
}
}
+fn read_char_delay_ms(limit_ms: u32) -> Option<u8> {
+ let mut total_delay_ms = 0u32;
+
+ while total_delay_ms < limit_ms {
+ if let Some(c) = read_char() {
+ return Some(c);
+ }
+
+ let ms = 50;
+
+ systick::delay_ms(ms);
+ total_delay_ms += ms;
+ }
+
+ None
+}
+
struct Context<'a> {
storage: &'a mut dyn Storage,
}
Supported commands:
help Show this help message.
clear_storage Fully erase the flash's contents.
+ dump_storage Dump the flash's contents.
";
self.tx_buf.write(usage);
},
Some(b"clear_storage") => self.run_clear_storage(&mut context),
+ Some(b"dump_storage") => self.run_dump_storage(&mut context),
Some(ref other) => {
self.tx_buf.write(b"unknown_command: ");
fn run_clear_storage(&self, context: &mut Context) {
context.storage.clear();
}
+
+ fn run_dump_storage(&mut self, context: &mut Context) {
+ self.tx_buf.write(b"waiting for receiver to start...\n");
+ self.tx_buf.flush();
+
+ let have_receiver = read_char_delay_ms(5000).map(|c| {
+ c == b'R'
+ }).map_or_else(|| {
+ false
+ }, |_| {
+ let mut yenc = Yencode::new(&mut self.tx_buf);
+
+ yenc.start(b"gps-watch-storage.bin");
+
+ const CHUNK_SIZE: usize = 1024;
+ let num_chunks = context.storage.size() / CHUNK_SIZE;
+
+ for i in 0..num_chunks {
+ let mut buf = [0u8; CHUNK_SIZE];
+
+ context.storage.read(i * CHUNK_SIZE, &mut buf);
+
+ yenc.data(&buf);
+ }
+
+ yenc.finish();
+
+ true
+ });
+
+ if !have_receiver {
+ self.tx_buf.write(b"no signal from receiver\n");
+ }
+
+ self.tx_buf.flush();
+ }
}