├── LICENSE ├── README.md ├── apps ├── .gitignore ├── am_flow_example.grc ├── am_flow_example.py ├── cursesgui.py ├── estimate.py ├── ham2mon.py ├── lockout.txt ├── nbfm_flow_example.grc ├── nbfm_flow_example.py ├── parser.py ├── priority.txt ├── receiver.py ├── scanner.py └── wav │ └── .gitignore ├── flow_example.png └── ham2mon.png /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. {http://fsf.org/} 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see {http://www.gnu.org/licenses/}. 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | scanoo Copyright (C) 2013 Mike Jameson 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | {http://www.gnu.org/licenses/}. 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | {http://www.gnu.org/philosophy/why-not-lgpl.html}. 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HAM2MON 2 | This is a GNU Radio (GR) based SDR scanner with a Curses interface, primarily meant for monitoring amateur radio narrow-band FM modulation and air-band AM modulation. It should work with any GrOsmoSDR source capable of at least 1 Msps. Unlike conventional radio scanners that lock and demodulate a single channel, this SDR scanner can demodulate and record audio from N channels in parallel within the digitizing bandwidth. The N (number of) channels is basically just limited by processor speed. A video detailing the project may be found here: 3 | 4 | http://youtu.be/BXptQFSV8E4 5 | 6 | ![GUI screenshot](https://github.com/madengr/ham2mon/blob/master/ham2mon.png) 7 | 8 | ## Tested with: 9 | - Ettus B200 at 16 Msps (http://www.ettus.com) 10 | - NooElec RTL2832 + R820T at 2 Msps (http://www.nooelec.com) 11 | - GNU Radio 3.7.10 (https://github.com/gnuradio/gnuradio) 12 | - GrOsmoSDR 0.1.4 (http://sdr.osmocom.org/trac/wiki/GrOsmoSDR) 13 | - Ettus UHD 3.10.0 (https://github.com/EttusResearch/uhd) 14 | 15 | ## Contributors: 16 | 17 | m0mik: 18 | - Added HackRF IF/BB gain parameters 19 | - Added 1dB shift option to threshold and gain settings 20 | 21 | atpage: 22 | - Fixed typos 23 | 24 | john: 25 | - Frequency correction option switch 26 | - Read from I/Q file documentation 27 | - Bits per audio sample (bps) option switch 28 | 29 | lachesis: 30 | - Mute switch 31 | - Simplified TunerDemod class 32 | - Removed 44 byte header-only files 33 | 34 | madengr: 35 | - Initial code 36 | - AM demodulation 37 | - Priority channels 38 | 39 | ## Console Operation: 40 | 41 | The following is an example of the option switches for UHD with NBFM demodulation, although omission of any will use default values (shown below) that are optimal for the B200: 42 | 43 | ./ham2mon.py -a "uhd" -n 8 -d 0 -f 146E6 -r 4E6 -g 30 -s -60 -v 0 -t 10 -w 44 | 45 | The following is an example of the option switches for UHD with AM demodulation, primarily meant for VHF air band reception. Note the squelch has been lowered 10 dB to aid with weak AM detection: 46 | 47 | ./ham2mon.py -a "uhd" -n 8 -d 1 -f 135E6 -r 4E6 -g 30 -s -70 -v 0 -t 10 -w 48 | 49 | The following is an example of the option switches for RTL2832U. Note the sample rate, squelch, and threshold have changed to reflect the reduced (8-bit) dynamic range of the RTL dongles compared to Ettus SDRs. In addition, these devices have poor IMD and image suppression, so strong signals may cause false demodulator locks: 50 | 51 | ./ham2mon.py -a "rtl" -n 4 -f 145E6 -r 2E6 -g 20 -s -40 -v 0 -t 30 -w 52 | 53 | Note that sometimes default RTL kernel driver (for receiving dvb) must be disabled. Google "rtl sdr blacklist" to read more about this issue, or just do this: 54 | 55 | sudo rmmod dvb_usb_rtl28xxu 56 | 57 | Example of reading from an IQ file: 58 | 59 | ./ham2mon.py -a "file=gqrx.raw,rate=8E6,repeat=false,throttle=true,freq=466E6" -r 8E6 -w 60 | 61 | ## GUI Controls: 62 | 63 | `t/r = Detection threshold +/- 5 dB. (T/R for +/- 1dB)` 64 | 65 | `p/o = Spectrum upper scale +/- 10 dB` 66 | 67 | `w/q = Spectrum lower scale +/- 10 dB` 68 | 69 | `g/f = RF gain +/- 10 dB (G/F for +/- 1dB)` 70 | 71 | `u/y = IF Gain +/- 10 dB (U/Y for +/- 1dB)` 72 | 73 | `]/[ = BB Gain +/- 10 dB (}/{ for +/- 1dB)` 74 | 75 | `s/a = Squelch +/- 1 dB` 76 | 77 | `./, = Volume +/- 1 dB` 78 | 79 | `k/j = RF center frequency +/- 100 kHz` 80 | 81 | `m/n = RF center frequency +/- 1 MHz` 82 | 83 | `v/c = RF center frequency +/- 10 MHz` 84 | 85 | `x/z = RF center frequency +/- 100 MHz` 86 | 87 | `0..9 = Lockout channel (must press during reception)` 88 | 89 | `l = Clear lockouts` 90 | 91 | `/ = Frequency entry mode (Esc to exit)` 92 | 93 | `CTRL-C = quit` 94 | 95 | ## Help Menu 96 | 97 | `Usage: ham2mon.py [options]` 98 | 99 | `Options:` 100 | 101 | ` -h, --help show this help message and exit` 102 | 103 | ` -a HW_ARGS, --args=HW_ARGS` 104 | ` Hardware args` 105 | 106 | ` -n NUM_DEMOD, --demod=NUM_DEMOD` 107 | ` Number of demodulators` 108 | 109 | ` -d TYPE_DEMOD, --demodulator=TYPE_DEMOD` 110 | ` Type of demodulator (0=NBFM, 1=AM)` 111 | 112 | ` -f CENTER_FREQ, --freq=CENTER_FREQ` 113 | ` Hardware RF center frequency in Hz` 114 | 115 | ` -r ASK_SAMP_RATE, --rate=ASK_SAMP_RATE` 116 | ` Hardware ask sample rate in sps (1E6 minimum)` 117 | 118 | ` -g GAIN_DB, --gain=GAIN_DB` 119 | ` Hardware RF gain in dB` 120 | 121 | ` -i IF_GAIN_DB, --if_gain=IF_GAIN_DB` 122 | ` Hardware IF gain in dB` 123 | 124 | ` -o BB_GAIN_DB, --bb_gain=BB_GAIN_DB` 125 | ` Hardware BB gain in dB` 126 | 127 | ` -s SQUELCH_DB, --squelch=SQUELCH_DB` 128 | ` Squelch in dB` 129 | 130 | ` -v VOLUME_DB, --volume=VOLUME_DB` 131 | ` Volume in dB` 132 | 133 | ` -t THRESHOLD_DB, --threshold=THRESHOLD_DB` 134 | ` Threshold in dB` 135 | 136 | ` -w, --write Record (write) channels to disk` 137 | 138 | ` -l LOCKOUT_FILE_NAME, --lockout=LOCKOUT_FILE_NAME` 139 | ` File of EOL delimited lockout channels in Hz` 140 | 141 | ` -p PRIORITY_FILE_NAME, --priority=PRIORITY_FILE_NAME` 142 | ` File of EOL delimited priority channels in Hz` 143 | 144 | ` -c FREQ_CORRECTION, --correction=FREQ_CORRECTION` 145 | ` Frequency correction in ppm` 146 | 147 | ` -m, --mute-audio Mute audio from speaker (still allows recording)` 148 | 149 | ` -b AUDIO_BPS, --bps=AUDIO_BPS` 150 | ` Audio bit depth (bps)` 151 | 152 | 153 | ## Description: 154 | The high speed signal processing is done in GR and the logic & control in Python. There are no custom GR blocks. The GUI is written in Curses and is meant to be lightweight. See the video for a basic overview. I attempted to make the program very object oriented and “Pythonic”. Each module runs on it's own for testing purposes. 155 | 156 | ![GRC screenshot](https://github.com/madengr/ham2mon/blob/master/flow_example.png) 157 | 158 | See the flow_example.grc for an example of the GR flow, and receiver.py for the Python coded flow. The complex samples are grouped into a vector of length 2^n and then decimated by keeping “1 in N” vectors. The FFT is taken followed by magnitude-squared to form a power spectrum. The FFT length is chosen, based on sample rate, to span about 3 RBW bins across a 12.5 kHz FM channel. The spectrum vectors are then integrated and further decimated for a video average, akin to the VBW of a spectrum analyzer. The spectrum is then probed by the Python code at ~10 Hz rate. 159 | 160 | The demodulator blocks are put into a hierarchical GR block so multiple can be instantiated in parallel. A frequency translating FIR filter tunes the channel, followed by two more decimating FIR filters to 12.5 kHz channel bandwidth. For sample rates 1 Msps or greater, the total decimation for the first three stages takes the rate to 40-80 ksps. A non-blocking power squelch silences the channel, followed by quadrature (FM) demodulation, or AGC and AM demodulation. The audio stream is filtered to 3.5 kHz bandwidth and further decimated to 8-16 ksps. A polyphase arbitrary resampler takes the final audio rate to a constant 8 ksps. The audio can then be mixed with other streams, or sunk to WAV file via a blocking squelch to remove dead audio. 161 | 162 | The scanner.py contains the control code, and may be run on on it's own non-interactively. It instantiates the receiver.py with N demodulators and probes the average spectrum at ~10 Hz. The spectrum is processed with estimate.py, which takes a weighted average of the spectrum bins that are above a threshold. This weighted average does a fair job of estimating the modulated channel center to sub-kHz resolution given the RBW is several kHz. The estimate.py returns a list of baseband channels that are rounded to the nearest 5 kHz (for NBFM band plan ambiguity). 163 | 164 | The lockout channels are removed from the list, priority channels bumped to the front, and the list used to tune the demodulators. The demodulators are only tuned if the channel has ceased activity from the last probe, otherwise the demodulator is held on the channel. Files, thus time stamps, are only re-written when the demodulator has moved, therefore priority channels are only time stamped at program start. The demodulators are parked at 0 Hz baseband when not tuned, as this provides a constant, low amplitude signal due to FM demod of LO leakage. 165 | 166 | The ham2mon.py interfaces the scanner.py with the curses.py GUI. The GUI provides a spectral display with adjustable scaling and detector threshold line. The center frequency, gain, squelch, and volume can be adjusted in real time, as well as adding channel lockouts. The hardware arguments, sample rate, number of demodulators, recording status, and lockout file are set via switches at run time. 167 | 168 | The default settings are optimized for an Ettus B200. The RTL dongle will require raising the squelch and adjustment of the spectrum scale and threshold. 169 | 170 | The next iteration of this program will probably use gr-dsd to decode P25 public safety in the 800 MHz band. 171 | -------------------------------------------------------------------------------- /apps/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc -------------------------------------------------------------------------------- /apps/am_flow_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | ################################################## 3 | # GNU Radio Python Flow Graph 4 | # Title: Ham2Mon AM Receiver Flow Example 5 | # Description: Example of GR DSP flow in receiver.py 6 | # Generated: Sun Aug 16 20:36:43 2015 7 | ################################################## 8 | 9 | if __name__ == '__main__': 10 | import ctypes 11 | import sys 12 | if sys.platform.startswith('linux'): 13 | try: 14 | x11 = ctypes.cdll.LoadLibrary('libX11.so') 15 | x11.XInitThreads() 16 | except: 17 | print "Warning: failed to XInitThreads()" 18 | 19 | from PyQt4 import Qt 20 | from gnuradio import analog 21 | from gnuradio import audio 22 | from gnuradio import blocks 23 | from gnuradio import eng_notation 24 | from gnuradio import fft 25 | from gnuradio import filter 26 | from gnuradio import gr 27 | from gnuradio import qtgui 28 | from gnuradio.eng_option import eng_option 29 | from gnuradio.fft import window 30 | from gnuradio.filter import firdes 31 | from gnuradio.filter import pfb 32 | from gnuradio.qtgui import Range, RangeWidget 33 | from optparse import OptionParser 34 | import numpy as np 35 | import osmosdr 36 | import sip 37 | import sys 38 | import time 39 | 40 | 41 | class am_flow_example(gr.top_block, Qt.QWidget): 42 | 43 | def __init__(self): 44 | gr.top_block.__init__(self, "Ham2Mon AM Receiver Flow Example") 45 | Qt.QWidget.__init__(self) 46 | self.setWindowTitle("Ham2Mon AM Receiver Flow Example") 47 | try: 48 | self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) 49 | except: 50 | pass 51 | self.top_scroll_layout = Qt.QVBoxLayout() 52 | self.setLayout(self.top_scroll_layout) 53 | self.top_scroll = Qt.QScrollArea() 54 | self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) 55 | self.top_scroll_layout.addWidget(self.top_scroll) 56 | self.top_scroll.setWidgetResizable(True) 57 | self.top_widget = Qt.QWidget() 58 | self.top_scroll.setWidget(self.top_widget) 59 | self.top_layout = Qt.QVBoxLayout(self.top_widget) 60 | self.top_grid_layout = Qt.QGridLayout() 61 | self.top_layout.addLayout(self.top_grid_layout) 62 | 63 | self.settings = Qt.QSettings("GNU Radio", "am_flow_example") 64 | self.restoreGeometry(self.settings.value("geometry").toByteArray()) 65 | 66 | ################################################## 67 | # Variables 68 | ################################################## 69 | self.samp_rate = samp_rate = 1E6 70 | self.initial_decim = initial_decim = 5 71 | self.samp_ratio = samp_ratio = samp_rate/1E6 72 | self.final_rate = final_rate = samp_rate/initial_decim**2/int(samp_rate/1E6) 73 | 74 | self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 = firdes.low_pass(1.0, final_rate, 3500, 500, firdes.WIN_HAMMING, 6.76) 75 | 76 | 77 | self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 = firdes.low_pass(1.0, samp_rate/25, 12.5E3, 1E3, firdes.WIN_HAMMING, 6.76) 78 | 79 | 80 | self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 = firdes.low_pass(1.0, 1, 0.090, 0.010, firdes.WIN_HAMMING, 6.76) 81 | 82 | self.squelch_dB = squelch_dB = -70 83 | self.gain_db = gain_db = 30 84 | self.final_decim = final_decim = int(samp_rate/1E6) 85 | self.file_name = file_name = "test.wav" 86 | self.fft_length = fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2)))) 87 | self.demod_bb_freq = demod_bb_freq = 390E3 88 | self.center_freq = center_freq = 144E6 89 | 90 | ################################################## 91 | # Blocks 92 | ################################################## 93 | self._squelch_dB_range = Range(-100, 0, 5, -70, 200) 94 | self._squelch_dB_win = RangeWidget(self._squelch_dB_range, self.set_squelch_dB, "Squelch (dB)", "counter_slider", float) 95 | self.top_grid_layout.addWidget(self._squelch_dB_win, 5,1,1,3) 96 | self._gain_db_range = Range(0, 70, 1, 30, 200) 97 | self._gain_db_win = RangeWidget(self._gain_db_range, self.set_gain_db, "HW Gain (dB)", "counter_slider", float) 98 | self.top_grid_layout.addWidget(self._gain_db_win, 4,1,1,3) 99 | self._demod_bb_freq_range = Range(-samp_rate/2, samp_rate/2, 5E3, 390E3, 200) 100 | self._demod_bb_freq_win = RangeWidget(self._demod_bb_freq_range, self.set_demod_bb_freq, "Demod BB Freq (Hz)", "counter_slider", float) 101 | self.top_grid_layout.addWidget(self._demod_bb_freq_win, 3,1,1,3) 102 | self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 103 | fft_length, #size 104 | samp_rate, #samp_rate 105 | "Averaged Spectrum", #name 106 | 1 #number of inputs 107 | ) 108 | self.qtgui_time_sink_x_0.set_update_time(0.10) 109 | self.qtgui_time_sink_x_0.set_y_axis(-60, 40) 110 | 111 | self.qtgui_time_sink_x_0.set_y_label("Power", "") 112 | 113 | self.qtgui_time_sink_x_0.enable_tags(-1, True) 114 | self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") 115 | self.qtgui_time_sink_x_0.enable_autoscale(False) 116 | self.qtgui_time_sink_x_0.enable_grid(False) 117 | self.qtgui_time_sink_x_0.enable_control_panel(False) 118 | 119 | if not True: 120 | self.qtgui_time_sink_x_0.disable_legend() 121 | 122 | labels = ["", "", "", "", "", 123 | "", "", "", "", ""] 124 | widths = [1, 1, 1, 1, 1, 125 | 1, 1, 1, 1, 1] 126 | colors = ["blue", "red", "green", "black", "cyan", 127 | "magenta", "yellow", "dark red", "dark green", "blue"] 128 | styles = [1, 1, 1, 1, 1, 129 | 1, 1, 1, 1, 1] 130 | markers = [-1, -1, -1, -1, -1, 131 | -1, -1, -1, -1, -1] 132 | alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 133 | 1.0, 1.0, 1.0, 1.0, 1.0] 134 | 135 | for i in xrange(1): 136 | if len(labels[i]) == 0: 137 | self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) 138 | else: 139 | self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) 140 | self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) 141 | self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) 142 | self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) 143 | self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) 144 | self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) 145 | 146 | self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) 147 | self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 0,1,3,1) 148 | self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 149 | 1024, #size 150 | firdes.WIN_BLACKMAN_hARRIS, #wintype 151 | 0, #fc 152 | final_rate, #bw 153 | "Decimated Channel", #name 154 | 1 #number of inputs 155 | ) 156 | self.qtgui_freq_sink_x_0_0.set_update_time(0.10) 157 | self.qtgui_freq_sink_x_0_0.set_y_axis(-200, -60) 158 | self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") 159 | self.qtgui_freq_sink_x_0_0.enable_autoscale(False) 160 | self.qtgui_freq_sink_x_0_0.enable_grid(False) 161 | self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) 162 | self.qtgui_freq_sink_x_0_0.enable_control_panel(False) 163 | 164 | if not True: 165 | self.qtgui_freq_sink_x_0_0.disable_legend() 166 | 167 | if complex == type(float()): 168 | self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True) 169 | 170 | labels = ["", "", "", "", "", 171 | "", "", "", "", ""] 172 | widths = [1, 1, 1, 1, 1, 173 | 1, 1, 1, 1, 1] 174 | colors = ["blue", "red", "green", "black", "cyan", 175 | "magenta", "yellow", "dark red", "dark green", "dark blue"] 176 | alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 177 | 1.0, 1.0, 1.0, 1.0, 1.0] 178 | for i in xrange(1): 179 | if len(labels[i]) == 0: 180 | self.qtgui_freq_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) 181 | else: 182 | self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i]) 183 | self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i]) 184 | self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i]) 185 | self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i]) 186 | 187 | self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget) 188 | self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win, 3,0,3,1) 189 | self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 190 | fft_length, #size 191 | firdes.WIN_BLACKMAN_hARRIS, #wintype 192 | 144E6, #fc 193 | samp_rate, #bw 194 | "Spectrum", #name 195 | 1 #number of inputs 196 | ) 197 | self.qtgui_freq_sink_x_0.set_update_time(0.10) 198 | self.qtgui_freq_sink_x_0.set_y_axis(-120, -20) 199 | self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") 200 | self.qtgui_freq_sink_x_0.enable_autoscale(False) 201 | self.qtgui_freq_sink_x_0.enable_grid(False) 202 | self.qtgui_freq_sink_x_0.set_fft_average(1.0) 203 | self.qtgui_freq_sink_x_0.enable_control_panel(False) 204 | 205 | if not True: 206 | self.qtgui_freq_sink_x_0.disable_legend() 207 | 208 | if complex == type(float()): 209 | self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) 210 | 211 | labels = ["", "", "", "", "", 212 | "", "", "", "", ""] 213 | widths = [1, 1, 1, 1, 1, 214 | 1, 1, 1, 1, 1] 215 | colors = ["blue", "red", "green", "black", "cyan", 216 | "magenta", "yellow", "dark red", "dark green", "dark blue"] 217 | alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 218 | 1.0, 1.0, 1.0, 1.0, 1.0] 219 | for i in xrange(1): 220 | if len(labels[i]) == 0: 221 | self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) 222 | else: 223 | self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) 224 | self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) 225 | self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) 226 | self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) 227 | 228 | self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) 229 | self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,3,1) 230 | self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_fff( 231 | 16E3/float(final_rate/5), 232 | taps=None, 233 | flt_size=32) 234 | self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) 235 | 236 | self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "uhd" ) 237 | self.osmosdr_source_0.set_sample_rate(samp_rate) 238 | self.osmosdr_source_0.set_center_freq(center_freq, 0) 239 | self.osmosdr_source_0.set_freq_corr(0, 0) 240 | self.osmosdr_source_0.set_dc_offset_mode(0, 0) 241 | self.osmosdr_source_0.set_iq_balance_mode(0, 0) 242 | self.osmosdr_source_0.set_gain_mode(False, 0) 243 | self.osmosdr_source_0.set_gain(gain_db, 0) 244 | self.osmosdr_source_0.set_if_gain(20, 0) 245 | self.osmosdr_source_0.set_bb_gain(20, 0) 246 | self.osmosdr_source_0.set_antenna("", 0) 247 | self.osmosdr_source_0.set_bandwidth(samp_rate*0.8, 0) 248 | 249 | self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0), demod_bb_freq, samp_rate) 250 | self.fir_filter_xxx_0_1 = filter.fir_filter_fff(initial_decim, (variable_low_pass_filter_taps_0)) 251 | self.fir_filter_xxx_0_1.declare_sample_delay(0) 252 | self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(int(samp_rate/1E6), (variable_low_pass_filter_taps_0)) 253 | self.fir_filter_xxx_0_0.declare_sample_delay(0) 254 | self.fir_filter_xxx_0 = filter.fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0)) 255 | self.fir_filter_xxx_0.declare_sample_delay(0) 256 | self.fft_vxx_0 = fft.fft_vcc(fft_length, True, (window.blackmanharris(fft_length)), True, 1) 257 | self.blocks_wavfile_sink_0 = blocks.wavfile_sink(file_name, 1, 16000, 8) 258 | self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_length) 259 | self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_length) 260 | self.blocks_probe_signal_vx_0 = blocks.probe_signal_vf(fft_length) 261 | self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, fft_length, 0) 262 | self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_gr_complex*fft_length, int(round(samp_rate/fft_length/1000))) 263 | self.blocks_integrate_xx_0 = blocks.integrate_ff(100, fft_length) 264 | self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_length) 265 | self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) 266 | self.audio_sink_0 = audio.sink(16000, "", True) 267 | self.analog_pwr_squelch_xx_0_0 = analog.pwr_squelch_ff(-200, 0.1, 0, True) 268 | self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(squelch_dB, 0.1, 0, False) 269 | self.analog_agc3_xx_0 = analog.agc3_cc(1e-0, 1e-4, 0.1, 10, 1) 270 | self.analog_agc3_xx_0.set_max_gain(10000) 271 | 272 | ################################################## 273 | # Connections 274 | ################################################## 275 | self.connect((self.analog_agc3_xx_0, 0), (self.blocks_complex_to_mag_0, 0)) 276 | self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_agc3_xx_0, 0)) 277 | self.connect((self.analog_pwr_squelch_xx_0_0, 0), (self.blocks_wavfile_sink_0, 0)) 278 | self.connect((self.blocks_complex_to_mag_0, 0), (self.fir_filter_xxx_0_1, 0)) 279 | self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) 280 | self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0, 0)) 281 | self.connect((self.blocks_keep_one_in_n_0, 0), (self.fft_vxx_0, 0)) 282 | self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_vx_0, 0)) 283 | self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_vector_to_stream_0, 0)) 284 | self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_keep_one_in_n_0, 0)) 285 | self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_time_sink_x_0, 0)) 286 | self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) 287 | self.connect((self.fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0, 0)) 288 | self.connect((self.fir_filter_xxx_0_0, 0), (self.analog_pwr_squelch_xx_0, 0)) 289 | self.connect((self.fir_filter_xxx_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) 290 | self.connect((self.fir_filter_xxx_0_1, 0), (self.pfb_arb_resampler_xxx_0, 0)) 291 | self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0, 0)) 292 | self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0)) 293 | self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) 294 | self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) 295 | self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.analog_pwr_squelch_xx_0_0, 0)) 296 | self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.audio_sink_0, 0)) 297 | 298 | def closeEvent(self, event): 299 | self.settings = Qt.QSettings("GNU Radio", "am_flow_example") 300 | self.settings.setValue("geometry", self.saveGeometry()) 301 | event.accept() 302 | 303 | def get_samp_rate(self): 304 | return self.samp_rate 305 | 306 | def set_samp_rate(self, samp_rate): 307 | self.samp_rate = samp_rate 308 | self.set_final_decim(int(self.samp_rate/1E6)) 309 | self.set_final_rate(self.samp_rate/self.initial_decim**2/int(self.samp_rate/1E6)) 310 | self.set_samp_ratio(self.samp_rate/1E6) 311 | self.blocks_keep_one_in_n_0.set_n(int(round(self.samp_rate/self.fft_length/1000))) 312 | self.osmosdr_source_0.set_sample_rate(self.samp_rate) 313 | self.osmosdr_source_0.set_bandwidth(self.samp_rate*0.8, 0) 314 | self.qtgui_freq_sink_x_0.set_frequency_range(144E6, self.samp_rate) 315 | self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate) 316 | 317 | def get_initial_decim(self): 318 | return self.initial_decim 319 | 320 | def set_initial_decim(self, initial_decim): 321 | self.initial_decim = initial_decim 322 | self.set_final_rate(self.samp_rate/self.initial_decim**2/int(self.samp_rate/1E6)) 323 | 324 | def get_samp_ratio(self): 325 | return self.samp_ratio 326 | 327 | def set_samp_ratio(self, samp_ratio): 328 | self.samp_ratio = samp_ratio 329 | self.set_fft_length(256 * int(pow(2, np.ceil(np.log(self.samp_ratio)/np.log(2))))) 330 | 331 | def get_final_rate(self): 332 | return self.final_rate 333 | 334 | def set_final_rate(self, final_rate): 335 | self.final_rate = final_rate 336 | self.pfb_arb_resampler_xxx_0.set_rate(16E3/float(self.final_rate/5)) 337 | self.qtgui_freq_sink_x_0_0.set_frequency_range(0, self.final_rate) 338 | 339 | def get_variable_low_pass_filter_taps_2(self): 340 | return self.variable_low_pass_filter_taps_2 341 | 342 | def set_variable_low_pass_filter_taps_2(self, variable_low_pass_filter_taps_2): 343 | self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 344 | 345 | def get_variable_low_pass_filter_taps_1(self): 346 | return self.variable_low_pass_filter_taps_1 347 | 348 | def set_variable_low_pass_filter_taps_1(self, variable_low_pass_filter_taps_1): 349 | self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 350 | 351 | def get_variable_low_pass_filter_taps_0(self): 352 | return self.variable_low_pass_filter_taps_0 353 | 354 | def set_variable_low_pass_filter_taps_0(self, variable_low_pass_filter_taps_0): 355 | self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 356 | self.fir_filter_xxx_0.set_taps((self.variable_low_pass_filter_taps_0)) 357 | self.fir_filter_xxx_0_0.set_taps((self.variable_low_pass_filter_taps_0)) 358 | self.fir_filter_xxx_0_1.set_taps((self.variable_low_pass_filter_taps_0)) 359 | self.freq_xlating_fir_filter_xxx_0.set_taps((self.variable_low_pass_filter_taps_0)) 360 | 361 | def get_squelch_dB(self): 362 | return self.squelch_dB 363 | 364 | def set_squelch_dB(self, squelch_dB): 365 | self.squelch_dB = squelch_dB 366 | self.analog_pwr_squelch_xx_0.set_threshold(self.squelch_dB) 367 | 368 | def get_gain_db(self): 369 | return self.gain_db 370 | 371 | def set_gain_db(self, gain_db): 372 | self.gain_db = gain_db 373 | self.osmosdr_source_0.set_gain(self.gain_db, 0) 374 | 375 | def get_final_decim(self): 376 | return self.final_decim 377 | 378 | def set_final_decim(self, final_decim): 379 | self.final_decim = final_decim 380 | 381 | def get_file_name(self): 382 | return self.file_name 383 | 384 | def set_file_name(self, file_name): 385 | self.file_name = file_name 386 | self.blocks_wavfile_sink_0.open(self.file_name) 387 | 388 | def get_fft_length(self): 389 | return self.fft_length 390 | 391 | def set_fft_length(self, fft_length): 392 | self.fft_length = fft_length 393 | self.blocks_keep_one_in_n_0.set_n(int(round(self.samp_rate/self.fft_length/1000))) 394 | 395 | def get_demod_bb_freq(self): 396 | return self.demod_bb_freq 397 | 398 | def set_demod_bb_freq(self, demod_bb_freq): 399 | self.demod_bb_freq = demod_bb_freq 400 | self.freq_xlating_fir_filter_xxx_0.set_center_freq(self.demod_bb_freq) 401 | 402 | def get_center_freq(self): 403 | return self.center_freq 404 | 405 | def set_center_freq(self, center_freq): 406 | self.center_freq = center_freq 407 | self.osmosdr_source_0.set_center_freq(self.center_freq, 0) 408 | 409 | 410 | if __name__ == '__main__': 411 | parser = OptionParser(option_class=eng_option, usage="%prog: [options]") 412 | (options, args) = parser.parse_args() 413 | from distutils.version import StrictVersion 414 | if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"): 415 | Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster')) 416 | qapp = Qt.QApplication(sys.argv) 417 | tb = am_flow_example() 418 | tb.start() 419 | tb.show() 420 | 421 | def quitting(): 422 | tb.stop() 423 | tb.wait() 424 | qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) 425 | qapp.exec_() 426 | tb = None # to clean up Qt widgets 427 | -------------------------------------------------------------------------------- /apps/cursesgui.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sun Jul 5 17:16:22 2015 5 | 6 | @author: madengr 7 | """ 8 | import locale 9 | locale.setlocale(locale.LC_ALL, '') 10 | import curses 11 | import time 12 | import numpy as np 13 | 14 | 15 | class SpectrumWindow(object): 16 | """Curses spectrum display window 17 | 18 | Args: 19 | screen (object): a curses screen object 20 | 21 | Attributes: 22 | max_db (float): Top of window in dB 23 | min_db (float): Bottom of window in dB 24 | threshold_db (float): Threshold horizontal line 25 | """ 26 | def __init__(self, screen): 27 | self.screen = screen 28 | 29 | # Set default values 30 | self.max_db = 50.0 31 | self.min_db = -20.0 32 | self.threshold_db = 20.0 33 | 34 | # Create a window object in top half of the screen, within the border 35 | screen_dims = screen.getmaxyx() 36 | height = int(screen_dims[0]/2.0) 37 | width = screen_dims[1]-2 38 | self.win = curses.newwin(height, width, 1, 1) 39 | self.dims = self.win.getmaxyx() 40 | 41 | # Right end of window resreved for string of N charachters 42 | self.chars = 7 43 | 44 | def draw_spectrum(self, data): 45 | """Scales input spectral data to window dimensions and draws bar graph 46 | 47 | Args: 48 | data (numpy.ndarray): FFT power spectrum data in linear, not dB 49 | 50 | Test cases for data with min_db=-100 and max_db=0 on 80x24 terminal: 51 | 1.0E-10 draws nothing since it is not above -100 dB 52 | 1.1E-10 draws one row 53 | 1.0E-05 draws 5 rows 54 | 1.0E+00 draws 10 rows 55 | 1.0E+01 draws 10 rows 56 | """ 57 | # Keep min_db to 10 dB below max_db 58 | if self.min_db > (self.max_db - 10): 59 | self.min_db = self.max_db - 10 60 | 61 | # Split the data into N window bins 62 | # N is window width between border (i.e. self.dims[1]-2 ) 63 | # Data must be at least as long as the window width or crash 64 | # Use the maximum value from each input data bin for the window bin 65 | win_bins = np.array_split(data, self.dims[1]-self.chars) 66 | win_bin_max = [] 67 | for win_bin in win_bins: 68 | win_bin_max.append(np.max(win_bin)) 69 | 70 | # Convert to dB 71 | win_bin_max_db = 10*np.log10(win_bin_max) 72 | 73 | # The plot windows starts from max_db at the top 74 | # and draws DOWNWARD to min_db (remember this is a curses window). 75 | # Thus linear scaling goes from min_y=1 at the top 76 | # and draws DOWNWARD to max_y=dims[0]-1 at the bottom 77 | # The "1" and "-1" is to account for the border at top and bottom 78 | min_y = 1 79 | max_y = self.dims[0]-1 80 | 81 | # Scaling factor for plot 82 | scale = (min_y-max_y)/(self.max_db-self.min_db) 83 | 84 | # Generate y position, clip to window, and convert to int 85 | pos_y = (win_bin_max_db - self.max_db) * scale 86 | pos_y = np.clip(pos_y, min_y, max_y) 87 | pos_y = pos_y.astype(int) 88 | 89 | # Clear previous contents, draw border, and title 90 | self.win.clear() 91 | self.win.border(0) 92 | self.win.addnstr(0, self.dims[1]/2-4, "SPECTRUM", 8, 93 | curses.color_pair(4)) 94 | 95 | # Draw the bars 96 | for pos_x in range(len(pos_y)): 97 | # Invert the y fill since we want bars 98 | # Offset x (column) by 1 so it does not start on the border 99 | self.win.vline(pos_y[pos_x], pos_x+1, "*", max_y-pos_y[pos_x]) 100 | 101 | # Draw the max_db and min_db strings 102 | string = ">" + "%+03d" % self.max_db 103 | self.win.addnstr(0, 1 + self.dims[1] - self.chars, string, self.chars, 104 | curses.color_pair(1)) 105 | string = ">" + "%+03d" % self.min_db 106 | self.win.addnstr(max_y, 1 + self.dims[1] - self.chars, string, 107 | self.chars, curses.color_pair(3)) 108 | 109 | # Generate threshold line, clip to window, and convert to int 110 | pos_yt = (self.threshold_db - self.max_db) * scale 111 | pos_yt = np.clip(pos_yt, min_y, max_y-1) 112 | pos_yt = pos_yt.astype(int) 113 | 114 | # Draw the theshold line 115 | # x=1 start to account for left border 116 | self.win.hline(pos_yt, 1, "-", len(pos_y)) 117 | 118 | # Draw the theshold string 119 | string = ">" + "%+03d" % self.threshold_db 120 | self.win.addnstr(pos_yt, (1 + self.dims[1] - self.chars), string, 121 | self.chars, curses.color_pair(2)) 122 | 123 | # Hide cursor 124 | self.win.leaveok(1) 125 | 126 | # Update virtual window 127 | self.win.noutrefresh() 128 | 129 | def proc_keyb(self, keyb): 130 | """Process keystrokes 131 | 132 | Args: 133 | keyb (int): keystroke in ASCII 134 | 135 | Returns: 136 | bool: True if receiver needs tuning, False if not 137 | 138 | """ 139 | if keyb == ord('t'): 140 | self.threshold_db += 5 141 | return True 142 | elif keyb == ord('r'): 143 | self.threshold_db -= 5 144 | return True 145 | elif keyb == ord('T'): 146 | self.threshold_db += 1 147 | return True 148 | elif keyb == ord('R'): 149 | self.threshold_db -= 1 150 | return True 151 | elif keyb == ord('p'): 152 | self.max_db += 10 153 | elif keyb == ord('o'): 154 | self.max_db -= 10 155 | elif keyb == ord('w'): 156 | self.min_db += 10 157 | elif keyb == ord('q'): 158 | self.min_db -= 10 159 | else: 160 | pass 161 | return False 162 | 163 | 164 | class ChannelWindow(object): 165 | """Curses channel display window 166 | 167 | Args: 168 | screen (object): a curses screen object 169 | """ 170 | # pylint: disable=too-few-public-methods 171 | 172 | def __init__(self, screen): 173 | self.screen = screen 174 | 175 | # Create a window object in the bottom half of the screen 176 | # Make it about 1/3 the screen width 177 | # Place on left side and to the right of the border 178 | screen_dims = screen.getmaxyx() 179 | height = int(screen_dims[0]/2.0)-2 180 | width = int(screen_dims[1]/3.0)-1 181 | self.win = curses.newwin(height, width, height + 3, 1) 182 | self.dims = self.win.getmaxyx() 183 | 184 | def draw_channels(self, gui_tuned_channels): 185 | """Draws tuned channels list 186 | 187 | Args: 188 | rf_channels [string]: List of strings in MHz 189 | """ 190 | 191 | # Clear previous contents, draw border, and title 192 | self.win.clear() 193 | self.win.border(0) 194 | self.win.addnstr(0, self.dims[1]/2-4, "CHANNELS", 8, 195 | curses.color_pair(4)) 196 | 197 | # Limit the displayed channels to no more than two rows 198 | max_length = 2*(self.dims[0]-2) 199 | if len(gui_tuned_channels) > max_length: 200 | gui_tuned_channels = gui_tuned_channels[:max_length] 201 | else: 202 | pass 203 | 204 | # Draw the tuned channels prefixed by index in list (demodulator index) 205 | for idx, gui_tuned_channel in enumerate(gui_tuned_channels): 206 | text = str(idx) + ": " + gui_tuned_channel 207 | if idx < self.dims[0]-2: 208 | # Display in first column 209 | self.win.addnstr(idx+1, 1, text, 11) 210 | else: 211 | # Display in second column 212 | self.win.addnstr(idx-self.dims[0]+3, 13, text, 11) 213 | 214 | # Hide cursor 215 | self.win.leaveok(1) 216 | 217 | # Update virtual window 218 | self.win.noutrefresh() 219 | 220 | 221 | class LockoutWindow(object): 222 | """Curses lockout channel display window 223 | 224 | Args: 225 | screen (object): a curses screen object 226 | """ 227 | # pylint: disable=too-few-public-methods 228 | 229 | def __init__(self, screen): 230 | self.screen = screen 231 | 232 | # Create a window object in the bottom half of the screen 233 | # Make it about 1/4 the screen width 234 | # Place on left side and to the right of the border 235 | screen_dims = screen.getmaxyx() 236 | height = int(screen_dims[0]/2.0)-2 237 | width = int(screen_dims[1]/4.0)-5 238 | self.win = curses.newwin(height, width, height + 3, 26) 239 | self.dims = self.win.getmaxyx() 240 | 241 | def draw_channels(self, gui_lockout_channels): 242 | """Draws tuned channels list 243 | 244 | Args: 245 | rf_channels [string]: List of strings in MHz 246 | """ 247 | # Clear previous contents, draw border, and title 248 | self.win.clear() 249 | self.win.border(0) 250 | self.win.addnstr(0, self.dims[1]/2-3, "LOCKOUT", 7, 251 | curses.color_pair(4)) 252 | 253 | # Draw the lockout channels 254 | for idx, gui_lockout_channel in enumerate(gui_lockout_channels): 255 | # Don't draw past height of window 256 | if idx <= self.dims[0]-3: 257 | text = " " + gui_lockout_channel 258 | self.win.addnstr(idx+1, 1, text, 11) 259 | else: 260 | pass 261 | 262 | # Hide cursor 263 | self.win.leaveok(1) 264 | 265 | # Update virtual window 266 | self.win.noutrefresh() 267 | 268 | def proc_keyb_set_lockout(self, keyb): 269 | """Process keystrokes to lock out channels 0 - 9 270 | 271 | Args: 272 | keyb (int): keystroke in ASCII 273 | 274 | Returns: 275 | bool: True if scanner needs adjusting, False if not 276 | """ 277 | # pylint: disable=no-self-use 278 | 279 | # Check if keys 0 - 9 pressed 280 | if keyb - 48 in range(10): 281 | return True 282 | else: 283 | return False 284 | 285 | def proc_keyb_clear_lockout(self, keyb): 286 | """Process keystrokes to clear lockout with "l" 287 | 288 | Args: 289 | keyb (int): keystroke in ASCII 290 | 291 | Returns: 292 | bool: True if scanner needs adjusting, False if not 293 | """ 294 | # pylint: disable=no-self-use 295 | 296 | # Check if 'l' is pressed 297 | if keyb == ord('l'): 298 | return True 299 | else: 300 | return False 301 | 302 | 303 | class RxWindow(object): 304 | """Curses receiver paramater window 305 | 306 | Args: 307 | screen (object): a curses screen object 308 | 309 | Attributes: 310 | center_freq (float): Hardware RF center frequency in Hz 311 | samp_rate (float): Hardware sample rate in sps (1E6 min) 312 | gain_db (int): Hardware RF gain in dB 313 | if_gain_db (int): Hardware IF gain in dB 314 | bb_gain_db (int): Hardware BB gain in dB 315 | squelch_db (int): Squelch in dB 316 | volume_dB (int): Volume in dB 317 | record (bool): Record audio to file if True 318 | lockout_file_name (string): Name of file with channels to lockout 319 | priority_file_name (string): Name of file with channels for priority 320 | """ 321 | # pylint: disable=too-many-instance-attributes 322 | 323 | def __init__(self, screen): 324 | self.screen = screen 325 | 326 | # Set default values 327 | self.center_freq = 146E6 328 | self.samp_rate = 2E6 329 | self.freq_entry = 'None' 330 | self.gain_db = 0 331 | self.if_gain_db = 16 332 | self.bb_gain_db = 16 333 | self.squelch_db = -60 334 | self.volume_db = 0 335 | self.type_demod = 0 336 | self.record = True 337 | self.lockout_file_name = "" 338 | self.priority_file_name = "" 339 | 340 | # Create a window object in the bottom half of the screen 341 | # Make it about 1/3 the screen width 342 | # Place on right side and to the left of the border 343 | screen_dims = screen.getmaxyx() 344 | height = int(screen_dims[0]/2.0)-2 345 | width = int(screen_dims[1]/2.0)-2 346 | self.win = curses.newwin(height, width, height + 3, 347 | int(screen_dims[1]-width-1)) 348 | self.dims = self.win.getmaxyx() 349 | 350 | def draw_rx(self): 351 | """Draws receiver paramaters 352 | """ 353 | 354 | # Clear previous contents, draw border, and title 355 | self.win.clear() 356 | self.win.border(0) 357 | self.win.addnstr(0, self.dims[1]/2-4, "RECEIVER", 8, 358 | curses.color_pair(4)) 359 | 360 | # Draw the receiver info prefix fields 361 | text = "RF Freq (MHz) : " 362 | self.win.addnstr(1, 1, text, 15) 363 | text = "RF Gain (dB) : " 364 | self.win.addnstr(2, 1, text, 15) 365 | text = "IF Gain (dB) : " 366 | self.win.addnstr(3, 1, text, 15) 367 | text = "BB Gain (dB) : " 368 | self.win.addnstr(4, 1, text, 15) 369 | text = "BB Rate (Msps): " 370 | self.win.addnstr(5, 1, text, 15) 371 | text = "BB Sql (dB) : " 372 | self.win.addnstr(6, 1, text, 15) 373 | text = "AF Vol (dB) : " 374 | self.win.addnstr(7, 1, text, 15) 375 | text = "Record : " 376 | self.win.addnstr(8, 1, text, 15) 377 | text = "Demod Type : " 378 | self.win.addnstr(9, 1, text, 15) 379 | text = "Files : " 380 | self.win.addnstr(10, 1, text, 15) 381 | 382 | # Draw the receiver info suffix fields 383 | if self.freq_entry <> 'None': 384 | text = self.freq_entry 385 | else: 386 | text = '{:.3f}'.format((self.center_freq)/1E6) 387 | self.win.addnstr(1, 17, text, 8, curses.color_pair(5)) 388 | text = str(self.gain_db) 389 | self.win.addnstr(2, 17, text, 8, curses.color_pair(5)) 390 | text = str(self.if_gain_db) 391 | self.win.addnstr(3, 17, text, 8, curses.color_pair(5)) 392 | text = str(self.bb_gain_db) 393 | self.win.addnstr(4, 17, text, 8, curses.color_pair(5)) 394 | text = str(self.samp_rate/1E6) 395 | self.win.addnstr(5, 17, text, 8) 396 | text = str(self.squelch_db) 397 | self.win.addnstr(6, 17, text, 8, curses.color_pair(5)) 398 | text = str(self.volume_db) 399 | self.win.addnstr(7, 17, text, 8, curses.color_pair(5)) 400 | text = str(self.record) 401 | self.win.addnstr(8, 17, text, 8) 402 | text = str(self.type_demod) 403 | self.win.addnstr(9, 17, text, 8) 404 | text = str(self.lockout_file_name) + " " + str(self.priority_file_name) 405 | self.win.addnstr(10, 17, text, 20) 406 | 407 | # Hide cursor 408 | self.win.leaveok(1) 409 | 410 | # Update virtual window 411 | self.win.noutrefresh() 412 | 413 | def proc_keyb_hard(self, keyb): 414 | """Process keystrokes to adjust hard receiver settings 415 | 416 | Tune center_freq in 100 MHz steps with 'x' and 'c' 417 | Tune center_freq in 10 MHz steps with 'v' and 'c' 418 | Tune center_freq in 1 MHz steps with 'm' and 'n' 419 | Tune center_freq in 100 kHz steps with 'k' and 'j' 420 | 421 | Args: 422 | keyb (int): keystroke in ASCII 423 | 424 | Returns: 425 | bool: True if receiver needs adjusting, False if not 426 | """ 427 | # pylint: disable=too-many-return-statements 428 | # pylint: disable=too-many-branches 429 | 430 | # Tune self.center_freq in 100 MHz steps with 'x' and 'c' 431 | if keyb == ord('x'): 432 | self.center_freq += 1E8 433 | return True 434 | elif keyb == ord('z'): 435 | self.center_freq -= 1E8 436 | return True 437 | # Tune self.center_freq in 10 MHz steps with 'v' and 'c' 438 | elif keyb == ord('v'): 439 | self.center_freq += 1E7 440 | return True 441 | elif keyb == ord('c'): 442 | self.center_freq -= 1E7 443 | return True 444 | # Tune self.center_freq in 1 MHz steps with 'm' and 'n' 445 | elif keyb == ord('m'): 446 | self.center_freq += 1E6 447 | return True 448 | elif keyb == ord('n'): 449 | self.center_freq -= 1E6 450 | return True 451 | # Tune self.center_freq in 100 kHz steps with 'k' and 'j' 452 | elif keyb == ord('k'): 453 | self.center_freq += 1E5 454 | return True 455 | elif keyb == ord('j'): 456 | self.center_freq -= 1E5 457 | return True 458 | elif keyb == ord('/'): 459 | # set mode to frequency entry 460 | self.freq_entry = '' 461 | return False 462 | elif keyb == 27: # ESC 463 | # end frequncy entry mode without seting the frequency 464 | self.freq_entry = 'None' 465 | return False 466 | elif keyb == ord('\n'): 467 | # set the frequency from what was entered 468 | try: 469 | self.center_freq = float(self.freq_entry) * 1E6 470 | except: 471 | pass 472 | self.freq_entry = 'None' 473 | return True 474 | elif self.freq_entry <> 'None' and (keyb - 48 in range (10) or keyb == ord('.')): 475 | # build up frequency from 1-9 and '.' 476 | self.freq_entry = self.freq_entry + chr(keyb) 477 | return False 478 | elif keyb == 127: # BKSP 479 | self.freq_entry = self.freq_entry[:-1] 480 | return False 481 | else: 482 | return False 483 | 484 | def proc_keyb_soft(self, keyb): 485 | """Process keystrokes to adjust soft receiver settings 486 | 487 | Tune gain_db in 10 dB steps with 'g' and 'f' 488 | Tune squelch_db in 1 dB steps with 's' and 'a' 489 | Tune volume_db in 1 dB steps with '.' and ',' 490 | 491 | Args: 492 | keyb (int): keystroke in ASCII 493 | 494 | Returns: 495 | bool: True if receiver needs tuning, False if not 496 | """ 497 | # pylint: disable=too-many-return-statements 498 | # pylint: disable=too-many-branches 499 | 500 | # Tune self.gain_db in 10 dB steps with 'g' and 'f' 501 | if keyb == ord('g'): 502 | self.gain_db += 10 503 | return True 504 | elif keyb == ord('f'): 505 | self.gain_db -= 10 506 | return True 507 | 508 | # Tune self.gain_db in 1 dB steps with 'G' and 'F' 509 | if keyb == ord('G'): 510 | self.gain_db += 1 511 | return True 512 | elif keyb == ord('F'): 513 | self.gain_db -= 1 514 | return True 515 | 516 | # Tune self.if_gain_db in 10 dB steps with 'u' and 'y' 517 | if keyb == ord('u'): 518 | self.if_gain_db += 10 519 | return True 520 | elif keyb == ord('y'): 521 | self.if_gain_db -= 10 522 | return True 523 | 524 | # Tune self.if_gain_db in 1 dB steps with 'U' and 'Y' 525 | if keyb == ord('U'): 526 | self.if_gain_db += 1 527 | return True 528 | elif keyb == ord('Y'): 529 | self.if_gain_db -= 1 530 | return True 531 | 532 | # Tune self.bb_gain_db in 10 dB steps with ']' and '[' 533 | if keyb == ord(']'): 534 | self.bb_gain_db += 10 535 | return True 536 | elif keyb == ord('['): 537 | self.bb_gain_db -= 10 538 | return True 539 | 540 | # Tune self.bb_gain_db in 1 dB steps with '}' and '{' 541 | if keyb == ord('}'): 542 | self.bb_gain_db += 1 543 | return True 544 | elif keyb == ord('{'): 545 | self.bb_gain_db -= 1 546 | return True 547 | 548 | # Tune self.squelch_db in 1 dB steps with 's' and 'a' 549 | elif keyb == ord('s'): 550 | self.squelch_db += 1 551 | return True 552 | elif keyb == ord('a'): 553 | self.squelch_db -= 1 554 | return True 555 | # Tune self.volume_db in 1 dB steps with '.' and ',' 556 | elif keyb == ord('.'): 557 | self.volume_db += 1 558 | return True 559 | elif keyb == ord(','): 560 | self.volume_db -= 1 561 | return True 562 | else:# pylint: disable=too-many-return-statements 563 | return False 564 | 565 | def setup_screen(screen): 566 | """Sets up screen 567 | """ 568 | # Set screen to getch() is non-blocking 569 | screen.nodelay(1) 570 | 571 | # Define some colors 572 | curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) 573 | curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) 574 | curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK) 575 | curses.init_pair(4, curses.COLOR_MAGENTA, curses.COLOR_BLACK) 576 | curses.init_pair(5, curses.COLOR_YELLOW, curses.COLOR_BLACK) 577 | 578 | # Add border 579 | screen.border(0) 580 | 581 | def main(): 582 | """Test most of the GUI (except lockout processing) 583 | 584 | Initialize and set up screen 585 | Create windows 586 | Generate dummy spectrum data 587 | Update windows with dummy values 588 | Process keyboard strokes 589 | """ 590 | # Use the curses.wrapper() to crash cleanly 591 | # Note the screen object is passed from the wrapper() 592 | # http://stackoverflow.com/questions/9854511/ppos_ython-curses-dilemma 593 | # The issue is the debuuger won't work with the wrapper() 594 | # So enable the next 2 lines and don't pass screen to main() 595 | screen = curses.initscr() 596 | curses.start_color() 597 | 598 | # Setup the screen 599 | setup_screen(screen) 600 | 601 | # Create windows 602 | specwin = SpectrumWindow(screen) 603 | chanwin = ChannelWindow(screen) 604 | lockoutwin = LockoutWindow(screen) 605 | rxwin = RxWindow(screen) 606 | 607 | while 1: 608 | # Generate some random spectrum data from -dyanmic_range to 0 dB 609 | # then offset_db 610 | length = 128 611 | dynamic_range_db = 100 612 | offset_db = 50 613 | data = np.power(10, (-dynamic_range_db*np.random.rand(length)/10)\ 614 | + offset_db/10) 615 | #data = 1E-5*np.ones(length) 616 | specwin.draw_spectrum(data) 617 | 618 | # Put some dummy values in the channel, lockout, and receiver windows 619 | chanwin.draw_channels(['144.100', '142.40', '145.00', '144.10',\ 620 | '142.40', '145.00', '144.10', '142.40', '145.00', '144.10', '142.40',\ 621 | '145.00', '142.40', '145.00', '144.10', '142.400', '145.00', '145.00']) 622 | lockoutwin.draw_channels(['144.100', '142.40', '145.00']) 623 | rxwin.draw_rx() 624 | 625 | # Update physical screen 626 | curses.doupdate() 627 | 628 | # Check for keystrokes and process 629 | keyb = screen.getch() 630 | specwin.proc_keyb(keyb) 631 | rxwin.proc_keyb_hard(keyb) 632 | rxwin.proc_keyb_soft(keyb) 633 | 634 | # Sleep to get about a 10 Hz refresh 635 | time.sleep(0.1) 636 | 637 | if __name__ == '__main__': 638 | try: 639 | #curses.wrapper(main) 640 | main() 641 | except KeyboardInterrupt: 642 | pass 643 | -------------------------------------------------------------------------------- /apps/estimate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sat Jul 4 12:09:03 2015 5 | 6 | @author: madengr 7 | """ 8 | 9 | import numpy as np 10 | 11 | def avg_freq(data): 12 | """Weighted average 13 | 14 | Takes spectrum bins and estimates frequency by weighted average 15 | 16 | Args: 17 | data (numpy.ndarray): FFT power spectrum in linear, not dB 18 | 19 | Returns: 20 | float: Fractional index into spectrum 21 | """ 22 | 23 | weighted_power = 0 24 | sum_power = 0 25 | for index, sample in enumerate(data): 26 | weighted_power += index*sample 27 | sum_power += sample 28 | return weighted_power / float(sum_power) 29 | 30 | 31 | def channel_estimate(spectrum, threshold): 32 | """Channel estimate 33 | 34 | Takes spectrum bins and returns channels above threshold 35 | 36 | Args: 37 | spectrum (numpy.ndarray): FFT power spectrum in linear, not dB 38 | threshold (float): Threshold value in linear, not dB 39 | 40 | Returns: 41 | List[float]: List of fractional indices into spectrum of channel center 42 | """ 43 | 44 | # Append a zero to handle last bin above threshold 45 | spectrum = np.append(spectrum, np.zeros(1)) 46 | 47 | length = len(spectrum) 48 | bins = [] 49 | channels = [] 50 | index = 0 51 | while index < length: 52 | if spectrum[index] > threshold: 53 | # If spectrum > threshold then append to bins list 54 | bins.append(spectrum[index]) 55 | index += 1 56 | elif len(bins) != 0: 57 | # Spectrum < threshold so find average freq and append to channels 58 | channels.append(index - len(bins) + avg_freq(bins)) 59 | index += 1 60 | bins = [] 61 | else: 62 | # Spectrum < threshold so move on 63 | index += 1 64 | return channels 65 | 66 | 67 | def main(): 68 | """ Tests the functions in this module""" 69 | 70 | # Test avg_freq() 71 | print "Testing avg_freq()" 72 | data = np.array([0, 1, 1, 0]) 73 | print "Input spectrum data is " + str(data) 74 | result = avg_freq(data) 75 | print "Average frequency is " + str(result) 76 | if result == 1.5: 77 | print "Test Pass" 78 | else: 79 | print "Test Fail" 80 | print "" 81 | 82 | # Test channel_estimate() 83 | print "Testing channel_estimate()" 84 | data = np.array([0, 1, 1, 0, 0, 1, 1, 1]) 85 | threshold = 0.5 86 | print "Input spectrum data is " + str(data) 87 | print "Threshold is " + str(threshold) 88 | result = channel_estimate(data, threshold) 89 | print "Channels at " + str(result) 90 | if result == [1.5, 6.0]: 91 | print "Test Pass" 92 | else: 93 | print "Test Fail" 94 | print "" 95 | 96 | 97 | if __name__ == '__main__': 98 | try: 99 | main() 100 | except KeyboardInterrupt: 101 | pass 102 | -------------------------------------------------------------------------------- /apps/ham2mon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Fri Jul 3 13:38:36 2015 5 | 6 | @author: madengr 7 | """ 8 | 9 | import scanner as scnr 10 | import curses 11 | import cursesgui 12 | import parser 13 | import time 14 | 15 | def main(screen): 16 | """Start scanner with GUI interface 17 | 18 | Initialize and set up screen 19 | Create windows 20 | Create scanner object 21 | Executes scan cycles 22 | Update windows 23 | Process keyboard strokes 24 | """ 25 | # pylint: disable=too-many-statements 26 | # pylint: disable-msg=R0914 27 | 28 | # Use the curses.wrapper() to crash cleanly 29 | # Note the screen object is passed from the wrapper() 30 | # http://stackoverflow.com/questions/9854511/python-curses-dilemma 31 | # The issue is the debuuger won't work with the wrapper() 32 | # Nor does the python optiosn parser 33 | # So enable the next 2 lines and don't pass screen to main() 34 | #screen = curses.initscr() 35 | #curses.start_color() 36 | 37 | # Setup the screen 38 | cursesgui.setup_screen(screen) 39 | 40 | # Create windows 41 | specwin = cursesgui.SpectrumWindow(screen) 42 | chanwin = cursesgui.ChannelWindow(screen) 43 | lockoutwin = cursesgui.LockoutWindow(screen) 44 | rxwin = cursesgui.RxWindow(screen) 45 | 46 | # Create scanner object 47 | ask_samp_rate = PARSER.ask_samp_rate 48 | num_demod = PARSER.num_demod 49 | type_demod = PARSER.type_demod 50 | hw_args = PARSER.hw_args 51 | record = PARSER.record 52 | play = PARSER.play 53 | lockout_file_name = PARSER.lockout_file_name 54 | priority_file_name = PARSER.priority_file_name 55 | freq_correction = PARSER.freq_correction 56 | audio_bps = PARSER.audio_bps 57 | scanner = scnr.Scanner(ask_samp_rate, num_demod, type_demod, hw_args, 58 | freq_correction, record, lockout_file_name, 59 | priority_file_name, play, audio_bps) 60 | 61 | # Set the paramaters 62 | scanner.set_center_freq(PARSER.center_freq) 63 | scanner.set_gain(PARSER.gain_db) 64 | scanner.set_if_gain(PARSER.if_gain_db) 65 | scanner.set_bb_gain(PARSER.bb_gain_db) 66 | scanner.set_squelch(PARSER.squelch_db) 67 | scanner.set_volume(PARSER.volume_db) 68 | scanner.set_threshold(PARSER.threshold_db) 69 | 70 | # Get the initial settings for GUI 71 | rxwin.center_freq = scanner.center_freq 72 | rxwin.samp_rate = scanner.samp_rate 73 | rxwin.gain_db = scanner.gain_db 74 | rxwin.if_gain_db = scanner.if_gain_db 75 | rxwin.bb_gain_db = scanner.bb_gain_db 76 | rxwin.squelch_db = scanner.squelch_db 77 | rxwin.volume_db = scanner.volume_db 78 | rxwin.record = scanner.record 79 | rxwin.type_demod = type_demod 80 | rxwin.lockout_file_name = scanner.lockout_file_name 81 | rxwin.priority_file_name = scanner.priority_file_name 82 | 83 | specwin.threshold_db = scanner.threshold_db 84 | 85 | while 1: 86 | # No need to go faster than 10 Hz rate of GNU Radio probe 87 | time.sleep(0.1) 88 | 89 | # Initiate a scan cycle 90 | scanner.scan_cycle() 91 | 92 | # Update the spectrum, channel, and rx displays 93 | specwin.draw_spectrum(scanner.spectrum) 94 | chanwin.draw_channels(scanner.gui_tuned_channels) 95 | lockoutwin.draw_channels(scanner.gui_lockout_channels) 96 | rxwin.draw_rx() 97 | 98 | # Update physical screen 99 | curses.doupdate() 100 | 101 | # Get keystroke 102 | keyb = screen.getch() 103 | 104 | # Send keystroke to spectrum window and update scanner if True 105 | if specwin.proc_keyb(keyb): 106 | scanner.set_threshold(specwin.threshold_db) 107 | 108 | # Send keystroke to RX window and update scanner if True 109 | if rxwin.proc_keyb_hard(keyb): 110 | # Set and update frequency 111 | scanner.set_center_freq(rxwin.center_freq) 112 | rxwin.center_freq = scanner.center_freq 113 | 114 | if rxwin.proc_keyb_soft(keyb): 115 | # Set and update RF gain 116 | scanner.set_gain(rxwin.gain_db) 117 | rxwin.gain_db = scanner.gain_db 118 | # Set and update IF gain 119 | scanner.set_if_gain(rxwin.if_gain_db) 120 | rxwin.if_gain_db = scanner.if_gain_db 121 | # Set and update BB gain 122 | scanner.set_bb_gain(rxwin.bb_gain_db) 123 | rxwin.bb_gain_db = scanner.bb_gain_db 124 | # Set and update squelch 125 | scanner.set_squelch(rxwin.squelch_db) 126 | rxwin.squelch_db = scanner.squelch_db 127 | # Set and update volume 128 | scanner.set_volume(rxwin.volume_db) 129 | rxwin.volume_db = scanner.volume_db 130 | 131 | # Send keystroke to lockout window and update lockout channels if True 132 | if lockoutwin.proc_keyb_set_lockout(keyb) and rxwin.freq_entry == 'None': 133 | # Subtract 48 from ascii keyb value to obtain 0 - 9 134 | idx = keyb - 48 135 | scanner.add_lockout(idx) 136 | if lockoutwin.proc_keyb_clear_lockout(keyb): 137 | scanner.clear_lockout() 138 | 139 | if __name__ == '__main__': 140 | try: 141 | # Do this since curses wrapper won't let parser write to screen 142 | PARSER = parser.CLParser() 143 | if len(PARSER.parser_args) != 0: 144 | PARSER.print_help() #pylint: disable=maybe-no-member 145 | raise SystemExit, 1 146 | else: 147 | curses.wrapper(main) 148 | except KeyboardInterrupt: 149 | pass 150 | except RuntimeError: 151 | print "" 152 | print "RuntimeError: SDR hardware not detected or insufficient USB permissions. Try running as root." 153 | print "" 154 | 155 | -------------------------------------------------------------------------------- /apps/lockout.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madengr/ham2mon/db9834ce923c1919602bf33cb47720daba9bc6ea/apps/lockout.txt -------------------------------------------------------------------------------- /apps/nbfm_flow_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | ################################################## 3 | # GNU Radio Python Flow Graph 4 | # Title: Ham2Mon NBFM Receiver Flow Example 5 | # Description: Example of GR DSP flow in receiver.py 6 | # Generated: Sun Aug 16 20:37:05 2015 7 | ################################################## 8 | 9 | if __name__ == '__main__': 10 | import ctypes 11 | import sys 12 | if sys.platform.startswith('linux'): 13 | try: 14 | x11 = ctypes.cdll.LoadLibrary('libX11.so') 15 | x11.XInitThreads() 16 | except: 17 | print "Warning: failed to XInitThreads()" 18 | 19 | from PyQt4 import Qt 20 | from gnuradio import analog 21 | from gnuradio import audio 22 | from gnuradio import blocks 23 | from gnuradio import eng_notation 24 | from gnuradio import fft 25 | from gnuradio import filter 26 | from gnuradio import gr 27 | from gnuradio import qtgui 28 | from gnuradio.eng_option import eng_option 29 | from gnuradio.fft import window 30 | from gnuradio.filter import firdes 31 | from gnuradio.filter import pfb 32 | from gnuradio.qtgui import Range, RangeWidget 33 | from optparse import OptionParser 34 | import math 35 | import numpy as np 36 | import osmosdr 37 | import sip 38 | import sys 39 | import time 40 | 41 | 42 | class nbfm_flow_example(gr.top_block, Qt.QWidget): 43 | 44 | def __init__(self): 45 | gr.top_block.__init__(self, "Ham2Mon NBFM Receiver Flow Example") 46 | Qt.QWidget.__init__(self) 47 | self.setWindowTitle("Ham2Mon NBFM Receiver Flow Example") 48 | try: 49 | self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) 50 | except: 51 | pass 52 | self.top_scroll_layout = Qt.QVBoxLayout() 53 | self.setLayout(self.top_scroll_layout) 54 | self.top_scroll = Qt.QScrollArea() 55 | self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) 56 | self.top_scroll_layout.addWidget(self.top_scroll) 57 | self.top_scroll.setWidgetResizable(True) 58 | self.top_widget = Qt.QWidget() 59 | self.top_scroll.setWidget(self.top_widget) 60 | self.top_layout = Qt.QVBoxLayout(self.top_widget) 61 | self.top_grid_layout = Qt.QGridLayout() 62 | self.top_layout.addLayout(self.top_grid_layout) 63 | 64 | self.settings = Qt.QSettings("GNU Radio", "nbfm_flow_example") 65 | self.restoreGeometry(self.settings.value("geometry").toByteArray()) 66 | 67 | ################################################## 68 | # Variables 69 | ################################################## 70 | self.samp_rate = samp_rate = 1E6 71 | self.initial_decim = initial_decim = 5 72 | self.samp_ratio = samp_ratio = samp_rate/1E6 73 | self.final_rate = final_rate = samp_rate/initial_decim**2/int(samp_rate/1E6) 74 | 75 | self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 = firdes.low_pass(1.0, final_rate, 3500, 500, firdes.WIN_HAMMING, 6.76) 76 | 77 | 78 | self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 = firdes.low_pass(1.0, samp_rate/25, 12.5E3, 1E3, firdes.WIN_HAMMING, 6.76) 79 | 80 | 81 | self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 = firdes.low_pass(1.0, 1, 0.090, 0.010, firdes.WIN_HAMMING, 6.76) 82 | 83 | self.squelch_dB = squelch_dB = -70 84 | self.gain_db = gain_db = 30 85 | self.final_decim = final_decim = int(samp_rate/1E6) 86 | self.file_name = file_name = "test.wav" 87 | self.fft_length = fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2)))) 88 | self.demod_bb_freq = demod_bb_freq = 390E3 89 | self.center_freq = center_freq = 144E6 90 | 91 | ################################################## 92 | # Blocks 93 | ################################################## 94 | self._squelch_dB_range = Range(-100, 0, 5, -70, 200) 95 | self._squelch_dB_win = RangeWidget(self._squelch_dB_range, self.set_squelch_dB, "Squelch (dB)", "counter_slider", float) 96 | self.top_grid_layout.addWidget(self._squelch_dB_win, 5,1,1,3) 97 | self._gain_db_range = Range(0, 70, 1, 30, 200) 98 | self._gain_db_win = RangeWidget(self._gain_db_range, self.set_gain_db, "HW Gain (dB)", "counter_slider", float) 99 | self.top_grid_layout.addWidget(self._gain_db_win, 4,1,1,3) 100 | self._demod_bb_freq_range = Range(-samp_rate/2, samp_rate/2, 5E3, 390E3, 200) 101 | self._demod_bb_freq_win = RangeWidget(self._demod_bb_freq_range, self.set_demod_bb_freq, "Demod BB Freq (Hz)", "counter_slider", float) 102 | self.top_grid_layout.addWidget(self._demod_bb_freq_win, 3,1,1,3) 103 | self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 104 | fft_length, #size 105 | samp_rate, #samp_rate 106 | "Averaged Spectrum", #name 107 | 1 #number of inputs 108 | ) 109 | self.qtgui_time_sink_x_0.set_update_time(0.10) 110 | self.qtgui_time_sink_x_0.set_y_axis(-60, 40) 111 | 112 | self.qtgui_time_sink_x_0.set_y_label("Power", "") 113 | 114 | self.qtgui_time_sink_x_0.enable_tags(-1, True) 115 | self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") 116 | self.qtgui_time_sink_x_0.enable_autoscale(False) 117 | self.qtgui_time_sink_x_0.enable_grid(False) 118 | self.qtgui_time_sink_x_0.enable_control_panel(False) 119 | 120 | if not True: 121 | self.qtgui_time_sink_x_0.disable_legend() 122 | 123 | labels = ["", "", "", "", "", 124 | "", "", "", "", ""] 125 | widths = [1, 1, 1, 1, 1, 126 | 1, 1, 1, 1, 1] 127 | colors = ["blue", "red", "green", "black", "cyan", 128 | "magenta", "yellow", "dark red", "dark green", "blue"] 129 | styles = [1, 1, 1, 1, 1, 130 | 1, 1, 1, 1, 1] 131 | markers = [-1, -1, -1, -1, -1, 132 | -1, -1, -1, -1, -1] 133 | alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 134 | 1.0, 1.0, 1.0, 1.0, 1.0] 135 | 136 | for i in xrange(1): 137 | if len(labels[i]) == 0: 138 | self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) 139 | else: 140 | self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) 141 | self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) 142 | self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) 143 | self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) 144 | self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) 145 | self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) 146 | 147 | self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) 148 | self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 0,1,3,1) 149 | self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 150 | 1024, #size 151 | firdes.WIN_BLACKMAN_hARRIS, #wintype 152 | 0, #fc 153 | final_rate, #bw 154 | "Decimated Channel", #name 155 | 1 #number of inputs 156 | ) 157 | self.qtgui_freq_sink_x_0_0.set_update_time(0.10) 158 | self.qtgui_freq_sink_x_0_0.set_y_axis(-200, -60) 159 | self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") 160 | self.qtgui_freq_sink_x_0_0.enable_autoscale(False) 161 | self.qtgui_freq_sink_x_0_0.enable_grid(False) 162 | self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) 163 | self.qtgui_freq_sink_x_0_0.enable_control_panel(False) 164 | 165 | if not True: 166 | self.qtgui_freq_sink_x_0_0.disable_legend() 167 | 168 | if complex == type(float()): 169 | self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True) 170 | 171 | labels = ["", "", "", "", "", 172 | "", "", "", "", ""] 173 | widths = [1, 1, 1, 1, 1, 174 | 1, 1, 1, 1, 1] 175 | colors = ["blue", "red", "green", "black", "cyan", 176 | "magenta", "yellow", "dark red", "dark green", "dark blue"] 177 | alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 178 | 1.0, 1.0, 1.0, 1.0, 1.0] 179 | for i in xrange(1): 180 | if len(labels[i]) == 0: 181 | self.qtgui_freq_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) 182 | else: 183 | self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i]) 184 | self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i]) 185 | self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i]) 186 | self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i]) 187 | 188 | self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget) 189 | self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win, 3,0,3,1) 190 | self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 191 | fft_length, #size 192 | firdes.WIN_BLACKMAN_hARRIS, #wintype 193 | 144E6, #fc 194 | samp_rate, #bw 195 | "Spectrum", #name 196 | 1 #number of inputs 197 | ) 198 | self.qtgui_freq_sink_x_0.set_update_time(0.10) 199 | self.qtgui_freq_sink_x_0.set_y_axis(-120, -20) 200 | self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") 201 | self.qtgui_freq_sink_x_0.enable_autoscale(False) 202 | self.qtgui_freq_sink_x_0.enable_grid(False) 203 | self.qtgui_freq_sink_x_0.set_fft_average(1.0) 204 | self.qtgui_freq_sink_x_0.enable_control_panel(False) 205 | 206 | if not True: 207 | self.qtgui_freq_sink_x_0.disable_legend() 208 | 209 | if complex == type(float()): 210 | self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) 211 | 212 | labels = ["", "", "", "", "", 213 | "", "", "", "", ""] 214 | widths = [1, 1, 1, 1, 1, 215 | 1, 1, 1, 1, 1] 216 | colors = ["blue", "red", "green", "black", "cyan", 217 | "magenta", "yellow", "dark red", "dark green", "dark blue"] 218 | alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 219 | 1.0, 1.0, 1.0, 1.0, 1.0] 220 | for i in xrange(1): 221 | if len(labels[i]) == 0: 222 | self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) 223 | else: 224 | self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) 225 | self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) 226 | self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) 227 | self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) 228 | 229 | self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) 230 | self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,3,1) 231 | self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_fff( 232 | 16E3/float(final_rate/5), 233 | taps=None, 234 | flt_size=32) 235 | self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) 236 | 237 | self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "uhd" ) 238 | self.osmosdr_source_0.set_sample_rate(samp_rate) 239 | self.osmosdr_source_0.set_center_freq(center_freq, 0) 240 | self.osmosdr_source_0.set_freq_corr(0, 0) 241 | self.osmosdr_source_0.set_dc_offset_mode(0, 0) 242 | self.osmosdr_source_0.set_iq_balance_mode(0, 0) 243 | self.osmosdr_source_0.set_gain_mode(False, 0) 244 | self.osmosdr_source_0.set_gain(gain_db, 0) 245 | self.osmosdr_source_0.set_if_gain(20, 0) 246 | self.osmosdr_source_0.set_bb_gain(20, 0) 247 | self.osmosdr_source_0.set_antenna("", 0) 248 | self.osmosdr_source_0.set_bandwidth(samp_rate*0.8, 0) 249 | 250 | self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0), demod_bb_freq, samp_rate) 251 | self.fir_filter_xxx_0_1 = filter.fir_filter_fff(initial_decim, (variable_low_pass_filter_taps_0)) 252 | self.fir_filter_xxx_0_1.declare_sample_delay(0) 253 | self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(int(samp_rate/1E6), (variable_low_pass_filter_taps_0)) 254 | self.fir_filter_xxx_0_0.declare_sample_delay(0) 255 | self.fir_filter_xxx_0 = filter.fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0)) 256 | self.fir_filter_xxx_0.declare_sample_delay(0) 257 | self.fft_vxx_0 = fft.fft_vcc(fft_length, True, (window.blackmanharris(fft_length)), True, 1) 258 | self.blocks_wavfile_sink_0 = blocks.wavfile_sink(file_name, 1, 16000, 8) 259 | self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_length) 260 | self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_length) 261 | self.blocks_probe_signal_vx_0 = blocks.probe_signal_vf(fft_length) 262 | self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, fft_length, 0) 263 | self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_gr_complex*fft_length, int(round(samp_rate/fft_length/1000))) 264 | self.blocks_integrate_xx_0 = blocks.integrate_ff(100, fft_length) 265 | self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_length) 266 | self.audio_sink_0 = audio.sink(16000, "", True) 267 | self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(0.050) 268 | self.analog_pwr_squelch_xx_0_0 = analog.pwr_squelch_ff(-200, 0.1, 0, True) 269 | self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(squelch_dB, 0.1, 0, False) 270 | 271 | ################################################## 272 | # Connections 273 | ################################################## 274 | self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_quadrature_demod_cf_0, 0)) 275 | self.connect((self.analog_pwr_squelch_xx_0_0, 0), (self.blocks_wavfile_sink_0, 0)) 276 | self.connect((self.analog_quadrature_demod_cf_0, 0), (self.fir_filter_xxx_0_1, 0)) 277 | self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) 278 | self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0, 0)) 279 | self.connect((self.blocks_keep_one_in_n_0, 0), (self.fft_vxx_0, 0)) 280 | self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_vx_0, 0)) 281 | self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_vector_to_stream_0, 0)) 282 | self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_keep_one_in_n_0, 0)) 283 | self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_time_sink_x_0, 0)) 284 | self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) 285 | self.connect((self.fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0, 0)) 286 | self.connect((self.fir_filter_xxx_0_0, 0), (self.analog_pwr_squelch_xx_0, 0)) 287 | self.connect((self.fir_filter_xxx_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) 288 | self.connect((self.fir_filter_xxx_0_1, 0), (self.pfb_arb_resampler_xxx_0, 0)) 289 | self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0, 0)) 290 | self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0)) 291 | self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) 292 | self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) 293 | self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.analog_pwr_squelch_xx_0_0, 0)) 294 | self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.audio_sink_0, 0)) 295 | 296 | def closeEvent(self, event): 297 | self.settings = Qt.QSettings("GNU Radio", "nbfm_flow_example") 298 | self.settings.setValue("geometry", self.saveGeometry()) 299 | event.accept() 300 | 301 | def get_samp_rate(self): 302 | return self.samp_rate 303 | 304 | def set_samp_rate(self, samp_rate): 305 | self.samp_rate = samp_rate 306 | self.set_final_decim(int(self.samp_rate/1E6)) 307 | self.set_final_rate(self.samp_rate/self.initial_decim**2/int(self.samp_rate/1E6)) 308 | self.set_samp_ratio(self.samp_rate/1E6) 309 | self.blocks_keep_one_in_n_0.set_n(int(round(self.samp_rate/self.fft_length/1000))) 310 | self.osmosdr_source_0.set_sample_rate(self.samp_rate) 311 | self.osmosdr_source_0.set_bandwidth(self.samp_rate*0.8, 0) 312 | self.qtgui_freq_sink_x_0.set_frequency_range(144E6, self.samp_rate) 313 | self.qtgui_time_sink_x_0.set_samp_rate(self.samp_rate) 314 | 315 | def get_initial_decim(self): 316 | return self.initial_decim 317 | 318 | def set_initial_decim(self, initial_decim): 319 | self.initial_decim = initial_decim 320 | self.set_final_rate(self.samp_rate/self.initial_decim**2/int(self.samp_rate/1E6)) 321 | 322 | def get_samp_ratio(self): 323 | return self.samp_ratio 324 | 325 | def set_samp_ratio(self, samp_ratio): 326 | self.samp_ratio = samp_ratio 327 | self.set_fft_length(256 * int(pow(2, np.ceil(np.log(self.samp_ratio)/np.log(2))))) 328 | 329 | def get_final_rate(self): 330 | return self.final_rate 331 | 332 | def set_final_rate(self, final_rate): 333 | self.final_rate = final_rate 334 | self.pfb_arb_resampler_xxx_0.set_rate(16E3/float(self.final_rate/5)) 335 | self.qtgui_freq_sink_x_0_0.set_frequency_range(0, self.final_rate) 336 | 337 | def get_variable_low_pass_filter_taps_2(self): 338 | return self.variable_low_pass_filter_taps_2 339 | 340 | def set_variable_low_pass_filter_taps_2(self, variable_low_pass_filter_taps_2): 341 | self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 342 | 343 | def get_variable_low_pass_filter_taps_1(self): 344 | return self.variable_low_pass_filter_taps_1 345 | 346 | def set_variable_low_pass_filter_taps_1(self, variable_low_pass_filter_taps_1): 347 | self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 348 | 349 | def get_variable_low_pass_filter_taps_0(self): 350 | return self.variable_low_pass_filter_taps_0 351 | 352 | def set_variable_low_pass_filter_taps_0(self, variable_low_pass_filter_taps_0): 353 | self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 354 | self.fir_filter_xxx_0.set_taps((self.variable_low_pass_filter_taps_0)) 355 | self.fir_filter_xxx_0_0.set_taps((self.variable_low_pass_filter_taps_0)) 356 | self.fir_filter_xxx_0_1.set_taps((self.variable_low_pass_filter_taps_0)) 357 | self.freq_xlating_fir_filter_xxx_0.set_taps((self.variable_low_pass_filter_taps_0)) 358 | 359 | def get_squelch_dB(self): 360 | return self.squelch_dB 361 | 362 | def set_squelch_dB(self, squelch_dB): 363 | self.squelch_dB = squelch_dB 364 | self.analog_pwr_squelch_xx_0.set_threshold(self.squelch_dB) 365 | 366 | def get_gain_db(self): 367 | return self.gain_db 368 | 369 | def set_gain_db(self, gain_db): 370 | self.gain_db = gain_db 371 | self.osmosdr_source_0.set_gain(self.gain_db, 0) 372 | 373 | def get_final_decim(self): 374 | return self.final_decim 375 | 376 | def set_final_decim(self, final_decim): 377 | self.final_decim = final_decim 378 | 379 | def get_file_name(self): 380 | return self.file_name 381 | 382 | def set_file_name(self, file_name): 383 | self.file_name = file_name 384 | self.blocks_wavfile_sink_0.open(self.file_name) 385 | 386 | def get_fft_length(self): 387 | return self.fft_length 388 | 389 | def set_fft_length(self, fft_length): 390 | self.fft_length = fft_length 391 | self.blocks_keep_one_in_n_0.set_n(int(round(self.samp_rate/self.fft_length/1000))) 392 | 393 | def get_demod_bb_freq(self): 394 | return self.demod_bb_freq 395 | 396 | def set_demod_bb_freq(self, demod_bb_freq): 397 | self.demod_bb_freq = demod_bb_freq 398 | self.freq_xlating_fir_filter_xxx_0.set_center_freq(self.demod_bb_freq) 399 | 400 | def get_center_freq(self): 401 | return self.center_freq 402 | 403 | def set_center_freq(self, center_freq): 404 | self.center_freq = center_freq 405 | self.osmosdr_source_0.set_center_freq(self.center_freq, 0) 406 | 407 | 408 | if __name__ == '__main__': 409 | parser = OptionParser(option_class=eng_option, usage="%prog: [options]") 410 | (options, args) = parser.parse_args() 411 | from distutils.version import StrictVersion 412 | if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"): 413 | Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster')) 414 | qapp = Qt.QApplication(sys.argv) 415 | tb = nbfm_flow_example() 416 | tb.start() 417 | tb.show() 418 | 419 | def quitting(): 420 | tb.stop() 421 | tb.wait() 422 | qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) 423 | qapp.exec_() 424 | tb = None # to clean up Qt widgets 425 | -------------------------------------------------------------------------------- /apps/parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sat Jul 18 15:21:33 2015 5 | 6 | @author: madengr 7 | """ 8 | 9 | from optparse import OptionParser 10 | from gnuradio.eng_option import eng_option 11 | 12 | class CLParser(object): 13 | """Command line parser 14 | 15 | Attributes: 16 | hw_args (string): Argument string to pass to harwdare 17 | num_demod (int): Number of parallel demodulators 18 | center_freq (float): Hardware RF center frequency in Hz 19 | ask_samp_rate (float): Asking sample rate of hardware in sps (1E6 min) 20 | gain_db (int): Hardware RF gain in dB 21 | squelch_db (int): Squelch in dB 22 | volume_dB (int): Volume in dB 23 | threshold_dB (int): Threshold for channel detection in dB 24 | record (bool): Record audio to file if True 25 | play (bool): Play audio through speaker if True 26 | lockout_file_name (string): Name of file with channels to lockout 27 | priority_file_name (string): Name of file with channels to for priority 28 | freq_correction (int): Frequency correction in ppm 29 | audio_bps (int): Audio bit depth in bps 30 | """ 31 | # pylint: disable=too-few-public-methods 32 | # pylint: disable=too-many-instance-attributes 33 | 34 | def __init__(self): 35 | 36 | # Setup the parser for command line arguments 37 | parser = OptionParser(option_class=eng_option) 38 | 39 | parser.add_option("-a", "--args", type="string", dest="hw_args", 40 | default='uhd', 41 | help="Hardware args") 42 | 43 | parser.add_option("-n", "--demod", type="int", dest="num_demod", 44 | default=4, 45 | help="Number of demodulators") 46 | 47 | parser.add_option("-d", "--demodulator", type="int", dest="type_demod", 48 | default=0, 49 | help="Type of demodulator (0=NBFM, 1=AM)") 50 | 51 | parser.add_option("-f", "--freq", type="string", dest="center_freq", 52 | default=146E6, 53 | help="Hardware RF center frequency in Hz") 54 | 55 | parser.add_option("-r", "--rate", type="string", dest="ask_samp_rate", 56 | default=4E6, 57 | help="Hardware ask sample rate in sps (1E6 minimum)") 58 | 59 | parser.add_option("-g", "--gain", type="eng_float", dest="gain_db", 60 | default=0, help="Hardware RF gain in dB") 61 | 62 | parser.add_option("-i", "--if_gain", type="eng_float", dest="if_gain_db", 63 | default=16, help="Hardware IF gain in dB") 64 | 65 | parser.add_option("-o", "--bb_gain", type="eng_float", dest="bb_gain_db", 66 | default=16, help="Hardware BB gain in dB") 67 | 68 | parser.add_option("-s", "--squelch", type="eng_float", 69 | dest="squelch_db", default=-60, 70 | help="Squelch in dB") 71 | 72 | parser.add_option("-v", "--volume", type="eng_float", 73 | dest="volume_db", default=0, 74 | help="Volume in dB") 75 | 76 | parser.add_option("-t", "--threshold", type="eng_float", 77 | dest="threshold_db", default=10, 78 | help="Threshold in dB") 79 | 80 | parser.add_option("-w", "--write", 81 | dest="record", default=False, action="store_true", 82 | help="Record (write) channels to disk") 83 | 84 | parser.add_option("-l", "--lockout", type="string", 85 | dest="lockout_file_name", 86 | default="", 87 | help="File of EOL delimited lockout channels in Hz") 88 | 89 | parser.add_option("-p", "--priority", type="string", 90 | dest="priority_file_name", 91 | default="", 92 | help="File of EOL delimited priority channels in Hz") 93 | 94 | parser.add_option("-c", "--correction", type="int", dest="freq_correction", 95 | default=0, 96 | help="Frequency correction in ppm") 97 | 98 | parser.add_option("-m", "--mute-audio", dest="play", 99 | action="store_false", default=True, 100 | help="Mute audio from speaker (still allows recording)") 101 | 102 | parser.add_option("-b", "--bps", type="int", dest="audio_bps", 103 | default=8, 104 | help="Audio bit depth (bps)") 105 | 106 | options = parser.parse_args()[0] 107 | self.parser_args = parser.parse_args()[1] 108 | 109 | self.hw_args = str(options.hw_args) 110 | self.num_demod = int(options.num_demod) 111 | self.type_demod = int(options.type_demod) 112 | self.center_freq = float(options.center_freq) 113 | self.ask_samp_rate = float(options.ask_samp_rate) 114 | self.gain_db = float(options.gain_db) 115 | self.if_gain_db = float(options.if_gain_db) 116 | self.bb_gain_db = float(options.bb_gain_db) 117 | self.squelch_db = float(options.squelch_db) 118 | self.volume_db = float(options.volume_db) 119 | self.threshold_db = float(options.threshold_db) 120 | self.record = bool(options.record) 121 | self.play = bool(options.play) 122 | self.lockout_file_name = str(options.lockout_file_name) 123 | self.priority_file_name = str(options.priority_file_name) 124 | self.freq_correction = int(options.freq_correction) 125 | self.audio_bps = int(options.audio_bps) 126 | 127 | 128 | def main(): 129 | """Test the parser""" 130 | 131 | parser = CLParser() 132 | 133 | if len(parser.parser_args) != 0: 134 | parser.print_help() #pylint: disable=maybe-no-member 135 | raise SystemExit, 1 136 | 137 | print "hw_args: " + parser.hw_args 138 | print "num_demod: " + str(parser.num_demod) 139 | print "type_demod: " + str(parser.type_demod) 140 | print "center_freq: " + str(parser.center_freq) 141 | print "ask_samp_rate: " + str(parser.ask_samp_rate) 142 | print "gain_db: " + str(parser.gain_db) 143 | print "if_gain_db: " + str(parser.if_gain_db) 144 | print "bb_gain_db: " + str(parser.bb_gain_db) 145 | print "squelch_db: " + str(parser.squelch_db) 146 | print "volume_db: " + str(parser.volume_db) 147 | print "threshold_db: " + str(parser.threshold_db) 148 | print "record: " + str(parser.record) 149 | print "lockout_file_name: " + str(parser.lockout_file_name) 150 | print "priority_file_name: " + str(parser.priority_file_name) 151 | print "freq_correction: " + str(parser.freq_correction) 152 | print "audio_bps: " + str(parser.audio_bps) 153 | 154 | 155 | if __name__ == '__main__': 156 | try: 157 | main() 158 | except KeyboardInterrupt: 159 | pass 160 | 161 | -------------------------------------------------------------------------------- /apps/priority.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madengr/ham2mon/db9834ce923c1919602bf33cb47720daba9bc6ea/apps/priority.txt -------------------------------------------------------------------------------- /apps/receiver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Fri Jul 3 13:38:36 2015 5 | 6 | @author: madengr 7 | """ 8 | 9 | from gnuradio import gr 10 | import osmosdr 11 | from gnuradio import filter as grfilter # Don't redefine Python's filter() 12 | from gnuradio import blocks 13 | from gnuradio import fft 14 | from gnuradio.fft import window 15 | from gnuradio import analog 16 | from gnuradio import audio 17 | import os 18 | import time 19 | import numpy as np 20 | from gnuradio.filter import pfb 21 | 22 | class BaseTuner(gr.hier_block2): 23 | """Some base methods that are the same between the known tuner types. 24 | 25 | See TunerDemodNBFM and TunerDemodAM for better documentation. 26 | """ 27 | 28 | def set_center_freq(self, center_freq, rf_center_freq): 29 | """Sets baseband center frequency and file name 30 | 31 | Sets baseband center frequency of frequency translating FIR filter 32 | Also sets file name of wave file sink 33 | If tuner is tuned to zero Hz then set to file name to /dev/null 34 | Otherwise set file name to tuned RF frequency in MHz 35 | 36 | Args: 37 | center_freq (float): Baseband center frequency in Hz 38 | rf_center_freq (float): RF center in Hz (for file name) 39 | """ 40 | # Since the frequency (hence file name) changed, then close it 41 | self.blocks_wavfile_sink.close() 42 | 43 | # If we never wrote any data to the wavfile sink, delete the file 44 | self._delete_wavfile_if_empty() 45 | 46 | # Set the frequency 47 | self.freq_xlating_fir_filter_ccc.set_center_freq(center_freq) 48 | self.center_freq = center_freq 49 | 50 | # Set the file name 51 | if self.center_freq == 0 or not self.record: 52 | # If tuner at zero Hz, or record false, then file name to /dev/null 53 | file_name = "/dev/null" 54 | else: 55 | # Otherwise use frequency and time stamp for file name 56 | tstamp = "_" + str(int(time.time())) 57 | file_freq = (rf_center_freq + self.center_freq)/1E6 58 | file_freq = np.round(file_freq, 3) 59 | file_name = 'wav/' + '{:.3f}'.format(file_freq) + tstamp + ".wav" 60 | 61 | # Make sure the 'wav' directory exists 62 | try: 63 | os.mkdir('wav') 64 | except OSError: # will need to add something here for Win support 65 | pass # directory already exists 66 | 67 | self.file_name = file_name 68 | self.blocks_wavfile_sink.open(self.file_name) 69 | 70 | def _delete_wavfile_if_empty(self): 71 | """Delete the current wavfile if it's empty.""" 72 | if (not self.record or not self.file_name or 73 | self.file_name == '/dev/null'): 74 | return 75 | 76 | # If we never wrote any data to the wavfile sink, delete 77 | # the (empty) wavfile 78 | if os.stat(self.file_name).st_size in (44, 0): # ugly hack 79 | os.unlink(self.file_name) # delete the file 80 | 81 | def set_squelch(self, squelch_db): 82 | """Sets the threshold for both squelches 83 | 84 | Args: 85 | squelch_db (float): Squelch in dB 86 | """ 87 | self.analog_pwr_squelch_cc.set_threshold(squelch_db) 88 | 89 | def __del__(self): 90 | """Called when the object is destroyed.""" 91 | # Make a best effort attempt to clean up our wavfile if it's empty 92 | try: 93 | self._delete_wavfile_if_empty() 94 | except Exception: 95 | pass # oh well, we're dying anyway 96 | 97 | class TunerDemodNBFM(BaseTuner): 98 | """Tuner, demodulator, and recorder chain for narrow band FM demodulation 99 | 100 | Kept as it's own class so multiple can be instantiated in parallel 101 | Accepts complex baseband samples at 1 Msps minimum 102 | Frequency translating FIR filter tunes from -samp_rate/2 to +samp_rate/2 103 | The following sample rates assume 1 Msps input 104 | First two stages of decimation are 5 each for a total of 25 105 | Thus first two stages brings 1 Msps down to 40 ksps 106 | The third stage decimates by int(samp_rate/1E6) 107 | Thus output rate will vary from 40 ksps to 79.99 ksps 108 | The channel is filtered to 12.5 KHz bandwidth followed by squelch 109 | The squelch is non-blocking since samples will be added with other demods 110 | The quadrature demod is followed by a fourth stage of decimation by 5 111 | This brings the sample rate down to 8 ksps to 15.98 ksps 112 | The audio is low-pass filtered to 3.5 kHz bandwidth 113 | The polyphase resampler resamples by samp_rate/(decims[1] * decims[0]**3) 114 | This results in a constant 8 ksps, irrespective of RF sample rate 115 | This 8 ksps audio stream may be added to other demod streams 116 | The audio is run through an additional blocking squelch at -200 dB 117 | This stops the sample flow so squelched audio is not recorded to file 118 | The wav file sink stores 8-bit samples (default/grainy quality but compact) 119 | Default demodulator center frequency is 0 Hz 120 | This is desired since hardware DC removal reduces sensitivity at 0 Hz 121 | NBFM demod of LO leakage will just be 0 amplitude 122 | 123 | Args: 124 | samp_rate (float): Input baseband sample rate in sps (1E6 minimum) 125 | audio_rate (float): Output audio sample rate in sps (8 kHz minimum) 126 | record (bool): Record audio to file if True 127 | audio_bps (int): Audio bit depth in bps (bits/samples) 128 | 129 | Attributes: 130 | center_freq (float): Baseband center frequency in Hz 131 | record (bool): Record audio to file if True 132 | """ 133 | # pylint: disable=too-many-instance-attributes 134 | 135 | def __init__(self, samp_rate=4E6, audio_rate=8000, record=True, 136 | audio_bps=8): 137 | gr.hier_block2.__init__(self, "TunerDemodNBFM", 138 | gr.io_signature(1, 1, gr.sizeof_gr_complex), 139 | gr.io_signature(1, 1, gr.sizeof_float)) 140 | 141 | # Default values 142 | self.center_freq = 0 143 | squelch_db = -60 144 | self.quad_demod_gain = 0.050 145 | self.file_name = "/dev/null" 146 | self.record = record 147 | 148 | # Decimation values for four stages of decimation 149 | decims = (5, int(samp_rate/1E6)) 150 | 151 | # Low pass filter taps for decimation by 5 152 | low_pass_filter_taps_0 = \ 153 | grfilter.firdes_low_pass(1, 1, 0.090, 0.010, 154 | grfilter.firdes.WIN_HAMMING) 155 | 156 | # Frequency translating FIR filter decimating by 5 157 | self.freq_xlating_fir_filter_ccc = \ 158 | grfilter.freq_xlating_fir_filter_ccc(decims[0], 159 | low_pass_filter_taps_0, 160 | self.center_freq, samp_rate) 161 | 162 | # FIR filter decimating by 5 163 | fir_filter_ccc_0 = grfilter.fir_filter_ccc(decims[0], 164 | low_pass_filter_taps_0) 165 | 166 | # Low pass filter taps for decimation from samp_rate/25 to 40-79.9 ksps 167 | # In other words, decimation by int(samp_rate/1E6) 168 | # 12.5 kHz cutoff for NBFM channel bandwidth 169 | low_pass_filter_taps_1 = grfilter.firdes_low_pass( 170 | 1, samp_rate/decims[0]**2, 12.5E3, 1E3, grfilter.firdes.WIN_HAMMING) 171 | 172 | # FIR filter decimation by int(samp_rate/1E6) 173 | fir_filter_ccc_1 = grfilter.fir_filter_ccc(decims[1], 174 | low_pass_filter_taps_1) 175 | 176 | # Non blocking power squelch 177 | self.analog_pwr_squelch_cc = analog.pwr_squelch_cc(squelch_db, 178 | 1e-1, 0, False) 179 | 180 | # Quadrature demod with gain set for decent audio 181 | # The gain will be later multiplied by the 0 dB normalized volume 182 | self.analog_quadrature_demod_cf = \ 183 | analog.quadrature_demod_cf(self.quad_demod_gain) 184 | 185 | # 3.5 kHz cutoff for audio bandwidth 186 | low_pass_filter_taps_2 = grfilter.firdes_low_pass(1,\ 187 | samp_rate/(decims[1] * decims[0]**2),\ 188 | 3.5E3, 500, grfilter.firdes.WIN_HAMMING) 189 | 190 | # FIR filter decimating by 5 from 40-79.9 ksps to 8-15.98 ksps 191 | fir_filter_fff_0 = grfilter.fir_filter_fff(decims[0], 192 | low_pass_filter_taps_2) 193 | 194 | # Polyphase resampler allows arbitary RF sample rates 195 | # Takes 8-15.98 ksps to a constant 8 ksps for audio 196 | pfb_resamp = audio_rate/float(samp_rate/(decims[1] * decims[0]**3)) 197 | pfb_arb_resampler_fff = pfb.arb_resampler_fff(pfb_resamp, taps=None, 198 | flt_size=32) 199 | 200 | # Connect the blocks for the demod 201 | self.connect(self, self.freq_xlating_fir_filter_ccc) 202 | self.connect(self.freq_xlating_fir_filter_ccc, fir_filter_ccc_0) 203 | self.connect(fir_filter_ccc_0, fir_filter_ccc_1) 204 | self.connect(fir_filter_ccc_1, self.analog_pwr_squelch_cc) 205 | self.connect(self.analog_pwr_squelch_cc, 206 | self.analog_quadrature_demod_cf) 207 | self.connect(self.analog_quadrature_demod_cf, fir_filter_fff_0) 208 | self.connect(fir_filter_fff_0, pfb_arb_resampler_fff) 209 | self.connect(pfb_arb_resampler_fff, self) 210 | 211 | # Need to set this to a very low value of -200 since it is after demod 212 | # Only want it to gate when the previous squelch has gone to zero 213 | analog_pwr_squelch_ff = analog.pwr_squelch_ff(-200, 1e-1, 0, True) 214 | 215 | # File sink with single channel and bits/sample 216 | self.blocks_wavfile_sink = blocks.wavfile_sink(self.file_name, 1, 217 | audio_rate, audio_bps) 218 | 219 | # Connect the blocks for recording 220 | self.connect(pfb_arb_resampler_fff, analog_pwr_squelch_ff) 221 | self.connect(analog_pwr_squelch_ff, self.blocks_wavfile_sink) 222 | 223 | def set_volume(self, volume_db): 224 | """Sets the volume 225 | 226 | Args: 227 | volume_db (float): Volume in dB 228 | """ 229 | gain = self.quad_demod_gain * 10**(volume_db/20.0) 230 | self.analog_quadrature_demod_cf.set_gain(gain) 231 | 232 | class TunerDemodAM(BaseTuner): 233 | """Tuner, demodulator, and recorder chain for AM demodulation 234 | 235 | Kept as it's own class so multiple can be instantiated in parallel 236 | Accepts complex baseband samples at 1 Msps minimum 237 | Frequency translating FIR filter tunes from -samp_rate/2 to +samp_rate/2 238 | The following sample rates assume 1 Msps input 239 | First two stages of decimation are 5 each for a total of 25 240 | Thus first two stages brings 1 Msps down to 40 ksps 241 | The third stage decimates by int(samp_rate/1E6) 242 | Thus output rate will vary from 40 ksps to 79.99 ksps 243 | The channel is filtered to 12.5 KHz bandwidth followed by squelch 244 | The squelch is non-blocking since samples will be added with other demods 245 | The AGC sets level (volume) prior to AM demod 246 | The AM demod is followed by a fourth stage of decimation by 5 247 | This brings the sample rate down to 8 ksps to 15.98 ksps 248 | The audio is low-pass filtered to 3.5 kHz bandwidth 249 | The polyphase resampler resamples by samp_rate/(decims[1] * decims[0]**3) 250 | This results in a constant 8 ksps, irrespective of RF sample rate 251 | This 8 ksps audio stream may be added to other demod streams 252 | The audio is run through an additional blocking squelch at -200 dB 253 | This stops the sample flow so squelced audio is not recorded to file 254 | The wav file sink stores 8-bit samples (default/grainy quality but compact) 255 | Default demodulator center frequency is 0 Hz 256 | This is desired since hardware DC removal reduces sensitivity at 0 Hz 257 | AM demod of LO leakage will just be 0 amplitude 258 | 259 | Args: 260 | samp_rate (float): Input baseband sample rate in sps (1E6 minimum) 261 | audio_rate (float): Output audio sample rate in sps (8 kHz minimum) 262 | record (bool): Record audio to file if True 263 | audio_bps (int): Audio bit depth in bps (bits/samples) 264 | 265 | Attributes: 266 | center_freq (float): Baseband center frequency in Hz 267 | record (bool): Record audio to file if True 268 | """ 269 | # pylint: disable=too-many-instance-attributes 270 | # pylint: disable=too-many-locals 271 | 272 | def __init__(self, samp_rate=4E6, audio_rate=8000, record=True, 273 | audio_bps=8): 274 | gr.hier_block2.__init__(self, "TunerDemodAM", 275 | gr.io_signature(1, 1, gr.sizeof_gr_complex), 276 | gr.io_signature(1, 1, gr.sizeof_float)) 277 | 278 | # Default values 279 | self.center_freq = 0 280 | squelch_db = -60 281 | self.agc_ref = 0.1 282 | self.file_name = "/dev/null" 283 | self.record = record 284 | 285 | # Decimation values for four stages of decimation 286 | decims = (5, int(samp_rate/1E6)) 287 | 288 | # Low pass filter taps for decimation by 5 289 | low_pass_filter_taps_0 = \ 290 | grfilter.firdes_low_pass(1, 1, 0.090, 0.010, 291 | grfilter.firdes.WIN_HAMMING) 292 | 293 | # Frequency translating FIR filter decimating by 5 294 | self.freq_xlating_fir_filter_ccc = \ 295 | grfilter.freq_xlating_fir_filter_ccc(decims[0], 296 | low_pass_filter_taps_0, 297 | self.center_freq, samp_rate) 298 | 299 | # FIR filter decimating by 5 300 | fir_filter_ccc_0 = grfilter.fir_filter_ccc(decims[0], 301 | low_pass_filter_taps_0) 302 | 303 | # Low pass filter taps for decimation from samp_rate/25 to 40-79.9 ksps 304 | # In other words, decimation by int(samp_rate/1E6) 305 | # 12.5 kHz cutoff for NBFM channel bandwidth 306 | low_pass_filter_taps_1 = grfilter.firdes_low_pass( 307 | 1, samp_rate/decims[0]**2, 12.5E3, 1E3, grfilter.firdes.WIN_HAMMING) 308 | 309 | # FIR filter decimation by int(samp_rate/1E6) 310 | fir_filter_ccc_1 = grfilter.fir_filter_ccc(decims[1], 311 | low_pass_filter_taps_1) 312 | 313 | # Non blocking power squelch 314 | # Squelch level needs to be lower than NBFM or else choppy AM demod 315 | self.analog_pwr_squelch_cc = analog.pwr_squelch_cc(squelch_db, 316 | 1e-1, 0, False) 317 | 318 | # AGC with reference set for nomninal 0 dB volume 319 | # Paramaters tweaked to prevent impulse during squelching 320 | self.agc3_cc = analog.agc3_cc(1.0, 1E-4, self.agc_ref, 10, 1) 321 | self.agc3_cc.set_max_gain(65536) 322 | 323 | # AM demod with complex_to_mag() 324 | # Can't use analog.am_demod_cf() since it won't work with N>2 demods 325 | am_demod_cf = blocks.complex_to_mag(1) 326 | 327 | # 3.5 kHz cutoff for audio bandwidth 328 | low_pass_filter_taps_2 = grfilter.firdes_low_pass(1,\ 329 | samp_rate/(decims[1] * decims[0]**2),\ 330 | 3.5E3, 500, grfilter.firdes.WIN_HAMMING) 331 | 332 | # FIR filter decimating by 5 from 40-79.9 ksps to 8-15.98 ksps 333 | fir_filter_fff_0 = grfilter.fir_filter_fff(decims[0], 334 | low_pass_filter_taps_2) 335 | 336 | # Polyphase resampler allows arbitary RF sample rates 337 | # Takes 8-15.98 ksps to a constant 8 ksps for audio 338 | pfb_resamp = audio_rate/float(samp_rate/(decims[1] * decims[0]**3)) 339 | pfb_arb_resampler_fff = pfb.arb_resampler_fff(pfb_resamp, taps=None, 340 | flt_size=32) 341 | 342 | # Connect the blocks for the demod 343 | self.connect(self, self.freq_xlating_fir_filter_ccc) 344 | self.connect(self.freq_xlating_fir_filter_ccc, fir_filter_ccc_0) 345 | self.connect(fir_filter_ccc_0, fir_filter_ccc_1) 346 | self.connect(fir_filter_ccc_1, self.analog_pwr_squelch_cc) 347 | self.connect(self.analog_pwr_squelch_cc, self.agc3_cc) 348 | self.connect(self.agc3_cc, am_demod_cf) 349 | self.connect(am_demod_cf, fir_filter_fff_0) 350 | self.connect(fir_filter_fff_0, pfb_arb_resampler_fff) 351 | self.connect(pfb_arb_resampler_fff, self) 352 | 353 | # Need to set this to a very low value of -200 since it is after demod 354 | # Only want it to gate when the previous squelch has gone to zero 355 | analog_pwr_squelch_ff = analog.pwr_squelch_ff(-200, 1e-1, 0, True) 356 | 357 | # File sink with single channel and 8 bits/sample 358 | self.blocks_wavfile_sink = blocks.wavfile_sink(self.file_name, 1, 359 | audio_rate, audio_bps) 360 | 361 | # Connect the blocks for recording 362 | self.connect(pfb_arb_resampler_fff, analog_pwr_squelch_ff) 363 | self.connect(analog_pwr_squelch_ff, self.blocks_wavfile_sink) 364 | 365 | def set_volume(self, volume_db): 366 | """Sets the volume 367 | 368 | Args: 369 | volume_db (float): Volume in dB 370 | """ 371 | agc_ref = self.agc_ref * 10**(volume_db/20.0) 372 | self.agc3_cc.set_reference(agc_ref) 373 | 374 | class Receiver(gr.top_block): 375 | """Receiver for NBFM and AM modulation 376 | 377 | Controls hardware and instantiates multiple tuner/demodulators 378 | Generates FFT power spectrum for channel estimation 379 | 380 | Args: 381 | ask_samp_rate (float): Asking sample rate of hardware in sps (1E6 min) 382 | num_demod (int): Number of parallel demodulators 383 | type_demod (int): Type of demodulator (0=NBFM, 1=AM) 384 | hw_args (string): Argument string to pass to hardware 385 | freq_correction (int): Frequency correction in ppm 386 | record (bool): Record audio to file if True 387 | audio_bps (int): Audio bit depth in bps (bits/samples) 388 | 389 | Attributes: 390 | center_freq (float): Hardware RF center frequency in Hz 391 | samp_rate (float): Hardware sample rate in sps (1E6 min) 392 | gain_db (int): Hardware RF gain in dB 393 | squelch_db (int): Squelch in dB 394 | volume_dB (int): Volume in dB 395 | """ 396 | # pylint: disable=too-many-instance-attributes 397 | # pylint: disable=too-many-locals 398 | # pylint: disable=too-many-arguments 399 | 400 | def __init__(self, ask_samp_rate=4E6, num_demod=4, type_demod=0, 401 | hw_args="uhd", freq_correction=0, record=True, play=True, 402 | audio_bps=8): 403 | 404 | # Call the initialization method from the parent class 405 | gr.top_block.__init__(self, "Receiver") 406 | 407 | # Default values 408 | self.center_freq = 144E6 409 | self.gain_db = 0 410 | self.if_gain_db = 16 411 | self.bb_gain_db = 16 412 | self.squelch_db = -60 413 | self.volume_db = 0 414 | audio_rate = 8000 415 | 416 | # Setup the USRP source, or use the USRP sim 417 | self.src = osmosdr.source(args="numchan=" + str(1) + " " + hw_args) 418 | self.src.set_sample_rate(ask_samp_rate) 419 | self.src.set_gain(self.gain_db) 420 | self.src.set_if_gain(self.if_gain_db) 421 | self.src.set_bb_gain(self.bb_gain_db) 422 | self.src.set_center_freq(self.center_freq) 423 | self.src.set_freq_corr(freq_correction) 424 | 425 | # Get the sample rate and center frequency from the hardware 426 | self.samp_rate = self.src.get_sample_rate() 427 | self.center_freq = self.src.get_center_freq() 428 | 429 | # Set the I/Q bandwidth to 80 % of sample rate 430 | self.src.set_bandwidth(0.8 * self.samp_rate) 431 | 432 | # NBFM channel is about 10 KHz wide 433 | # Want about 3 FFT bins to span a channel 434 | # Use length FFT so 4 Msps / 1024 = 3906.25 Hz/bin 435 | # This also means 3906.25 vectors/second 436 | # Using below formula keeps FFT size a power of two 437 | # Also keeps bin size constant for power of two sampling rates 438 | # Use of 256 sets 3906.25 Hz/bin; increase to reduce bin size 439 | samp_ratio = self.samp_rate / 1E6 440 | fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2)))) 441 | 442 | # -----------Flow for FFT-------------- 443 | 444 | # Convert USRP steam to vector 445 | stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 446 | fft_length) 447 | 448 | # Want about 1000 vector/sec 449 | amount = int(round(self.samp_rate/fft_length/1000)) 450 | keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex* 451 | fft_length, amount) 452 | 453 | # Take FFT 454 | fft_vcc = fft.fft_vcc(fft_length, True, 455 | window.blackmanharris(fft_length), True, 1) 456 | 457 | # Compute the power 458 | complex_to_mag_squared = blocks.complex_to_mag_squared(fft_length) 459 | 460 | # Video average and decimate from 1000 vector/sec to 10 vector/sec 461 | integrate_ff = blocks.integrate_ff(100, fft_length) 462 | 463 | # Probe vector 464 | self.probe_signal_vf = blocks.probe_signal_vf(fft_length) 465 | 466 | # Connect the blocks 467 | self.connect(self.src, stream_to_vector, keep_one_in_n, 468 | fft_vcc, complex_to_mag_squared, 469 | integrate_ff, self.probe_signal_vf) 470 | 471 | # -----------Flow for Demod-------------- 472 | 473 | # Create N parallel demodulators as a list of objects 474 | # Default to NBFM demod 475 | self.demodulators = [] 476 | for idx in range(num_demod): 477 | if type_demod == 1: 478 | self.demodulators.append(TunerDemodAM(self.samp_rate, 479 | audio_rate, record, 480 | audio_bps)) 481 | else: 482 | self.demodulators.append(TunerDemodNBFM(self.samp_rate, 483 | audio_rate, record, 484 | audio_bps)) 485 | 486 | if play: 487 | # Create an adder 488 | add_ff = blocks.add_ff(1) 489 | 490 | # Connect the demodulators between the source and adder 491 | for idx, demodulator in enumerate(self.demodulators): 492 | self.connect(self.src, demodulator, (add_ff, idx)) 493 | 494 | # Audio sink 495 | audio_sink = audio.sink(audio_rate) 496 | 497 | # Connect the summed outputs to the audio sink 498 | self.connect(add_ff, audio_sink) 499 | else: 500 | # Just connect each demodulator to the receiver source 501 | for demodulator in self.demodulators: 502 | self.connect(self.src, demodulator) 503 | 504 | def set_center_freq(self, center_freq): 505 | """Sets RF center frequency of hardware 506 | 507 | Args: 508 | center_freq (float): Hardware RF center frequency in Hz 509 | """ 510 | # Tune the hardware 511 | self.src.set_center_freq(center_freq) 512 | 513 | # Update center frequency with hardware center frequency 514 | # Do this to account for slight hardware offsets 515 | self.center_freq = self.src.get_center_freq() 516 | 517 | def set_gain(self, gain_db): 518 | """Sets gain of RF hardware 519 | 520 | Args: 521 | gain_db (float): Hardware RF gain in dB 522 | """ 523 | self.src.set_gain(gain_db) 524 | self.gain_db = self.src.get_gain() 525 | 526 | def set_if_gain(self, if_gain_db): 527 | """Sets IF gain of RF hardware 528 | 529 | Args: 530 | if_gain_db (float): Hardware IF gain in dB 531 | """ 532 | self.src.set_if_gain(if_gain_db) 533 | self.if_gain_db = if_gain_db 534 | 535 | def set_bb_gain(self, bb_gain_db): 536 | """Sets BB gain of RF hardware 537 | 538 | Args: 539 | bb_gain_db (float): Hardware BB gain in dB 540 | """ 541 | self.src.set_bb_gain(bb_gain_db) 542 | self.bb_gain_db = bb_gain_db 543 | 544 | def set_squelch(self, squelch_db): 545 | """Sets squelch of all demodulators and clamps range 546 | 547 | Args: 548 | squelch_db (float): Squelch in dB 549 | """ 550 | self.squelch_db = max(min(0, squelch_db), -100) 551 | for demodulator in self.demodulators: 552 | demodulator.set_squelch(self.squelch_db) 553 | 554 | def set_volume(self, volume_db): 555 | """Sets volume of all demodulators and clamps range 556 | 557 | Args: 558 | volume_db (float): Volume in dB 559 | """ 560 | self.volume_db = max(min(20, volume_db), -20) 561 | for demodulator in self.demodulators: 562 | demodulator.set_volume(self.volume_db) 563 | 564 | def get_demod_freqs(self): 565 | """Gets baseband frequencies of all demodulators 566 | 567 | Returns: 568 | List[float]: List of baseband center frequencies in Hz 569 | """ 570 | center_freqs = [] 571 | for demodulator in self.demodulators: 572 | center_freqs.append(demodulator.center_freq) 573 | return center_freqs 574 | 575 | 576 | def main(): 577 | """Test the receiver 578 | 579 | Sets up the hadrware 580 | Tunes a couple of demodulators 581 | Prints the max power spectrum 582 | """ 583 | 584 | # Create receiver object 585 | ask_samp_rate = 4E6 586 | num_demod = 4 587 | type_demod = 0 588 | hw_args = "uhd" 589 | freq_correction = 0 590 | record = False 591 | play = True 592 | audio_bps = 8 593 | receiver = Receiver(ask_samp_rate, num_demod, type_demod, hw_args, 594 | freq_correction, record, play, audio_bps) 595 | 596 | # Start the receiver and wait for samples to accumulate 597 | receiver.start() 598 | time.sleep(1) 599 | 600 | # Set frequency, gain, squelch, and volume 601 | center_freq = 144.5E6 602 | receiver.set_center_freq(center_freq) 603 | receiver.set_gain(10) 604 | print "\n" 605 | print "Started %s at %.3f Msps" % (hw_args, receiver.samp_rate/1E6) 606 | print "RX at %.3f MHz with %d dB gain" % (receiver.center_freq/1E6, 607 | receiver.gain_db) 608 | receiver.set_squelch(-60) 609 | receiver.set_volume(0) 610 | print "%d demods of type %d at %d dB squelch and %d dB volume" % \ 611 | (num_demod, type_demod, receiver.squelch_db, receiver.volume_db) 612 | 613 | # Create some baseband channels to tune based on 144 MHz center 614 | channels = np.zeros(num_demod) 615 | channels[0] = 144.39E6 - receiver.center_freq # APRS 616 | channels[1] = 144.6E6 - receiver.center_freq 617 | 618 | # Tune demodulators to baseband channels 619 | # If recording on, this creates empty wav file since manually tuning. 620 | for idx, demodulator in enumerate(receiver.demodulators): 621 | demodulator.set_center_freq(channels[idx], center_freq) 622 | 623 | # Print demodulator info 624 | for idx, channel in enumerate(channels): 625 | print "Tuned demod %d to %.3f MHz" % (idx, 626 | (channel+receiver.center_freq) 627 | /1E6) 628 | 629 | while 1: 630 | # No need to go faster than 10 Hz rate of GNU Radio probe 631 | # Just do 1 Hz here 632 | time.sleep(1) 633 | 634 | # Grab the FFT data and print max value 635 | spectrum = receiver.probe_signal_vf.level() 636 | print "Max spectrum of %.3f" % (np.max(spectrum)) 637 | 638 | # Stop the receiver 639 | receiver.stop() 640 | receiver.wait() 641 | 642 | 643 | if __name__ == '__main__': 644 | try: 645 | main() 646 | except KeyboardInterrupt: 647 | pass 648 | -------------------------------------------------------------------------------- /apps/scanner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Fri Jul 3 13:38:36 2015 5 | 6 | @author: madengr 7 | """ 8 | import __builtin__ 9 | import receiver as recvr 10 | import estimate 11 | import parser as prsr 12 | import time 13 | import numpy as np 14 | import sys 15 | 16 | class Scanner(object): 17 | """Scanner that controls receiver 18 | 19 | Estimates channels from FFT power spectrum that are above threshold 20 | Rounds channels to nearest 5 kHz 21 | Removes channels that are locked out 22 | Tunes demodulators to new channels 23 | Holds demodulators on channels between scan cycles 24 | 25 | Args: 26 | ask_samp_rate (float): Asking sample rate of hardware in sps (1E6 min) 27 | num_demod (int): Number of parallel demodulators 28 | type_demod (int): Type of demodulator (0=NBFM, 1=AM) 29 | hw_args (string): Argument string to pass to harwdare 30 | freq_correction (int): Frequency correction in ppm 31 | record (bool): Record audio to file if True 32 | audio_bps (int): Audio bit depth in bps (bits/samples) 33 | 34 | Attributes: 35 | center_freq (float): Hardware RF center frequency in Hz 36 | samp_rate (float): Hardware sample rate in sps (1E6 min) 37 | gain_db (int): Hardware RF gain in dB 38 | squelch_db (int): Squelch in dB 39 | volume_dB (int): Volume in dB 40 | threshold_dB (int): Threshold for channel detection in dB 41 | spectrum (numpy.ndarray): FFT power spectrum data in linear, not dB 42 | lockout_channels [float]: List of baseband lockout channels in Hz 43 | priority_channels [float]: List of baseband priority channels in Hz 44 | gui_tuned_channels [str] List of tuned RF channels in MHz for GUI 45 | gui_tuned_lockout_channels [str]: List of lockout channels in MHz GUI 46 | channel_spacing (float): Spacing that channels will be rounded 47 | lockout_file_name (string): Name of file with channels to lockout 48 | priority_file_name (string): Name of file with channels for priority 49 | """ 50 | # pylint: disable=too-many-instance-attributes 51 | # pylint: disable=too-many-arguments 52 | 53 | def __init__(self, ask_samp_rate=4E6, num_demod=4, type_demod=0, 54 | hw_args="uhd", freq_correction=0, record=True, 55 | lockout_file_name="", priority_file_name="", play=True, 56 | audio_bps=8): 57 | 58 | # Default values 59 | self.gain_db = 0 60 | self.if_gain_db = 16 61 | self.bb_gain_db = 16 62 | self.squelch_db = -60 63 | self.volume_db = 0 64 | self.threshold_db = 10 65 | self.record = record 66 | self.play = play 67 | self.spectrum = [] 68 | self.lockout_channels = [] 69 | self.priority_channels = [] 70 | self.gui_tuned_channels = [] 71 | self.gui_lockout_channels = [] 72 | self.channel_spacing = 5000 73 | self.lockout_file_name = lockout_file_name 74 | self.priority_file_name = priority_file_name 75 | 76 | # Create receiver object 77 | self.receiver = recvr.Receiver(ask_samp_rate, num_demod, type_demod, 78 | hw_args, freq_correction, record, play, 79 | audio_bps) 80 | 81 | # Get the hardware sample rate and center frequency 82 | self.samp_rate = self.receiver.samp_rate 83 | self.center_freq = self.receiver.center_freq 84 | 85 | # Start the receiver and wait for samples to accumulate 86 | self.receiver.start() 87 | time.sleep(1) 88 | 89 | def scan_cycle(self): 90 | """Execute one scan cycle 91 | 92 | Should be called no more than 10 Hz rate 93 | Estimates channels from FFT power spectrum that are above threshold 94 | Rounds channels to nearest 5 kHz 95 | Removes channels that are already a priority 96 | Moves priority channels in front 97 | Removes channels that are locked out 98 | Tunes demodulators to new channels 99 | Holds demodulators on channels between scan cycles 100 | Creates RF channel lists for GUI 101 | """ 102 | # pylint: disable=too-many-branches 103 | 104 | # Retune demodulators that are locked out 105 | for demodulator in self.receiver.demodulators: 106 | if demodulator.center_freq in self.lockout_channels: 107 | demodulator.set_center_freq(0, self.center_freq) 108 | else: 109 | pass 110 | 111 | # Grab the FFT data, set threshold, and estimate baseband channels 112 | self.spectrum = self.receiver.probe_signal_vf.level() 113 | threshold = 10**(self.threshold_db/10.0) 114 | channels = np.array(estimate.channel_estimate(self.spectrum, 115 | threshold)) 116 | 117 | # Convert channels from bin indices to baseband frequency in Hz 118 | channels = (channels-len(self.spectrum)/2)*\ 119 | self.samp_rate/len(self.spectrum) 120 | 121 | # Round channels to channel spacing 122 | # Note this affects tuning the demodulators 123 | # 5000 Hz is adequate for NBFM 124 | channels = np.round(channels / self.channel_spacing) * self.channel_spacing 125 | 126 | # Remove channels that are already in the priority list 127 | temp = [] 128 | for channel in channels: 129 | if channel not in self.priority_channels: 130 | temp = np.append(temp, channel) 131 | else: 132 | pass 133 | channels = temp 134 | 135 | # Put the priority channels in front 136 | channels = np.append(self.priority_channels, channels) 137 | 138 | # Remove channels that are locked out 139 | temp = [] 140 | for channel in channels: 141 | if channel not in self.lockout_channels: 142 | temp = np.append(temp, channel) 143 | else: 144 | pass 145 | channels = temp 146 | 147 | # Set demodulators that are no longer in channel list to 0 Hz 148 | for demodulator in self.receiver.demodulators: 149 | if demodulator.center_freq not in channels: 150 | demodulator.set_center_freq(0, self.center_freq) 151 | else: 152 | pass 153 | 154 | # Add new channels to demodulators 155 | for channel in channels: 156 | # If channel not in demodulators 157 | if channel not in self.receiver.get_demod_freqs(): 158 | # Sequence through each demodulator 159 | for demodulator in self.receiver.demodulators: 160 | # If demodulator is empty and channel not already there 161 | if (demodulator.center_freq == 0) and \ 162 | (channel not in self.receiver.get_demod_freqs()): 163 | # Assing channel to empty demodulator 164 | demodulator.set_center_freq(channel, self.center_freq) 165 | else: 166 | pass 167 | else: 168 | pass 169 | 170 | # Create an tuned channel list of strings for the GUI 171 | # If channel is a zero then use an empty string 172 | self.gui_tuned_channels = [] 173 | for demod_freq in self.receiver.get_demod_freqs(): 174 | if demod_freq == 0: 175 | text = "" 176 | else: 177 | # Calculate actual RF frequency 178 | gui_tuned_channel = (demod_freq + \ 179 | self.center_freq)/1E6 180 | text = '{:.3f}'.format(gui_tuned_channel) 181 | self.gui_tuned_channels.append(text) 182 | 183 | def add_lockout(self, idx): 184 | """Adds baseband frequency to lockout channels and updates GUI list 185 | 186 | Args: 187 | idx (int): Index of tuned channel 188 | """ 189 | # Check to make sure index is within the number of demodulators 190 | if idx < len(self.receiver.demodulators): 191 | # Lockout if not zero and not already locked out 192 | demod_freq = self.receiver.demodulators[idx].center_freq 193 | if (demod_freq != 0) and (demod_freq not in self.lockout_channels): 194 | self.lockout_channels = np.append(self.lockout_channels, 195 | demod_freq) 196 | 197 | # Create a lockout channel list of strings for the GUI 198 | self.gui_lockout_channels = [] 199 | for lockout_channel in self.lockout_channels: 200 | gui_lockout_channel = (lockout_channel + \ 201 | self.receiver.center_freq)/1E6 202 | text = '{:.3f}'.format(gui_lockout_channel) 203 | self.gui_lockout_channels.append(text) 204 | 205 | def clear_lockout(self): 206 | """Clears lockout channels and updates GUI list 207 | """ 208 | # Clear the lockout channels 209 | self.lockout_channels = [] 210 | 211 | # Process lockout file if it was provided 212 | if self.lockout_file_name != "": 213 | # Open file, split to list, remove empty strings 214 | with open(self.lockout_file_name) as lockout_file: 215 | lines = lockout_file.read().splitlines() 216 | lockout_file.close() 217 | lines = __builtin__.filter(None, lines) 218 | # Convert to baseband frequencies, round, and append 219 | for freq in lines: 220 | bb_freq = float(freq) - self.center_freq 221 | bb_freq = round(bb_freq/self.channel_spacing)*\ 222 | self.channel_spacing 223 | self.lockout_channels.append(bb_freq) 224 | else: 225 | pass 226 | 227 | # Create a lockout channel list of strings for the GUI 228 | self.gui_lockout_channels = [] 229 | for lockout_channel in self.lockout_channels: 230 | gui_lockout_channel = (lockout_channel + \ 231 | self.receiver.center_freq)/1E6 232 | text = '{:.3f}'.format(gui_lockout_channel) 233 | self.gui_lockout_channels.append(text) 234 | 235 | def update_priority(self): 236 | """Updates priority channels 237 | """ 238 | # Clear the priority channels 239 | self.priority_channels = [] 240 | 241 | # Process priority file if it was provided 242 | if self.priority_file_name != "": 243 | # Open file, split to list, remove empty strings 244 | with open(self.priority_file_name) as priority_file: 245 | lines = priority_file.read().splitlines() 246 | priority_file.close() 247 | lines = __builtin__.filter(None, lines) 248 | # Convert to baseband frequencies, round, and append if within BW 249 | for freq in lines: 250 | bb_freq = float(freq) - self.center_freq 251 | bb_freq = round(bb_freq/self.channel_spacing)*\ 252 | self.channel_spacing 253 | if abs(bb_freq) <= self.samp_rate/2.0: 254 | self.priority_channels.append(bb_freq) 255 | else: 256 | pass 257 | else: 258 | pass 259 | 260 | def set_center_freq(self, center_freq): 261 | """Sets RF center frequency of hardware and clears lockout channels 262 | 263 | Args: 264 | center_freq (float): Hardware RF center frequency in Hz 265 | """ 266 | # Tune the receiver then update with actual frequency 267 | self.receiver.set_center_freq(center_freq) 268 | self.center_freq = self.receiver.center_freq 269 | 270 | # Update the priority since frequency is changing 271 | self.update_priority() 272 | 273 | # Clear the lockout since frequency is changing 274 | self.clear_lockout() 275 | 276 | def set_gain(self, gain_db): 277 | """Sets gain of RF hardware 278 | 279 | Args: 280 | gain_db (float): Hardware RF gain in dB 281 | """ 282 | self.receiver.set_gain(gain_db) 283 | self.gain_db = self.receiver.gain_db 284 | 285 | def set_if_gain(self, if_gain_db): 286 | """Sets IF gain of RF hardware 287 | 288 | Args: 289 | if_gain_db (float): Hardware IF gain in dB 290 | """ 291 | self.receiver.set_if_gain(if_gain_db) 292 | self.if_gain_db = self.receiver.if_gain_db 293 | 294 | def set_bb_gain(self, bb_gain_db): 295 | """Sets BB gain of RF hardware 296 | 297 | Args: 298 | bb_gain_db (float): Hardware BB gain in dB 299 | """ 300 | self.receiver.set_bb_gain(bb_gain_db) 301 | self.bb_gain_db = self.receiver.bb_gain_db 302 | 303 | def set_squelch(self, squelch_db): 304 | """Sets squelch of all demodulators 305 | 306 | Args: 307 | squelch_db (float): Squelch in dB 308 | """ 309 | self.receiver.set_squelch(squelch_db) 310 | self.squelch_db = self.receiver.squelch_db 311 | 312 | def set_volume(self, volume_db): 313 | """Sets volume of all demodulators 314 | 315 | Args: 316 | volume_db (float): Volume in dB 317 | """ 318 | self.receiver.set_volume(volume_db) 319 | self.volume_db = self.receiver.volume_db 320 | 321 | def set_threshold(self, threshold_db): 322 | """Sets threshold in dB for channel detection 323 | 324 | Args: 325 | threshold_db (float): Threshold in dB 326 | """ 327 | self.threshold_db = threshold_db 328 | 329 | def stop(self): 330 | """Stop the receiver 331 | """ 332 | self.receiver.stop() 333 | self.receiver.wait() 334 | 335 | 336 | def main(): 337 | """Test the scanner 338 | 339 | Gets options from parser 340 | Sets up the scanner 341 | Assigns a channel to lockout 342 | Executes scan cycles 343 | Prints channels as they change 344 | """ 345 | 346 | # Create parser object 347 | parser = prsr.CLParser() 348 | 349 | if len(parser.parser_args) != 0: 350 | parser.print_help() #pylint: disable=maybe-no-member 351 | raise SystemExit, 1 352 | 353 | # Create scanner object 354 | ask_samp_rate = parser.ask_samp_rate 355 | num_demod = parser.num_demod 356 | type_demod = parser.type_demod 357 | hw_args = parser.hw_args 358 | freq_correction = parser.freq_correction 359 | record = parser.record 360 | lockout_file_name = parser.lockout_file_name 361 | priority_file_name = parser.priority_file_name 362 | audio_bps = parser.audio_bps 363 | scanner = Scanner(ask_samp_rate, num_demod, type_demod, hw_args, 364 | freq_correction, record, lockout_file_name, 365 | priority_file_name, audio_bps) 366 | 367 | # Set frequency, gain, squelch, and volume 368 | scanner.set_center_freq(parser.center_freq) 369 | scanner.set_gain(parser.gain_db) 370 | scanner.set_if_gain(parser.if_gain_db) 371 | scanner.set_bb_gain(parser.bb_gain_db) 372 | print "\n" 373 | print "Started %s at %.3f Msps" % (hw_args, scanner.samp_rate/1E6) 374 | print "RX at %.3f MHz with %d dB gain" % (scanner.center_freq/1E6, 375 | scanner.gain_db) 376 | scanner.set_squelch(parser.squelch_db) 377 | scanner.set_volume(parser.volume_db) 378 | print "%d demods of type %d at %d dB squelch and %d dB volume" % \ 379 | (num_demod, type_demod, scanner.squelch_db, scanner.volume_db) 380 | 381 | # Create this epmty list to allow printing to screen 382 | old_gui_tuned_channels = [] 383 | 384 | while 1: 385 | # No need to go faster than 10 Hz rate of GNU Radio probe 386 | time.sleep(0.1) 387 | 388 | # Execute a scan cycle 389 | scanner.scan_cycle() 390 | 391 | # Print the GUI tuned channels if they have changed 392 | if scanner.gui_tuned_channels != old_gui_tuned_channels: 393 | sys.stdout.write("Tuners at: ") 394 | for text in scanner.gui_tuned_channels: 395 | sys.stdout.write(text + " ") 396 | sys.stdout.write("\n") 397 | else: 398 | pass 399 | old_gui_tuned_channels = scanner.gui_tuned_channels 400 | 401 | 402 | if __name__ == '__main__': 403 | try: 404 | main() 405 | except KeyboardInterrupt: 406 | pass 407 | -------------------------------------------------------------------------------- /apps/wav/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /flow_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madengr/ham2mon/db9834ce923c1919602bf33cb47720daba9bc6ea/flow_example.png -------------------------------------------------------------------------------- /ham2mon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madengr/ham2mon/db9834ce923c1919602bf33cb47720daba9bc6ea/ham2mon.png --------------------------------------------------------------------------------