MCPcopy Create free account
hub / github.com/FutureSDR/FutureSDR / work

Method work

examples/zigbee/src/decoder.rs:82–182  ·  view source on GitHub ↗
(
        &mut self,
        io: &mut WorkIo,
        mo: &mut MessageOutputs,
        _meta: &mut BlockMeta,
    )

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 9

decodeFunction · 0.85
lenMethod · 0.80
into_iterMethod · 0.80
matchingMethod · 0.80
pushMethod · 0.80
sliceMethod · 0.45
postMethod · 0.45
finishedMethod · 0.45
consumeMethod · 0.45

Tested by

no test coverage detected