From b4ef18b2fa7861c2286628457f51e74bfd2d440f Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Tue, 23 May 2017 21:07:59 +0200 Subject: [PATCH] Keep cca scan function separated modified: examples/rf_environment/rf_environment.c --- examples/rf_environment/rf_environment.c | 34 +++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/examples/rf_environment/rf_environment.c b/examples/rf_environment/rf_environment.c index 2d587fe0b..fc7be6f4e 100644 --- a/examples/rf_environment/rf_environment.c +++ b/examples/rf_environment/rf_environment.c @@ -132,6 +132,25 @@ set_cca_thresh(radio_value_t thresh) } return 0; } + +void +do_all_chan_cca(int *cca, int try) +{ + int j; + for(j = 0; j < 16; j++) { + set_chan(j+11); + cca[j] = 0; +#ifdef CONTIKI_TARGET_AVR_RSS2 + watchdog_periodic(); +#endif + NETSTACK_RADIO.on(); + for(i = 0; i < try; i++) { + cca[j] += NETSTACK_RADIO.channel_clear(); + } + NETSTACK_RADIO.off(); + } +} + PROCESS_THREAD(rf_scan_process, ev, data) { PROCESS_BEGIN(); @@ -155,18 +174,9 @@ PROCESS_THREAD(rf_scan_process, ev, data) for(k = -90; k <= -60; k += 2) { set_cca_thresh(k); - for(j = 0; j < 16; j++) { - set_chan(j+11); - cca[j] = 0; -#ifdef CONTIKI_TARGET_AVR_RSS2 - watchdog_periodic(); -#endif - NETSTACK_RADIO.on(); - for(i = 0; i < SAMPLES; i++) { - cca[j] += NETSTACK_RADIO.channel_clear(); - } - NETSTACK_RADIO.off(); - } + + do_all_chan_cca(cca, SAMPLES); + printf("cca_thresh=%-3ddBm", get_cca_thresh()); worst = 0;