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 extern volatile dbg_t dbg;
00046
00047
00048 static void show_status(channel_t choffs);
00049 time_t timer_scan(timer_arg_t t);
00050
00051
00052
00056 void scan_init(void)
00057 {
00058
00059 PRINTF("Scanning channels, scan period %ums"NL,
00060 SCAN_PERIOD_MS);
00061 PRINT(" bad"
00062 " Avg. "
00063 " 802.15.4 frames "
00064 " "NL);
00065 PRINT("chan frm crc "
00066 " ed lqi "
00067 " B D A C "
00068 " PER"NL);
00069
00070 ctx.cchan = TRX_MIN_CHANNEL;
00071 trx_bit_write(SR_CHANNEL, ctx.cchan);
00072 trx_reg_write(RG_TRX_STATE, CMD_RX_ON);
00073
00074 ctx.thdl = timer_start(timer_scan,MSEC(SCAN_PERIOD_MS),0);
00075 }
00076
00080 void scan_update_status(void)
00081 {
00082 scan_result_t *scres;
00083 uint32_t cmask;
00084
00085 cmask = TRX_SUPPORTED_CHANNELS;
00086 do
00087 {
00088 show_status(ctx.cchan);
00089 ctx.cchan += 1;
00090 if (ctx.cchan > TRX_MAX_CHANNEL)
00091 {
00092 ctx.cchan = TRX_MIN_CHANNEL;
00093 }
00094 cmask &= ~(1UL<<ctx.cchan);
00095 if(((ctx.cmask & (1UL<<ctx.cchan)) != 0) || (cmask == 0))
00096 {
00097
00098
00099 break;
00100 }
00101 }
00102 while(1);
00103 if (ctx.scanres_reset)
00104 {
00105 scres = &ctx.scanres[CHANNEL_OFFSET(ctx.cchan)];
00106 memset(scres,0,sizeof(scan_result_t));
00107 if (ctx.scanres_reset < 32)
00108 {
00109 ctx.scanres_reset --;
00110 }
00111 }
00112
00113
00114 trx_bit_write(SR_CHANNEL, ctx.cchan);
00115 cli();
00116 ctx.state = SCAN;
00117 sei();
00118
00119 ctx.thdl = timer_start(timer_scan,MSEC(SCAN_PERIOD_MS),0);
00120
00121 }
00122
00127 static void show_status(channel_t channel)
00128 {
00129 static uint16_t updates = 0;
00130 scan_result_t *scres;
00131 uint16_t per = 0, lqi, ed;
00132 uint8_t choffs;
00133
00134 updates++;
00135 choffs = CHANNEL_OFFSET(channel);
00136 if((ctx.cmask & (1UL<<channel)) == 0)
00137 {
00138
00139 PRINTF(" %2d n/a"NL, channel);
00140 }
00141 else
00142 {
00143
00144 scres = &ctx.scanres[choffs];
00145 if (scres->framecnt > 0)
00146 {
00147 per = (scres->framecnt - scres->crc_ok) * 100 / scres->framecnt;
00148 }
00149
00150 lqi = (scres->framecnt > 0) ? scres->lqisum / scres->framecnt : 0;
00151 ed = (scres->framecnt > 0) ? scres->edsum / scres->framecnt : 0;
00152
00153 PRINTF(" %2d % 5u % 5u "
00154 " % 3u %3u ",
00155 channel, scres->framecnt, scres->framecnt - scres->crc_ok,
00156 ed, lqi);
00157
00158 PRINTF(" % 5u % 5u % 5u % 5u"
00159 " % 3u"NL,
00160 scres->ftypes[0], scres->ftypes[1], scres->ftypes[2], scres->ftypes[3],
00161 per
00162 );
00163 }
00164 if (choffs == CHANNEL_MAX_OFFSET)
00165 {
00166 PRINTF("=== ur %d err %d frames: %d ==="NL, ctx.irq_ur, dbg.err, ctx.frames);
00167
00168 hif_puts("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\n");
00169 }
00170 hif_puts("\r*\r\b");
00171
00172
00173 if (ctx.scanres_reset)
00174 {
00175 if (ctx.scanres_reset <= TRX_NB_CHANNELS)
00176 {
00177 hif_puts("\rr");
00178 }
00179 else
00180 {
00181 hif_puts("\rR");
00182 }
00183 hif_puts(" \r\b");
00184 }
00185 else
00186 {
00187 hif_puts("\r*\r\b");
00188 }
00189 }
00190
00191
00195 time_t timer_scan(timer_arg_t t)
00196 {
00197 if (dbg.tmrl) dbg.err = 1;
00198 dbg.tmrl ++;
00199
00200 ctx.state = SCAN_DONE;
00201 dbg.tmrl --;
00202 return 0;
00203 }
00204