| 80 | I: CpuBufferReader<Item = f32>, |
| 81 | { |
| 82 | async fn work( |
| 83 | &mut self, |
| 84 | io: &mut WorkIo, |
| 85 | mo: &mut MessageOutputs, |
| 86 | _meta: &BlockMeta, |
| 87 | ) -> Result<()> { |
| 88 | let inbuf = self.input.slice().to_vec(); |
| 89 | let inbuf_len = inbuf.len(); |
| 90 | |
| 91 | for v in inbuf.into_iter() { |
| 92 | if v > 0.0 { |
| 93 | self.correlator.shift_reg = (self.correlator.shift_reg << 1) | 1; |
| 94 | } else { |
| 95 | self.correlator.shift_reg <<= 1; |
| 96 | } |
| 97 | |
| 98 | self.chip_count = (self.chip_count + 1) % 32; |
| 99 | |
| 100 | match &mut self.state { |
| 101 | State::Search => { |
| 102 | if self.correlator.matching(0) { |
| 103 | // info!("premable found"); |
| 104 | self.state = State::PreambleFound; |
| 105 | self.chip_count = 0; |
| 106 | } |
| 107 | } |
| 108 | State::PreambleFound => { |
| 109 | if self.chip_count == 0 { |
| 110 | if self.correlator.matching(7) { |
| 111 | self.state = State::SearchSfd; |
| 112 | } else if !self.correlator.matching(0) { |
| 113 | self.state = State::Search; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | State::SearchSfd => { |
| 118 | if self.chip_count == 0 { |
| 119 | if self.correlator.matching(10) { |
| 120 | self.state = State::SearchHeader { byte: None }; |
| 121 | } else { |
| 122 | self.state = State::Search; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | State::SearchHeader { byte } => { |
| 127 | if self.chip_count == 0 { |
| 128 | if let Some(i) = |
| 129 | decode(self.correlator.shift_reg, self.correlator.threshold) |
| 130 | { |
| 131 | if let Some(o) = byte { |
| 132 | let len = (i << 4) | *o; |
| 133 | if len < 128 { |
| 134 | self.state = State::Decode { |
| 135 | len: len as usize, |
| 136 | data: Vec::new(), |
| 137 | byte: None, |
| 138 | }; |
| 139 | } else { |