Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00037
00038 #include "sniffer.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047 static void show_status(channel_t choffs);
00048 time_t timer_scan(timer_arg_t t);
00049
00050
00051
00055 void scan_init(void)
00056 {
00057
00058 PRINTF("Scanning channels, scan period %ums"NL,
00059 SCAN_PERIOD_MS);
00060 PRINT(" bad"
00061 " Avg. "
00062 " 802.15.4 frames "
00063 " "NL);
00064 PRINT("chan frm crc "
00065 " ed lqi "
00066 " B D A C "
00067 " PER"NL);
00068
00069 ctx.cchan = TRX_MIN_CHANNEL;
00070 trx_bit_write(SR_CHANNEL, ctx.cchan);
00071 trx_reg_write(RG_TRX_STATE, CMD_RX_ON);
00072
00073 ctx.thdl = timer_start(timer_scan,MSEC(SCAN_PERIOD_MS),0);
00074 }
00075
00079 void scan_update_status(void)
00080 {
00081 scan_result_t *scres;
00082 uint32_t cmask;
00083
00084 cmask = TRX_SUPPORTED_CHANNELS;
00085 do
00086 {
00087 show_status(ctx.cchan);
00088 ctx.cchan += 1;
00089 if (ctx.cchan > TRX_MAX_CHANNEL)
00090 {
00091 ctx.cchan = TRX_MIN_CHANNEL;
00092 }
00093 cmask &= ~(1UL<<ctx.cchan);
00094 if(((ctx.cmask & (1UL<<ctx.cchan)) != 0) || (cmask == 0))
00095 {
00096
00097
00098 break;
00099 }
00100 }
00101 while(1);
00102 if (ctx.scanres_reset)
00103 {
00104 scres = &ctx.scanres[CHANNEL_OFFSET(ctx.cchan)];
00105 memset(scres,0,sizeof(scan_result_t));
00106 if (ctx.scanres_reset < 32)
00107 {
00108 ctx.scanres_reset --;
00109 }
00110 }
00111
00112
00113 trx_bit_write(SR_CHANNEL, ctx.cchan);
00114 cli();
00115 ctx.state = SCAN;
00116 sei();
00117
00118 ctx.thdl = timer_start(timer_scan,MSEC(SCAN_PERIOD_MS),0);
00119
00120 }
00121
00126 static void show_status(channel_t channel)
00127 {
00128 static uint16_t updates = 0;
00129 scan_result_t *scres;
00130 uint16_t per = 0, lqi, ed;
00131 uint8_t choffs;
00132
00133 updates++;
00134 choffs = CHANNEL_OFFSET(channel);
00135 if((ctx.cmask & (1UL<<channel)) == 0)
00136 {
00137
00138 PRINTF(" %2d n/a"NL, channel);
00139 }
00140 else
00141 {
00142
00143 scres = &ctx.scanres[choffs];
00144 if (scres->framecnt > 0)
00145 {
00146 per = (scres->framecnt - scres->crc_ok) * 100 / scres->framecnt;
00147 }
00148
00149 lqi = (scres->framecnt > 0) ? scres->lqisum / scres->framecnt : 0;
00150 ed = (scres->framecnt > 0) ? scres->edsum / scres->framecnt : 0;
00151
00152 PRINTF(" %2d % 5u % 5u "
00153 " % 3u %3u ",
00154 channel, scres->framecnt, scres->framecnt - scres->crc_ok,
00155 ed, lqi);
00156
00157 PRINTF(" % 5u % 5u % 5u % 5u"
00158 " % 3u"NL,
00159 scres->ftypes[0], scres->ftypes[1], scres->ftypes[2], scres->ftypes[3],
00160 per
00161 );
00162 }
00163 if (choffs == CHANNEL_MAX_OFFSET)
00164 {
00165 PRINTF("=== ur %d frames: %d ==="NL, ctx.irq_ur, ctx.frames);
00166
00167 hif_puts("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\n");
00168 }
00169 hif_puts("\r*\r\b");
00170
00171
00172 if (ctx.scanres_reset)
00173 {
00174 if (ctx.scanres_reset <= TRX_NB_CHANNELS)
00175 {
00176 hif_puts("\rr");
00177 }
00178 else
00179 {
00180 hif_puts("\rR");
00181 }
00182 hif_puts(" \r\b");
00183 }
00184 else
00185 {
00186 hif_puts("\r*\r\b");
00187 }
00188 }
00189
00190
00194 time_t timer_scan(timer_arg_t t)
00195 {
00196 ctx.state = SCAN_DONE;
00197 return 0;
00198 }
00199