├── .gitignore ├── COPYING ├── ChangeLog ├── Makefile ├── Makefile.osx ├── README ├── fano.c ├── fano.h ├── mettab.c ├── nhash.c ├── tab.c ├── wsprd.c ├── wsprd_utils.c └── wsprd_utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 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 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 5-8-2015 Joe Taylor, K1JT and Steve Franke, K9AN 2 | 3 | Merged in Joe Taylor's modifications which yield a huge speed improvement 4 | and also increase # of decodes by 2-3%. Speed improvement ranges from a 5 | factor of 4 to a factor of 8 depending on noise type, with the larger 6 | improvements associated with files that contain significant lightning events. 7 | 8 | 3-7-2015 Steve K9AN 9 | 10 | Fixed a problem that affected extended callsigns with a 2-character suffix. 11 | 12 | 2-20-2015 Steve K9AN 13 | 14 | Fixed a bug that caused slight frequency error (less than 0.5 Hz). Thanks 15 | to Glenn, N6GN for pointing me toward this issue. 16 | 17 | Also added one more digit of precision to frequency reports in ALL_WSPR.TXT. 18 | This will be used to study the variability of frequency estimates. 19 | 20 | 2-16-2015 Steve K9AN 21 | 22 | Applied grid6 patch contributed by John, KD6EKQ. This fixes a bug that 23 | caused the displayed 6-digit locator to be corrupted when there were two 24 | or more type 3 messages decoded. 25 | 26 | 2-15-2015 Steve K9AN 27 | 28 | Applied patch file contributed by John, KD6EKQ. This adds the following: 29 | 30 | * Added the ability to read and incorporate fftw wisdom to speed up the 31 | DFT transforms when using PCM WAV input files. The code checks for the 32 | "WSPRD_FFTW_WISDOM" environment variable. If set, it specifies the 33 | file with fftw wisdom. 34 | 35 | * Relaxed the error checks on PCM WAV input files to allow 24, 32 bit and 36 | float sample formats (libsndfile handles the details of the conversion, 37 | so there is no real reason to exclude such files). 38 | 39 | * Added the -e command line option. It enables code that corrects for 40 | transceiver tuning error. The argument is the dial freq error in Hz. 41 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS= -I/usr/include -Wall -O2 3 | LDFLAGS = -L/usr/lib 4 | LIBS = -lfftw3 -lm 5 | 6 | DEPS = fano.h wsprd_utils.h 7 | OBJ = wsprd.o wsprd_utils.o fano.o tab.o nhash.o 8 | 9 | %.o: %.c $(DEPS) 10 | $(CC) -c -o $@ $< $(CFLAGS) 11 | 12 | k9an-wsprd: $(OBJ) 13 | $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) 14 | -------------------------------------------------------------------------------- /Makefile.osx: -------------------------------------------------------------------------------- 1 | CC=clang 2 | CFLAGS= -I/opt/local/include -Wall -O2 3 | LDFLAGS = -L/opt/local/lib 4 | LIBS = -lfftw3 -lm 5 | 6 | DEPS = fano.h wsprd_utils.h 7 | OBJ = wsprd.o wsprd_utils.o fano.o tab.o nhash.o 8 | 9 | %.o: %.c $(DEPS) 10 | $(CC) -c -o $@ $< $(CFLAGS) 11 | 12 | k9an-wsprd: $(OBJ) 13 | $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) 14 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a copy of K9AN's WSPR Decoder (https://github.com/k9an/old_wsprcan) modified slightly to read and write to stdin/out 2 | The reason it is not a fork is that, in the past, he uploaded huge amounts of wav files which are still downloaded due to git's 3 | version control, so this is just the output files. Original README is below. 4 | 5 | k9an-wsprd is a decoder for K1JT's Weak Signal Propagation Reporter (WSPR) mode. 6 | 7 | The program is written in C and is a command-line program that reads from a 8 | .c2 file or .wav file and writes output to the console. It is designed so that 9 | it can be used as a drop-in replacement for the wsprd program that wspr-x uses 10 | for decoding. 11 | 12 | k9an-wsprd requires only one external library: libfftw3 13 | 14 | COMPILING: 15 | A bare-bones Makefile is included. 16 | 17 | USAGE: 18 | k9an-wsprd [-nqwv] [-f freq] [-e error] infile 19 | 20 | -e error (error is dial frequency error in Hz) 21 | -f freq (freq is dial frequency in MHz) 22 | -H don't use (or update) the hashtable 23 | -n write estimated noise level to file "noise.dat" 24 | -q quick mode doesn't dig deep for weak signals 25 | -v verbose 26 | -w wideband mode displays decoded signals within +/- 150 Hz 27 | 28 | infile can be either .wav or .c2 29 | 30 | e.g. 31 | ./k9an-wsprd -wf 14.0956 140709_2258.wav 32 | 33 | Note that for .c2 files, the frequency within the file overrides the command 34 | line value. 35 | 36 | FEATURES: 37 | By default, k9an-wsprd reports signals that are within +/- 110 Hz of the 38 | subband center frequency. The wideband option (-w) extends this to +/- 150 Hz. 39 | 40 | k9an-wsprd maintains a hashtable and will decode all three types of wspr 41 | messages. An option (-H) is available to turn off use of the hashtable. 42 | 43 | k9an-wsprd was optimized to maximize the number of decodes on a crowded band. It 44 | uses a looser selection criterion than K1JT's program and therefore tries to 45 | decode more potential signals. Sometimes, it gets lucky! 46 | 47 | The symbols are decoded using Phil Karn's sequential decoder routine, 48 | fano.c. 49 | 50 | The code checks for the "WSPRD_FFTW_WISDOM" environment variable. If set, this 51 | variable specifies the file that contains the fftw wisdom. 52 | 53 | 54 | NOTES: 55 | This program attempts to maximize the number of successful decodes per transmit 56 | interval by trying to decode virtually every peak in the averaged spectrum. 57 | As such, there will be occasional duplicate decodes when two closely spaced 58 | peaks come from the same signal. The program removes dupes based on callsign 59 | and frequency. Two decodes that have the same callsign and estimated frequencies 60 | that are within 1 Hz will be treated as decodes of the same signal. This 61 | dupechecking is turned off with the -v flag. 62 | 63 | Feedback and suggestions for improvement are welcome! 64 | 65 | Steve Franke, k9an 66 | Urbana, IL, USA 67 | s.j.franke@icloud.com 68 | 69 | 70 | -------------------------------------------------------------------------------- /fano.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of wsprd. 3 | 4 | File name: fano.c 5 | 6 | Description: Soft decision Fano sequential decoder for K=32 r=1/2 7 | convolutional code. 8 | 9 | Copyright 1994, Phil Karn, KA9Q 10 | Minor modifications by Joe Taylor, K1JT 11 | */ 12 | 13 | #define LL 1 // Select Layland-Lushbaugh code 14 | #include 15 | #include 16 | #include 17 | #include "fano.h" 18 | 19 | struct node { 20 | unsigned long encstate; // Encoder state of next node 21 | long gamma; // Cumulative metric to this node 22 | int metrics[4]; // Metrics indexed by all possible tx syms 23 | int tm[2]; // Sorted metrics for current hypotheses 24 | int i; // Current branch being tested 25 | }; 26 | 27 | // Convolutional coding polynomials. All are rate 1/2, K=32 28 | #ifdef NASA_STANDARD 29 | /* "NASA standard" code by Massey & Costello 30 | * Nonsystematic, quick look-in, dmin=11, dfree=23 31 | * used on Pioneer 10-12, Helios A,B 32 | */ 33 | #define POLY1 0xbbef6bb7 34 | #define POLY2 0xbbef6bb5 35 | #endif 36 | 37 | #ifdef MJ 38 | /* Massey-Johannesson code 39 | * Nonsystematic, quick look-in, dmin=13, dfree>=23 40 | * Purported to be more computationally efficient than Massey-Costello 41 | */ 42 | #define POLY1 0xb840a20f 43 | #define POLY2 0xb840a20d 44 | #endif 45 | 46 | #ifdef LL 47 | /* Layland-Lushbaugh code 48 | * Nonsystematic, non-quick look-in, dmin=?, dfree=? 49 | */ 50 | #define POLY1 0xf2d05351 51 | #define POLY2 0xe4613c47 52 | #endif 53 | 54 | /* Convolutional encoder macro. Takes the encoder state, generates 55 | * a rate 1/2 symbol pair and stores it in 'sym'. The symbol generated from 56 | * POLY1 goes into the 2-bit of sym, and the symbol generated from POLY2 57 | * goes into the 1-bit. 58 | */ 59 | #define ENCODE(sym,encstate) {\ 60 | unsigned long _tmp;\ 61 | \ 62 | _tmp = (encstate) & POLY1;\ 63 | _tmp ^= _tmp >> 16;\ 64 | (sym) = Partab[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\ 65 | _tmp = (encstate) & POLY2;\ 66 | _tmp ^= _tmp >> 16;\ 67 | (sym) |= Partab[(_tmp ^ (_tmp >> 8)) & 0xff];\ 68 | } 69 | 70 | 71 | /* Convolutionally encode a packet. The input data bytes are read 72 | * high bit first and the encoded packet is written into 'symbols', 73 | * one symbol per byte. The first symbol is generated from POLY1, 74 | * the second from POLY2. 75 | * 76 | * Storing only one symbol per byte uses more space, but it is faster 77 | * and easier than trying to pack them more compactly. 78 | */ 79 | int encode( 80 | unsigned char *symbols, // Output buffer, 2*nbytes 81 | unsigned char *data, // Input buffer, nbytes 82 | unsigned int nbytes) // Number of bytes in data 83 | { 84 | unsigned long encstate; 85 | int sym; 86 | int i; 87 | 88 | encstate = 0; 89 | while(nbytes-- != 0) { 90 | for(i=7;i>=0;i--) { 91 | encstate = (encstate << 1) | ((*data >> i) & 1); 92 | ENCODE(sym,encstate); 93 | *symbols++ = sym >> 1; 94 | *symbols++ = sym & 1; 95 | } 96 | data++; 97 | } 98 | return 0; 99 | } 100 | 101 | /* Decode packet with the Fano algorithm. 102 | * Return 0 on success, -1 on timeout 103 | */ 104 | int fano( 105 | unsigned int *metric, // Final path metric (returned value) 106 | unsigned int *cycles, // Cycle count (returned value) 107 | unsigned int *maxnp, // Progress before timeout (returned value) 108 | unsigned char *data, // Decoded output data 109 | unsigned char *symbols, // Raw deinterleaved input symbols 110 | unsigned int nbits, // Number of output bits 111 | int mettab[2][256], // Metric table, [sent sym][rx symbol] 112 | int delta, // Threshold adjust parameter 113 | unsigned int maxcycles) // Decoding timeout in cycles per bit 114 | { 115 | struct node *nodes; // First node 116 | struct node *np; // Current node 117 | struct node *lastnode; // Last node 118 | struct node *tail; // First node of tail 119 | int t; // Threshold 120 | int m0,m1; 121 | int ngamma; 122 | unsigned int lsym; 123 | unsigned int i; 124 | 125 | if((nodes = (struct node *)malloc(nbits*sizeof(struct node))) == NULL) { 126 | printf("malloc failed\n"); 127 | return 0; 128 | } 129 | lastnode = &nodes[nbits-1]; 130 | tail = &nodes[nbits-31]; 131 | *maxnp = 0; 132 | 133 | /* Compute all possible branch metrics for each symbol pair 134 | * This is the only place we actually look at the raw input symbols 135 | */ 136 | for(np=nodes;np <= lastnode;np++) { 137 | np->metrics[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]]; 138 | np->metrics[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]]; 139 | np->metrics[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; 140 | np->metrics[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; 141 | symbols += 2; 142 | } 143 | np = nodes; 144 | np->encstate = 0; 145 | 146 | // Compute and sort branch metrics from root node */ 147 | ENCODE(lsym,np->encstate); // 0-branch (LSB is 0) 148 | m0 = np->metrics[lsym]; 149 | 150 | /* Now do the 1-branch. To save another ENCODE call here and 151 | * inside the loop, we assume that both polynomials are odd, 152 | * providing complementary pairs of branch symbols. 153 | 154 | * This code should be modified if a systematic code were used. 155 | */ 156 | 157 | m1 = np->metrics[3^lsym]; 158 | if(m0 > m1) { 159 | np->tm[0] = m0; // 0-branch has better metric 160 | np->tm[1] = m1; 161 | } else { 162 | np->tm[0] = m1; // 1-branch is better 163 | np->tm[1] = m0; 164 | np->encstate++; // Set low bit 165 | } 166 | np->i = 0; // Start with best branch 167 | maxcycles *= nbits; 168 | np->gamma = t = 0; 169 | 170 | // Start the Fano decoder 171 | for(i=1;i <= maxcycles;i++) { 172 | if((int)(np-nodes) > *maxnp) *maxnp=(int)(np-nodes); 173 | #ifdef debug 174 | printf("k=%ld, g=%ld, t=%d, m[%d]=%d, maxnp=%d\n", 175 | np-nodes,np->gamma,t,np->i,np->tm[np->i],*maxnp); 176 | #endif 177 | // Look forward */ 178 | ngamma = np->gamma + np->tm[np->i]; 179 | if(ngamma >= t) { 180 | if(np->gamma < t + delta) { // Node is acceptable 181 | /* First time we've visited this node; 182 | * Tighten threshold. 183 | * 184 | * This loop could be replaced with 185 | * t += delta * ((ngamma - t)/delta); 186 | * but the multiply and divide are slower. 187 | */ 188 | while(ngamma >= t + delta) t += delta; 189 | } 190 | np[1].gamma = ngamma; // Move forward 191 | np[1].encstate = np->encstate << 1; 192 | if(++np == lastnode) { 193 | break; // Done! 194 | } 195 | 196 | /* Compute and sort metrics, starting with the 197 | * zero branch 198 | */ 199 | ENCODE(lsym,np->encstate); 200 | if(np >= tail) { 201 | /* The tail must be all zeroes, so don't 202 | * bother computing the 1-branches here. 203 | */ 204 | np->tm[0] = np->metrics[lsym]; 205 | } else { 206 | m0 = np->metrics[lsym]; 207 | m1 = np->metrics[3^lsym]; 208 | if(m0 > m1) { 209 | np->tm[0] = m0; // 0-branch is better 210 | np->tm[1] = m1; 211 | } else { 212 | np->tm[0] = m1; // 1-branch is better 213 | np->tm[1] = m0; 214 | np->encstate++; // Set low bit 215 | } 216 | } 217 | np->i = 0; // Start with best branch 218 | continue; 219 | } 220 | // Threshold violated, can't go forward 221 | for(;;) { // Look backward 222 | if(np == nodes || np[-1].gamma < t) { 223 | /* Can't back up either. 224 | * Relax threshold and and look 225 | * forward again to better branch. 226 | */ 227 | t -= delta; 228 | if(np->i != 0) { 229 | np->i = 0; 230 | np->encstate ^= 1; 231 | } 232 | break; 233 | } 234 | // Back up 235 | if(--np < tail && np->i != 1) { 236 | np->i++; // Search next best branch 237 | np->encstate ^= 1; 238 | break; 239 | } // else keep looking back 240 | } 241 | } 242 | *metric = np->gamma; // Return the final path metric 243 | 244 | // Copy decoded data to user's buffer 245 | nbits >>= 3; 246 | np = &nodes[7]; 247 | while(nbits-- != 0) { 248 | *data++ = np->encstate; 249 | np += 8; 250 | } 251 | *cycles = i+1; 252 | free(nodes); 253 | if(i >= maxcycles) return -1; // Decoder timed out 254 | return 0; // Successful completion 255 | } 256 | -------------------------------------------------------------------------------- /fano.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of wsprd. 3 | 4 | File name: fano.h 5 | 6 | Description: Header file for sequential Fano decoder. 7 | 8 | Copyright 1994, Phil Karn, KA9Q 9 | Minor modifications by Joe Taylor, K1JT 10 | */ 11 | 12 | int fano(unsigned int *metric, unsigned int *cycles, unsigned int *maxnp, 13 | unsigned char *data,unsigned char *symbols, unsigned int nbits, 14 | int mettab[2][256],int delta,unsigned int maxcycles); 15 | 16 | int encode(unsigned char *symbols,unsigned char *data,unsigned int nbytes); 17 | 18 | extern unsigned char Partab[]; 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /mettab.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of k9an-wsprd. 3 | 4 | File name: mettab.c 5 | Description: 6 | 7 | Copyright 2014-2015, Steven Franke, K9AN 8 | License: GNU GPL v3 9 | 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program. If not, see . 22 | */ 23 | 24 | int mettab[2][256]={ 25 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 26 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 27 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 28 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 29 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 30 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 31 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 32 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 33 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 34 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 35 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 36 | 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 37 | -1, -1, -1, -2, -2, -3, -4, -4, -5, -6, 38 | -7, -7, -8, -9, -10, -11, -12, -12, -13, -14, 39 | -15, -16, -17, -17, -18, -19, -20, -21, -22, -22, 40 | -23, -24, -25, -26, -26, -27, -28, -29, -30, -30, 41 | -31, -32, -33, -33, -34, -35, -36, -36, -37, -38, 42 | -38, -39, -40, -41, -41, -42, -43, -43, -44, -45, 43 | -45, -46, -47, -47, -48, -49, -49, -50, -51, -51, 44 | -52, -53, -53, -54, -54, -55, -56, -56, -57, -57, 45 | -58, -59, -59, -60, -60, -61, -62, -62, -62, -63, 46 | -64, -64, -65, -65, -66, -67, -67, -67, -68, -69, 47 | -69, -70, -70, -71, -72, -72, -72, -72, -73, -74, 48 | -75, -75, -75, -77, -76, -76, -78, -78, -80, -81, 49 | -80, -79, -83, -82, -81, -82, -82, -83, -84, -84, 50 | -84, -87, -86, -87, -88, -89, -89, -89, -88, -87, 51 | -86, -87, -84, -84, -84, -83, -82, -82, -81, -82, 52 | -83, -79, -80, -81, -80, -78, -78, -76, -76, -77, 53 | -75, -75, -75, -74, -73, -72, -72, -72, -72, -71, 54 | -70, -70, -69, -69, -68, -67, -67, -67, -66, -65, 55 | -65, -64, -64, -63, -62, -62, -62, -61, -60, -60, 56 | -59, -59, -58, -57, -57, -56, -56, -55, -54, -54, 57 | -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, 58 | -47, -46, -45, -45, -44, -43, -43, -42, -41, -41, 59 | -40, -39, -38, -38, -37, -36, -36, -35, -34, -33, 60 | -33, -32, -31, -30, -30, -29, -28, -27, -26, -26, 61 | -25, -24, -23, -22, -22, -21, -20, -19, -18, -17, 62 | -17, -16, -15, -14, -13, -12, -12, -11, -10, -9, 63 | -8, -7, -7, -6, -5, -4, -4, -3, -2, -2, 64 | -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 65 | 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 66 | 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 67 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 68 | 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 69 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 70 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 71 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 72 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 73 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 74 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 75 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 76 | 5, 5}; 77 | -------------------------------------------------------------------------------- /nhash.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of k9an-wsprd. 3 | 4 | File name: wspr.c 5 | Description: k9an-wsprd is a detector/demodulator/decoder for K1JT's 6 | Weak Signal Propagation Reporter (WSPR) mode. 7 | 8 | Copyright 2014-2015, Steven Franke, K9AN 9 | License: GNU GPL v3 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | */ 24 | 25 | /* 26 | *------------------------------------------------------------------------------- 27 | * 28 | * This file is part of the WSPR application, Weak Signal Propogation Reporter 29 | * 30 | * File Name: nhash.c 31 | * Description: Functions to produce 32-bit hashes for hash table lookup 32 | * 33 | * Copyright (C) 2008-2014 Joseph Taylor, K1JT 34 | * License: GNU GPL v3+ 35 | * 36 | * This program is free software; you can redistribute it and/or modify it under 37 | * the terms of the GNU General Public License as published by the Free Software 38 | * Foundation; either version 3 of the License, or (at your option) any later 39 | * version. 40 | * 41 | * This program is distributed in the hope that it will be useful, but WITHOUT 42 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 43 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 44 | * details. 45 | * 46 | * You should have received a copy of the GNU General Public License along with 47 | * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 48 | * Street, Fifth Floor, Boston, MA 02110-1301, USA. 49 | * 50 | * Files: lookup3.c 51 | * Copyright: Copyright (C) 2006 Bob Jenkins 52 | * License: public-domain 53 | * You may use this code any way you wish, private, educational, or commercial. 54 | * It's free. 55 | * 56 | *------------------------------------------------------------------------------- 57 | */ 58 | 59 | /* 60 | These are functions for producing 32-bit hashes for hash table lookup. 61 | hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() 62 | are externally useful functions. Routines to test the hash are included 63 | if SELF_TEST is defined. You can use this free for any purpose. It's in 64 | the public domain. It has no warranty. 65 | 66 | You probably want to use hashlittle(). hashlittle() and hashbig() 67 | hash byte arrays. hashlittle() is is faster than hashbig() on 68 | little-endian machines. Intel and AMD are little-endian machines. 69 | On second thought, you probably want hashlittle2(), which is identical to 70 | hashlittle() except it returns two 32-bit hashes for the price of one. 71 | You could implement hashbig2() if you wanted but I haven't bothered here. 72 | 73 | If you want to find a hash of, say, exactly 7 integers, do 74 | a = i1; b = i2; c = i3; 75 | mix(a,b,c); 76 | a += i4; b += i5; c += i6; 77 | mix(a,b,c); 78 | a += i7; 79 | final(a,b,c); 80 | then use c as the hash value. If you have a variable length array of 81 | 4-byte integers to hash, use hashword(). If you have a byte array (like 82 | a character string), use hashlittle(). If you have several byte arrays, or 83 | a mix of things, see the comments above hashlittle(). 84 | 85 | Why is this so big? I read 12 bytes at a time into 3 4-byte integers, 86 | then mix those integers. This is fast (you can do a lot more thorough 87 | mixing with 12*3 instructions on 3 integers than you can with 3 instructions 88 | on 1 byte), but shoehorning those bytes into integers efficiently is messy. 89 | */ 90 | 91 | #define SELF_TEST 1 92 | 93 | #include /* defines printf for tests */ 94 | #include /* defines time_t for timings in the test */ 95 | #ifdef Win32 96 | #include "win_stdint.h" /* defines uint32_t etc */ 97 | #else 98 | #include /* defines uint32_t etc */ 99 | #endif 100 | //#include /* attempt to define endianness */ 101 | //#ifdef linux 102 | //# include /* attempt to define endianness */ 103 | //#endif 104 | 105 | #define HASH_LITTLE_ENDIAN 1 106 | 107 | #define hashsize(n) ((uint32_t)1<<(n)) 108 | #define hashmask(n) (hashsize(n)-1) 109 | #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) 110 | 111 | /* 112 | ------------------------------------------------------------------------------- 113 | mix -- mix 3 32-bit values reversibly. 114 | 115 | This is reversible, so any information in (a,b,c) before mix() is 116 | still in (a,b,c) after mix(). 117 | 118 | If four pairs of (a,b,c) inputs are run through mix(), or through 119 | mix() in reverse, there are at least 32 bits of the output that 120 | are sometimes the same for one pair and different for another pair. 121 | This was tested for: 122 | * pairs that differed by one bit, by two bits, in any combination 123 | of top bits of (a,b,c), or in any combination of bottom bits of 124 | (a,b,c). 125 | * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed 126 | the output delta to a Gray code (a^(a>>1)) so a string of 1's (as 127 | is commonly produced by subtraction) look like a single 1-bit 128 | difference. 129 | * the base values were pseudorandom, all zero but one bit set, or 130 | all zero plus a counter that starts at zero. 131 | 132 | Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that 133 | satisfy this are 134 | 4 6 8 16 19 4 135 | 9 15 3 18 27 15 136 | 14 9 3 7 17 3 137 | Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing 138 | for "differ" defined as + with a one-bit base and a two-bit delta. I 139 | used http://burtleburtle.net/bob/hash/avalanche.html to choose 140 | the operations, constants, and arrangements of the variables. 141 | 142 | This does not achieve avalanche. There are input bits of (a,b,c) 143 | that fail to affect some output bits of (a,b,c), especially of a. The 144 | most thoroughly mixed value is c, but it doesn't really even achieve 145 | avalanche in c. 146 | 147 | This allows some parallelism. Read-after-writes are good at doubling 148 | the number of bits affected, so the goal of mixing pulls in the opposite 149 | direction as the goal of parallelism. I did what I could. Rotates 150 | seem to cost as much as shifts on every machine I could lay my hands 151 | on, and rotates are much kinder to the top and bottom bits, so I used 152 | rotates. 153 | ------------------------------------------------------------------------------- 154 | */ 155 | #define mix(a,b,c) \ 156 | { \ 157 | a -= c; a ^= rot(c, 4); c += b; \ 158 | b -= a; b ^= rot(a, 6); a += c; \ 159 | c -= b; c ^= rot(b, 8); b += a; \ 160 | a -= c; a ^= rot(c,16); c += b; \ 161 | b -= a; b ^= rot(a,19); a += c; \ 162 | c -= b; c ^= rot(b, 4); b += a; \ 163 | } 164 | 165 | /* 166 | ------------------------------------------------------------------------------- 167 | final -- final mixing of 3 32-bit values (a,b,c) into c 168 | 169 | Pairs of (a,b,c) values differing in only a few bits will usually 170 | produce values of c that look totally different. This was tested for 171 | * pairs that differed by one bit, by two bits, in any combination 172 | of top bits of (a,b,c), or in any combination of bottom bits of 173 | (a,b,c). 174 | * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed 175 | the output delta to a Gray code (a^(a>>1)) so a string of 1's (as 176 | is commonly produced by subtraction) look like a single 1-bit 177 | difference. 178 | * the base values were pseudorandom, all zero but one bit set, or 179 | all zero plus a counter that starts at zero. 180 | 181 | These constants passed: 182 | 14 11 25 16 4 14 24 183 | 12 14 25 16 4 14 24 184 | and these came close: 185 | 4 8 15 26 3 22 24 186 | 10 8 15 26 3 22 24 187 | 11 8 15 26 3 22 24 188 | ------------------------------------------------------------------------------- 189 | */ 190 | #define final(a,b,c) \ 191 | { \ 192 | c ^= b; c -= rot(b,14); \ 193 | a ^= c; a -= rot(c,11); \ 194 | b ^= a; b -= rot(a,25); \ 195 | c ^= b; c -= rot(b,16); \ 196 | a ^= c; a -= rot(c,4); \ 197 | b ^= a; b -= rot(a,14); \ 198 | c ^= b; c -= rot(b,24); \ 199 | } 200 | 201 | /* 202 | ------------------------------------------------------------------------------- 203 | hashlittle() -- hash a variable-length key into a 32-bit value 204 | k : the key (the unaligned variable-length array of bytes) 205 | length : the length of the key, counting by bytes 206 | initval : can be any 4-byte value 207 | Returns a 32-bit value. Every bit of the key affects every bit of 208 | the return value. Two keys differing by one or two bits will have 209 | totally different hash values. 210 | 211 | The best hash table sizes are powers of 2. There is no need to do 212 | mod a prime (mod is sooo slow!). If you need less than 32 bits, 213 | use a bitmask. For example, if you need only 10 bits, do 214 | h = (h & hashmask(10)); 215 | In which case, the hash table should have hashsize(10) elements. 216 | 217 | If you are hashing n strings (uint8_t **)k, do it like this: 218 | for (i=0, h=0; i 12) 244 | { 245 | a += k[0]; 246 | b += k[1]; 247 | c += k[2]; 248 | mix(a,b,c); 249 | length -= 12; 250 | k += 3; 251 | } 252 | 253 | /*----------------------------- handle the last (probably partial) block */ 254 | /* 255 | * "k[2]&0xffffff" actually reads beyond the end of the string, but 256 | * then masks off the part it's not allowed to read. Because the 257 | * string is aligned, the masked-off tail is in the same word as the 258 | * rest of the string. Every machine with memory protection I've seen 259 | * does it on word boundaries, so is OK with this. But VALGRIND will 260 | * still catch it and complain. The masking trick does make the hash 261 | * noticably faster for short strings (like English words). 262 | */ 263 | #ifndef VALGRIND 264 | 265 | switch(length) 266 | { 267 | case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; 268 | case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; 269 | case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; 270 | case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; 271 | case 8 : b+=k[1]; a+=k[0]; break; 272 | case 7 : b+=k[1]&0xffffff; a+=k[0]; break; 273 | case 6 : b+=k[1]&0xffff; a+=k[0]; break; 274 | case 5 : b+=k[1]&0xff; a+=k[0]; break; 275 | case 4 : a+=k[0]; break; 276 | case 3 : a+=k[0]&0xffffff; break; 277 | case 2 : a+=k[0]&0xffff; break; 278 | case 1 : a+=k[0]&0xff; break; 279 | case 0 : return c; /* zero length strings require no mixing */ 280 | } 281 | 282 | #else /* make valgrind happy */ 283 | 284 | k8 = (const uint8_t *)k; 285 | switch(length) 286 | { 287 | case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; 288 | case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ 289 | case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ 290 | case 9 : c+=k8[8]; /* fall through */ 291 | case 8 : b+=k[1]; a+=k[0]; break; 292 | case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ 293 | case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ 294 | case 5 : b+=k8[4]; /* fall through */ 295 | case 4 : a+=k[0]; break; 296 | case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ 297 | case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ 298 | case 1 : a+=k8[0]; break; 299 | case 0 : return c; 300 | } 301 | 302 | #endif /* !valgrind */ 303 | 304 | } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { 305 | const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ 306 | const uint8_t *k8; 307 | 308 | /*--------------- all but last block: aligned reads and different mixing */ 309 | while (length > 12) 310 | { 311 | a += k[0] + (((uint32_t)k[1])<<16); 312 | b += k[2] + (((uint32_t)k[3])<<16); 313 | c += k[4] + (((uint32_t)k[5])<<16); 314 | mix(a,b,c); 315 | length -= 12; 316 | k += 6; 317 | } 318 | 319 | /*----------------------------- handle the last (probably partial) block */ 320 | k8 = (const uint8_t *)k; 321 | switch(length) 322 | { 323 | case 12: c+=k[4]+(((uint32_t)k[5])<<16); 324 | b+=k[2]+(((uint32_t)k[3])<<16); 325 | a+=k[0]+(((uint32_t)k[1])<<16); 326 | break; 327 | case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ 328 | case 10: c+=k[4]; 329 | b+=k[2]+(((uint32_t)k[3])<<16); 330 | a+=k[0]+(((uint32_t)k[1])<<16); 331 | break; 332 | case 9 : c+=k8[8]; /* fall through */ 333 | case 8 : b+=k[2]+(((uint32_t)k[3])<<16); 334 | a+=k[0]+(((uint32_t)k[1])<<16); 335 | break; 336 | case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ 337 | case 6 : b+=k[2]; 338 | a+=k[0]+(((uint32_t)k[1])<<16); 339 | break; 340 | case 5 : b+=k8[4]; /* fall through */ 341 | case 4 : a+=k[0]+(((uint32_t)k[1])<<16); 342 | break; 343 | case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ 344 | case 2 : a+=k[0]; 345 | break; 346 | case 1 : a+=k8[0]; 347 | break; 348 | case 0 : return c; /* zero length requires no mixing */ 349 | } 350 | 351 | } else { /* need to read the key one byte at a time */ 352 | const uint8_t *k = (const uint8_t *)key; 353 | 354 | /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ 355 | while (length > 12) 356 | { 357 | a += k[0]; 358 | a += ((uint32_t)k[1])<<8; 359 | a += ((uint32_t)k[2])<<16; 360 | a += ((uint32_t)k[3])<<24; 361 | b += k[4]; 362 | b += ((uint32_t)k[5])<<8; 363 | b += ((uint32_t)k[6])<<16; 364 | b += ((uint32_t)k[7])<<24; 365 | c += k[8]; 366 | c += ((uint32_t)k[9])<<8; 367 | c += ((uint32_t)k[10])<<16; 368 | c += ((uint32_t)k[11])<<24; 369 | mix(a,b,c); 370 | length -= 12; 371 | k += 12; 372 | } 373 | 374 | /*-------------------------------- last block: affect all 32 bits of (c) */ 375 | switch(length) /* all the case statements fall through */ 376 | { 377 | case 12: c+=((uint32_t)k[11])<<24; 378 | case 11: c+=((uint32_t)k[10])<<16; 379 | case 10: c+=((uint32_t)k[9])<<8; 380 | case 9 : c+=k[8]; 381 | case 8 : b+=((uint32_t)k[7])<<24; 382 | case 7 : b+=((uint32_t)k[6])<<16; 383 | case 6 : b+=((uint32_t)k[5])<<8; 384 | case 5 : b+=k[4]; 385 | case 4 : a+=((uint32_t)k[3])<<24; 386 | case 3 : a+=((uint32_t)k[2])<<16; 387 | case 2 : a+=((uint32_t)k[1])<<8; 388 | case 1 : a+=k[0]; 389 | break; 390 | case 0 : return c; 391 | } 392 | } 393 | 394 | final(a,b,c); 395 | c=(32767&c); 396 | 397 | return c; 398 | } 399 | -------------------------------------------------------------------------------- /tab.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of k9an-wsprd. 3 | 4 | File name: tab.c 5 | Description: k9an-wsprd is a detector/demodulator/decoder for K1JT's 6 | Weak Signal Propagation Reporter (WSPR) mode. 7 | 8 | Copyright 2014-2015, Steven Franke, K9AN 9 | License: GNU GPL v3 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | */ 24 | 25 | /* 8-bit parity lookup table, generated by partab.c */ 26 | unsigned char Partab[] = { 27 | 0, 1, 1, 0, 1, 0, 0, 1, 28 | 1, 0, 0, 1, 0, 1, 1, 0, 29 | 1, 0, 0, 1, 0, 1, 1, 0, 30 | 0, 1, 1, 0, 1, 0, 0, 1, 31 | 1, 0, 0, 1, 0, 1, 1, 0, 32 | 0, 1, 1, 0, 1, 0, 0, 1, 33 | 0, 1, 1, 0, 1, 0, 0, 1, 34 | 1, 0, 0, 1, 0, 1, 1, 0, 35 | 1, 0, 0, 1, 0, 1, 1, 0, 36 | 0, 1, 1, 0, 1, 0, 0, 1, 37 | 0, 1, 1, 0, 1, 0, 0, 1, 38 | 1, 0, 0, 1, 0, 1, 1, 0, 39 | 0, 1, 1, 0, 1, 0, 0, 1, 40 | 1, 0, 0, 1, 0, 1, 1, 0, 41 | 1, 0, 0, 1, 0, 1, 1, 0, 42 | 0, 1, 1, 0, 1, 0, 0, 1, 43 | 1, 0, 0, 1, 0, 1, 1, 0, 44 | 0, 1, 1, 0, 1, 0, 0, 1, 45 | 0, 1, 1, 0, 1, 0, 0, 1, 46 | 1, 0, 0, 1, 0, 1, 1, 0, 47 | 0, 1, 1, 0, 1, 0, 0, 1, 48 | 1, 0, 0, 1, 0, 1, 1, 0, 49 | 1, 0, 0, 1, 0, 1, 1, 0, 50 | 0, 1, 1, 0, 1, 0, 0, 1, 51 | 0, 1, 1, 0, 1, 0, 0, 1, 52 | 1, 0, 0, 1, 0, 1, 1, 0, 53 | 1, 0, 0, 1, 0, 1, 1, 0, 54 | 0, 1, 1, 0, 1, 0, 0, 1, 55 | 1, 0, 0, 1, 0, 1, 1, 0, 56 | 0, 1, 1, 0, 1, 0, 0, 1, 57 | 0, 1, 1, 0, 1, 0, 0, 1, 58 | 1, 0, 0, 1, 0, 1, 1, 0, 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /wsprd.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of program wsprd, a detector/demodulator/decoder 3 | for the Weak Signal Propagation Reporter (WSPR) mode. Presently 4 | implemented for WSPR-2; needs some changes for WSPR-15. 5 | 6 | File name: wsprd.c 7 | 8 | Copyright 2001-2015, Joe Taylor, K1JT 9 | Copyright 2014-2015, Steven Franke, K9AN 10 | 11 | License: GNU GPL v3 12 | 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation, either version 3 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program. If not, see . 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "fano.h" 37 | #include "wsprd_utils.h" 38 | 39 | #define max(x,y) ((x) > (y) ? (x) : (y)) 40 | // Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, 41 | // FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE 42 | #define PATIENCE FFTW_ESTIMATE 43 | fftw_plan PLAN1,PLAN2,PLAN3; 44 | 45 | unsigned char pr3[162]= 46 | {1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0, 47 | 0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1, 48 | 0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1, 49 | 1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1, 50 | 0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0, 51 | 0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1, 52 | 0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1, 53 | 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, 54 | 0,0}; 55 | 56 | unsigned long nr; 57 | 58 | //*************************************************************************** 59 | unsigned long readc2file(char *ptr_to_infile, double *idat, double *qdat, 60 | double *freq) 61 | { 62 | float buffer[2*65536]; 63 | double dfreq; 64 | int i,ntrmin; 65 | char *c2file[15]; 66 | FILE* fp; 67 | 68 | fp=fopen(ptr_to_infile,"r"); 69 | fp = fopen(ptr_to_infile,"rb"); 70 | if (fp == NULL) { 71 | fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); 72 | return 1; 73 | } 74 | unsigned long nread=fread(c2file,sizeof(char),14,fp); 75 | nread=fread(&ntrmin,sizeof(int),1,fp); 76 | nread=fread(&dfreq,sizeof(double),1,fp); 77 | *freq=dfreq; 78 | nread=fread(buffer,sizeof(float),2*45000,fp); 79 | 80 | for(i=0; i<45000; i++) { 81 | idat[i]=buffer[2*i]; 82 | qdat[i]=-buffer[2*i+1]; 83 | } 84 | 85 | if( nread == 2*45000 ) { 86 | return nread/2; 87 | } else { 88 | return 1; 89 | } 90 | } 91 | 92 | //*************************************************************************** 93 | unsigned long readwavfile(char *ptr_to_infile, double *idat, double *qdat ) 94 | { 95 | unsigned long i, j; 96 | int nfft1=1474560;; 97 | int nfft2=nfft1/32; //nfft2=46080 98 | int nh2=nfft2/2; 99 | double df=12000.0/nfft1; 100 | int i0=1500.0/df+0.5; 101 | double *realin; 102 | fftw_complex *fftin, *fftout; 103 | 104 | FILE *fp; 105 | unsigned long npoints=114*12000; 106 | short int *buf2; 107 | buf2 = malloc(npoints*sizeof(short int)); 108 | 109 | fp = fopen(ptr_to_infile,"rb"); 110 | if (fp == NULL) { 111 | fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); 112 | return 1; 113 | } 114 | 115 | nr=fread(buf2,2,22,fp); //Read and ignore header 116 | nr=fread(buf2,2,npoints,fp); //Read raw data 117 | fclose(fp); 118 | 119 | realin=(double*) fftw_malloc(sizeof(double)*nfft1); 120 | fftout=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*nfft1); 121 | PLAN1 = fftw_plan_dft_r2c_1d(nfft1, realin, fftout, PATIENCE); 122 | 123 | for (i=0; inh2 ) j=j-nfft2; 140 | fftin[i][0]=fftout[j][0]; 141 | fftin[i][1]=fftout[j][1]; 142 | } 143 | 144 | fftw_free(fftout); 145 | fftout=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*nfft2); 146 | PLAN2 = fftw_plan_dft_1d(nfft2, fftin, fftout, FFTW_BACKWARD, PATIENCE); 147 | fftw_execute(PLAN2); 148 | 149 | for (i=0; i0) & (k syncmax ) { //Save best parameters 272 | syncmax=ss/totp; 273 | best_shift=lag; 274 | fbest=f0; 275 | } 276 | } // lag loop 277 | } //freq loop 278 | 279 | if( mode <=1 ) { //Send best params back to caller 280 | *sync=syncmax; 281 | *shift1=best_shift; 282 | *f1=fbest; 283 | return; 284 | } 285 | 286 | if( mode == 2 ) { 287 | *sync=syncmax; 288 | for (i=0; i<162; i++) { //Normalize the soft symbols 289 | fsum=fsum+fsymb[i]/162.0; 290 | f2sum=f2sum+fsymb[i]*fsymb[i]/162.0; 291 | } 292 | fac=sqrt(f2sum-fsum*fsum); 293 | for (i=0; i<162; i++) { 294 | fsymb[i]=symfac*fsymb[i]/fac; 295 | if( fsymb[i] > 127) fsymb[i]=127.0; 296 | if( fsymb[i] < -128 ) fsymb[i]=-128.0; 297 | symbols[i]=fsymb[i] + 128; 298 | } 299 | return; 300 | } 301 | return; 302 | } 303 | 304 | //*************************************************************************** 305 | void usage(void) 306 | { 307 | printf("Usage: wsprd [options...] infile\n"); 308 | printf(" infile must have suffix .wav or .c2\n"); 309 | printf("\n"); 310 | printf("Options:\n"); 311 | printf(" -e x (x is transceiver dial frequency error in Hz)\n"); 312 | printf(" -f x (x is transceiver dial frequency in MHz)\n"); 313 | // blanking is not yet implemented. The options are accepted for compatibility 314 | // with development version of wsprd. 315 | // printf(" -t n (n is blanking duration in milliseconds)\n"); 316 | // printf(" -b n (n is pct of time that is blanked)\n"); 317 | printf(" -H do not use (or update) the hash table\n"); 318 | printf(" -n write noise estimates to file noise.dat\n"); 319 | printf(" -q quick mode - doesn't dig deep for weak signals\n"); 320 | printf(" -v verbose mode\n"); 321 | printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n"); 322 | } 323 | 324 | //*************************************************************************** 325 | int main(int argc, char *argv[]) 326 | { 327 | extern char *optarg; 328 | extern int optind; 329 | int i,j,k; 330 | unsigned char *symbols, *decdata; 331 | signed char message[]={-9,13,-35,123,57,-39,64,0,0,0,0}; 332 | char *callsign,*grid,*grid6, *call_loc_pow, *cdbm; 333 | char *ptr_to_infile,*ptr_to_infile_suffix; 334 | char uttime[5],date[7]; 335 | int c,delta,nfft2=65536,verbose=0,quickmode=0,writenoise=0,usehashtable=1; 336 | int shift1, lagmin, lagmax, lagstep, worth_a_try, not_decoded, nadd, ndbm; 337 | int32_t n1, n2, n3; 338 | unsigned int nbits; 339 | unsigned int npoints, metric, maxcycles, cycles, maxnp; 340 | float df=375.0/256.0/2; 341 | float freq0[200],snr0[200],drift0[200],sync0[200]; 342 | int shift0[200]; 343 | float dt=1.0/375.0; 344 | double dialfreq_cmdline=0.0, dialfreq; 345 | float dialfreq_error=0.0; 346 | float fmin=-110, fmax=110; 347 | float f1, fstep, sync1, drift1, tblank=0, fblank=0; 348 | double *idat, *qdat; 349 | clock_t t0,t00; 350 | double tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0; 351 | double tsync1=0.0,tsync2=0.0,ttotal=0.0; 352 | 353 | // Parameters used for performance-tuning: 354 | maxcycles=10000; //Fano timeout limit 355 | double minsync1=0.10; //First sync limit 356 | double minsync2=0.12; //Second sync limit 357 | int iifac=3; //Step size in final DT peakup 358 | int symfac=45; //Soft-symbol normalizing factor 359 | int maxdrift=4; //Maximum (+/-) drift 360 | double minrms=52.0 * (symfac/64.0); //Final test for palusible decoding 361 | delta=60; //Fano threshold step 362 | 363 | t00=clock(); 364 | fftw_complex *fftin, *fftout; 365 | #include "./mettab.c" 366 | 367 | // Check for an optional FFTW wisdom file 368 | FILE *fp_fftw_wisdom_file; 369 | if ((fp_fftw_wisdom_file = fopen("fftw_wisdom_wsprd", "r"))) { 370 | fftw_import_wisdom_from_file(fp_fftw_wisdom_file); 371 | fclose(fp_fftw_wisdom_file); 372 | } 373 | 374 | idat=malloc(sizeof(double)*nfft2); 375 | qdat=malloc(sizeof(double)*nfft2); 376 | 377 | while ( (c = getopt(argc, argv, "b:e:f:Hnqt:wv")) !=-1 ) { 378 | switch (c) { 379 | case 'b': 380 | fblank = strtof(optarg,NULL); 381 | break; 382 | case 'e': 383 | dialfreq_error = strtof(optarg,NULL); // units of Hz 384 | // dialfreq_error = dial reading - actual, correct frequency 385 | break; 386 | case 'f': 387 | dialfreq_cmdline = strtod(optarg,NULL); // units of MHz 388 | break; 389 | case 'H': 390 | usehashtable = 0; 391 | break; 392 | case 'n': 393 | writenoise = 1; 394 | break; 395 | case 'q': 396 | quickmode = 1; 397 | break; 398 | case 't': 399 | tblank = strtof(optarg,NULL); 400 | break; 401 | case 'v': 402 | verbose = 1; 403 | break; 404 | case 'w': 405 | fmin=-150.0; 406 | fmax=150.0; 407 | break; 408 | case '?': 409 | usage(); 410 | return 1; 411 | } 412 | } 413 | 414 | if( optind+1 > argc) { 415 | usage(); 416 | return 1; 417 | } else { 418 | ptr_to_infile=argv[optind]; 419 | } 420 | 421 | FILE *fall_wspr, *fwsprd, *fhash, *ftimer; 422 | FILE *fdiag; 423 | fall_wspr=fopen("/dev/null", "w"); 424 | fwsprd=fopen("/dev/null","w"); 425 | fdiag=fopen("/dev/null","a"); 426 | 427 | if((ftimer=fopen("wsprd_timer","r"))) { 428 | //Accumulate timing data 429 | nr=fscanf(ftimer,"%lf %lf %lf %lf %lf %lf %lf", 430 | &treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&ttotal); 431 | fclose(ftimer); 432 | } 433 | ftimer=fopen("/dev/null","w"); 434 | 435 | // Parse date and time from given filename 436 | time_t calendar = time(NULL); 437 | struct tm utc; 438 | gmtime_r(&calendar, &utc); 439 | strftime(date, 7, "%y%m%d", &utc); 440 | strftime(uttime, 5, "%H%M", &utc); 441 | date[6]='\0'; 442 | uttime[4]='\0'; 443 | 444 | if( strstr(ptr_to_infile,".wav") || strcmp(ptr_to_infile, "/dev/stdin") == 0) { 445 | ptr_to_infile_suffix=strstr("test.wav",".wav"); 446 | 447 | t0 = clock(); 448 | npoints=readwavfile(ptr_to_infile, idat, qdat); 449 | treadwav += (double)(clock()-t0)/CLOCKS_PER_SEC; 450 | 451 | if( npoints == 1 ) { 452 | return 1; 453 | } 454 | dialfreq=dialfreq_cmdline - (dialfreq_error*1.0e-06); 455 | } else if ( strstr(ptr_to_infile,".c2") !=0 ) { 456 | ptr_to_infile_suffix=strstr(ptr_to_infile,".c2"); 457 | npoints=readc2file(ptr_to_infile, idat, qdat, &dialfreq); 458 | if( npoints == 1 ) { 459 | return 1; 460 | } 461 | dialfreq -= (dialfreq_error*1.0e-06); 462 | } else { 463 | printf("Error: Failed to open %s\n",ptr_to_infile); 464 | printf("WSPR file must have suffix .wav or .c2\n"); 465 | return 1; 466 | } 467 | 468 | // Do windowed ffts over 2 symbols, stepped by half symbols 469 | int nffts=4*floor(npoints/512)-1; 470 | fftin=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*512); 471 | fftout=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*512); 472 | PLAN3 = fftw_plan_dft_1d(512, fftin, fftout, FFTW_FORWARD, PATIENCE); 473 | 474 | float ps[512][nffts]; 475 | float w[512]; 476 | for(i=0; i<512; i++) { 477 | w[i]=sin(0.006135923*i); 478 | } 479 | 480 | memset(ps,0.0, sizeof(float)*512*nffts); 481 | for (i=0; i511 ) 491 | k=k-512; 492 | ps[j][i]=fftout[k][0]*fftout[k][0]+fftout[k][1]*fftout[k][1]; 493 | } 494 | } 495 | 496 | fftw_free(fftin); 497 | fftw_free(fftout); 498 | 499 | // Compute average spectrum 500 | float psavg[512]; 501 | memset(psavg,0.0, sizeof(float)*512); 502 | for (i=0; ismspec[j-1]) && (smspec[j]>smspec[j+1]) && (npk<200)) { 549 | freq0[npk]=(j-205)*df; 550 | snr0[npk]=10*log10(smspec[j])-26.5; 551 | npk++; 552 | } 553 | } 554 | 555 | // Compute corrected fmin, fmax, accounting for dial frequency error 556 | fmin += dialfreq_error; // dialfreq_error is in units of Hz 557 | fmax += dialfreq_error; 558 | 559 | // Don't waste time on signals outside of the range [fmin,fmax]. 560 | i=0; 561 | for( j=0; j= fmin && freq0[j] <= fmax ) { 563 | freq0[i]=freq0[j]; 564 | snr0[i]=snr0[j]; 565 | i++; 566 | } 567 | } 568 | npk=i; 569 | 570 | t0=clock(); 571 | /* Make coarse estimates of shift (DT), freq, and drift 572 | 573 | * Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative 574 | to nominal start time, which is 2 seconds into the file 575 | 576 | * Calculates shift relative to the beginning of the file 577 | 578 | * Negative shifts mean that signal started before start of file 579 | 580 | * The program prints DT = shift-2 s 581 | 582 | * Shifts that cause sync vector to fall off of either end of the data 583 | vector are accommodated by "partial decoding", such that missing 584 | symbols produce a soft-decision symbol value of 128 585 | 586 | * The frequency drift model is linear, deviation of +/- drift/2 over the 587 | span of 162 symbols, with deviation equal to 0 at the center of the 588 | signal vector. 589 | */ 590 | 591 | int idrift,ifr,if0,ifd,k0; 592 | int kindex; 593 | float smax,ss,pow,p0,p1,p2,p3; 594 | for(j=0; j smax ) { //Save coarse parameters 622 | smax=sync1; 623 | shift0[j]=128*(k0+1); 624 | drift0[j]=idrift; 625 | freq0[j]=(ifr-256)*df; 626 | sync0[j]=sync1; 627 | } 628 | } 629 | } 630 | } 631 | } 632 | tcandidates += (double)(clock()-t0)/CLOCKS_PER_SEC; 633 | 634 | nbits=81; 635 | symbols=malloc(sizeof(char)*nbits*2); 636 | memset(symbols,0,sizeof(char)*nbits*2); 637 | decdata=malloc((nbits+7)/8); 638 | grid=malloc(sizeof(char)*5); 639 | grid6=malloc(sizeof(char)*7); 640 | callsign=malloc(sizeof(char)*13); 641 | call_loc_pow=malloc(sizeof(char)*23); 642 | cdbm=malloc(sizeof(char)*3); 643 | float allfreqs[npk]; 644 | memset(allfreqs,0,sizeof(float)*npk); 645 | char allcalls[npk][13]; 646 | memset(allcalls,0,sizeof(char)*npk*13); 647 | memset(grid,0,sizeof(char)*5); 648 | memset(grid6,0,sizeof(char)*7); 649 | memset(callsign,0,sizeof(char)*13); 650 | memset(call_loc_pow,0,sizeof(char)*23); 651 | memset(cdbm,0,sizeof(char)*3); 652 | char hashtab[32768][13]; 653 | memset(hashtab,0,sizeof(char)*32768*13); 654 | uint32_t nhash( const void *, size_t, uint32_t); 655 | int nh; 656 | 657 | if( usehashtable ) { 658 | char line[80], hcall[12]; 659 | if( (fhash=fopen("hashtable.txt","r+")) ) { 660 | while (fgets(line, sizeof(line), fhash) != NULL) { 661 | sscanf(line,"%d %s",&nh,hcall); 662 | strcpy(*hashtab+nh*13,hcall); 663 | } 664 | } else { 665 | fhash=fopen("/dev/null","w+"); 666 | } 667 | fclose(fhash); 668 | } 669 | 670 | int uniques=0, noprint=0; 671 | /* 672 | Refine the estimates of freq, shift using sync as a metric. 673 | Sync is calculated such that it is a float taking values in the range 674 | [0.0,1.0]. 675 | 676 | Function sync_and_demodulate has three modes of operation 677 | mode is the last argument: 678 | 679 | 0 = no frequency or drift search. find best time lag. 680 | 1 = no time lag or drift search. find best frequency. 681 | 2 = no frequency or time lag search. Calculate soft-decision 682 | symbols using passed frequency and shift. 683 | 684 | NB: best possibility for OpenMP may be here: several worker threads 685 | could each work on one candidate at a time. 686 | */ 687 | 688 | for (j=0; j minsync1 ) { 713 | worth_a_try = 1; 714 | } else { 715 | worth_a_try = 0; 716 | } 717 | 718 | int idt=0, ii=0, jiggered_shift; 719 | uint32_t ihash; 720 | double y,sq,rms; 721 | not_decoded=1; 722 | 723 | while ( worth_a_try && not_decoded && idt<=(128/iifac)) { 724 | ii=(idt+1)/2; 725 | if( idt%2 == 1 ) ii=-ii; 726 | ii=iifac*ii; 727 | jiggered_shift=shift1+ii; 728 | 729 | // Use mode 2 to get soft-decision symbols 730 | t0 = clock(); 731 | sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, 732 | &jiggered_shift, lagmin, lagmax, lagstep, &drift1, symfac, 733 | &sync1, 2); 734 | tsync2 += (double)(clock()-t0)/CLOCKS_PER_SEC; 735 | 736 | sq=0.0; 737 | for(i=0; i<162; i++) { 738 | y=(double)symbols[i] - 128.0; 739 | sq += y*y; 740 | } 741 | rms=sqrt(sq/162.0); 742 | 743 | if((sync1 > minsync2) && (rms > minrms)) { 744 | deinterleave(symbols); 745 | t0 = clock(); 746 | not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits, 747 | mettab,delta,maxcycles); 748 | tfano += (double)(clock()-t0)/CLOCKS_PER_SEC; 749 | 750 | /* ### Used for timing tests: 751 | if(not_decoded) fprintf(fdiag, 752 | "%6s %4s %4.1f %3.0f %4.1f %10.7f %-18s %2d %5u %4d %6.1f %2d\n", 753 | date,uttime,sync1*10,snr0[j], shift1*dt-2.0, dialfreq+(1500+f1)/1e6, 754 | "@ ", (int)drift1, cycles/81, ii, rms, maxnp); 755 | */ 756 | } 757 | idt++; 758 | if( quickmode ) break; 759 | } 760 | 761 | if( worth_a_try && !not_decoded ) { 762 | for(i=0; i<11; i++) { 763 | if( decdata[i]>127 ) { 764 | message[i]=decdata[i]-256; 765 | } else { 766 | message[i]=decdata[i]; 767 | } 768 | } 769 | 770 | unpack50(message,&n1,&n2); 771 | unpackcall(n1,callsign); 772 | unpackgrid(n2, grid); 773 | int ntype = (n2&127) - 64; 774 | 775 | /* 776 | Based on the value of ntype, decide whether this is a Type 1, 2, or 777 | 3 message. 778 | 779 | * Type 1: 6 digit call, grid, power - ntype is positive and is a member 780 | of the set {0,3,7,10,13,17,20...60} 781 | 782 | * Type 2: extended callsign, power - ntype is positive but not 783 | a member of the set of allowed powers 784 | 785 | * Type 3: hash, 6 digit grid, power - ntype is negative. 786 | */ 787 | 788 | if( (ntype >= 0) && (ntype <= 62) ) { 789 | int nu=ntype%10; 790 | if( nu == 0 || nu == 3 || nu == 7 ) { 791 | ndbm=ntype; 792 | memset(call_loc_pow,0,sizeof(char)*23); 793 | sprintf(cdbm,"%2d",ndbm); 794 | strncat(call_loc_pow,callsign,strlen(callsign)); 795 | strncat(call_loc_pow," ",1); 796 | strncat(call_loc_pow,grid,4); 797 | strncat(call_loc_pow," ",1); 798 | strncat(call_loc_pow,cdbm,2); 799 | strncat(call_loc_pow,"\0",1); 800 | 801 | ihash=nhash(callsign,strlen(callsign),(uint32_t)146); 802 | strcpy(*hashtab+ihash*13,callsign); 803 | 804 | noprint=0; 805 | } else { 806 | nadd=nu; 807 | if( nu > 3 ) nadd=nu-3; 808 | if( nu > 7 ) nadd=nu-7; 809 | n3=n2/128+32768*(nadd-1); 810 | unpackpfx(n3,callsign); 811 | ndbm=ntype-nadd; 812 | 813 | memset(call_loc_pow,0,sizeof(char)*23); 814 | sprintf(cdbm,"%2d",ndbm); 815 | strncat(call_loc_pow,callsign,strlen(callsign)); 816 | strncat(call_loc_pow," ",1); 817 | strncat(call_loc_pow,cdbm,2); 818 | strncat(call_loc_pow,"\0",1); 819 | 820 | ihash=nhash(callsign,strlen(callsign),(uint32_t)146); 821 | strcpy(*hashtab+ihash*13,callsign); 822 | 823 | noprint=0; 824 | } 825 | } else if ( ntype < 0 ) { 826 | ndbm=-(ntype+1); 827 | memset(grid6,0,sizeof(char)*7); 828 | strncat(grid6,callsign+5,1); 829 | strncat(grid6,callsign,5); 830 | ihash=(n2-ntype-64)/128; 831 | if( strncmp(hashtab[ihash],"\0",1) != 0 ) { 832 | sprintf(callsign,"<%s>",hashtab[ihash]); 833 | } else { 834 | sprintf(callsign,"%5s","<...>"); 835 | } 836 | 837 | memset(call_loc_pow,0,sizeof(char)*23); 838 | sprintf(cdbm,"%2d",ndbm); 839 | strncat(call_loc_pow,callsign,strlen(callsign)); 840 | strncat(call_loc_pow," ",1); 841 | strncat(call_loc_pow,grid6,strlen(grid6)); 842 | strncat(call_loc_pow," ",1); 843 | strncat(call_loc_pow,cdbm,2); 844 | strncat(call_loc_pow,"\0",1); 845 | 846 | noprint=0; 847 | 848 | // I don't know what to do with these... They show up as "A000AA" grids. 849 | if( ntype == -64 ) noprint=1; 850 | 851 | } 852 | 853 | // Remove dupes (same callsign and freq within 1 Hz) 854 | int dupe=0; 855 | for (i=0; i. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifndef int32_t 35 | #define int32_t int 36 | #endif 37 | 38 | void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ) 39 | { 40 | int32_t i,i4; 41 | 42 | i=dat[0]; 43 | i4=i&255; 44 | *n1=i4<<20; 45 | 46 | i=dat[1]; 47 | i4=i&255; 48 | *n1=*n1+(i4<<12); 49 | 50 | i=dat[2]; 51 | i4=i&255; 52 | *n1=*n1+(i4<<4); 53 | 54 | i=dat[3]; 55 | i4=i&255; 56 | *n1=*n1+((i4>>4)&15); 57 | *n2=(i4&15)<<18; 58 | 59 | i=dat[4]; 60 | i4=i&255; 61 | *n2=*n2+(i4<<10); 62 | 63 | i=dat[5]; 64 | i4=i&255; 65 | *n2=*n2+(i4<<2); 66 | 67 | i=dat[6]; 68 | i4=i&255; 69 | *n2=*n2+((i4>>6)&3); 70 | } 71 | 72 | void unpackcall( int32_t ncall, char *call ) 73 | { 74 | char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', 75 | 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', 76 | 'U','V','W','X','Y','Z',' '}; 77 | int32_t n; 78 | int i; 79 | char tmp[7]; 80 | 81 | n=ncall; 82 | strcpy(call,"......"); 83 | if (n < 262177560 ) { 84 | i=n%27+10; 85 | tmp[5]=c[i]; 86 | n=n/27; 87 | i=n%27+10; 88 | tmp[4]=c[i]; 89 | n=n/27; 90 | i=n%27+10; 91 | tmp[3]=c[i]; 92 | n=n/27; 93 | i=n%10; 94 | tmp[2]=c[i]; 95 | n=n/10; 96 | i=n%36; 97 | tmp[1]=c[i]; 98 | n=n/36; 99 | i=n; 100 | tmp[0]=c[i]; 101 | tmp[6]='\0'; 102 | // remove leading whitespace 103 | for(i=0; i<5; i++) { 104 | if( tmp[i] != c[36] ) 105 | break; 106 | } 107 | sprintf(call,"%-6s",&tmp[i]); 108 | // remove trailing whitespace 109 | for(i=0; i<6; i++) { 110 | if( call[i] == c[36] ) { 111 | call[i]='\0'; 112 | } 113 | } 114 | } 115 | } 116 | 117 | void unpackgrid( int32_t ngrid, char *grid) 118 | { 119 | char c[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E', 120 | 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', 121 | 'U','V','W','X','Y','Z',' '}; 122 | int dlat, dlong; 123 | 124 | ngrid=ngrid>>7; 125 | if( ngrid < 32400 ) { 126 | dlat=(ngrid%180)-90; 127 | dlong=(ngrid/180)*2 - 180 + 2; 128 | if( dlong < -180 ) 129 | dlong=dlong+360; 130 | if( dlong > 180 ) 131 | dlong=dlong+360; 132 | int nlong = 60.0*(180.0-dlong)/5.0; 133 | int n1 = nlong/240; 134 | int n2 = (nlong - 240*n1)/24; 135 | grid[0] = c[10+n1]; 136 | grid[2]= c[n2]; 137 | 138 | int nlat = 60.0*(dlat+90)/2.5; 139 | n1 = nlat/240; 140 | n2 = (nlat-240*n1)/24; 141 | grid[1]=c[10+n1]; 142 | grid[3]=c[n2]; 143 | } else { 144 | strcpy(grid,"XXXX"); 145 | } 146 | } 147 | 148 | void unpackpfx( int32_t nprefix, char *call) 149 | { 150 | char nc, pfx[4]="", tmpcall[7]=""; 151 | int i; 152 | int32_t n; 153 | 154 | strcpy(tmpcall,call); 155 | 156 | if( nprefix < 60000 ) { 157 | // add a prefix of 1 to 3 characters 158 | n=nprefix; 159 | for (i=2; i>=0; i--) { 160 | nc=n%37; 161 | if( (nc >= 0) & (nc <= 9) ) { 162 | pfx[i]=nc+48; 163 | } 164 | else if( (nc >= 10) & (nc <= 35) ) { 165 | pfx[i]=nc+55; 166 | } 167 | else { 168 | pfx[i]=' '; 169 | } 170 | n=n/37; 171 | } 172 | 173 | strcpy(call,pfx); 174 | strncat(call,"/",1); 175 | strncat(call,tmpcall,strlen(tmpcall)); 176 | 177 | } else { 178 | // add a suffix of 1 or 2 characters 179 | nc=nprefix-60000; 180 | if( (nc >= 0) & (nc <= 9) ) { 181 | pfx[0]=nc+48; 182 | strcpy(call,tmpcall); 183 | strncat(call,"/",1); 184 | strncat(call,pfx,1); 185 | } 186 | else if( (nc >= 10) & (nc <= 35) ) { 187 | pfx[0]=nc+55; 188 | strcpy(call,tmpcall); 189 | strncat(call,"/",1); 190 | strncat(call,pfx,1); 191 | } 192 | else if( (nc >= 36) & (nc <= 125) ) { 193 | pfx[0]=(nc-26)/10+48; 194 | pfx[1]=(nc-26)%10+48; 195 | strcpy(call,tmpcall); 196 | strncat(call,"/",1); 197 | strncat(call,pfx,2); 198 | } 199 | } 200 | } 201 | 202 | void deinterleave(unsigned char *sym) 203 | { 204 | unsigned char tmp[162]; 205 | unsigned char p, i, j; 206 | 207 | p=0; 208 | i=0; 209 | while (p<162) { 210 | j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; 211 | if (j < 162 ) { 212 | tmp[p]=sym[j]; 213 | p=p+1; 214 | } 215 | i=i+1; 216 | } 217 | for (i=0; i<162; i++) { 218 | sym[i]=tmp[i]; 219 | } 220 | } 221 | 222 | // used by qsort 223 | int floatcomp(const void* elem1, const void* elem2) 224 | { 225 | if(*(const float*)elem1 < *(const float*)elem2) 226 | return -1; 227 | return *(const float*)elem1 > *(const float*)elem2; 228 | } 229 | -------------------------------------------------------------------------------- /wsprd_utils.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void unpack50( signed char *dat, int32_t *n1, int32_t *n2 ); 6 | 7 | void unpackcall( int32_t ncall, char *call ); 8 | 9 | void unpackgrid( int32_t ngrid, char *grid); 10 | 11 | void unpackpfx( int32_t nprefix, char *call); 12 | 13 | void deinterleave(unsigned char *sym); 14 | 15 | // used by qsort 16 | int floatcomp(const void* elem1, const void* elem2); 17 | 18 | --------------------------------------------------------------------------------