├── .github └── workflows │ └── codeql-analysis.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG ├── CMakeLists.txt ├── CONTRIBUTING.md ├── COPYRIGHT ├── DSD_Author.pgp ├── README.md ├── cmake ├── FindITPP.cmake ├── FindLibPortAudio.cmake ├── FindLibSndFile.cmake ├── FindMBE.cmake ├── cmake_uninstall.cmake.in ├── git_revision.cmake └── git_revision.cmake.in ├── debian ├── changelog ├── compat ├── control ├── copyright ├── dsd.install ├── rules └── source │ ├── format │ └── options ├── include ├── Golay24.hpp ├── Hamming.hpp ├── ReedSolomon.hpp ├── config.h ├── descramble.h ├── dmr_const.h ├── dsd.h ├── dstar_const.h ├── dstar_header.h ├── fcs.h ├── git_ver.h ├── nxdn96_const.h ├── nxdn_const.h ├── p25p1_check_hdu.h ├── p25p1_check_ldu.h ├── p25p1_check_nid.h ├── p25p1_const.h ├── p25p1_hdu.h ├── p25p1_heuristics.h ├── p25p1_ldu.h ├── pa_devs.h ├── provoice_const.h └── x2tdma_const.h ├── src ├── Hamming.cpp ├── dmr_data.c ├── dmr_voice.c ├── dsd_audio.c ├── dsd_dibit.c ├── dsd_file.c ├── dsd_filters.c ├── dsd_frame.c ├── dsd_frame_sync.c ├── dsd_main.c ├── dsd_mbe.c ├── dsd_serial.c ├── dsd_symbol.c ├── dsd_upsample.c ├── dstar.c ├── dstar_header.c ├── git_ver.c.in ├── nxdn96.c ├── nxdn_data.c ├── nxdn_voice.c ├── p25_lcw.c ├── p25p1_check_hdu.cpp ├── p25p1_check_ldu.cpp ├── p25p1_check_nid.cpp ├── p25p1_hdu.c ├── p25p1_heuristics.c ├── p25p1_ldu.c ├── p25p1_ldu1.c ├── p25p1_ldu2.c ├── p25p1_tdu.c ├── p25p1_tdulc.c ├── pa_devs.c ├── provoice.c ├── x2tdma_data.c └── x2tdma_voice.c └── test ├── CMakeLists.txt ├── gmock ├── CMakeLists.txt ├── include │ └── gmock │ │ ├── gmock-actions.h │ │ ├── gmock-cardinalities.h │ │ ├── gmock-generated-actions.h │ │ ├── gmock-generated-actions.h.pump │ │ ├── gmock-generated-function-mockers.h │ │ ├── gmock-generated-function-mockers.h.pump │ │ ├── gmock-generated-matchers.h │ │ ├── gmock-generated-matchers.h.pump │ │ ├── gmock-generated-nice-strict.h │ │ ├── gmock-generated-nice-strict.h.pump │ │ ├── gmock-matchers.h │ │ ├── gmock-more-actions.h │ │ ├── gmock-more-matchers.h │ │ ├── gmock-spec-builders.h │ │ ├── gmock.h │ │ └── internal │ │ ├── gmock-generated-internal-utils.h │ │ ├── gmock-generated-internal-utils.h.pump │ │ ├── gmock-internal-utils.h │ │ └── gmock-port.h └── src │ ├── gmock-all.cc │ ├── gmock-cardinalities.cc │ ├── gmock-internal-utils.cc │ ├── gmock-matchers.cc │ ├── gmock-spec-builders.cc │ ├── gmock.cc │ └── gmock_main.cc ├── golay24-test.cpp ├── gtest ├── CMakeLists.txt ├── cmake │ └── internal_utils.cmake ├── include │ └── gtest │ │ ├── gtest-death-test.h │ │ ├── gtest-message.h │ │ ├── gtest-param-test.h │ │ ├── gtest-param-test.h.pump │ │ ├── gtest-printers.h │ │ ├── gtest-spi.h │ │ ├── gtest-test-part.h │ │ ├── gtest-typed-test.h │ │ ├── gtest.h │ │ ├── gtest_pred_impl.h │ │ ├── gtest_prod.h │ │ └── internal │ │ ├── gtest-death-test-internal.h │ │ ├── gtest-filepath.h │ │ ├── gtest-internal.h │ │ ├── gtest-linked_ptr.h │ │ ├── gtest-param-util-generated.h │ │ ├── gtest-param-util-generated.h.pump │ │ ├── gtest-param-util.h │ │ ├── gtest-port.h │ │ ├── gtest-string.h │ │ ├── gtest-tuple.h │ │ ├── gtest-tuple.h.pump │ │ ├── gtest-type-util.h │ │ └── gtest-type-util.h.pump └── src │ ├── gtest-all.cc │ ├── gtest-death-test.cc │ ├── gtest-filepath.cc │ ├── gtest-internal-inl.h │ ├── gtest-port.cc │ ├── gtest-printers.cc │ ├── gtest-test-part.cc │ ├── gtest-typed-test.cc │ ├── gtest.cc │ └── gtest_main.cc ├── hamming-test.cpp ├── reedsolomon-test.cpp └── test.cpp /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '36 11 * * 5' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'cpp' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | - name: Install dependencies 44 | run: | 45 | sudo apt-add-repository ppa:szechyjs/dsd 46 | sudo apt-get install -y libmbe-dev libsndfile1-dev libitpp-dev portaudio19-dev 47 | 48 | # Initializes the CodeQL tools for scanning. 49 | - name: Initialize CodeQL 50 | uses: github/codeql-action/init@v1 51 | with: 52 | languages: ${{ matrix.language }} 53 | # If you wish to specify custom queries, you can do so here or in a config file. 54 | # By default, queries listed here will override any specified in a config file. 55 | # Prefix the list here with "+" to use these queries and those in the config file. 56 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 57 | 58 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 59 | # If this step fails, then you should remove it and run the build manually (see below) 60 | - name: Autobuild 61 | uses: github/codeql-action/autobuild@v1 62 | 63 | # ℹ️ Command-line programs to run using the OS shell. 64 | # 📚 https://git.io/JvXDl 65 | 66 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 67 | # and modify them (or add more) to build your code if your project 68 | # uses a compiled language 69 | 70 | #- run: | 71 | # make bootstrap 72 | # make release 73 | 74 | - name: Perform CodeQL Analysis 75 | uses: github/codeql-action/analyze@v1 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dsd 2 | *.[ao] 3 | *.so* 4 | *.dylib 5 | build 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | dist: trusty 4 | sudo: false 5 | 6 | compiler: 7 | - gcc 8 | 9 | addons: 10 | apt: 11 | sources: 12 | - sourceline: 'ppa:szechyjs/dsd' 13 | packages: 14 | - libmbe-dev 15 | - libsndfile1-dev 16 | - libitpp-dev 17 | - portaudio19-dev 18 | 19 | before_script: 20 | - mkdir build 21 | - cd build 22 | - cmake .. 23 | 24 | script: 25 | - make 26 | - make test 27 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 1.7.0-dev 2 | New features: 3 | CMake build system replaces Makefile 4 | Use libsndfile for reading and writing audio files 5 | Initial DSTAR voice support 6 | 7 | 1.6.0 8 | New features: 9 | Auto mutes P25 encrypted signals by default. 10 | Raised cosine filters. 11 | 12 | Fixed bugs: 13 | Changed the crazy dibit buffer which filled for ever until it 14 | ran out of allocated memory then caused a segmentation error. The 15 | buffer is now allowed to fill to 90% before being returned to the 16 | initial pointer value where it over writes the old samples, it 17 | seems to work ok and no segmentation errors now. 18 | Input level is now calculated differently, before when it reported 50% 19 | the soundcard would be fully overloaded. With the new method aim for 30% inlvl. 20 | 21 | 1.4.1 22 | New features: 23 | Several new sync types for existing formats now recognized: 24 | Decodes voice from NXDN 4800 (6.25kHz) signals 25 | Decodes voice from NXDN 9600 (12.5kHz) repeater output 26 | Decodes voice from DMR/MotoTRBO simplex/repeater input 27 | Decodes voice from X2-TDMA simplex/repeater input 28 | 29 | Fixed bugs: 30 | renamed "input:" to "inlvl:" to reduce confusion. This value 31 | indicates the audio input level, NOT the "decode success 32 | rate". Voice decode errors are indicated by the errorbars "=". 33 | 34 | 1.4 35 | New features: 36 | Decodes voice from NXDN 9600 (12.5 kHz) simplex/repeater input 37 | NXDN96 frames enabled by default 38 | Improved resistance to NXDN96 sync false positives 39 | 40 | Fixed bugs: 41 | .wav file header updated after playing .imb/.amb data files 42 | .imb/.amb files now have correct tgid in filename 43 | 44 | 1.3.1 New features: 45 | Support for ProVoice EA sync 46 | CTRL-C is now caught so .wav files can be properly closed 47 | DSD now shows mbelib version as well as it's own version 48 | -R resume option now triggers on any TSDU so control channels can be left 49 | in conventional scanlists. 50 | Auto output gain now has 0.5 second hold time for faster error burst recovery 51 | (was 1.5 seconds) 52 | Audio output upsampling function simplified and improved 53 | 54 | Fixed bugs: 55 | DSD_Author.pgp now has correct public key (was copy of mbelib_Author key) 56 | TGID and SRC are now cleared after TDULC or TDU. 57 | Voice error counter is now reset in noCarrier() 58 | TGID and SRC were not displaying for X2-TDMA frames 59 | Fixed buffer issue in resumeScan() 60 | Fixed error in .wav file headers preventing playback on some apps 61 | 62 | 1.3 New features: 63 | Decodes voice from ProVoice signals (requires -fp option) 64 | algid and kid are now shown in hex notation 65 | 66 | Fixed bugs: 67 | auto output gain now has faster rise time 68 | MoTDMA is now correctly labeled X2-TDMA 69 | 70 | 1.2 New features: 71 | Decodes voice for DMR standard (including MOTOTRBO) 72 | Full metadata (src, talkgroup, lcinfo, mfid, lcformat, mi, algid, keyid) for X2-TDMA 73 | TDMA slot identification for X2-TDMA/DMR/MOTOTRBO 74 | Identifies non-voice frame types for X2-TDMA/DMR/MOTOTRBO 75 | Frame only (no voice yet) support for 9600 baud NXDN 76 | Auto leveling audio output gain (default) and -g option for fixed gain 77 | GFSK modulation optimizations and improved C4FM/GFSK/QPSK auto detect 78 | 79 | Fixed bugs: 80 | nac was showing wrong ID 81 | P25 metadata (lcinfo, mfid, lfcormat, mi, keyid, algid, lsd) are now 82 | printed out in the correct bit order (MSB -> LSB), was reversed. 83 | fixed serveral bugs in dsd_upsample.c, with improved quality 84 | 85 | 1.1 New features: 86 | Scanner control options to allow scan resume during certain TDULC 87 | Improved upsampling function audio quality 88 | Greatly improved handling of X2-TDMA frames 89 | Much faster QPSK decision point tracking by default 90 | 91 | Fixed bugs: 92 | playMbeFiles was not output to .wav file when -w was given 93 | Now correctly detects/handles Mot and P25 talkgroup formats 94 | PDU frames were not detected 95 | 96 | 1.0.3 Fixed buggy C4FM/QPSK auto detection and added -A option to adjust it. 97 | 98 | 1.0 Initial release 99 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(dsd) 2 | cmake_minimum_required(VERSION 2.8.11) 3 | 4 | SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") 5 | 6 | include(git_revision) 7 | git_describe(GIT_TAG) 8 | 9 | find_package(LibSndFile REQUIRED) 10 | find_package(MBE REQUIRED) 11 | find_package(ITPP REQUIRED) 12 | find_package(LibPortAudio) 13 | 14 | include_directories(SYSTEM ${LIBSNDFILE_INCLUDE_DIR} ${MBE_INCLUDE_DIR} ${ITPP_INCLUDE_DIR}) 15 | set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY}) 16 | 17 | if(PORTAUDIO_FOUND) 18 | include_directories(SYSTEM ${PORTAUDIO_INCLUDE_DIRS}) 19 | list(APPEND LIBS ${PORTAUDIO_LIBRARIES}) 20 | add_definitions(-DUSE_PORTAUDIO) 21 | endif(PORTAUDIO_FOUND) 22 | 23 | FILE(GLOB SRCS src/*.c src/*.cpp) 24 | FILE(GLOB HEADERS include/*.h include/*.hpp) 25 | 26 | configure_file("src/git_ver.c.in" "${CMAKE_CURRENT_BINARY_DIR}/git_ver.c" @ONLY) 27 | list(APPEND SRCS "${CMAKE_CURRENT_BINARY_DIR}/git_ver.c") 28 | 29 | include_directories("${PROJECT_SOURCE_DIR}/include") 30 | 31 | ADD_EXECUTABLE(dsd ${SRCS} ${HEADERS}) 32 | TARGET_LINK_LIBRARIES(dsd ${LIBS}) 33 | 34 | include(GNUInstallDirs) 35 | install(TARGETS dsd DESTINATION ${CMAKE_INSTALL_BINDIR}) 36 | 37 | # man page 38 | find_program(HELP2MAN_FOUND help2man) 39 | if (HELP2MAN_FOUND) 40 | add_custom_command(TARGET dsd POST_BUILD 41 | COMMAND help2man 42 | ARGS -n "Digital Speech Decoder" 43 | --version-string=${GIT_TAG} 44 | -o ${CMAKE_CURRENT_BINARY_DIR}/dsd.1 45 | --no-info 46 | $ 47 | ) 48 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dsd.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) 49 | endif() 50 | 51 | # uninstall target 52 | configure_file( 53 | "cmake/cmake_uninstall.cmake.in" 54 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 55 | IMMEDIATE @ONLY) 56 | 57 | add_custom_target(uninstall 58 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 59 | 60 | option(DISABLE_TEST "Disable building of test framework." OFF) 61 | 62 | if (NOT DISABLE_TEST) 63 | enable_testing() 64 | add_subdirectory(test) 65 | endif() 66 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | **Please review the appropriate guideline page before submitting an Issue or a 2 | Pull Request.** 3 | 4 | ### Issues 5 | 6 | Issues include: 7 | 8 | - Bug reports 9 | - Feature requests 10 | - Help 11 | - Build errors 12 | 13 | [Reporting Guidelines](https://github.com/szechyjs/dsd/wiki/Bug-reports) 14 | 15 | ### Code Contributions 16 | 17 | [Contributing Guidelines](https://github.com/szechyjs/dsd/wiki/Contributing) 18 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | dstar_header.c/h, descramble.h, and fcs.h are under the following license: 2 | 3 | dstar_header.c/h and fcs.h: Copyright (C) 2010 by Kristoff Bonne, ON1ARF 4 | descramble.h: Copyright (C) 2011 by Jonathan Naylor, G4KLX 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; version 2 of the License. 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | All other code is under the following license: 15 | 16 | Copyright (C) 2010 DSD Author 17 | GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 18 | 19 | Permission to use, copy, modify, and/or distribute this software for any 20 | purpose with or without fee is hereby granted, provided that the above 21 | copyright notice and this permission notice appear in all copies. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 24 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 25 | AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 26 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 27 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 28 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 29 | PERFORMANCE OF THIS SOFTWARE. 30 | -------------------------------------------------------------------------------- /DSD_Author.pgp: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v1.4.10 3 | 4 | mQENBEufuqsBCADAtWFE1qE3xqJE4xggUn6id0fVulM7y+rSH1VPxo7Ps9duc/O9 5 | VegEx8+N5KphDROS4RgHxMiS1O8Qy5Hpq4gEp6RvLNj3s+0DMwqRZoA0tBCkNmvF 6 | K7sF+GncrOu/NZkDIZ8emN9NWWeWynWJvuM2H5HQA9yCq+YTFae5sgyr3APC3xh4 7 | OkTuVMcclGTJdVrISlNBDpo/AZLJ/nV0SgITpiZVsI4RSNiQPP1kX+2fIDEAwtxN 8 | 3HIDyegDoX36cOItsb05zHkLxoUoZnWoxMvV3rwnqXg5cr6PWfiwgqWd0avl1sg6 9 | abpR6MKV68OCpTkqMrDIXJJrM2sTz+ZB2bBtABEBAAG0CkRTRCBBdXRob3KJATgE 10 | EwECACIFAkufuqsCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEPqiY10/ 11 | HX/Q11UH/0ZutGQWLZyZD5ZqVdBeYEf6IKhKhaC2vD/+5zUJ2cIgT5xJVTPCKN7X 12 | sygBANJc9GyPRYRvQecdcTHR5B+wUKCPeibv9iQuU3v7Uqb5edXEh2b4jOMWNvHJ 13 | l3lqBdUefuQdbc2xXCPgn+GkyexXEBsVF3hCzWV9r4bCpY57iWUYZZT0wAbN81hz 14 | jPKCCRmF+gZUUufxyhUGq/+eAKeUll6lgG5Ms2YKOlUMphfMav45qgWZHj1DASOV 15 | wPsiIVUaC6+GtHTTzHYRL05ydxxduX+yyKDO1emCE4fx1n3jdwToHLRrC1ui+AJM 16 | Q1s+bp+bGmMYaYaKc/JtNHcN8mbWyCK5AQ0ES5+6qwEIAJvPrnv2QO5Be3FRsnYL 17 | qbA1h/Lj0SjnuimaiNOzCYFIYtusLpyWjwWUnOEXdw5FoExqUStOHJ557SDG/zFB 18 | qy+DsNC9ncSRZ5U2tUQUtt50m2lpYvoy/sVf3oN+IsyZ5hZpiAwrxlyMC/aoGR3C 19 | 6ZlLkZ42azNCmEmoBniIxQ+XwhwkLMRsOnqLoFyXB9CcDFIXeEhZkVWZT0B5+20f 20 | yGSBDJ6VcIAASoaIyvSwU9l/DT7D/s0J8WnZQZmRdrsZ3Ikj0Sv/4D2MJnCVJTSw 21 | DHq5Sf7DmUq/WD0iWRLEXWmPt9w3WxP4imhtmIpICxCDoeQUTkqFpOTf29sVcpPt 22 | 838AEQEAAYkBHwQYAQIACQUCS5+6qwIbDAAKCRD6omNdPx1/0O8ECADAcPORjGFl 23 | RnIrsgiVMp82GQ7hnZZxktU1WVVx8EsPTT1DD79nIoeKI+UcenzuOGyTX7DGcy+P 24 | rWntUbt2ZygPTbP5Wu6zd845y9EzjxQ5q0vDF4oAefQptwqGDVeO/KBv9cZLbnih 25 | VEjQELgC/rVB7nd5p83EL5vb8qL/Eiu65stxwZ3QOT9pp2bsAPk6LJWWnVqJroKI 26 | Pc6KWG7n6mMJPbhFmE8Ld2lcNlSKQwLHIxDocL2GAqh5S5hJeGg2oLMFpy0g2Ron 27 | 643w0zPfpKC15TlnkJDCIgtRlHovrs42Qkypz9y3e8yOL9O0RLYIKbuKw4mNR3cT 28 | OdeV+TjfiZ5I 29 | =2oe6 30 | -----END PGP PUBLIC KEY BLOCK----- 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/szechyjs/dsd.svg?branch=master)](https://travis-ci.org/szechyjs/dsd) 2 | 3 | # Digital Speech Decoder 1.7.0-dev 4 | DSD is able to decode [several digital voice formats](https://github.com/szechyjs/dsd/wiki/Supported-formats) from discriminator 5 | tap audio and synthesize the decoded speech. Speech 6 | synthesis requires mbelib, which is a separate package. 7 | 8 | 9 | ## Information 10 | 11 | ### The DSD Wiki 12 | The DSD Wiki has lots of additional information about DSD including build 13 | instructions and answers to the most frequently asked questions. 14 | Please browse the Wiki after finishing this README. 15 | 16 | [https://github.com/szechyjs/dsd/wiki](https://github.com/szechyjs/dsd/wiki) 17 | 18 | ### Bug reports 19 | If you discover a problem with DSD, we would like to know about it. 20 | However, we ask that you please review these guidelines before submitting a 21 | bug report: 22 | 23 | [https://github.com/szechyjs/dsd/wiki/Bug-reports](https://github.com/szechyjs/dsd/wiki/Bug-reports) 24 | 25 | Please don't contact developers directly through email or other channels. 26 | We ask that you follow the guidelines above and use the 27 | [Issue Tracker](http://github.com/szechyjs/dsd/issues). 28 | 29 | ### Contributing 30 | We hope that you will consider contributing to DSD. Please read this short 31 | overview for some information about how to get started. 32 | 33 | [https://github.com/szechyjs/dsd/wiki/Contributing](https://github.com/szechyjs/dsd/wiki/Contributing) 34 | 35 | You will usually want to write tests for your changes. To run the test suite 36 | run `make test` from your build directory. 37 | 38 | ## License 39 | Copyright (C) 2010 DSD Author 40 | GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 41 | 42 | Permission to use, copy, modify, and/or distribute this software for any 43 | purpose with or without fee is hereby granted, provided that the above 44 | copyright notice and this permission notice appear in all copies. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 47 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 48 | AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 49 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 50 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 51 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 52 | PERFORMANCE OF THIS SOFTWARE. 53 | -------------------------------------------------------------------------------- /cmake/FindITPP.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find ITPP 2 | # Once done this will define 3 | # 4 | # ITPP_FOUND - System has ITPP 5 | # ITPP_INCLUDE_DIR - The ITPP include directory 6 | # ITPP_LIBRARY - The library needed to use ITPP 7 | # 8 | 9 | find_path(ITPP_INCLUDE_DIR itpp/itcomm.h) 10 | 11 | set(ITPP_NAMES ${ITPP_NAMES} itpp libitpp libitpp.dll) 12 | FIND_LIBRARY(ITPP_LIBRARY NAMES ${ITPP_NAMES}) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args(ITPP DEFAULT_MSG ITPP_LIBRARY ITPP_INCLUDE_DIR) -------------------------------------------------------------------------------- /cmake/FindLibPortAudio.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Portaudio 2 | # Once done this will define 3 | # 4 | # PORTAUDIO_FOUND - system has Portaudio 5 | # PORTAUDIO_INCLUDE_DIRS - the Portaudio include directory 6 | # PORTAUDIO_LIBRARIES - Link these to use Portaudio 7 | # PORTAUDIO_DEFINITIONS - Compiler switches required for using Portaudio 8 | # PORTAUDIO_VERSION - Portaudio version 9 | # 10 | # Copyright (c) 2006 Andreas Schneider 11 | # 12 | # Redistribution and use is allowed according to the terms of the New BSD license. 13 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 14 | # 15 | 16 | 17 | if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) 18 | # in cache already 19 | set(PORTAUDIO_FOUND TRUE) 20 | else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) 21 | if (NOT WIN32) 22 | include(FindPkgConfig) 23 | pkg_check_modules(PORTAUDIO2 portaudio-2.0) 24 | endif (NOT WIN32) 25 | 26 | find_path (PORTAUDIO_INCLUDE_DIRS 27 | NAMES 28 | portaudio.h 29 | PATHS 30 | ${PORTAUDIO2_INCLUDEDIR} 31 | /usr/include 32 | /usr/local/include 33 | /opt/local/include 34 | /sw/include 35 | ) 36 | if (NOT PORTAUDIO_INCLUDE_DIRS) 37 | set (PORTAUDIO_INCLUDE_DIRS 38 | ${PORTAUDIO2_INCLUDE_DIRS} 39 | ) 40 | list (APPEND PORTAUDIO_INCLUDE_DIRS ${PORTAUDIO2_INCLUDEDIR}) 41 | endif (NOT PORTAUDIO_INCLUDE_DIRS) 42 | 43 | find_library (PORTAUDIO_LIBRARIES 44 | NAMES 45 | portaudio 46 | PATHS 47 | ${PORTAUDIO2_LIBDIR} 48 | /usr/lib 49 | /usr/local/lib 50 | /opt/local/lib 51 | /sw/lib 52 | ) 53 | if (NOT PORTAUDIO_LIBRARIES) 54 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 55 | set(PORTAUDIO_LIBRARIES "${PORTAUDIO2_LIBDIR}/lib${PORTAUDIO2_LIBRARIES}.dylib") 56 | else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 57 | set(PORTAUDIO_LIBRARIES 58 | ${PORTAUDIO2_LIBRARIES} 59 | ) 60 | endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 61 | endif (NOT PORTAUDIO_LIBRARIES) 62 | 63 | if (PORTAUDIO2_VERSION) 64 | set(PORTAUDIO_VERSION 65 | ${PORTAUDIO2_VERSION} 66 | ) 67 | else (PORTAUDIO2_VERSION) 68 | set(PORTAUDIO_VERSION 69 | 18 70 | ) 71 | endif (PORTAUDIO2_VERSION) 72 | 73 | if (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) 74 | set(PORTAUDIO_FOUND TRUE) 75 | endif (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) 76 | 77 | if (PORTAUDIO_FOUND) 78 | if (NOT Portaudio_FIND_QUIETLY) 79 | message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}") 80 | endif (NOT Portaudio_FIND_QUIETLY) 81 | else (PORTAUDIO_FOUND) 82 | if (Portaudio_FIND_REQUIRED) 83 | message(FATAL_ERROR "Could not find Portaudio") 84 | endif (Portaudio_FIND_REQUIRED) 85 | endif (PORTAUDIO_FOUND) 86 | 87 | # show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view 88 | mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES) 89 | 90 | endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) 91 | -------------------------------------------------------------------------------- /cmake/FindLibSndFile.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Libsndfile 2 | # Once done this will define 3 | # 4 | # LIBSNDFILE_FOUND - System has LIBSNDFILE 5 | # LIBSNDFILE_INCLUDE_DIR - The SNDFILE include directory 6 | # LIBSNDFILE_LIBRARY - The library needed to use SNDFILE 7 | # 8 | 9 | find_path(LIBSNDFILE_INCLUDE_DIR sndfile.h) 10 | 11 | SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile) 12 | FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES}) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args(LIBSNDFILE DEFAULT_MSG LIBSNDFILE_LIBRARY 16 | LIBSNDFILE_INCLUDE_DIR) -------------------------------------------------------------------------------- /cmake/FindMBE.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find MBE 2 | # Once done this will define 3 | # 4 | # MBE_FOUND - System has MBE 5 | # MBE_INCLUDE_DIR - The MBE include directory 6 | # MBE_LIBRARY - The library needed to use MBE 7 | # 8 | 9 | find_path(MBE_INCLUDE_DIR mbelib.h) 10 | 11 | set(MBE_NAMES ${MBE_NAMES} mbe libmbe) 12 | find_library(MBE_LIBRARY NAMES ${MBE_NAMES}) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | find_package_handle_standard_args(MBE DEFAULT_MSG MBE_LIBRARY MBE_INCLUDE_DIR) 16 | -------------------------------------------------------------------------------- /cmake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | cmake_policy(SET CMP0007 OLD) 8 | list(REVERSE files) 9 | foreach (file ${files}) 10 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | if (EXISTS "$ENV{DESTDIR}${file}") 12 | execute_process( 13 | COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" 14 | OUTPUT_VARIABLE rm_out 15 | RESULT_VARIABLE rm_retval 16 | ) 17 | if(NOT ${rm_retval} EQUAL 0) 18 | message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 19 | endif (NOT ${rm_retval} EQUAL 0) 20 | else (EXISTS "$ENV{DESTDIR}${file}") 21 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 22 | endif (EXISTS "$ENV{DESTDIR}${file}") 23 | endforeach(file) -------------------------------------------------------------------------------- /cmake/git_revision.cmake: -------------------------------------------------------------------------------- 1 | # - Returns a version string from Git 2 | # 3 | # These functions force a re-configure on each git commit so that you can 4 | # trust the values of the variables in your build system. 5 | # 6 | # get_git_head_revision( [ ...]) 7 | # 8 | # Returns the refspec and sha hash of the current head revision 9 | # 10 | # git_describe( [ ...]) 11 | # 12 | # Returns the results of git describe on the source tree, and adjusting 13 | # the output so that it tests false if an error occurs. 14 | # 15 | # git_get_exact_tag( [ ...]) 16 | # 17 | # Returns the results of git describe --exact-match on the source tree, 18 | # and adjusting the output so that it tests false if there was no exact 19 | # matching tag. 20 | # 21 | # Requires CMake 2.6 or newer (uses the 'function' command) 22 | # 23 | # Original Author: 24 | # 2009-2010 Ryan Pavlik 25 | # http://academic.cleardefinition.com 26 | # Iowa State University HCI Graduate Program/VRAC 27 | # 28 | # Copyright Iowa State University 2009-2010. 29 | # Distributed under the Boost Software License, Version 1.0. 30 | # (See accompanying file LICENSE_1_0.txt or copy at 31 | # http://www.boost.org/LICENSE_1_0.txt) 32 | 33 | if(__get_git_revision_description) 34 | return() 35 | endif() 36 | set(__get_git_revision_description YES) 37 | 38 | # We must run the following at "include" time, not at function call time, 39 | # to find the path to this module rather than the path to a calling list file 40 | get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) 41 | 42 | function(get_git_head_revision _refspecvar _hashvar) 43 | set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 44 | set(GIT_DIR "${GIT_PARENT_DIR}/.git") 45 | while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories 46 | set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") 47 | get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) 48 | if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) 49 | # We have reached the root directory, we are not in git 50 | set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 51 | set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 52 | return() 53 | endif() 54 | set(GIT_DIR "${GIT_PARENT_DIR}/.git") 55 | endwhile() 56 | # check if this is a submodule 57 | if(NOT IS_DIRECTORY ${GIT_DIR}) 58 | file(READ ${GIT_DIR} submodule) 59 | string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) 60 | get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) 61 | get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) 62 | endif() 63 | set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") 64 | if(NOT EXISTS "${GIT_DATA}") 65 | file(MAKE_DIRECTORY "${GIT_DATA}") 66 | endif() 67 | 68 | if(NOT EXISTS "${GIT_DIR}/HEAD") 69 | return() 70 | endif() 71 | set(HEAD_FILE "${GIT_DATA}/HEAD") 72 | configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) 73 | 74 | configure_file("cmake/git_revision.cmake.in" 75 | "${GIT_DATA}/grabRef.cmake" 76 | @ONLY) 77 | include("${GIT_DATA}/grabRef.cmake") 78 | 79 | set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) 80 | set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) 81 | endfunction() 82 | 83 | function(git_describe _var) 84 | if(NOT GIT_FOUND) 85 | find_package(Git QUIET) 86 | endif() 87 | get_git_head_revision(refspec hash) 88 | if(NOT GIT_FOUND) 89 | set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) 90 | return() 91 | endif() 92 | if(NOT hash) 93 | set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) 94 | return() 95 | endif() 96 | 97 | # TODO sanitize 98 | #if((${ARGN}" MATCHES "&&") OR 99 | # (ARGN MATCHES "||") OR 100 | # (ARGN MATCHES "\\;")) 101 | # message("Please report the following error to the project!") 102 | # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") 103 | #endif() 104 | 105 | #message(STATUS "Arguments to execute_process: ${ARGN}") 106 | 107 | execute_process(COMMAND 108 | "${GIT_EXECUTABLE}" 109 | describe 110 | ${hash} 111 | ${ARGN} 112 | WORKING_DIRECTORY 113 | "${CMAKE_SOURCE_DIR}" 114 | RESULT_VARIABLE 115 | res 116 | OUTPUT_VARIABLE 117 | out 118 | ERROR_QUIET 119 | OUTPUT_STRIP_TRAILING_WHITESPACE) 120 | if(NOT res EQUAL 0) 121 | set(out "${out}-${res}-NOTFOUND") 122 | endif() 123 | 124 | set(${_var} "${out}" PARENT_SCOPE) 125 | endfunction() 126 | 127 | function(git_get_exact_tag _var) 128 | git_describe(out --exact-match ${ARGN}) 129 | set(${_var} "${out}" PARENT_SCOPE) 130 | endfunction() 131 | -------------------------------------------------------------------------------- /cmake/git_revision.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Internal file for GetGitRevisionDescription.cmake 3 | # 4 | # Requires CMake 2.6 or newer (uses the 'function' command) 5 | # 6 | # Original Author: 7 | # 2009-2010 Ryan Pavlik 8 | # http://academic.cleardefinition.com 9 | # Iowa State University HCI Graduate Program/VRAC 10 | # 11 | # Copyright Iowa State University 2009-2010. 12 | # Distributed under the Boost Software License, Version 1.0. 13 | # (See accompanying file LICENSE_1_0.txt or copy at 14 | # http://www.boost.org/LICENSE_1_0.txt) 15 | 16 | set(HEAD_HASH) 17 | 18 | file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) 19 | 20 | string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) 21 | if(HEAD_CONTENTS MATCHES "ref") 22 | # named branch 23 | string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") 24 | if(EXISTS "@GIT_DIR@/${HEAD_REF}") 25 | configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 26 | elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") 27 | configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 28 | set(HEAD_HASH "${HEAD_REF}") 29 | endif() 30 | else() 31 | # detached HEAD 32 | configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) 33 | endif() 34 | 35 | if(NOT HEAD_HASH) 36 | file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) 37 | string(STRIP "${HEAD_HASH}" HEAD_HASH) 38 | endif() 39 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | dsd (1.7.0~1) bionic; urgency=medium 2 | 3 | ** SNAPSHOT build ** 4 | 5 | * Initial upload! 6 | 7 | -- Jared Szechy Thu, 28 Jun 2018 23:00:00 -0400 8 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: dsd 2 | Section: hamradio 3 | Priority: optional 4 | Maintainer: Jared Szechy 5 | Build-Depends: debhelper (>= 9), libmbe-dev, libitpp-dev, libsndfile1-dev, 6 | portaudio19-dev, cmake, git, help2man 7 | Standards-Version: 4.1.4 8 | Homepage: https://github.com/szechyjs/dsd 9 | Vcs-Git: https://github.com/szechyjs/dsd.git 10 | Vcs-Browser: https://github.com/szechyjs/dsd 11 | 12 | Package: dsd 13 | Section: hamradio 14 | Architecture: any 15 | Multi-Arch: foreign 16 | Pre-Depends: ${misc:Pre-Depends} 17 | Depends: ${shlibs:Depends}, ${misc:Depends} 18 | Description: Digital Speech Decoder 19 | DSD is able to decode several digital voice formats from discriminator tap 20 | audio and synthesize the decoded speech. -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: DSD 3 | Upstream-Contact: Jared Szechy 4 | Source: https://github.com/szechyjs/dsd 5 | 6 | Files: * 7 | Copyright: Copyright (C) 2010 DSD Author 8 | License: ISC 9 | 10 | Files: debian/* cmake/* CMakeLists.txt 11 | Copyright: Copyright (C) 2018 Jared Szechy, K8JSS 12 | License: ISC 13 | 14 | Files: cmake/git_revision.cmake* 15 | Copyright: 2009-2010 Ryan Pavlik 16 | Iowa State University 2009-2010 17 | License: BSL-1.0 18 | 19 | Files: src/dstar_header.c include/dstar_header.h include/fcs.h 20 | Copyright: Copyright (C) 2010 by Kristoff Bonne, ON1ARF 21 | License: GPL-2 22 | 23 | Files: include/descramble.h 24 | Copyright: Copyright (C) 2011 by Jonathan Naylor, G4KLX 25 | License: GPL-2 26 | 27 | Files: test/gtest/* test/gmock/* 28 | Copyright: Copyright 2008, Google Inc. 29 | License: BSD-3-Clause 30 | 31 | License: GPL-2 32 | This program is free software; you can redistribute it and/or modify 33 | it under the terms of the GNU General Public License as published by 34 | the Free Software Foundation; version 2 of the License. 35 | . 36 | This program is distributed in the hope that it will be useful, 37 | but WITHOUT ANY WARRANTY; without even the implied warranty of 38 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 39 | GNU General Public License for more details. 40 | . 41 | On Debian systems, the complete text of the GNU General 42 | Public License can be found in `/usr/share/common-licenses/GPL-2'. 43 | 44 | License: ISC 45 | Permission to use, copy, modify, and/or distribute this software for any 46 | purpose with or without fee is hereby granted, provided that the above 47 | copyright notice and this permission notice appear in all copies. 48 | . 49 | THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 50 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 51 | AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 52 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 53 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 54 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 55 | PERFORMANCE OF THIS SOFTWARE. 56 | 57 | License: BSD-3-Clause 58 | Redistribution and use in source and binary forms, with or without 59 | modification, are permitted provided that the following conditions are met: 60 | . 61 | * Redistributions of source code must retain the above copyright notice, this 62 | list of conditions and the following disclaimer. 63 | . 64 | * Redistributions in binary form must reproduce the above copyright notice, 65 | this list of conditions and the following disclaimer in the documentation 66 | and/or other materials provided with the distribution. 67 | . 68 | * Neither the name of the copyright holder nor the names of its 69 | contributors may be used to endorse or promote products derived from 70 | this software without specific prior written permission. 71 | . 72 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 73 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 74 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 75 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 76 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 77 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 78 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 79 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 80 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 81 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 | 83 | License: BSL-1.0 84 | Boost Software License - Version 1.0 - August 17th, 2003 85 | . 86 | Permission is hereby granted, free of charge, to any person or organization 87 | obtaining a copy of the software and accompanying documentation covered by 88 | this license (the "Software") to use, reproduce, display, distribute, 89 | execute, and transmit the Software, and to prepare derivative works of the 90 | Software, and to permit third-parties to whom the Software is furnished to 91 | do so, all subject to the following: 92 | . 93 | The copyright notices in the Software and this entire statement, including 94 | the above license grant, this restriction and the following disclaimer, 95 | must be included in all copies of the Software, in whole or in part, and 96 | all derivative works of the Software, unless such copies or derivative 97 | works are solely in the form of machine-executable object code generated by 98 | a source language processor. 99 | . 100 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 101 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 102 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 103 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 104 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 105 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 106 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /debian/dsd.install: -------------------------------------------------------------------------------- 1 | usr/bin/* 2 | usr/share/man/man1/* -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ 5 | 6 | # debhelper defaults to running make install DESTDIR=debian/$(PACKAGE) 7 | # when the source package builds only one binary package. 8 | override_dh_auto_install: 9 | dh_auto_install --destdir=$(CURDIR)/debian/tmp -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) -------------------------------------------------------------------------------- /debian/source/options: -------------------------------------------------------------------------------- 1 | tar-ignore = .gitignore -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * System target 20 | */ 21 | #define BSD // bsd/linux audio interface 22 | //#define SOLARIS // solaris audio interface, untested 23 | 24 | /* 25 | * noisy debug/development options 26 | */ 27 | //#define X2TDMA_DUMP // cach and sync bits dump 28 | //#define DMR_DUMP 29 | //#define DSTAR_DUMP // dstar frame dump 30 | //#define NXDN_DUMP 31 | //#define UPSAMPLE_DEBUG 32 | //#define PROVOICE_DUMP 33 | -------------------------------------------------------------------------------- /include/dmr_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MAIN 19 | extern const int rW[36]; 20 | extern const int rX[36]; 21 | extern const int rY[36]; 22 | extern const int rZ[36]; 23 | 24 | #else 25 | /* 26 | * DMR AMBE interleave schedule 27 | */ 28 | const int rW[36] = { 29 | 0, 1, 0, 1, 0, 1, 30 | 0, 1, 0, 1, 0, 1, 31 | 0, 1, 0, 1, 0, 1, 32 | 0, 1, 0, 1, 0, 2, 33 | 0, 2, 0, 2, 0, 2, 34 | 0, 2, 0, 2, 0, 2 35 | }; 36 | 37 | const int rX[36] = { 38 | 23, 10, 22, 9, 21, 8, 39 | 20, 7, 19, 6, 18, 5, 40 | 17, 4, 16, 3, 15, 2, 41 | 14, 1, 13, 0, 12, 10, 42 | 11, 9, 10, 8, 9, 7, 43 | 8, 6, 7, 5, 6, 4 44 | }; 45 | 46 | const int rY[36] = { 47 | 0, 2, 0, 2, 0, 2, 48 | 0, 2, 0, 3, 0, 3, 49 | 1, 3, 1, 3, 1, 3, 50 | 1, 3, 1, 3, 1, 3, 51 | 1, 3, 1, 3, 1, 3, 52 | 1, 3, 1, 3, 1, 3 53 | }; 54 | 55 | const int rZ[36] = { 56 | 5, 3, 4, 2, 3, 1, 57 | 2, 0, 1, 13, 0, 12, 58 | 22, 11, 21, 10, 20, 9, 59 | 19, 8, 18, 7, 17, 6, 60 | 16, 5, 15, 4, 14, 3, 61 | 13, 2, 12, 1, 11, 0 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/dstar_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * dstar interleave experiments 20 | */ 21 | 22 | #ifndef _MAIN 23 | 24 | extern const int dW[72]; 25 | extern const int dX[72]; 26 | 27 | #else 28 | const int dW[72] = { 29 | 30 | // 0-11 31 | 0, 0, 32 | 3, 2, 33 | 1, 1, 34 | 0, 0, 35 | 1, 1, 36 | 0, 0, 37 | 38 | // 12-23 39 | 3, 2, 40 | 1, 1, 41 | 3, 2, 42 | 1, 1, 43 | 0, 0, 44 | 3, 2, 45 | 46 | // 24-35 47 | 0, 0, 48 | 3, 2, 49 | 1, 1, 50 | 0, 0, 51 | 1, 1, 52 | 0, 0, 53 | 54 | // 36-47 55 | 3, 2, 56 | 1, 1, 57 | 3, 2, 58 | 1, 1, 59 | 0, 0, 60 | 3, 2, 61 | 62 | // 48-59 63 | 0, 0, 64 | 3, 2, 65 | 1, 1, 66 | 0, 0, 67 | 1, 1, 68 | 0, 0, 69 | 70 | // 60-71 71 | 3, 2, 72 | 1, 1, 73 | 3, 3, 74 | 2, 1, 75 | 0, 0, 76 | 3, 3, 77 | }; 78 | const int dX[72] = { 79 | 80 | // 0-11 81 | 10, 22, 82 | 11, 9, 83 | 10, 22, 84 | 11, 23, 85 | 8, 20, 86 | 9, 21, 87 | 88 | // 12-23 89 | 10, 8, 90 | 9, 21, 91 | 8, 6, 92 | 7, 19, 93 | 8, 20, 94 | 9, 7, 95 | 96 | // 24-35 97 | 6, 18, 98 | 7, 5, 99 | 6, 18, 100 | 7, 19, 101 | 4, 16, 102 | 5, 17, 103 | 104 | // 36-47 105 | 6, 4, 106 | 5, 17, 107 | 4, 2, 108 | 3, 15, 109 | 4, 16, 110 | 5, 3, 111 | 112 | // 48-59 113 | 2, 14, 114 | 3, 1, 115 | 2, 14, 116 | 3, 15, 117 | 0, 12, 118 | 1, 13, 119 | 120 | // 60-71 121 | 2, 0, 122 | 1, 13, 123 | 0, 12, 124 | 10, 11, 125 | 0, 12, 126 | 1, 13, 127 | }; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /include/dstar_header.h: -------------------------------------------------------------------------------- 1 | /* This is the header file for dstar_header.c, which is under the GPL. */ 2 | 3 | #ifndef _DSTAR_HEADER_H 4 | #define _DSTAR_HEADER_H 5 | void dstar_header_decode(int radioheaderbuffer[660]); 6 | #endif /* _DSTAR_HEADER_H */ -------------------------------------------------------------------------------- /include/fcs.h: -------------------------------------------------------------------------------- 1 | /* fcs.h */ 2 | 3 | // Viterbi decoder using Traceback method. 4 | 5 | // Original Source was written by Sho Tamaoki and Tom Wada 6 | // See http://www.lsi.ie.u-ryukyu.ac.jp/~sho/midterm/ 7 | // Modified by Satoshi Yasuda 7m3tjz/ad6gz 8 | // Modified by Jonathan Nayor, G4KLX (C) 2009 9 | 10 | // Converted from C++ to C by Kristoff Bonne, ON1ARF 11 | 12 | /* 13 | * Copyright (C) 2010 by Kristoff Bonne, ON1ARF 14 | * 15 | * This program is free software; you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation; version 2 of the License. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | */ 24 | 25 | #include 26 | 27 | static const unsigned short ccittTab[] = { 28 | 0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf, 29 | 0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7, 30 | 0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e, 31 | 0x9cc9,0x8d40,0xbfdb,0xae52,0xdaed,0xcb64,0xf9ff,0xe876, 32 | 0x2102,0x308b,0x0210,0x1399,0x6726,0x76af,0x4434,0x55bd, 33 | 0xad4a,0xbcc3,0x8e58,0x9fd1,0xeb6e,0xfae7,0xc87c,0xd9f5, 34 | 0x3183,0x200a,0x1291,0x0318,0x77a7,0x662e,0x54b5,0x453c, 35 | 0xbdcb,0xac42,0x9ed9,0x8f50,0xfbef,0xea66,0xd8fd,0xc974, 36 | 0x4204,0x538d,0x6116,0x709f,0x0420,0x15a9,0x2732,0x36bb, 37 | 0xce4c,0xdfc5,0xed5e,0xfcd7,0x8868,0x99e1,0xab7a,0xbaf3, 38 | 0x5285,0x430c,0x7197,0x601e,0x14a1,0x0528,0x37b3,0x263a, 39 | 0xdecd,0xcf44,0xfddf,0xec56,0x98e9,0x8960,0xbbfb,0xaa72, 40 | 0x6306,0x728f,0x4014,0x519d,0x2522,0x34ab,0x0630,0x17b9, 41 | 0xef4e,0xfec7,0xcc5c,0xddd5,0xa96a,0xb8e3,0x8a78,0x9bf1, 42 | 0x7387,0x620e,0x5095,0x411c,0x35a3,0x242a,0x16b1,0x0738, 43 | 0xffcf,0xee46,0xdcdd,0xcd54,0xb9eb,0xa862,0x9af9,0x8b70, 44 | 0x8408,0x9581,0xa71a,0xb693,0xc22c,0xd3a5,0xe13e,0xf0b7, 45 | 0x0840,0x19c9,0x2b52,0x3adb,0x4e64,0x5fed,0x6d76,0x7cff, 46 | 0x9489,0x8500,0xb79b,0xa612,0xd2ad,0xc324,0xf1bf,0xe036, 47 | 0x18c1,0x0948,0x3bd3,0x2a5a,0x5ee5,0x4f6c,0x7df7,0x6c7e, 48 | 0xa50a,0xb483,0x8618,0x9791,0xe32e,0xf2a7,0xc03c,0xd1b5, 49 | 0x2942,0x38cb,0x0a50,0x1bd9,0x6f66,0x7eef,0x4c74,0x5dfd, 50 | 0xb58b,0xa402,0x9699,0x8710,0xf3af,0xe226,0xd0bd,0xc134, 51 | 0x39c3,0x284a,0x1ad1,0x0b58,0x7fe7,0x6e6e,0x5cf5,0x4d7c, 52 | 0xc60c,0xd785,0xe51e,0xf497,0x8028,0x91a1,0xa33a,0xb2b3, 53 | 0x4a44,0x5bcd,0x6956,0x78df,0x0c60,0x1de9,0x2f72,0x3efb, 54 | 0xd68d,0xc704,0xf59f,0xe416,0x90a9,0x8120,0xb3bb,0xa232, 55 | 0x5ac5,0x4b4c,0x79d7,0x685e,0x1ce1,0x0d68,0x3ff3,0x2e7a, 56 | 0xe70e,0xf687,0xc41c,0xd595,0xa12a,0xb0a3,0x8238,0x93b1, 57 | 0x6b46,0x7acf,0x4854,0x59dd,0x2d62,0x3ceb,0x0e70,0x1ff9, 58 | 0xf78f,0xe606,0xd49d,0xc514,0xb1ab,0xa022,0x92b9,0x8330, 59 | 0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78}; 60 | 61 | 62 | uint16_t calc_fcs (unsigned char * dvstartframe, int size) { 63 | // this function calculated the CRC-values of a DSTAR digital 64 | // voice frame. It calculates this value on octets 0 up to 38 of the D-STAR 65 | // radio header (fields flag1, flag2, flag3, destination, departure, companion, 66 | // own1 and own2) 67 | uint16_t m_crc; 68 | int loop; 69 | unsigned short tmp; 70 | 71 | m_crc=0xFFFF; 72 | 73 | for (loop=0; loop < size; loop++) { 74 | tmp = (m_crc & 0x00ff) ^ dvstartframe[loop]; 75 | 76 | m_crc = (m_crc >> 8) ^ ccittTab[tmp]; 77 | 78 | }; // end for 79 | 80 | // calculate and save crc-value in fields 54 and 55 of dvframe 81 | m_crc = ~m_crc; 82 | 83 | tmp = m_crc; 84 | m_crc = (m_crc << 8) | (tmp >> 8 & 0xFF); 85 | 86 | 87 | // done 88 | return(m_crc); 89 | }; // end function 90 | -------------------------------------------------------------------------------- /include/git_ver.h: -------------------------------------------------------------------------------- 1 | extern const char GIT_TAG[]; 2 | -------------------------------------------------------------------------------- /include/nxdn96_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * NXDN AMBE interleave schedule 20 | */ 21 | 22 | #ifndef _MAIN 23 | extern const int nW[36]; 24 | extern const int nX[36]; 25 | extern const int nY[36]; 26 | extern const int nZ[36]; 27 | 28 | #else 29 | 30 | const int nW[36] = { 0, 1, 0, 1, 0, 1, 31 | 0, 1, 0, 1, 0, 1, 32 | 0, 1, 0, 1, 0, 1, 33 | 0, 1, 0, 1, 0, 2, 34 | 0, 2, 0, 2, 0, 2, 35 | 0, 2, 0, 2, 0, 2 36 | }; 37 | 38 | const int nX[36] = { 23, 10, 22, 9, 21, 8, 39 | 20, 7, 19, 6, 18, 5, 40 | 17, 4, 16, 3, 15, 2, 41 | 14, 1, 13, 0, 12, 10, 42 | 11, 9, 10, 8, 9, 7, 43 | 8, 6, 7, 5, 6, 4 44 | }; 45 | 46 | const int nY[36] = { 0, 2, 0, 2, 0, 2, 47 | 0, 2, 0, 3, 0, 3, 48 | 1, 3, 1, 3, 1, 3, 49 | 1, 3, 1, 3, 1, 3, 50 | 1, 3, 1, 3, 1, 3, 51 | 1, 3, 1, 3, 1, 3 52 | }; 53 | 54 | const int nZ[36] = { 5, 3, 4, 2, 3, 1, 55 | 2, 0, 1, 13, 0, 12, 56 | 22, 11, 21, 10, 20, 9, 57 | 19, 8, 18, 7, 17, 6, 58 | 16, 5, 15, 4, 14, 3, 59 | 13, 2, 12, 1, 11, 0 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/nxdn_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MAIN 19 | extern const int nW[36]; 20 | extern const int nX[36]; 21 | extern const int nY[36]; 22 | extern const int nZ[36]; 23 | extern const char nxdnpr[145]; 24 | 25 | #else 26 | /* 27 | * pseudorandom bit sequence 28 | */ 29 | const char nxdnpr[145] = { 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1 }; 30 | 31 | /* 32 | * NXDN AMBE interleave schedule 33 | */ 34 | const int nW[36] = { 0, 1, 0, 1, 0, 1, 35 | 0, 1, 0, 1, 0, 1, 36 | 0, 1, 0, 1, 0, 1, 37 | 0, 1, 0, 1, 0, 2, 38 | 0, 2, 0, 2, 0, 2, 39 | 0, 2, 0, 2, 0, 2 40 | }; 41 | 42 | const int nX[36] = { 23, 10, 22, 9, 21, 8, 43 | 20, 7, 19, 6, 18, 5, 44 | 17, 4, 16, 3, 15, 2, 45 | 14, 1, 13, 0, 12, 10, 46 | 11, 9, 10, 8, 9, 7, 47 | 8, 6, 7, 5, 6, 4 48 | }; 49 | 50 | const int nY[36] = { 0, 2, 0, 2, 0, 2, 51 | 0, 2, 0, 3, 0, 3, 52 | 1, 3, 1, 3, 1, 3, 53 | 1, 3, 1, 3, 1, 3, 54 | 1, 3, 1, 3, 1, 3, 55 | 1, 3, 1, 3, 1, 3 56 | }; 57 | 58 | const int nZ[36] = { 5, 3, 4, 2, 3, 1, 59 | 2, 0, 1, 13, 0, 12, 60 | 22, 11, 21, 10, 20, 9, 61 | 19, 8, 18, 7, 17, 6, 62 | 16, 5, 15, 4, 14, 3, 63 | 13, 2, 12, 1, 11, 0 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/p25p1_check_hdu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef P25P1_CHECK_HDU_H_f5f079faf2d64cf5831e1da1ab83b9ba 3 | #define P25P1_CHECK_HDU_H_f5f079faf2d64cf5831e1da1ab83b9ba 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /** 10 | * Attempts to correct an hex (6-bit) word using the Golay(24,12,8) FEC. 11 | * \param hex The 6-bit word to error correct, given as a char array of 6 elements, one bit each. 12 | * \param parity A 12-bit word with the Golay parity data, given as a char array of 12 elements. 13 | * \param fixed_error Output. Filled with the number of errors fixed in the input. 14 | * \return 1 if there were uncorrectable errors in the input, 0 otherwise. 15 | */ 16 | int check_and_fix_golay_24_6(char* hex, char* parity, int* fixed_errors); 17 | 18 | /** 19 | * Attempts to correct a 12-bit word using the Golay(24,12,8) FEC. 20 | * \param dodeca The 12-bit word to error correct, given as a char array of 12 elements, one bit each. 21 | * \param parity A 12-bit word with the Golay parity data, given as a char array of 12 elements. 22 | * \param fixed_error Output. Filled with the number of errors fixed in the input. 23 | * \return 1 if there were uncorrectable errors in the input, 0 otherwise. 24 | */ 25 | int check_and_fix_golay_24_12(char* dodeca, char* parity, int* fixed_errors); 26 | 27 | /** 28 | * Encodes an hex word using the Golay(24,12,8) FEC. 29 | * \param hex A 6-bit word to encode. 30 | * \param out_parity The address to be filled with the calculated Golay parity. 31 | */ 32 | void encode_golay_24_6(char* hex, char* out_parity); 33 | 34 | /** 35 | * Encodes an 12-bitword using the Golay(24,12,8) FEC. 36 | * \param dodeca A 12-bit word to encode. 37 | * \param out_parity The address to be filled with the calculated Golay parity. 38 | */ 39 | void encode_golay_24_12(char* dodeca, char* out_parity); 40 | 41 | /** 42 | * Attempts to correct 20 hex words using the Reed-Solomon(36,20,17) FEC. 43 | * \param data The packed hex words, each of 6 chars, one after the other. 44 | * \param parity The corresponding 16 hex words with the parity information. 45 | * \return 1 if irrecoverable errors have been detected, 0 otherwise. 46 | */ 47 | int check_and_fix_redsolomon_36_20_17(char* data, char* parity); 48 | 49 | /** 50 | * Calculates the Reed-Solomon parity of 20 words of 6 bits each. 51 | * \param hex_data The address with the words whose parity we want to calculate. 52 | * \param fixed_parity The address to be filled with the calculated parity. 16 words of 6 bits are produced. 53 | */ 54 | void encode_reedsolomon_36_20_17(char* hex_data, char* fixed_parity); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif // P25P1_CHECK_HDU_H_f5f079faf2d64cf5831e1da1ab83b9ba 61 | -------------------------------------------------------------------------------- /include/p25p1_check_ldu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef P25P1_CHECK_LDU_H_c1734445a67e47caa25673d7a4ce7520 3 | #define P25P1_CHECK_LDU_H_c1734445a67e47caa25673d7a4ce7520 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /** 10 | * Attempts to error correct a hex (6-bit) word using the Hamming(10,6,3) FEC. 11 | * \param hex The 6-bit word to error correct. 12 | * \param parity The parity to use in the error correction. 4 bits. 13 | * \return The estimated error count. It might be erroneous. 14 | */ 15 | int check_and_fix_hamming_10_6_3(char* hex, char* parity); 16 | 17 | /** 18 | * Encodes an hex word with the Hamming(10,6,3) FEC. 19 | * \param hex The 6-bit word to error correct. 20 | * \param out_parity The address where to store the calculated parity. 4 bytes are used, one for each bit. 21 | */ 22 | void encode_hamming_10_6_3(char* hex, char* out_parity); 23 | 24 | /** 25 | * Attempts to correct 12 hex words using the Reed-Solomon(24,12,13) FEC. 26 | * \param data The packed hex words, each of 6 chars, one after the other. 27 | * \param parity The corresponding 12 hex words with the parity information. 28 | * \return 1 if irrecoverable errors have been detected, 0 otherwise. 29 | */ 30 | int check_and_fix_reedsolomon_24_12_13(char* data, char* parity); 31 | 32 | /** 33 | * Encodes 12 hex words with the Reed-Solomon(24,12,13) FEC. 34 | * \param hex_data The packed 12 hex words to encode. 35 | * \fixed_parity The address were to store the 12 hex words with the Reed-Solomon parity. 36 | */ 37 | void encode_reedsolomon_24_12_13(char* hex_data, char* fixed_parity); 38 | 39 | /** 40 | * Attempts to correct 16 hex words using the Reed-Solomon(24,16,9) FEC. 41 | * \param data The packed 16 hex words, each of 6 chars, one after the other. 42 | * \param parity The corresponding 8 hex words with the parity information. 43 | * \return 1 if irrecoverable errors have been detected, 0 otherwise. 44 | */ 45 | int check_and_fix_reedsolomon_24_16_9(char* data, char* parity); 46 | 47 | /** 48 | * Encodes 12 hex words with the Reed-Solomon(24,16,9) FEC. 49 | * \param hex_data The packed 16 hex words to encode. 50 | * \fixed_parity The address were to store the 8 hex words with the Reed-Solomon parity. 51 | */ 52 | void encode_reedsolomon_24_16_9(char* hex_data, char* fixed_parity); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // P25P1_CHECK_LDU_H_c1734445a67e47caa25673d7a4ce7520 59 | -------------------------------------------------------------------------------- /include/p25p1_check_nid.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef P25P1_CHECK_NID_H_3af071e917ea43fdb51326e2cbfbde0a 3 | #define P25P1_CHECK_NID_H_3af071e917ea43fdb51326e2cbfbde0a 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | /** 10 | * Checks a NID value, returns the fixed NAC, DUID and also an indication if it failed to decode the NID. 11 | * \param bch_code Input. An array to the 63 bytes, each containing one bit of the NID. This includes the 12 | * NAC (12 bits), DUID (4 bits) and 47 bits of BCH parity. 13 | * \param new_nac Output. An address where to store the calculated NAC value after error correction. Should 14 | * be large enough to accommodate for an integer. 15 | * \param new_duid Output. An address where to store the calculated DUID value after error correction. Should 16 | * be able to accommodate 3 chars. 17 | * \param parity Input. The parity value read. 18 | * \return 0 if there were errors processing the NID. 19 | */ 20 | int check_NID(char* bch_code, int* new_nac, char* new_duid, unsigned char parity); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif // P25P1_CHECK_NID_H_3af071e917ea43fdb51326e2cbfbde0a 27 | -------------------------------------------------------------------------------- /include/p25p1_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MAIN 19 | 20 | extern const int iW[72]; 21 | extern const int iX[72]; 22 | extern const int iY[72]; 23 | extern const int iZ[72]; 24 | 25 | #else 26 | /* 27 | * P25 Phase1 IMBE interleave schedule 28 | */ 29 | 30 | const int iW[72] = { 31 | 0, 2, 4, 1, 3, 5, 32 | 0, 2, 4, 1, 3, 6, 33 | 0, 2, 4, 1, 3, 6, 34 | 0, 2, 4, 1, 3, 6, 35 | 0, 2, 4, 1, 3, 6, 36 | 0, 2, 4, 1, 3, 6, 37 | 0, 2, 5, 1, 3, 6, 38 | 0, 2, 5, 1, 3, 6, 39 | 0, 2, 5, 1, 3, 7, 40 | 0, 2, 5, 1, 3, 7, 41 | 0, 2, 5, 1, 4, 7, 42 | 0, 3, 5, 2, 4, 7 43 | }; 44 | 45 | const int iX[72] = { 46 | 22, 20, 10, 20, 18, 0, 47 | 20, 18, 8, 18, 16, 13, 48 | 18, 16, 6, 16, 14, 11, 49 | 16, 14, 4, 14, 12, 9, 50 | 14, 12, 2, 12, 10, 7, 51 | 12, 10, 0, 10, 8, 5, 52 | 10, 8, 13, 8, 6, 3, 53 | 8, 6, 11, 6, 4, 1, 54 | 6, 4, 9, 4, 2, 6, 55 | 4, 2, 7, 2, 0, 4, 56 | 2, 0, 5, 0, 13, 2, 57 | 0, 21, 3, 21, 11, 0 58 | }; 59 | 60 | const int iY[72] = { 61 | 1, 3, 5, 0, 2, 4, 62 | 1, 3, 6, 0, 2, 4, 63 | 1, 3, 6, 0, 2, 4, 64 | 1, 3, 6, 0, 2, 4, 65 | 1, 3, 6, 0, 2, 4, 66 | 1, 3, 6, 0, 2, 5, 67 | 1, 3, 6, 0, 2, 5, 68 | 1, 3, 6, 0, 2, 5, 69 | 1, 3, 6, 0, 2, 5, 70 | 1, 3, 7, 0, 2, 5, 71 | 1, 4, 7, 0, 3, 5, 72 | 2, 4, 7, 1, 3, 5 73 | }; 74 | 75 | const int iZ[72] = { 76 | 21, 19, 1, 21, 19, 9, 77 | 19, 17, 14, 19, 17, 7, 78 | 17, 15, 12, 17, 15, 5, 79 | 15, 13, 10, 15, 13, 3, 80 | 13, 11, 8, 13, 11, 1, 81 | 11, 9, 6, 11, 9, 14, 82 | 9, 7, 4, 9, 7, 12, 83 | 7, 5, 2, 7, 5, 10, 84 | 5, 3, 0, 5, 3, 8, 85 | 3, 1, 5, 3, 1, 6, 86 | 1, 14, 3, 1, 22, 4, 87 | 22, 12, 1, 22, 20, 2 88 | }; 89 | #endif 90 | -------------------------------------------------------------------------------- /include/p25p1_hdu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef P25P1_HDU_H_9f95c3a5072842e8aaf94444e1452d20 3 | #define P25P1_HDU_H_9f95c3a5072842e8aaf94444e1452d20 4 | 5 | 6 | #include "p25p1_heuristics.h" 7 | 8 | /** 9 | * Reads a dibit (two bits) from the stream of data. Takes into account the periodic occurrence of status 10 | * bits that show up every 36 dibits. Status bits are discarded. 11 | * \param opts A pointer the the DSD options. 12 | * \param state A pointer the the DSD state structure. 13 | * \param output A pointer to be filled with the dibit read. Two bytes used for each dibit. 14 | * \param status_count Variable used to keep track of the status symbols in the dibit stream. There is one 15 | * status every 36 dibits. With this counter we can skip the status. 16 | * \param analog_signal A pointer with the actual analog value read from the input signal and that has been 17 | * interpreted as the dibit we are returning in output. 18 | * \param did_read_status Address were a boolean is returned. This is set to true when one status symbol was 19 | * read (and skipped). This indicates that the sequence on dibits has been broken and is used by the P25 20 | * heuristics. 21 | */ 22 | int read_dibit (dsd_opts* opts, dsd_state* state, char* output, int* status_count, int* analog_signal, 23 | int* did_read_status); 24 | 25 | /** 26 | * Reads a number of dibits and stores its value together with the actual analog value that has been 27 | * intrepreted as the dibit into an AnalogSignal structure. This is used later in the P25 heuristics module 28 | * to improve the accuracy of the digitizer. 29 | * \param opts A pointer the the DSD options. 30 | * \param state A pointer the the DSD state structure. 31 | * \param output A pointer to be filled with the dibits read. 32 | * \param count The number of bits to read (remember: 1 dibit = 2 bits). 33 | * \param status_count Variable used to keep track of the status symbols in the dibit stream. There is one 34 | * status every 36 dibits. With this counter we can skip the status. 35 | * \param analog_signal_array The pointer to the start of a sequence of AnalogSignal structures. The 36 | * information is updated for each dibit read. 37 | * \param analog_signal_index The actual index into the AnalogSignal array. This is increased here wich each 38 | * dibit read. 39 | */ 40 | void read_dibit_update_analog_data (dsd_opts* opts, dsd_state* state, char* buffer, unsigned int count, 41 | int* status_count, AnalogSignal* analog_signal_array, int* analog_signal_index); 42 | 43 | /** 44 | * Reads a word, made up of length bits or length/2 dibits. Also keeps track of the status dibits. 45 | */ 46 | void read_word (dsd_opts* opts, dsd_state* state, char* word, unsigned int length, int* status_count, 47 | AnalogSignal* analog_signal_array, int* analog_signal_index); 48 | 49 | /** 50 | * Reads 4 bits from the stream of data. Those are the parity bits that follow each hex word. 51 | */ 52 | void read_hamm_parity (dsd_opts* opts, dsd_state* state, char* parity, int* status_count, 53 | AnalogSignal* analog_signal_array, int* analog_signal_index); 54 | 55 | /** 56 | * Reads 12 bits from the stream of data. Those are the extended Golay parity bits that follow a word of data. 57 | */ 58 | void read_golay24_parity (dsd_opts* opts, dsd_state* state, char* parity, int* status_count, AnalogSignal* analog_signal_array, int* analog_signal_index); 59 | 60 | /** 61 | * Reads bits from the data stream that should all be zeros. This is valuable information for the 62 | * heuristics module and we update it. 63 | * \param opts A pointer the the DSD options. 64 | * \param state A pointer the the DSD state structure. 65 | * \param analog_signal_array The pointer to the start of a sequence of AnalogSignal structures. 66 | * \param length Number of bits to read. 67 | * \param status_count Variable used to keep track of the status symbols in the dibit stream. 68 | * \param new_sequence Bool used to update the sequence_broken value of the first AnalogSignal element. 69 | */ 70 | void read_zeros(dsd_opts* opts, dsd_state* state, AnalogSignal* analog_signal_array, unsigned int length, 71 | int* status_count, int new_sequence); 72 | 73 | #endif // P25P1_HDU_H_9f95c3a5072842e8aaf94444e1452d20 74 | -------------------------------------------------------------------------------- /include/p25p1_heuristics.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef P25P1_HEURISTICS_H_030dd3530b7546abbb56f8dd1e66a2f6 3 | #define P25P1_HEURISTICS_H_030dd3530b7546abbb56f8dd1e66a2f6 4 | 5 | #define HEURISTICS_SIZE 200 6 | typedef struct 7 | { 8 | int values[HEURISTICS_SIZE]; 9 | float means[HEURISTICS_SIZE]; 10 | int index; 11 | int count; 12 | float sum; 13 | float var_sum; 14 | } SymbolHeuristics; 15 | 16 | typedef struct 17 | { 18 | unsigned int bit_count; 19 | unsigned int bit_error_count; 20 | SymbolHeuristics symbols[4][4]; 21 | } P25Heuristics; 22 | 23 | typedef struct 24 | { 25 | int value; 26 | int dibit; 27 | int corrected_dibit; 28 | int sequence_broken; 29 | } AnalogSignal; 30 | 31 | #ifdef __cplusplus 32 | extern "C"{ 33 | #endif 34 | 35 | /** 36 | * Initializes the heuristics state. 37 | * \param heuristics The P25Heuristics structure to initialize. 38 | */ 39 | void initialize_p25_heuristics(P25Heuristics* heuristics); 40 | 41 | /** 42 | * Important method that estimates the most likely symbol for a given analog signal value and previous dibit. 43 | * This is called by the digitizer. 44 | * \param rf_mod Indicates the modulation used. The previous dibit is only used on C4FM. 45 | * \param heuristics Pointer to the P25Heuristics module with all the needed state information. 46 | * \param previous_dibit The previous dibit. 47 | * \param analog_value The signal's analog value we want to interpret as a dibit. 48 | * \param dibit Address were to store the estimated dibit. 49 | * \return A boolean set to true if we are able to estimate a dibit. The reason why we might not be able 50 | * to estimate it is because we don't have enough information to model the Gaussians (not enough data 51 | * has been passed to contribute_to_heuristics). 52 | */ 53 | int estimate_symbol(int rf_mod, P25Heuristics* heuristics, int previous_dibit, int analog_value, int* dibit); 54 | 55 | /** 56 | * Log some useful information on the heuristics state. 57 | */ 58 | void debug_print_heuristics(P25Heuristics* heuristics); 59 | 60 | /** 61 | * This method contributes valuable information from dibits whose value we are confident is correct. We take 62 | * the dibits and corresponding analog signal values to model the Gaussians for each dibit (and previous 63 | * dibit if enabled). 64 | * \param rf_mod Indicates the modulation used. The previous dibit is only used on C4FM. 65 | * \param heuristics Pointer to the P25Heuristics module with all the needed state information. 66 | * \param analog_signal_array Sequence of AnalogSignal which contain the cleared dibits and analog values. 67 | * \param count number of cleared dibits passed (= number of elements to use from analog_signal_array). 68 | */ 69 | void contribute_to_heuristics(int rf_mod, P25Heuristics* heuristics, AnalogSignal* analog_signal_array, int count); 70 | 71 | /** 72 | * Updates the estimate for the BER (bit error rate). Mind this is method is not called for every single 73 | * bit in the data stream but only for those bits over which we have an estimate of its error rate, 74 | * specifically the bits that are protected by Reed-Solomon codes. 75 | * \param heuristics The heuristics state. 76 | * \param bits The number of bits we have read. 77 | * \param errors The number of errors we estimate in those bits. 78 | */ 79 | void update_error_stats(P25Heuristics* heuristics, int bits, int errors); 80 | 81 | /** 82 | * Returns the estimate for the BER (bit error rate). 83 | * \return The estimated BER. This is just the percentage of errors over the processed bits. 84 | */ 85 | float get_P25_BER_estimate(P25Heuristics* heuristics); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif // P25P1_HEURISTICS_H_030dd3530b7546abbb56f8dd1e66a2f6 92 | -------------------------------------------------------------------------------- /include/p25p1_ldu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef P25P1_LDU_H_a3c417fcb7804991b0e6d828066bd133 3 | #define P25P1_LDU_H_a3c417fcb7804991b0e6d828066bd133 4 | 5 | #include "dsd.h" 6 | 7 | #include "p25p1_hdu.h" 8 | #include "p25p1_const.h" 9 | #include "p25p1_heuristics.h" 10 | 11 | /** 12 | * Separate imbe frames and deinterleave. 13 | * This important methods read the IMBE data from the stream and passes it to the vocoder to produce audio. 14 | * \param opts The DSD options. 15 | * \param state The DSD state. 16 | * \status_count An index that allows us to skip the status words interleaved every 36 dibit in the data 17 | * stream. 18 | */ 19 | void process_IMBE (dsd_opts* opts, dsd_state* state, int* status_count); 20 | 21 | /** 22 | * Reads an hex word, its parity bits and attempts to error correct it using the Hamming FEC. 23 | * \param opts The DSD options. 24 | * \param state The DSD state. 25 | * \param hex Pointer where to store the read hex word. Six bytes, one per bit. 26 | * \param status_count An index that allows us to skip the status words interleaved every 36 dibit in the data 27 | * stream. 28 | * \param analog_singal_array Pointer to a sequence of AnalogSignal elements. 29 | * \param analog_signal_index The current index in the analog_singal_array. This value is increased on each 30 | * dibit read. 31 | */ 32 | void read_and_correct_hex_word (dsd_opts* opts, dsd_state* state, char* hex, int* status_count, 33 | AnalogSignal* analog_signal_array, int* analog_signal_index); 34 | 35 | /** 36 | * Correct the information in analog_signal_array according with the content of data, which has been 37 | * error corrected and should be valid. 38 | * \param Dibits that have already been error corrected and we trust are correct. 39 | * \count Number of dibits. 40 | * \param analog_signal_array Pointer to a sequence of AnalogSignal elements, as many as the value of count. 41 | */ 42 | void correct_hamming_dibits(char* hex_data, int hex_count, AnalogSignal* analog_signal_array); 43 | 44 | /** 45 | * Logs some debug info. 46 | */ 47 | void debug_ldu_header(dsd_state* state); 48 | 49 | #endif // P25P1_LDU_H_a3c417fcb7804991b0e6d828066bd133 50 | -------------------------------------------------------------------------------- /include/pa_devs.h: -------------------------------------------------------------------------------- 1 | #ifndef PA_DEVS_H 2 | #define PA_DEVS_H 3 | 4 | void printPortAudioDevices(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/provoice_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MAIN 19 | 20 | extern const int pW[142]; 21 | extern const int pX[142]; 22 | 23 | #else 24 | /* 25 | * ProVoice IMBE interleave schedule 26 | */ 27 | 28 | const int pW[142] = { 29 | 0, 1, 2, 3, 4, 6, 30 | 0, 1, 2, 3, 4, 6, 31 | 0, 1, 2, 3, 4, 6, 32 | 0, 1, 2, 3, 5, 6, 33 | 0, 1, 2, 3, 5, 6, 34 | 0, 1, 2, 3, 5, 6, 35 | 0, 1, 3, 4, 5, 6, 36 | 1, 2, 3, 4, 5, 6, 37 | 0, 1, 2, 3, 4, 6, 38 | 0, 1, 2, 3, 4, 6, 39 | 0, 1, 2, 3, 4, 6, 40 | 0, 1, 2, 3, 5, 6, 41 | 0, 1, 2, 3, 5, 6, 42 | 0, 1, 2, 3, 5, 6, 43 | 1, 2, 3, 4, 5, 6, 44 | 1, 2, 3, 4, 5, 45 | 0, 1, 2, 3, 4, 6, 46 | 0, 1, 2, 3, 4, 6, 47 | 0, 1, 2, 3, 5, 6, 48 | 0, 1, 2, 3, 5, 6, 49 | 0, 1, 2, 3, 5, 6, 50 | 0, 1, 2, 4, 5, 6, 51 | 1, 2, 3, 4, 5, 6, 52 | 1, 2, 3, 4, 6 53 | }; 54 | 55 | const int pX[142] = { 56 | 18, 18, 17, 16, 7, 21, 57 | 15, 15, 14, 13, 4, 18, 58 | 12, 12, 11, 10, 1, 15, 59 | 9, 9, 8, 7, 13, 12, 60 | 6, 6, 5, 4, 10, 9, 61 | 3, 3, 2, 1, 7, 6, 62 | 0, 0, 22, 13, 4, 3, 63 | 21, 20, 19, 10, 1, 0, 64 | 17, 17, 16, 15, 6, 20, 65 | 14, 14, 13, 12, 3, 17, 66 | 11, 11, 10, 9, 0, 14, 67 | 8, 8, 7, 6, 12, 11, 68 | 5, 5, 4, 3, 9, 8, 69 | 2, 2, 1, 0, 6, 5, 70 | 23, 22, 21, 12, 3, 2, 71 | 20, 19, 18, 9, 0, 72 | 16, 16, 15, 14, 5, 19, 73 | 13, 13, 12, 11, 2, 16, 74 | 10, 10, 9, 8, 14, 13, 75 | 7, 7, 6, 5, 11, 10, 76 | 4, 4, 3, 2, 8, 7, 77 | 1, 1, 0, 14, 5, 4, 78 | 22, 21, 20, 11, 2, 1, 79 | 19, 18, 17, 8, 22 80 | }; 81 | #endif 82 | -------------------------------------------------------------------------------- /include/x2tdma_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * X2TDMA AMBE interleave schedule 20 | */ 21 | 22 | #ifndef _MAIN 23 | extern const int aW[36]; 24 | extern const int aX[36]; 25 | extern const int aY[36]; 26 | extern const int aZ[36]; 27 | 28 | #else 29 | 30 | const int aW[36] = { 0, 1, 0, 1, 0, 1, 31 | 0, 1, 0, 1, 0, 1, 32 | 0, 1, 0, 1, 0, 1, 33 | 0, 1, 0, 1, 0, 2, 34 | 0, 2, 0, 2, 0, 2, 35 | 0, 2, 0, 2, 0, 2 36 | }; 37 | 38 | const int aX[36] = { 23, 10, 22, 9, 21, 8, 39 | 20, 7, 19, 6, 18, 5, 40 | 17, 4, 16, 3, 15, 2, 41 | 14, 1, 13, 0, 12, 10, 42 | 11, 9, 10, 8, 9, 7, 43 | 8, 6, 7, 5, 6, 4 44 | }; 45 | 46 | const int aY[36] = { 0, 2, 0, 2, 0, 2, 47 | 0, 2, 0, 3, 0, 3, 48 | 1, 3, 1, 3, 1, 3, 49 | 1, 3, 1, 3, 1, 3, 50 | 1, 3, 1, 3, 1, 3, 51 | 1, 3, 1, 3, 1, 3 52 | }; 53 | 54 | const int aZ[36] = { 5, 3, 4, 2, 3, 1, 55 | 2, 0, 1, 13, 0, 12, 56 | 22, 11, 21, 10, 20, 9, 57 | 19, 8, 18, 7, 17, 6, 58 | 16, 5, 15, 4, 14, 3, 59 | 13, 2, 12, 1, 11, 0 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/Hamming.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Hamming.hpp" 3 | 4 | // definition outside class declaration 5 | Hamming_10_6_3_data Hamming_10_6_3::data; 6 | 7 | // definition outside class declaration 8 | // Should go *after* Hamming_10_6_3_data since Hamming_10_6_3_TableImpl_data constructor uses 9 | // Hamming_10_6_3 which in its turn depends on Hamming_10_6_3_data 10 | Hamming_10_6_3_TableImpl_data Hamming_10_6_3_TableImpl::data; 11 | 12 | 13 | int Hamming_10_6_3::decode(std::bitset<10>& input) 14 | { 15 | int error_count; 16 | 17 | // Compute syndromes 18 | int s0 = ((data.h0 & input).count() & 1) << 3; 19 | int s1 = ((data.h1 & input).count() & 1) << 2; 20 | int s2 = ((data.h2 & input).count() & 1) << 1; 21 | int s3 = ((data.h3 & input).count() & 1); 22 | int parity = s0 | s1 | s2 | s3; 23 | 24 | if (parity == 0) { 25 | //std::cout << input << " is OK" << std::endl; 26 | error_count = 0; 27 | } else { 28 | // Error detected, attempt to fix it 29 | int bad_bit_index = data.bad_bit_table[parity]; 30 | 31 | if (bad_bit_index < 0) { 32 | //std::cout << "Irrecoverable error: " << std::bitset<6>(input.to_string()) << std::endl; 33 | error_count = 2; 34 | } else { 35 | // Error in a data bit, or more than one error 36 | // If there is one erroneous bit, the bad one is the one indicated by parity 37 | if (bad_bit_index < 4) { 38 | // Error detected in a parity bit 39 | //std::cout << "Error on parity bit " << bad_bit_index << std::endl; 40 | error_count = 1; 41 | } else { 42 | input.flip(bad_bit_index); 43 | //std::cout << "Error on data bit " << bad_bit_index << ", hopefully fixed: " << std::bitset<6>(input.to_string()) << std::endl; 44 | error_count = 1; 45 | } 46 | } 47 | } 48 | //std::cout << std::endl; 49 | 50 | return error_count; 51 | } 52 | 53 | int Hamming_10_6_3::encode(std::bitset<6>& input) 54 | { 55 | // Compute syndromes 56 | int s0 = ((data.gt0 & input).count() & 1) << 3; 57 | int s1 = ((data.gt1 & input).count() & 1) << 2; 58 | int s2 = ((data.gt2 & input).count() & 1) << 1; 59 | int s3 = ((data.gt3 & input).count() & 1); 60 | int parity = s0 | s1 | s2 | s3; 61 | 62 | return parity; 63 | } 64 | 65 | int Hamming_10_6_3_TableImpl::decode(int input, int* output) 66 | { 67 | assert (input < 1024 && input >= 0); 68 | 69 | // Making use of a table... 70 | 71 | *output = data.fixed_values[input]; 72 | 73 | return data.error_counts[input]; 74 | } 75 | 76 | int Hamming_10_6_3_TableImpl::encode(int input) 77 | { 78 | assert (input < 64 && input >= 0); 79 | 80 | // Making use of a table... 81 | 82 | return data.encode_parities[input]; 83 | } 84 | -------------------------------------------------------------------------------- /src/dmr_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "dsd.h" 19 | 20 | void 21 | processDMRdata (dsd_opts * opts, dsd_state * state) 22 | { 23 | 24 | int i, dibit; 25 | int *dibit_p; 26 | char sync[25]; 27 | char syncdata[25]; 28 | char cachdata[13]; 29 | char cc[5]; 30 | char bursttype[5]; 31 | 32 | #ifdef DMR_DUMP 33 | int k; 34 | char syncbits[49]; 35 | char cachbits[25]; 36 | #endif 37 | 38 | cc[4] = 0; 39 | bursttype[4] = 0; 40 | 41 | dibit_p = state->dibit_buf_p - 90; 42 | 43 | // CACH 44 | for (i = 0; i < 12; i++) 45 | { 46 | dibit = *dibit_p; 47 | dibit_p++; 48 | if (opts->inverted_dmr == 1) 49 | { 50 | dibit = (dibit ^ 2); 51 | } 52 | cachdata[i] = dibit; 53 | if (i == 2) 54 | { 55 | state->currentslot = (1 & (dibit >> 1)); // bit 1 56 | if (state->currentslot == 0) 57 | { 58 | state->slot0light[0] = '['; 59 | state->slot0light[6] = ']'; 60 | state->slot1light[0] = ' '; 61 | state->slot1light[6] = ' '; 62 | } 63 | else 64 | { 65 | state->slot1light[0] = '['; 66 | state->slot1light[6] = ']'; 67 | state->slot0light[0] = ' '; 68 | state->slot0light[6] = ' '; 69 | } 70 | } 71 | } 72 | cachdata[12] = 0; 73 | 74 | #ifdef DMR_DUMP 75 | k = 0; 76 | for (i = 0; i < 12; i++) 77 | { 78 | dibit = cachdata[i]; 79 | cachbits[k] = (1 & (dibit >> 1)) + 48; // bit 1 80 | k++; 81 | cachbits[k] = (1 & dibit) + 48; // bit 0 82 | k++; 83 | } 84 | cachbits[24] = 0; 85 | printf ("%s ", cachbits); 86 | #endif 87 | 88 | // current slot 89 | dibit_p += 49; 90 | 91 | // slot type 92 | dibit = *dibit_p; 93 | dibit_p++; 94 | if (opts->inverted_dmr == 1) 95 | { 96 | dibit = (dibit ^ 2); 97 | } 98 | cc[0] = (1 & (dibit >> 1)) + 48; // bit 1 99 | cc[1] = (1 & dibit) + 48; // bit 0 100 | 101 | dibit = *dibit_p; 102 | dibit_p++; 103 | if (opts->inverted_dmr == 1) 104 | { 105 | dibit = (dibit ^ 2); 106 | } 107 | cc[2] = (1 & (dibit >> 1)) + 48; // bit 1 108 | cc[3] = (1 & dibit) + 48; // bit 0 109 | 110 | dibit = *dibit_p; 111 | dibit_p++; 112 | if (opts->inverted_dmr == 1) 113 | { 114 | dibit = (dibit ^ 2); 115 | } 116 | bursttype[0] = (1 & (dibit >> 1)) + 48; // bit 1 117 | bursttype[1] = (1 & dibit) + 48; // bit 0 118 | 119 | dibit = *dibit_p; 120 | dibit_p++; 121 | if (opts->inverted_dmr == 1) 122 | { 123 | dibit = (dibit ^ 2); 124 | } 125 | bursttype[2] = (1 & (dibit >> 1)) + 48; // bit 1 126 | bursttype[3] = (1 & dibit) + 48; // bit 0 127 | 128 | // parity bit 129 | dibit_p++; 130 | 131 | if (strcmp (bursttype, "0000") == 0) 132 | { 133 | sprintf (state->fsubtype, " PI Header "); 134 | } 135 | else if (strcmp (bursttype, "0001") == 0) 136 | { 137 | sprintf (state->fsubtype, " VOICE Header "); 138 | } 139 | else if (strcmp (bursttype, "0010") == 0) 140 | { 141 | sprintf (state->fsubtype, " TLC "); 142 | } 143 | else if (strcmp (bursttype, "0011") == 0) 144 | { 145 | sprintf (state->fsubtype, " CSBK "); 146 | } 147 | else if (strcmp (bursttype, "0100") == 0) 148 | { 149 | sprintf (state->fsubtype, " MBC Header "); 150 | } 151 | else if (strcmp (bursttype, "0101") == 0) 152 | { 153 | sprintf (state->fsubtype, " MBC "); 154 | } 155 | else if (strcmp (bursttype, "0110") == 0) 156 | { 157 | sprintf (state->fsubtype, " DATA Header "); 158 | } 159 | else if (strcmp (bursttype, "0111") == 0) 160 | { 161 | sprintf (state->fsubtype, " RATE 1/2 DATA"); 162 | } 163 | else if (strcmp (bursttype, "1000") == 0) 164 | { 165 | sprintf (state->fsubtype, " RATE 3/4 DATA"); 166 | } 167 | else if (strcmp (bursttype, "1001") == 0) 168 | { 169 | sprintf (state->fsubtype, " Slot idle "); 170 | } 171 | else if (strcmp (bursttype, "1010") == 0) 172 | { 173 | sprintf (state->fsubtype, " Rate 1 DATA "); 174 | } 175 | else 176 | { 177 | sprintf (state->fsubtype, " "); 178 | } 179 | 180 | // signaling data or sync 181 | for (i = 0; i < 24; i++) 182 | { 183 | dibit = *dibit_p; 184 | dibit_p++; 185 | if (opts->inverted_dmr == 1) 186 | { 187 | dibit = (dibit ^ 2); 188 | } 189 | syncdata[i] = dibit; 190 | sync[i] = (dibit | 1) + 48; 191 | } 192 | sync[24] = 0; 193 | syncdata[24] = 0; 194 | 195 | #ifdef DMR_DUMP 196 | k = 0; 197 | for (i = 0; i < 24; i++) 198 | { 199 | dibit = syncdata[i]; 200 | syncbits[k] = (1 & (dibit >> 1)) + 48; // bit 1 201 | k++; 202 | syncbits[k] = (1 & dibit) + 48; // bit 0 203 | k++; 204 | } 205 | syncbits[48] = 0; 206 | printf ("%s ", syncbits); 207 | #endif 208 | 209 | if ((strcmp (sync, DMR_BS_DATA_SYNC) == 0) || (strcmp (sync, DMR_MS_DATA_SYNC) == 0)) 210 | { 211 | if (state->currentslot == 0) 212 | { 213 | sprintf (state->slot0light, "[slot0]"); 214 | } 215 | else 216 | { 217 | sprintf (state->slot1light, "[slot1]"); 218 | } 219 | } 220 | 221 | if (opts->errorbars == 1) 222 | { 223 | printf ("%s %s ", state->slot0light, state->slot1light); 224 | } 225 | 226 | // current slot second half, cach, next slot 1st half 227 | skipDibit (opts, state, 120); 228 | 229 | if (opts->errorbars == 1) 230 | { 231 | if (strcmp (state->fsubtype, " ") == 0) 232 | { 233 | printf (" Unknown burst type: %s\n", bursttype); 234 | } 235 | else 236 | { 237 | printf ("%s\n", state->fsubtype); 238 | } 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /src/dsd_filters.c: -------------------------------------------------------------------------------- 1 | // DMR filter 2 | #define NZEROS 60 3 | float ngain = 7.423339364f; 4 | static float xv[NZEROS+1]; 5 | float xcoeffs[] = 6 | { -0.0083649323f, -0.0265444850f, -0.0428141462f, -0.0537571943f, 7 | -0.0564141052f, -0.0489161045f, -0.0310068662f, -0.0043393881f, 8 | +0.0275375106f, +0.0595423283f, +0.0857543325f, +0.1003565948f, 9 | +0.0986944931f, +0.0782804830f, +0.0395670487f, -0.0136691535f, 10 | -0.0744390415f, -0.1331834575f, -0.1788967208f, -0.2005995448f, 11 | -0.1889627181f, -0.1378439993f, -0.0454976231f, +0.0847488694f, 12 | +0.2444859269f, +0.4209222342f, +0.5982295474f, +0.7593684540f, 13 | +0.8881539892f, +0.9712773915f, +0.9999999166f, +0.9712773915f, 14 | +0.8881539892f, +0.7593684540f, +0.5982295474f, +0.4209222342f, 15 | +0.2444859269f, +0.0847488694f, -0.0454976231f, -0.1378439993f, 16 | -0.1889627181f, -0.2005995448f, -0.1788967208f, -0.1331834575f, 17 | -0.0744390415f, -0.0136691535f, +0.0395670487f, +0.0782804830f, 18 | +0.0986944931f, +0.1003565948f, +0.0857543325f, +0.0595423283f, 19 | +0.0275375106f, -0.0043393881f, -0.0310068662f, -0.0489161045f, 20 | -0.0564141052f, -0.0537571943f, -0.0428141462f, -0.0265444850f, 21 | -0.0083649323f, 22 | }; 23 | 24 | // NXDN filter 25 | #define NXZEROS 134 26 | float nxgain = 15.95930463f; 27 | 28 | static float nxv[NXZEROS+1]; 29 | 30 | float nxcoeffs[] = 31 | { +0.031462429f, +0.031747267f, +0.030401148f, +0.027362877f, 32 | +0.022653298f, +0.016379869f, +0.008737200f, +0.000003302f, 33 | -0.009468531f, -0.019262057f, -0.028914291f, -0.037935027f, 34 | -0.045828927f, -0.052119261f, -0.056372283f, -0.058221106f, 35 | -0.057387924f, -0.053703443f, -0.047122444f, -0.037734535f, 36 | -0.025769308f, -0.011595336f, +0.004287292f, +0.021260954f, 37 | +0.038610717f, +0.055550276f, +0.071252765f, +0.084885375f, 38 | +0.095646450f, +0.102803611f, +0.105731303f, +0.103946126f, 39 | +0.097138329f, +0.085197939f, +0.068234131f, +0.046586711f, 40 | +0.020828821f, -0.008239664f, -0.039608255f, -0.072081234f, 41 | -0.104311776f, -0.134843790f, -0.162160200f, -0.184736015f, 42 | -0.201094346f, -0.209863285f, -0.209831516f, -0.200000470f, 43 | -0.179630919f, -0.148282051f, -0.105841323f, -0.052543664f, 44 | +0.011020985f, +0.083912428f, +0.164857408f, +0.252278939f, 45 | +0.344336996f, +0.438979335f, +0.534000832f, +0.627109358f, 46 | +0.715995947f, +0.798406824f, +0.872214756f, +0.935487176f, 47 | +0.986548646f, +1.024035395f, +1.046939951f, +1.054644241f, 48 | +1.046939951f, +1.024035395f, +0.986548646f, +0.935487176f, 49 | +0.872214756f, +0.798406824f, +0.715995947f, +0.627109358f, 50 | +0.534000832f, +0.438979335f, +0.344336996f, +0.252278939f, 51 | +0.164857408f, +0.083912428f, +0.011020985f, -0.052543664f, 52 | -0.105841323f, -0.148282051f, -0.179630919f, -0.200000470f, 53 | -0.209831516f, -0.209863285f, -0.201094346f, -0.184736015f, 54 | -0.162160200f, -0.134843790f, -0.104311776f, -0.072081234f, 55 | -0.039608255f, -0.008239664f, +0.020828821f, +0.046586711f, 56 | +0.068234131f, +0.085197939f, +0.097138329f, +0.103946126f, 57 | +0.105731303f, +0.102803611f, +0.095646450f, +0.084885375f, 58 | +0.071252765f, +0.055550276f, +0.038610717f, +0.021260954f, 59 | +0.004287292f, -0.011595336f, -0.025769308f, -0.037734535f, 60 | -0.047122444f, -0.053703443f, -0.057387924f, -0.058221106f, 61 | -0.056372283f, -0.052119261f, -0.045828927f, -0.037935027f, 62 | -0.028914291f, -0.019262057f, -0.009468531f, +0.000003302f, 63 | +0.008737200f, +0.016379869f, +0.022653298f, +0.027362877f, 64 | +0.030401148f, +0.031747267f, +0.031462429f, 65 | }; 66 | 67 | short dsd_input_filter(short sample, int mode); 68 | 69 | short 70 | dmr_filter(short sample) 71 | { 72 | return dsd_input_filter(sample, 1); 73 | } 74 | 75 | short 76 | nxdn_filter(short sample) 77 | { 78 | return dsd_input_filter(sample, 2); 79 | } 80 | 81 | 82 | short 83 | dsd_input_filter(short sample, int mode) 84 | { 85 | float sum; int i; 86 | float gain; 87 | int zeros; 88 | float *v, *coeffs; 89 | switch(mode) { 90 | case 1: 91 | gain = ngain; 92 | v = xv; 93 | coeffs = xcoeffs; 94 | zeros = NZEROS; 95 | break; 96 | case 2: 97 | gain = nxgain; 98 | v = nxv; 99 | coeffs = nxcoeffs; 100 | zeros = NXZEROS; 101 | break; 102 | default: 103 | return sample; 104 | } 105 | 106 | for (i = 0; i < zeros; i++) 107 | v[i] = v[i+1]; 108 | 109 | v[zeros] = sample; // unfiltered sample in 110 | sum = 0.0f; 111 | 112 | for (i = 0; i <= zeros; i++) 113 | sum += (coeffs[i] * v[i]); 114 | 115 | return (short)(sum / ngain); // filtered sample out 116 | } -------------------------------------------------------------------------------- /src/dsd_mbe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "dsd.h" 19 | 20 | void 21 | playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv) 22 | { 23 | 24 | int i; 25 | char imbe_d[88]; 26 | char ambe_d[49]; 27 | 28 | for (i = state->optind; i < argc; i++) 29 | { 30 | sprintf (opts->mbe_in_file, "%s", argv[i]); 31 | openMbeInFile (opts, state); 32 | mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); 33 | printf ("playing %s\n", opts->mbe_in_file); 34 | while (feof (opts->mbe_in_f) == 0) 35 | { 36 | if (state->mbe_file_type == 0) 37 | { 38 | readImbe4400Data (opts, state, imbe_d); 39 | mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); 40 | processAudio (opts, state); 41 | if (opts->wav_out_f != NULL) 42 | { 43 | writeSynthesizedVoice (opts, state); 44 | } 45 | 46 | if (opts->audio_out == 1) 47 | { 48 | playSynthesizedVoice (opts, state); 49 | } 50 | } 51 | else if (state->mbe_file_type == 1) 52 | { 53 | readAmbe2450Data (opts, state, ambe_d); 54 | mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); 55 | processAudio (opts, state); 56 | if (opts->wav_out_f != NULL) 57 | { 58 | writeSynthesizedVoice (opts, state); 59 | } 60 | if (opts->audio_out == 1) 61 | { 62 | playSynthesizedVoice (opts, state); 63 | } 64 | } 65 | if (exitflag == 1) 66 | { 67 | cleanupAndExit (opts, state); 68 | } 69 | } 70 | } 71 | } 72 | 73 | void 74 | processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24]) 75 | { 76 | 77 | int i; 78 | char imbe_d[88]; 79 | char ambe_d[49]; 80 | #ifdef AMBE_PACKET_OUT 81 | char ambe_d_str[50]; 82 | #endif 83 | 84 | for (i = 0; i < 88; i++) 85 | { 86 | imbe_d[i] = 0; 87 | } 88 | 89 | if ((state->synctype == 0) || (state->synctype == 1)) 90 | { 91 | // 0 +P25p1 92 | // 1 -P25p1 93 | 94 | mbe_processImbe7200x4400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_fr, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); 95 | if (opts->mbe_out_f != NULL) 96 | { 97 | saveImbe4400Data (opts, state, imbe_d); 98 | } 99 | } 100 | else if ((state->synctype == 14) || (state->synctype == 15)) 101 | { 102 | mbe_processImbe7100x4400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe7100_fr, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); 103 | if (opts->mbe_out_f != NULL) 104 | { 105 | saveImbe4400Data (opts, state, imbe_d); 106 | } 107 | } 108 | else if ((state->synctype == 6) || (state->synctype == 7)) 109 | { 110 | mbe_processAmbe3600x2400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); 111 | if (opts->mbe_out_f != NULL) 112 | { 113 | saveAmbe2450Data (opts, state, ambe_d); 114 | } 115 | } 116 | else 117 | { 118 | mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); 119 | #ifdef AMBE_PACKET_OUT 120 | for(i=0; i<49; i++) { 121 | ambe_d_str[i] = ambe_d[i] + '0'; 122 | } 123 | ambe_d_str[49] = '\0'; 124 | // print binary string 125 | fprintf(stderr, "\n?\t?\t%s\t", ambe_d_str); 126 | // print error data 127 | fprintf(stderr, "E1: %d; E2: %d; S: %s", state->errs, state->errs2, state->err_str); 128 | #endif 129 | if (opts->mbe_out_f != NULL) 130 | { 131 | saveAmbe2450Data (opts, state, ambe_d); 132 | } 133 | } 134 | 135 | if (opts->errorbars == 1) 136 | { 137 | printf ("%s", state->err_str); 138 | } 139 | 140 | state->debug_audio_errors += state->errs2; 141 | 142 | processAudio (opts, state); 143 | if (opts->wav_out_f != NULL) 144 | { 145 | writeSynthesizedVoice (opts, state); 146 | } 147 | 148 | if (opts->audio_out == 1) 149 | { 150 | playSynthesizedVoice (opts, state); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/dsd_serial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dsd.h" 3 | 4 | void 5 | openSerial (dsd_opts * opts, dsd_state * state) 6 | { 7 | 8 | struct termios tty; 9 | speed_t baud; 10 | 11 | printf ("Opening serial port %s and setting baud to %i\n", opts->serial_dev, opts->serial_baud); 12 | opts->serial_fd = open (opts->serial_dev, O_WRONLY); 13 | if (opts->serial_fd == -1) 14 | { 15 | printf ("Error, couldn't open %s\n", opts->serial_dev); 16 | exit (1); 17 | } 18 | 19 | tty.c_cflag = 0; 20 | 21 | baud = B115200; 22 | switch (opts->serial_baud) 23 | { 24 | case 1200: 25 | baud = B1200; 26 | case 2400: 27 | baud = B2400; 28 | case 4800: 29 | baud = B4800; 30 | case 9600: 31 | baud = B9600; 32 | break; 33 | case 19200: 34 | baud = B19200; 35 | break; 36 | case 38400: 37 | baud = B38400; 38 | break; 39 | case 57600: 40 | baud = B57600; 41 | break; 42 | case 115200: 43 | baud = B115200; 44 | break; 45 | case 230400: 46 | baud = B230400; 47 | break; 48 | } 49 | if (opts->serial_baud > 0) 50 | { 51 | cfsetospeed (&tty, baud); 52 | cfsetispeed (&tty, baud); 53 | } 54 | 55 | tty.c_cflag |= (tty.c_cflag & ~CSIZE) | CS8; 56 | tty.c_iflag = IGNBRK; 57 | tty.c_lflag = 0; 58 | tty.c_oflag = 0; 59 | tty.c_cflag &= ~CRTSCTS; 60 | tty.c_iflag &= ~(IXON | IXOFF | IXANY); 61 | tty.c_cflag &= ~(PARENB | PARODD); 62 | tty.c_cflag &= ~CSTOPB; 63 | tty.c_cc[VMIN] = 1; 64 | tty.c_cc[VTIME] = 5; 65 | 66 | tcsetattr (opts->serial_fd, TCSANOW, &tty); 67 | 68 | } 69 | 70 | void 71 | resumeScan (dsd_opts * opts, dsd_state * state) 72 | { 73 | 74 | char cmd[16]; 75 | ssize_t result; 76 | 77 | if (opts->serial_fd > 0) 78 | { 79 | sprintf (cmd, "\rKEY00\r"); 80 | result = write (opts->serial_fd, cmd, 7); 81 | cmd[0] = 2; 82 | cmd[1] = 75; 83 | cmd[2] = 15; 84 | cmd[3] = 3; 85 | cmd[4] = 93; 86 | cmd[5] = 0; 87 | result = write (opts->serial_fd, cmd, 5); 88 | state->numtdulc = 0; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/dsd_upsample.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "dsd.h" 19 | 20 | void 21 | upsample (dsd_state * state, float invalue) 22 | { 23 | 24 | int i, j, sum; 25 | float *outbuf1, c, d; 26 | 27 | outbuf1 = state->audio_out_float_buf_p; 28 | outbuf1--; 29 | c = *outbuf1; 30 | d = invalue; 31 | // basic triangle interpolation 32 | outbuf1++; 33 | *outbuf1 = ((invalue * (float) 0.166) + (c * (float) 0.834)); 34 | outbuf1++; 35 | *outbuf1 = ((invalue * (float) 0.332) + (c * (float) 0.668)); 36 | outbuf1++; 37 | *outbuf1 = ((invalue * (float) 0.5) + (c * (float) 0.5)); 38 | outbuf1++; 39 | *outbuf1 = ((invalue * (float) 0.668) + (c * (float) 0.332)); 40 | outbuf1++; 41 | *outbuf1 = ((invalue * (float) 0.834) + (c * (float) 0.166)); 42 | outbuf1++; 43 | *outbuf1 = d; 44 | outbuf1++; 45 | 46 | if (state->audio_out_idx2 > 24) 47 | { 48 | // smoothing 49 | outbuf1 -= 16; 50 | for (j = 0; j < 4; j++) 51 | { 52 | for (i = 0; i < 6; i++) 53 | { 54 | sum = 0; 55 | outbuf1 -= 2; 56 | sum += (int)*outbuf1; 57 | outbuf1 += 2; 58 | sum += (int)*outbuf1; 59 | outbuf1 += 2; 60 | sum += (int)*outbuf1; 61 | outbuf1 -= 2; 62 | *outbuf1 = (sum / (float) 3); 63 | outbuf1++; 64 | } 65 | outbuf1 -= 8; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/dstar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * Note: D-STAR support is fairly complete at this point. 20 | * The ambe3600x2450 decoder is similar butnot compatible with D-STAR voice frames. 21 | * The dstar interleave pattern is different as well. 22 | * GMSK modulation optimizations will also required to get a usable bit error 23 | */ 24 | 25 | #include "dsd.h" 26 | #include "dstar_const.h" 27 | #include "dstar_header.h" 28 | 29 | 30 | void processDSTAR(dsd_opts * opts, dsd_state * state) { 31 | // extracts AMBE frames from D-STAR voice frame 32 | int i, j, dibit; 33 | char ambe_fr[4][24]; 34 | unsigned char data[9]; 35 | unsigned int bits[4]; 36 | int framecount; 37 | int sync_missed = 0; 38 | unsigned char slowdata[4]; 39 | unsigned int bitbuffer = 0; 40 | const int *w, *x; 41 | 42 | if (opts->errorbars == 1) { 43 | printf("e:"); 44 | } 45 | 46 | #ifdef DSTAR_DUMP 47 | printf ("\n"); 48 | #endif 49 | 50 | if (state->synctype == 18) { 51 | framecount = 0; 52 | state->synctype = 6; 53 | } else if (state->synctype == 19) { 54 | framecount = 0; 55 | state->synctype = 7; 56 | } else { 57 | framecount = 1; //just saw a sync frame; there should be 20 not 21 till the next 58 | } 59 | 60 | while (sync_missed < 3) { 61 | 62 | memset(ambe_fr, 0, 96); 63 | // voice frame 64 | w = dW; 65 | x = dX; 66 | 67 | for (i = 0; i < 72; i++) { 68 | 69 | dibit = getDibit(opts, state); 70 | 71 | bitbuffer <<= 1; 72 | if (dibit == 1) { 73 | bitbuffer |= 0x01; 74 | } 75 | if ((bitbuffer & 0x00FFFFFF) == 0x00AAB468) { 76 | // we're slipping bits 77 | printf("sync in voice after i=%d, restarting\n", i); 78 | //ugh just start over 79 | i = 0; 80 | w = dW; 81 | x = dX; 82 | framecount = 1; 83 | continue; 84 | } 85 | 86 | ambe_fr[*w][*x] = (1 & dibit); 87 | w++; 88 | x++; 89 | } 90 | 91 | 92 | processMbeFrame(opts, state, NULL, ambe_fr, NULL); 93 | 94 | // data frame - 24 bits 95 | for (i = 73; i < 97; i++) { 96 | dibit = getDibit(opts, state); 97 | bitbuffer <<= 1; 98 | if (dibit == 1) { 99 | bitbuffer |= 0x01; 100 | } 101 | if ((bitbuffer & 0x00FFFFFF) == 0x00AAB468) { 102 | // looking if we're slipping bits 103 | if (i != 96) { 104 | printf("sync after i=%d\n", i); 105 | i = 96; 106 | } 107 | } 108 | } 109 | 110 | slowdata[0] = (bitbuffer >> 16) & 0x000000FF; 111 | slowdata[1] = (bitbuffer >> 8) & 0x000000FF; 112 | slowdata[2] = (bitbuffer) & 0x000000FF; 113 | slowdata[3] = 0; 114 | 115 | if ((bitbuffer & 0x00FFFFFF) == 0x00AAB468) { 116 | //We got sync! 117 | //printf("Sync on framecount = %d\n", framecount); 118 | sync_missed = 0; 119 | } else if ((bitbuffer & 0x00FFFFFF) == 0xAAAAAA) { 120 | //End of transmission 121 | printf("End of transmission\n"); 122 | goto end; 123 | } else if (framecount % 21 == 0) { 124 | printf("Missed sync on framecount = %d, value = %x/%x/%x\n", 125 | framecount, slowdata[0], slowdata[1], slowdata[2]); 126 | sync_missed++; 127 | } else if (framecount != 0 && (bitbuffer & 0x00FFFFFF) != 0x000000) { 128 | slowdata[0] ^= 0x70; 129 | slowdata[1] ^= 0x4f; 130 | slowdata[2] ^= 0x93; 131 | //printf("unscrambled- %s",slowdata); 132 | 133 | } else if (framecount == 0) { 134 | //printf("never scrambled-%s\n",slowdata); 135 | } 136 | 137 | framecount++; 138 | } 139 | 140 | end: if (opts->errorbars == 1) { 141 | printf("\n"); 142 | } 143 | } 144 | 145 | void processDSTAR_HD(dsd_opts * opts, dsd_state * state) { 146 | 147 | int i, j; 148 | int radioheaderbuffer[660]; 149 | 150 | for (j = 0; j < 660; j++) { 151 | radioheaderbuffer[j] = getDibit(opts, state); 152 | } 153 | 154 | // Note: These routines contain GPLed code. Remove if you object to that. 155 | // Due to this, they are in a separate source file. 156 | dstar_header_decode(radioheaderbuffer); 157 | 158 | //We officially have sync now, so just pass on to the above routine: 159 | 160 | processDSTAR(opts, state); 161 | 162 | } 163 | 164 | -------------------------------------------------------------------------------- /src/dstar_header.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * This code is taken largely from on1arf's GMSK code. Original copyright below: 4 | * 5 | * 6 | * Copyright (C) 2011 by Kristoff Bonne, ON1ARF 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; version 2 of the License. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | */ 18 | 19 | #include "fcs.h" 20 | #include "descramble.h" 21 | #include "dstar_header.h" 22 | 23 | void dstar_header_decode(int radioheaderbuffer[660]) { 24 | int radioheaderbuffer2[660]; 25 | unsigned char radioheader[41]; 26 | int octetcount, bitcount, loop; 27 | unsigned char bit2octet[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; 28 | unsigned int FCSinheader; 29 | unsigned int FCScalculated; 30 | int len; 31 | 32 | scramble(radioheaderbuffer, radioheaderbuffer2); 33 | deinterleave(radioheaderbuffer2, radioheaderbuffer); 34 | len = FECdecoder(radioheaderbuffer, radioheaderbuffer2); 35 | memset(radioheader, 0, 41); 36 | // note we receive 330 bits, but we only use 328 of them (41 octets) 37 | // bits 329 and 330 are unused 38 | octetcount = 0; 39 | bitcount = 0; 40 | for (loop = 0; loop < 328; loop++) { 41 | if (radioheaderbuffer2[loop]) { 42 | radioheader[octetcount] |= bit2octet[bitcount]; 43 | }; 44 | bitcount++; 45 | // increase octetcounter and reset bitcounter every 8 bits 46 | if (bitcount >= 8) { 47 | octetcount++; 48 | bitcount = 0; 49 | } 50 | } 51 | // print header 52 | printf("\nDSTAR HEADER: "); 53 | //printf("FLAG1: %02X - FLAG2: %02X - FLAG3: %02X\n", radioheader[0], 54 | // radioheader[1], radioheader[2]); 55 | printf("RPT 2: %c%c%c%c%c%c%c%c ", radioheader[3], radioheader[4], 56 | radioheader[5], radioheader[6], radioheader[7], radioheader[8], 57 | radioheader[9], radioheader[10]); 58 | printf("RPT 1: %c%c%c%c%c%c%c%c ", radioheader[11], radioheader[12], 59 | radioheader[13], radioheader[14], radioheader[15], radioheader[16], 60 | radioheader[17], radioheader[18]); 61 | printf("YOUR: %c%c%c%c%c%c%c%c ", radioheader[19], radioheader[20], 62 | radioheader[21], radioheader[22], radioheader[23], radioheader[24], 63 | radioheader[25], radioheader[26]); 64 | printf("MY: %c%c%c%c%c%c%c%c/%c%c%c%c\n", radioheader[27], 65 | radioheader[28], radioheader[29], radioheader[30], radioheader[31], 66 | radioheader[32], radioheader[33], radioheader[34], radioheader[35], 67 | radioheader[36], radioheader[37], radioheader[38]); 68 | //FCSinheader = ((radioheader[39] << 8) | radioheader[40]) & 0xFFFF; 69 | //FCScalculated = calc_fcs((unsigned char*) radioheader, 39); 70 | //printf("Check sum = %04X ", FCSinheader); 71 | //if (FCSinheader == FCScalculated) { 72 | // printf("(OK)\n"); 73 | //} else { 74 | // printf("(NOT OK- Calculated FCS = %04X)\n", FCScalculated); 75 | //}; // end else - if 76 | } 77 | -------------------------------------------------------------------------------- /src/git_ver.c.in: -------------------------------------------------------------------------------- 1 | #define _GIT_TAG "@GIT_TAG@" 2 | const char GIT_TAG[] = _GIT_TAG; 3 | -------------------------------------------------------------------------------- /src/nxdn96.c: -------------------------------------------------------------------------------- 1 | #include "dsd.h" 2 | #include "nxdn96_const.h" 3 | 4 | void 5 | processNXDN96 (dsd_opts * opts, dsd_state * state) 6 | { 7 | int i, j, k, dibit; 8 | 9 | char ambe_fr[4][24]; 10 | const int *w, *x, *y, *z; 11 | 12 | if (opts->errorbars == 1) 13 | { 14 | printf ("VOICE e:"); 15 | } 16 | 17 | #ifdef NXDN_DUMP 18 | printf ("\n"); 19 | #endif 20 | 21 | for (k = 0; k < 4; k++) 22 | { 23 | for (i = 0; i < 222; i++) 24 | { 25 | dibit = getDibit (opts, state); 26 | #ifdef NXDN_DUMP 27 | printf ("%c", dibit + 48); 28 | #endif 29 | } 30 | #ifdef NXDN_DUMP 31 | printf (" "); 32 | #endif 33 | 34 | if (k < 3) 35 | { 36 | for (j = 0; j < 4; j++) 37 | { 38 | w = nW; 39 | x = nX; 40 | y = nY; 41 | z = nZ; 42 | for (i = 0; i < 36; i++) 43 | { 44 | dibit = getDibit (opts, state); 45 | #ifdef NXDN_DUMP 46 | printf ("%c", dibit + 48); 47 | #endif 48 | ambe_fr[*w][*x] = (1 & (dibit >> 1)); // bit 1 49 | ambe_fr[*y][*z] = (1 & dibit); // bit 0 50 | w++; 51 | x++; 52 | y++; 53 | z++; 54 | } 55 | processMbeFrame (opts, state, NULL, ambe_fr, NULL); 56 | #ifdef NXDN_DUMP 57 | printf (" "); 58 | #endif 59 | } 60 | } 61 | else 62 | { 63 | for (j = 0; j < 3; j++) // we skip the last voice frame until frame sync can work with < 24 symbols 64 | { 65 | w = nW; 66 | x = nX; 67 | y = nY; 68 | z = nZ; 69 | for (i = 0; i < 36; i++) 70 | { 71 | dibit = getDibit (opts, state); 72 | #ifdef NXDN_DUMP 73 | printf ("%c", dibit + 48); 74 | #endif 75 | ambe_fr[*w][*x] = (1 & (dibit >> 1)); // bit 1 76 | ambe_fr[*y][*z] = (1 & dibit); // bit 0 77 | w++; 78 | x++; 79 | y++; 80 | z++; 81 | } 82 | processMbeFrame (opts, state, NULL, ambe_fr, NULL); 83 | #ifdef NXDN_DUMP 84 | printf (" "); 85 | #endif 86 | } 87 | } 88 | 89 | if (k < 3) 90 | { 91 | for (i = 0; i < 18; i++) 92 | { 93 | dibit = getDibit (opts, state); 94 | #ifdef NXDN_DUMP 95 | printf ("%c", dibit + 48); 96 | #endif 97 | } 98 | #ifdef NXDN_DUMP 99 | printf (" "); 100 | #endif 101 | 102 | } 103 | else 104 | { 105 | for (i = 0; i < 30; i++) 106 | { 107 | dibit = getDibit (opts, state); 108 | #ifdef NXDN_DUMP 109 | printf ("%c", dibit + 48); 110 | #endif 111 | } 112 | } 113 | } 114 | 115 | #ifdef NXDN_DUMP 116 | printf ("\n"); 117 | #endif 118 | 119 | if (opts->errorbars == 1) 120 | { 121 | printf ("\n"); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/nxdn_data.c: -------------------------------------------------------------------------------- 1 | #include "dsd.h" 2 | 3 | void 4 | processNXDNData (dsd_opts * opts, dsd_state * state) 5 | { 6 | int i, dibit; 7 | 8 | if (opts->errorbars == 1) 9 | { 10 | printf ("DATA "); 11 | } 12 | 13 | for (i = 0; i < 30; i++) 14 | { 15 | dibit = getDibit (opts, state); 16 | #ifdef NXDN_DUMP 17 | printf ("%c", dibit + 48); 18 | #endif 19 | } 20 | #ifdef NXDN_DUMP 21 | printf (" "); 22 | #endif 23 | 24 | for (i = 0; i < 144; i++) 25 | { 26 | dibit = getDibit (opts, state); 27 | #ifdef NXDN_DUMP 28 | printf ("%c", dibit + 48); 29 | #endif 30 | } 31 | 32 | if (opts->errorbars == 1) 33 | { 34 | printf ("\n"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/nxdn_voice.c: -------------------------------------------------------------------------------- 1 | #include "dsd.h" 2 | #include "nxdn_const.h" 3 | 4 | void 5 | processNXDNVoice (dsd_opts * opts, dsd_state * state) 6 | { 7 | int i, j, dibit; 8 | char ambe_fr[4][24]; 9 | const int *w, *x, *y, *z; 10 | const char *pr; 11 | 12 | if (opts->errorbars == 1) 13 | { 14 | printf ("VOICE e:"); 15 | } 16 | 17 | for (i = 0; i < 30; i++) 18 | { 19 | dibit = getDibit (opts, state); 20 | #ifdef NXDN_DUMP 21 | printf ("%c", dibit + 48); 22 | #endif 23 | } 24 | #ifdef NXDN_DUMP 25 | printf (" "); 26 | #endif 27 | 28 | pr = nxdnpr; 29 | for (j = 0; j < 4; j++) 30 | { 31 | w = nW; 32 | x = nX; 33 | y = nY; 34 | z = nZ; 35 | for (i = 0; i < 36; i++) 36 | { 37 | dibit = getDibit (opts, state); 38 | #ifdef NXDN_DUMP 39 | printf ("%c", dibit + 48); 40 | #endif 41 | ambe_fr[*w][*x] = *pr ^ (1 & (dibit >> 1)); // bit 1 42 | pr++; 43 | ambe_fr[*y][*z] = (1 & dibit); // bit 0 44 | w++; 45 | x++; 46 | y++; 47 | z++; 48 | } 49 | processMbeFrame (opts, state, NULL, ambe_fr, NULL); 50 | #ifdef NXDN_DUMP 51 | printf (" "); 52 | #endif 53 | } 54 | 55 | if (opts->errorbars == 1) 56 | { 57 | printf ("\n"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/p25_lcw.c: -------------------------------------------------------------------------------- 1 | #include "dsd.h" 2 | 3 | void 4 | processP25lcw (dsd_opts * opts, dsd_state * state, char *lcformat, char *mfid, char *lcinfo) 5 | { 6 | 7 | char tgid[17], tmpstr[255]; 8 | long talkgroup, source; 9 | int i, j; 10 | 11 | tgid[16] = 0; 12 | 13 | if (opts->p25lc == 1) 14 | { 15 | printf ("lcformat: %s mfid: %s lcinfo: %s ", lcformat, mfid, lcinfo); 16 | if (opts->p25tg == 0) 17 | { 18 | printf ("\n"); 19 | } 20 | } 21 | 22 | if (strcmp (lcformat, "00000100") == 0) 23 | { 24 | 25 | // first tg is the active channel 26 | j = 0; 27 | for (i = 40; i < 52; i++) 28 | { 29 | if (state->tgcount < 24) 30 | { 31 | state->tg[state->tgcount][j] = lcinfo[i]; 32 | } 33 | tmpstr[j] = lcinfo[i]; 34 | j++; 35 | } 36 | tmpstr[12] = 48; 37 | tmpstr[13] = 48; 38 | tmpstr[14] = 48; 39 | tmpstr[15] = 48; 40 | tmpstr[16] = 0; 41 | talkgroup = strtol (tmpstr, NULL, 2); 42 | state->lasttg = talkgroup; 43 | if (state->tgcount < 24) 44 | { 45 | state->tgcount = state->tgcount + 1; 46 | } 47 | if (opts->p25tg == 1) 48 | { 49 | printf ("tg: %li ", talkgroup); 50 | } 51 | 52 | if (opts->p25tg == 1) 53 | { 54 | printf ("tg: %li ", talkgroup); 55 | 56 | // the remaining 3 appear to be other active tg's on the system 57 | j = 0; 58 | for (i = 28; i < 40; i++) 59 | { 60 | tmpstr[j] = lcinfo[i]; 61 | j++; 62 | } 63 | tmpstr[12] = 48; 64 | tmpstr[13] = 48; 65 | tmpstr[14] = 48; 66 | tmpstr[15] = 48; 67 | tmpstr[16] = 0; 68 | talkgroup = strtol (tmpstr, NULL, 2); 69 | printf ("%li ", talkgroup); 70 | j = 0; 71 | for (i = 16; i < 28; i++) 72 | { 73 | tmpstr[j] = lcinfo[i]; 74 | j++; 75 | } 76 | tmpstr[12] = 48; 77 | tmpstr[13] = 48; 78 | tmpstr[14] = 48; 79 | tmpstr[15] = 48; 80 | tmpstr[16] = 0; 81 | talkgroup = strtol (tmpstr, NULL, 2); 82 | printf ("%li ", talkgroup); 83 | j = 0; 84 | for (i = 4; i < 16; i++) 85 | { 86 | tmpstr[j] = lcinfo[i]; 87 | j++; 88 | } 89 | tmpstr[12] = 48; 90 | tmpstr[13] = 48; 91 | tmpstr[14] = 48; 92 | tmpstr[15] = 48; 93 | tmpstr[16] = 0; 94 | talkgroup = strtol (tmpstr, NULL, 2); 95 | printf ("%li\n", talkgroup); 96 | } 97 | } 98 | 99 | else if (strcmp (lcformat, "00000000") == 0) 100 | { 101 | j = 0; 102 | if (strcmp (mfid, "10010000") == 0) 103 | { 104 | for (i = 20; i < 32; i++) 105 | { 106 | if (state->tgcount < 24) 107 | { 108 | state->tg[state->tgcount][j] = lcinfo[i]; 109 | } 110 | tmpstr[j] = lcinfo[i]; 111 | j++; 112 | } 113 | tmpstr[12] = 48; 114 | tmpstr[13] = 48; 115 | tmpstr[14] = 48; 116 | tmpstr[15] = 48; 117 | } 118 | else 119 | { 120 | for (i = 16; i < 32; i++) 121 | { 122 | if (state->tgcount < 24) 123 | { 124 | state->tg[state->tgcount][j] = lcinfo[i]; 125 | } 126 | tmpstr[j] = lcinfo[i]; 127 | j++; 128 | } 129 | } 130 | tmpstr[16] = 0; 131 | talkgroup = strtol (tmpstr, NULL, 2); 132 | state->lasttg = talkgroup; 133 | if (state->tgcount < 24) 134 | { 135 | state->tgcount = state->tgcount + 1; 136 | } 137 | if (opts->p25tg == 1) 138 | { 139 | printf ("tg: %li ", talkgroup); 140 | } 141 | 142 | j = 0; 143 | for (i = 32; i < 56; i++) 144 | { 145 | tmpstr[j] = lcinfo[i]; 146 | j++; 147 | } 148 | tmpstr[24] = 0; 149 | source = strtol (tmpstr, NULL, 2); 150 | state->lastsrc = source; 151 | if (opts->p25tg == 1) 152 | { 153 | printf ("src: %li emr: %c\n", source, lcinfo[0]); 154 | } 155 | } 156 | else if ((opts->p25tg == 1) && (opts->p25lc == 1)) 157 | { 158 | printf ("\n"); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/p25p1_check_hdu.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "p25p1_check_hdu.h" 3 | #include "ReedSolomon.hpp" 4 | #include "Golay24.hpp" 5 | 6 | // Uncomment for very verbose trace messages 7 | //#define CHECK_HDU_DEBUG 8 | 9 | // The following methods are just a C bridge for the C++ implementations of the Golay and ReedSolomon 10 | // algorithms. 11 | 12 | static DSDGolay24 golay24; 13 | 14 | static DSDReedSolomon_36_20_17 reed_solomon_36_20_17; 15 | 16 | int check_and_fix_golay_24_6(char* hex, char* parity, int* fixed_errors) 17 | { 18 | #ifdef CHECK_HDU_DEBUG 19 | printf("["); 20 | for(unsigned int i=0; i<6; i++) { 21 | printf("%c", (hex[i] != 0)? 'X': ' '); 22 | } 23 | printf("] ["); 24 | for(unsigned int i=12; i<24; i++) { 25 | printf("%c", (parity[i-12] != 0)? 'X': ' '); 26 | } 27 | printf("]"); 28 | #endif 29 | 30 | int irrecoverable_errors = golay24.decode_6(hex, parity, fixed_errors); 31 | 32 | #ifdef CHECK_HDU_DEBUG 33 | printf(" -> ["); 34 | for(unsigned int i=0; i<6; i++) { 35 | printf("%c", (hex[i] != 0)? 'X': ' '); 36 | } 37 | printf("]"); 38 | if (irrecoverable_errors) { 39 | printf(" Errors: >4"); 40 | } else { 41 | printf(" Errors: %i", *fixed_errors); 42 | } 43 | printf("\n"); 44 | #endif 45 | 46 | return irrecoverable_errors; 47 | } 48 | 49 | int check_and_fix_golay_24_12(char* dodeca, char* parity, int* fixed_errors) 50 | { 51 | #ifdef CHECK_HDU_DEBUG 52 | printf("["); 53 | for(unsigned int i=0; i<12; i++) { 54 | printf("%c", (dodeca[i] != 0)? 'X': ' '); 55 | } 56 | printf("] ["); 57 | for(unsigned int i=12; i<24; i++) { 58 | printf("%c", (parity[i-12] != 0)? 'X': ' '); 59 | } 60 | printf("]"); 61 | #endif 62 | 63 | int irrecoverable_errors = golay24.decode_12(dodeca, parity, fixed_errors); 64 | 65 | #ifdef CHECK_HDU_DEBUG 66 | printf(" -> ["); 67 | for(unsigned int i=0; i<12; i++) { 68 | printf("%c", (dodeca[i] != 0)? 'X': ' '); 69 | } 70 | printf("]"); 71 | if (irrecoverable_errors) { 72 | printf(" Errors: >4"); 73 | } else { 74 | printf(" Errors: %i", *fixed_errors); 75 | } 76 | printf("\n"); 77 | #endif 78 | 79 | return irrecoverable_errors; 80 | } 81 | 82 | void encode_golay_24_6(char* hex, char* out_parity) 83 | { 84 | golay24.encode_6(hex, out_parity); 85 | } 86 | 87 | void encode_golay_24_12(char* dodeca, char* out_parity) 88 | { 89 | golay24.encode_12(dodeca, out_parity); 90 | } 91 | 92 | 93 | int check_and_fix_redsolomon_36_20_17(char* data, char* parity) 94 | { 95 | #ifdef CHECK_HDU_DEBUG 96 | char original[20][6]; 97 | for (int i = 0; i < 20; i++) { 98 | for (int j = 0; j < 6; j++) { 99 | original[i][j] = data[i*6+j]; 100 | } 101 | } 102 | #endif 103 | 104 | int irrecoverable_errors = reed_solomon_36_20_17.decode(data, parity); 105 | 106 | #ifdef CHECK_HDU_DEBUG 107 | printf("Results for Reed-Solomon code (36,20,17)\n\n"); 108 | if (irrecoverable_errors == 0) { 109 | printf(" i original fixed\n"); 110 | for (int i = 0; i < 20; i++) { 111 | printf("%3d [", i); 112 | for (int j = 0; j < 6; j++) { 113 | printf("%c", (original[i][j] == 1)? 'X' : ' '); 114 | } 115 | printf("] ["); 116 | for (int j = 0; j < 6; j++) { 117 | printf("%c", (data[i*6+j] == 1)? 'X' : ' '); 118 | } 119 | printf("]\n"); 120 | } 121 | } else { 122 | printf("Irrecoverable errors found\n"); 123 | printf(" i original fixed\n"); 124 | for (int i = 0; i < 20; i++) { 125 | printf("%3d [", i); 126 | for (int j = 0; j < 6; j++) { 127 | printf("%c", (original[i][j] == 1)? 'X' : ' '); 128 | } 129 | printf("]\n"); 130 | } 131 | } 132 | printf("\n"); 133 | #endif 134 | 135 | return irrecoverable_errors; 136 | } 137 | 138 | void encode_reedsolomon_36_20_17(char* hex_data, char* fixed_parity) 139 | { 140 | reed_solomon_36_20_17.encode(hex_data, fixed_parity); 141 | } 142 | 143 | -------------------------------------------------------------------------------- /src/p25p1_check_ldu.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "p25p1_check_ldu.h" 3 | 4 | #include "Hamming.hpp" 5 | #include "ReedSolomon.hpp" 6 | 7 | // Uncomment for very verbose trace messages 8 | //#define CHECK_LDU_DEBUG 9 | 10 | // The following methods are just a C bridge for the C++ implementations of the Golay and ReedSolomon 11 | // algorithms. 12 | 13 | static Hamming_10_6_3_TableImpl hamming; 14 | static DSDReedSolomon_24_12_13 reed_solomon_24_12_13; 15 | static DSDReedSolomon_24_16_9 reed_solomon_24_16_9; 16 | 17 | int check_and_fix_hamming_10_6_3(char* hex, char* parity) 18 | { 19 | return hamming.decode(hex, parity); 20 | } 21 | 22 | void encode_hamming_10_6_3(char* hex, char* out_parity) 23 | { 24 | hamming.encode(hex, out_parity); 25 | } 26 | 27 | int check_and_fix_reedsolomon_24_12_13(char* data, char* parity) 28 | { 29 | #ifdef CHECK_LDU_DEBUG 30 | char original[12][6]; 31 | for (int i = 0; i < 12; i++) { 32 | for (int j = 0; j < 6; j++) { 33 | original[i][j] = data[i*6+j]; 34 | } 35 | } 36 | #endif 37 | 38 | int irrecoverable_error = reed_solomon_24_12_13.decode(data, parity); 39 | 40 | #ifdef CHECK_LDU_DEBUG 41 | printf("Results for Reed-Solomon code (24,12,13)\n\n"); 42 | if (irrecoverable_error == 0) { 43 | printf(" i original fixed\n"); 44 | for (int i = 0; i < 12; i++) { 45 | printf("%3d [", i); 46 | for (int j = 0; j < 6; j++) { 47 | printf("%c", (original[i][j] == 1)? 'X' : ' '); 48 | } 49 | printf("] ["); 50 | for (int j = 0; j < 6; j++) { 51 | printf("%c", (data[i*6+j] == 1)? 'X' : ' '); 52 | } 53 | printf("]\n"); 54 | } 55 | } else { 56 | printf("Irrecoverable errors found\n"); 57 | printf(" i original fixed\n"); 58 | for (int i = 0; i < 12; i++) { 59 | printf("%3d [", i); 60 | for (int j = 0; j < 6; j++) { 61 | printf("%c", (original[i][j] == 1)? 'X' : ' '); 62 | } 63 | printf("]\n"); 64 | } 65 | } 66 | printf("\n"); 67 | #endif 68 | 69 | return irrecoverable_error; 70 | } 71 | 72 | void encode_reedsolomon_24_12_13(char* hex_data, char* fixed_parity) 73 | { 74 | reed_solomon_24_12_13.encode(hex_data, fixed_parity); 75 | } 76 | 77 | int check_and_fix_reedsolomon_24_16_9(char* data, char* parity) 78 | { 79 | #ifdef CHECK_LDU_DEBUG 80 | char original[16][6]; 81 | for (int i = 0; i < 16; i++) { 82 | for (int j = 0; j < 6; j++) { 83 | original[i][j] = data[i*6+j]; 84 | } 85 | } 86 | #endif 87 | 88 | int irrecoverable_error = reed_solomon_24_16_9.decode(data, parity); 89 | 90 | #ifdef CHECK_LDU_DEBUG 91 | printf("Results for Reed-Solomon code (24,16,9)\n\n"); 92 | if (irrecoverable_error == 0) { 93 | printf(" i original fixed\n"); 94 | for (int i = 0; i < 16; i++) { 95 | printf("%3d [", i); 96 | for (int j = 0; j < 6; j++) { 97 | printf("%c", (original[i][j] == 1)? 'X' : ' '); 98 | } 99 | printf("] ["); 100 | for (int j = 0; j < 6; j++) { 101 | printf("%c", (data[i*6+j] == 1)? 'X' : ' '); 102 | } 103 | printf("]\n"); 104 | } 105 | } else { 106 | printf("Irrecoverable errors found\n"); 107 | printf(" i original fixed\n"); 108 | for (int i = 0; i < 16; i++) { 109 | printf("%3d [", i); 110 | for (int j = 0; j < 6; j++) { 111 | printf("%c", (original[i][j] == 1)? 'X' : ' '); 112 | } 113 | printf("]\n"); 114 | } 115 | } 116 | printf("\n"); 117 | #endif 118 | 119 | return irrecoverable_error; 120 | } 121 | 122 | void encode_reedsolomon_24_16_9(char* hex_data, char* fixed_parity) 123 | { 124 | reed_solomon_24_16_9.encode(hex_data, fixed_parity); 125 | } 126 | -------------------------------------------------------------------------------- /src/p25p1_check_nid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "p25p1_check_nid.h" 4 | 5 | 6 | 7 | using namespace itpp; 8 | 9 | // Ideas taken from http://op25.osmocom.org/trac/wiki.png/browser/op25/gr-op25/lib/decoder_ff_impl.cc 10 | // See also p25_training_guide.pdf page 48. 11 | // See also tia-102-baaa-a-project_25-fdma-common_air_interface.pdf page 40. 12 | // BCH encoder/decoder implementation from IT++. GNU GPL 3 license. 13 | 14 | itpp::BCH bch(63, 16, 11, "6 3 3 1 1 4 1 3 6 7 2 3 5 4 5 3", true); 15 | 16 | /** 17 | * Convenience class to calculate the parity of the DUID values. Keeps a table with the expected outcomes 18 | * for fast lookup. 19 | */ 20 | class ParityTable 21 | { 22 | private: 23 | unsigned char table[16]; 24 | 25 | unsigned char get_index(unsigned char x, unsigned char y) 26 | { 27 | return (x<<2) + y; 28 | } 29 | 30 | public: 31 | ParityTable() 32 | { 33 | for (unsigned int i=0; i 2 | 3 | #ifdef USE_PORTAUDIO 4 | #include 5 | 6 | #ifdef WIN32 7 | #include 8 | #endif 9 | 10 | void printPortAudioDevices() 11 | { 12 | int i, numDevices, defaultDisplayed; 13 | const PaDeviceInfo *deviceInfo; 14 | PaStreamParameters inputParameters, outputParameters; 15 | PaError err; 16 | 17 | 18 | Pa_Initialize(); 19 | 20 | printf( "\nPortAudio version number = %d\nPortAudio version text = '%s'\n", 21 | Pa_GetVersion(), Pa_GetVersionText() ); 22 | 23 | 24 | numDevices = Pa_GetDeviceCount(); 25 | if( numDevices < 0 ) 26 | { 27 | printf( "ERROR: Pa_GetDeviceCount returned 0x%x\n", numDevices ); 28 | err = numDevices; 29 | goto error; 30 | } 31 | 32 | printf( "Number of devices = %d\n", numDevices ); 33 | for( i=0; ihostApi )->defaultInputDevice ) 46 | { 47 | const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 48 | printf( "[ Default %s Input", hostInfo->name ); 49 | defaultDisplayed = 1; 50 | } 51 | 52 | if( i == Pa_GetDefaultOutputDevice() ) 53 | { 54 | printf( (defaultDisplayed ? "," : "[") ); 55 | printf( " Default Output" ); 56 | defaultDisplayed = 1; 57 | } 58 | else if( i == Pa_GetHostApiInfo( deviceInfo->hostApi )->defaultOutputDevice ) 59 | { 60 | const PaHostApiInfo *hostInfo = Pa_GetHostApiInfo( deviceInfo->hostApi ); 61 | printf( (defaultDisplayed ? "," : "[") ); 62 | printf( " Default %s Output", hostInfo->name ); 63 | defaultDisplayed = 1; 64 | } 65 | 66 | if( defaultDisplayed ) 67 | printf( " ]\n" ); 68 | 69 | /* print device info fields */ 70 | #ifdef WIN32 71 | { /* Use wide char on windows, so we can show UTF-8 encoded device names */ 72 | wchar_t wideName[MAX_PATH]; 73 | MultiByteToWideChar(CP_UTF8, 0, deviceInfo->name, -1, wideName, MAX_PATH-1); 74 | wprintf( L"Name = %s\n", wideName ); 75 | } 76 | #else 77 | printf( "Name = %s\n", deviceInfo->name ); 78 | #endif 79 | printf( "Host API = %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name ); 80 | printf( "Max inputs = %d", deviceInfo->maxInputChannels ); 81 | printf( ", Max outputs = %d\n", deviceInfo->maxOutputChannels ); 82 | printf( "Default sample rate = %8.2f\n", deviceInfo->defaultSampleRate ); 83 | } 84 | 85 | Pa_Terminate(); 86 | 87 | printf("----------------------------------------------\n"); 88 | return; 89 | 90 | error: 91 | Pa_Terminate(); 92 | fprintf( stderr, "An error occured while using the portaudio stream\n" ); 93 | fprintf( stderr, "Error number: %d\n", err ); 94 | fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); 95 | } 96 | 97 | #else 98 | 99 | void printPortAudioDevices() 100 | { 101 | printf("PortAudio not supported in this build of dsd\n"); 102 | } 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/x2tdma_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 DSD Author 3 | * GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include "dsd.h" 19 | 20 | void 21 | processX2TDMAdata (dsd_opts * opts, dsd_state * state) 22 | { 23 | 24 | int i, dibit; 25 | int *dibit_p; 26 | char sync[25]; 27 | char syncdata[25]; 28 | char cachdata[13]; 29 | char cc[4]; 30 | int aiei; 31 | char bursttype[5]; 32 | 33 | #ifdef X2TDMA_DUMP 34 | int k; 35 | char syncbits[49]; 36 | char cachbits[25]; 37 | #endif 38 | 39 | cc[3] = 0; 40 | bursttype[4] = 0; 41 | 42 | dibit_p = state->dibit_buf_p - 90; 43 | 44 | // CACH 45 | for (i = 0; i < 12; i++) 46 | { 47 | dibit = *dibit_p; 48 | dibit_p++; 49 | if (opts->inverted_x2tdma == 1) 50 | { 51 | dibit = (dibit ^ 2); 52 | } 53 | cachdata[i] = dibit; 54 | if (i == 2) 55 | { 56 | state->currentslot = (1 & (dibit >> 1)); // bit 1 57 | if (state->currentslot == 0) 58 | { 59 | state->slot0light[0] = '['; 60 | state->slot0light[6] = ']'; 61 | state->slot1light[0] = ' '; 62 | state->slot1light[6] = ' '; 63 | } 64 | else 65 | { 66 | state->slot1light[0] = '['; 67 | state->slot1light[6] = ']'; 68 | state->slot0light[0] = ' '; 69 | state->slot0light[6] = ' '; 70 | } 71 | } 72 | } 73 | cachdata[12] = 0; 74 | 75 | #ifdef X2TDMA_DUMP 76 | k = 0; 77 | for (i = 0; i < 12; i++) 78 | { 79 | dibit = cachdata[i]; 80 | cachbits[k] = (1 & (dibit >> 1)) + 48; // bit 1 81 | k++; 82 | cachbits[k] = (1 & dibit) + 48; // bit 0 83 | k++; 84 | } 85 | cachbits[24] = 0; 86 | printf ("%s ", cachbits); 87 | #endif 88 | 89 | // current slot 90 | dibit_p += 49; 91 | 92 | // slot type 93 | dibit = *dibit_p; 94 | dibit_p++; 95 | if (opts->inverted_x2tdma == 1) 96 | { 97 | dibit = (dibit ^ 2); 98 | } 99 | cc[0] = (1 & (dibit >> 1)) + 48; // bit 1 100 | cc[1] = (1 & dibit) + 48; // bit 0 101 | 102 | dibit = *dibit_p; 103 | dibit_p++; 104 | if (opts->inverted_x2tdma == 1) 105 | { 106 | dibit = (dibit ^ 2); 107 | } 108 | cc[2] = (1 & (dibit >> 1)) + 48; // bit 1 109 | aiei = (1 & dibit); // bit 0 110 | 111 | dibit = *dibit_p; 112 | dibit_p++; 113 | if (opts->inverted_x2tdma == 1) 114 | { 115 | dibit = (dibit ^ 2); 116 | } 117 | bursttype[0] = (1 & (dibit >> 1)) + 48; // bit 1 118 | bursttype[1] = (1 & dibit) + 48; // bit 0 119 | 120 | dibit = *dibit_p; 121 | dibit_p++; 122 | if (opts->inverted_x2tdma == 1) 123 | { 124 | dibit = (dibit ^ 2); 125 | } 126 | bursttype[2] = (1 & (dibit >> 1)) + 48; // bit 1 127 | bursttype[3] = (1 & dibit) + 48; // bit 0 128 | 129 | // parity bit 130 | dibit_p++; 131 | 132 | if (strcmp (bursttype, "0000") == 0) 133 | { 134 | sprintf (state->fsubtype, " PI Header "); 135 | } 136 | else if (strcmp (bursttype, "0001") == 0) 137 | { 138 | sprintf (state->fsubtype, " VOICE Header "); 139 | } 140 | else if (strcmp (bursttype, "0010") == 0) 141 | { 142 | sprintf (state->fsubtype, " TLC "); 143 | } 144 | else if (strcmp (bursttype, "0011") == 0) 145 | { 146 | sprintf (state->fsubtype, " CSBK "); 147 | } 148 | else if (strcmp (bursttype, "0100") == 0) 149 | { 150 | sprintf (state->fsubtype, " MBC Header "); 151 | } 152 | else if (strcmp (bursttype, "0101") == 0) 153 | { 154 | sprintf (state->fsubtype, " MBC "); 155 | } 156 | else if (strcmp (bursttype, "0110") == 0) 157 | { 158 | sprintf (state->fsubtype, " DATA Header "); 159 | } 160 | else if (strcmp (bursttype, "0111") == 0) 161 | { 162 | sprintf (state->fsubtype, " RATE 1/2 DATA"); 163 | } 164 | else if (strcmp (bursttype, "1000") == 0) 165 | { 166 | sprintf (state->fsubtype, " RATE 3/4 DATA"); 167 | } 168 | else if (strcmp (bursttype, "1001") == 0) 169 | { 170 | sprintf (state->fsubtype, " Slot idle "); 171 | } 172 | else if (strcmp (bursttype, "1010") == 0) 173 | { 174 | sprintf (state->fsubtype, " Rate 1 DATA "); 175 | } 176 | else 177 | { 178 | sprintf (state->fsubtype, " "); 179 | } 180 | 181 | // signaling data or sync 182 | for (i = 0; i < 24; i++) 183 | { 184 | dibit = *dibit_p; 185 | dibit_p++; 186 | if (opts->inverted_x2tdma == 1) 187 | { 188 | dibit = (dibit ^ 2); 189 | } 190 | syncdata[i] = dibit; 191 | sync[i] = (dibit | 1) + 48; 192 | } 193 | sync[24] = 0; 194 | syncdata[24] = 0; 195 | 196 | #ifdef X2TDMA_DUMP 197 | k = 0; 198 | for (i = 0; i < 24; i++) 199 | { 200 | dibit = syncdata[i]; 201 | syncbits[k] = (1 & (dibit >> 1)) + 48; // bit 1 202 | k++; 203 | syncbits[k] = (1 & dibit) + 48; // bit 0 204 | k++; 205 | } 206 | syncbits[48] = 0; 207 | printf ("%s ", syncbits); 208 | #endif 209 | 210 | if ((strcmp (sync, X2TDMA_BS_DATA_SYNC) == 0) || (strcmp (sync, X2TDMA_BS_DATA_SYNC) == 0)) 211 | { 212 | if (state->currentslot == 0) 213 | { 214 | sprintf (state->slot0light, "[slot0]"); 215 | } 216 | else 217 | { 218 | sprintf (state->slot1light, "[slot1]"); 219 | } 220 | } 221 | 222 | if (opts->errorbars == 1) 223 | { 224 | printf ("%s %s ", state->slot0light, state->slot1light); 225 | } 226 | 227 | // current slot second half, cach, next slot 1st half 228 | skipDibit (opts, state, 120); 229 | 230 | if (opts->errorbars == 1) 231 | { 232 | if (strcmp (state->fsubtype, " ") == 0) 233 | { 234 | printf (" Unknown burst type: %s\n", bursttype); 235 | } 236 | else 237 | { 238 | printf ("%s\n", state->fsubtype); 239 | } 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(dsdtest) 2 | 3 | add_subdirectory(gtest) 4 | add_subdirectory(gmock) 5 | 6 | FILE(GLOB SRCS *.cpp ${dsd_SOURCE_DIR}/src/Hamming.cpp) 7 | 8 | include_directories( 9 | ${PROJECT_SOURCE_DIR}/gtest/include 10 | ${PROJECT_SOURCE_DIR}/gmock/include 11 | ) 12 | 13 | ADD_EXECUTABLE(dsdtest ${SRCS}) 14 | TARGET_LINK_LIBRARIES(dsdtest gmock gtest) 15 | 16 | add_test(gtest dsdtest) 17 | -------------------------------------------------------------------------------- /test/gmock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | # CMake build script for Google Mock. 3 | # 4 | # To run the tests for Google Mock itself on Linux, use 'make test' or 5 | # ctest. You can select which tests to run using 'ctest -R regex'. 6 | # For more options, run 'ctest --help'. 7 | 8 | # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to 9 | # make it prominent in the GUI. 10 | option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) 11 | 12 | ######################################################################## 13 | # 14 | # Project-wide settings 15 | 16 | # Name of the project. 17 | # 18 | # CMake files in this project can refer to the root source directory 19 | # as ${gmock_SOURCE_DIR} and to the root binary directory as 20 | # ${gmock_BINARY_DIR}. 21 | # Language "C" is required for find_package(Threads). 22 | project(gmock CXX C) 23 | cmake_minimum_required(VERSION 2.6.2) 24 | 25 | # Adds Google Mock's and Google Test's header directories to the search path. 26 | include_directories("${gmock_SOURCE_DIR}/include" 27 | "${gmock_SOURCE_DIR}" 28 | "${gtest_SOURCE_DIR}/include") 29 | 30 | ######################################################################## 31 | # 32 | # Defines the gmock & gmock_main libraries. User tests should link 33 | # with one of them. 34 | 35 | # Google Mock libraries. We build them using more strict warnings than what 36 | # are used for other targets, to ensure that Google Mock can be compiled by 37 | # a user aggressive about warnings. 38 | cxx_library(gmock 39 | "${cxx_strict}" 40 | src/gmock-all.cc) 41 | 42 | cxx_library(gmock_main 43 | "${cxx_strict}" 44 | src/gmock-all.cc 45 | src/gmock_main.cc) 46 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-cardinalities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements some commonly used cardinalities. More 35 | // cardinalities can be defined by the user implementing the 36 | // CardinalityInterface interface if necessary. 37 | 38 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 39 | #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 40 | 41 | #include 42 | #include // NOLINT 43 | #include "gmock/internal/gmock-port.h" 44 | #include "gtest/gtest.h" 45 | 46 | namespace testing { 47 | 48 | // To implement a cardinality Foo, define: 49 | // 1. a class FooCardinality that implements the 50 | // CardinalityInterface interface, and 51 | // 2. a factory function that creates a Cardinality object from a 52 | // const FooCardinality*. 53 | // 54 | // The two-level delegation design follows that of Matcher, providing 55 | // consistency for extension developers. It also eases ownership 56 | // management as Cardinality objects can now be copied like plain values. 57 | 58 | // The implementation of a cardinality. 59 | class CardinalityInterface { 60 | public: 61 | virtual ~CardinalityInterface() {} 62 | 63 | // Conservative estimate on the lower/upper bound of the number of 64 | // calls allowed. 65 | virtual int ConservativeLowerBound() const { return 0; } 66 | virtual int ConservativeUpperBound() const { return INT_MAX; } 67 | 68 | // Returns true iff call_count calls will satisfy this cardinality. 69 | virtual bool IsSatisfiedByCallCount(int call_count) const = 0; 70 | 71 | // Returns true iff call_count calls will saturate this cardinality. 72 | virtual bool IsSaturatedByCallCount(int call_count) const = 0; 73 | 74 | // Describes self to an ostream. 75 | virtual void DescribeTo(::std::ostream* os) const = 0; 76 | }; 77 | 78 | // A Cardinality is a copyable and IMMUTABLE (except by assignment) 79 | // object that specifies how many times a mock function is expected to 80 | // be called. The implementation of Cardinality is just a linked_ptr 81 | // to const CardinalityInterface, so copying is fairly cheap. 82 | // Don't inherit from Cardinality! 83 | class GTEST_API_ Cardinality { 84 | public: 85 | // Constructs a null cardinality. Needed for storing Cardinality 86 | // objects in STL containers. 87 | Cardinality() {} 88 | 89 | // Constructs a Cardinality from its implementation. 90 | explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} 91 | 92 | // Conservative estimate on the lower/upper bound of the number of 93 | // calls allowed. 94 | int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } 95 | int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } 96 | 97 | // Returns true iff call_count calls will satisfy this cardinality. 98 | bool IsSatisfiedByCallCount(int call_count) const { 99 | return impl_->IsSatisfiedByCallCount(call_count); 100 | } 101 | 102 | // Returns true iff call_count calls will saturate this cardinality. 103 | bool IsSaturatedByCallCount(int call_count) const { 104 | return impl_->IsSaturatedByCallCount(call_count); 105 | } 106 | 107 | // Returns true iff call_count calls will over-saturate this 108 | // cardinality, i.e. exceed the maximum number of allowed calls. 109 | bool IsOverSaturatedByCallCount(int call_count) const { 110 | return impl_->IsSaturatedByCallCount(call_count) && 111 | !impl_->IsSatisfiedByCallCount(call_count); 112 | } 113 | 114 | // Describes self to an ostream 115 | void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } 116 | 117 | // Describes the given actual call count to an ostream. 118 | static void DescribeActualCallCountTo(int actual_call_count, 119 | ::std::ostream* os); 120 | 121 | private: 122 | internal::linked_ptr impl_; 123 | }; 124 | 125 | // Creates a cardinality that allows at least n calls. 126 | GTEST_API_ Cardinality AtLeast(int n); 127 | 128 | // Creates a cardinality that allows at most n calls. 129 | GTEST_API_ Cardinality AtMost(int n); 130 | 131 | // Creates a cardinality that allows any number of calls. 132 | GTEST_API_ Cardinality AnyNumber(); 133 | 134 | // Creates a cardinality that allows between min and max calls. 135 | GTEST_API_ Cardinality Between(int min, int max); 136 | 137 | // Creates a cardinality that allows exactly n calls. 138 | GTEST_API_ Cardinality Exactly(int n); 139 | 140 | // Creates a cardinality from its implementation. 141 | inline Cardinality MakeCardinality(const CardinalityInterface* c) { 142 | return Cardinality(c); 143 | } 144 | 145 | } // namespace testing 146 | 147 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 148 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-generated-nice-strict.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $$ This is a Pump source file. Please use Pump to convert it to 3 | $$ gmock-generated-nice-strict.h. 4 | $$ 5 | $var n = 10 $$ The maximum arity we support. 6 | // Copyright 2008, Google Inc. 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are 11 | // met: 12 | // 13 | // * Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // * Redistributions in binary form must reproduce the above 16 | // copyright notice, this list of conditions and the following disclaimer 17 | // in the documentation and/or other materials provided with the 18 | // distribution. 19 | // * Neither the name of Google Inc. nor the names of its 20 | // contributors may be used to endorse or promote products derived from 21 | // this software without specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | // Author: wan@google.com (Zhanyong Wan) 36 | 37 | // Implements class templates NiceMock, NaggyMock, and StrictMock. 38 | // 39 | // Given a mock class MockFoo that is created using Google Mock, 40 | // NiceMock is a subclass of MockFoo that allows 41 | // uninteresting calls (i.e. calls to mock methods that have no 42 | // EXPECT_CALL specs), NaggyMock is a subclass of MockFoo 43 | // that prints a warning when an uninteresting call occurs, and 44 | // StrictMock is a subclass of MockFoo that treats all 45 | // uninteresting calls as errors. 46 | // 47 | // Currently a mock is naggy by default, so MockFoo and 48 | // NaggyMock behave like the same. However, we will soon 49 | // switch the default behavior of mocks to be nice, as that in general 50 | // leads to more maintainable tests. When that happens, MockFoo will 51 | // stop behaving like NaggyMock and start behaving like 52 | // NiceMock. 53 | // 54 | // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of 55 | // their respective base class, with up-to $n arguments. Therefore 56 | // you can write NiceMock(5, "a") to construct a nice mock 57 | // where MockFoo has a constructor that accepts (int, const char*), 58 | // for example. 59 | // 60 | // A known limitation is that NiceMock, NaggyMock, 61 | // and StrictMock only works for mock methods defined using 62 | // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. 63 | // If a mock method is defined in a base class of MockFoo, the "nice" 64 | // or "strict" modifier may not affect it, depending on the compiler. 65 | // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT 66 | // supported. 67 | // 68 | // Another known limitation is that the constructors of the base mock 69 | // cannot have arguments passed by non-const reference, which are 70 | // banned by the Google C++ style guide anyway. 71 | 72 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 73 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 74 | 75 | #include "gmock/gmock-spec-builders.h" 76 | #include "gmock/internal/gmock-port.h" 77 | 78 | namespace testing { 79 | 80 | $range kind 0..2 81 | $for kind [[ 82 | 83 | $var clazz=[[$if kind==0 [[NiceMock]] 84 | $elif kind==1 [[NaggyMock]] 85 | $else [[StrictMock]]]] 86 | 87 | $var method=[[$if kind==0 [[AllowUninterestingCalls]] 88 | $elif kind==1 [[WarnUninterestingCalls]] 89 | $else [[FailUninterestingCalls]]]] 90 | 91 | template 92 | class $clazz : public MockClass { 93 | public: 94 | // We don't factor out the constructor body to a common method, as 95 | // we have to avoid a possible clash with members of MockClass. 96 | $clazz() { 97 | ::testing::Mock::$method( 98 | internal::ImplicitCast_(this)); 99 | } 100 | 101 | // C++ doesn't (yet) allow inheritance of constructors, so we have 102 | // to define it for each arity. 103 | template 104 | explicit $clazz(const A1& a1) : MockClass(a1) { 105 | ::testing::Mock::$method( 106 | internal::ImplicitCast_(this)); 107 | } 108 | 109 | $range i 2..n 110 | $for i [[ 111 | $range j 1..i 112 | template <$for j, [[typename A$j]]> 113 | $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { 114 | ::testing::Mock::$method( 115 | internal::ImplicitCast_(this)); 116 | } 117 | 118 | 119 | ]] 120 | virtual ~$clazz() { 121 | ::testing::Mock::UnregisterCallReaction( 122 | internal::ImplicitCast_(this)); 123 | } 124 | 125 | private: 126 | GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz); 127 | }; 128 | 129 | ]] 130 | 131 | // The following specializations catch some (relatively more common) 132 | // user errors of nesting nice and strict mocks. They do NOT catch 133 | // all possible errors. 134 | 135 | // These specializations are declared but not defined, as NiceMock, 136 | // NaggyMock, and StrictMock cannot be nested. 137 | 138 | template 139 | class NiceMock >; 140 | template 141 | class NiceMock >; 142 | template 143 | class NiceMock >; 144 | 145 | template 146 | class NaggyMock >; 147 | template 148 | class NaggyMock >; 149 | template 150 | class NaggyMock >; 151 | 152 | template 153 | class StrictMock >; 154 | template 155 | class StrictMock >; 156 | template 157 | class StrictMock >; 158 | 159 | } // namespace testing 160 | 161 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 162 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-more-matchers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: marcus.boerger@google.com (Marcus Boerger) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements some matchers that depend on gmock-generated-matchers.h. 35 | // 36 | // Note that tests are implemented in gmock-matchers_test.cc rather than 37 | // gmock-more-matchers-test.cc. 38 | 39 | #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_ 40 | #define GMOCK_GMOCK_MORE_MATCHERS_H_ 41 | 42 | #include "gmock/gmock-generated-matchers.h" 43 | 44 | namespace testing { 45 | 46 | // Defines a matcher that matches an empty container. The container must 47 | // support both size() and empty(), which all STL-like containers provide. 48 | MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { 49 | if (arg.empty()) { 50 | return true; 51 | } 52 | *result_listener << "whose size is " << arg.size(); 53 | return false; 54 | } 55 | 56 | } // namespace testing 57 | 58 | #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ 59 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This is the main header file a user should include. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ 37 | #define GMOCK_INCLUDE_GMOCK_GMOCK_H_ 38 | 39 | // This file implements the following syntax: 40 | // 41 | // ON_CALL(mock_object.Method(...)) 42 | // .With(...) ? 43 | // .WillByDefault(...); 44 | // 45 | // where With() is optional and WillByDefault() must appear exactly 46 | // once. 47 | // 48 | // EXPECT_CALL(mock_object.Method(...)) 49 | // .With(...) ? 50 | // .Times(...) ? 51 | // .InSequence(...) * 52 | // .WillOnce(...) * 53 | // .WillRepeatedly(...) ? 54 | // .RetiresOnSaturation() ? ; 55 | // 56 | // where all clauses are optional and WillOnce() can be repeated. 57 | 58 | #include "gmock/gmock-actions.h" 59 | #include "gmock/gmock-cardinalities.h" 60 | #include "gmock/gmock-generated-actions.h" 61 | #include "gmock/gmock-generated-function-mockers.h" 62 | #include "gmock/gmock-generated-nice-strict.h" 63 | #include "gmock/gmock-generated-matchers.h" 64 | #include "gmock/gmock-matchers.h" 65 | #include "gmock/gmock-more-actions.h" 66 | #include "gmock/gmock-more-matchers.h" 67 | #include "gmock/internal/gmock-internal-utils.h" 68 | 69 | namespace testing { 70 | 71 | // Declares Google Mock flags that we want a user to use programmatically. 72 | GMOCK_DECLARE_bool_(catch_leaked_mocks); 73 | GMOCK_DECLARE_string_(verbose); 74 | 75 | // Initializes Google Mock. This must be called before running the 76 | // tests. In particular, it parses the command line for the flags 77 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, 78 | // it is removed from argv, and *argc is decremented. 79 | // 80 | // No value is returned. Instead, the Google Mock flag variables are 81 | // updated. 82 | // 83 | // Since Google Test is needed for Google Mock to work, this function 84 | // also initializes Google Test and parses its flags, if that hasn't 85 | // been done. 86 | GTEST_API_ void InitGoogleMock(int* argc, char** argv); 87 | 88 | // This overloaded version can be used in Windows programs compiled in 89 | // UNICODE mode. 90 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv); 91 | 92 | } // namespace testing 93 | 94 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_ 95 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $$ This is a Pump source file. Please use Pump to convert it to 3 | $$ gmock-generated-function-mockers.h. 4 | $$ 5 | $var n = 10 $$ The maximum arity we support. 6 | // Copyright 2007, Google Inc. 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are 11 | // met: 12 | // 13 | // * Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // * Redistributions in binary form must reproduce the above 16 | // copyright notice, this list of conditions and the following disclaimer 17 | // in the documentation and/or other materials provided with the 18 | // distribution. 19 | // * Neither the name of Google Inc. nor the names of its 20 | // contributors may be used to endorse or promote products derived from 21 | // this software without specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | // Author: wan@google.com (Zhanyong Wan) 36 | 37 | // Google Mock - a framework for writing C++ mock classes. 38 | // 39 | // This file contains template meta-programming utility classes needed 40 | // for implementing Google Mock. 41 | 42 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 43 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 44 | 45 | #include "gmock/internal/gmock-port.h" 46 | 47 | namespace testing { 48 | 49 | template 50 | class Matcher; 51 | 52 | namespace internal { 53 | 54 | // An IgnoredValue object can be implicitly constructed from ANY value. 55 | // This is used in implementing the IgnoreResult(a) action. 56 | class IgnoredValue { 57 | public: 58 | // This constructor template allows any value to be implicitly 59 | // converted to IgnoredValue. The object has no data member and 60 | // doesn't try to remember anything about the argument. We 61 | // deliberately omit the 'explicit' keyword in order to allow the 62 | // conversion to be implicit. 63 | template 64 | IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) 65 | }; 66 | 67 | // MatcherTuple::type is a tuple type where each field is a Matcher 68 | // for the corresponding field in tuple type T. 69 | template 70 | struct MatcherTuple; 71 | 72 | 73 | $range i 0..n 74 | $for i [[ 75 | $range j 1..i 76 | $var typename_As = [[$for j, [[typename A$j]]]] 77 | $var As = [[$for j, [[A$j]]]] 78 | $var matcher_As = [[$for j, [[Matcher]]]] 79 | template <$typename_As> 80 | struct MatcherTuple< ::std::tr1::tuple<$As> > { 81 | typedef ::std::tr1::tuple<$matcher_As > type; 82 | }; 83 | 84 | 85 | ]] 86 | // Template struct Function, where F must be a function type, contains 87 | // the following typedefs: 88 | // 89 | // Result: the function's return type. 90 | // ArgumentN: the type of the N-th argument, where N starts with 1. 91 | // ArgumentTuple: the tuple type consisting of all parameters of F. 92 | // ArgumentMatcherTuple: the tuple type consisting of Matchers for all 93 | // parameters of F. 94 | // MakeResultVoid: the function type obtained by substituting void 95 | // for the return type of F. 96 | // MakeResultIgnoredValue: 97 | // the function type obtained by substituting Something 98 | // for the return type of F. 99 | template 100 | struct Function; 101 | 102 | template 103 | struct Function { 104 | typedef R Result; 105 | typedef ::std::tr1::tuple<> ArgumentTuple; 106 | typedef typename MatcherTuple::type ArgumentMatcherTuple; 107 | typedef void MakeResultVoid(); 108 | typedef IgnoredValue MakeResultIgnoredValue(); 109 | }; 110 | 111 | 112 | $range i 1..n 113 | $for i [[ 114 | $range j 1..i 115 | $var typename_As = [[$for j [[, typename A$j]]]] 116 | $var As = [[$for j, [[A$j]]]] 117 | $var matcher_As = [[$for j, [[Matcher]]]] 118 | $range k 1..i-1 119 | $var prev_As = [[$for k, [[A$k]]]] 120 | template 121 | struct Function 122 | : Function { 123 | typedef A$i Argument$i; 124 | typedef ::std::tr1::tuple<$As> ArgumentTuple; 125 | typedef typename MatcherTuple::type ArgumentMatcherTuple; 126 | typedef void MakeResultVoid($As); 127 | typedef IgnoredValue MakeResultIgnoredValue($As); 128 | }; 129 | 130 | 131 | ]] 132 | } // namespace internal 133 | 134 | } // namespace testing 135 | 136 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 137 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/internal/gmock-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: vadimb@google.com (Vadim Berman) 31 | // 32 | // Low-level types and utilities for porting Google Mock to various 33 | // platforms. They are subject to change without notice. DO NOT USE 34 | // THEM IN USER CODE. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 37 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | // Most of the types needed for porting Google Mock are also required 44 | // for Google Test and are defined in gtest-port.h. 45 | #include "gtest/internal/gtest-linked_ptr.h" 46 | #include "gtest/internal/gtest-port.h" 47 | 48 | // To avoid conditional compilation everywhere, we make it 49 | // gmock-port.h's responsibility to #include the header implementing 50 | // tr1/tuple. gmock-port.h does this via gtest-port.h, which is 51 | // guaranteed to pull in the tuple header. 52 | 53 | // For MS Visual C++, check the compiler version. At least VS 2003 is 54 | // required to compile Google Mock. 55 | #if defined(_MSC_VER) && _MSC_VER < 1310 56 | # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." 57 | #endif 58 | 59 | // Macro for referencing flags. This is public as we want the user to 60 | // use this syntax to reference Google Mock flags. 61 | #define GMOCK_FLAG(name) FLAGS_gmock_##name 62 | 63 | // Macros for declaring flags. 64 | #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) 65 | #define GMOCK_DECLARE_int32_(name) \ 66 | extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) 67 | #define GMOCK_DECLARE_string_(name) \ 68 | extern GTEST_API_ ::std::string GMOCK_FLAG(name) 69 | 70 | // Macros for defining flags. 71 | #define GMOCK_DEFINE_bool_(name, default_val, doc) \ 72 | GTEST_API_ bool GMOCK_FLAG(name) = (default_val) 73 | #define GMOCK_DEFINE_int32_(name, default_val, doc) \ 74 | GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) 75 | #define GMOCK_DEFINE_string_(name, default_val, doc) \ 76 | GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) 77 | 78 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 79 | -------------------------------------------------------------------------------- /test/gmock/src/gmock-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Mocking Framework (Google Mock) 33 | // 34 | // This file #includes all Google Mock implementation .cc files. The 35 | // purpose is to allow a user to build Google Mock by compiling this 36 | // file alone. 37 | 38 | // This line ensures that gmock.h can be compiled on its own, even 39 | // when it's fused. 40 | #include "gmock/gmock.h" 41 | 42 | // The following lines pull in the real gmock *.cc files. 43 | #include "src/gmock-cardinalities.cc" 44 | #include "src/gmock-internal-utils.cc" 45 | #include "src/gmock-matchers.cc" 46 | #include "src/gmock-spec-builders.cc" 47 | #include "src/gmock.cc" 48 | -------------------------------------------------------------------------------- /test/gmock/src/gmock-cardinalities.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements cardinalities. 35 | 36 | #include "gmock/gmock-cardinalities.h" 37 | 38 | #include 39 | #include // NOLINT 40 | #include 41 | #include 42 | #include "gmock/internal/gmock-internal-utils.h" 43 | #include "gtest/gtest.h" 44 | 45 | namespace testing { 46 | 47 | namespace { 48 | 49 | // Implements the Between(m, n) cardinality. 50 | class BetweenCardinalityImpl : public CardinalityInterface { 51 | public: 52 | BetweenCardinalityImpl(int min, int max) 53 | : min_(min >= 0 ? min : 0), 54 | max_(max >= min_ ? max : min_) { 55 | std::stringstream ss; 56 | if (min < 0) { 57 | ss << "The invocation lower bound must be >= 0, " 58 | << "but is actually " << min << "."; 59 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 60 | } else if (max < 0) { 61 | ss << "The invocation upper bound must be >= 0, " 62 | << "but is actually " << max << "."; 63 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 64 | } else if (min > max) { 65 | ss << "The invocation upper bound (" << max 66 | << ") must be >= the invocation lower bound (" << min 67 | << ")."; 68 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 69 | } 70 | } 71 | 72 | // Conservative estimate on the lower/upper bound of the number of 73 | // calls allowed. 74 | virtual int ConservativeLowerBound() const { return min_; } 75 | virtual int ConservativeUpperBound() const { return max_; } 76 | 77 | virtual bool IsSatisfiedByCallCount(int call_count) const { 78 | return min_ <= call_count && call_count <= max_; 79 | } 80 | 81 | virtual bool IsSaturatedByCallCount(int call_count) const { 82 | return call_count >= max_; 83 | } 84 | 85 | virtual void DescribeTo(::std::ostream* os) const; 86 | 87 | private: 88 | const int min_; 89 | const int max_; 90 | 91 | GTEST_DISALLOW_COPY_AND_ASSIGN_(BetweenCardinalityImpl); 92 | }; 93 | 94 | // Formats "n times" in a human-friendly way. 95 | inline internal::string FormatTimes(int n) { 96 | if (n == 1) { 97 | return "once"; 98 | } else if (n == 2) { 99 | return "twice"; 100 | } else { 101 | std::stringstream ss; 102 | ss << n << " times"; 103 | return ss.str(); 104 | } 105 | } 106 | 107 | // Describes the Between(m, n) cardinality in human-friendly text. 108 | void BetweenCardinalityImpl::DescribeTo(::std::ostream* os) const { 109 | if (min_ == 0) { 110 | if (max_ == 0) { 111 | *os << "never called"; 112 | } else if (max_ == INT_MAX) { 113 | *os << "called any number of times"; 114 | } else { 115 | *os << "called at most " << FormatTimes(max_); 116 | } 117 | } else if (min_ == max_) { 118 | *os << "called " << FormatTimes(min_); 119 | } else if (max_ == INT_MAX) { 120 | *os << "called at least " << FormatTimes(min_); 121 | } else { 122 | // 0 < min_ < max_ < INT_MAX 123 | *os << "called between " << min_ << " and " << max_ << " times"; 124 | } 125 | } 126 | 127 | } // Unnamed namespace 128 | 129 | // Describes the given call count to an ostream. 130 | void Cardinality::DescribeActualCallCountTo(int actual_call_count, 131 | ::std::ostream* os) { 132 | if (actual_call_count > 0) { 133 | *os << "called " << FormatTimes(actual_call_count); 134 | } else { 135 | *os << "never called"; 136 | } 137 | } 138 | 139 | // Creates a cardinality that allows at least n calls. 140 | GTEST_API_ Cardinality AtLeast(int n) { return Between(n, INT_MAX); } 141 | 142 | // Creates a cardinality that allows at most n calls. 143 | GTEST_API_ Cardinality AtMost(int n) { return Between(0, n); } 144 | 145 | // Creates a cardinality that allows any number of calls. 146 | GTEST_API_ Cardinality AnyNumber() { return AtLeast(0); } 147 | 148 | // Creates a cardinality that allows between min and max calls. 149 | GTEST_API_ Cardinality Between(int min, int max) { 150 | return Cardinality(new BetweenCardinalityImpl(min, max)); 151 | } 152 | 153 | // Creates a cardinality that allows exactly n calls. 154 | GTEST_API_ Cardinality Exactly(int n) { return Between(n, n); } 155 | 156 | } // namespace testing 157 | -------------------------------------------------------------------------------- /test/gmock/src/gmock-internal-utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file defines some utilities useful for implementing Google 35 | // Mock. They are subject to change without notice, so please DO NOT 36 | // USE THEM IN USER CODE. 37 | 38 | #include "gmock/internal/gmock-internal-utils.h" 39 | 40 | #include 41 | #include // NOLINT 42 | #include 43 | #include "gmock/gmock.h" 44 | #include "gmock/internal/gmock-port.h" 45 | #include "gtest/gtest.h" 46 | 47 | namespace testing { 48 | namespace internal { 49 | 50 | // Converts an identifier name to a space-separated list of lower-case 51 | // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is 52 | // treated as one word. For example, both "FooBar123" and 53 | // "foo_bar_123" are converted to "foo bar 123". 54 | GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) { 55 | string result; 56 | char prev_char = '\0'; 57 | for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) { 58 | // We don't care about the current locale as the input is 59 | // guaranteed to be a valid C++ identifier name. 60 | const bool starts_new_word = IsUpper(*p) || 61 | (!IsAlpha(prev_char) && IsLower(*p)) || 62 | (!IsDigit(prev_char) && IsDigit(*p)); 63 | 64 | if (IsAlNum(*p)) { 65 | if (starts_new_word && result != "") 66 | result += ' '; 67 | result += ToLower(*p); 68 | } 69 | } 70 | return result; 71 | } 72 | 73 | // This class reports Google Mock failures as Google Test failures. A 74 | // user can define another class in a similar fashion if he intends to 75 | // use Google Mock with a testing framework other than Google Test. 76 | class GoogleTestFailureReporter : public FailureReporterInterface { 77 | public: 78 | virtual void ReportFailure(FailureType type, const char* file, int line, 79 | const string& message) { 80 | AssertHelper(type == kFatal ? 81 | TestPartResult::kFatalFailure : 82 | TestPartResult::kNonFatalFailure, 83 | file, 84 | line, 85 | message.c_str()) = Message(); 86 | if (type == kFatal) { 87 | posix::Abort(); 88 | } 89 | } 90 | }; 91 | 92 | // Returns the global failure reporter. Will create a 93 | // GoogleTestFailureReporter and return it the first time called. 94 | GTEST_API_ FailureReporterInterface* GetFailureReporter() { 95 | // Points to the global failure reporter used by Google Mock. gcc 96 | // guarantees that the following use of failure_reporter is 97 | // thread-safe. We may need to add additional synchronization to 98 | // protect failure_reporter if we port Google Mock to other 99 | // compilers. 100 | static FailureReporterInterface* const failure_reporter = 101 | new GoogleTestFailureReporter(); 102 | return failure_reporter; 103 | } 104 | 105 | // Protects global resources (stdout in particular) used by Log(). 106 | static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex); 107 | 108 | // Returns true iff a log with the given severity is visible according 109 | // to the --gmock_verbose flag. 110 | GTEST_API_ bool LogIsVisible(LogSeverity severity) { 111 | if (GMOCK_FLAG(verbose) == kInfoVerbosity) { 112 | // Always show the log if --gmock_verbose=info. 113 | return true; 114 | } else if (GMOCK_FLAG(verbose) == kErrorVerbosity) { 115 | // Always hide it if --gmock_verbose=error. 116 | return false; 117 | } else { 118 | // If --gmock_verbose is neither "info" nor "error", we treat it 119 | // as "warning" (its default value). 120 | return severity == kWarning; 121 | } 122 | } 123 | 124 | // Prints the given message to stdout iff 'severity' >= the level 125 | // specified by the --gmock_verbose flag. If stack_frames_to_skip >= 126 | // 0, also prints the stack trace excluding the top 127 | // stack_frames_to_skip frames. In opt mode, any positive 128 | // stack_frames_to_skip is treated as 0, since we don't know which 129 | // function calls will be inlined by the compiler and need to be 130 | // conservative. 131 | GTEST_API_ void Log(LogSeverity severity, 132 | const string& message, 133 | int stack_frames_to_skip) { 134 | if (!LogIsVisible(severity)) 135 | return; 136 | 137 | // Ensures that logs from different threads don't interleave. 138 | MutexLock l(&g_log_mutex); 139 | 140 | // "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a 141 | // macro. 142 | 143 | if (severity == kWarning) { 144 | // Prints a GMOCK WARNING marker to make the warnings easily searchable. 145 | std::cout << "\nGMOCK WARNING:"; 146 | } 147 | // Pre-pends a new-line to message if it doesn't start with one. 148 | if (message.empty() || message[0] != '\n') { 149 | std::cout << "\n"; 150 | } 151 | std::cout << message; 152 | if (stack_frames_to_skip >= 0) { 153 | #ifdef NDEBUG 154 | // In opt mode, we have to be conservative and skip no stack frame. 155 | const int actual_to_skip = 0; 156 | #else 157 | // In dbg mode, we can do what the caller tell us to do (plus one 158 | // for skipping this function's stack frame). 159 | const int actual_to_skip = stack_frames_to_skip + 1; 160 | #endif // NDEBUG 161 | 162 | // Appends a new-line to message if it doesn't end with one. 163 | if (!message.empty() && *message.rbegin() != '\n') { 164 | std::cout << "\n"; 165 | } 166 | std::cout << "Stack trace:\n" 167 | << ::testing::internal::GetCurrentOsStackTraceExceptTop( 168 | ::testing::UnitTest::GetInstance(), actual_to_skip); 169 | } 170 | std::cout << ::std::flush; 171 | } 172 | 173 | } // namespace internal 174 | } // namespace testing 175 | -------------------------------------------------------------------------------- /test/gmock/src/gmock_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include 33 | #include "gmock/gmock.h" 34 | #include "gtest/gtest.h" 35 | 36 | // MS C++ compiler/linker has a bug on Windows (not on Windows CE), which 37 | // causes a link error when _tmain is defined in a static library and UNICODE 38 | // is enabled. For this reason instead of _tmain, main function is used on 39 | // Windows. See the following link to track the current status of this bug: 40 | // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=394464 // NOLINT 41 | #if GTEST_OS_WINDOWS_MOBILE 42 | # include // NOLINT 43 | 44 | GTEST_API_ int _tmain(int argc, TCHAR** argv) { 45 | #else 46 | GTEST_API_ int main(int argc, char** argv) { 47 | #endif // GTEST_OS_WINDOWS_MOBILE 48 | std::cout << "Running main() from gmock_main.cc\n"; 49 | // Since Google Mock depends on Google Test, InitGoogleMock() is 50 | // also responsible for initializing Google Test. Therefore there's 51 | // no need for calling testing::InitGoogleTest() separately. 52 | testing::InitGoogleMock(&argc, argv); 53 | return RUN_ALL_TESTS(); 54 | } 55 | -------------------------------------------------------------------------------- /test/golay24-test.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit tests for the Golay24 implementation. 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | #include "gmock/gmock.h" 7 | 8 | #include "Golay24.hpp" 9 | 10 | class Golay24Test : public testing::Test 11 | { 12 | protected: 13 | 14 | /** 15 | * Converts an 24-bit word packed in an integer to a binary string. 16 | */ 17 | static const char *hex_to_bin24(unsigned long x) 18 | { 19 | static char b[27]; 20 | int z, i; 21 | 22 | for (z = 1, i = 0; i < 26; z <<= 1, i++) 23 | { 24 | b[i] = ((x & z) != 0)? 'X' : ' '; 25 | if (i == 5 || i == 12) { 26 | i++; 27 | b[i] = '-'; 28 | } 29 | } 30 | b[26] = '\0'; 31 | 32 | return b; 33 | } 34 | 35 | /** 36 | * Attempts to FEC an hex word in the DSD format writing some useful debugging information on the way. 37 | * \param expected_errors Set it to 4 to indicate that we expect uncorrectable errors 38 | */ 39 | static void fix_golay24(char* hex, char* sgp, char* expected, int expected_errors) 40 | { 41 | DSDGolay24 golay24; 42 | 43 | unsigned int trashed_codeword = golay24.adapt_to_codeword(hex, 6, sgp); 44 | 45 | //printf("[%s]", hex_to_bin24(trashed_codeword)); 46 | 47 | int fixed_errors = 0; 48 | int many_errors = golay24.decode_6(hex, sgp, &fixed_errors); // try to correct bit errors 49 | 50 | /* 51 | printf(" -> "); 52 | printf("["); 53 | for (unsigned int i=0; i<6; i++) { 54 | printf("%c", hex[i]? 'X' : ' '); 55 | } 56 | printf("] "); 57 | if (many_errors) { 58 | // Signal that there were errors that couldn't get fixed, probably more than 4. 59 | printf(" +4 errors"); 60 | } else { 61 | printf(" %i errors", fixed_errors); 62 | } 63 | */ 64 | 65 | // check 66 | if (expected_errors == 4) { 67 | EXPECT_EQ(1, many_errors); 68 | } else { 69 | EXPECT_EQ(0, many_errors); 70 | EXPECT_EQ(expected_errors, fixed_errors); 71 | } 72 | 73 | //printf("\n"); 74 | } 75 | 76 | static void check_encode(char* hex, char* expected_parity) 77 | { 78 | DSDGolay24 golay24; 79 | char parity[12]; 80 | 81 | golay24.encode_6(hex, parity); 82 | 83 | for(unsigned int i=0; i<12; i++) { 84 | EXPECT_EQ(expected_parity[i], parity[i]); 85 | } 86 | } 87 | }; 88 | 89 | TEST_F(Golay24Test, Test1) 90 | { 91 | char hex[6] = { 1, 0, 0, 0, 1, 1}; 92 | char parity[12] = { 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0}; 93 | char expected[6] = { 1, 0, 0, 0, 1, 1}; 94 | 95 | fix_golay24(hex, parity, expected, 1); 96 | } 97 | 98 | TEST_F(Golay24Test, Test2) 99 | { 100 | char hex[6] = { 1, 0, 1, 0, 1, 0}; 101 | char parity[12] = { 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1}; 102 | char expected[6] = { 1, 0, 1, 0, 1, 0}; 103 | 104 | fix_golay24(hex, parity, expected, 0); 105 | } 106 | 107 | TEST_F(Golay24Test, Test3) 108 | { 109 | char hex[6] = { 1, 0, 1, 1, 1, 0}; 110 | char parity[12] = { 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0}; 111 | char expected[6] = { 1, 0, 1, 1, 1, 0}; 112 | 113 | fix_golay24(hex, parity, expected, 4); // should fail, many errors 114 | } 115 | 116 | TEST_F(Golay24Test, Test4) 117 | { 118 | char hex[6] = { 0, 0, 1, 0, 0, 0}; 119 | char parity[12] = { 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0}; 120 | char expected[6] = { 0, 0, 1, 0, 0, 0}; 121 | 122 | fix_golay24(hex, parity, expected, 0); 123 | } 124 | 125 | TEST_F(Golay24Test, Test5) 126 | { 127 | char hex[6] = { 1, 0, 0, 0, 0, 0}; 128 | char parity[12] = { 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1}; 129 | char expected[6] = { 1, 0, 0, 1, 0, 0}; 130 | 131 | fix_golay24(hex, parity, expected, 4); // should fail, many errors 132 | } 133 | 134 | TEST_F(Golay24Test, Test6) 135 | { 136 | char hex[6] = { 0, 0, 0, 0, 0, 0}; 137 | char parity[12] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}; 138 | char expected[6] = { 0, 0, 0, 0, 0, 0}; 139 | 140 | fix_golay24(hex, parity, expected, 4); // should fail, many errors 141 | } 142 | 143 | TEST_F(Golay24Test, Test7) 144 | { 145 | char hex[6] = { 1, 0, 0, 0, 0, 0}; 146 | char parity[12] = { 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0}; 147 | char expected[6] = { 0, 0, 1, 0, 0, 0}; 148 | 149 | fix_golay24(hex, parity, expected, 2); 150 | } 151 | 152 | TEST_F(Golay24Test, Test_encode_1) 153 | { 154 | char hex[6] = { 1, 0, 1, 0, 1, 0}; 155 | char expected_parity[12] = { 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1}; 156 | 157 | check_encode(hex, expected_parity); 158 | } 159 | 160 | TEST_F(Golay24Test, Test_encode_2) 161 | { 162 | char hex[6] = { 0, 0, 1, 0, 0, 0}; 163 | char expected_parity[12] = { 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0}; 164 | 165 | check_encode(hex, expected_parity); 166 | } 167 | 168 | TEST_F(Golay24Test, Test_encode_3) 169 | { 170 | char hex[6] = { 0, 0, 0, 0, 0, 0}; 171 | char expected_parity[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 172 | 173 | check_encode(hex, expected_parity); 174 | } 175 | -------------------------------------------------------------------------------- /test/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | # CMake build script for Google Test. 3 | # 4 | # To run the tests for Google Test itself on Linux, use 'make test' or 5 | # ctest. You can select which tests to run using 'ctest -R regex'. 6 | # For more options, run 'ctest --help'. 7 | 8 | # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to 9 | # make it prominent in the GUI. 10 | option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) 11 | 12 | # When other libraries are using a shared version of runtime libraries, 13 | # Google Test also has to use one. 14 | option( 15 | gtest_force_shared_crt 16 | "Use shared (DLL) run-time lib even when Google Test is built as static lib." 17 | OFF) 18 | 19 | option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF) 20 | 21 | # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). 22 | include(cmake/hermetic_build.cmake OPTIONAL) 23 | 24 | if (COMMAND pre_project_set_up_hermetic_build) 25 | pre_project_set_up_hermetic_build() 26 | endif() 27 | 28 | ######################################################################## 29 | # 30 | # Project-wide settings 31 | 32 | # Name of the project. 33 | # 34 | # CMake files in this project can refer to the root source directory 35 | # as ${gtest_SOURCE_DIR} and to the root binary directory as 36 | # ${gtest_BINARY_DIR}. 37 | # Language "C" is required for find_package(Threads). 38 | project(gtest CXX C) 39 | cmake_minimum_required(VERSION 2.6.2) 40 | 41 | if (COMMAND set_up_hermetic_build) 42 | set_up_hermetic_build() 43 | endif() 44 | 45 | # Define helper functions and macros used by Google Test. 46 | include(cmake/internal_utils.cmake) 47 | 48 | config_compiler_and_linker() # Defined in internal_utils.cmake. 49 | 50 | # Where Google Test's .h files can be found. 51 | include_directories( 52 | ${gtest_SOURCE_DIR}/include 53 | ${gtest_SOURCE_DIR}) 54 | 55 | # Where Google Test's libraries can be found. 56 | link_directories(${gtest_BINARY_DIR}/src) 57 | 58 | ######################################################################## 59 | # 60 | # Defines the gtest & gtest_main libraries. User tests should link 61 | # with one of them. 62 | 63 | # Google Test libraries. We build them using more strict warnings than what 64 | # are used for other targets, to ensure that gtest can be compiled by a user 65 | # aggressive about warnings. 66 | cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) 67 | cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) 68 | target_link_libraries(gtest_main gtest) 69 | 70 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest-test-part.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | 33 | #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 34 | #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 35 | 36 | #include 37 | #include 38 | #include "gtest/internal/gtest-internal.h" 39 | #include "gtest/internal/gtest-string.h" 40 | 41 | namespace testing { 42 | 43 | // A copyable object representing the result of a test part (i.e. an 44 | // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). 45 | // 46 | // Don't inherit from TestPartResult as its destructor is not virtual. 47 | class GTEST_API_ TestPartResult { 48 | public: 49 | // The possible outcomes of a test part (i.e. an assertion or an 50 | // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). 51 | enum Type { 52 | kSuccess, // Succeeded. 53 | kNonFatalFailure, // Failed but the test can continue. 54 | kFatalFailure // Failed and the test should be terminated. 55 | }; 56 | 57 | // C'tor. TestPartResult does NOT have a default constructor. 58 | // Always use this constructor (with parameters) to create a 59 | // TestPartResult object. 60 | TestPartResult(Type a_type, 61 | const char* a_file_name, 62 | int a_line_number, 63 | const char* a_message) 64 | : type_(a_type), 65 | file_name_(a_file_name == NULL ? "" : a_file_name), 66 | line_number_(a_line_number), 67 | summary_(ExtractSummary(a_message)), 68 | message_(a_message) { 69 | } 70 | 71 | // Gets the outcome of the test part. 72 | Type type() const { return type_; } 73 | 74 | // Gets the name of the source file where the test part took place, or 75 | // NULL if it's unknown. 76 | const char* file_name() const { 77 | return file_name_.empty() ? NULL : file_name_.c_str(); 78 | } 79 | 80 | // Gets the line in the source file where the test part took place, 81 | // or -1 if it's unknown. 82 | int line_number() const { return line_number_; } 83 | 84 | // Gets the summary of the failure message. 85 | const char* summary() const { return summary_.c_str(); } 86 | 87 | // Gets the message associated with the test part. 88 | const char* message() const { return message_.c_str(); } 89 | 90 | // Returns true iff the test part passed. 91 | bool passed() const { return type_ == kSuccess; } 92 | 93 | // Returns true iff the test part failed. 94 | bool failed() const { return type_ != kSuccess; } 95 | 96 | // Returns true iff the test part non-fatally failed. 97 | bool nonfatally_failed() const { return type_ == kNonFatalFailure; } 98 | 99 | // Returns true iff the test part fatally failed. 100 | bool fatally_failed() const { return type_ == kFatalFailure; } 101 | 102 | private: 103 | Type type_; 104 | 105 | // Gets the summary of the failure message by omitting the stack 106 | // trace in it. 107 | static std::string ExtractSummary(const char* message); 108 | 109 | // The name of the source file where the test part took place, or 110 | // "" if the source file is unknown. 111 | std::string file_name_; 112 | // The line in the source file where the test part took place, or -1 113 | // if the line number is unknown. 114 | int line_number_; 115 | std::string summary_; // The test failure summary. 116 | std::string message_; // The test failure message. 117 | }; 118 | 119 | // Prints a TestPartResult object. 120 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result); 121 | 122 | // An array of TestPartResult objects. 123 | // 124 | // Don't inherit from TestPartResultArray as its destructor is not 125 | // virtual. 126 | class GTEST_API_ TestPartResultArray { 127 | public: 128 | TestPartResultArray() {} 129 | 130 | // Appends the given TestPartResult to the array. 131 | void Append(const TestPartResult& result); 132 | 133 | // Returns the TestPartResult at the given index (0-based). 134 | const TestPartResult& GetTestPartResult(int index) const; 135 | 136 | // Returns the number of TestPartResult objects in the array. 137 | int size() const; 138 | 139 | private: 140 | std::vector array_; 141 | 142 | GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); 143 | }; 144 | 145 | // This interface knows how to report a test part result. 146 | class TestPartResultReporterInterface { 147 | public: 148 | virtual ~TestPartResultReporterInterface() {} 149 | 150 | virtual void ReportTestPartResult(const TestPartResult& result) = 0; 151 | }; 152 | 153 | namespace internal { 154 | 155 | // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a 156 | // statement generates new fatal failures. To do so it registers itself as the 157 | // current test part result reporter. Besides checking if fatal failures were 158 | // reported, it only delegates the reporting to the former result reporter. 159 | // The original result reporter is restored in the destructor. 160 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 161 | class GTEST_API_ HasNewFatalFailureHelper 162 | : public TestPartResultReporterInterface { 163 | public: 164 | HasNewFatalFailureHelper(); 165 | virtual ~HasNewFatalFailureHelper(); 166 | virtual void ReportTestPartResult(const TestPartResult& result); 167 | bool has_new_fatal_failure() const { return has_new_fatal_failure_; } 168 | private: 169 | bool has_new_fatal_failure_; 170 | TestPartResultReporterInterface* original_reporter_; 171 | 172 | GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); 173 | }; 174 | 175 | } // namespace internal 176 | 177 | } // namespace testing 178 | 179 | #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 180 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /test/gtest/src/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // Sometimes it's desirable to build Google Test by compiling a single file. 35 | // This file serves this purpose. 36 | 37 | // This line ensures that gtest.h can be compiled on its own, even 38 | // when it's fused. 39 | #include "gtest/gtest.h" 40 | 41 | // The following lines pull in the real gtest *.cc files. 42 | #include "src/gtest.cc" 43 | #include "src/gtest-death-test.cc" 44 | #include "src/gtest-filepath.cc" 45 | #include "src/gtest-port.cc" 46 | #include "src/gtest-printers.cc" 47 | #include "src/gtest-test-part.cc" 48 | #include "src/gtest-typed-test.cc" 49 | -------------------------------------------------------------------------------- /test/gtest/src/gtest-test-part.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | 34 | #include "gtest/gtest-test-part.h" 35 | 36 | // Indicates that this translation unit is part of Google Test's 37 | // implementation. It must come before gtest-internal-inl.h is 38 | // included, or there will be a compiler error. This trick is to 39 | // prevent a user from accidentally including gtest-internal-inl.h in 40 | // his code. 41 | #define GTEST_IMPLEMENTATION_ 1 42 | #include "src/gtest-internal-inl.h" 43 | #undef GTEST_IMPLEMENTATION_ 44 | 45 | namespace testing { 46 | 47 | using internal::GetUnitTestImpl; 48 | 49 | // Gets the summary of the failure message by omitting the stack trace 50 | // in it. 51 | std::string TestPartResult::ExtractSummary(const char* message) { 52 | const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 53 | return stack_trace == NULL ? message : 54 | std::string(message, stack_trace); 55 | } 56 | 57 | // Prints a TestPartResult object. 58 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { 59 | return os 60 | << result.file_name() << ":" << result.line_number() << ": " 61 | << (result.type() == TestPartResult::kSuccess ? "Success" : 62 | result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : 63 | "Non-fatal failure") << ":\n" 64 | << result.message() << std::endl; 65 | } 66 | 67 | // Appends a TestPartResult to the array. 68 | void TestPartResultArray::Append(const TestPartResult& result) { 69 | array_.push_back(result); 70 | } 71 | 72 | // Returns the TestPartResult at the given index (0-based). 73 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 74 | if (index < 0 || index >= size()) { 75 | printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 76 | internal::posix::Abort(); 77 | } 78 | 79 | return array_[index]; 80 | } 81 | 82 | // Returns the number of TestPartResult objects in the array. 83 | int TestPartResultArray::size() const { 84 | return static_cast(array_.size()); 85 | } 86 | 87 | namespace internal { 88 | 89 | HasNewFatalFailureHelper::HasNewFatalFailureHelper() 90 | : has_new_fatal_failure_(false), 91 | original_reporter_(GetUnitTestImpl()-> 92 | GetTestPartResultReporterForCurrentThread()) { 93 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); 94 | } 95 | 96 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 97 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( 98 | original_reporter_); 99 | } 100 | 101 | void HasNewFatalFailureHelper::ReportTestPartResult( 102 | const TestPartResult& result) { 103 | if (result.fatally_failed()) 104 | has_new_fatal_failure_ = true; 105 | original_reporter_->ReportTestPartResult(result); 106 | } 107 | 108 | } // namespace internal 109 | 110 | } // namespace testing 111 | -------------------------------------------------------------------------------- /test/gtest/src/gtest-typed-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest-typed-test.h" 33 | #include "gtest/gtest.h" 34 | 35 | namespace testing { 36 | namespace internal { 37 | 38 | #if GTEST_HAS_TYPED_TEST_P 39 | 40 | // Skips to the first non-space char in str. Returns an empty string if str 41 | // contains only whitespace characters. 42 | static const char* SkipSpaces(const char* str) { 43 | while (IsSpace(*str)) 44 | str++; 45 | return str; 46 | } 47 | 48 | // Verifies that registered_tests match the test names in 49 | // defined_test_names_; returns registered_tests if successful, or 50 | // aborts the program otherwise. 51 | const char* TypedTestCasePState::VerifyRegisteredTestNames( 52 | const char* file, int line, const char* registered_tests) { 53 | typedef ::std::set::const_iterator DefinedTestIter; 54 | registered_ = true; 55 | 56 | // Skip initial whitespace in registered_tests since some 57 | // preprocessors prefix stringizied literals with whitespace. 58 | registered_tests = SkipSpaces(registered_tests); 59 | 60 | Message errors; 61 | ::std::set tests; 62 | for (const char* names = registered_tests; names != NULL; 63 | names = SkipComma(names)) { 64 | const std::string name = GetPrefixUntilComma(names); 65 | if (tests.count(name) != 0) { 66 | errors << "Test " << name << " is listed more than once.\n"; 67 | continue; 68 | } 69 | 70 | bool found = false; 71 | for (DefinedTestIter it = defined_test_names_.begin(); 72 | it != defined_test_names_.end(); 73 | ++it) { 74 | if (name == *it) { 75 | found = true; 76 | break; 77 | } 78 | } 79 | 80 | if (found) { 81 | tests.insert(name); 82 | } else { 83 | errors << "No test named " << name 84 | << " can be found in this test case.\n"; 85 | } 86 | } 87 | 88 | for (DefinedTestIter it = defined_test_names_.begin(); 89 | it != defined_test_names_.end(); 90 | ++it) { 91 | if (tests.count(*it) == 0) { 92 | errors << "You forgot to list test " << *it << ".\n"; 93 | } 94 | } 95 | 96 | const std::string& errors_str = errors.GetString(); 97 | if (errors_str != "") { 98 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 99 | errors_str.c_str()); 100 | fflush(stderr); 101 | posix::Abort(); 102 | } 103 | 104 | return registered_tests; 105 | } 106 | 107 | #endif // GTEST_HAS_TYPED_TEST_P 108 | 109 | } // namespace internal 110 | } // namespace testing 111 | -------------------------------------------------------------------------------- /test/gtest/src/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | -------------------------------------------------------------------------------- /test/reedsolomon-test.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit tests for the Reed-Solomon implementation. 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | #include "gmock/gmock.h" 7 | 8 | #include "ReedSolomon.hpp" 9 | 10 | TEST(ReedSolomonTest, Test1) 11 | { 12 | ReedSolomon_63<8> rs; 13 | 14 | int recd[63] = {}; 15 | int expected[63] = {}; 16 | int output[63]; 17 | 18 | // send this message 19 | recd[ 0] = 8+4; 20 | recd[ 1] = 3; 21 | recd[ 2] = 8+2; 22 | recd[ 3] = 16+1; 23 | recd[ 4] = 16+2; 24 | recd[ 5] = 32+8+3; // error 25 | recd[ 6] = 4; 26 | recd[ 7] = 32+2; 27 | recd[ 8] = 32+2; // error 28 | recd[ 9] = 32+16+8+1; 29 | recd[10] = 32+16+1; 30 | recd[11] = 32+16+3; 31 | recd[12] = 16+8; // error 32 | recd[13] = 32+2; // error 33 | recd[14] = 16+4; 34 | recd[15] = 16+4+3; 35 | recd[16+0] = 1; 36 | recd[16+1] = 0; 37 | recd[16+2] = 0; 38 | recd[16+3] = 0; 39 | recd[16+4] = 0; 40 | recd[16+5] = 0; 41 | recd[16+6] = 8; 42 | 43 | // expect this message 44 | expected[ 0] = 8+4; 45 | expected[ 1] = 3; 46 | expected[ 2] = 8+2; 47 | expected[ 3] = 16+1; 48 | expected[ 4] = 16+2; 49 | expected[ 5] = 32+3; 50 | expected[ 6] = 4; 51 | expected[ 7] = 32+2; 52 | expected[ 8] = 32+8+2; 53 | expected[ 9] = 32+16+8+1; 54 | expected[10] = 32+16+1; 55 | expected[11] = 32+16+3; 56 | expected[12] = 16; 57 | expected[13] = 32+8+2; 58 | expected[14] = 16+4; 59 | expected[15] = 16+4+3; 60 | expected[16+0] = 1; 61 | expected[16+1] = 0; 62 | expected[16+2] = 0; 63 | expected[16+3] = 0; 64 | expected[16+4] = 0; 65 | expected[16+5] = 0; 66 | expected[16+6] = 8; 67 | 68 | 69 | rs.decode(recd, output); /* recd[] is returned in polynomial form */ 70 | 71 | /* 72 | printf("Results for Reed-Solomon code (n=%3d, k=%3d, t= %3d)\n\n", nn, kk, tt); 73 | printf(" i recd[i](decoded)\n"); 74 | for (int i = 0; i < nn; i++) { 75 | char b[9]; 76 | byte_to_binary(b, output[i]); 77 | printf("%3d [%s]\n", i, b); 78 | } 79 | printf("\n"); 80 | */ 81 | 82 | EXPECT_THAT(expected, testing::ElementsAreArray(output, 63)); 83 | } 84 | 85 | static void generate_random_bits(char* p, unsigned int count) 86 | { 87 | for (unsigned int i=0; i RAND_MAX/2)? 1 : 0; 89 | } 90 | } 91 | 92 | TEST(ReedSolomonTest, Test_encode_24_12_13) 93 | { 94 | char hex[12*6]; 95 | char parity[12*6]; 96 | 97 | DSDReedSolomon_24_12_13 rs; 98 | 99 | for (unsigned i=0; i<1000; i++) { 100 | generate_random_bits((char*)hex, 12*6); 101 | 102 | // Make a copy 103 | char expected[12*6]; 104 | 105 | memcpy(expected, hex, 12*6); 106 | 107 | 108 | 109 | // Encode 110 | rs.encode(hex, parity); 111 | 112 | // Decode back, should have the same result and no errors 113 | int irrecoverable_errors = rs.decode(hex, parity); 114 | 115 | EXPECT_EQ(0, irrecoverable_errors); 116 | 117 | EXPECT_THAT(expected, testing::ElementsAreArray(hex, 12*6)); 118 | } 119 | } 120 | 121 | TEST(ReedSolomonTest, Test_encode_24_16_9) 122 | { 123 | char hex[16*6]; 124 | char parity[8*6]; 125 | 126 | DSDReedSolomon_24_16_9 rs; 127 | 128 | for (unsigned i=0; i<1000; i++) { 129 | generate_random_bits((char*)hex, 16*6); 130 | 131 | // Make a copy 132 | char expected[16*6]; 133 | 134 | memcpy(expected, hex, 16*6); 135 | 136 | 137 | 138 | // Encode 139 | rs.encode(hex, parity); 140 | 141 | // Decode back, should have the same result and no errors 142 | int irrecoverable_errors = rs.decode(hex, parity); 143 | 144 | EXPECT_EQ(0, irrecoverable_errors); 145 | 146 | EXPECT_THAT(expected, testing::ElementsAreArray(hex, 16*6)); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /test/test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | int main(int argc, char* argv[]) 4 | { 5 | ::testing::InitGoogleTest(&argc, argv); 6 | return RUN_ALL_TESTS(); 7 | } 8 | --------------------------------------------------------------------------------