From 359a6ebaf59aa19699cbd61b07406999e6732373 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 4 Sep 2018 09:20:59 +0200 Subject: Rework rfm95 and kiss --- src/kiss.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/kiss.rs') 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 } impl<'a> KissDecoder<'a> { - pub fn new(stream: &T) -> io::Result + pub fn new(stream: &'a mut T) -> io::Result where T: Read { Ok(KissDecoder { @@ -36,22 +35,21 @@ impl<'a> KissDecoder<'a> { } } -/* -pub struct KissEncoder { - stream: Write, - buffer: Vec +pub struct KissEncoder<'a> { + stream: &'a mut Write, } -impl KissEncoder { - pub fn new(stream: Write) -> io::Result { +impl<'a> KissEncoder<'a> { + pub fn new(stream: &'a mut T) -> io::Result + 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) -> Option> { } 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]); } -*/ -- cgit v1.2.3