1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![warn(unused_imports)]
mod decoding;
mod encoding;
pub mod consts {
use core::num::NonZeroU32;
pub const LEAD_PULSE_LENGTH : NonZeroU32 = unsafe { NonZeroU32::new_unchecked(2168) };
pub const SYNC_PULSE1_LENGTH: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(667) };
pub const SYNC_PULSE2_LENGTH: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(735) };
pub const ZERO_PULSE_LENGTH : NonZeroU32 = unsafe { NonZeroU32::new_unchecked(855) };
pub const ONE_PULSE_LENGTH : NonZeroU32 = unsafe { NonZeroU32::new_unchecked(1710) };
pub const PAUSE_PULSE_LENGTH: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(3_500_000) };
pub const LEAD_PULSES_HEAD: u16 = 8063;
pub const LEAD_PULSES_DATA: u16 = 3223;
}
pub use decoding::*;
pub use encoding::*;
#[cfg(test)]
mod tests {
use std::fs::File;
use std::io::{Cursor, Result, Seek, SeekFrom, Read};
use crate::tap::*;
#[test]
fn tap_pulse_works() -> Result<()> { let file = File::open("../resources/read_tap_test.tap")?;
let mut pulse_iter = read_tap_pulse_iter(file);
let mut tap_writer = write_tap(Cursor::new(Vec::new()))?;
assert_eq!(5, tap_writer.write_pulses_as_tap_chunks(&mut pulse_iter)?);
assert_eq!(1, tap_writer.end_pulse_chunk()?);
let tgt: Vec<u8> = tap_writer.into_inner().into_inner().into_inner();
let mut file: File = pulse_iter.into_inner().into_inner().into_inner();
file.seek(SeekFrom::Start(0))?;
let mut src = Vec::new();
file.read_to_end(&mut src)?;
assert_eq!(src, tgt);
Ok(())
}
}