projects
/
gps-watch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
application: Set up a Logger instance.
[gps-watch.git]
/
src
/
common
/
shell.rs
diff --git
a/src/common/shell.rs
b/src/common/shell.rs
index 730a0a89fd78a85131fe221d943d5f5425ef0426..bb59b62e322f62edd5e81685d9cf4664361f3837 100644
(file)
--- a/
src/common/shell.rs
+++ b/
src/common/shell.rs
@@
-22,7
+22,7
@@
*/
use buffer::Buffer;
*/
use buffer::Buffer;
-use
storage::Storage
;
+use
logger::Logger
;
use yencode::Yencode;
use systick;
use yencode::Yencode;
use systick;
@@
-108,10
+108,6
@@
fn read_char_delay_ms(limit_ms: u32) -> Option<u8> {
None
}
None
}
-struct Context<'a> {
- storage: &'a mut dyn Storage,
-}
-
impl<'a> Shell<'a> {
pub fn new(tx_buf: &mut Buffer) -> Shell {
Shell {
impl<'a> Shell<'a> {
pub fn new(tx_buf: &mut Buffer) -> Shell {
Shell {
@@
-121,11
+117,7
@@
impl<'a> Shell<'a> {
}
}
}
}
- pub fn update(&mut self, storage: &mut dyn Storage) {
- let mut context = Context {
- storage: storage,
- };
-
+ pub fn update(&mut self, logger: &mut Logger) {
while let Some(c) = read_char() {
if c != b'\n' {
if self.command_offset != self.command_buffer.len() {
while let Some(c) = read_char() {
if c != b'\n' {
if self.command_offset != self.command_buffer.len() {
@@
-140,7
+132,7
@@
impl<'a> Shell<'a> {
self.command_buffer[command_length] = b'\0';
if command_length != 0 {
self.command_buffer[command_length] = b'\0';
if command_length != 0 {
- self.dispatch(command_length,
&mut context
);
+ self.dispatch(command_length,
logger
);
}
} else {
self.command_buffer[self.command_offset] = b'\0';
}
} else {
self.command_buffer[self.command_offset] = b'\0';
@@
-154,7
+146,7
@@
impl<'a> Shell<'a> {
}
}
}
}
- fn dispatch(&mut self, command_length: usize,
mut context: &mut Context
) {
+ fn dispatch(&mut self, command_length: usize,
logger: &mut Logger
) {
let command : [u8; 32] = self.command_buffer;
let mut args_iter = ArgumentIter {
let command : [u8; 32] = self.command_buffer;
let mut args_iter = ArgumentIter {
@@
-174,8
+166,8
@@
Supported commands:
self.tx_buf.write(usage);
},
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(b"clear_storage") => self.run_clear_storage(
logger
),
+ Some(b"dump_storage") => self.run_dump_storage(
logger
),
Some(ref other) => {
self.tx_buf.write(b"unknown_command: ");
Some(ref other) => {
self.tx_buf.write(b"unknown_command: ");
@@
-188,11
+180,11
@@
Supported commands:
}
}
}
}
- fn run_clear_storage(&self,
context: &mut Context
) {
-
context
.storage.clear();
+ fn run_clear_storage(&self,
logger: &mut Logger
) {
+
logger
.storage.clear();
}
}
- fn run_dump_storage(&mut self,
context: &mut Context
) {
+ fn run_dump_storage(&mut self,
logger: &mut Logger
) {
self.tx_buf.write(b"waiting for receiver to start...\n");
self.tx_buf.flush();
self.tx_buf.write(b"waiting for receiver to start...\n");
self.tx_buf.flush();
@@
-206,12
+198,12
@@
Supported commands:
yenc.start(b"gps-watch-storage.bin");
const CHUNK_SIZE: usize = 1024;
yenc.start(b"gps-watch-storage.bin");
const CHUNK_SIZE: usize = 1024;
- let num_chunks =
context
.storage.size() / CHUNK_SIZE;
+ let num_chunks =
logger
.storage.size() / CHUNK_SIZE;
for i in 0..num_chunks {
let mut buf = [0u8; CHUNK_SIZE];
for i in 0..num_chunks {
let mut buf = [0u8; CHUNK_SIZE];
-
context
.storage.read(i * CHUNK_SIZE, &mut buf);
+
logger
.storage.read(i * CHUNK_SIZE, &mut buf);
yenc.data(&buf);
}
yenc.data(&buf);
}