]> code.octet-stream.net Git - m17rt/blob - m17app/src/tnc.rs
Start handling TNC->host messages with KissBuffer
[m17rt] / m17app / src / tnc.rs
1 use std::io::{self, ErrorKind, Read, Write};
2
3 use m17core::tnc::SoftTnc;
4
5 ///
6 pub trait Tnc: Read + Write + Sized {
7 fn try_clone(&mut self) -> Result<Self, TncError>;
8 fn start(&mut self) -> Result<(), TncError>;
9 fn close(&mut self) -> Result<(), TncError>;
10 }
11
12 #[derive(Debug)]
13 pub enum TncError {
14 General(String),
15 }
16
17 // TODO: move the following to its own module
18
19 pub struct Soundmodem {
20 tnc: SoftTnc,
21 config: SoundmodemConfig,
22 }
23
24 pub struct SoundmodemConfig {
25 // sound cards, PTT, etc.
26 }
27
28 impl Read for Soundmodem {
29 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
30 self.tnc
31 .read_kiss(buf)
32 .map_err(|s| io::Error::new(ErrorKind::Other, format!("{:?}", s)))
33 }
34 }
35
36 impl Write for Soundmodem {
37 fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
38 self.tnc
39 .write_kiss(buf)
40 .map_err(|s| io::Error::new(ErrorKind::Other, format!("{:?}", s)))
41 }
42
43 fn flush(&mut self) -> std::io::Result<()> {
44 Ok(())
45 }
46 }
47
48 impl Tnc for Soundmodem {
49 fn try_clone(&mut self) -> Result<Self, TncError> {
50 unimplemented!();
51 }
52
53 fn start(&mut self) -> Result<(), TncError> {
54 unimplemented!();
55 }
56
57 fn close(&mut self) -> Result<(), TncError> {
58 unimplemented!();
59 }
60 }