psnotch.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================r
  9. *
  10. * psnotch.c - Qualcomm Atheros Prescaler Notching Utility
  11. *
  12. * Atheros Powerline Toolkit;
  13. *
  14. * this program is the Atheros INT6000 Dynamic Notching Utility
  15. *
  16. * this program inspects the following frequency bands for SW signals:
  17. *
  18. * 120 m 2,300 - 2,495 kHz tropic band
  19. * 90 m 3,200 - 3,400 kHz tropic band
  20. * 75 m 3,900 - 4,000 kHz shared with the amateur radio 75/80 meter band
  21. * 60 m 4,750 - 5,060 kHz tropic band
  22. * 49 m 5,900 - 6,200 kHz
  23. * 40 m/41m 7,100 - 7,350 kHz shared with the amateur radio 40 meter band
  24. * 31 m 9,400 - 9,900 kHz Currently most heavily used band
  25. * 25 m 11,600 - 12,100 kHz
  26. * 22 m 13,570 - 13,870 kHz substantially used only in Eurasia
  27. * 19 m 15,100 - 15,800 kHz
  28. * 16 m 17,480 - 17,900 kHz
  29. * 15 m 18,900 - 19,020 kHz almost unused, could become a DRM band
  30. * 13 m 21,450 - 21,850 kHz
  31. * 11 m 25,600 - 26,100 kHz may be used for local DRM broadcasting
  32. *
  33. * Contributor(s):
  34. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  35. *
  36. *--------------------------------------------------------------------*/
  37. /*====================================================================*
  38. * system header files;
  39. *--------------------------------------------------------------------*/
  40. #include <stdio.h>
  41. #include <ctype.h>
  42. #include <math.h>
  43. #include <ctype.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46. #include <fcntl.h>
  47. #include <string.h>
  48. /*====================================================================*
  49. * custom header files;
  50. *--------------------------------------------------------------------*/
  51. #include "../tools/getoptv.h"
  52. #include "../tools/putoptv.h"
  53. #include "../tools/error.h"
  54. #include "../tools/flags.h"
  55. #include "../tools/chars.h"
  56. #include "../tools/number.h"
  57. /*====================================================================*
  58. * custom source files;
  59. *--------------------------------------------------------------------*/
  60. #ifndef MAKEFILE
  61. #include "../tools/getoptv.c"
  62. #include "../tools/putoptv.c"
  63. #include "../tools/version.c"
  64. #include "../tools/error.c"
  65. #include "../tools/uintspec.c"
  66. #include "../tools/todigit.c"
  67. #endif
  68. /*====================================================================*
  69. * program constants;
  70. *--------------------------------------------------------------------*/
  71. #define _PRINTF_DEBUG
  72. #define PSNOTCH_VERBOSE (1 << 0)
  73. #define PSNOTCH_SILENCE (1 << 1)
  74. #define PSNOTCH_COMMA (1 << 2)
  75. #define CARRIERS 1155
  76. #define TONES 917
  77. #define SLOTS 6
  78. #define INDEX_TO_FREQ(index) ((float)(index + 74)/40.96)
  79. #define FREQ_TO_INDEX(freq) ((unsigned)(40.96 * freq)-74)
  80. /*====================================================================*
  81. * program variables;
  82. *--------------------------------------------------------------------*/
  83. typedef struct carrier
  84. {
  85. uint16_t amplitude;
  86. uint8_t slots [SLOTS];
  87. }
  88. carrier;
  89. typedef struct map
  90. {
  91. unsigned slots;
  92. struct carrier carriers [CARRIERS];
  93. }
  94. map;
  95. uint8_t hambands [CARRIERS] =
  96. {
  97. 0,
  98. 0,
  99. 0,
  100. 0,
  101. 0,
  102. 0,
  103. 0,
  104. 0,
  105. 0,
  106. 0,
  107. 0,
  108. 0,
  109. 1,
  110. 1,
  111. 1,
  112. 1,
  113. 1,
  114. 1,
  115. 1,
  116. 1,
  117. 1,
  118. 1,
  119. 1,
  120. 1,
  121. 1,
  122. 1,
  123. 1,
  124. 1,
  125. 1,
  126. 1,
  127. 1,
  128. 1,
  129. 1,
  130. 1,
  131. 1,
  132. 1,
  133. 1,
  134. 1,
  135. 1,
  136. 1,
  137. 1,
  138. 1,
  139. 1,
  140. 1,
  141. 1,
  142. 1,
  143. 1,
  144. 1,
  145. 1,
  146. 1,
  147. 1,
  148. 1,
  149. 1,
  150. 1,
  151. 1,
  152. 1,
  153. 1,
  154. 1,
  155. 1,
  156. 1,
  157. 1,
  158. 1,
  159. 1,
  160. 1,
  161. 1,
  162. 1,
  163. 2,
  164. 2,
  165. 2,
  166. 2,
  167. 2,
  168. 2,
  169. 2,
  170. 2,
  171. 2,
  172. 2,
  173. 2,
  174. 2,
  175. 2,
  176. 2,
  177. 2,
  178. 2,
  179. 2,
  180. 2,
  181. 2,
  182. 2,
  183. 2,
  184. 2,
  185. 2,
  186. 2,
  187. 2,
  188. 2,
  189. 2,
  190. 2,
  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. 1,
  218. 1,
  219. 1,
  220. 1,
  221. 1,
  222. 1,
  223. 1,
  224. 1,
  225. 1,
  226. 1,
  227. 1,
  228. 1,
  229. 1,
  230. 1,
  231. 1,
  232. 1,
  233. 1,
  234. 1,
  235. 1,
  236. 1,
  237. 1,
  238. 2,
  239. 2,
  240. 2,
  241. 2,
  242. 2,
  243. 2,
  244. 2,
  245. 2,
  246. 2,
  247. 2,
  248. 2,
  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. 1,
  293. 1,
  294. 1,
  295. 1,
  296. 1,
  297. 1,
  298. 1,
  299. 1,
  300. 1,
  301. 1,
  302. 1,
  303. 1,
  304. 1,
  305. 1,
  306. 2,
  307. 2,
  308. 2,
  309. 2,
  310. 2,
  311. 2,
  312. 2,
  313. 2,
  314. 2,
  315. 2,
  316. 2,
  317. 2,
  318. 2,
  319. 2,
  320. 2,
  321. 2,
  322. 2,
  323. 2,
  324. 2,
  325. 2,
  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. 1,
  361. 1,
  362. 1,
  363. 1,
  364. 1,
  365. 1,
  366. 1,
  367. 1,
  368. 1,
  369. 1,
  370. 1,
  371. 1,
  372. 1,
  373. 1,
  374. 1,
  375. 1,
  376. 1,
  377. 1,
  378. 1,
  379. 1,
  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. 2,
  434. 2,
  435. 2,
  436. 2,
  437. 2,
  438. 2,
  439. 2,
  440. 2,
  441. 2,
  442. 2,
  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. 1,
  488. 1,
  489. 1,
  490. 1,
  491. 1,
  492. 1,
  493. 1,
  494. 1,
  495. 1,
  496. 1,
  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. 2,
  594. 2,
  595. 2,
  596. 2,
  597. 2,
  598. 2,
  599. 2,
  600. 2,
  601. 2,
  602. 2,
  603. 2,
  604. 2,
  605. 2,
  606. 2,
  607. 2,
  608. 2,
  609. 2,
  610. 2,
  611. 2,
  612. 2,
  613. 2,
  614. 2,
  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. 1,
  648. 1,
  649. 1,
  650. 1,
  651. 1,
  652. 1,
  653. 1,
  654. 1,
  655. 1,
  656. 1,
  657. 1,
  658. 1,
  659. 1,
  660. 1,
  661. 1,
  662. 1,
  663. 1,
  664. 1,
  665. 1,
  666. 1,
  667. 1,
  668. 1,
  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. 2,
  761. 2,
  762. 2,
  763. 2,
  764. 2,
  765. 2,
  766. 2,
  767. 2,
  768. 2,
  769. 2,
  770. 2,
  771. 2,
  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. 1,
  815. 1,
  816. 1,
  817. 1,
  818. 1,
  819. 1,
  820. 1,
  821. 1,
  822. 1,
  823. 1,
  824. 1,
  825. 1,
  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. 2,
  881. 2,
  882. 2,
  883. 2,
  884. 2,
  885. 2,
  886. 2,
  887. 2,
  888. 2,
  889. 2,
  890. 2,
  891. 2,
  892. 2,
  893. 2,
  894. 2,
  895. 2,
  896. 2,
  897. 2,
  898. 2,
  899. 2,
  900. 2,
  901. 2,
  902. 2,
  903. 2,
  904. 2,
  905. 2,
  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. 1,
  935. 1,
  936. 1,
  937. 1,
  938. 1,
  939. 1,
  940. 1,
  941. 1,
  942. 1,
  943. 1,
  944. 1,
  945. 1,
  946. 1,
  947. 1,
  948. 1,
  949. 1,
  950. 1,
  951. 1,
  952. 1,
  953. 1,
  954. 1,
  955. 1,
  956. 1,
  957. 1,
  958. 1,
  959. 1,
  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. 2,
  1040. 2,
  1041. 2,
  1042. 2,
  1043. 2,
  1044. 2,
  1045. 2,
  1046. 2,
  1047. 2,
  1048. 2,
  1049. 2,
  1050. 2,
  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. 1,
  1094. 1,
  1095. 1,
  1096. 1,
  1097. 1,
  1098. 1,
  1099. 1,
  1100. 1,
  1101. 1,
  1102. 1,
  1103. 1,
  1104. 1,
  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. 0,
  1168. 0,
  1169. 0,
  1170. 0,
  1171. 0,
  1172. 0,
  1173. 0,
  1174. 0,
  1175. 0,
  1176. 0,
  1177. 0,
  1178. 0,
  1179. 0,
  1180. 0,
  1181. 0,
  1182. 0,
  1183. 0,
  1184. 0,
  1185. 0,
  1186. 0,
  1187. 0,
  1188. 0,
  1189. 0,
  1190. 0,
  1191. 0,
  1192. 0,
  1193. 0,
  1194. 0,
  1195. 0,
  1196. 0,
  1197. 0,
  1198. 0,
  1199. 0,
  1200. 0,
  1201. 0,
  1202. 0,
  1203. 0,
  1204. 0,
  1205. 0,
  1206. 0,
  1207. 0,
  1208. 0,
  1209. 0,
  1210. 0,
  1211. 0,
  1212. 0,
  1213. 0,
  1214. 0,
  1215. 0,
  1216. 0,
  1217. 0,
  1218. 0,
  1219. 0,
  1220. 0,
  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. };
  1253. /*====================================================================*
  1254. *
  1255. * int read_scalers (struct map * map);
  1256. *
  1257. * read a prescaler file from stdin; permit comments and blank
  1258. * input lines; the set of prescalers are technically known as
  1259. * an amplitude map;
  1260. *
  1261. * an amplitude map consists an offset (frequency) and a scaler
  1262. * (amplitude); we read, check and discard the offset but store
  1263. * the scaler;
  1264. *
  1265. *--------------------------------------------------------------------*/
  1266. void read_scalers (struct map * map)
  1267. {
  1268. unsigned carriers = 0;
  1269. unsigned tones = 0;
  1270. uint32_t carrier;
  1271. uint32_t amplitude;
  1272. signed c;
  1273. while ((c = getc (stdin)) != EOF)
  1274. {
  1275. if (isspace (c))
  1276. {
  1277. continue;
  1278. }
  1279. if ((c == '#') || (c == ';'))
  1280. {
  1281. do
  1282. {
  1283. c = getc (stdin);
  1284. }
  1285. while (nobreak (c));
  1286. continue;
  1287. }
  1288. carrier = 0;
  1289. while (isdigit (c))
  1290. {
  1291. carrier *= 10;
  1292. carrier += c - '0';
  1293. c = getc (stdin);
  1294. }
  1295. if (carrier != carriers)
  1296. {
  1297. error (1, 0, "Prescaler %d/%d out of order", carrier, carriers);
  1298. }
  1299. if (carrier >= CARRIERS)
  1300. {
  1301. break;
  1302. }
  1303. while (isblank (c))
  1304. {
  1305. c = getc (stdin);
  1306. }
  1307. amplitude = 0;
  1308. while (isxdigit (c))
  1309. {
  1310. amplitude *= 16;
  1311. amplitude += todigit (c);
  1312. c = getc (stdin);
  1313. }
  1314. map->carriers [carrier].amplitude = amplitude;
  1315. if (amplitude)
  1316. {
  1317. tones++;
  1318. }
  1319. while ((c != EOF) && (c != '\n'))
  1320. {
  1321. c = getc (stdin);
  1322. }
  1323. carriers++;
  1324. }
  1325. if (carriers != CARRIERS)
  1326. {
  1327. error (1, 0, "Have %d amplitude map carriers but need %d", carriers, CARRIERS);
  1328. }
  1329. if (tones != TONES)
  1330. {
  1331. error (1, 0, "Expected %d amplitude map scalers but read %d", TONES, tones);
  1332. }
  1333. return;
  1334. }
  1335. /*====================================================================*
  1336. *
  1337. * void write_scalers (struct map * map);
  1338. *
  1339. * print amplitude map on stdout in a format suitabl for input to
  1340. * program psin or the Windows Device Manager;
  1341. *
  1342. *--------------------------------------------------------------------*/
  1343. void write_scalers (struct map * map)
  1344. {
  1345. unsigned carrier = 0;
  1346. for (carrier = 0; carrier < CARRIERS; carrier++)
  1347. {
  1348. printf ("%.8u %.8hX\n", carrier, map->carriers [carrier].amplitude);
  1349. }
  1350. return;
  1351. }
  1352. /*====================================================================*
  1353. *
  1354. * void read_tonemaps (struct map * map, FILE *fp);
  1355. *
  1356. * read tone map from a file; a tonemap file can be created using
  1357. * program int6ktone;
  1358. *
  1359. * input consists of 1159 lines; the first line is a comment; the
  1360. * next two lines contain GIL and AGC information; the remaining
  1361. * 1155 lines consist of an offset follwed by 5 or 6 slot values;
  1362. *
  1363. * although 1155 values are read, the first 917 contain tonemap
  1364. * data and rest contain 0 values; the 917 values correspond to
  1365. * the 917 amplitude scalers;
  1366. *
  1367. * the tone map may be read either before or after the amplitude
  1368. * map is read;
  1369. *
  1370. *--------------------------------------------------------------------*/
  1371. void read_tonemaps (struct map * map, FILE * fp)
  1372. {
  1373. uint8_t slots [SLOTS];
  1374. unsigned tones = 0;
  1375. unsigned tone = 0;
  1376. unsigned slot = 0;
  1377. signed c;
  1378. map->slots = SLOTS;
  1379. memset (slots, 0, sizeof (slots));
  1380. while ((c = getc (fp)) != EOF)
  1381. {
  1382. if (c == '#')
  1383. {
  1384. while (((c = getc (fp)) != EOF) && (c != '\n'));
  1385. }
  1386. if (isspace (c))
  1387. {
  1388. continue;
  1389. }
  1390. tone = 0;
  1391. while (isdigit (c))
  1392. {
  1393. tone *= 10;
  1394. tone += c - '0';
  1395. c = getc (fp);
  1396. }
  1397. if (tone != tones)
  1398. {
  1399. error (1, ECANCELED, "Tonemap %d/%d is out of order", tone, tones);
  1400. }
  1401. while (isblank (c))
  1402. {
  1403. c = getc (fp);
  1404. }
  1405. for (slot = 0; slot < SLOTS; slot++)
  1406. {
  1407. unsigned value = 0;
  1408. while (isdigit (c))
  1409. {
  1410. value *= 10;
  1411. value += c - '0';
  1412. c = getc (fp);
  1413. }
  1414. map->carriers [tone].slots [slot] = value;
  1415. while (isblank (c))
  1416. {
  1417. c = getc (fp);
  1418. }
  1419. }
  1420. while ((c != EOF) && (c != '\n'))
  1421. {
  1422. c = getc (fp);
  1423. }
  1424. tones++;
  1425. }
  1426. if (tones != TONES)
  1427. {
  1428. error (0, 0, "Have %d tone map carriers but need %d", tones, TONES);
  1429. }
  1430. return;
  1431. }
  1432. /*====================================================================*
  1433. *
  1434. * void align_tones (struct map * map);
  1435. *
  1436. * the tonemap consists of 917 consecutive carriers the amplitude
  1437. * map consists of 1155 carriers having 917 non-zero values; this
  1438. * function distributes the tonemap entries so that they align to
  1439. * corresponding amplitude map entries;
  1440. *
  1441. * alignment cannot be performed until both the amplitude map and
  1442. * tone map have been read;
  1443. *
  1444. *--------------------------------------------------------------------*/
  1445. void align_tones (struct map * map)
  1446. {
  1447. unsigned carriers = CARRIERS;
  1448. unsigned tones = TONES;
  1449. while (carriers--)
  1450. {
  1451. if (map->carriers [carriers].amplitude)
  1452. {
  1453. if (tones)
  1454. {
  1455. tones--;
  1456. memcpy (& map->carriers [carriers].slots, & map->carriers [tones].slots, SLOTS);
  1457. memset (& map->carriers [tones].slots, 0, SLOTS);
  1458. }
  1459. }
  1460. }
  1461. return;
  1462. }
  1463. /*====================================================================*
  1464. *
  1465. * unsigned notch_tones (struct map * scalers, unsigned lower, unsigned upper);
  1466. *
  1467. * scan a range of tones for signals; signals are indicated by low
  1468. * mean-square values computed across all slots for a given tone;
  1469. *
  1470. * there may not be much change from one carrier to the next; we
  1471. * accentuate changes by squaring then summing slot values; this
  1472. * produces a reasonably clean parabolic dip in the map where the
  1473. * signal occurs;
  1474. *
  1475. * function watch_tones can be used to observe tone map values and
  1476. * signal dips over a given range of map values; generally, it is
  1477. * best to display a wider range of tones than those being notched;
  1478. *
  1479. *--------------------------------------------------------------------*/
  1480. unsigned notch_tones (struct map * map, unsigned lower, unsigned upper, unsigned limit)
  1481. {
  1482. unsigned slot;
  1483. unsigned notch = 0;
  1484. while (lower < upper)
  1485. {
  1486. unsigned total = 0;
  1487. for (slot = 0; slot < map->slots; slot++)
  1488. {
  1489. unsigned value = 0;
  1490. value = map->carriers [lower].slots [slot];
  1491. value *= value;
  1492. total += value;
  1493. }
  1494. if (slot)
  1495. {
  1496. total /= slot;
  1497. }
  1498. if (total < limit)
  1499. {
  1500. map->carriers [lower].amplitude = 0;
  1501. notch = 2;
  1502. }
  1503. lower++;
  1504. }
  1505. return (notch);
  1506. }
  1507. /*====================================================================*
  1508. *
  1509. * void watch_tones (struct map * map, unsigned lower, unsigned upper);
  1510. *
  1511. * print amplitude and tone values over a given range along with a
  1512. * plot of the values used to detect signal dips; for best effect,
  1513. * the range used here should exceed the notching range to provide
  1514. * context information;
  1515. *
  1516. *--------------------------------------------------------------------*/
  1517. void watch_tones (struct map * map, unsigned lower, unsigned upper)
  1518. {
  1519. unsigned slot;
  1520. while (lower < upper)
  1521. {
  1522. unsigned total = 0;
  1523. fprintf (stderr, "%04d %04X", lower, map->carriers [lower].amplitude);
  1524. for (slot = 0; slot < map->slots; slot++)
  1525. {
  1526. unsigned value = 0;
  1527. value = map->carriers [lower].slots [slot];
  1528. fprintf (stderr, " %02X", value);
  1529. value *= value;
  1530. total += value;
  1531. }
  1532. if (slot)
  1533. {
  1534. total /= slot;
  1535. }
  1536. fprintf (stderr, " %6.3f ", INDEX_TO_FREQ (lower));
  1537. while (total--)
  1538. {
  1539. fprintf (stderr, "#");
  1540. }
  1541. fprintf (stderr, "\n");
  1542. lower++;
  1543. }
  1544. return;
  1545. }
  1546. /*====================================================================*
  1547. *
  1548. * void watch_tone2 (struct map * map, unsigned lower, unsigned upper);
  1549. *
  1550. * print amplitude and tone values over a given range along with a
  1551. * plot of the values used to detect signal dips; for best effect,
  1552. * the range used here should exceed the notching range to provide
  1553. * context information;
  1554. *
  1555. *--------------------------------------------------------------------*/
  1556. void watch_tone2 (struct map * map, unsigned lower, unsigned upper)
  1557. {
  1558. unsigned slot;
  1559. while (lower < upper)
  1560. {
  1561. unsigned total = 0;
  1562. fprintf (stderr, "%d,%d", lower, map->carriers [lower].amplitude);
  1563. for (slot = 0; slot < map->slots; slot++)
  1564. {
  1565. unsigned value = 0;
  1566. value = map->carriers [lower].slots [slot];
  1567. fprintf (stderr, ",%d", value);
  1568. value *= value;
  1569. total += value;
  1570. }
  1571. if (slot)
  1572. {
  1573. total /= slot;
  1574. }
  1575. fprintf (stderr, ",%d", total);
  1576. fprintf (stderr, ",%6.3f", INDEX_TO_FREQ (lower));
  1577. fprintf (stderr, "\n");
  1578. lower++;
  1579. }
  1580. return;
  1581. }
  1582. /*====================================================================*
  1583. *
  1584. * int main (int argc, char const * argv[]);
  1585. *
  1586. * read an amplitude map from stdin and print a notched amplitude
  1587. * map on stdout; use a tone map file to determine if a signal is
  1588. * present where notching chould occur; notching ranges are input
  1589. * as map offsets, not carrier frequencies;
  1590. *
  1591. *--------------------------------------------------------------------*/
  1592. int main (int argc, char const * argv [])
  1593. {
  1594. char const * optv [] =
  1595. {
  1596. "cf:l:L:t:u:U:qv",
  1597. PUTOPTV_S_FILTER,
  1598. "Qualcomm Atheros Prescaler Notching Utility",
  1599. "c\tcomma delimited output",
  1600. "f f\tread tonemap file (f)",
  1601. "t n\tthreshold is (n) units",
  1602. "l n\tlower notch range is (n)",
  1603. "L n\tlower graph range is (n)",
  1604. "u n\tupper notch range is (n)",
  1605. "U n\tupper graph range is (n)",
  1606. "v\tverbose output",
  1607. (char const *) (0)
  1608. };
  1609. struct map map;
  1610. FILE * fp = (FILE *) (0);
  1611. unsigned lower = CARRIERS - 1;
  1612. unsigned upper = 0;
  1613. unsigned LOWER = 0;
  1614. unsigned UPPER = CARRIERS - 1;
  1615. signed limit = 4;
  1616. signed status = 0;
  1617. flag_t flags = (flag_t) (0);
  1618. signed c;
  1619. memset (& map, 0, sizeof (map));
  1620. while (~ (c = getoptv (argc, argv, optv)))
  1621. {
  1622. switch (c)
  1623. {
  1624. case 'c':
  1625. _setbits (flags, PSNOTCH_COMMA);
  1626. break;
  1627. case 'f':
  1628. if ((fp = fopen (optarg, "rb")) == (FILE *) (0))
  1629. {
  1630. error (1, errno, "Can't open %s", optarg);
  1631. }
  1632. read_tonemaps (& map, fp);
  1633. fclose (fp);
  1634. break;
  1635. case 'l':
  1636. lower = (unsigned) (uintspec (optarg, 0, CARRIERS - 1));
  1637. break;
  1638. case 'u':
  1639. upper = (unsigned) (uintspec (optarg, 0, CARRIERS - 1));
  1640. break;
  1641. case 'L':
  1642. LOWER = (unsigned) (uintspec (optarg, 0, CARRIERS - 1));
  1643. break;
  1644. case 'U':
  1645. UPPER = (unsigned) (uintspec (optarg, 0, CARRIERS - 1));
  1646. break;
  1647. case 't':
  1648. limit = (signed) (uintspec (optarg, 0, 49));
  1649. break;
  1650. case 'q':
  1651. _setbits (flags, PSNOTCH_SILENCE);
  1652. break;
  1653. case 'v':
  1654. _setbits (flags, PSNOTCH_VERBOSE);
  1655. break;
  1656. default:
  1657. break;
  1658. }
  1659. }
  1660. argv += optind;
  1661. argc -= optind;
  1662. read_scalers (& map);
  1663. align_tones (& map);
  1664. if (_anyset (flags, PSNOTCH_COMMA))
  1665. {
  1666. watch_tone2 (& map, LOWER, UPPER);
  1667. }
  1668. else if (_anyset (flags, PSNOTCH_VERBOSE))
  1669. {
  1670. watch_tones (& map, LOWER, UPPER);
  1671. }
  1672. if (fp)
  1673. {
  1674. status = notch_tones (& map, lower, upper, limit);
  1675. }
  1676. write_scalers (& map);
  1677. return (status);
  1678. }