use super::*;
mod util;
use crate::test_util::*;
use util::*;
use crate::nb_device::Event;
#[test]
fn test_join_rx1() {
let mut device = test_device();
let response = device.join(get_otaa_credentials()).unwrap();
assert!(matches!(response, Response::TimeoutRequest(5000)));
let response = device.handle_event(Event::TimeoutFired).unwrap();
assert!(matches!(response, Response::TimeoutRequest(5100)));
device.get_radio().set_rxtx_handler(handle_join_request::<1>);
let response = device.handle_event(Event::RadioEvent(radio::Event::Phy(()))).unwrap();
assert!(matches!(response, Response::JoinSuccess));
assert!(device.get_session_keys().is_some());
}
#[test]
fn test_join_rx2() {
let mut device = test_device();
device.get_radio().set_rxtx_handler(handle_join_request::<2>);
let response = device.join(get_otaa_credentials()).unwrap();
assert!(matches!(response, Response::TimeoutRequest(5000)));
let response = device.handle_event(Event::TimeoutFired).unwrap();
assert!(matches!(response, Response::TimeoutRequest(5100)));
let response = device.handle_event(Event::TimeoutFired).unwrap();
assert!(matches!(response, Response::TimeoutRequest(6000)));
let response = device.handle_event(Event::TimeoutFired).unwrap();
assert!(matches!(response, Response::TimeoutRequest(6100)));
let response = device.handle_event(Event::RadioEvent(radio::Event::Phy(()))).unwrap();
assert!(matches!(response, Response::JoinSuccess));
assert!(device.get_session_keys().is_some());
}
#[test]
fn test_unconfirmed_uplink_no_downlink() {
let mut device = test_device();
device.join(get_abp_credentials()).unwrap();
let response = device.send(&[0; 1], 1, false).unwrap();
assert!(matches!(response, Response::TimeoutRequest(1000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(1100)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(2000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(2100)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::RxComplete));
}
#[test]
fn test_confirmed_uplink_no_ack() {
let mut device = test_device();
let response = device.join(get_abp_credentials());
assert!(matches!(response, Ok(Response::JoinSuccess)));
let response = device.send(&[0; 1], 1, true).unwrap();
assert!(matches!(response, Response::TimeoutRequest(1000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(1100)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(2000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(2100)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::NoAck));
}
#[test]
fn test_confirmed_uplink_with_ack_rx1() {
let mut device = test_device();
let response = device.join(get_abp_credentials());
assert!(matches!(response, Ok(Response::JoinSuccess)));
let response = device.send(&[0; 1], 1, true).unwrap();
assert!(matches!(response, Response::TimeoutRequest(1000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(1100)));
device.get_radio().set_rxtx_handler(handle_data_uplink_with_link_adr_req::<0, 0>);
let response = device.handle_event(Event::RadioEvent(radio::Event::Phy(()))).unwrap();
assert!(matches!(response, Response::DownlinkReceived(0)));
}
#[test]
fn test_confirmed_uplink_with_ack_rx2() {
let mut device = test_device();
let response = device.join(get_abp_credentials());
assert!(matches!(response, Ok(Response::JoinSuccess)));
let response = device.send(&[0; 1], 1, true).unwrap();
assert!(matches!(response, Response::TimeoutRequest(1000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(1100)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(2000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(2100)));
device.get_radio().set_rxtx_handler(handle_data_uplink_with_link_adr_req::<0, 0>);
let response = device.handle_event(Event::RadioEvent(radio::Event::Phy(()))).unwrap();
assert!(matches!(response, Response::DownlinkReceived(0)));
}
#[test]
fn test_link_adr_ans() {
let mut device = test_device();
let response = device.join(get_abp_credentials());
assert!(matches!(response, Ok(Response::JoinSuccess)));
let response = device.send(&[0; 1], 1, true).unwrap();
assert!(matches!(response, Response::TimeoutRequest(1000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(1100)));
device.get_radio().set_rxtx_handler(handle_data_uplink_with_link_adr_req::<0, 0>);
let response = device.handle_event(Event::RadioEvent(radio::Event::Phy(()))).unwrap();
assert!(matches!(response, Response::DownlinkReceived(0)));
let response = device.send(&[0; 1], 1, true).unwrap();
assert!(matches!(response, Response::TimeoutRequest(1000)));
let response = device.handle_event(Event::TimeoutFired).unwrap(); assert!(matches!(response, Response::TimeoutRequest(1100)));
device.get_radio().set_rxtx_handler(handle_data_uplink_with_link_adr_ans);
let response = device.handle_event(Event::RadioEvent(radio::Event::Phy(()))).unwrap();
assert!(matches!(response, Response::DownlinkReceived(1)));
}