+ match self.state {
+ State::Idle | State::RxAcquiringStream(_) | State::RxStream(_) | State::RxPacket(_) => {
+ // We will let CSMA decide whether to actually go ahead.
+ // That's not implemented yet, so let's just check DCD.
+ let channel_free = !self.dcd;
+ let stream_wants_to_tx = self.stream_pending_lsf.is_some();
+ let packet_wants_to_tx = self.packet_full || (self.packet_next != self.packet_curr);
+ if channel_free && stream_wants_to_tx {
+ self.state = State::TxStream;
+ } else if channel_free && packet_wants_to_tx {
+ self.state = State::TxPacket;
+ } else {
+ return None;
+ }
+ self.ptt = true;
+ // TODO: true txdelay
+ Some(ModulatorFrame::Preamble { tx_delay: 0 })
+ }
+ State::TxStream => {
+ if !self.stream_full && self.stream_next == self.stream_curr {
+ return None;
+ }
+ if let Some(lsf) = self.stream_pending_lsf.take() {
+ return Some(ModulatorFrame::Lsf(lsf));
+ }
+ let frame = self.stream_queue[self.stream_curr].clone();
+ if self.stream_full {
+ self.stream_full = false;
+ }
+ self.stream_curr = (self.stream_curr + 1) % 8;
+ if frame.end_of_stream {
+ self.state = State::Idle;
+ }
+ Some(ModulatorFrame::Stream(frame))
+ }
+ State::TxStreamSentEndOfStream => {
+ self.state = State::TxEnding;
+ Some(ModulatorFrame::EndOfTransmission)
+ }
+ State::TxPacket => {
+ if !self.packet_full && self.packet_next == self.packet_curr {
+ return None;
+ }
+ while self.packet_next != self.packet_curr {
+ match self.packet_queue[self.packet_curr].next_frame() {
+ Some(frame) => {
+ return Some(frame);
+ }
+ None => {
+ self.packet_curr = (self.packet_curr + 1) % 4;
+ }
+ }
+ }
+ self.state = State::TxEnding;
+ Some(ModulatorFrame::EndOfTransmission)
+ }
+ State::TxEnding | State::TxEndingAtTime(_) => {
+ // Once we have signalled EOT we withold any new frames until
+ // the channel fully clears and we are ready to TX again
+ None
+ }
+ }