rust-iot / rust-radio-sx127x

Rust driver for the Semtech SX127x series of Sub-GHz LoRa/ISM radio transceivers
Mozilla Public License 2.0
33 stars 16 forks source link

lora_check_receive restart argument #13

Closed pdgilbert closed 7 months ago

pdgilbert commented 3 years ago

Following code in the tests/integration.rs file I have my lora_sp_receive example working on an stm32f411 but I am confused by the restart option, especial a true setting, and not sure if I correctly understand the comment (src/lora.rs line 336)

/// This returns true if a boolean indicating whether a packet has been received.
/// The restart option specifies whether transient timeout or CRC errors should be
/// internally handled (returning Ok(false)) or passed back to the caller as errors.

Does that mean that

Why is the argument called "restart option"?

Which restart option do you suggest in what situations?

For reference, the example code is at https://github.com/pdgilbert/eg_stm_hal/blob/master/examples/lora_spi_receive.rs and currently the main part is

#[entry]
fn main() -> !{

    let mut lora =  setup();         //delay is available in lora

    lora.start_receive().unwrap();   // should handle error

    let mut buff = [0u8; 1024];
    let mut n: usize ;
    let mut info = PacketInfo::default();

    loop {

       let poll = lora.check_receive(false);    

       match poll {
            Ok(v)  if v  =>  {n = lora.get_received(&mut info, &mut buff).unwrap();
                              hprintln!("RX complete ({:?}, length: {})", info, n).unwrap();
                              //hprintln!("{:?}", &buff[..n]).unwrap();
                              hprintln!("{}", to_str(&buff[..n])).unwrap();
                              },

            Ok(_v)       =>  hprint!(".").unwrap(),           // print . if nothing received

        Err(err)     =>  hprintln!("poll error {:?} ", err).unwrap(),
            };

       lora.delay_ms(100u32);
       };

}
ryankurte commented 3 years ago

as you've determined you need to poll on check_receive to see whether something is received, all of this is just interacting with the internal radio state machine.

setting restart lets the driver internally deal with any CRC or recoverable errors and re-enter receive mode (if it can, otherwise you'll still get an error), not setting this returns errors to the higher level for handling but requires another start_receive call to return the radio to receive mode when an error occurs. you can see the code for this here

pdgilbert commented 3 years ago

Ok, I think I understand. I guess there are not concepts of optional or default arguments in Rust, and restartis bool rather than Option(bool), so I suppose by "setting it" you mean setting intrue and by "not setting it" you mean setting it false. (I realize this is a bit pedantic but I have a differ background.)

ryankurte commented 3 years ago

yeah pretty much, it could be an object with more stuff but, that's also adding another associated type which as you've discovered proportionately increases the complexity of integrating traits... a documentation improvement would be welcome if you can think of a better way of presenting this

pdgilbert commented 7 months ago

This issue is out-of-date and effectively resolved.