psnotch.c.html 21 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. psnotch.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='pskey.c.html' title=' pskey.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='psout.c.html' title=' psout.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================r
  62. *
  63. * psnotch.c - Atheros Prescaler Notching Utility
  64. *
  65. * Atheros Powerline Toolkit;
  66. *
  67. * this program is the Atheros INT6000 Dynamic Notching Utility
  68. *
  69. * this program inspects the following frequency bands for SW signals:
  70. *
  71. * 120 m 2,300 - 2,495 kHz tropic band
  72. * 90 m 3,200 - 3,400 kHz tropic band
  73. * 75 m 3,900 - 4,000 kHz shared with the amateur radio 75/80 meter band
  74. * 60 m 4,750 - 5,060 kHz tropic band
  75. * 49 m 5,900 - 6,200 kHz
  76. * 40 m/41m 7,100 - 7,350 kHz shared with the amateur radio 40 meter band
  77. * 31 m 9,400 - 9,900 kHz Currently most heavily used band
  78. * 25 m 11,600 - 12,100 kHz
  79. * 22 m 13,570 - 13,870 kHz substantially used only in Eurasia
  80. * 19 m 15,100 - 15,800 kHz
  81. * 16 m 17,480 - 17,900 kHz
  82. * 15 m 18,900 - 19,020 kHz almost unused, could become a DRM band
  83. * 13 m 21,450 - 21,850 kHz
  84. * 11 m 25,600 - 26,100 kHz may be used for local DRM broadcasting
  85. *
  86. *
  87. * Contributor(s):
  88. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  89. *
  90. *--------------------------------------------------------------------*/
  91. /*====================================================================*&quot;
  92. * system header files;
  93. *--------------------------------------------------------------------*/
  94. #include &lt;stdio.h&gt;
  95. #include &lt;ctype.h&gt;
  96. #include &lt;math.h&gt;
  97. #include &lt;ctype.h&gt;
  98. #include &lt;sys/types.h&gt;
  99. #include &lt;sys/stat.h&gt;
  100. #include &lt;fcntl.h&gt;
  101. #include &lt;string.h&gt;
  102. /*====================================================================*
  103. * custom header files;
  104. *--------------------------------------------------------------------*/
  105. #include &quot;../tools/getoptv.h&quot;
  106. #include &quot;../tools/putoptv.h&quot;
  107. #include &quot;../tools/error.h&quot;
  108. #include &quot;../tools/flags.h&quot;
  109. #include &quot;../tools/chars.h&quot;
  110. #include &quot;../tools/number.h&quot;
  111. /*====================================================================*
  112. * custom source files;
  113. *--------------------------------------------------------------------*/
  114. #ifndef MAKEFILE
  115. #include &quot;../tools/getoptv.c&quot;
  116. #include &quot;../tools/putoptv.c&quot;
  117. #include &quot;../tools/version.c&quot;
  118. #include &quot;../tools/error.c&quot;
  119. #include &quot;../tools/uintspec.c&quot;
  120. #include &quot;../tools/todigit.c&quot;
  121. #endif
  122. /*====================================================================*
  123. * program constants;
  124. *--------------------------------------------------------------------*/
  125. #define _PRINTF_DEBUG
  126. #define PSNOTCH_VERBOSE (1 &lt;&lt; 0)
  127. #define PSNOTCH_SILENCE (1 &lt;&lt; 1)
  128. #define PSNOTCH_COMMA (1 &lt;&lt; 2)
  129. #define CARRIERS 1155
  130. #define TONES 917
  131. #define SLOTS 6
  132. #define INDEX_TO_FREQ(index) ((float)(index + 74)/40.96)
  133. #define FREQ_TO_INDEX(freq) ((unsigned)(40.96 * freq)-74)
  134. /*====================================================================*
  135. * program variables;
  136. *--------------------------------------------------------------------*/
  137. typedef struct carrier
  138. {
  139. uint16_t amplitude;
  140. uint8_t slots [SLOTS];
  141. }
  142. carrier;
  143. typedef struct map
  144. {
  145. unsigned slots;
  146. struct carrier carriers [CARRIERS];
  147. }
  148. map;
  149. uint8_t hambands [CARRIERS] =
  150. {
  151. 0,
  152. 0,
  153. 0,
  154. 0,
  155. 0,
  156. 0,
  157. 0,
  158. 0,
  159. 0,
  160. 0,
  161. 0,
  162. 0,
  163. 1,
  164. 1,
  165. 1,
  166. 1,
  167. 1,
  168. 1,
  169. 1,
  170. 1,
  171. 1,
  172. 1,
  173. 1,
  174. 1,
  175. 1,
  176. 1,
  177. 1,
  178. 1,
  179. 1,
  180. 1,
  181. 1,
  182. 1,
  183. 1,
  184. 1,
  185. 1,
  186. 1,
  187. 1,
  188. 1,
  189. 1,
  190. 1,
  191. 1,
  192. 1,
  193. 1,
  194. 1,
  195. 1,
  196. 1,
  197. 1,
  198. 1,
  199. 1,
  200. 1,
  201. 1,
  202. 1,
  203. 1,
  204. 1,
  205. 1,
  206. 1,
  207. 1,
  208. 1,
  209. 1,
  210. 1,
  211. 1,
  212. 1,
  213. 1,
  214. 1,
  215. 1,
  216. 1,
  217. 2,
  218. 2,
  219. 2,
  220. 2,
  221. 2,
  222. 2,
  223. 2,
  224. 2,
  225. 2,
  226. 2,
  227. 2,
  228. 2,
  229. 2,
  230. 2,
  231. 2,
  232. 2,
  233. 2,
  234. 2,
  235. 2,
  236. 2,
  237. 2,
  238. 2,
  239. 2,
  240. 2,
  241. 2,
  242. 2,
  243. 2,
  244. 2,
  245. 1,
  246. 1,
  247. 1,
  248. 1,
  249. 1,
  250. 1,
  251. 1,
  252. 1,
  253. 1,
  254. 1,
  255. 1,
  256. 1,
  257. 1,
  258. 1,
  259. 1,
  260. 1,
  261. 1,
  262. 1,
  263. 1,
  264. 1,
  265. 1,
  266. 1,
  267. 1,
  268. 1,
  269. 1,
  270. 1,
  271. 1,
  272. 1,
  273. 1,
  274. 1,
  275. 1,
  276. 1,
  277. 1,
  278. 1,
  279. 1,
  280. 1,
  281. 1,
  282. 1,
  283. 1,
  284. 1,
  285. 1,
  286. 1,
  287. 1,
  288. 1,
  289. 1,
  290. 1,
  291. 1,
  292. 2,
  293. 2,
  294. 2,
  295. 2,
  296. 2,
  297. 2,
  298. 2,
  299. 2,
  300. 2,
  301. 2,
  302. 2,
  303. 1,
  304. 1,
  305. 1,
  306. 1,
  307. 1,
  308. 1,
  309. 1,
  310. 1,
  311. 1,
  312. 1,
  313. 1,
  314. 1,
  315. 1,
  316. 1,
  317. 1,
  318. 1,
  319. 1,
  320. 1,
  321. 1,
  322. 1,
  323. 1,
  324. 1,
  325. 1,
  326. 1,
  327. 1,
  328. 1,
  329. 1,
  330. 1,
  331. 1,
  332. 1,
  333. 1,
  334. 1,
  335. 1,
  336. 1,
  337. 1,
  338. 1,
  339. 1,
  340. 1,
  341. 1,
  342. 1,
  343. 1,
  344. 1,
  345. 1,
  346. 1,
  347. 1,
  348. 1,
  349. 1,
  350. 1,
  351. 1,
  352. 1,
  353. 1,
  354. 1,
  355. 1,
  356. 1,
  357. 1,
  358. 1,
  359. 1,
  360. 2,
  361. 2,
  362. 2,
  363. 2,
  364. 2,
  365. 2,
  366. 2,
  367. 2,
  368. 2,
  369. 2,
  370. 2,
  371. 2,
  372. 2,
  373. 2,
  374. 2,
  375. 2,
  376. 2,
  377. 2,
  378. 2,
  379. 2,
  380. 1,
  381. 1,
  382. 1,
  383. 1,
  384. 1,
  385. 1,
  386. 1,
  387. 1,
  388. 1,
  389. 1,
  390. 1,
  391. 1,
  392. 1,
  393. 1,
  394. 1,
  395. 1,
  396. 1,
  397. 1,
  398. 1,
  399. 1,
  400. 1,
  401. 1,
  402. 1,
  403. 1,
  404. 1,
  405. 1,
  406. 1,
  407. 1,
  408. 1,
  409. 1,
  410. 1,
  411. 1,
  412. 1,
  413. 1,
  414. 1,
  415. 1,
  416. 1,
  417. 1,
  418. 1,
  419. 1,
  420. 1,
  421. 1,
  422. 1,
  423. 1,
  424. 1,
  425. 1,
  426. 1,
  427. 1,
  428. 1,
  429. 1,
  430. 1,
  431. 1,
  432. 1,
  433. 1,
  434. 1,
  435. 1,
  436. 1,
  437. 1,
  438. 1,
  439. 1,
  440. 1,
  441. 1,
  442. 1,
  443. 1,
  444. 1,
  445. 1,
  446. 1,
  447. 1,
  448. 1,
  449. 1,
  450. 1,
  451. 1,
  452. 1,
  453. 1,
  454. 1,
  455. 1,
  456. 1,
  457. 1,
  458. 1,
  459. 1,
  460. 1,
  461. 1,
  462. 1,
  463. 1,
  464. 1,
  465. 1,
  466. 1,
  467. 1,
  468. 1,
  469. 1,
  470. 1,
  471. 1,
  472. 1,
  473. 1,
  474. 1,
  475. 1,
  476. 1,
  477. 1,
  478. 1,
  479. 1,
  480. 1,
  481. 1,
  482. 1,
  483. 1,
  484. 1,
  485. 1,
  486. 1,
  487. 2,
  488. 2,
  489. 2,
  490. 2,
  491. 2,
  492. 2,
  493. 2,
  494. 2,
  495. 2,
  496. 2,
  497. 1,
  498. 1,
  499. 1,
  500. 1,
  501. 1,
  502. 1,
  503. 1,
  504. 1,
  505. 1,
  506. 1,
  507. 1,
  508. 1,
  509. 1,
  510. 1,
  511. 1,
  512. 1,
  513. 1,
  514. 1,
  515. 1,
  516. 1,
  517. 1,
  518. 1,
  519. 1,
  520. 1,
  521. 1,
  522. 1,
  523. 1,
  524. 1,
  525. 1,
  526. 1,
  527. 1,
  528. 1,
  529. 1,
  530. 1,
  531. 1,
  532. 1,
  533. 1,
  534. 1,
  535. 1,
  536. 1,
  537. 1,
  538. 1,
  539. 1,
  540. 1,
  541. 1,
  542. 1,
  543. 1,
  544. 1,
  545. 1,
  546. 1,
  547. 1,
  548. 1,
  549. 1,
  550. 1,
  551. 1,
  552. 1,
  553. 1,
  554. 1,
  555. 1,
  556. 1,
  557. 1,
  558. 1,
  559. 1,
  560. 1,
  561. 1,
  562. 1,
  563. 1,
  564. 1,
  565. 1,
  566. 1,
  567. 1,
  568. 1,
  569. 1,
  570. 1,
  571. 1,
  572. 1,
  573. 1,
  574. 1,
  575. 1,
  576. 1,
  577. 1,
  578. 1,
  579. 1,
  580. 1,
  581. 1,
  582. 1,
  583. 1,
  584. 1,
  585. 1,
  586. 1,
  587. 1,
  588. 1,
  589. 1,
  590. 1,
  591. 1,
  592. 1,
  593. 1,
  594. 1,
  595. 1,
  596. 1,
  597. 1,
  598. 1,
  599. 1,
  600. 1,
  601. 1,
  602. 1,
  603. 1,
  604. 1,
  605. 1,
  606. 1,
  607. 1,
  608. 1,
  609. 1,
  610. 1,
  611. 1,
  612. 1,
  613. 1,
  614. 1,
  615. 1,
  616. 1,
  617. 1,
  618. 1,
  619. 1,
  620. 1,
  621. 1,
  622. 1,
  623. 1,
  624. 1,
  625. 1,
  626. 1,
  627. 1,
  628. 1,
  629. 1,
  630. 1,
  631. 1,
  632. 1,
  633. 1,
  634. 1,
  635. 1,
  636. 1,
  637. 1,
  638. 1,
  639. 1,
  640. 1,
  641. 1,
  642. 1,
  643. 1,
  644. 1,
  645. 1,
  646. 1,
  647. 2,
  648. 2,
  649. 2,
  650. 2,
  651. 2,
  652. 2,
  653. 2,
  654. 2,
  655. 2,
  656. 2,
  657. 2,
  658. 2,
  659. 2,
  660. 2,
  661. 2,
  662. 2,
  663. 2,
  664. 2,
  665. 2,
  666. 2,
  667. 2,
  668. 2,
  669. 1,
  670. 1,
  671. 1,
  672. 1,
  673. 1,
  674. 1,
  675. 1,
  676. 1,
  677. 1,
  678. 1,
  679. 1,
  680. 1,
  681. 1,
  682. 1,
  683. 1,
  684. 1,
  685. 1,
  686. 1,
  687. 1,
  688. 1,
  689. 1,
  690. 1,
  691. 1,
  692. 1,
  693. 1,
  694. 1,
  695. 1,
  696. 1,
  697. 1,
  698. 1,
  699. 1,
  700. 1,
  701. 1,
  702. 1,
  703. 1,
  704. 1,
  705. 1,
  706. 1,
  707. 1,
  708. 1,
  709. 1,
  710. 1,
  711. 1,
  712. 1,
  713. 1,
  714. 1,
  715. 1,
  716. 1,
  717. 1,
  718. 1,
  719. 1,
  720. 1,
  721. 1,
  722. 1,
  723. 1,
  724. 1,
  725. 1,
  726. 1,
  727. 1,
  728. 1,
  729. 1,
  730. 1,
  731. 1,
  732. 1,
  733. 1,
  734. 1,
  735. 1,
  736. 1,
  737. 1,
  738. 1,
  739. 1,
  740. 1,
  741. 1,
  742. 1,
  743. 1,
  744. 1,
  745. 1,
  746. 1,
  747. 1,
  748. 1,
  749. 1,
  750. 1,
  751. 1,
  752. 1,
  753. 1,
  754. 1,
  755. 1,
  756. 1,
  757. 1,
  758. 1,
  759. 1,
  760. 1,
  761. 1,
  762. 1,
  763. 1,
  764. 1,
  765. 1,
  766. 1,
  767. 1,
  768. 1,
  769. 1,
  770. 1,
  771. 1,
  772. 1,
  773. 1,
  774. 1,
  775. 1,
  776. 1,
  777. 1,
  778. 1,
  779. 1,
  780. 1,
  781. 1,
  782. 1,
  783. 1,
  784. 1,
  785. 1,
  786. 1,
  787. 1,
  788. 1,
  789. 1,
  790. 1,
  791. 1,
  792. 1,
  793. 1,
  794. 1,
  795. 1,
  796. 1,
  797. 1,
  798. 1,
  799. 1,
  800. 1,
  801. 1,
  802. 1,
  803. 1,
  804. 1,
  805. 1,
  806. 1,
  807. 1,
  808. 1,
  809. 1,
  810. 1,
  811. 1,
  812. 1,
  813. 1,
  814. 2,
  815. 2,
  816. 2,
  817. 2,
  818. 2,
  819. 2,
  820. 2,
  821. 2,
  822. 2,
  823. 2,
  824. 2,
  825. 2,
  826. 1,
  827. 1,
  828. 1,
  829. 1,
  830. 1,
  831. 1,
  832. 1,
  833. 1,
  834. 1,
  835. 1,
  836. 1,
  837. 1,
  838. 1,
  839. 1,
  840. 1,
  841. 1,
  842. 1,
  843. 1,
  844. 1,
  845. 1,
  846. 1,
  847. 1,
  848. 1,
  849. 1,
  850. 1,
  851. 1,
  852. 1,
  853. 1,
  854. 1,
  855. 1,
  856. 1,
  857. 1,
  858. 1,
  859. 1,
  860. 1,
  861. 1,
  862. 1,
  863. 1,
  864. 1,
  865. 1,
  866. 1,
  867. 1,
  868. 1,
  869. 1,
  870. 1,
  871. 1,
  872. 1,
  873. 1,
  874. 1,
  875. 1,
  876. 1,
  877. 1,
  878. 1,
  879. 1,
  880. 1,
  881. 1,
  882. 1,
  883. 1,
  884. 1,
  885. 1,
  886. 1,
  887. 1,
  888. 1,
  889. 1,
  890. 1,
  891. 1,
  892. 1,
  893. 1,
  894. 1,
  895. 1,
  896. 1,
  897. 1,
  898. 1,
  899. 1,
  900. 1,
  901. 1,
  902. 1,
  903. 1,
  904. 1,
  905. 1,
  906. 1,
  907. 1,
  908. 1,
  909. 1,
  910. 1,
  911. 1,
  912. 1,
  913. 1,
  914. 1,
  915. 1,
  916. 1,
  917. 1,
  918. 1,
  919. 1,
  920. 1,
  921. 1,
  922. 1,
  923. 1,
  924. 1,
  925. 1,
  926. 1,
  927. 1,
  928. 1,
  929. 1,
  930. 1,
  931. 1,
  932. 1,
  933. 1,
  934. 2,
  935. 2,
  936. 2,
  937. 2,
  938. 2,
  939. 2,
  940. 2,
  941. 2,
  942. 2,
  943. 2,
  944. 2,
  945. 2,
  946. 2,
  947. 2,
  948. 2,
  949. 2,
  950. 2,
  951. 2,
  952. 2,
  953. 2,
  954. 2,
  955. 2,
  956. 2,
  957. 2,
  958. 2,
  959. 2,
  960. 1,
  961. 1,
  962. 1,
  963. 1,
  964. 1,
  965. 1,
  966. 1,
  967. 1,
  968. 1,
  969. 1,
  970. 1,
  971. 1,
  972. 1,
  973. 1,
  974. 1,
  975. 1,
  976. 1,
  977. 1,
  978. 1,
  979. 1,
  980. 1,
  981. 1,
  982. 1,
  983. 1,
  984. 1,
  985. 1,
  986. 1,
  987. 1,
  988. 1,
  989. 1,
  990. 1,
  991. 1,
  992. 1,
  993. 1,
  994. 1,
  995. 1,
  996. 1,
  997. 1,
  998. 1,
  999. 1,
  1000. 1,
  1001. 1,
  1002. 1,
  1003. 1,
  1004. 1,
  1005. 1,
  1006. 1,
  1007. 1,
  1008. 1,
  1009. 1,
  1010. 1,
  1011. 1,
  1012. 1,
  1013. 1,
  1014. 1,
  1015. 1,
  1016. 1,
  1017. 1,
  1018. 1,
  1019. 1,
  1020. 1,
  1021. 1,
  1022. 1,
  1023. 1,
  1024. 1,
  1025. 1,
  1026. 1,
  1027. 1,
  1028. 1,
  1029. 1,
  1030. 1,
  1031. 1,
  1032. 1,
  1033. 1,
  1034. 1,
  1035. 1,
  1036. 1,
  1037. 1,
  1038. 1,
  1039. 1,
  1040. 1,
  1041. 1,
  1042. 1,
  1043. 1,
  1044. 1,
  1045. 1,
  1046. 1,
  1047. 1,
  1048. 1,
  1049. 1,
  1050. 1,
  1051. 1,
  1052. 1,
  1053. 1,
  1054. 1,
  1055. 1,
  1056. 1,
  1057. 1,
  1058. 1,
  1059. 1,
  1060. 1,
  1061. 1,
  1062. 1,
  1063. 1,
  1064. 1,
  1065. 1,
  1066. 1,
  1067. 1,
  1068. 1,
  1069. 1,
  1070. 1,
  1071. 1,
  1072. 1,
  1073. 1,
  1074. 1,
  1075. 1,
  1076. 1,
  1077. 1,
  1078. 1,
  1079. 1,
  1080. 1,
  1081. 1,
  1082. 1,
  1083. 1,
  1084. 1,
  1085. 1,
  1086. 1,
  1087. 1,
  1088. 1,
  1089. 1,
  1090. 1,
  1091. 1,
  1092. 1,
  1093. 2,
  1094. 2,
  1095. 2,
  1096. 2,
  1097. 2,
  1098. 2,
  1099. 2,
  1100. 2,
  1101. 2,
  1102. 2,
  1103. 2,
  1104. 2,
  1105. 1,
  1106. 1,
  1107. 1,
  1108. 1,
  1109. 1,
  1110. 1,
  1111. 1,
  1112. 1,
  1113. 1,
  1114. 1,
  1115. 1,
  1116. 1,
  1117. 1,
  1118. 1,
  1119. 1,
  1120. 1,
  1121. 1,
  1122. 1,
  1123. 1,
  1124. 1,
  1125. 1,
  1126. 1,
  1127. 1,
  1128. 1,
  1129. 1,
  1130. 1,
  1131. 1,
  1132. 1,
  1133. 1,
  1134. 1,
  1135. 1,
  1136. 1,
  1137. 1,
  1138. 1,
  1139. 1,
  1140. 1,
  1141. 1,
  1142. 1,
  1143. 1,
  1144. 1,
  1145. 1,
  1146. 1,
  1147. 1,
  1148. 1,
  1149. 1,
  1150. 1,
  1151. 1,
  1152. 1,
  1153. 1,
  1154. 1,
  1155. 1,
  1156. 1,
  1157. 1,
  1158. 1,
  1159. 1,
  1160. 1,
  1161. 1,
  1162. 1,
  1163. 1,
  1164. 1,
  1165. 1,
  1166. 1,
  1167. 1,
  1168. 1,
  1169. 1,
  1170. 1,
  1171. 1,
  1172. 1,
  1173. 1,
  1174. 1,
  1175. 1,
  1176. 1,
  1177. 1,
  1178. 1,
  1179. 1,
  1180. 1,
  1181. 1,
  1182. 1,
  1183. 1,
  1184. 1,
  1185. 1,
  1186. 1,
  1187. 1,
  1188. 1,
  1189. 1,
  1190. 1,
  1191. 1,
  1192. 1,
  1193. 1,
  1194. 1,
  1195. 1,
  1196. 1,
  1197. 1,
  1198. 1,
  1199. 1,
  1200. 1,
  1201. 1,
  1202. 1,
  1203. 1,
  1204. 1,
  1205. 1,
  1206. 1,
  1207. 1,
  1208. 1,
  1209. 1,
  1210. 1,
  1211. 1,
  1212. 1,
  1213. 1,
  1214. 1,
  1215. 1,
  1216. 1,
  1217. 1,
  1218. 1,
  1219. 1,
  1220. 1,
  1221. 0,
  1222. 0,
  1223. 0,
  1224. 0,
  1225. 0,
  1226. 0,
  1227. 0,
  1228. 0,
  1229. 0,
  1230. 0,
  1231. 0,
  1232. 0,
  1233. 0,
  1234. 0,
  1235. 0,
  1236. 0,
  1237. 0,
  1238. 0,
  1239. 0,
  1240. 0,
  1241. 0,
  1242. 0,
  1243. 0,
  1244. 0,
  1245. 0,
  1246. 0,
  1247. 0,
  1248. 0,
  1249. 0,
  1250. 0,
  1251. 0,
  1252. 0,
  1253. 0,
  1254. 0,
  1255. 0,
  1256. 0,
  1257. 0,
  1258. 0,
  1259. 0,
  1260. 0,
  1261. 0,
  1262. 0,
  1263. 0,
  1264. 0,
  1265. 0,
  1266. 0,
  1267. 0,
  1268. 0,
  1269. 0,
  1270. 0,
  1271. 0,
  1272. 0,
  1273. 0,
  1274. 0,
  1275. 0,
  1276. 0,
  1277. 0,
  1278. 0,
  1279. 0,
  1280. 0,
  1281. 0,
  1282. 0,
  1283. 0,
  1284. 0,
  1285. 0,
  1286. 0,
  1287. 0,
  1288. 0,
  1289. 0,
  1290. 0,
  1291. 0,
  1292. 0,
  1293. 0,
  1294. 0,
  1295. 0,
  1296. 0,
  1297. 0,
  1298. 0,
  1299. 0,
  1300. 0,
  1301. 0,
  1302. 0,
  1303. 0,
  1304. 0,
  1305. 0
  1306. };
  1307. /*====================================================================*
  1308. *
  1309. * int read_scalers (struct map * map);
  1310. *
  1311. * read a prescaler file from stdin; permit comments and blank
  1312. * input lines; the set of prescalers are technically known as
  1313. * an amplitude map;
  1314. *
  1315. * an amplitude map consists an offset (frequency) and a scaler
  1316. * (amplitude); we read, check and discard the offset but store
  1317. * the scaler;
  1318. *
  1319. *--------------------------------------------------------------------*/
  1320. void read_scalers (struct map * map)
  1321. {
  1322. unsigned carriers = 0;
  1323. unsigned tones = 0;
  1324. uint32_t carrier;
  1325. uint32_t amplitude;
  1326. signed c;
  1327. while ((c = getc (stdin)) != EOF)
  1328. {
  1329. if (isspace (c))
  1330. {
  1331. continue;
  1332. }
  1333. if ((c == '#') || (c == ';'))
  1334. {
  1335. do
  1336. {
  1337. c = getc (stdin);
  1338. }
  1339. while (nobreak (c));
  1340. continue;
  1341. }
  1342. carrier = 0;
  1343. while (isdigit (c))
  1344. {
  1345. carrier *= 10;
  1346. carrier += c - '0';
  1347. c = getc (stdin);
  1348. }
  1349. if (carrier != carriers)
  1350. {
  1351. error (1, 0, &quot;Prescaler %d/%d out of order&quot;, carrier, carriers);
  1352. }
  1353. if (carrier &gt;= CARRIERS)
  1354. {
  1355. break;
  1356. }
  1357. while (isblank (c))
  1358. {
  1359. c = getc (stdin);
  1360. }
  1361. amplitude = 0;
  1362. while (isxdigit (c))
  1363. {
  1364. amplitude *= 16;
  1365. amplitude += todigit (c);
  1366. c = getc (stdin);
  1367. }
  1368. map-&gt;carriers [carrier].amplitude = amplitude;
  1369. if (amplitude)
  1370. {
  1371. tones++;
  1372. }
  1373. while ((c != EOF) &amp;&amp; (c != '\n'))
  1374. {
  1375. c = getc (stdin);
  1376. }
  1377. carriers++;
  1378. }
  1379. if (carriers != CARRIERS)
  1380. {
  1381. error (1, 0, &quot;Have %d amplitude map carriers but need %d&quot;, carriers, CARRIERS);
  1382. }
  1383. if (tones != TONES)
  1384. {
  1385. error (1, 0, &quot;Expected %d amplitude map scalers but read %d&quot;, TONES, tones);
  1386. }
  1387. return;
  1388. }
  1389. /*====================================================================*
  1390. *
  1391. * void write_scalers (struct map * map);
  1392. *
  1393. * print amplitude map on stdout in a format suitabl for input to
  1394. * program psin or the Windows Device Manager;
  1395. *
  1396. *
  1397. *--------------------------------------------------------------------*/
  1398. void write_scalers (struct map * map)
  1399. {
  1400. unsigned carrier = 0;
  1401. for (carrier = 0; carrier &lt; CARRIERS; carrier++)
  1402. {
  1403. printf (&quot;%.8u %.8hX\n&quot;, carrier, map-&gt;carriers [carrier].amplitude);
  1404. }
  1405. return;
  1406. }
  1407. /*====================================================================*
  1408. *
  1409. * void read_tonemaps (struct map * map, FILE *fp);
  1410. *
  1411. * read tone map from a file; a tonemap file can be created using
  1412. * program int6ktone;
  1413. *
  1414. * input consists of 1159 lines; the first line is a comment; the
  1415. * next two lines contain GIL and AGC information; the remaining
  1416. * 1155 lines consist of an offset follwed by 5 or 6 slot values;
  1417. *
  1418. * although 1155 values are read, the first 917 contain tonemap
  1419. * data and rest contain 0 values; the 917 values correspond to
  1420. * the 917 amplitude scalers;
  1421. *
  1422. * the tone map may be read either before or after the amplitude
  1423. * map is read;
  1424. *
  1425. *
  1426. *--------------------------------------------------------------------*/
  1427. void read_tonemaps (struct map * map, FILE *fp)
  1428. {
  1429. uint8_t slots [SLOTS];
  1430. unsigned tones = 0;
  1431. unsigned tone = 0;
  1432. unsigned slot = 0;
  1433. signed c;
  1434. map-&gt;slots = SLOTS;
  1435. memset (slots, 0, sizeof (slots));
  1436. while ((c = getc (fp)) != EOF)
  1437. {
  1438. if (c == '#')
  1439. {
  1440. while (((c = getc (fp)) != EOF) &amp;&amp; (c != '\n'));
  1441. }
  1442. if (isspace (c))
  1443. {
  1444. continue;
  1445. }
  1446. tone = 0;
  1447. while (isdigit (c))
  1448. {
  1449. tone *= 10;
  1450. tone += c - '0';
  1451. c = getc (fp);
  1452. }
  1453. if (tone != tones)
  1454. {
  1455. error (1, ECANCELED, &quot;Tonemap %d/%d is out of order&quot;, tone, tones);
  1456. }
  1457. while (isblank (c))
  1458. {
  1459. c = getc (fp);
  1460. }
  1461. for (slot = 0; slot &lt; SLOTS; slot++)
  1462. {
  1463. unsigned value = 0;
  1464. while (isdigit (c))
  1465. {
  1466. value *= 10;
  1467. value += c - '0';
  1468. c = getc (fp);
  1469. }
  1470. map-&gt;carriers [tone].slots [slot] = value;
  1471. while (isblank (c))
  1472. {
  1473. c = getc (fp);
  1474. }
  1475. }
  1476. while ((c != EOF) &amp;&amp; (c != '\n'))
  1477. {
  1478. c = getc (fp);
  1479. }
  1480. tones++;
  1481. }
  1482. if (tones != TONES)
  1483. {
  1484. error (0, 0, &quot;Have %d tone map carriers but need %d&quot;, tones, TONES);
  1485. }
  1486. return;
  1487. }
  1488. /*====================================================================*
  1489. *
  1490. * void align_tones (struct map * map);
  1491. *
  1492. * the tonemap consists of 917 consecutive carriers the amplitude
  1493. * map consists of 1155 carriers having 917 non-zero values; this
  1494. * function distributes the tonemap entries so that they align to
  1495. * corresponding amplitude map entries;
  1496. *
  1497. * alignment cannot be performed until both the amplitude map and
  1498. * tone map have been read;
  1499. *
  1500. *
  1501. *--------------------------------------------------------------------*/
  1502. void align_tones (struct map * map)
  1503. {
  1504. unsigned carriers = CARRIERS;
  1505. unsigned tones = TONES;
  1506. while (carriers--)
  1507. {
  1508. if (map-&gt;carriers [carriers].amplitude)
  1509. {
  1510. if (tones)
  1511. {
  1512. tones--;
  1513. memcpy (&amp;map-&gt;carriers [carriers].slots, &amp;map-&gt;carriers [tones].slots, SLOTS);
  1514. memset (&amp;map-&gt;carriers [tones].slots, 0, SLOTS);
  1515. }
  1516. }
  1517. }
  1518. return;
  1519. }
  1520. /*====================================================================*
  1521. *
  1522. * unsigned notch_tones (struct map * scalers, unsigned lower, unsigned upper);
  1523. *
  1524. * scan a range of tones for signals; signals are indicated by low
  1525. * mean-square values computed across all slots for a given tone;
  1526. *
  1527. * there may not be much change from one carrier to the next; we
  1528. * accentuate changes by squaring then summing slot values; this
  1529. * produces a reasonably clean parabolic dip in the map where the
  1530. * signal occurs;
  1531. *
  1532. * function watch_tones can be used to observe tone map values and
  1533. * signal dips over a given range of map values; generally, it is
  1534. * best to display a wider range of tones than those being notched;
  1535. *
  1536. *
  1537. *--------------------------------------------------------------------*/
  1538. unsigned notch_tones (struct map * map, unsigned lower, unsigned upper, unsigned limit)
  1539. {
  1540. unsigned slot;
  1541. unsigned notch = 0;
  1542. while (lower &lt; upper)
  1543. {
  1544. unsigned total = 0;
  1545. for (slot = 0; slot &lt; map-&gt;slots; slot++)
  1546. {
  1547. unsigned value = 0;
  1548. value = map-&gt;carriers [lower].slots [slot];
  1549. value *= value;
  1550. total += value;
  1551. }
  1552. if (slot)
  1553. {
  1554. total /= slot;
  1555. }
  1556. if (total &lt; limit)
  1557. {
  1558. map-&gt;carriers [lower].amplitude = 0;
  1559. notch = 2;
  1560. }
  1561. lower++;
  1562. }
  1563. return (notch);
  1564. }
  1565. /*====================================================================*
  1566. *
  1567. * void watch_tones (struct map * map, unsigned lower, unsigned upper);
  1568. *
  1569. * print amplitude and tone values over a given range along with a
  1570. * plot of the values used to detect signal dips; for best effect,
  1571. * the range used here should exceed the notching range to provide
  1572. * context information;
  1573. *
  1574. *
  1575. *--------------------------------------------------------------------*/
  1576. void watch_tones (struct map * map, unsigned lower, unsigned upper)
  1577. {
  1578. unsigned slot;
  1579. while (lower &lt; upper)
  1580. {
  1581. unsigned total = 0;
  1582. fprintf (stderr, &quot;%04d %04X&quot;, lower, map-&gt;carriers [lower].amplitude);
  1583. for (slot = 0; slot &lt; map-&gt;slots; slot++)
  1584. {
  1585. unsigned value = 0;
  1586. value = map-&gt;carriers [lower].slots [slot];
  1587. fprintf (stderr, &quot; %02X&quot;, value);
  1588. value *= value;
  1589. total += value;
  1590. }
  1591. if (slot)
  1592. {
  1593. total /= slot;
  1594. }
  1595. fprintf (stderr, &quot; %6.3f &quot;, INDEX_TO_FREQ (lower));
  1596. while (total--)
  1597. {
  1598. fprintf (stderr, &quot;#&quot;);
  1599. }
  1600. fprintf (stderr, &quot;\n&quot;);
  1601. lower++;
  1602. }
  1603. return;
  1604. }
  1605. /*====================================================================*
  1606. *
  1607. * void watch_tone2 (struct map * map, unsigned lower, unsigned upper);
  1608. *
  1609. * print amplitude and tone values over a given range along with a
  1610. * plot of the values used to detect signal dips; for best effect,
  1611. * the range used here should exceed the notching range to provide
  1612. * context information;
  1613. *
  1614. *
  1615. *--------------------------------------------------------------------*/
  1616. void watch_tone2 (struct map * map, unsigned lower, unsigned upper)
  1617. {
  1618. unsigned slot;
  1619. while (lower &lt; upper)
  1620. {
  1621. unsigned total = 0;
  1622. fprintf (stderr, &quot;%d,%d&quot;, lower, map-&gt;carriers [lower].amplitude);
  1623. for (slot = 0; slot &lt; map-&gt;slots; slot++)
  1624. {
  1625. unsigned value = 0;
  1626. value = map-&gt;carriers [lower].slots [slot];
  1627. fprintf (stderr, &quot;,%d&quot;, value);
  1628. value *= value;
  1629. total += value;
  1630. }
  1631. if (slot)
  1632. {
  1633. total /= slot;
  1634. }
  1635. fprintf (stderr, &quot;,%d&quot;, total);
  1636. fprintf (stderr, &quot;,%6.3f&quot;, INDEX_TO_FREQ (lower));
  1637. fprintf (stderr, &quot;\n&quot;);
  1638. lower++;
  1639. }
  1640. return;
  1641. }
  1642. /*====================================================================*
  1643. *
  1644. * int main (int argc, char const * argv[]);
  1645. *
  1646. * read an amplitude map from stdin and print a notched amplitude
  1647. * map on stdout; use a tone map file to determine if a signal is
  1648. * present where notching chould occur; notching ranges are input
  1649. * as map offsets, not carrier frequencies;
  1650. *
  1651. *
  1652. *--------------------------------------------------------------------*/
  1653. int main (int argc, char const * argv [])
  1654. {
  1655. char const * optv [] =
  1656. {
  1657. &quot;cf:l:L:t:u:U:qv&quot;,
  1658. PUTOPTV_S_FILTER,
  1659. &quot;Atheros Prescaler Notching Utility&quot;,
  1660. &quot;c\tcomma delimited output&quot;,
  1661. &quot;f f\tread tonemap file (f)&quot;,
  1662. &quot;t n\tthreshold is (n) units&quot;,
  1663. &quot;l n\tlower notch range is (n)&quot;,
  1664. &quot;L n\tlower graph range is (n)&quot;,
  1665. &quot;u n\tupper notch range is (n)&quot;,
  1666. &quot;U n\tupper graph range is (n)&quot;,
  1667. &quot;v\tverbose output&quot;,
  1668. (char const *)(0)
  1669. };
  1670. struct map map;
  1671. FILE * fp = (FILE *)(0);
  1672. unsigned lower = CARRIERS-1;
  1673. unsigned upper = 0;
  1674. unsigned LOWER = 0;
  1675. unsigned UPPER = CARRIERS-1;
  1676. signed limit = 4;
  1677. signed status = 0;
  1678. flag_t flags = (flag_t)(0);
  1679. signed c;
  1680. memset (&amp;map, 0, sizeof (map));
  1681. while ((c = getoptv (argc, argv, optv)) != -1)
  1682. {
  1683. switch (c)
  1684. {
  1685. case 'c':
  1686. _setbits (flags, PSNOTCH_COMMA);
  1687. break;
  1688. case 'f':
  1689. if ((fp = fopen (optarg, &quot;rb&quot;)) == (FILE *)(0))
  1690. {
  1691. error (1, errno, &quot;Can't open %s&quot;, optarg);
  1692. }
  1693. read_tonemaps (&amp;map, fp);
  1694. fclose (fp);
  1695. break;
  1696. case 'l':
  1697. lower = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1698. break;
  1699. case 'u':
  1700. upper = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1701. break;
  1702. case 'L':
  1703. LOWER = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1704. break;
  1705. case 'U':
  1706. UPPER = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1707. break;
  1708. case 't':
  1709. limit = (signed)(uintspec (optarg, 0, 49));
  1710. break;
  1711. case 'q':
  1712. _setbits (flags, PSNOTCH_SILENCE);
  1713. break;
  1714. case 'v':
  1715. _setbits (flags, PSNOTCH_VERBOSE);
  1716. break;
  1717. default:
  1718. break;
  1719. }
  1720. }
  1721. argv += optind;
  1722. argc -= optind;
  1723. read_scalers (&amp;map);
  1724. align_tones (&amp;map);
  1725. if (_anyset (flags, PSNOTCH_COMMA))
  1726. {
  1727. watch_tone2 (&amp;map, LOWER, UPPER);
  1728. }
  1729. else if (_anyset (flags, PSNOTCH_VERBOSE))
  1730. {
  1731. watch_tones (&amp;map, LOWER, UPPER);
  1732. }
  1733. if (fp)
  1734. {
  1735. status = notch_tones (&amp;map, lower, upper, limit);
  1736. }
  1737. write_scalers (&amp;map);
  1738. return (status);
  1739. }
  1740. </pre>
  1741. <div class='footerlink'>
  1742. [<a href='pskey.c.html' title=' pskey.c '>PREV</a>]
  1743. [<a href='toolkit.html' title=' Index '>HOME</a>]
  1744. [<a href='psout.c.html' title=' psout.c '>NEXT</a>]
  1745. </div>
  1746. </body>
  1747. </html>