diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-09-04 09:20:59 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-09-04 09:20:59 +0200 |
commit | 359a6ebaf59aa19699cbd61b07406999e6732373 (patch) | |
tree | d758f8dad49094ac6a7aa15dd0e817b2cf3c1cc5 /src/kiss.rs | |
parent | 4c9f3c8dbfc67d9e1f8479538ba9c9b6dc3be5c4 (diff) | |
download | raspi-rfm95-kiss-359a6ebaf59aa19699cbd61b07406999e6732373.tar.gz raspi-rfm95-kiss-359a6ebaf59aa19699cbd61b07406999e6732373.tar.bz2 raspi-rfm95-kiss-359a6ebaf59aa19699cbd61b07406999e6732373.zip |
Diffstat (limited to 'src/kiss.rs')
-rw-r--r-- | src/kiss.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/kiss.rs b/src/kiss.rs index 397922d..e9f4703 100644 --- a/src/kiss.rs +++ b/src/kiss.rs @@ -1,7 +1,6 @@ // Taken from ax25-rs, which is // SPDX-License-Identifier: Apache-2.0 use std::io; -use std::io::prelude::*; use std::io::{Read, Write}; const FEND: u8 = 0xC0; @@ -10,12 +9,12 @@ const TFEND: u8 = 0xDC; const TFESC: u8 = 0xDD; pub struct KissDecoder<'a> { - stream: &'a Read, + stream: &'a mut Read, buffer: Vec<u8> } impl<'a> KissDecoder<'a> { - pub fn new<T>(stream: &T) -> io::Result<KissDecoder> + pub fn new<T>(stream: &'a mut T) -> io::Result<KissDecoder> where T: Read { Ok(KissDecoder { @@ -36,22 +35,21 @@ impl<'a> KissDecoder<'a> { } } -/* -pub struct KissEncoder { - stream: Write, - buffer: Vec<u8> +pub struct KissEncoder<'a> { + stream: &'a mut Write, } -impl KissEncoder { - pub fn new(stream: Write) -> io::Result<KissEncoder> { +impl<'a> KissEncoder<'a> { + pub fn new<T>(stream: &'a mut T) -> io::Result<KissEncoder> + where T: Write + { Ok(KissEncoder { stream: stream, - buffer: Vec::new() }) } pub fn send_frame(&mut self, frame: &[u8]) -> io::Result<()> { - // 0x00 is the KISS command byte, which is two nybbles + // 0x00 is the KISS command byte, which is two nibbles // port = 0 // command = 0 (all following bytes are a data frame to transmit) self.stream.write(&[FEND, 0x00])?; @@ -72,7 +70,7 @@ fn make_frame_from_buffer(buffer: &mut Vec<u8>) -> Option<Vec<u8>> { } let mut state = Scan::LookingForStartMarker; let mut final_idx = 0; - + // Check for possible frame read-only until we know we have a complete frame // If we take one out, clear out buffer up to the final index for (idx, &c) in buffer.iter().enumerate() { @@ -180,4 +178,3 @@ fn test_two_frames_double_fend() { assert_eq!(make_frame_from_buffer(&mut rx), Some(vec![0x03, 0x04])); assert_eq!(rx, vec![FEND]); } -*/ |