pub fn decode_bytes(samples: Vec<f32>, sample_rate_hz: f32, dft_size: usize) -> Vec<Vec<u8>> {
    const PREAMBLE: [Bit; 8] = [Bit::One, Bit::One, Bit::Zero, Bit::One, Bit::Zero, Bit::One,
                                Bit::Zero, Bit::One];
    let mut bytestrings = Vec::new();
    let mut decoded_bytes = Vec::new();
    let mut curr_byte = 0u8;
    let mut curr_byte_pos = 0u8;
    let mut decoding = false;
    let mut last_byte: [Bit; 8] = [Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate];
    let bits = BitIterator::new(samples, sample_rate_hz, dft_size);
    for bit in bits {
        if !decoding {
            for i in 0..7 {
                last_byte[i] = last_byte[i + 1]
            }
            last_byte[7] = bit;
            if last_byte == PREAMBLE {
                // Start decoding when we detect a preamble byte
                decoding = true;
                curr_byte = 0xab;
                curr_byte_pos = 7;
            }
        }
        if decoding {
            match bit {
                Bit::Zero => {
                    // Do nothing
                }
                Bit::One => {
                    curr_byte |= 1 << curr_byte_pos;
                }
                Bit::Indeterminate => {
                    // Message ended
                    decoding = false;
                    bytestrings.push(decoded_bytes);
                    decoded_bytes = Vec::new();
                }
            }
            curr_byte_pos = (curr_byte_pos + 1) % 8;
            if curr_byte_pos == 0 {
                decoded_bytes.push(curr_byte);
                curr_byte = 0;
            }
        }
    }
    bytestrings
}
/// Decode an FSK-encoded SAME signal into strings of bytes
Decode an FSK-encoded SAME signal into strings of bytes
Decode an FSK - encoded SAME signal into strings of bytes
pub fn decode_bytes(samples: Vec<f32>, sample_rate_hz: f32, dft_size: usize) -> Vec<Vec<u8>> {
    const PREAMBLE: [Bit; 8] = [Bit::One, Bit::One, Bit::Zero, Bit::One, Bit::Zero, Bit::One,
                                Bit::Zero, Bit::One];
    let mut bytestrings = Vec::new();
    let mut decoded_bytes = Vec::new();
    let mut curr_byte = 0u8;
    let mut curr_byte_pos = 0u8;
    let mut decoding = false;
    let mut last_byte: [Bit; 8] = [Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate,
                                   Bit::Indeterminate];
    let bits = BitIterator::new(samples, sample_rate_hz, dft_size);
    for bit in bits {
        if !decoding {
            for i in 0..7 {
                last_byte[i] = last_byte[i + 1]
            }
            last_byte[7] = bit;
            if last_byte == PREAMBLE {
                // Start decoding when we detect a preamble byte
                decoding = true;
                curr_byte = 0xab;
                curr_byte_pos = 7;
            }
        }
        if decoding {
            match bit {
                Bit::Zero => {
                    // Do nothing
                }
                Bit::One => {
                    curr_byte |= 1 << curr_byte_pos;
                }
                Bit::Indeterminate => {
                    // Message ended
                    decoding = false;
                    bytestrings.push(decoded_bytes);
                    decoded_bytes = Vec::new();
                }
            }
            curr_byte_pos = (curr_byte_pos + 1) % 8;
            if curr_byte_pos == 0 {
                decoded_bytes.push(curr_byte);
                curr_byte = 0;
            }
        }
    }
    bytestrings
}
pub fn decode_bytes ( samples : Vec < f32 > , sample_rate_hz : f32 , dft_size : usize ) -> Vec < Vec < u8 > > { const PREAMBLE : [ Bit ; 8 ] = [ Bit :: One , Bit :: One , Bit :: Zero , Bit :: One , Bit :: Zero , Bit :: One , Bit :: Zero , Bit :: One ] ; let mut bytestrings = Vec :: new ( ) ; let mut decoded_bytes = Vec :: new ( ) ; let mut curr_byte = 0u8 ; let mut curr_byte_pos = 0u8 ; let mut decoding = false ; let mut last_byte : [ Bit ; 8 ] = [ Bit :: Indeterminate , Bit :: Indeterminate , Bit :: Indeterminate , Bit :: Indeterminate , Bit :: Indeterminate , Bit :: Indeterminate , Bit :: Indeterminate , Bit :: Indeterminate ] ; let bits = BitIterator :: new ( samples , sample_rate_hz , dft_size ) ; for bit in bits { if ! decoding { for i in 0 .. 7 { last_byte [ i ] = last_byte [ i + 1 ] } last_byte [ 7 ] = bit ; if last_byte == PREAMBLE { // Start decoding when we detect a preamble byte decoding = true ; curr_byte = 0xab ; curr_byte_pos = 7 ; } } if decoding { match bit { Bit :: Zero => { // Do nothing } Bit :: One => { curr_byte |= 1 << curr_byte_pos ; } Bit :: Indeterminate => { // Message ended decoding = false ; bytestrings . push ( decoded_bytes ) ; decoded_bytes = Vec :: new ( ) ; } } curr_byte_pos = ( curr_byte_pos + 1 ) % 8 ; if curr_byte_pos == 0 { decoded_bytes . push ( curr_byte ) ; curr_byte = 0 ; } } } bytestrings }
Decode an FSK-encoded SAME signal into strings of bytes
Decode an FSK - encoded SAME signal into strings of bytes
samples
Vec<f32>
sample_rate_hz
f32
dft_size
usize