Compare commits

...

141 Commits

Author SHA1 Message Date
wb2osz 390d4a8c27
Update ci.yml
Upload artifact v2 doesn't work anymore.
2024-09-13 11:53:01 -04:00
Rafael Gustavo da Cunha Pereira Pinto 69407ccf84 Update codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 41e7851376 Update codeql-analysis-python.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto c5c7d4a44d Update codeql-analysis-python.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto e7b4650935 Update codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 21048d5d1a Create codeql-analysis-python.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 3aa8097461 removing python from codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 3f3fed216b Update codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 9ae4edcabf Update codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 7935054ee3 Update codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto c499496bbc Update CMakeLists.txt 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 0a1670f7c2 Update codeql-analysis.yml 2024-05-06 14:30:42 -04:00
Rafael Gustavo da Cunha Pereira Pinto 7552105282 Update codeql-analysis.yml to v2 2024-05-06 14:30:42 -04:00
wb2osz de293a1f25 Merge remote-tracking branch 'origin/dev' 2023-10-28 16:03:04 +01:00
wb2osz 2260df15a5 Release Notes 1.7. 2023-10-28 15:01:48 +01:00
wb2osz 6ed85d12b1 User Guide for release 1.7. 2023-10-28 02:03:55 +01:00
wb2osz 62e4566cc9 Change version to 1.7 release. 2023-10-28 02:03:19 +01:00
wb2osz 9807304d63 Bump version to 1.7 release. 2023-10-28 01:10:20 +01:00
wb2osz 091670a917 New device identifier location. 2023-10-28 01:00:50 +01:00
wb2osz 7b9325ecb6 Documentation update for release 1.7. 2023-10-27 23:31:57 +01:00
wb2osz fae30a6035 Move to new directory. 2023-10-14 22:34:32 +01:00
wb2osz 786e43322f Fix comment. 2023-10-14 17:45:39 +01:00
wb2osz 34ba203532 Clean up sample direwolf.conf file. 2023-10-14 17:39:42 +01:00
wb2osz 88e2222db6 Better keyword for preemptive digipeating. 2023-10-14 17:37:46 +01:00
wb2osz 6b76e1d98d Don't let t1v get out of control. 2023-10-14 17:34:46 +01:00
wb2osz 6bd296bd7e glibc 2.38 has strlcpy and strlcat but cmake does not detect it. 2023-10-14 17:31:07 +01:00
wb2osz ab834f338b Second attempt to fix build on Alpine Linux. issues 150, 319, 344. 2023-09-25 03:17:15 +01:00
wb2osz 3c73a6b2b2 Revert "Fix build on Alpine Linux. issues 150, 319, 344."
This reverts commit 877d1c7707.
2023-09-22 22:43:12 -04:00
wb2osz 877d1c7707 Fix build on Alpine Linux. issues 150, 319, 344. 2023-09-23 02:48:28 +01:00
wb2osz ba0313ca78 Add FTM-500D to recognized device identifers. 2023-09-11 00:08:58 +01:00
wb2osz a08d0939b5 Add FEC type to station heard line. 2023-09-11 00:07:36 +01:00
wb2osz 7a8e4320ac Issue 486. Maybe. 2023-08-16 15:00:10 +01:00
Brent Petit a87b72e040
Handle slow Hamlib init. This change adds a retry loop to the (#484)
rig_open call. If the rig_open continues to fail after 5 tries,
exit.
2023-08-08 13:48:53 -04:00
wb2osz 2434e5f13b Minor cleanups. 2023-08-08 17:34:06 +01:00
wb2osz dfc063f905 Minor clarifications. 2023-08-08 00:14:47 +01:00
wb2osz 80bbf5a553 FIX_BITS default to 0. 2023-08-08 00:02:44 +01:00
wb2osz 790c8ab723 Additional documentation location. 2023-08-07 23:51:08 +01:00
wb2osz 9d2ded2eec Add TH-D75 and another seen on APRS Thursday. 2023-08-07 23:47:48 +01:00
Andrew Rodland c5ad945c3c
Fix IL2PTX config parsing (#483)
We were checking `*t` for end of string instead of `*c`, but `t` never changes, so we would run off of the end of the buffer and output a very large number of config errors before eventually crashing.
2023-07-17 13:21:22 -04:00
wb2osz fed79a7978 Mention IL2P transmit for channels besides first. 2023-07-17 02:28:16 +01:00
wb2osz e84a622515 Look past third party header for packet filtering. 2023-06-14 01:37:08 +01:00
wb2osz f9cf42b291 Better interpretation of bulletin identifiers. 2023-06-03 20:24:30 +01:00
wb2osz 4008153334 Silently ignore AGW protocol application login. 2023-05-21 21:32:54 +01:00
wb2osz d6ae84daad Set AIOC HID permission. 2023-05-21 21:27:48 +01:00
wb2osz 415a08da1e Add AIOC to list for cm108 ptt. 2023-05-18 00:17:39 +01:00
wb2osz a3d3143d21 +x permission 2023-05-15 00:45:02 +01:00
wb2osz e53fa0c110 Fix Windows 11 build. 2023-05-14 23:33:06 +01:00
wb2osz 0058145eff Minor typo. 2023-05-14 23:32:05 +01:00
wb2osz b1b3e854be Remove Ubuntu 18 from automated test build. 2023-05-14 23:30:44 +01:00
wb2osz 577b2b3cf2 Automated test case for EAS SAME. 2023-05-14 23:27:45 +01:00
wb2osz f8b9cae461 Improved error messages. 2023-05-14 23:25:02 +01:00
wb2osz 92a2097d30 New warnings for gcc 11.3. 2023-05-11 21:29:45 +01:00
wb2osz 24a06aef9e 1.7 dev version G 2023-05-08 03:23:26 +01:00
wb2osz b1727345e0 Issue 401 - Avoid receiving own transmission due to audio crosstalk. 2023-05-08 02:27:59 +01:00
wb2osz 8e32286604 Issue 275 - AGW 'd' would not abort a connect attempt in progress. 2023-05-07 02:38:00 +01:00
wb2osz 8000e46c02 Issue 427 - callsign order for AGW protocol 'Y'. 2023-05-04 18:56:09 +01:00
wb2osz 5fb4081c86 Remove capability to download tocalls.txt, etc. 2023-05-02 02:27:15 +01:00
wb2osz 110b85a781 Add EAS to gen_packets. 2023-05-01 02:41:05 +01:00
wb2osz 4ac666df6a Clean up atest EAS receive. 2023-04-30 21:48:51 +01:00
wb2osz 4cd63df5be Use channel rather than port when dumping KISS frame. 2023-04-26 01:07:05 +01:00
wb2osz 75ccf181f9 Improve config error checking. 2023-04-07 16:29:27 -04:00
wb2osz 019ff3bda6 Update config.c 2023-04-07 14:14:32 -04:00
wb2osz 11468f26f8 Improve error message. 2023-03-05 15:38:06 +00:00
wb2osz eb813e5804 Reduce noise. 2023-03-05 15:12:49 +00:00
wb2osz 7573f996c4 Improve error message. 2023-03-05 15:11:00 +00:00
wb2osz dbb4777ba7 More comments. 2023-03-05 15:10:05 +00:00
wb2osz cac83f2506 Improve error message. 2023-03-05 15:07:46 +00:00
wb2osz b4b7b1388d Improve error message. 2023-03-05 15:06:48 +00:00
wb2osz 8a978876bd Cleanup. 2023-03-05 15:06:07 +00:00
wb2osz 8cb73d2507 More documentation references. 2023-03-05 15:04:31 +00:00
wb2osz c25629a286 Merge branch 'dev' of http://github.com/wb2osz/direwolf into dev 2023-01-30 03:09:23 +00:00
wb2osz 8e289025d7 Notes for future. 2023-01-30 03:03:30 +00:00
wb2osz 04ecdbc6fc Complete the new ICHANNEL feature. 2023-01-30 02:50:17 +00:00
ra1nb0w 0f92f463f4
github actions implementation (#396)
* Create codeql-analysis.yml

* cmake: add support for Visual Studio 2019

* enable github actions (aka continuous integration)

basic implementation to enable github actions with:
- triggered each push or pull request
- built on ubuntu (multiple version), macOS, windows
- the binary has debug facilities enabled
- ignore any commit/push on the .github folder
- run all tests
- create an archive with binaries (available for 90 days)
- can manually triggered setting custom cmake flags

* cmake: fix MSVC check

* github actions: remove ubuntu 18.04; add ubuntu 22.04

* github actions: fix windows ci

---------

Co-authored-by: wb2osz <wb2osz@comcast.net>
2023-01-28 16:07:56 -05:00
dforsi fedfef92cd
Fix spellling (#409)
Fixed with
codespell --skip external,symbols*.txt,tocalls.txt,./cmake/* --ignore-words-list clen,convers,dout,feets,fo,inout,ist,ot,parm,pres,ro,siz,usng,xwindows --summary

running first with only --write-changes and then adding --interactive=2

Co-authored-by: Daniele Forsi <iu5hkx@gmail.com>
2023-01-28 15:58:09 -05:00
wb2osz 031c937cdb Issue 444 - Command line -x calibrate tones are reversed 2023-01-28 16:36:51 +00:00
wb2osz ef573f2acf Pull request 439 - Fix audio level display for B demodulator. 2023-01-23 23:11:34 +00:00
Brent Petit 399ffcccb3 Add in a couple missing includes to clean up build warnings 2023-01-16 10:43:25 -05:00
wb2osz 9553abc28e Tested compatibility with gpsd 3.25. 2023-01-15 22:54:11 +00:00
wb2osz 1d452fe1ab Tested compatibility with gpsd 3.25. 2023-01-15 21:55:08 +00:00
wb2osz 17d3d0a621 Increase max AFSK filter size. 2022-12-18 20:19:37 +00:00
wb2osz 07ea828c28 Assorted minor cleanups. 2022-11-25 22:59:36 +00:00
wb2osz 397362787f Remove cmake warnings about slight name mismatches. 2022-11-25 21:26:23 +00:00
wb2osz 8913a852fd clean up 2022-10-01 02:32:43 +01:00
wb2osz d0fc24aa5d Just comments. 2022-10-01 02:28:10 +01:00
wb2osz acace8cd9a Variable speed for gen_packets. 2022-10-01 01:08:28 +01:00
wb2osz 429d095665 Issue 417 - Allow UTF-8 characters for Mac audio device names. 2022-09-25 22:30:19 +01:00
wb2osz 30869c7afc Issues 405 & 406 and other improvements in message interpretation. 2022-07-04 02:11:55 +01:00
wb2osz d11bd6f3f2 pull request 355 - verb correction 2022-05-24 02:23:05 +01:00
wb2osz 59288b7c56 Pull Request 394 - fix compilation on musl 2022-05-24 02:03:37 +01:00
wb2osz c9ffbd71c3 Merge branch 'dev' of http://github.com/wb2osz/direwolf into dev 2022-03-23 19:25:58 -04:00
wb2osz f97c024a90 More FX.25 tests. 2022-03-24 00:22:19 +01:00
wb2osz 722fefbda6 Compile warnings. 2022-03-24 00:21:12 +01:00
wb2osz 18c65f48a8 Note for future experiment. 2022-03-24 00:19:51 +01:00
wb2osz 368bc42337 Spelling errors. 2022-03-24 00:15:04 +01:00
wb2osz 06d6cabb58 Special ATGP digipeating hack. 2022-03-24 00:12:01 +01:00
wb2osz 3dd125e1e3 UTF-8 discussion 2022-03-24 00:10:21 +01:00
wb2osz a558348635 UTF-8 in config file experiment. 2022-03-24 00:07:31 +01:00
wb2osz 7d3c1d100e
Create codeql-analysis.yml 2022-03-23 18:38:53 -04:00
Daniele Forsi bb16c725b9 Fix spelling errors
Fixed with:
codespell --ignore-words-list=dout,feets,fo,inout,ist,ot,parm,usng src --write-changes --interactive=2
and manual editing.
2022-03-22 20:10:29 -04:00
wb2osz 0bd31ae16e Clean up warnings. 2022-02-27 15:30:16 +00:00
wb2osz e108147655 Fix ttgrid corner and various cleanups. 2022-02-25 22:29:07 +00:00
wb2osz 4f6ca0d389 Update tocalls.txt and symbols-new.txt 2022-02-21 16:30:03 +00:00
wb2osz 27019b4793 The constant thorn in my side. 2022-02-16 02:55:19 +00:00
wb2osz 26727bbace Pull request 301 2022-02-16 02:43:29 +00:00
wb2osz 89021dd50c Cleanups 2022-02-16 02:42:15 +00:00
wb2osz dcabb8f7a5 Digipeat noid 2022-01-30 20:00:43 +00:00
wb2osz 0f2b241763 More error checking for messages. 2022-01-17 22:10:47 +00:00
wb2osz 366e0ab6e0 Clean up 2022-01-03 15:36:07 +00:00
wb2osz 42314b7219 gpsd 3.23 (API 12) compatibility and cleanups. 2022-01-02 02:55:11 +00:00
wb2osz 5dbe2ce136 Allow speed for GPSNMEA configuration. 2021-12-29 17:30:20 -05:00
wb2osz 65869bc643 Issue 366 - Remove 0x from pid in monitor header. 2021-12-19 16:30:45 -05:00
wb2osz eef35cf891 Issue 367 - AGW monitoring must handle binary data. 2021-12-19 21:06:42 +00:00
wb2osz 45cd680b90 First rough approximation of ICHANNEL. 2021-12-09 22:30:31 -05:00
wb2osz 9b9744ba15 Speed up 9600 demodulator. 2021-11-22 21:15:17 -05:00
wb2osz 049614d16c Fix IL2P for 9600 bps. 2021-11-22 21:10:31 -05:00
wb2osz 6442466a5d Shut off confusing debug message. 2021-11-11 20:01:30 -05:00
wb2osz 9016fa5fe6 Make IL2P test scripts executable. 2021-10-22 19:09:35 -04:00
wb2osz 53e9ff7908 Add IL2P. 2021-10-22 17:29:20 -04:00
wb2osz 17b9336ce0 Merge branch 'dev' of http://github.com/wb2osz/direwolf into dev 2021-09-29 18:41:02 -04:00
wb2osz 8619b74c7b Pull request 353 - Fix spelling errors. 2021-09-29 18:28:17 -04:00
wb2osz 023f675caa Avoid serial port write error for Windows, 2021-09-21 13:29:29 -04:00
wb2osz 3220931439 Race condition when starting up with transmit queue not empty. Larger buffers. 2021-09-21 13:22:27 -04:00
wb2osz 1712fbcfb9 cleanup 2021-09-21 13:20:10 -04:00
wb2osz b77762780f More debug code. 2021-09-21 13:00:36 -04:00
wb2osz 257d2e3544 New get/set methods for packet object. 2021-09-21 12:56:45 -04:00
wb2osz 1b3ed76584 Add a comment about bundling multiple frames in single transmission. 2021-09-21 12:53:17 -04:00
Daniele Forsi edc5707cfe Fix errors in man pages
Errors found with codespell.
2021-09-19 21:25:00 +02:00
Daniele Forsi d10ccb6cc0 Fix errors in strings
Errors found with codespell.
2021-09-19 21:25:00 +02:00
Daniele Forsi 6bfd22811c Fix errors in comments
Errors found with codespell.
2021-09-19 21:25:00 +02:00
wb2osz b66c21d39b Fix broken hyperlink in README. 2021-04-10 21:21:37 -04:00
wb2osz 6370b26d85 Pull request 322 - SNDIO support for BSD. 2021-04-10 21:14:26 -04:00
wb2osz 0e68a7712a Pull Request 322 - SNDIO support for BSD. 2021-04-10 20:47:46 -04:00
wb2osz 73d5d139b4 Recognize Windows form of device path. 2021-04-10 20:46:13 -04:00
wb2osz 12de518fa9 Mention installation with Mac Ports. 2021-04-10 20:45:13 -04:00
wb2osz 44df4a7612 Issue 325 - When building regex for Windows, don't repeatedly define the global variable re_syntax_options. 2021-04-10 20:00:47 -04:00
SASANO Takayoshi 0c285a0c6d cosme
rewrite

    int err;
    err = poll_sndio();
    if (err < 0) {
        :

to

    if (poll_sndio() < 0) {
        :
2021-02-26 06:57:59 +09:00
SASANO Takayoshi c18b562409 add sndio support (CMake) 2021-02-25 20:36:34 +09:00
SASANO Takayoshi 677117bff0 add sndio support 2021-02-25 20:35:41 +09:00
wb2osz fe6cba2b0d
Merge pull request #309 from df7cb/telemetry-python3
scripts/telemetry-toolkit/telem-volts.py: Port to python3
2021-01-03 17:47:36 -05:00
Christoph Berg a30f90956b scripts/telemetry-toolkit/telem-volts.py: Port to python3 2021-01-03 22:45:36 +01:00
135 changed files with 9459 additions and 1667 deletions

162
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,162 @@
name: 'build direwolf'
on:
# permit to manually trigger the CI
workflow_dispatch:
inputs:
cmake_flags:
description: 'Custom CMAKE flags'
required: false
push:
paths-ignore:
- '.github/**'
pull_request:
paths-ignore:
- '.github/**'
jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: 'Windows Latest MinGW 64bit',
os: windows-latest,
cc: 'x86_64-w64-mingw32-gcc',
cxx: 'x86_64-w64-mingw32-g++',
ar: 'x86_64-w64-mingw32-ar',
windres: 'x86_64-w64-mingw32-windres',
arch: 'x86_64',
build_type: 'Release',
cmake_extra_flags: '-G "MinGW Makefiles"'
}
- {
name: 'Windows 2019 MinGW 32bit',
os: windows-2019,
cc: 'i686-w64-mingw32-gcc',
cxx: 'i686-w64-mingw32-g++',
ar: 'i686-w64-mingw32-ar',
windres: 'i686-w64-mingw32-windres',
arch: 'i686',
build_type: 'Release',
cmake_extra_flags: '-G "MinGW Makefiles"'
}
- {
name: 'macOS latest',
os: macos-latest,
cc: 'clang',
cxx: 'clang++',
arch: 'x86_64',
build_type: 'Release',
cmake_extra_flags: ''
}
- {
name: 'Ubuntu latest Debug',
os: ubuntu-latest,
cc: 'gcc',
cxx: 'g++',
arch: 'x86_64',
build_type: 'Debug',
cmake_extra_flags: ''
}
- {
name: 'Ubuntu 22.04',
os: ubuntu-22.04,
cc: 'gcc',
cxx: 'g++',
arch: 'x86_64',
build_type: 'Release',
cmake_extra_flags: ''
}
- {
name: 'Ubuntu 20.04',
os: ubuntu-20.04,
cc: 'gcc',
cxx: 'g++',
arch: 'x86_64',
build_type: 'Release',
cmake_extra_flags: ''
}
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 8
- name: dependency
shell: bash
run: |
# this is not perfect but enought for now
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update
sudo apt-get install libasound2-dev libudev-dev libhamlib-dev gpsd
elif [ "$RUNNER_OS" == "macOS" ]; then
# just to simplify I use homebrew but
# we can use macports (latest direwolf is already available as port)
brew install portaudio hamlib gpsd
elif [ "$RUNNER_OS" == "Windows" ]; then
# add the folder to PATH
echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH
fi
- name: create build environment
run: |
cmake -E make_directory ${{github.workspace}}/build
- name: configure
shell: bash
working-directory: ${{github.workspace}}/build
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
export CC=${{ matrix.config.cc }}
export CXX=${{ matrix.config.cxx }}
export AR=${{ matrix.config.ar }}
export WINDRES=${{ matrix.config.windres }}
fi
cmake $GITHUB_WORKSPACE \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DCMAKE_C_COMPILER=${{ matrix.config.cc }} \
-DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} \
-DCMAKE_CXX_FLAGS="-Werror" -DUNITTEST=1 \
${{ matrix.config.cmake_extra_flags }} \
${{ github.event.inputs.cmake_flags }}
- name: build
shell: bash
working-directory: ${{github.workspace}}/build
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
export CC=${{ matrix.config.cc }}
export CXX=${{ matrix.config.cxx }}
export AR=${{ matrix.config.ar }}
export WINDRES=${{ matrix.config.windres }}
fi
cmake --build . --config ${{ matrix.config.build_type }} \
${{ github.event.inputs.cmake_flags }}
- name: test
continue-on-error: true
shell: bash
working-directory: ${{github.workspace}}/build
run: |
ctest -C ${{ matrix.config.build_type }} \
--parallel 2 --output-on-failure \
${{ github.event.inputs.cmake_flags }}
- name: package
shell: bash
working-directory: ${{github.workspace}}/build
run: |
if [ "$RUNNER_OS" == "Windows" ] || [ "$RUNNER_OS" == "macOS" ]; then
make package
fi
- name: archive binary
uses: actions/upload-artifact@v4
with:
name: direwolf_${{ matrix.config.os }}_${{ matrix.config.arch }}_${{ github.sha }}
path: |
${{github.workspace}}/build/direwolf-*.zip
${{github.workspace}}/build/direwolf.conf
${{github.workspace}}/build/src/*
${{github.workspace}}/build/CMakeCache.txt
!${{github.workspace}}/build/src/cmake_install.cmake
!${{github.workspace}}/build/src/CMakeFiles
!${{github.workspace}}/build/src/Makefile

View File

@ -0,0 +1,64 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL - Python"
on:
push:
branches: [ dev ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ dev ]
schedule:
- cron: '25 8 * * 4'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
setup-python-dependencies: true
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

74
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL - CPP"
on:
push:
branches: [ dev ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ dev ]
schedule:
- cron: '25 8 * * 4'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
setup-python-dependencies: true
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
- run: |
mkdir build
cd build
cmake -DUNITTEST=1 ..
make
make test
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

View File

@ -2,12 +2,39 @@
# Revision History #
## Version 1.7 -- Under Development ('dev' branch) ##
## Version 1.7 -- October 2023 ##
### New Documentation: ###
Additional documentation location to slow down growth of main repository. [https://github.com/wb2osz/direwolf-doc](https://github.com/wb2osz/direwolf-doc) . These are more oriented toward achieving a goal and understanding, as opposed to the User Guide which describes the functionality.
- ***APRS Digipeaters***
- ***Internal Packet Routing***
- ***Radio Interface Guide***
- ***Successful IGate Operation***
- ***Understanding APRS Packets***
### New Features: ###
- Limited support for CM109/CM119 GPIO PTT on Windows.
- New ICHANNEL configuration option to map a KISS client application channel to APRS-IS. Packets from APRS-IS will be presented to client applications as the specified channel. Packets sent, by client applications, to that channel will go to APRS-IS rather than a radio channel. Details in ***Internal-Packet-Routing.pdf***.
- New variable speed option for gen_packets. For example, "-v 5,0.1" would generate packets from 5% too slow to 5% too fast with increments of 0.1. Some implementations might have imprecise timing. Use this to test how well TNCs tolerate sloppy timing.
- Improved Layer 2 Protocol [(IL2P)](https://en.wikipedia.org/wiki/FX.25_Forward_Error_Correction). Compatible with Nino TNC for 1200 and 9600 bps. Use "-I 1" on command line to enable transmit for first channel. For more general case, add to config file (simplified version, see User Guide for more details):
> After: "CHANNEL 1" (or other channel)
>
> Add: "IL2PTX 1"
- Limited support for CM108/CM119 GPIO PTT on Windows.
- Dire Wolf now advertises itself using DNS Service Discovery. This allows suitable APRS / Packet Radio applications to find a network KISS TNC without knowing the IP address or TCP port. Thanks to Hessu for providing this. Currently available only for Linux and Mac OSX. [Read all about it here.](https://github.com/hessu/aprs-specs/blob/master/TCP-KISS-DNS-SD.md)
@ -15,9 +42,28 @@
- The BEACON configuration now recognizes the SOURCE= option. This replaces the AX.25 source address rather than using the MYCALL value for the channel. This is useful for sending more than 5 analog telemetry channels. Use two, or more, source addresses with up to 5 analog channels each.
- For more flexibility, the FX.25 transmit property can now be set individually by channel, rather than having a global setting for all channels. The -X on the command line applies only to channel 0. For other channels you need to add a new line to the configuration file. You can specify a specific number of parity bytes (16, 32, 64) or 1 to choose automatically based on packet size.
> After: "CHANNEL 1" (or other channel)
>
> Add: "FX25TX 1" (or 16 or 32 or 64)
### Bugs Fixed: ###
- The t/m packet filter incorrectly included bulletins. It now allows only "messages" to specific stations. Use of t/m is discouraged. i/180 is the preferred filter for messages to users recently heard locally.
- Packet filtering now skips over any third party header before classifying packet types.
- Fixed build for Alpine Linux.
### Notes: ###
The Windows binary distribution now uses gcc (MinGW) version 11.3.0.
The Windows version is built for both 32 and 64 bit operating systems.
Use the 64 bit version if possible; it runs considerably faster.
## Version 1.6 -- October 2020 ##
### New Build Procedure: ###

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1.0)
cmake_minimum_required(VERSION 3.5.0)
project(direwolf)
@ -133,7 +133,7 @@ endif()
# auto include current directory
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# set OS dependant variables
# set OS dependent variables
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LINUX TRUE)
@ -145,6 +145,10 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
configure_file("${CMAKE_SOURCE_DIR}/cmake/cpack/${CMAKE_PROJECT_NAME}.desktop.in"
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop" @ONLY)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
set(OPENBSD TRUE)
set(HAVE_SNDIO TRUE)
elseif(APPLE)
if("${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "")
message(STATUS "Build for macOS target: local version")
@ -163,15 +167,16 @@ elseif(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_MACOS_DNSSD")
elseif (WIN32)
if(NOT VS2015 AND NOT VS2017)
message(FATAL_ERROR "You must use Microsoft Visual Studio 2015 or 2017 as compiler")
if(C_MSVC)
if (NOT VS2015 AND NOT VS2017 AND NOT VS2019)
message(FATAL_ERROR "You must use Microsoft Visual Studio 2015, 2017 or 2019 as compiler")
else()
# compile with full multicore
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CUSTOM_SHELL_BIN "")
endif()
endif()
# compile with full multicore
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CUSTOM_SHELL_BIN "")
endif()
if (C_CLANG OR C_GCC)
@ -201,10 +206,16 @@ if (C_CLANG OR C_GCC)
# I also took out -Wextra because it spews out so much noise a serious problem was not noticed.
# It might go back in someday when I have more patience to clean up all the warnings.
#
# TODO:
# Try error checking -fsanitize=bounds-strict -fsanitize=leak
# Requires libubsan and liblsan, respectively.
###set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wvla -ffast-math -ftree-vectorize -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE ${EXTRA_FLAGS}")
if(FREEBSD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wvla -ffast-math -ftree-vectorize -D_DEFAULT_SOURCE ${EXTRA_FLAGS}")
else()
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wvla -ffast-math -ftree-vectorize -D_GNU_SOURCE -fsanitize=bounds-strict ${EXTRA_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wvla -ffast-math -ftree-vectorize -D_GNU_SOURCE ${EXTRA_FLAGS}")
endif()
#
@ -254,9 +265,33 @@ endif(WIN32 OR CYGWIN)
# requirements
include(CheckSymbolExists)
# Some platforms provide their own strlcpy & strlcat. (BSD, MacOSX)
# Others don't so we provide our own. (Most, but not all Linux)
# Define the preprocessor macro so libgps does not supply its own version.
# Others don't so we provide our own. (Windows, most, but not all Linux)
# Here we detect whether these are provided by the OS and set a symbol
# so that:
# (1) libgps does not supply its own version.
# (2) we know whether we need to supply our own copy.
#
# This was all working fine until these were added to the gnu c library 2.38.
# References:
# - https://www.gnu.org/software/libc/sources.html
# - https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=NEWS;hb=HEAD
#
# This test is not detecting them for glibc 2.38 resulting in a conflict.
# Why? Are they declared in a different file or in some strange way?
#
# This is how they are declared in include/string.h:
#
# extern __typeof (strlcpy) __strlcpy;
# libc_hidden_proto (__strlcpy)
# extern __typeof (strlcat) __strlcat;
# libc_hidden_proto (__strlcat)
#
# Apparently cmake does not recognize this style.
# Keep this here for BSD type systems where it behaves as expected.
# We will need to add a hack in direwolf.h to define these if glibc version >= 2.38.
check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
if(HAVE_STRLCPY)
add_compile_options(-DHAVE_STRLCPY)
@ -301,6 +336,12 @@ if(LINUX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_AVAHI_CLIENT")
endif()
elseif (HAVE_SNDIO)
find_package(sndio REQUIRED)
if(SNDIO_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SNDIO")
endif()
elseif (NOT WIN32 AND NOT CYGWIN)
find_package(Portaudio REQUIRED)
if(PORTAUDIO_FOUND)
@ -316,6 +357,8 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108")
set(PORTAUDIO_INCLUDE_DIRS "")
set(PORTAUDIO_LIBRARIES "")
set(SNDIO_INCLUDE_DIRS "")
set(SNDIO_LIBRARIES "")
endif()
# manage and fetch new data

View File

@ -1,4 +1,4 @@

# Dire Wolf #
### Decoded Information from Radio Emissions for Windows Or Linux Fans ###
@ -9,11 +9,15 @@ Why waste $200 and settle for mediocre receive performance from a 1980's technol
![](tnc-test-cd-results.png)
Dire Wolf now includes [FX.25](https://en.wikipedia.org/wiki/FX.25_Forward_Error_Correction/) which adds Forward Error Correction (FEC) in a way that is completely compatible with existing systems. If both ends are capable of FX.25, your information will continue to get through under conditions where regular AX.25 is completely useless.
Dire Wolf includes [FX.25](https://en.wikipedia.org/wiki/FX.25_Forward_Error_Correction) which adds Forward Error Correction (FEC) in a way that is completely compatible with existing systems. If both ends are capable of FX.25, your information will continue to get through under conditions where regular AX.25 is completely useless. This was originally developed for satellites and is now seeing widespread use on HF.
![](fx25.png)
Dire Wolf is a modern software replacement for the old 1980's style TNC built with special hardware.
Version 1.7 adds [IL2P](https://en.wikipedia.org/wiki/Improved_Layer_2_Protocol), a different method of FEC with less overhead but it is not compatible with AX.25.
### Dire Wolf is a modern software replacement for the old 1980's style TNC built with special hardware. ###
Without any additional software, it can perform as:
@ -76,7 +80,21 @@ It can also be used as a virtual TNC for other applications such as [APRSIS32](h
- **Standard 300, 1200 & 9600 bps modems and more.**
- **Modems:**
300 bps AFSK for HF
1200 bps AFSK most common for VHF/UHF
2400 & 4800 bps PSK
9600 bps GMSK/G3RUH
AIS reception
EAS SAME reception
- **DTMF ("Touch Tone") Decoding and Encoding.**
@ -96,12 +114,16 @@ It can also be used as a virtual TNC for other applications such as [APRSIS32](h
## Documentation ##
[Stable Version](https://github.com/wb2osz/direwolf/tree/master/doc)
[Latest Development Version](https://github.com/wb2osz/direwolf/tree/dev/doc)
[Latest Development Version ("dev" branch)](https://github.com/wb2osz/direwolf/tree/dev/doc)
[Power Point presentation](https://github.com/wb2osz/direwolf-presentation) -- Why not give a talk at a local club meeting?
[Additional Topics](https://github.com/wb2osz/direwolf-doc)
[Power Point presentations](https://github.com/wb2osz/direwolf-presentation) -- Why not give a talk at a local club meeting?
Youtube has many interesting and helpful videos. Searching for [direwolf tnc](https://www.youtube.com/results?search_query=direwolf+tnc) or [direwolf aprs](https://www.youtube.com/results?search_query=direwolf+aprs) will produce the most relevant results.
## Installation ##
@ -192,6 +214,9 @@ Read the **User Guide** in the [**doc** directory](https://github.com/wb2osz/dir
If you have problems, post them to the [Dire Wolf packet TNC](https://groups.io/g/direwolf) discussion group.
You can also install a pre-built version from Mac Ports. Keeping this up to date depends on volunteers who perform the packaging. This version could lag behind development.
sudo port install direwolf
## Join the conversation ##

View File

@ -9,7 +9,7 @@ if(AVAHI_CLIENT_LIBRARY)
set(AVAHI_CLIENT_FOUND TRUE)
endif()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(AVAHI DEFAULT_MSG AVAHI_COMMON_FOUND AVAHI_CLIENT_FOUND)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Avahi DEFAULT_MSG AVAHI_COMMON_FOUND AVAHI_CLIENT_FOUND)
if (AVAHI_FOUND)
set(AVAHI_INCLUDE_DIRS ${AVAHI_UI_INCLUDE_DIR})

View File

@ -5,7 +5,9 @@ elseif(NOT DEFINED C_GCC AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(C_GCC 1)
elseif(NOT DEFINED C_MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(C_MSVC 1)
if(MSVC_VERSION GREATER 1910 AND MSVC_VERSION LESS 1919)
if(MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS_EQUAL 1929)
set(VS2019 ON)
elseif(MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919)
set(VS2017 ON)
elseif(MSVC_VERSION GREATER 1899 AND MSVC_VERSION LESS 1910)
set(VS2015 ON)

View File

@ -52,7 +52,7 @@ find_library(HAMLIB_LIBRARY
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HAMLIB
find_package_handle_standard_args(hamlib
DEFAULT_MSG
HAMLIB_LIBRARY
HAMLIB_INCLUDE_DIR

View File

@ -0,0 +1,42 @@
# - Try to find sndio
#
# SNDIO_FOUND - system has sndio
# SNDIO_LIBRARIES - location of the library for sndio
# SNDIO_INCLUDE_DIRS - location of the include files for sndio
set(SNDIO_ROOT_DIR
"${SNDIO_ROOT_DIR}"
CACHE
PATH
"Directory to search for sndio")
# no need to check pkg-config
find_path(SNDIO_INCLUDE_DIRS
NAMES
sndio.h
PATHS
/usr/local/include
/usr/include
/opt/local/include
HINTS
${SNDIO_ROOT_DIR}
)
find_library(SNDIO_LIBRARIES
NAMES
sndio
PATHS
/usr/local/lib
/usr/lib
/usr/lib64
/opt/local/lib
HINTS
${SNDIIO_ROOT_DIR}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SNDIO DEFAULT_MSG SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES)
mark_as_advanced(SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES)

View File

@ -65,7 +65,7 @@ find_path(UDEV_INCLUDE_DIR
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(UDEV
find_package_handle_standard_args(udev
DEFAULT_MSG
UDEV_LIBRARY
UDEV_INCLUDE_DIR

View File

@ -3,7 +3,7 @@
# $ ls -l /dev/hidraw*
# crw------- 1 root root 247, 0 Sep 24 09:40 /dev/hidraw0
#
# An ordinary user, trying to acccess it will be denied.
# An ordinary user, trying to access it will be denied.
#
# Unnecessarily running applications as root is generally a bad idea because it makes it too easy
# to accidentally trash your system. We need to relax the restrictions so ordinary users can use these devices.
@ -28,3 +28,9 @@ SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0d8c", GROUP="audio", MODE="0660"
#
# Read the User Guide and run the "cm108" application for more information.
#
#
# Same thing for the "All In One Cable."
#
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="7388", GROUP="audio", MODE="0660"

View File

@ -29,16 +29,21 @@
%C%# Extensive documentation can be found here:
%C%# Stable release - https://github.com/wb2osz/direwolf/tree/master/doc
%C%# Latest development - https://github.com/wb2osz/direwolf/tree/dev/doc
%C%# Additional topics - https://github.com/wb2osz/direwolf-doc
%C%#
%W%# The complete documentation set can also be found in the doc folder.
%L%# The complete documentation set can also be found in
%W%# The basic documentation set can also be found in the doc folder.
%L%# The basic documentation set can also be found in
%L%# /usr/local/share/doc/direwolf/ or /usr/share/doc/direwolf/
%L%# Concise "man" pages are also available for Linux.
%M%# /usr/local/share/doc/direwolf/ or /usr/share/doc/direwolf/
%M%# Concise "man" pages are also available for Mac OSX.
%C%#
%C%# Questions??? Join the discussion forum: https://groups.io/g/direwolf
%C%#
%C%#
%C%# This sample file does not have examples for all of the possibilities.
%C%# Consult the User Guide for more details on configuration options.%C%#
%C%# Consult the User Guide for more details on configuration options
%C%# and other documents for more details for different uses.
%C%#
%C%# These are the most likely settings you might change:
%C%#
@ -93,6 +98,11 @@
%C%# Many people will simply use the default sound device.
%C%# Some might want to use an alternative device by choosing it here.
%C%#
%C%#
%C%# Many examples of radio interfaces and PTT options can be found in:
%C%# https://github.com/wb2osz/direwolf-doc/blob/main/Radio-Interface-Guide.pdf
%C%#
%C%#
%R% ---------- Windows ----------
%R%
%W%# When the Windows version starts up, it displays something like
@ -231,14 +241,14 @@
%C%# It can be up to 6 letters and digits with an optional ssid.
%C%# The APRS specification requires that it be upper case.
%C%#
%C%# Example (don't use this unless you are me): MYCALL WB2OSZ-5
%C%# Example (don't use this unless you are me): MYCALL WB2OSZ-5
%C%#
%C%
%C%MYCALL N0CALL
%C%
%C%#
%C%# Pick a suitable modem speed based on your situation.
%C%# 1200 Most common for VHF/UHF. Default if not specified.
%C%# 1200 Most common for VHF/UHF. This is the default if not specified.
%C%# 2400 QPSK compatible with MFJ-2400, and probably PK232-2400 & KPC-2400.
%C%# 300 Low speed for HF SSB. Default tones 1600 & 1800.
%C%# EAS Emergency Alert System (EAS) Specific Area Message Encoding (SAME).
@ -263,6 +273,10 @@
%C%
%C%#DTMF
%C%
%C%# Push to Talk (PTT) can be confusing because there are so many different cases.
%C%# Radio-Interface-Guide.pdf in https://github.com/wb2osz/direwolf-doc
%C%# goes into detail about the various options.
%C%
%L%# If using a C-Media CM108/CM119 or similar USB Audio Adapter,
%L%# you can use a GPIO pin for PTT control. This is very convenient
%L%# because a single USB connection is used for both audio and PTT.
@ -290,6 +304,7 @@
%C%#PTT COM1 RTS
%C%#PTT COM1 RTS -DTR
%L%#PTT /dev/ttyUSB0 RTS
%L%#PTT /dev/ttyUSB0 RTS -DTR
%C%
%L%#
%L%# On Linux, you can also use general purpose I/O pins if
@ -301,7 +316,7 @@
%L%
%L%#PTT GPIO 25
%L%
%C%# The Data Carrier Detect (DCD) signal can be sent to the same places
%C%# The Data Carrier Detect (DCD) signal can be sent to most of the same places
%C%# as the PTT signal. This could be used to light up an LED like a normal TNC.
%C%
%C%#DCD COM1 -DTR
@ -369,11 +384,11 @@
%W%
%C%#
%C%# It is sometimes possible to recover frames with a bad FCS.
%C%# This applies to all channels.
%C%# This is not a global setting.
%C%# It applies only the the most recent CHANNEL specified.
%C%#
%C%# 0 [NONE] - Don't try to repair.
%C%# 1 [SINGLE] - Attempt to fix single bit error. (default)
%C%# ... see User Guide for more values and in-depth discussion.
%C%# 0 - Don't try to repair. (default)
%C%# 1 - Attempt to fix single bit error.
%C%#
%C%
%C%#FIX_BITS 0
@ -398,15 +413,21 @@
%C%# Example:
%C%#
%C%# This results in a broadcast once every 10 minutes.
%C%# Every half hour, it can travel via two digipeater hops.
%C%# Every half hour, it can travel via one digipeater hop.
%C%# The others are kept local.
%C%#
%C%
%C%#PBEACON delay=1 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W power=50 height=20 gain=4 comment="Chelmsford MA" via=WIDE1-1,WIDE2-1
%C%#PBEACON delay=1 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W power=50 height=20 gain=4 comment="Chelmsford MA" via=WIDE1-1
%C%#PBEACON delay=11 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W power=50 height=20 gain=4 comment="Chelmsford MA"
%C%#PBEACON delay=21 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W power=50 height=20 gain=4 comment="Chelmsford MA"
%C%
%C%
%C%#
%C%# Did you know that APRS comments and messages can contain UTF-8 characters, not only plain ASCII?
%C%#
%C%#PBEACON delay=1 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W comment=" Did you know that APRS comments and messages can contain UTF-8 characters? \xe0\xb8\xa7\xe0\xb8\xb4\xe0\xb8\x97\xe0\xb8\xa2\xe0\xb8\xb8\xe0\xb8\xaa\xe0\xb8\xa1\xe0\xb8\xb1\xe0\xb8\x84\xe0\xb8\xa3\xe0\xb9\x80\xe0\xb8\xa5\xe0\xb9\x88\xe0\xb8\x99"
%C%#PBEACON delay=11 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W comment=" Did you know that APRS comments and messages can contain UTF-8 characters? \xce\xa1\xce\xb1\xce\xb4\xce\xb9\xce\xbf\xce\xb5\xcf\x81\xce\xb1\xcf\x83\xce\xb9\xcf\x84\xce\xb5\xcf\x87\xce\xbd\xce\xb9\xcf\x83\xce\xbc\xcf\x8c\xcf\x82"
%C%#PBEACON delay=21 every=30 overlay=S symbol="digi" lat=42^37.14N long=071^20.83W comment=" Did you know that APRS comments and messages can contain UTF-8 characters? \xe3\x82\xa2\xe3\x83\x9e\xe3\x83\x81\xe3\x83\xa5\xe3\x82\xa2\xe7\x84\xa1\xe7\xb7\x9a"
%C%#
%C%# With UTM coordinates instead of latitude and longitude.
%C%
%C%#PBEACON delay=1 every=10 overlay=S symbol="digi" zone=19T easting=307477 northing=4720178
@ -442,17 +463,11 @@
%C%# the "#" from the beginning of the line below.
%C%#
%C%
%C%#DIGIPEAT 0 0 ^WIDE[3-7]-[1-7]$|^TEST$ ^WIDE[12]-[12]$ TRACE
%C%#DIGIPEAT 0 0 ^WIDE[3-7]-[1-7]$|^TEST$ ^WIDE[12]-[12]$
%C%
%C%# See User Guide for more explanation of what this means and how
%C%# it can be customized for your particular needs.
%C%# See User Guide and "APRS-Digipeaters.pdf" for more explanation of what
%C%# this means and how it can be customized for your particular needs.
%C%
%C%# Filtering can be used to limit was is digipeated.
%C%# For example, only weather weather reports, received on channel 0,
%C%# will be retransmitted on channel 1.
%C%#
%C%
%C%#FILTER 0 1 t/wn
%C%
%C%# Traditional connected mode packet radio uses a different
%C%# type of digipeating. See User Guide for details.
@ -486,6 +501,7 @@
%C%# without sending it over the air and relying on someone else to
%C%# forward it to an IGate server. This is done by using sendto=IG rather
%C%# than a radio channel number. Overlay R for receive only, T for two way.
%C%# There is no need to send it as often as you would over the radio.
%C%
%C%#PBEACON sendto=IG delay=0:30 every=60:00 symbol="igate" overlay=R lat=42^37.14N long=071^20.83W
%C%#PBEACON sendto=IG delay=0:30 every=60:00 symbol="igate" overlay=T lat=42^37.14N long=071^20.83W
@ -494,13 +510,14 @@
%C%# To relay messages from the Internet to radio, you need to add
%C%# one more option with the transmit channel number and a VIA path.
%C%
%C%#IGTXVIA 0 WIDE1-1
%C%#IGTXVIA 0 WIDE1-1,WIDE2-1
%C%
%C%
%C%# Finally, we don't want to flood the radio channel.
%C%# The IGate function will limit the number of packets transmitted
%C%# during 1 minute and 5 minute intervals. If a limit would
%C%# be exceeded, the packet is dropped and message is displayed in red.
%C%# This might be low for APRS Thursday when there is abnormally high activity.
%C%
%C%IGTXLIMIT 6 10
%C%
@ -517,82 +534,4 @@
%C%#
%C%# See separate "APRStt-Implementation-Notes" document for details.
%C%#
%C%
%C%#
%C%# Sample gateway configuration based on:
%C%#
%C%# http://www.aprs.org/aprstt/aprstt-coding24.txt
%C%# http://www.aprs.org/aprs-jamboree-2013.html
%C%#
%C%
%C%# Define specific points.
%C%
%C%TTPOINT B01 37^55.37N 81^7.86W
%C%TTPOINT B7495088 42.605237 -71.34456
%C%TTPOINT B934 42.605237 -71.34456
%C%
%C%TTPOINT B901 42.661279 -71.364452
%C%TTPOINT B902 42.660411 -71.364419
%C%TTPOINT B903 42.659046 -71.364452
%C%TTPOINT B904 42.657578 -71.364602
%C%
%C%
%C%# For location at given bearing and distance from starting point.
%C%
%C%TTVECTOR B5bbbddd 37^55.37N 81^7.86W 0.01 mi
%C%
%C%# For location specified by x, y coordinates.
%C%
%C%TTGRID Byyyxxx 37^50.00N 81^00.00W 37^59.99N 81^09.99W
%C%
%C%# UTM location for Lowell-Dracut-Tyngsborough State Forest.
%C%
%C%TTUTM B6xxxyyy 19T 10 300000 4720000
%C%
%C%
%C%
%C%# Location for the corral.
%C%
%C%TTCORRAL 37^55.50N 81^7.00W 0^0.02N
%C%
%C%# Compact messages - Fixed locations xx and object yyy where
%C%# Object numbers 100 - 199 = bicycle
%C%# Object numbers 200 - 299 = fire truck
%C%# Others = dog
%C%
%C%TTMACRO xx1yy B9xx*AB166*AA2B4C5B3B0A1yy
%C%TTMACRO xx2yy B9xx*AB170*AA3C4C7C3B0A2yy
%C%TTMACRO xxyyy B9xx*AB180*AA3A6C4A0Ayyy
%C%
%C%TTMACRO z Cz
%C%
%C%# Receive on channel 0, Transmit object reports on channel 1 with optional via path.
%C%# You probably want to put in a transmit delay on the APRStt channel so it
%C%# it doesn't start sending a response before the user releases PTT.
%C%# This is in 10 ms units so 100 means 1000 ms = 1 second.
%C%
%C%#TTOBJ 0 1 WIDE1-1
%C%#CHANNEL 0
%C%#DWAIT 100
%C%
%C%# Advertise gateway position with beacon.
%C%
%C%# OBEACON DELAY=0:15 EVERY=10:00 VIA=WIDE1-1 OBJNAME=WB2OSZ-tt SYMBOL=APRStt LAT=42^37.14N LONG=71^20.83W COMMENT="APRStt Gateway"
%C%
%C%
%C%# Sample speech responses.
%C%# Default is Morse code "R" for received OK and "?" for all errors.
%C%
%C%#TTERR OK SPEECH Message Received.
%C%#TTERR D_MSG SPEECH D not implemented.
%C%#TTERR INTERNAL SPEECH Internal error.
%C%#TTERR MACRO_NOMATCH SPEECH No definition for digit sequence.
%C%#TTERR BAD_CHECKSUM SPEECH Bad checksum on call.
%C%#TTERR INVALID_CALL SPEECH Invalid callsign.
%C%#TTERR INVALID_OBJNAME SPEECH Invalid object name.
%C%#TTERR INVALID_SYMBOL SPEECH Invalid symbol.
%C%#TTERR INVALID_LOC SPEECH Invalid location.
%C%#TTERR NO_CALL SPEECH No call or object name.
%C%#TTERR SATSQ SPEECH Satellite square must be 4 digits.
%C%#TTERR SUFFIX_NO_CALL SPEECH Send full call before using suffix.
%C%

View File

@ -1,4 +1,19 @@
#
# Update: 1 May 2023 (still 1.7 dev version)
#
# The original intention was to allow an easy way to download the most
# recent versions of some files.
#
# "update-data" would only work once.
#
# These locations are no longer being maintained:
# http://www.aprs.org/aprs11/tocalls.txt -- 14 Dec 2021
# http://www.aprs.org/symbols/symbols-new.txt -- 17 Mar 2021
# http://www.aprs.org/symbols/symbolsX.txt -- 25 Nov 2015
# so there is no reason to provide a capability grab the latest version.
#
# Rather than fixing an obsolete capability, it will just be removed.
#
# The destination field is often used to identify the manufacturer/model.
# These are not hardcoded into Dire Wolf. Instead they are read from
# a file called tocalls.txt at application start up time.
@ -6,24 +21,13 @@
# The original permanent symbols are built in but the "new" symbols,
# using overlays, are often updated. These are also read from files.
#
# You can obtain an updated copy by typing "make data-update".
# This is not part of the normal build process. You have to do this explicitly.
#
# The locations below appear to be the most recent.
# The copy at http://www.aprs.org/tocalls.txt is out of date.
#
include(ExternalProject)
set(TOCALLS_TXT "tocalls.txt")
set(TOCALLS_TXT_BKP "tocalls.txt.old")
set(TOCALLS_URL "http://www.aprs.org/aprs11/tocalls.txt")
set(SYMBOLS-NEW_TXT "symbols-new.txt")
set(SYMBOLS-NEW_TXT_BKP "symbols-new.txt.old")
set(SYMBOLS-NEW_URL "http://www.aprs.org/symbols/symbols-new.txt")
set(SYMBOLSX_TXT "symbolsX.txt")
set(SYMBOLSX_TXT_BKP "symbolsX.txt.old")
set(SYMBOLSX_URL "http://www.aprs.org/symbols/symbolsX.txt")
set(CUSTOM_BINARY_DATA_DIR "${CMAKE_BINARY_DIR}/data")
# we can also move to a separate cmake file and use file(download)
@ -32,63 +36,6 @@ file(COPY "${CUSTOM_DATA_DIR}/${TOCALLS_TXT}" DESTINATION "${CUSTOM_BINARY_DATA_
file(COPY "${CUSTOM_DATA_DIR}/${SYMBOLS-NEW_TXT}" DESTINATION "${CUSTOM_BINARY_DATA_DIR}")
file(COPY "${CUSTOM_DATA_DIR}/${SYMBOLSX_TXT}" DESTINATION "${CUSTOM_BINARY_DATA_DIR}")
add_custom_target(data_rename
COMMAND ${CMAKE_COMMAND} -E rename "${CUSTOM_BINARY_DATA_DIR}/${TOCALLS_TXT}" "${CUSTOM_BINARY_DATA_DIR}/${TOCALLS_TXT_BKP}"
COMMAND ${CMAKE_COMMAND} -E rename "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLS-NEW_TXT}" "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLS-NEW_TXT_BKP}"
COMMAND ${CMAKE_COMMAND} -E rename "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLSX_TXT}" "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLSX_TXT_BKP}"
)
ExternalProject_Add(download_tocalls
DEPENDS data_rename
URL ${TOCALLS_URL}
PREFIX ""
DOWNLOAD_DIR "${CUSTOM_BINARY_DATA_DIR}"
DOWNLOAD_NAME "${TOCALLS_TXT}"
DOWNLOAD_NO_EXTRACT 0
EXCLUDE_FROM_ALL 1
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
ExternalProject_Add(download_symbols-new
DEPENDS data_rename
URL ${SYMBOLS-NEW_URL}
PREFIX ""
DOWNLOAD_DIR "${CUSTOM_BINARY_DATA_DIR}"
DOWNLOAD_NAME "${SYMBOLS-NEW_TXT}"
DOWNLOAD_NO_EXTRACT 0
EXCLUDE_FROM_ALL 1
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
ExternalProject_Add(download_symbolsx
DEPENDS data_rename
URL ${SYMBOLSX_URL}
PREFIX ""
DOWNLOAD_DIR "${CUSTOM_BINARY_DATA_DIR}"
DOWNLOAD_NAME "${SYMBOLSX_TXT}"
DOWNLOAD_NO_EXTRACT 0
EXCLUDE_FROM_ALL 1
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
add_custom_target(update-data)
add_dependencies(update-data data_rename download_tocalls download_symbols-new download_symbolsx)
install(FILES "${CUSTOM_BINARY_DATA_DIR}/${TOCALLS_TXT}" DESTINATION ${INSTALL_DATA_DIR})
install(FILES "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLS-NEW_TXT}" DESTINATION ${INSTALL_DATA_DIR})
install(FILES "${CUSTOM_BINARY_DATA_DIR}/${SYMBOLSX_TXT}" DESTINATION ${INSTALL_DATA_DIR})

View File

@ -1,7 +1,6 @@
APRS SYMBOL OVERLAY and EXTENSION TABLES in APRS 1.2 17 Jun 2018
APRS SYMBOL OVERLAY and EXTENSION TABLES in APRS 1.2 17 Mar 2021
------------------------------------------------------------------------
BACKGROUND: Since October 2007, overlay characters (36/symbol) are
allowed on all symbols. This allows thousands of uniquely specified
symbols instead of the original 188 (94 primary and 94 alternate).
@ -9,7 +8,9 @@ But the master symbol document, http://aprs.org/symbols/symbolsX.txt,
only has one line per symbol. So this added overlay list below gives
us thousands of new symbol codes.
17 Jun19: Added several overlays for RAIL symbol
17 Mar 21 Added L& for LORA Igate
24 Jun18: Updated CAR symbols
17 Jun18: Added several overlays for RAIL symbol
03 Apr17: Added Methane Hazard symbol "MH"
13 Feb17: Added Ez = Emergency Power (shelter), Cars: P> = Plugin
S> = Solar powered. Moved Ham club C- to Buildings Ch.
@ -211,14 +212,18 @@ CARS: #> (Vehicles)
/> = normal car (side view)
\> = Top view and symbol POINTS in direction of travel
#> = Reserve overlays 1-9 for numbered cars (new Aug 2014)
B> = Battery (was E for electric)
3> = Model 3 (Tesla)
B> = BEV - Battery EV(was E for electric)
D> = DIY - Do it yourself
E> = Ethanol (was electric)
F> = Fuelcell or hydrogen
H> = Homemade
P> = Plugin-hybrid
H> = Hybrid
L> = Leaf
P> = PHEV - Plugin-hybrid
S> = Solar powered
T> = Tesla (temporary)
V> = GM Volt (temporary)
V> = Volt (temporary)
X> = Model X
CIVIL DEFENSE or TRIANGLE: #c
/c = Incident Command Post
@ -269,6 +274,7 @@ FE = (F overlay) Fog was \{
GATEWAYS: #&
/& = HF Gateway <= the original primary table definition
I& = Igate Generic (please use more specific overlay)
L& - Lora Igate
R& = Receive only IGate (do not send msgs back to RF)
P& = PSKmail node
T& = TX igate with path set to 1 hop only)
@ -339,17 +345,17 @@ I; = Islands on the air
S; = Summits on the air
W; = WOTA
POWER or ENERGY: #%
POWER and ENERGY: #%
/% = DX cluster <= the original primary table definition
C% = Coal
E% = Emergency (new Aug 2014)
G% = Geothermal
G% = Gas Turbine
H% = Hydroelectric
N% = Nuclear
P% = Portable (new Aug 2014)
R% = Renewable (hydrogen etc fuels)
S% = Solar
T% = Turbine
T% = Thermal (geo)
W% = Wind
RAIL Symbols: #=

View File

@ -1,44 +1,37 @@
<title>
APRS TO-CALL VERSION NUMBERS 13 Oct 2020
-------------------------------------------------------------------
WB4APR
APRS TO-CALL VERSION NUMBERS 14 Dec 2021
---------------------------------------------------------------------
WB4APR
</title>
<version_notes>
07 Jun 23 Added APK005 for Kenwood TH-D75
14 Dec 21 Added APATAR ATA-R APRS Digipeater by TA7W/OH2UDS and TA6AEU
26 Sep 21 Added APRRDZ EPS32 https://github.com/dl9rdz/rdz_ttgo_sonde
18 Sep 21 Added APCSS for AMSAT Cubesat Simulator https://cubesatsim.org
16 Sep 21 Added APY05D for Yaesu FT5D series
04 Sep 21 APLOxx LoRa KISS TNC/Tracker https://github.com/SQ9MDD/TTGO-T-Beam-LoRa-APRS
24 Aug 21 Added APLSxx SARIMESH http://www.sarimesh.net
22 Aug 21 Added APE2Ax for VA3NNW's Email-2-APRS ap
30 Jun 21 Added APCNxx for carNET by DG5OAW
14 Jun 21 Added APN2xx for NOSaprs JNOS 2.0 - VE4KLM
24 Apr 21 Added APMPAD for DF1JSL's WXBot clone and extension
20 Apr 21 Added APLCxx for APRScube by DL3DCW
19 Apr 21 Added APVMxx for DRCC-DVM Voice (Digital Radio China Club)
13 Apr 21 Added APIxxx for all Dstar ICOMS (APRS via DPRS)
23 MAr 20 Added APW9xx For 9A9Y Weather Tracker
16 Feb 21 Added API970 for I com 9700
13 Oct 20 Added APIZCI hymTR IZCI Tracker by TA7W/OH2UDS and TA6AEU
13 Aug 20 Added APLGxx for LoRa Gateway/Digipeater
APLTxx for LoRa Tracker - OE5BPA
02 Aug 20 Added APNVxx for SQ8L's VP digi and Nodes
26 May 20 Added APY300 for Yaesu
5 May 20 added APESPG ESP SmartBeacon APRS-IS Client
APESPW ESP Weather Station APRS-IS Client
17 Apr 20 Added APGDTx for VK4FAST's Graphic Data Terminal
19 Mar 20 Added APOSW and APOSB for OpenSPOT2 and 3
20 Jan 20 Added APBT62 for BTech DMR 6x2
08 Jan 20 Added APCLUB for Brazil APRS network
06 Jan 20 Added APMQxx for Ham Radio of Things WB2OSZ
18 Dec 19 Added APTPNx: TARPN Packet Node Tracker by KN4ORB
02 Dec 19 added APJ8xx For Jordan / KN4CRD JS8Call application
8 Sep 19 Added APBSDx for OpenBSD or HamBSD https://hambsd.org/
19 Aug 19 Added APNKMX for KAM-XL
and Added APAT51 for Anytone AT-D578UV APRS radio
16 Jul 19 expanded APMGxx to cover PiCrumbs and MiniGate
24 Jun 19 Added APTCMA for CAPI tracker - PU1CMA Brazil
4 Jun 19 added APATxx for Anytone
8 May 19 added APQTHx for W8WJB's QTH.app
12 Mar 19 added APLIGx for LightAPRS
3 Dec 18 added APRARX forVK5QI's radiosonde tracking
8 Nov 18 added APELKx for WB8ELK balloons
24 Oct 18 added APGBLN for NW5W's GoBalloon
18 Apr 18 added APBKxx for PY5BK Bravo Tracker in Brazil
7 Mar 18 added APERSx Runner tracking by Jason,KG7YKZ
8 Jan 18 added APTCHE PU3IKE in Brazil TcheTracker/Tcheduino
2020 Added APHBLx,APIZCI,APLGxx,APLTxx,APNVxx,APY300,APESPG,APESPW
APGDTx,APOSWx,APOSBx,APBT62,APCLUB,APMQxx
2019 Added APTPNx,APJ8xx,APBSDx,APNKMX,APAT51,APMGxx,APTCMA,
APATxx,APQTHx,APLIGx
2018 added APRARX,APELKx,APGBLN,APBKxx,APERSx,APTCHE
2017 Added APHWxx,APDVxx,APPICO,APBMxx,APP6xx,APTAxx,APOCSG,APCSMS,
APPMxx,APOFF,APDTMF,APRSON,APDIGI,APSAT,APTBxx,APIExx,
APSFxx
2016 added APYSxx,APINxx,APNICx,APTKPT,APK004,APFPRS,APCDS0,APDNOx
2015 Added APSTPO,APAND1,APDRxx,APZ247,APHTxx,APMTxx,APZMAJ
APB2MF,APR2MF,APAVT5
APB2MF,APR2MF,APAVT5
</version_notes>
<description>
@ -52,6 +45,10 @@ bytes of the field are available to indicate the software version
number or application. The following applications have requested
a TOCALL number series:
Authors with similar alphabetic requirements are encouraged to share
their address space with other software. Work out agreements amongst
yourselves and keep me informed.
</description>
<tocalls>
@ -69,7 +66,8 @@ a TOCALL number series:
APAHxx AHub
APAND1 APRSdroid (pre-release) http://aprsdroid.org/
APAMxx Altus Metrum GPS trackers
APATxx for Anytone. 81 for 878 HT
APATAR ATA-R APRS Digipeater by TA7W/OH2UDS and TA6AEU
APAT8x for Anytone. 81 for 878 HT
APAT51 for Anytone AT-D578UV APRS mobile radio
APAVT5 SainSonic AP510 which is a 1watt tracker
APAWxx AGWPE
@ -89,7 +87,9 @@ a TOCALL number series:
APCLEZ Telit EZ10 GSM application ZS6CEY
APCLUB Brazil APRS network
APCLWX EYWeather GPRS/GSM WX station by ZS6EY
APCNxx for carNET by DG5OAW
APCSMS for Cosmos (used for sending commands @USNA)
APCSS for AMSAT cubesats https://cubesatsim.org
APCWP8 John GM7HHB, WinphoneAPRS
APCYxx Cybiko applications
APD APD4xx UP4DAR platform
@ -112,6 +112,7 @@ a TOCALL number series:
APDVxx OE6PLD's SSTV with APRS status exchange
APDWxx DireWolf, WB2OSZ
APE APExxx Telemetry devices
APE2Ax VA3NNW's Email-2-APRS ap
APECAN Pecan Pico APRS Balloon Tracker
APELKx WB8ELK balloons
APERXQ Experimental tracker by PE1RXQ
@ -128,9 +129,21 @@ a TOCALL number series:
APGDTx for VK4FAST's Graphic Data Terminal
APH APHKxx for LA1BR tracker/digipeater
APHAXn SM2APRS by PY2UEP
APHBLx for DMR Gateway by Eric - KF7EEL
APHTxx HMTracker by IU0AAC
APHWxx for use in "HamWAN
API APICQx for ICQ
API API282 for ICOM IC-2820
API31 for ICOM ID-31
API410 for ICOM ID-4100
API51 for ICOM ID-51
API510 for ICOM ID-5100
API710 for ICOM IC-7100
API80 for ICOM IC-80
API880 for ICOM ID-880
API910 for ICOM IC-9100
API92 for ICOM IC-92
API970 for ICOM 9700
APICQx for ICQ
APICxx HA9MCQ's Pic IGate
APIExx W7KMV's PiAPRS system
APINxx PinPoint by AB0WV
@ -144,20 +157,26 @@ a TOCALL number series:
APK APK0xx Kenwood TH-D7's
APK003 Kenwood TH-D72
APK004 Kenwood TH-D74
APK005 Kenwood TH-D75
APK1xx Kenwood D700's
APK102 Kenwood D710
APKRAM KRAMstuff.com - Mark. G7LEU
APL APLGxx LoRa Gateway/Digipeater OE5BPA
APL APLCxx APRScube by DL3DCW
APLGxx LoRa Gateway/Digipeater OE5BPA
APLIGx LightAPRS - TA2MUN and TA9OHC
APLOxx LoRa KISS TNC/Tracker
APLQRU Charlie - QRU Server
APLMxx WA0TQG transceiver controller
APLSxx SARIMESH ( http://www.sarimesh.net )
APLTxx LoRa Tracker - OE5BPA
APM APMxxx MacAPRS,
APMGxx PiCrumbs and MiniGate - Alex, AB0TJ
APMIxx SQ3PLX http://microsat.com.pl/
APMPAD DF1JSL's WXBot clone and extension
APMQxx Ham Radio of Things WB2OSZ
APMTxx LZ1PPL for tracker
APN APNxxx Network nodes, digis, etc
APN2xx NOSaprs for JNOS 2.0 - VE4KLM
APN3xx Kantronics KPC-3 rom versions
APN9xx Kantronics KPC-9612 Roms
APNAxx WB6ZSU's APRServe
@ -234,10 +253,12 @@ a TOCALL number series:
APU3xx UIview terminal program
APUDRx NW Digital Radio's UDR (APRS/Dstar)
APV APVxxx Voice over Internet applications
APVMxx DRCC-DVM Digital Voice (Digital Radio China Club)
APVRxx for IRLP
APVLxx for I-LINK
APVExx for ECHO link
APW APWxxx WinAPRS, etc
APW9xx 9A9Y Weather Tracker
APWAxx APRSISCE Android version
APWSxx DF4IAN's WS2300 WX station
APWMxx APRSISCE KJ4ERJ
@ -249,14 +270,17 @@ a TOCALL number series:
APY01D Yaesu FT1D series
APY02D Yaesu FT2D series
APY03D Yaesu FT3D series
APY05D Yaesu FT5D series
APY100 Yaesu FTM-100D series
APY300 Yaesu FTM-300D series
APY350 Yaesu FTM-350 series
APY400 Yaesu FTM-400D series
APZ APZxxx Experimental
APZ200 old versions of JNOS
APZ247 for UPRS NR0Q
APZ0xx Xastir (old versions. See APX)
APZMAJ Martyn M1MAJ DeLorme inReach Tracker
APZMDM github/codec2_talkie - product code not registered
APZMDR for HaMDR trackers - hessu * hes.iki.fi]
APZPAD Smart Palm
APZTKP TrackPoint, Nick N0LP (Balloon tracking)(depricated)
@ -265,15 +289,11 @@ a TOCALL number series:
</tocalls>
<notes>
Authors with similar alphabetic requirements are encouraged to share
their address space with other software. Work out agreements amongst
yourselves and keep me informed.
</notes>
<altnets>
REGISTERED ALTNETS:
-------------------
REGISTERED TOCALL ALTNETS:
--------------------------
ALTNETS are uses of the AX-25 tocall to distinguish specialized
traffic that may be flowing on the APRS-IS, but that are not intended
@ -301,6 +321,6 @@ and need some special recognition. Here are some ideas:
<altnet_list>
SATERN - Salvation Army Altnet
AFMARS - Airforce Mars
AFMARS - Airforce Mars
AMARS - Army Mars
</altnet_list>

View File

@ -1,4 +1,4 @@
# Documentation for Dire Wolf #
# Documentation for Dire Wolf #
Click on the document name to view in your web browser or the link following to download the PDF file.
@ -154,6 +154,14 @@ and a couple things that can be done about it.
Here, we take a closer look at some of the frames on the TNC Test CD in hopes of gaining some insights into why some are easily decoded and others are more difficult.
There are a lot of ugly signals out there. Many can be improved by decreasing the transmit volume. Others are just plain weird and you have to wonder how they are being generated.
## Additional Documentation for Dire Wolf Software TNC #
When there was little documentation, it was all added to the source code repository [https://github.com/wb2osz/direwolf/tree/master/doc](https://github.com/wb2osz/direwolf/tree/master/doc)
The growing number of documentation files and revisions are making the source code repository very large which means long download times. Additional documentation, not tied to a specific release, is now being added to [https://github.com/wb2osz/direwolf-doc](https://github.com/wb2osz/direwolf-doc)
## Questions? Experiences to share? ##
Here are some good places to ask questions and share your experiences:

Binary file not shown.

Binary file not shown.

View File

@ -236,7 +236,7 @@ extern "C" {
* The function Convert_MGRS_To_UPS converts an MGRS coordinate string
* to UPS (hemisphere, easting, and northing) coordinates, according
* to the current ellipsoid parameters. If any errors occur, the error
* code(s) are returned by the function, otherwide UPS_NO_ERROR is returned.
* code(s) are returned by the function, otherwise UPS_NO_ERROR is returned.
*
* MGRS : MGRS coordinate string (input)
* Hemisphere : Hemisphere either 'N' or 'S' (output)

View File

@ -32,9 +32,22 @@ if(LINUX)
)
endif()
add_library(misc STATIC
${misc_SOURCES}
)
# Add_library doesn't like to get an empty source file list.
# I tried several variations on this theme to test whether the list
# was not empty and was not successful in getting it to work
# on both Alpine and RPi.
#if("${misc_SOURCES}")
# This is less elegant and less maintainable but it works.
if ((NOT HAVE_STRLCPY) OR (NOT HAVE_STRLCAT))
add_library(misc STATIC
${misc_SOURCES}
)
else()
set(MISC_LIBRARIES "" CACHE INTERNAL "")
endif()
elseif(WIN32 OR CYGWIN) # windows

View File

@ -18,7 +18,7 @@ if(WIN32 OR CYGWIN) # windows
)
set_target_properties(regex
PROPERTIES COMPILE_FLAGS "-Dbool=int -Dtrue=1 -Dfalse=0 -DUSE_REGEX_STATIC"
PROPERTIES COMPILE_FLAGS "-Dbool=int -Dtrue=1 -Dfalse=0 -DREGEX_STATIC"
)
endif()

View File

@ -35,17 +35,23 @@
#if (defined __WIN32__) || (defined _WIN32)
# ifdef BUILD_REGEX_DLL
# define REGEX_DLL_IMPEXP __DLL_EXPORT__
# define REGEX_VARIABLE_IMPEXP __DLL_EXPORT__
# elif defined(REGEX_STATIC)
# define REGEX_DLL_IMPEXP
# define REGEX_VARIABLE_IMPEXP
# elif defined (USE_REGEX_DLL)
# define REGEX_DLL_IMPEXP __DLL_IMPORT__
# define REGEX_VARIABLE_IMPEXP __DLL_IMPORT__
# elif defined (USE_REGEX_STATIC)
# define REGEX_DLL_IMPEXP
# define REGEX_VARIABLE_IMPEXP extern
# else /* assume USE_REGEX_DLL */
# define REGEX_DLL_IMPEXP __DLL_IMPORT__
# define REGEX_VARIABLE_IMPEXP __DLL_IMPORT__
# endif
#else /* __WIN32__ */
# define REGEX_DLL_IMPEXP
# define REGEX_VARIABLE_IMPEXP
#endif
/* Allow the use in C++ code. */
@ -202,7 +208,8 @@ typedef unsigned long int reg_syntax_t;
some interfaces). When a regexp is compiled, the syntax used is
stored in the pattern buffer, so changing this does not affect
already-compiled regexps. */
REGEX_DLL_IMPEXP reg_syntax_t re_syntax_options;
//REGEX_VARIABLE_IMPEXP reg_syntax_t re_syntax_options;
extern reg_syntax_t re_syntax_options;
/* Define combinations of the above bits for the standard possibilities.
(The [[[ comments delimit what gets put into the Texinfo file, so

View File

@ -37,6 +37,10 @@ Data rate in bits/sec. Standard values are 300, 1200, 2400, 4800, 9600.
4800 bps uses 8PSK based on V.27 standard.
.P
9600 bps and up uses K9NG/G3RUH standard.
.P
AIS for ship Automatic Identification System.
.P
EAS for Emergency Alert System (EAS) Specific Area Message Encoding (SAME).
.RE
.RE
.PD

View File

@ -87,7 +87,15 @@ Divide audio sample by n for first channel.
.TP
.BI "-X " "n"
1 to enable FX.25 transmit.
1 to enable FX.25 transmit. 16, 32, 64 for specific number of check bytes.
.TP
.BI "-I " "n"
Enable IL2P transmit. n=1 is recommended. 0 uses weaker FEC.
.TP
.BI "-i " "n"
Enable IL2P transmit, inverted polarity. n=1 is recommended. 0 uses weaker FEC.
.TP
.BI "-d " "x"

View File

@ -46,6 +46,8 @@ Data rate in bits/sec for first channel. Standard values are 300, 1200, 2400, 4
4800 bps uses 8PSK based on V.27 standard.
.P
9600 bps and up uses K9NG/G3RUH standard.
.P
EAS for Emergency Alert System (EAS) Specific Area Message Encoding (SAME).
.RE
.RE
.PD
@ -62,6 +64,18 @@ Force G3RUH modem regardless of data rate.
.BI "-J "
2400 bps QPSK compatible with MFJ-2400.
.TP
.BI "-X " "n"
1 to enable FX.25 transmit. 16, 32, 64 for specific number of check bytes.
.TP
.BI "-I " "n"
Enable IL2P transmit. n=1 is recommended. 0 uses weaker FEC.
.TP
.BI "-i " "n"
Enable IL2P transmit, inverted polarity. n=1 is recommended. 0 uses weaker FEC.
.TP
.BI "-m " "n"
@ -88,9 +102,13 @@ Send output to .wav file.
8 bit audio rather than 16.
.TP
.B "-2"
.BI "-2"
2 channels of audio rather than 1.
.TP
.BI "-v" "max[,incr]"
Variable speed with specified maximum error and optional increment.
.SH EXAMPLES
.P

View File

@ -45,7 +45,7 @@ Example: %H:%M:%S for current time in hours, minutes, seconds.
.TP
.BI "-f " "xmit-directory"
Files in this directory are transmited and deleted.
Files in this directory are transmitted and deleted.
Another application places a file here when it wants something to be transmitted.
.TP

View File

@ -11,7 +11,7 @@ tt2text \- Convert Touch Tone sequence to text
.SH DESCRIPTION
\fBtt2text\fR converts a Touch Tone squence to text. There are two types
\fBtt2text\fR converts a Touch Tone sequence to text. There are two types
of encoding:
.RS
.HP

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# Part of Dire Wolf APRS Telemetry Toolkit, WB2OSZ, 2015
@ -33,4 +33,4 @@ volts = adc.readADCSingleEnded(0, gain, sps) * 0.001 * (r1+r2) / r2
# (multiply by expected value, divide by uncalibrated result.)
#volts = volts * 4.98 / 4.889
print "%.3f" % (volts)
print("%.3f" % (volts))

View File

@ -8,6 +8,7 @@ include_directories(
${ALSA_INCLUDE_DIRS}
${UDEV_INCLUDE_DIRS}
${PORTAUDIO_INCLUDE_DIRS}
${SNDIO_INCLUDE_DIRS}
${CUSTOM_GEOTRANZ_DIR}
${CUSTOM_HIDAPI_DIR}
)
@ -59,6 +60,13 @@ list(APPEND direwolf_SOURCES
hdlc_rec2.c
hdlc_send.c
igate.c
il2p_codec.c
il2p_scramble.c
il2p_rec.c
il2p_payload.c
il2p_init.c
il2p_header.c
il2p_send.c
kiss_frame.c
kiss.c
kissserial.c
@ -116,7 +124,11 @@ if(LINUX)
list(REMOVE_ITEM direwolf_SOURCES
dwgpsd.c
)
else() # macOS freebsd openbsd
elseif(HAVE_SNDIO)
list(APPEND direwolf_SOURCES
audio.c
)
else() # macOS freebsd
list(APPEND direwolf_SOURCES
audio_portaudio.c
)
@ -143,6 +155,7 @@ target_link_libraries(direwolf
${ALSA_LIBRARIES}
${UDEV_LIBRARIES}
${PORTAUDIO_LIBRARIES}
${SNDIO_LIBRARIES}
${AVAHI_LIBRARIES}
)
@ -283,12 +296,20 @@ target_link_libraries(log2gpx
list(APPEND gen_packets_SOURCES
gen_packets.c
ax25_pad.c
ax25_pad2.c
fx25_encode.c
fx25_extract.c
fx25_init.c
fx25_send.c
hdlc_send.c
fcs_calc.c
gen_tone.c
il2p_codec.c
il2p_scramble.c
il2p_payload.c
il2p_init.c
il2p_header.c
il2p_send.c
morse.c
dtmf.c
textcolor.c
@ -315,14 +336,22 @@ list(APPEND atest_SOURCES
demod_9600.c
dsp.c
fx25_extract.c
fx25_encode.c
fx25_init.c
fx25_rec.c
hdlc_rec.c
hdlc_rec2.c
il2p_codec.c
il2p_scramble.c
il2p_rec.c
il2p_payload.c
il2p_init.c
il2p_header.c
multi_modem.c
rrbb.c
fcs_calc.c
ax25_pad.c
ax25_pad2.c
decode_aprs.c
dwgpsnmea.c
dwgps.c
@ -415,6 +444,29 @@ if(WIN32 OR CYGWIN)
endif()
# TNC interoperability testing for AX.25 connected mode.
# tnctest
list(APPEND tnctest_SOURCES
tnctest.c
textcolor.c
dtime_now.c
serial_port.c
)
add_executable(tnctest
${tnctest_SOURCES}
)
target_link_libraries(tnctest
${MISC_LIBRARIES}
Threads::Threads
)
if(WIN32 OR CYGWIN)
target_link_libraries(tnctest ws2_32)
endif()
# List USB audio adapters than can use GPIO for PTT.
# Originally for Linux only (using udev).
# Version 1.7 adds it for Windows. Needs hidapi library.
@ -514,6 +566,7 @@ install(TARGETS gen_packets DESTINATION ${INSTALL_BIN_DIR})
install(TARGETS atest DESTINATION ${INSTALL_BIN_DIR})
install(TARGETS ttcalc DESTINATION ${INSTALL_BIN_DIR})
install(TARGETS kissutil DESTINATION ${INSTALL_BIN_DIR})
install(TARGETS tnctest DESTINATION ${INSTALL_BIN_DIR})
install(TARGETS appserver DESTINATION ${INSTALL_BIN_DIR})
if(UDEV_FOUND OR WIN32 OR CYGWIN)
install(TARGETS cm108 DESTINATION ${INSTALL_BIN_DIR})

View File

@ -321,7 +321,7 @@ static void * tnc_listen_thread (void *arg)
s_tnc_sock = dwsock_connect (s_tnc_host, s_tnc_port, "TNC", 0, 0, tncaddr);
if (s_tnc_sock != -1) {
dw_printf ("Succesfully reattached to network TNC.\n");
dw_printf ("Successfully reattached to network TNC.\n");
// Might need to run TNC initialization again.
// For example, a server would register its callsigns.
@ -365,7 +365,7 @@ static void * tnc_listen_thread (void *arg)
}
/*
* Call to/from fields are 10 bytes but contents must not exceeed 9 characters.
* Call to/from fields are 10 bytes but contents must not exceed 9 characters.
* It's not guaranteed that unused bytes will contain 0 so we
* don't issue error message in this case.
*/
@ -600,7 +600,7 @@ int agwlib_G_ask_port_information (void)
* Returns: Number of bytes sent for success, -1 for error.
*
* Description: This only starts the sequence and does not wait.
* Success or failue will be indicated sometime later by ?
* Success or failure will be indicated sometime later by ?
*
*--------------------------------------------------------------------*/
@ -635,7 +635,7 @@ int agwlib_C_connect (int chan, char *call_from, char *call_to)
* Returns: Number of bytes sent for success, -1 for error.
*
* Description: This only starts the sequence and does not wait.
* Success or failue will be indicated sometime later by ?
* Success or failure will be indicated sometime later by ?
*
*--------------------------------------------------------------------*/
@ -722,13 +722,13 @@ int agwlib_D_send_connected_data (int chan, int pid, char *call_from, char *call
* hand we don't want to get TOO far ahead when transferring a large file.
*
* Before disconnecting from another station, it would be good to know
* that it actually recevied the last message we sent. For this reason,
* that it actually received the last message we sent. For this reason,
* I think it would be good for this to include frames that were
* transmitted but not yet acknowleged. (Even if it was transmitted once,
* transmitted but not yet acknowledged. (Even if it was transmitted once,
* it could still be transmitted again, if lost, so you could say it is
* still waiting for transmission.)
*
* See server.c for a more precise definition of exacly how this is defined.
* See server.c for a more precise definition of exactly how this is defined.
*
*--------------------------------------------------------------------*/

View File

@ -338,7 +338,7 @@ void ais_to_nmea (unsigned char *ais, int ais_len, char *nmea, int nmea_size)
*
* Name: ais_parse
*
* Purpose: Parse AIS sentence and extract interesing parts.
* Purpose: Parse AIS sentence and extract interesting parts.
*
* Inputs: sentence NMEA sentence.
*
@ -594,7 +594,7 @@ int ais_parse (char *sentence, int quiet, char *descr, int descr_size, char *mss
*
* Returns: -1 Invalid message type.
* 0 Good length.
* 1 Unexpected lenth.
* 1 Unexpected length.
*
*--------------------------------------------------------------------*/

View File

@ -320,7 +320,7 @@ static void poll_timing_test (void)
*
* data - Should look something like this for incoming:
* *** CONNECTED to Station xxx\r
* and ths for my request being accepted:
* and this for my request being accepted:
* *** CONNECTED With Station xxx\r
*
* session_id - Session id to be used in data transfer and
@ -491,15 +491,19 @@ void agw_cb_D_connected_data (int chan, char *call_from, char *call_to, int data
// who - list people currently logged in.
int n;
char greeting[80];
char greeting[128];
snprintf (greeting, sizeof(greeting), "Session Channel User Since\r");
agwlib_D_send_connected_data (chan, 0xF0, mycall, call_from, strlen(greeting), greeting);
for (n = 0; n < MAX_SESSIONS; n++) {
if (session[n].client_addr[0]) {
// I think compiler is confused. It says up to 520 characters can be written.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"
snprintf (greeting, sizeof(greeting), " %2d %d %-9s [time later]\r",
n, session[n].channel, session[n].client_addr);
#pragma GCC diagnostic pop
agwlib_D_send_connected_data (chan, 0xF0, mycall, call_from, strlen(greeting), greeting);
}
}

View File

@ -212,7 +212,7 @@ void aprs_tt_init (struct tt_config_s *p, int debug)
* The complete message is then processed.
* The touch tone decoder sends $ if no activity
* for some amount of time, perhaps 5 seconds.
* A partially accumulated messge is discarded if
* A partially accumulated message is discarded if
* there is a long gap.
*
* '.' means no activity during processing period.
@ -590,7 +590,7 @@ static int parse_fields (char *msg)
* Purpose: Expand compact form "macro" to full format then process.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should contain only digits.
*
* Returns: 0 for success or one of the TT_ERROR_... codes.
@ -705,7 +705,7 @@ static int expand_macro (char *e)
* Purpose: Extract traditional format callsign or object name from touch tone sequence.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "A" then a digit.
*
* Outputs: m_callsign
@ -888,7 +888,7 @@ static int parse_callsign (char *e)
* Purpose: Extract object name from touch tone sequence.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "AA".
*
* Outputs: m_callsign
@ -950,7 +950,7 @@ static int parse_object_name (char *e)
* Purpose: Extract symbol from touch tone sequence.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "AB".
*
* Outputs: m_symtab_or_overlay
@ -1064,7 +1064,7 @@ static int parse_symbol (char *e)
* Purpose: Extract QIKcom-2 / APRStt 3 ten digit call or five digit suffix.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "AC".
*
* Outputs: m_callsign
@ -1147,7 +1147,7 @@ static int parse_aprstt3_call (char *e)
* Purpose: Extract location from touch tone sequence.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "B".
*
* Outputs: m_latitude
@ -1283,13 +1283,26 @@ static int parse_location (char *e)
lat0 = tt_config.ttloc_ptr[ipat].grid.lat0;
lat9 = tt_config.ttloc_ptr[ipat].grid.lat9;
double yrange = lat9 - lat0;
y = atof(ystr);
m_latitude = lat0 + y * (lat9-lat0) / (pow(10., strlen(ystr)) - 1.);
double user_y_max = round(pow(10., strlen(ystr)) - 1.); // e.g. 999 for 3 digits
m_latitude = lat0 + yrange * y / user_y_max;
#if 0
dw_printf ("TTLOC_GRID LAT min=%f, max=%f, range=%f\n", lat0, lat9, yrange);
dw_printf ("TTLOC_GRID LAT user_y=%f, user_y_max=%f\n", y, user_y_max);
dw_printf ("TTLOC_GRID LAT min + yrange * user_y / user_y_range = %f\n", m_latitude);
#endif
lon0 = tt_config.ttloc_ptr[ipat].grid.lon0;
lon9 = tt_config.ttloc_ptr[ipat].grid.lon9;
double xrange = lon9 - lon0;
x = atof(xstr);
m_longitude = lon0 + x * (lon9-lon0) / (pow(10., strlen(xstr)) - 1.);
double user_x_max = round(pow(10., strlen(xstr)) - 1.);
m_longitude = lon0 + xrange * x / user_x_max;
#if 0
dw_printf ("TTLOC_GRID LON min=%f, max=%f, range=%f\n", lon0, lon9, xrange);
dw_printf ("TTLOC_GRID LON user_x=%f, user_x_max=%f\n", x, user_x_max);
dw_printf ("TTLOC_GRID LON min + xrange * user_x / user_x_range = %f\n", m_longitude);
#endif
m_dao[2] = e[0];
m_dao[3] = e[1];
@ -1494,7 +1507,7 @@ static int parse_location (char *e)
* defined in the configuration file.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "B".
*
* valstrsize - size of the outputs so we can check for buffer overflow.
@ -1645,7 +1658,7 @@ static int find_ttloc_match (char *e, char *xstr, char *ystr, char *zstr, char *
* Purpose: Extract comment / status or other special information from touch tone message.
*
* Inputs: e - An "entry" extracted from a complete
* APRStt messsage.
* APRStt message.
* In this case, it should start with "C".
*
* Outputs: m_comment
@ -1972,6 +1985,7 @@ static const struct {
/* Latitude comes out ok, 37.9137 -> 55.82 min. */
/* Longitude -81.1254 -> 8.20 min */
{ "B21234*A67979#", "679", "12", "7A", "", "", "12.3400", "56.1200", "!TB2!" },
{ "B533686*A67979#", "679", "12", "7A", "", "", "37.9222", "81.1143", "!TB5!" },
// TODO: should test other coordinate systems.

View File

@ -123,7 +123,7 @@ struct tt_config_s {
int obj_recv_chan; /* Channel to listen for tones. */
int obj_xmit_chan; /* Channel to transmit object report. */
/* -1 for none. This could happpen if we */
/* -1 for none. This could happen if we */
/* are only sending to application */
/* and/or IGate. */

View File

@ -2,7 +2,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2019 John Langner, WB2OSZ
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2019, 2021, 2022, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -23,12 +23,12 @@
*
* Name: atest.c
*
* Purpose: Test fixture for the AFSK demodulator.
* Purpose: Test fixture for the Dire Wolf demodulators.
*
* Inputs: Takes audio from a .WAV file insted of the audio device.
* Inputs: Takes audio from a .WAV file instead of the audio device.
*
* Description: This can be used to test the AFSK demodulator under
* controlled and reproducable conditions for tweaking.
* Description: This can be used to test the demodulators under
* controlled and reproducible conditions for tweaking.
*
* For example
*
@ -68,6 +68,7 @@
#include <string.h>
#include <time.h>
#include <getopt.h>
#include <ctype.h>
#define ATEST_C 1
@ -82,6 +83,7 @@
#include "ptt.h"
#include "dtime_now.h"
#include "fx25.h"
#include "il2p.h"
#include "hdlc_rec.h"
@ -106,7 +108,7 @@ struct wav_header { /* .WAV file header. */
/* 8 bit samples are unsigned bytes */
/* in range of 0 .. 255. */
/* 16 bit samples are signed short */
/* 16 bit samples are little endian signed short */
/* in range of -32768 .. +32767. */
static struct {
@ -189,6 +191,7 @@ static int h_opt = 0; // Hexadecimal display of received packet.
static char P_opt[16] = ""; // Demodulator profiles.
static int d_x_opt = 1; // FX.25 debug.
static int d_o_opt = 0; // "-d o" option for DCD output control. */
static int d_2_opt = 0; // "-d 2" option for IL2P details. */
static int dcd_count = 0;
static int dcd_missing_errors = 0;
@ -273,12 +276,12 @@ int main (int argc, char *argv[])
case 'B': /* -B for data Bit rate */
/* Also implies modem type based on speed. */
/* Special case "AIS" rather than number. */
/* Special cases AIS, EAS rather than number. */
if (strcasecmp(optarg, "AIS") == 0) {
B_opt = 12345; // See special case below.
B_opt = 0xA15A15; // See special case below.
}
else if (strcasecmp(optarg, "EAS") == 0) {
B_opt = 23456; // See special case below.
B_opt = 0xEA5EA5; // See special case below.
}
else {
B_opt = atoi(optarg);
@ -389,6 +392,7 @@ int main (int argc, char *argv[])
switch (*p) {
case 'x': d_x_opt++; break; // FX.25
case 'o': d_o_opt++; break; // DCD output control
case '2': d_2_opt++; break; // IL2P debug out
default: break;
}
}
@ -421,11 +425,6 @@ int main (int argc, char *argv[])
my_audio_config.achan[0].baud = B_opt;
if (my_audio_config.achan[0].baud < MIN_BAUD || my_audio_config.achan[0].baud > MAX_BAUD) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
exit (EXIT_FAILURE);
}
/* We have similar logic in direwolf.c, config.c, gen_packets.c, and atest.c, */
/* that need to be kept in sync. Maybe it could be a common function someday. */
@ -434,7 +433,6 @@ int main (int argc, char *argv[])
my_audio_config.achan[0].modem_type = MODEM_AFSK;
my_audio_config.achan[0].mark_freq = 1615;
my_audio_config.achan[0].space_freq = 1785;
//strlcpy (my_audio_config.achan[0].profiles, "A", sizeof(my_audio_config.achan[0].profiles));
}
else if (my_audio_config.achan[0].baud < 600) { // e.g. HF SSB packet
my_audio_config.achan[0].modem_type = MODEM_AFSK;
@ -442,13 +440,11 @@ int main (int argc, char *argv[])
my_audio_config.achan[0].space_freq = 1800;
// Previously we had a "D" which was fine tuned for 300 bps.
// In v1.7, it's not clear if we should use "B" or just stick with "A".
//strlcpy (my_audio_config.achan[0].profiles, "B", sizeof(my_audio_config.achan[0].profiles));
}
else if (my_audio_config.achan[0].baud < 1800) { // common 1200
my_audio_config.achan[0].modem_type = MODEM_AFSK;
my_audio_config.achan[0].mark_freq = DEFAULT_MARK_FREQ;
my_audio_config.achan[0].space_freq = DEFAULT_SPACE_FREQ;
// Should default to E+ or something similar later.
}
else if (my_audio_config.achan[0].baud < 3600) {
my_audio_config.achan[0].modem_type = MODEM_QPSK;
@ -462,14 +458,14 @@ int main (int argc, char *argv[])
my_audio_config.achan[0].space_freq = 0;
strlcpy (my_audio_config.achan[0].profiles, "", sizeof(my_audio_config.achan[0].profiles));
}
else if (my_audio_config.achan[0].baud == 12345) { // Hack for different use of 9600
else if (my_audio_config.achan[0].baud == 0xA15A15) { // Hack for different use of 9600
my_audio_config.achan[0].modem_type = MODEM_AIS;
my_audio_config.achan[0].baud = 9600;
my_audio_config.achan[0].mark_freq = 0;
my_audio_config.achan[0].space_freq = 0;
strlcpy (my_audio_config.achan[0].profiles, " ", sizeof(my_audio_config.achan[0].profiles)); // avoid getting default later.
}
else if (my_audio_config.achan[0].baud == 23456) {
else if (my_audio_config.achan[0].baud == 0xEA5EA5) {
my_audio_config.achan[0].modem_type = MODEM_EAS;
my_audio_config.achan[0].baud = 521; // Actually 520.83 but we have an integer field here.
// Will make more precise in afsk demod init.
@ -484,6 +480,12 @@ int main (int argc, char *argv[])
strlcpy (my_audio_config.achan[0].profiles, " ", sizeof(my_audio_config.achan[0].profiles)); // avoid getting default later.
}
if (my_audio_config.achan[0].baud < MIN_BAUD || my_audio_config.achan[0].baud > MAX_BAUD) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
exit (EXIT_FAILURE);
}
/*
* -g option means force g3RUH regardless of speed.
*/
@ -539,6 +541,7 @@ int main (int argc, char *argv[])
}
fx25_init (d_x_opt);
il2p_init (d_2_opt);
start_time = dtime_now();
@ -616,9 +619,9 @@ int main (int argc, char *argv[])
my_audio_config.adev[0].bits_per_sample = format.wbitspersample;
my_audio_config.adev[0].num_channels = format.nchannels;
my_audio_config.achan[0].medium = MEDIUM_RADIO;
my_audio_config.chan_medium[0] = MEDIUM_RADIO;
if (format.nchannels == 2) {
my_audio_config.achan[1].medium = MEDIUM_RADIO;
my_audio_config.chan_medium[1] = MEDIUM_RADIO;
}
text_color_set(DW_COLOR_INFO);
@ -705,7 +708,7 @@ int main (int argc, char *argv[])
dw_printf ("%d packets decoded in %.3f seconds. %.1f x realtime\n", packets_decoded_total, elapsed, total_filetime/elapsed);
if (d_o_opt) {
dw_printf ("DCD count = %d\n", dcd_count);
dw_printf ("DCD missing erors = %d\n", dcd_missing_errors);
dw_printf ("DCD missing errors = %d\n", dcd_missing_errors);
}
if (error_if_less_than != -1 && packets_decoded_total < error_if_less_than) {
@ -754,14 +757,14 @@ int audio_get (int a)
* This is called when we have a good frame.
*/
void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, int is_fx25, retry_t retries, char *spectrum)
void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, fec_type_t fec_type, retry_t retries, char *spectrum)
{
char stemp[500];
unsigned char *pinfo;
int info_len;
int h;
char heard[AX25_MAX_ADDR_LEN];
char heard[2 * AX25_MAX_ADDR_LEN + 20];
char alevel_text[AX25_ALEVEL_TO_TEXT_SIZE];
packets_decoded_one++;
@ -806,29 +809,48 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
}
ax25_alevel_to_text (alevel, alevel_text);
if (my_audio_config.achan[chan].fix_bits == RETRY_NONE && my_audio_config.achan[chan].passall == 0) {
dw_printf ("%s audio level = %s %s\n", heard, alevel_text, spectrum);
/* As suggested by KJ4ERJ, if we are receiving from */
/* WIDEn-0, it is quite likely (but not guaranteed), that */
/* we are actually hearing the preceding station in the path. */
if (h >= AX25_REPEATER_2 &&
strncmp(heard, "WIDE", 4) == 0 &&
isdigit(heard[4]) &&
heard[5] == '\0') {
char probably_really[AX25_MAX_ADDR_LEN];
ax25_get_addr_with_ssid(pp, h-1, probably_really);
strlcat (heard, " (probably ", sizeof(heard));
strlcat (heard, probably_really, sizeof(heard));
strlcat (heard, ")", sizeof(heard));
}
else if (is_fx25) {
dw_printf ("%s audio level = %s %s\n", heard, alevel_text, spectrum);
}
else {
assert (retries >= RETRY_NONE && retries <= RETRY_MAX);
dw_printf ("%s audio level = %s [%s] %s\n", heard, alevel_text, retry_text[(int)retries], spectrum);
switch (fec_type) {
case fec_type_fx25:
dw_printf ("%s audio level = %s FX.25 %s\n", heard, alevel_text, spectrum);
break;
case fec_type_il2p:
dw_printf ("%s audio level = %s IL2P %s\n", heard, alevel_text, spectrum);
break;
case fec_type_none:
default:
if (my_audio_config.achan[chan].fix_bits == RETRY_NONE && my_audio_config.achan[chan].passall == 0) {
// No fix_bits or passall specified.
dw_printf ("%s audio level = %s %s\n", heard, alevel_text, spectrum);
}
else {
assert (retries >= RETRY_NONE && retries <= RETRY_MAX); // validate array index.
dw_printf ("%s audio level = %s [%s] %s\n", heard, alevel_text, retry_text[(int)retries], spectrum);
}
break;
}
#endif
//#if defined(EXPERIMENT_G) || defined(EXPERIMENT_H)
// int j;
//
// for (j=0; j<MAX_SUBCHANS; j++) {
// if (spectrum[j] == '|') {
// count[j]++;
// }
// }
//#endif
// Display non-APRS packets in a different color.
@ -873,7 +895,7 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
#if 1 // temp experiment TODO: remove this.
#if 0 // temp experiment
#include "decode_aprs.h"
#include "log.h"
@ -882,7 +904,7 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
decode_aprs_t A;
decode_aprs (&A, pp, 0);
decode_aprs (&A, pp, 0, NULL);
// Temp experiment to see how different systems set the RR bits in the source and destination.
// log_rr_bits (&A, pp);

View File

@ -75,18 +75,17 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#if USE_ALSA
#include <alsa/asoundlib.h>
#else
#include <errno.h>
#ifdef __OpenBSD__
#include <soundcard.h>
#elif USE_SNDIO
#include <sndio.h>
#include <poll.h>
#else
#include <sys/soundcard.h>
#endif
#endif
#include "audio.h"
@ -111,6 +110,9 @@ static struct adev_s {
int bytes_per_frame; /* number of bytes for a sample from all channels. */
/* e.g. 4 for stereo 16 bit. */
#elif USE_SNDIO
struct sio_hdl *sndio_in_handle;
struct sio_hdl *sndio_out_handle;
#else
int oss_audio_device_fd; /* Single device, both directions. */
@ -141,6 +143,9 @@ static struct adev_s {
#if USE_ALSA
static int set_alsa_params (int a, snd_pcm_t *handle, struct audio_s *pa, char *name, char *dir);
//static void alsa_select_device (char *pick_dev, int direction, char *result);
#elif USE_SNDIO
static int set_sndio_params (int a, struct sio_hdl *handle, struct audio_s *pa, char *devname, char *inout);
static int poll_sndio (struct sio_hdl *hdl, int events);
#else
static int set_oss_params (int a, int fd, struct audio_s *pa);
#endif
@ -201,7 +206,7 @@ static int calcbufsize(int rate, int chans, int bits)
* more restrictive in its capabilities.
* It might say, the best I can do is mono, 8 bit, 8000/sec.
*
* The sofware modem must use this ACTUAL information
* The software modem must use this ACTUAL information
* that the device is supplying, that could be different
* than what the user specified.
*
@ -212,7 +217,9 @@ static int calcbufsize(int rate, int chans, int bits)
int audio_open (struct audio_s *pa)
{
#if !USE_SNDIO
int err;
#endif
int chan;
int a;
char audio_in_name[30];
@ -224,7 +231,11 @@ int audio_open (struct audio_s *pa)
memset (adev, 0, sizeof(adev));
for (a=0; a<MAX_ADEVS; a++) {
#ifndef USE_ALSA
#if USE_ALSA
adev[a].audio_in_handle = adev[a].audio_out_handle = NULL;
#elif USE_SNDIO
adev[a].sndio_in_handle = adev[a].sndio_out_handle = NULL;
#else
adev[a].oss_audio_device_fd = -1;
#endif
adev[a].udp_sock = -1;
@ -343,11 +354,33 @@ int audio_open (struct audio_s *pa)
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not open audio device %s for input\n%s\n",
audio_in_name, snd_strerror(err));
if (err == -EBUSY) {
dw_printf ("This means that some other application is using that device.\n");
dw_printf ("The solution is to identify that other application and stop it.\n");
}
return (-1);
}
adev[a].inbuf_size_in_bytes = set_alsa_params (a, adev[a].audio_in_handle, pa, audio_in_name, "input");
#elif USE_SNDIO
adev[a].sndio_in_handle = sio_open (audio_in_name, SIO_REC, 0);
if (adev[a].sndio_in_handle == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not open audio device %s for input\n",
audio_in_name);
return (-1);
}
adev[a].inbuf_size_in_bytes = set_sndio_params (a, adev[a].sndio_in_handle, pa, audio_in_name, "input");
if (!sio_start (adev[a].sndio_in_handle)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not start audio device %s for input\n",
audio_in_name);
return (-1);
}
#else // OSS
adev[a].oss_audio_device_fd = open (pa->adev[a].adevice_in, O_RDWR);
@ -430,6 +463,10 @@ int audio_open (struct audio_s *pa)
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not open audio device %s for output\n%s\n",
audio_out_name, snd_strerror(err));
if (err == -EBUSY) {
dw_printf ("This means that some other application is using that device.\n");
dw_printf ("The solution is to identify that other application and stop it.\n");
}
return (-1);
}
@ -439,6 +476,27 @@ int audio_open (struct audio_s *pa)
return (-1);
}
#elif USE_SNDIO
adev[a].sndio_out_handle = sio_open (audio_out_name, SIO_PLAY, 0);
if (adev[a].sndio_out_handle == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not open audio device %s for output\n",
audio_out_name);
return (-1);
}
adev[a].outbuf_size_in_bytes = set_sndio_params (a, adev[a].sndio_out_handle, pa, audio_out_name, "output");
if (adev[a].inbuf_size_in_bytes <= 0 || adev[a].outbuf_size_in_bytes <= 0) {
return (-1);
}
if (!sio_start (adev[a].sndio_out_handle)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not start audio device %s for output\n",
audio_out_name);
return (-1);
}
#endif
/*
@ -675,6 +733,112 @@ static int set_alsa_params (int a, snd_pcm_t *handle, struct audio_s *pa, char *
} /* end alsa_set_params */
#elif USE_SNDIO
/*
* Set parameters for sound card. (sndio)
*
* See /usr/include/sndio.h for details.
*/
static int set_sndio_params (int a, struct sio_hdl *handle, struct audio_s *pa, char *devname, char *inout)
{
struct sio_par q, r;
/* Signed 16 bit little endian or unsigned 8 bit. */
sio_initpar (&q);
q.bits = pa->adev[a].bits_per_sample;
q.bps = (q.bits + 7) / 8;
q.sig = (q.bits == 8) ? 0 : 1;
q.le = 1; /* always little endian */
q.msb = 0; /* LSB aligned */
q.rchan = q.pchan = pa->adev[a].num_channels;
q.rate = pa->adev[a].samples_per_sec;
q.xrun = SIO_IGNORE;
q.appbufsz = calcbufsize(pa->adev[a].samples_per_sec, pa->adev[a].num_channels, pa->adev[a].bits_per_sample);
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("suggest buffer size %d bytes for %s %s.\n",
q.appbufsz, devname, inout);
#endif
/* challenge new setting */
if (!sio_setpar (handle, &q)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not set hardware parameter for %s %s.\n",
devname, inout);
return (-1);
}
/* get response */
if (!sio_getpar (handle, &r)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Could not obtain current hardware setting for %s %s.\n",
devname, inout);
return (-1);
}
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("audio buffer size %d bytes for %s %s.\n",
r.appbufsz, devname, inout);
#endif
if (q.rate != r.rate) {
text_color_set(DW_COLOR_INFO);
dw_printf ("Asked for %d samples/sec but got %d for %s %s.",
pa->adev[a].samples_per_sec, r.rate, devname, inout);
pa->adev[a].samples_per_sec = r.rate;
}
/* not supported */
if (q.bits != r.bits || q.bps != r.bps || q.sig != r.sig ||
(q.bits > 8 && q.le != r.le) ||
(*inout == 'o' && q.pchan != r.pchan) ||
(*inout == 'i' && q.rchan != r.rchan)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Unsupported format for %s %s.\n", devname, inout);
return (-1);
}
return r.appbufsz;
} /* end set_sndio_params */
static int poll_sndio (struct sio_hdl *hdl, int events)
{
struct pollfd *pfds;
int nfds, revents;
nfds = sio_nfds (hdl);
pfds = alloca (nfds * sizeof(struct pollfd));
do {
nfds = sio_pollfd (hdl, pfds, events);
if (nfds < 1) {
/* no need to wait */
return (0);
}
if (poll (pfds, nfds, -1) < 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("poll %d\n", errno);
return (-1);
}
revents = sio_revents (hdl, pfds);
} while (!(revents & (events | POLLHUP)));
/* unrecoverable error occurred */
if (revents & POLLHUP) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("waited for %s, POLLHUP received\n", (events & POLLIN) ? "POLLIN" : "POLLOUT");
return (-1);
}
return (0);
}
#else
@ -769,7 +933,7 @@ static int set_oss_params (int a, int fd, struct audio_s *pa)
* This was long ago under different conditions.
* Should study this again some day.
*
* Your milage may vary.
* Your mileage may vary.
*/
err = ioctl (fd, SNDCTL_DSP_GETBLKSIZE, &ossbuf_size_in_bytes);
if (err == -1) {
@ -842,7 +1006,9 @@ __attribute__((hot))
int audio_get (int a)
{
int n;
#if USE_ALSA
int retries = 0;
#endif
#if STATISTICS
/* Gather numbers for read from audio device. */
@ -936,6 +1102,8 @@ int audio_get (int a)
dw_printf ("This is most likely caused by the CPU being too slow to keep up with the audio stream.\n");
dw_printf ("Use the \"top\" command, in another command window, to look at CPU usage.\n");
dw_printf ("This might be a temporary condition so we will attempt to recover a few times before giving up.\n");
dw_printf ("If using a very slow CPU, try reducing the CPU load by using -P- command\n");
dw_printf ("line option for 9600 bps or -D3 for slower AFSK .\n");
}
audio_stats (a,
@ -970,7 +1138,28 @@ int audio_get (int a)
}
#else /* end ALSA, begin OSS */
#elif USE_SNDIO
while (adev[a].inbuf_next >= adev[a].inbuf_len) {
assert (adev[a].sndio_in_handle != NULL);
if (poll_sndio (adev[a].sndio_in_handle, POLLIN) < 0) {
adev[a].inbuf_len = 0;
adev[a].inbuf_next = 0;
return (-1);
}
n = sio_read (adev[a].sndio_in_handle, adev[a].inbuf_ptr, adev[a].inbuf_size_in_bytes);
adev[a].inbuf_len = n;
adev[a].inbuf_next = 0;
audio_stats (a,
save_audio_config_p->adev[a].num_channels,
n / (save_audio_config_p->adev[a].num_channels * save_audio_config_p->adev[a].bits_per_sample / 8),
save_audio_config_p->statistics_interval);
}
#else /* begin OSS */
/* Fixed in 1.2. This was formerly outside of the switch */
/* so the OSS version did not process stdin or UDP. */
@ -1250,6 +1439,37 @@ int audio_flush (int a)
adev[a].outbuf_len = 0;
return (-1);
#elif USE_SNDIO
int k;
unsigned char *ptr;
int len;
ptr = adev[a].outbuf_ptr;
len = adev[a].outbuf_len;
while (len > 0) {
assert (adev[a].sndio_out_handle != NULL);
if (poll_sndio (adev[a].sndio_out_handle, POLLOUT) < 0) {
text_color_set(DW_COLOR_ERROR);
perror("Can't write to audio device");
adev[a].outbuf_len = 0;
return (-1);
}
k = sio_write (adev[a].sndio_out_handle, ptr, len);
#if DEBUGx
text_color_set(DW_COLOR_DEBUG);
dw_printf ("audio_flush(): write %d returns %d\n", len, k);
fflush (stdout);
#endif
ptr += k;
len -= k;
}
adev[a].outbuf_len = 0;
return (0);
#else /* OSS */
int k;
@ -1320,7 +1540,7 @@ int audio_flush (int a)
* (3) Call this function, which might or might not wait long enough.
* (4) Add (1) and (2) resulting in when PTT should be turned off.
* (5) Take difference between current time and desired PPT off time
* and wait for additoinal time if required.
* and wait for additional time if required.
*
*----------------------------------------------------------------*/
@ -1351,6 +1571,10 @@ void audio_wait (int a)
* Either way, the caller will now compensate for it.
*/
#elif USE_SNDIO
poll_sndio (adev[a].sndio_out_handle, POLLOUT);
#else
assert (adev[a].oss_audio_device_fd > 0);
@ -1396,7 +1620,22 @@ int audio_close (void)
snd_pcm_close (adev[a].audio_in_handle);
snd_pcm_close (adev[a].audio_out_handle);
adev[a].audio_in_handle = adev[a].audio_out_handle = NULL;
#elif USE_SNDIO
if (adev[a].sndio_in_handle != NULL && adev[a].sndio_out_handle != NULL) {
audio_wait (a);
sio_stop (adev[a].sndio_in_handle);
sio_stop (adev[a].sndio_out_handle);
sio_close (adev[a].sndio_in_handle);
sio_close (adev[a].sndio_out_handle);
adev[a].sndio_in_handle = adev[a].sndio_out_handle = NULL;
#else
if (adev[a].oss_audio_device_fd > 0) {

View File

@ -72,7 +72,7 @@ struct audio_s {
struct adev_param_s {
/* Properites of the sound device. */
/* Properties of the sound device. */
int defined; /* Was device defined? */
/* First one defaults to yes. */
@ -102,15 +102,16 @@ struct audio_s {
/* This is the probability, in per cent, of randomly corrupting it. */
/* Normally this is 0. 25 would mean corrupt it 25% of the time. */
int recv_error_rate; /* Similar but the % probablity of dropping a received frame. */
int recv_error_rate; /* Similar but the % probability of dropping a received frame. */
float recv_ber; /* Receive Bit Error Rate (BER). */
/* Probability of inverting a bit coming out of the modem. */
int fx25_xmit_enable; /* Enable transmission of FX.25. */
//int fx25_xmit_enable; /* Enable transmission of FX.25. */
/* See fx25_init.c for explanation of values. */
/* Initially this applies to all channels. */
/* This should probably be per channel. One step at a time. */
/* v1.7 - replaced by layer2_xmit==LAYER2_FX25 */
int fx25_auto_enable; /* Turn on FX.25 for current connected mode session */
/* under poor conditions. */
@ -118,32 +119,50 @@ struct audio_s {
/* I put it here, rather than with the rest of the link layer */
/* parameters because it is really a part of the HDLC layer */
/* and is part of the KISS TNC functionality rather than our data link layer. */
/* Future: not used yet. */
char timestamp_format[40]; /* -T option */
/* Precede received & transmitted frames with timestamp. */
/* Command line option uses "strftime" format string. */
/* Properties for each channel, common to receive and transmit. */
/* Can be different for each radio channel. */
/* originally a "channel" was always connected to an internal modem. */
/* In version 1.6, this is generalized so that a channel (as seen by client application) */
/* can be connected to something else. Initially, this will allow application */
/* access to the IGate. Later we might have network TNCs or other internal functions. */
// Properties for all channels.
enum medium_e chan_medium[MAX_TOTAL_CHANS];
// MEDIUM_NONE for invalid.
// MEDIUM_RADIO for internal modem. (only possibility earlier)
// MEDIUM_IGATE allows application access to IGate.
// MEDIUM_NETTNC for external TNC via TCP.
int igate_vchannel; /* Virtual channel mapped to APRS-IS. */
/* -1 for none. */
/* Redundant but it makes things quicker and simpler */
/* than always searching thru above. */
/* Properties for each radio channel, common to receive and transmit. */
/* Can be different for each radio channel. */
struct achan_param_s {
// Originally there was a boolean, called "valid", to indicate that the
// channel is valid. This has been replaced with the new "medium" which
// will allow channels to correspond to things other than internal modems.
enum medium_e medium; // MEDIUM_NONE for invalid.
// MEDIUM_RADIO for internal modem. (only possibility earlier)
// MEDIUM_IGATE allows application access to IGate.
// Currently, we have a fixed mapping from audio sources to channel.
//
// ADEVICE CHANNEL (mono) (stereo)
// 0 0 0, 1
// 1 2 2, 3
// 2 4 4, 5
//
// A future feauture might allow the user to specify a different audio source.
// This would allow multiple modems (with associated channel) to share an audio source.
// int audio_source; // Default would be [0,1,2,3,4,5]
// What else should be moved out of structure and enlarged when NETTNC is implemented. ???
char mycall[AX25_MAX_ADDR_LEN]; /* Call associated with this radio channel. */
/* Could all be the same or different. */
@ -156,9 +175,26 @@ struct audio_s {
/* Might try MFJ-2400 / CCITT v.26 / Bell 201 someday. */
/* No modem. Might want this for DTMF only channel. */
enum layer2_t { LAYER2_AX25 = 0, LAYER2_FX25, LAYER2_IL2P } layer2_xmit;
// IL2P - New for version 1.7.
// New layer 2 with FEC. Much less overhead than FX.25 but no longer backward compatible.
// Only applies to transmit.
// Listening for FEC sync word should add negligible overhead so
// we leave reception enabled all the time as we do with FX.25.
// TODO: FX.25 should probably be put here rather than global for all channels.
int fx25_strength; // Strength of FX.25 FEC.
// 16, 23, 64 for specific number of parity symbols.
// 1 for automatic selection based on frame size.
int il2p_max_fec; // 1 for max FEC length, 0 for automatic based on size.
int il2p_invert_polarity; // 1 means invert on transmit. Receive handles either automatically.
enum v26_e { V26_UNSPECIFIED=0, V26_A, V26_B } v26_alternative;
// Original implementaion used alternative A for 2400 bbps PSK.
// Original implementation used alternative A for 2400 bbps PSK.
// Years later, we discover that MFJ-2400 used alternative B.
// It's likely the others did too. it also works a little better.
// Default to MFJ compatible and print warning if user did not
@ -263,7 +299,7 @@ struct audio_s {
#define MAX_GPIO_NAME_LEN 20 // 12 would cover any case I've seen so this should be safe
char out_gpio_name[MAX_GPIO_NAME_LEN];
/* orginally, gpio number NN was assumed to simply */
/* originally, gpio number NN was assumed to simply */
/* have the name gpioNN but this turned out not to be */
/* the case for CubieBoard where it was longer. */
/* This is filled in by ptt_init so we don't have to */
@ -300,7 +336,7 @@ struct audio_s {
int in_gpio_num; /* GPIO number */
char in_gpio_name[MAX_GPIO_NAME_LEN];
/* orginally, gpio number NN was assumed to simply */
/* originally, gpio number NN was assumed to simply */
/* have the name gpioNN but this turned out not to be */
/* the case for CubieBoard where it was longer. */
/* This is filled in by ptt_init so we don't have to */
@ -314,7 +350,7 @@ struct audio_s {
int dwait; /* First wait extra time for receiver squelch. */
/* Default 0 units of 10 mS each . */
int slottime; /* Slot time in 10 mS units for persistance algorithm. */
int slottime; /* Slot time in 10 mS units for persistence algorithm. */
/* Typical value is 10 meaning 100 milliseconds. */
int persist; /* Sets probability for transmitting after each */
@ -352,8 +388,8 @@ struct audio_s {
#define DEFAULT_ADEVICE "" /* Mac OSX: Empty string = default audio device. */
#elif USE_ALSA
#define DEFAULT_ADEVICE "default" /* Use default device for ALSA. */
#elif __OpenBSD__
#define DEFAULT_ADEVICE "default" /* Use default device for OpenBSD-portaudio. */
#elif USE_SNDIO
#define DEFAULT_ADEVICE "default" /* Use default device for sndio. */
#else
#define DEFAULT_ADEVICE "/dev/dsp" /* First audio device for OSS. (FreeBSD) */
#endif
@ -390,7 +426,8 @@ struct audio_s {
#define DEFAULT_BITS_PER_SAMPLE 16
#define DEFAULT_FIX_BITS RETRY_INVERT_SINGLE
#define DEFAULT_FIX_BITS RETRY_NONE // Interesting research project but even a single bit fix up
// will occasionally let corrupted packets through.
/*
* Standard for AFSK on VHF FM.
@ -420,11 +457,11 @@ struct audio_s {
*/
#define DEFAULT_DWAIT 0
#define DEFAULT_SLOTTIME 10
#define DEFAULT_SLOTTIME 10 // *10mS = 100mS
#define DEFAULT_PERSIST 63
#define DEFAULT_TXDELAY 30
#define DEFAULT_TXTAIL 10
#define DEFAULT_FULLDUP 0
#define DEFAULT_TXDELAY 30 // *10mS = 300mS
#define DEFAULT_TXTAIL 10 // *10mS = 100mS
#define DEFAULT_FULLDUP 0 // false = half duplex
/*
* Note that we have two versions of these in audio.c and audio_win.c.

View File

@ -156,7 +156,7 @@ static int calcbufsize(int rate, int chans, int bits)
* the same device name for more then one connected device
* (ie two SignaLinks). Appending a Portaudio device index to the
* the device name ensure we can find the correct one. And if it's not
* available return the first occurence that matches the device name.
* available return the first occurrence that matches the device name.
*----------------------------------------------------------------*/
static int searchPADevice(struct adev_s *dev, char *_devName, int reqDeviceNo, int io_flag)
{
@ -213,7 +213,21 @@ static int pa_devNN(char *deviceStr, char *_devName, size_t length, int *_devNo)
while(*cPtr) {
cVal = *cPtr++;
if(cVal == ':') break;
if(((cVal >= ' ') && (cVal <= '~')) && (count < length)) {
// See Issue 417.
// Originally this copied only printable ASCII characters (space thru ~).
// That is a problem for some locales that use UTF-8 characters in the device name.
// original: if(((cVal >= ' ') && (cVal <= '~')) && (count < length)) {
// At first I was thinking we should keep the test for < ' ' but then I
// remembered that char type can be signed or unsigned depending on implementation.
// If characters are signed then a value above 0x7f would be considered negative.
// It seems to me that the test for buffer full is off by one.
// count could reach length, leaving no room for a nul terminator.
// Compare has been changed so count is limited to length minus 1.
if(count < length - 1) {
_devName[count++] = cVal;
}
@ -513,7 +527,7 @@ static int paOutput16CB( const void *inputBuffer, void *outputBuffer,
* more restrictive in its capabilities.
* It might say, the best I can do is mono, 8 bit, 8000/sec.
*
* The sofware modem must use this ACTUAL information
* The software modem must use this ACTUAL information
* that the device is supplying, that could be different
* than what the user specified.
*
@ -1149,7 +1163,7 @@ int audio_put (int a, int c)
static double start = 0, end = 0, diff = 0;
if(adev[a].outbuf_len == 0)
start = dtime_now();
start = dtime_monotonic();
#endif
if(c >= 0) {
@ -1178,7 +1192,7 @@ int audio_put (int a, int c)
#ifdef __TIMED__
count += frames;
if(c < 0) { // When the Ax25 frames are flushed.
end = dtime_now();
end = dtime_monotonic();
diff = end - start;
if(count)
dw_printf ("Transfer Time:%3.9f No of Frames:%d Per frame:%3.9f speed:%f\n",
@ -1246,7 +1260,7 @@ int audio_flush (int a)
* (3) Call this function, which might or might not wait long enough.
* (4) Add (1) and (2) resulting in when PTT should be turned off.
* (5) Take difference between current time and desired PPT off time
* and wait for additoinal time if required.
* and wait for additional time if required.
*
*----------------------------------------------------------------*/

View File

@ -65,7 +65,6 @@
#include "audio_stats.h"
#include "textcolor.h"
#include "dtime_now.h"
#include "demod.h" /* for alevel_t & demod_get_audio_level() */

View File

@ -84,7 +84,7 @@ static struct audio_s *save_audio_config_p;
*/
/*
* Originally, we had an abitrary buf time of 40 mS.
* Originally, we had an arbitrary buf time of 40 mS.
*
* For mono, the buffer size was rounded up from 3528 to 4k so
* it was really about 50 mS per buffer or about 20 per second.
@ -209,7 +209,7 @@ static struct adev_s {
* more restrictive in its capabilities.
* It might say, the best I can do is mono, 8 bit, 8000/sec.
*
* The sofware modem must use this ACTUAL information
* The software modem must use this ACTUAL information
* that the device is supplying, that could be different
* than what the user specified.
*
@ -561,6 +561,8 @@ int audio_open (struct audio_s *pa)
*/
case AUDIO_IN_TYPE_SOUNDCARD:
// Use InitializeCriticalSectionAndSpinCount to avoid exceptions in low memory situations?
InitializeCriticalSection (&(A->in_cs));
err = waveInOpen (&(A->audio_in_handle), in_dev_no[a], &wf, (DWORD_PTR)in_callback, a, CALLBACK_FUNCTION);
@ -921,7 +923,7 @@ int audio_get (int a)
* c - One byte in range of 0 - 255.
*
*
* Global In: out_current - index of output buffer currenly being filled.
* Global In: out_current - index of output buffer currently being filled.
*
* Returns: Normally non-negative.
* -1 for any type of error.
@ -1072,7 +1074,7 @@ int audio_flush (int a)
* (3) Call this function, which might or might not wait long enough.
* (4) Add (1) and (2) resulting in when PTT should be turned off.
* (5) Take difference between current time and desired PPT off time
* and wait for additoinal time if required.
* and wait for additional time if required.
*
*----------------------------------------------------------------*/

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2016, 2017, 2018 John Langner, WB2OSZ
// Copyright (C) 2016, 2017, 2018, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -26,6 +26,10 @@
* Establish connections and transfer data in the proper
* order with retries.
*
* Using the term "data link" is rather unfortunate because it causes
* confusion to someone familiar with the OSI networking model.
* This corresponds to the layer 4 transport, not layer 2 data link.
*
* Description:
*
* Typical sequence for establishing a connection
@ -190,14 +194,16 @@
// Debug switches for different types of information.
// Should have command line options instead of changing source and recompiling.
static int s_debug_protocol_errors = 1; // Less serious Protocol errors.
static int s_debug_protocol_errors = 0; // Less serious Protocol errors.
// Useful for debugging but unnecessarily alarming other times.
// Was it intentially left on for release 1.6?
static int s_debug_client_app = 0; // Interaction with client application.
// dl_connect_request, dl_data_request, dl_data_indication, etc.
static int s_debug_radio = 0; // Received frames and channel busy status.
// lm_data_indication, lm_channel_busy
static int s_debug_variables = 0; // Variables, state changes.
static int s_debug_retry = 0; // Related to lost I frames, REJ, SREJ, timeout, resending.
@ -246,7 +252,7 @@ typedef struct ax25_dlsm_s {
// notifications about state changes.
char addrs[AX25_MAX_REPEATERS][AX25_MAX_ADDR_LEN];
char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN];
// Up to 10 addresses, same order as in frame.
int num_addr; // Number of addresses. Should be in range 2 .. 10.
@ -255,7 +261,7 @@ typedef struct ax25_dlsm_s {
// addrs[OWNCALL] is owncall for this end of link.
// Note that we are acting on behalf of
// a client application so the APRS mycall
// might not be relevent.
// might not be relevant.
#define PEERCALL AX25_DESTINATION
// addrs[PEERCALL] is call for other end.
@ -319,8 +325,8 @@ typedef struct ax25_dlsm_s {
int reject_exception; // A REJ frame has been sent to the remote station. (boolean)
// This is used only when receving an I frame, in states 3 & 4, SREJ not enabled.
// When an I frame has an unepected N(S),
// This is used only when receiving an I frame, in states 3 & 4, SREJ not enabled.
// When an I frame has an unexpected N(S),
// - if not already set, set it and send REJ.
// When an I frame with expected N(S) is received, clear it.
// This would prevent us from sending additional REJ while
@ -343,7 +349,7 @@ typedef struct ax25_dlsm_s {
// Sometimes the flow chart has SAT instead of SRT.
// I think that is a typographical error.
float t1v; // How long to wait for an acknowlegement before resending.
float t1v; // How long to wait for an acknowledgement before resending.
// Value used when starting timer T1, in seconds.
// "FRACK" parameter in some implementations.
// Typically it might be 3 seconds after frame has been
@ -590,6 +596,8 @@ static int AX25MODULO(int n, int m, const char *file, const char *func, int line
#define PAUSE_TM201 pause_tm201(S, __func__, __LINE__)
#define RESUME_TM201 resume_tm201(S, __func__, __LINE__)
// TODO: add SELECT_T1_VALUE for debugging.
static void dl_data_indication (ax25_dlsm_t *S, int pid, char *data, int len);
@ -824,6 +832,11 @@ static ax25_dlsm_t *get_link_handle (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LE
// Create new data link state machine.
p = calloc (sizeof(ax25_dlsm_t), 1);
if (p == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
p->magic1 = MAGIC1;
p->start_time = dtime_now();
p->stream_id = next_stream_id++;
@ -1066,12 +1079,31 @@ void dl_disconnect_request (dlq_item_t *E)
case state_1_awaiting_connection:
case state_5_awaiting_v22_connection:
// TODO: "requeue." Not sure what to do here.
// If we put it back in the queue we will get it back again probably still in same state.
// Need a way to defer it until the next state change.
// Erratum: The protocol spec says "requeue." If we put disconnect req back in the
// queue we will probably get it back again here while still in same state.
// I don't think we would want to delay it until the next state transition.
// Suppose someone tried to connect to another station, which is not responding, and decided to cancel
// before all of the SABMe retries were used up. I think we would want to transmit a DISC, send a disc
// notice to the user, and go directly into disconnected state, rather than into awaiting release.
// New code v1.7 dev, May 6 2023
text_color_set(DW_COLOR_INFO);
dw_printf ("Stream %d: In progress connection attempt to %s terminated by user.\n", S->stream_id, S->addrs[PEERCALL]);
discard_i_queue (S);
SET_RC(0);
int p1 = 1;
int nopid0 = 0;
packet_t pp15 = ax25_u_frame (S->addrs, S->num_addr, cr_cmd, frame_type_U_DISC, p1, nopid0, NULL, 0);
lm_data_request (S->chan, TQ_PRIO_1_LO, pp15);
STOP_T1; // started in establish_data_link.
STOP_T3; // probably don't need.
enter_new_state (S, state_0_disconnected, __func__, __LINE__);
server_link_terminated (S->chan, S->client, S->addrs[PEERCALL], S->addrs[OWNCALL], 0);
break;
case state_2_awaiting_release:
{
// We have previously started the disconnect sequence and are waiting
@ -1157,7 +1189,7 @@ void dl_disconnect_request (dlq_item_t *E)
*
* Erratum: Not sure how to interpret that. See example below for how it was implemented.
*
* Version 1.6: Bug 252. Segmentation was occuring for a V2.0 link. From the spec:
* Version 1.6: Bug 252. Segmentation was occurring for a V2.0 link. From the spec:
* "The receipt of an XID response from the other station establishes that both
* stations are using AX.25 version 2.2 or higher and enables the use of the
* segmenter/reassembler and selective reject."
@ -1493,6 +1525,11 @@ void dl_register_callsign (dlq_item_t *E)
}
r = calloc(sizeof(reg_callsign_t),1);
if (r == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
strlcpy (r->callsign, E->addrs[0], sizeof(r->callsign));
r->chan = E->chan;
r->client = E->client;
@ -1564,15 +1601,51 @@ void dl_unregister_callsign (dlq_item_t *E)
*
* Description: This is the sum of:
* - Incoming connected data, from application still in the queue.
* - I frames which have been transmitted but not yet acknowleged.
* - I frames which have been transmitted but not yet acknowledged.
*
* Confusion: https://github.com/wb2osz/direwolf/issues/427
*
* There are different, inconsistent versions of the protocol spec.
*
* One of them simply has:
*
* CallFrom is our call
* CallTo is the call of the other station
*
* A more detailed version has the same thing in the table of fields:
*
* CallFrom 10 bytes Our CallSign
* CallTo 10 bytes Other CallSign
*
* (My first implementation went with that.)
*
* HOWEVER, shortly after that, is contradictory information:
*
* Careful must be exercised to fill correctly both the CallFrom
* and CallTo fields to match the ones of an existing connection,
* otherwise AGWPE wont return any information at all from this query.
*
* The order of the CallFrom and CallTo is not trivial, it should
* reflect the order used to start the connection, so
*
* * If we started the connection CallFrom=US and CallTo=THEM
* * If the other end started the connection CallFrom=THEM and CallTo=US
*
* This seems to make everything unnecessarily more complicated.
* We should only care about the stream going from the local station to the
* remote station. Why would it matter who reqested the link? The state
* machine doesn't even contain this information so the TNC doesn't know.
* The client app interface needs to behave differently for the two cases.
*
* The new code, below, May 2023, should handle both of those cases.
*
*------------------------------------------------------------------------------*/
void dl_outstanding_frames_request (dlq_item_t *E)
{
ax25_dlsm_t *S;
int ok_to_create = 0; // must exist already.
const int ok_to_create = 0; // must exist already.
int reversed_addrs = 0;
if (s_debug_client_app) {
text_color_set(DW_COLOR_DEBUG);
@ -1580,12 +1653,28 @@ void dl_outstanding_frames_request (dlq_item_t *E)
}
S = get_link_handle (E->addrs, E->num_addr, E->chan, E->client, ok_to_create);
if (S != NULL) {
reversed_addrs = 0;
}
else {
// Try swapping the addresses.
// this is communicating with the client app, not over the air,
// so we don't need to worry about digipeaters.
if (S == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Can't get outstanding frames for %s -> %s, chan %d\n", E->addrs[OWNCALL], E->addrs[PEERCALL], E->chan);
server_outstanding_frames_reply (E->chan, E->client, E->addrs[OWNCALL], E->addrs[PEERCALL], 0);
return;
char swapped[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN];
memset (swapped, 0, sizeof(swapped));
strlcpy (swapped[PEERCALL], E->addrs[OWNCALL], sizeof(swapped[PEERCALL]));
strlcpy (swapped[OWNCALL], E->addrs[PEERCALL], sizeof(swapped[OWNCALL]));
S = get_link_handle (swapped, E->num_addr, E->chan, E->client, ok_to_create);
if (S != NULL) {
reversed_addrs = 1;
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Can't get outstanding frames for %s -> %s, chan %d\n", E->addrs[OWNCALL], E->addrs[PEERCALL], E->chan);
server_outstanding_frames_reply (E->chan, E->client, E->addrs[OWNCALL], E->addrs[PEERCALL], 0);
return;
}
}
// Add up these
@ -1614,7 +1703,13 @@ void dl_outstanding_frames_request (dlq_item_t *E)
}
}
server_outstanding_frames_reply (S->chan, S->client, S->addrs[OWNCALL], S->addrs[PEERCALL], count1 + count2);
if (reversed_addrs) {
// Other end initiated the link.
server_outstanding_frames_reply (S->chan, S->client, S->addrs[PEERCALL], S->addrs[OWNCALL], count1 + count2);
}
else {
server_outstanding_frames_reply (S->chan, S->client, S->addrs[OWNCALL], S->addrs[PEERCALL], count1 + count2);
}
} // end dl_outstanding_frames_request
@ -1633,7 +1728,7 @@ void dl_outstanding_frames_request (dlq_item_t *E)
* Description: By client application we mean something that attached with the
* AGW network protocol.
*
* Clean out anything related to the specfied client application.
* Clean out anything related to the specified client application.
* This would include state machines and registered callsigns.
*
*------------------------------------------------------------------------------*/
@ -2201,7 +2296,7 @@ void lm_data_indication (dlq_item_t *E)
break;
// Erratum: The AX.25 spec is not clear about whether SREJ should be command, response, or both.
// The underlying X.25 spec clearly says it is reponse only. Let's go with that.
// The underlying X.25 spec clearly says it is response only. Let's go with that.
case frame_type_S_SREJ:
case frame_type_U_DM:
@ -2224,7 +2319,7 @@ void lm_data_indication (dlq_item_t *E)
case frame_type_U_UI:
// Don't test at this point in case an APRS frame gets thru.
// APRS doesn't specify what to put in the Source and Dest C bits.
// In practice we see all 4 possble combinations.
// In practice we see all 4 possible combinations.
// I have an opinion about what would be "correct" (discussed elsewhere)
// but in practice no one seems to care.
break;
@ -2701,7 +2796,7 @@ static void i_frame_continued (ax25_dlsm_t *S, int p, int ns, int pid, char *inf
if (S->rxdata_by_ns[ns] != NULL) {
// There is a possibility that we might have another received frame stashed
// away from 8 or 128 (modulo) frames back. Remove it so it doesn't accidently
// away from 8 or 128 (modulo) frames back. Remove it so it doesn't accidentally
// show up at some future inopportune time.
cdata_delete (S->rxdata_by_ns[ns]);
@ -2786,7 +2881,7 @@ static void i_frame_continued (ax25_dlsm_t *S, int p, int ns, int pid, char *inf
// we discard 3,4,5,6, and tell the other end to resend everything starting with 2.
// At one time, I had some doubts about when to use command or response for REJ.
// I now believe that reponse, as implied by setting F in the flow chart, is correct.
// I now believe that response, as implied by setting F in the flow chart, is correct.
int f = p;
int nr = S->vr; // Next expected sequence number.
@ -2796,7 +2891,7 @@ static void i_frame_continued (ax25_dlsm_t *S, int p, int ns, int pid, char *inf
S->reject_exception = 1;
if (s_debug_retry) {
text_color_set(DW_COLOR_ERROR); // make it more noticable.
text_color_set(DW_COLOR_ERROR); // make it more noticeable.
dw_printf ("sending REJ, at %s %d, SREJ not enabled case, V(R)=%d", __func__, __LINE__, S->vr);
}
@ -2860,7 +2955,7 @@ static void i_frame_continued (ax25_dlsm_t *S, int p, int ns, int pid, char *inf
// In version 1.4:
// We end up sending more SREJ than necessary and and get back redundant information. Example:
// When we see 113 missing, we ask for a resend.
// When we see 115 & 116 missing, a cummulative SREJ asks for everything.
// When we see 115 & 116 missing, a cumulative SREJ asks for everything.
// The other end dutifully sends 113 twice.
//
// [0.4] DW1>DW0:(SREJ res, n(r)=113, f=0)
@ -2890,7 +2985,7 @@ static void i_frame_continued (ax25_dlsm_t *S, int p, int ns, int pid, char *inf
// int allow_f1 = 0; // F=1 from X.25 2.4.6.4 b) 3)
int allow_f1 = 1; // F=1 from X.25 2.4.6.4 b) 3)
// send only for this gap, not cummulative from V(R).
// send only for this gap, not cumulative from V(R).
int last = AX25MODULO(ns - 1, S->modulo, __FILE__, __func__, __LINE__);
int first = last;
@ -2993,7 +3088,7 @@ dw_printf ("%s:%d, %d srej exceptions, V(R)=%d, N(S)=%d\n", __func__, __LINE__,
if (first == AX25MODULO(S->vr - 1, S->modulo, __FILE__, __func__, __LINE__)) {
// Oops! Went too far. This I frame was already processed.
text_color_set(DW_COLOR_ERROR);
dw_printf ("INTERNAL ERROR calulating what to put in SREJ, %s line %d\n", __func__, __LINE__);
dw_printf ("INTERNAL ERROR calculating what to put in SREJ, %s line %d\n", __func__, __LINE__);
dw_printf ("V(R)=%d, N(S)=%d, SREJ exception=%d, first=%d, ask_resend_count=%d\n", S->vr, ns, selective_reject_exception(S), first, ask_resend_count);
int k;
for (k=0; k<128; k++) {
@ -3146,7 +3241,7 @@ static void send_srej_frames (ax25_dlsm_t *S, int *resend, int count, int allow_
if (s_debug_retry) {
text_color_set(DW_COLOR_INFO);
dw_printf ("%s line %d\n", __func__, __LINE__);
//dw_printf ("state=%d, count=%d, k=%d, V(R)=%d, SREJ exeception=%d\n", S->state, count, S->k_maxframe, S->vr, selective_reject_exception(S));
//dw_printf ("state=%d, count=%d, k=%d, V(R)=%d, SREJ exception=%d\n", S->state, count, S->k_maxframe, S->vr, selective_reject_exception(S));
dw_printf ("state=%d, count=%d, k=%d, V(R)=%d\n", S->state, count, S->k_maxframe, S->vr);
dw_printf ("resend[]=");
@ -3447,7 +3542,7 @@ static void rr_rnr_frame (ax25_dlsm_t *S, int ready, cmdres_t cr, int pf, int nr
// we received RR frames with N(R) values indicating that the other side received everything
// that we sent. Eventually rc could reach the limit and we would get an error.
// If we are in state 4, and other guy ack'ed last I frame we sent, transition to state 3.
// The same thing was done for receving I frames after check_i_frame_ackd.
// The same thing was done for receiving I frames after check_i_frame_ackd.
// Thought: Could we simply call check_i_frame_ackd, for consistency, rather than only setting V(A)?
@ -3759,7 +3854,7 @@ static void rej_frame (ax25_dlsm_t *S, cmdres_t cr, int pf, int nr)
*
* The SREJ command/response initiates more-efficient error recovery by requesting the retransmission of a
* single I frame following the detection of a sequence error. This is an advancement over the earlier versions in
* which the requested I frame was retransmitted togther with all additional I frames subsequently transmitted and
* which the requested I frame was retransmitted together with all additional I frames subsequently transmitted and
* successfully received.
*
* When a TNC sends one or more SREJ commands, each with the P bit set to "0" or "1", or one or more SREJ
@ -4409,7 +4504,7 @@ static void disc_frame (ax25_dlsm_t *S, int p)
* earliest opportunity. If the TNC is not capable of accepting a SABME command, it responds with a DM frame.
*
* A TNC that uses a version of AX.25 prior to v2.2 responds with a FRMR.
* ( I think the KPC-3+ has a bug - it replys with DM - WB2OSZ )
* ( I think the KPC-3+ has a bug - it replies with DM - WB2OSZ )
*
* 4.3.3.5. Disconnected Mode (DM) Response
*
@ -4636,7 +4731,7 @@ static void ua_frame (ax25_dlsm_t *S, int f)
if (f == 1) {
if (S->layer_3_initiated) {
text_color_set(DW_COLOR_INFO);
// TODO: add via if apppropriate.
// TODO: add via if appropriate.
dw_printf ("Stream %d: Connected to %s. (%s)\n", S->stream_id, S->addrs[PEERCALL], S->state == state_5_awaiting_v22_connection ? "v2.2" : "v2.0");
// There is a subtle difference here between connect confirm and indication.
// connect *confirm* means "has been made"
@ -5615,7 +5710,7 @@ static void clear_exception_conditions (ax25_dlsm_t *S)
*
* Other guy gets RR/RNR command P=1.
* Same action for either state 3 or 4.
* Whether he has outstanding un-ack'ed sent I frames is irrelevent.
* Whether he has outstanding un-ack'ed sent I frames is irrelevant.
* He calls "enquiry response" which sends RR/RNR response F=1.
* (Read about detour 1 below and in enquiry_response.)
*
@ -6035,7 +6130,7 @@ static void check_need_for_response (ax25_dlsm_t *S, ax25_frame_type_t frame_typ
*
* Outputs: S->srt New smoothed roundtrip time.
*
* S->t1v How long to wait for an acknowlegement before resending.
* S->t1v How long to wait for an acknowledgement before resending.
* Value used when starting timer T1, in seconds.
* Here it is dynamically adjusted.
*
@ -6134,7 +6229,7 @@ static void select_t1_value (ax25_dlsm_t *S)
// This goes up exponentially if implemented as documented!
// For example, if we were trying to connect to a station which is not there, we
// would retry after 3, the 8, 16, 32, ... and not time out for over an hour.
// would retry after 3, then 8, 16, 32, ... and not time out for over an hour.
// That's ridiculous. Let's try increasing it by a quarter second each time.
// We now give up after about a minute.
@ -6151,12 +6246,30 @@ static void select_t1_value (ax25_dlsm_t *S)
}
// See https://groups.io/g/direwolf/topic/100782658#8542
// Perhaps the demands of file transfer lead to this problem.
// "Temporary" hack.
// Automatic fine tuning of t1v generally works well, but on very rare occasions, it gets wildly out of control.
// Until I have more time to properly diagnose this, add some guardrails so it does not go flying off a cliff.
// The initial value of t1v is frack + frack * 2 (number of digipeateers in path)
// If anything, it should automatically be adjusted down.
// Let's say, something smells fishy if it exceeds twice that initial value.
// TODO: Add some instrumentation to record where this was called from and all the values in the printf below.
#if 1
if (S->t1v < 0.25 || S->t1v > 2 * (g_misc_config_p->frack * (2 * (S->num_addr - 2) + 1)) ) {
INIT_T1V_SRT;
}
#else
if (S->t1v < 0.99 || S->t1v > 30) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("INTERNAL ERROR? Stream %d: select_t1_value, rc = %d, t1 remaining = %.3f, old srt = %.3f, new srt = %.3f, Extreme new t1v = %.3f\n",
S->stream_id, S->rc, S->t1_remaining_when_last_stopped, old_srt, S->srt, S->t1v);
}
#endif
} /* end select_t1_value */

View File

@ -49,7 +49,7 @@
*
*
* APRS uses only UI frames.
* Each starts with 2-10 addressses (14-70 octets):
* Each starts with 2-10 addresses (14-70 octets):
*
* * Destination Address (note: opposite order in printed format)
*
@ -350,8 +350,9 @@ void ax25_delete (packet_t this_p)
* strict - True to enforce rules for packets sent over the air.
* False to be more lenient for packets from IGate server.
*
* Messages from an IGate server can have longer
* addresses after qAC. Up to 9 observed so far.
* Packets from an IGate server can have longer
* addresses after qAC. Up to 9 observed so far.
* The SSID can be 2 alphanumeric characters, not just 1 to 15.
*
* We can just truncate the name because we will only
* end up discarding it. TODO: check on this.
@ -372,7 +373,7 @@ packet_t ax25_from_text (char *monitor, int strict)
/*
* Tearing it apart is destructive so make our own copy first.
*/
char stuff[512];
char stuff[AX25_MAX_PACKET_LEN+1];
char *pinfo;
int ssid_temp, heard_temp;
@ -511,6 +512,13 @@ packet_t ax25_from_text (char *monitor, int strict)
// printf ("DEBUG: get digi loop, num addr = %d, address = '%s'\n", k, pa);// FIXME
// Hack for q construct, from APRS-IS, so it does not cause panic later.
if ( ! strict && pa[0] == 'q' && pa[1] == 'A') {
pa[0] = 'Q';
pa[2] = toupper(pa[2]);
}
if ( ! ax25_parse_addr (k, pa, strict, atemp, &ssid_temp, &heard_temp)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Failed to create packet from text. Bad digipeater address\n");
@ -733,6 +741,7 @@ packet_t ax25_dup (packet_t copy_from)
* alphanumeric characters for the SSID.
* We also get messages like this from a server.
* KB1POR>APU25N,TCPIP*,qAC,T2NUENGLD:...
* K1BOS-B>APOSB,TCPIP,WR2X-2*:...
*
* 2 (extra true) will complain if * is found at end.
*
@ -940,7 +949,7 @@ int ax25_check_addresses (packet_t pp)
*
* Name: ax25_unwrap_third_party
*
* Purpose: Unwrap a third party messge from the header.
* Purpose: Unwrap a third party message from the header.
*
* Inputs: copy_from - Existing packet object.
*
@ -1717,6 +1726,19 @@ int ax25_get_info (packet_t this_p, unsigned char **paddr)
} /* end ax25_get_info */
void ax25_set_info (packet_t this_p, unsigned char *new_info_ptr, int new_info_len)
{
unsigned char *old_info_ptr;
int old_info_len = ax25_get_info (this_p, &old_info_ptr);
this_p->frame_len -= old_info_len;
if (new_info_len < 0) new_info_len = 0;
if (new_info_len > AX25_MAX_INFO_LEN) new_info_len = AX25_MAX_INFO_LEN;
memcpy (old_info_ptr, new_info_ptr, new_info_len);
this_p->frame_len += new_info_len;
}
/*------------------------------------------------------------------------------
*
* Name: ax25_cut_at_crlf
@ -1844,7 +1866,7 @@ packet_t ax25_get_nextp (packet_t this_p)
*
* Inputs: this_p - Current packet object.
*
* release_time - Time as returned by dtime_now().
* release_time - Time as returned by dtime_monotonic().
*
*------------------------------------------------------------------------------*/
@ -1892,6 +1914,25 @@ void ax25_set_modulo (packet_t this_p, int modulo)
}
/*------------------------------------------------------------------------------
*
* Name: ax25_get_modulo
*
* Purpose: Get modulo value for I and S frame sequence numbers.
*
* Returns: 8 or 128 if known.
* 0 if unknown.
*
*------------------------------------------------------------------------------*/
int ax25_get_modulo (packet_t this_p)
{
assert (this_p->magic1 == MAGIC);
assert (this_p->magic2 == MAGIC);
return (this_p->modulo);
}
@ -1944,6 +1985,7 @@ void ax25_format_addrs (packet_t this_p, char *result)
}
ax25_get_addr_with_ssid (this_p, AX25_SOURCE, stemp);
// FIXME: For ALL strcat: Pass in sizeof result and use strlcat.
strcat (result, stemp);
strcat (result, ">");
@ -2598,6 +2640,15 @@ int ax25_get_frame_len (packet_t this_p)
} /* end ax25_get_frame_len */
unsigned char *ax25_get_frame_data_ptr (packet_t this_p)
{
assert (this_p->magic1 == MAGIC);
assert (this_p->magic2 == MAGIC);
return (this_p->frame_data);
} /* end ax25_get_frame_data_ptr */
/*------------------------------------------------------------------------------
*
@ -2710,6 +2761,7 @@ unsigned short ax25_m_m_crc (packet_t pp)
unsigned char fbuf[AX25_MAX_PACKET_LEN];
int flen;
// TODO: I think this can be more efficient by getting the packet content pointer instead of copying.
flen = ax25_pack (pp, fbuf);
crc = 0xffff;
@ -2762,7 +2814,8 @@ unsigned short ax25_m_m_crc (packet_t pp)
*
*------------------------------------------------------------------*/
#define MAXSAFE 500
//#define MAXSAFE 500
#define MAXSAFE AX25_MAX_INFO_LEN
void ax25_safe_print (char *pstr, int len, int ascii_only)
{
@ -2870,7 +2923,9 @@ int ax25_alevel_to_text (alevel_t alevel, char text[AX25_ALEVEL_TO_TEXT_SIZE])
snprintf (text, AX25_ALEVEL_TO_TEXT_SIZE, "%d(%+d/%+d)", alevel.rec, alevel.mark, alevel.space);
}
else if (alevel.mark == -1 && alevel.space == -1) { /* PSK - single number. */
else if ((alevel.mark == -1 && alevel.space == -1) || /* PSK */
(alevel.mark == -99 && alevel.space == -99)) { /* v. 1.7 "B" FM demodulator. */
// ?? Where does -99 come from?
snprintf (text, AX25_ALEVEL_TO_TEXT_SIZE, "%d", alevel.rec);
}

View File

@ -11,7 +11,7 @@
#define AX25_MAX_REPEATERS 8
#define AX25_MIN_ADDRS 2 /* Destinatin & Source. */
#define AX25_MIN_ADDRS 2 /* Destination & Source. */
#define AX25_MAX_ADDRS 10 /* Destination, Source, 8 digipeaters. */
#define AX25_DESTINATION 0 /* Address positions in frame. */
@ -98,7 +98,7 @@ struct packet_s {
*
* Bits: H R R SSID 0
*
* H for digipeaters set to 0 intially.
* H for digipeaters set to 0 initially.
* Changed to 1 when position has been used.
*
* for source & destination it is called
@ -397,6 +397,7 @@ extern int ax25_get_first_not_repeated(packet_t pp);
extern int ax25_get_rr (packet_t this_p, int n);
extern int ax25_get_info (packet_t pp, unsigned char **paddr);
extern void ax25_set_info (packet_t pp, unsigned char *info_ptr, int info_len);
extern int ax25_cut_at_crlf (packet_t this_p);
extern void ax25_set_nextp (packet_t this_p, packet_t next_p);
@ -409,6 +410,7 @@ extern void ax25_set_release_time (packet_t this_p, double release_time);
extern double ax25_get_release_time (packet_t this_p);
extern void ax25_set_modulo (packet_t this_p, int modulo);
extern int ax25_get_modulo (packet_t this_p);
extern void ax25_format_addrs (packet_t pp, char *);
extern void ax25_format_via_path (packet_t this_p, char *result, size_t result_size);
@ -428,6 +430,7 @@ extern int ax25_get_c2 (packet_t this_p);
extern int ax25_get_pid (packet_t this_p);
extern int ax25_get_frame_len (packet_t this_p);
extern unsigned char *ax25_get_frame_data_ptr (packet_t this_p);
extern unsigned short ax25_dedupe_crc (packet_t pp);

View File

@ -102,7 +102,9 @@
*
* RR note: It seems that some implementations put a hint
* in the "RR" reserved bits.
* http://www.tapr.org/pipermail/ax25-layer2/2005-October/000297.html
* http://www.tapr.org/pipermail/ax25-layer2/2005-October/000297.html (now broken)
* https://elixir.bootlin.com/linux/latest/source/net/ax25/ax25_addr.c#L237
*
* The RR bits can also be used for "DAMA" which is
* some sort of channel access coordination scheme.
* http://internet.freepage.de/cgi-bin/feets/freepage_ext/41030x030A/rewrite/hennig/afu/afudoc/afudama.html
@ -406,7 +408,7 @@ packet_t ax25_s_frame (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int num_ad
}
// Erratum: The AX.25 spec is not clear about whether SREJ should be command, response, or both.
// The underlying X.25 spec clearly says it is reponse only. Let's go with that.
// The underlying X.25 spec clearly says it is response only. Let's go with that.
if (ftype == frame_type_S_SREJ && cr != cr_res) {
text_color_set(DW_COLOR_ERROR);

View File

@ -162,9 +162,10 @@ void beacon_init (struct audio_s *pmodem, struct misc_config_s *pconfig, struct
int chan = g_misc_config_p->beacon[j].sendto_chan;
if (chan < 0) chan = 0; /* For IGate, use channel 0 call. */
if (chan >= MAX_CHANS) chan = 0; // For ICHANNEL, use channel 0 call.
if (g_modem_config_p->achan[chan].medium == MEDIUM_RADIO ||
g_modem_config_p->achan[chan].medium == MEDIUM_NETTNC) {
if (g_modem_config_p->chan_medium[chan] == MEDIUM_RADIO ||
g_modem_config_p->chan_medium[chan] == MEDIUM_NETTNC) {
if (strlen(g_modem_config_p->achan[chan].mycall) > 0 &&
strcasecmp(g_modem_config_p->achan[chan].mycall, "N0CALL") != 0 &&
@ -614,6 +615,22 @@ static void * beacon_thread (void *arg)
/* i.e. Don't take relative to now in case there was some delay. */
bp->next += bp->every;
// https://github.com/wb2osz/direwolf/pull/301
// https://github.com/wb2osz/direwolf/pull/301
// This happens with a portable system with no Internet connection.
// On reboot, the time is in the past.
// After time gets set from GPS, all beacons from that interval are sent.
// FIXME: This will surely break time slotted scheduling.
// TODO: The correct fix will be using monotonic, rather than clock, time.
/* craigerl: if next beacon is scheduled in the past, then set next beacon relative to now (happens when NTP pushes clock AHEAD) */
/* fixme: if NTP sets clock BACK an hour, this thread will sleep for that hour */
if ( bp->next < now ) {
bp->next = now + bp->every;
text_color_set(DW_COLOR_INFO);
dw_printf("\nSystem clock appears to have jumped forward. Beacon schedule updated.\n\n");
}
}
} /* if time to send it */
@ -790,11 +807,17 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
assert (bp->sendto_chan >= 0);
strlcpy (mycall, g_modem_config_p->achan[bp->sendto_chan].mycall, sizeof(mycall));
if (g_modem_config_p->chan_medium[bp->sendto_chan] == MEDIUM_IGATE) { // ICHANNEL uses chan 0 mycall.
// TODO: Maybe it should be allowed to have own.
strlcpy (mycall, g_modem_config_p->achan[0].mycall, sizeof(mycall));
}
else {
strlcpy (mycall, g_modem_config_p->achan[bp->sendto_chan].mycall, sizeof(mycall));
}
if (strlen(mycall) == 0 || strcmp(mycall, "NOCALL") == 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("MYCALL not set for beacon in config file line %d.\n", bp->lineno);
dw_printf ("MYCALL not set for beacon to chan %d in config file line %d.\n", bp->sendto_chan, bp->lineno);
return;
}
@ -1031,7 +1054,7 @@ static void beacon_send (int j, dwgps_info_t *gpsinfo)
text_color_set(DW_COLOR_XMIT);
dw_printf ("[ig] %s\n", beacon_text);
igate_send_rec_packet (0, pp);
igate_send_rec_packet (-1, pp); // Channel -1 to avoid RF>IS filtering.
ax25_delete (pp);
break;

View File

@ -34,7 +34,7 @@
* are significantly different and I thought it would be
* too confusing to munge them together.
*
* References: The Ax.25 protcol barely mentions digipeaters and
* References: The Ax.25 protocol barely mentions digipeaters and
* and doesn't describe how they should work.
*
*------------------------------------------------------------------*/
@ -132,7 +132,7 @@ void cdigipeater (int from_chan, packet_t pp)
// Connected mode is allowed only for channels with internal modem.
// It probably wouldn't matter for digipeating but let's keep that rule simple and consistent.
if ( from_chan < 0 || from_chan >= MAX_CHANS || save_audio_config_p->achan[from_chan].medium != MEDIUM_RADIO) {
if ( from_chan < 0 || from_chan >= MAX_CHANS || save_audio_config_p->chan_medium[from_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("cdigipeater: Did not expect to receive on invalid channel %d.\n", from_chan);
return;
@ -255,7 +255,7 @@ static packet_t cdigipeat_match (int from_chan, packet_t pp, char *mycall_rec, c
* Originally this was the only one.
* Should we change it to AFILTER to make it clearer?
* CFILTER - Similar for connected moded digipeater.
* IGFILTER - APRS-IS (IGate) server side - completely diffeent.
* IGFILTER - APRS-IS (IGate) server side - completely different.
* Confusing with similar name but much different idea.
* Maybe this should be renamed to SUBSCRIBE or something like that.
*

View File

@ -30,10 +30,11 @@
*
* Description:
*
* There is an incresing demand for using the GPIO pins of USB audio devices for PTT.
* There is an increasing demand for using the GPIO pins of USB audio devices for PTT.
* We have a few commercial products:
*
* DINAH https://hamprojects.info/dinah/
* PAUL https://hamprojects.info/paul/
* DMK URI http://www.dmkeng.com/URI_Order_Page.htm
* RB-USB RIM http://www.repeater-builder.com/products/usb-rim-lite.html
* RA-35 http://www.masterscommunications.com/products/radio-adapter/ra35.html
@ -53,7 +54,7 @@
* painful roundabout way. This is documented in the User Guide, section called,
* "Hamlib PTT Example 2: Use GPIO of USB audio adapter. (e.g. DMK URI)"
*
* It's rather involved and the explantion doesn't cover the case of multiple
* It's rather involved and the explanation doesn't cover the case of multiple
* USB-Audio adapters. It is not as straightforward as you might expect. Here we have
* an example of 3 C-Media USB adapters, a SignaLink USB, a keyboard, and a mouse.
*
@ -93,6 +94,12 @@
* with a single USB Audio Adapter, but does not automatically handle the multiple device case.
* Manual configuration needs to be used in this case.
*
* Here is something new and interesting. The All in One cable (AIOC).
* https://github.com/skuep/AIOC/tree/master
*
* A microcontroller is used to emulate a CM108-compatible soundcard
* and a serial port. It fits right on the side of a Bao Feng or similar.
*
*---------------------------------------------------------------*/
#include "direwolf.h"
@ -178,6 +185,11 @@ static int cm108_write (char *name, int iomask, int iodata);
#define SSS_PID2 0x1607
#define SSS_PID3 0x160b
// https://github.com/skuep/AIOC/blob/master/stm32/aioc-fw/Src/usb_descriptors.h
#define AIOC_VID 0x1209
#define AIOC_PID 0x7388
// Device VID PID Number of GPIO
// ------ --- --- --------------
@ -217,7 +229,9 @@ static int cm108_write (char *name, int iomask, int iodata);
|| p == CMEDIA_PID_CM119A \
|| p == CMEDIA_PID_CM119B )) \
|| \
(v == SSS_VID && (p == SSS_PID1 || p == SSS_PID2 || p == SSS_PID3)) )
(v == SSS_VID && (p == SSS_PID1 || p == SSS_PID2 || p == SSS_PID3)) \
|| \
(v == AIOC_VID && p == AIOC_PID) )
// Look out for null source pointer, and avoid buffer overflow on destination.
@ -243,6 +257,12 @@ static void substr_se (char *dest, const char *src, int start, int endp1)
#endif
// Maximum length of name for PTT HID.
// For Linux, this was originally 17 to handle names like /dev/hidraw3.
// Windows has more complicated names. The longest I saw was 95 but longer have been reported.
#define MAXX_HIDRAW_NAME_LEN 128
/*
* Result of taking inventory of USB soundcards and USB HIDs.
*/
@ -258,7 +278,8 @@ struct thing_s {
// Oversized to silence a compiler warning.
char plughw2[72]; // With name rather than number.
char devpath[128]; // Kernel dev path. Does not include /sys mount point.
char devnode_hidraw[128]; // e.g. /dev/hidraw3 - for Linux - was length 17
char devnode_hidraw[MAXX_HIDRAW_NAME_LEN];
// e.g. /dev/hidraw3 - for Linux - was length 17
// The Windows path for a HID looks like this, lengths up to 95 seen.
// \\?\hid#vid_0d8c&pid_000c&mi_03#8&164d11c9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
char devnode_usb[25]; // e.g. /dev/bus/usb/001/012
@ -304,7 +325,7 @@ static void usage(void)
dw_printf ("which ones can be used for GPIO PTT.\n");
#endif
dw_printf ("\n");
dw_printf ("Specify the HID device path to test the PTT fuction.\n");
dw_printf ("Specify the HID device path to test the PTT function.\n");
dw_printf ("Its state should change once per second.\n");
#if __WIN32__
dw_printf ("You might need to quote the path depending on the command processor.\n");
@ -740,7 +761,7 @@ int cm108_inventory (struct thing_s *things, int max_things)
* ptt_device_size - Size of result area to avoid buffer overflow.
*
* Outputs: ptt_device - Device name, something like /dev/hidraw2.
* Will be emptry string if no match found.
* Will be empty string if no match found.
*
* Returns: none
*
@ -852,9 +873,9 @@ void cm108_find_ptt (char *output_audio_device, char *ptt_device, int ptt_devic
*
* Errors: A descriptive error message will be printed for any problem.
*
* Future: For our initial implementation we are making the simplifying
* Shortcut: For our initial implementation we are making the simplifying
* restriction of using only one GPIO pin per device and limit
* configuratin to PTT only.
* configuration to PTT only.
* Longer term, we might want to have DCD, and maybe other
* controls thru the same chip.
* In this case, we would need to retain bit masks for each
@ -882,7 +903,6 @@ int cm108_set_gpio_pin (char *name, int num, int state)
iomask = 1 << (num - 1); // 0=input, 1=output
iodata = state << (num - 1); // 0=low, 1=high
return (cm108_write (name, iomask, iodata));
} /* end cm108_set_gpio_pin */

View File

@ -317,7 +317,7 @@ static double parse_ll (char *str, enum parse_ll_which_e which, int line)
* - Negative zone for south.
* - Separate North or South.
*
* I'm using the first alternatve.
* I'm using the first alternative.
* GEOTRANS uses the third.
* We will also recognize the second one but I'm not sure if I want to document it.
*
@ -585,7 +585,7 @@ static int check_via_path (char *via_path)
*
*--------------------------------------------------------------------*/
#define MAXCMDLEN 256
#define MAXCMDLEN 1200
static char *split (char *string, int rest_of_line)
@ -709,6 +709,14 @@ static char *split (char *string, int rest_of_line)
*
*--------------------------------------------------------------------*/
static void rtfm()
{
text_color_set(DW_COLOR_ERROR);
dw_printf ("See online documentation:\n");
dw_printf (" stable release: https://github.com/wb2osz/direwolf/tree/master/doc\n");
dw_printf (" development version: https://github.com/wb2osz/direwolf/tree/dev/doc\n");
dw_printf (" additional topics: https://github.com/wb2osz/direwolf-doc\n");
}
void config_init (char *fname, struct audio_s *p_audio_config,
struct digi_config_s *p_digi_config,
@ -736,6 +744,8 @@ void config_init (char *fname, struct audio_s *p_audio_config,
memset (p_audio_config, 0, sizeof(struct audio_s));
p_audio_config->igate_vchannel = -1; // none.
/* First audio device is always available with defaults. */
/* Others must be explicitly defined before use. */
@ -755,7 +765,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
for (channel=0; channel<MAX_CHANS; channel++) {
int ot, it;
p_audio_config->achan[channel].medium = MEDIUM_NONE; /* One or both channels will be */
p_audio_config->chan_medium[channel] = MEDIUM_NONE; /* One or both channels will be */
/* set to radio when corresponding */
/* audio device is defined. */
p_audio_config->achan[channel].modem_type = MODEM_AFSK;
@ -770,6 +780,10 @@ void config_init (char *fname, struct audio_s *p_audio_config,
p_audio_config->achan[channel].num_freq = 1;
p_audio_config->achan[channel].offset = 0;
p_audio_config->achan[channel].layer2_xmit = LAYER2_AX25;
p_audio_config->achan[channel].il2p_max_fec = 1;
p_audio_config->achan[channel].il2p_invert_polarity = 0;
p_audio_config->achan[channel].fix_bits = DEFAULT_FIX_BITS;
p_audio_config->achan[channel].sanity_test = SANITY_APRS;
p_audio_config->achan[channel].passall = 0;
@ -804,7 +818,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/* First channel should always be valid. */
/* If there is no ADEVICE, it uses default device in mono. */
p_audio_config->achan[0].medium = MEDIUM_RADIO;
p_audio_config->chan_medium[0] = MEDIUM_RADIO;
memset (p_digi_config, 0, sizeof(struct digi_config_s)); // APRS digipeater
p_digi_config->dedupe_time = DEFAULT_DEDUPE;
@ -964,7 +978,8 @@ void config_init (char *fname, struct audio_s *p_audio_config,
text_color_set(DW_COLOR_ERROR);
dw_printf ("ERROR - Could not open config file %s\n", filepath);
dw_printf ("Try using -c command line option for alternate location.\n");
return;
rtfm();
exit(EXIT_FAILURE);
}
dw_printf ("\nReading config file %s\n", filepath);
@ -1021,13 +1036,14 @@ void config_init (char *fname, struct audio_s *p_audio_config,
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Missing name of audio device for ADEVICE command on line %d.\n", line);
continue;
rtfm();
exit(EXIT_FAILURE);
}
p_audio_config->adev[adevice].defined = 1;
/* First channel of device is valid. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].medium = MEDIUM_RADIO;
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice)] = MEDIUM_RADIO;
strlcpy (p_audio_config->adev[adevice].adevice_in, t, sizeof(p_audio_config->adev[adevice].adevice_in));
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
@ -1082,7 +1098,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
p_audio_config->adev[adevice].defined = 1;
/* First channel of device is valid. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].medium = MEDIUM_RADIO;
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice)] = MEDIUM_RADIO;
strlcpy (p_audio_config->adev[adevice].adevice_in, t, sizeof(p_audio_config->adev[adevice].adevice_in));
}
@ -1109,7 +1125,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
p_audio_config->adev[adevice].defined = 1;
/* First channel of device is valid. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].medium = MEDIUM_RADIO;
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice)] = MEDIUM_RADIO;
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
}
@ -1156,9 +1172,9 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/* Set valid channels depending on mono or stereo. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].medium = MEDIUM_RADIO;
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice)] = MEDIUM_RADIO;
if (n == 2) {
p_audio_config->achan[ADEVFIRSTCHAN(adevice) + 1].medium = MEDIUM_RADIO;
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice) + 1] = MEDIUM_RADIO;
}
}
else {
@ -1172,7 +1188,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
*/
/*
* CHANNEL - Set channel for following commands.
* CHANNEL n - Set channel for channel-specific commands.
*/
else if (strcasecmp(t, "CHANNEL") == 0) {
@ -1188,7 +1204,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
channel = n;
if (p_audio_config->achan[n].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[n] != MEDIUM_RADIO) {
if ( ! p_audio_config->adev[ACHAN2ADEV(n)].defined) {
text_color_set(DW_COLOR_ERROR);
@ -1208,6 +1224,44 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
}
/*
* ICHANNEL n - Define IGate virtual channel.
*
* This allows a client application to talk to to APRS-IS
* by using a channel number outside the normal range for modems.
* In the future there might be other typs of virtual channels.
* This does not change the current channel number used by MODEM, PTT, etc.
*/
else if (strcasecmp(t, "ICHANNEL") == 0) {
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing virtual channel number for ICHANNEL command.\n", line);
continue;
}
int ichan = atoi(t);
if (ichan >= MAX_CHANS && ichan < MAX_TOTAL_CHANS) {
if (p_audio_config->chan_medium[ichan] == MEDIUM_NONE) {
p_audio_config->chan_medium[ichan] = MEDIUM_IGATE;
// This is redundant but saves the time of searching through all
// the channels for each packet.
p_audio_config->igate_vchannel = ichan;
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: ICHANNEL can't use %d because it is already in use.\n", line, ichan);
}
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: ICHANNEL number must in range of %d to %d.\n", line, MAX_CHANS, MAX_TOTAL_CHANS-1);
}
}
/*
* MYCALL station
*/
@ -1650,6 +1704,9 @@ void config_init (char *fname, struct audio_s *p_audio_config,
text_color_set(DW_COLOR_INFO);
dw_printf ("Line %d: Using a FIX_BITS value greater than %d is not recommended for normal operation.\n",
line, DEFAULT_FIX_BITS);
dw_printf ("FIX_BITS > 1 was an interesting experiment but turned out to be a bad idea.\n");
dw_printf ("Don't be surprised if it takes 100%% CPU, direwolf can't keep up with the audio stream,\n");
dw_printf ("and you see messages like \"Audio input device 0 error code -32: Broken pipe\"\n");
}
t = split(NULL,0);
@ -1817,7 +1874,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
strlcpy (p_audio_config->achan[channel].octrl[ot].ptt_device, t, sizeof(p_audio_config->achan[channel].octrl[ot].ptt_device));
// Optional serial port rate for CAT controll PTT.
// Optional serial port rate for CAT control PTT.
t = split(NULL,0);
if (t != NULL) {
@ -1893,6 +1950,16 @@ void config_init (char *fname, struct audio_s *p_audio_config,
p_audio_config->achan[channel].octrl[ot].out_gpio_num = atoi(t);
p_audio_config->achan[channel].octrl[ot].ptt_invert = 0;
}
#if __WIN32__
else if (*t == '\\') {
strlcpy (p_audio_config->achan[channel].octrl[ot].ptt_device, t, sizeof(p_audio_config->achan[channel].octrl[ot].ptt_device));
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file line %d: Found \"%s\" when expecting GPIO number or device name like \\\\?\\hid#vid_0d8c&... .\n", line, t);
continue;
}
#else
else if (*t == '/') {
strlcpy (p_audio_config->achan[channel].octrl[ot].ptt_device, t, sizeof(p_audio_config->achan[channel].octrl[ot].ptt_device));
}
@ -1901,6 +1968,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
dw_printf ("Config file line %d: Found \"%s\" when expecting GPIO number or device name like /dev/hidraw1.\n", line, t);
continue;
}
#endif
}
if (p_audio_config->achan[channel].octrl[ot].out_gpio_num < 1 || p_audio_config->achan[channel].octrl[ot].out_gpio_num > 8) {
text_color_set(DW_COLOR_ERROR);
@ -1928,7 +1996,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
dw_printf ("Config file line %d: %s with CM108 is only available when USB Audio GPIO support is enabled.\n", line, otname);
dw_printf ("You must rebuild direwolf with CM108 Audio Adapter GPIO PTT support.\n");
dw_printf ("See Interface Guide for details.\n");
rtfm();
exit (EXIT_FAILURE);
#endif
}
@ -2241,7 +2309,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
* 0 = off, 1 = auto mode, others are suggestions for testing
* or special cases. 16, 32, 64 is number of parity bytes to add.
* Also set by "-X n" command line option.
* Current a global setting. Could be per channel someday.
* V1.7 changed from global to per-channel setting.
*/
else if (strcasecmp(t, "FX25TX") == 0) {
@ -2254,13 +2322,15 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
n = atoi(t);
if (n >= 0 && n < 200) {
p_audio_config->fx25_xmit_enable = n;
p_audio_config->achan[channel].fx25_strength = n;
p_audio_config->achan[channel].layer2_xmit = LAYER2_FX25;
}
else {
p_audio_config->fx25_xmit_enable = 1;
p_audio_config->achan[channel].fx25_strength = 1;
p_audio_config->achan[channel].layer2_xmit = LAYER2_FX25;
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Unreasonable value for FX.25 transmission mode. Using %d.\n",
line, p_audio_config->fx25_xmit_enable);
line, p_audio_config->achan[channel].fx25_strength);
}
}
@ -2293,12 +2363,57 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
}
/*
* IL2PTX [ + - ] [ 0 1 ] - Enable IL2P transmission. Default off.
* "+" means normal polarity. Redundant since it is the default.
* (command line -I for first channel)
* "-" means inverted polarity. Do not use for 1200 bps.
* (command line -i for first channel)
* "0" means weak FEC. Not recommended.
* "1" means stronger FEC. "Max FEC." Default if not specified.
*/
else if (strcasecmp(t, "IL2PTX") == 0) {
p_audio_config->achan[channel].layer2_xmit = LAYER2_IL2P;
p_audio_config->achan[channel].il2p_max_fec = 1;
p_audio_config->achan[channel].il2p_invert_polarity = 0;
while ((t = split(NULL,0)) != NULL) {
for (char *c = t; *c != '\0'; c++) {
switch (*c) {
case '+':
p_audio_config->achan[channel].il2p_invert_polarity = 0;
break;
case '-':
p_audio_config->achan[channel].il2p_invert_polarity = 1;
break;
case '0':
p_audio_config->achan[channel].il2p_max_fec = 0;
break;
case '1':
p_audio_config->achan[channel].il2p_max_fec = 1;
break;
default:
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Invalid parameter '%c' fol IL2PTX command.\n", line, *c);
continue;
break;
}
}
}
}
/*
* ==================== APRS Digipeater parameters ====================
*/
/*
* DIGIPEAT from-chan to-chan alias-pattern wide-pattern [ OFF|DROP|MARK|TRACE ]
* DIGIPEAT from-chan to-chan alias-pattern wide-pattern [ OFF|DROP|MARK|TRACE | ATGP=alias ]
*
* ATGP is an ugly hack for the specific need of ATGP which needs more that 8 digipeaters.
* DO NOT put this in the User Guide. On a need to know basis.
*/
else if (strcasecmp(t, "DIGIPEAT") == 0 || strcasecmp(t, "DIGIPEATER") == 0) {
@ -2329,8 +2444,8 @@ void config_init (char *fname, struct audio_s *p_audio_config,
// Channels specified must be radio channels or network TNCs.
if (p_audio_config->achan[from_chan].medium != MEDIUM_RADIO &&
p_audio_config->achan[from_chan].medium != MEDIUM_NETTNC) {
if (p_audio_config->chan_medium[from_chan] != MEDIUM_RADIO &&
p_audio_config->chan_medium[from_chan] != MEDIUM_NETTNC) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: FROM-channel %d is not valid.\n",
line, from_chan);
@ -2357,8 +2472,8 @@ void config_init (char *fname, struct audio_s *p_audio_config,
continue;
}
if (p_audio_config->achan[to_chan].medium != MEDIUM_RADIO &&
p_audio_config->achan[to_chan].medium != MEDIUM_NETTNC) {
if (p_audio_config->chan_medium[to_chan] != MEDIUM_RADIO &&
p_audio_config->chan_medium[to_chan] != MEDIUM_NETTNC) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TO-channel %d is not valid.\n",
line, to_chan);
@ -2408,7 +2523,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Preemptive digipeating DROP option is discouraged.\n", line);
dw_printf ("It can create a via path which is misleading about the actual path taken.\n");
dw_printf ("TRACE is the best choice for this feature.\n");
dw_printf ("PREEMPT is the best choice for this feature.\n");
p_digi_config->preempt[from_chan][to_chan] = PREEMPT_DROP;
t = split(NULL,0);
}
@ -2416,14 +2531,18 @@ void config_init (char *fname, struct audio_s *p_audio_config,
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Preemptive digipeating MARK option is discouraged.\n", line);
dw_printf ("It can create a via path which is misleading about the actual path taken.\n");
dw_printf ("TRACE is the best choice for this feature.\n");
dw_printf ("PREEMPT is the best choice for this feature.\n");
p_digi_config->preempt[from_chan][to_chan] = PREEMPT_MARK;
t = split(NULL,0);
}
else if (strcasecmp(t, "TRACE") == 0) {
else if ((strcasecmp(t, "TRACE") == 0) || (strncasecmp(t, "PREEMPT", 7) == 0)){
p_digi_config->preempt[from_chan][to_chan] = PREEMPT_TRACE;
t = split(NULL,0);
}
else if (strncasecmp(t, "ATGP=", 5) == 0) {
strlcpy (p_digi_config->atgp[from_chan][to_chan], t+5, sizeof(p_digi_config->atgp[from_chan][to_chan]));;
t = split(NULL,0);
}
}
if (t != NULL) {
@ -2486,7 +2605,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
// Only radio channels are valid for regenerate.
if (p_audio_config->achan[from_chan].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[from_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: FROM-channel %d is not valid.\n",
line, from_chan);
@ -2512,7 +2631,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
MAX_CHANS-1, line);
continue;
}
if (p_audio_config->achan[to_chan].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[to_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TO-channel %d is not valid.\n",
line, to_chan);
@ -2563,7 +2682,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
// There is discussion about this in the document called
// Why-is-9600-only-twice-as-fast-as-1200.pdf
if (p_audio_config->achan[from_chan].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[from_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: FROM-channel %d is not valid.\n",
line, from_chan);
@ -2590,7 +2709,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
MAX_CHANS-1, line);
continue;
}
if (p_audio_config->achan[to_chan].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[to_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TO-channel %d is not valid.\n",
line, to_chan);
@ -2652,11 +2771,11 @@ void config_init (char *fname, struct audio_s *p_audio_config,
* There is discussion about this in the document called
* Why-is-9600-only-twice-as-fast-as-1200.pdf
*
* IGFILTER - APRS-IS (IGate) server side - completely diffeent.
* IGFILTER - APRS-IS (IGate) server side - completely different.
* I'm not happy with this name because IG sounds like IGate
* which is really the client side. More comments later.
* Maybe it should be called subscribe or something like that
* because the subscriptions are cummulative.
* because the subscriptions are cumulative.
*/
else if (strcasecmp(t, "FILTER") == 0) {
@ -2671,6 +2790,12 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
if (*t == 'i' || *t == 'I') {
from_chan = MAX_CHANS;
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: FILTER IG ... on line %d.\n", line);
dw_printf ("Warning! Don't mess with IS>RF filtering unless you are an expert and have an unusual situation.\n");
dw_printf ("Warning! The default is fine for nearly all situations.\n");
dw_printf ("Warning! Be sure to read carefully and understand Successful-APRS-Gateway-Operation.pdf .\n");
dw_printf ("Warning! If you insist, be sure to add \" | i/180 \" so you don't break messaging.\n");
}
else {
from_chan = isdigit(*t) ? atoi(t) : -999;
@ -2681,14 +2806,14 @@ void config_init (char *fname, struct audio_s *p_audio_config,
continue;
}
if (p_audio_config->achan[from_chan].medium != MEDIUM_RADIO &&
p_audio_config->achan[from_chan].medium != MEDIUM_NETTNC) {
if (p_audio_config->chan_medium[from_chan] != MEDIUM_RADIO &&
p_audio_config->chan_medium[from_chan] != MEDIUM_NETTNC) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: FROM-channel %d is not valid.\n",
line, from_chan);
continue;
}
if (p_audio_config->achan[from_chan].medium == MEDIUM_IGATE) {
if (p_audio_config->chan_medium[from_chan] == MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Use 'IG' rather than %d for FROM-channel.\n",
line, from_chan);
@ -2704,6 +2829,12 @@ void config_init (char *fname, struct audio_s *p_audio_config,
}
if (*t == 'i' || *t == 'I') {
to_chan = MAX_CHANS;
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: FILTER ... IG ... on line %d.\n", line);
dw_printf ("Warning! Don't mess with RF>IS filtering unless you are an expert and have an unusual situation.\n");
dw_printf ("Warning! Expected behavior is for everything to go from RF to IS.\n");
dw_printf ("Warning! The default is fine for nearly all situations.\n");
dw_printf ("Warning! Be sure to read carefully and understand Successful-APRS-Gateway-Operation.pdf .\n");
}
else {
to_chan = isdigit(*t) ? atoi(t) : -999;
@ -2713,14 +2844,14 @@ void config_init (char *fname, struct audio_s *p_audio_config,
MAX_CHANS-1, line);
continue;
}
if (p_audio_config->achan[to_chan].medium != MEDIUM_RADIO &&
p_audio_config->achan[to_chan].medium != MEDIUM_NETTNC) {
if (p_audio_config->chan_medium[to_chan] != MEDIUM_RADIO &&
p_audio_config->chan_medium[to_chan] != MEDIUM_NETTNC) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TO-channel %d is not valid.\n",
line, to_chan);
continue;
}
if (p_audio_config->achan[to_chan].medium == MEDIUM_IGATE) {
if (p_audio_config->chan_medium[to_chan] == MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Use 'IG' rather than %d for TO-channel.\n",
line, to_chan);
@ -2755,6 +2886,9 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/*
* CFILTER from-chan to-chan filter_specification_expression
*
* Why did I put this here?
* What would be a useful use case? Perhaps block by source or destination?
*/
else if (strcasecmp(t, "CFILTER") == 0) {
@ -2779,7 +2913,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
// DO NOT allow a network TNC here.
// Must be internal modem to have necessary knowledge about channel status.
if (p_audio_config->achan[from_chan].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[from_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: FROM-channel %d is not valid.\n",
line, from_chan);
@ -2800,7 +2934,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
MAX_CHANS-1, line);
continue;
}
if (p_audio_config->achan[to_chan].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[to_chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TO-channel %d is not valid.\n",
line, to_chan);
@ -3114,7 +3248,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing latitude for TTGRID command.\n", line);
dw_printf ("Line %d: Missing minimum latitude for TTGRID command.\n", line);
continue;
}
tl->grid.lat0 = parse_ll(t,LAT,line);
@ -3124,7 +3258,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing longitude for TTGRID command.\n", line);
dw_printf ("Line %d: Missing minimum longitude for TTGRID command.\n", line);
continue;
}
tl->grid.lon0 = parse_ll(t,LON,line);
@ -3134,7 +3268,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing latitude for TTGRID command.\n", line);
dw_printf ("Line %d: Missing maximum latitude for TTGRID command.\n", line);
continue;
}
tl->grid.lat9 = parse_ll(t,LAT,line);
@ -3144,13 +3278,16 @@ void config_init (char *fname, struct audio_s *p_audio_config,
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing longitude for TTGRID command.\n", line);
dw_printf ("Line %d: Missing maximum longitude for TTGRID command.\n", line);
continue;
}
tl->grid.lon0 = parse_ll(t,LON,line);
tl->grid.lon9 = parse_ll(t,LON,line);
/* temp debugging */
// dw_printf ("CONFIG TTGRID min %f %f\n", tl->grid.lat0, tl->grid.lon0);
// dw_printf ("CONFIG TTGRID max %f %f\n", tl->grid.lat9, tl->grid.lon9);
//for (j=0; j<p_tt_config->ttloc_len; j++) {
// dw_printf ("debug ttloc %d/%d %s\n", j, p_tt_config->ttloc_size,
// p_tt_config->ttloc_ptr[j].pattern);
@ -3687,7 +3824,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
strlcpy(tl->pattern, "", sizeof(tl->pattern));
/* Pattern: Any combination of digits, x, y, and z. */
/* Also make note of which letters are used in pattern and defintition. */
/* Also make note of which letters are used in pattern and definition. */
/* Version 1.2: also allow A,B,C,D in the pattern. */
t = split(NULL,0);
@ -3961,7 +4098,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
// I suppose we need internal modem channel here.
// otherwise a DTMF decoder would not be available.
if (p_audio_config->achan[r].medium != MEDIUM_RADIO) {
if (p_audio_config->chan_medium[r] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TTOBJ DTMF receive channel %d is not valid.\n",
line, r);
@ -3987,8 +4124,8 @@ void config_init (char *fname, struct audio_s *p_audio_config,
dw_printf ("Config file: Transmit channel must be in range of 0 to %d on line %d.\n", MAX_CHANS-1, line);
x = -1;
}
else if (p_audio_config->achan[x].medium != MEDIUM_RADIO &&
p_audio_config->achan[x].medium != MEDIUM_NETTNC) {
else if (p_audio_config->chan_medium[x] != MEDIUM_RADIO &&
p_audio_config->chan_medium[x] != MEDIUM_NETTNC) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: TTOBJ transmit channel %d is not valid.\n", line, x);
x = -1;
@ -4473,6 +4610,13 @@ void config_init (char *fname, struct audio_s *p_audio_config,
continue;
}
n = atoi(t);
t = split(NULL,0);
if (t != NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Unexpected \"%s\" after the port number.\n", line, t);
dw_printf ("Perhaps you were trying to use feature available only with KISSPORT.\n");
continue;
}
if ((n >= MIN_IP_PORT_NUMBER && n <= MAX_IP_PORT_NUMBER) || n == 0) {
p_misc_config->agwpe_port = n;
}
@ -4629,6 +4773,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/*
* KISSCOPY - Data from network KISS client is copied to all others.
* This does not apply to pseudo terminal KISS.
*/
else if (strcasecmp(t, "KISSCOPY") == 0) {
@ -4674,7 +4819,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/*
* GPSNMEA - Device name for reading from GPS receiver.
* GPSNMEA serial-device [ speed ] - Direct connection to GPS receiver.
*/
else if (strcasecmp(t, "gpsnmea") == 0) {
t = split(NULL,0);
@ -4683,8 +4828,15 @@ void config_init (char *fname, struct audio_s *p_audio_config,
dw_printf ("Config file, line %d: Missing serial port name for GPS receiver.\n", line);
continue;
}
strlcpy (p_misc_config->gpsnmea_port, t, sizeof(p_misc_config->gpsnmea_port));
t = split(NULL,0);
if (t != NULL) {
int n = atoi(t);
p_misc_config->gpsnmea_speed = n;
}
else {
strlcpy (p_misc_config->gpsnmea_port, t, sizeof(p_misc_config->gpsnmea_port));
p_misc_config->gpsnmea_speed = 4800; // The standard at one time.
}
}
@ -4773,26 +4925,26 @@ void config_init (char *fname, struct audio_s *p_audio_config,
strlcpy (p_misc_config->waypoint_serial_port, t, sizeof(p_misc_config->waypoint_serial_port));
}
/* Anthing remaining is the formats to enable. */
/* Anything remaining is the formats to enable. */
t = split(NULL,1);
if (t != NULL) {
for ( ; *t != '\0' ; t++ ) {
switch (toupper(*t)) {
case 'N':
p_misc_config->waypoint_formats |= WPT_FORMAT_NMEA_GENERIC;
p_misc_config->waypoint_formats |= WPL_FORMAT_NMEA_GENERIC;
break;
case 'G':
p_misc_config->waypoint_formats |= WPT_FORMAT_GARMIN;
p_misc_config->waypoint_formats |= WPL_FORMAT_GARMIN;
break;
case 'M':
p_misc_config->waypoint_formats |= WPT_FORMAT_MAGELLAN;
p_misc_config->waypoint_formats |= WPL_FORMAT_MAGELLAN;
break;
case 'K':
p_misc_config->waypoint_formats |= WPT_FORMAT_KENWOOD;
p_misc_config->waypoint_formats |= WPL_FORMAT_KENWOOD;
break;
case 'A':
p_misc_config->waypoint_formats |= WPT_FORMAT_AIS;
p_misc_config->waypoint_formats |= WPL_FORMAT_AIS;
break;
case ' ':
case ',':
@ -4866,7 +5018,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Old style 'BEACON' has been replaced with new commands.\n", line);
dw_printf ("Use PBEACON, OBEACON, or CBEACON instead.\n");
dw_printf ("Use PBEACON, OBEACON, TBEACON, or CBEACON instead.\n");
}
@ -4881,6 +5033,9 @@ void config_init (char *fname, struct audio_s *p_audio_config,
* New style with keywords for options.
*/
// TODO: maybe add proportional pathing so multiple beacon timing does not need to be manually constructed?
// http://www.aprs.org/newN/ProportionalPathing.txt
else if (strcasecmp(t, "PBEACON") == 0 ||
strcasecmp(t, "OBEACON") == 0 ||
strcasecmp(t, "TBEACON") == 0 ||
@ -5140,7 +5295,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/*
* V20 address [ address ... ] - Stations known to support only AX.25 v2.0.
* When connecting to these, skip SABME and go right to SABM.
* Possible to have multiple and they are cummulative.
* Possible to have multiple and they are cumulative.
*/
else if (strcasecmp(t, "V20") == 0) {
@ -5174,9 +5329,9 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/*
* NOXID address [ address ... ] - Stations known not to understand XID.
* After connecting to these (with v2.2 obviously), don't try using XID commmand.
* After connecting to these (with v2.2 obviously), don't try using XID command.
* AX.25 for Linux is the one known case so far.
* Possible to have multiple and they are cummulative.
* Possible to have multiple and they are cumulative.
*/
else if (strcasecmp(t, "NOXID") == 0) {
@ -5306,7 +5461,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
/* When IGate is enabled, all radio channels must have a callsign associated. */
if (strlen(p_igate_config->t2_login) > 0 &&
(p_audio_config->achan[i].medium == MEDIUM_RADIO || p_audio_config->achan[i].medium == MEDIUM_NETTNC)) {
(p_audio_config->chan_medium[i] == MEDIUM_RADIO || p_audio_config->chan_medium[i] == MEDIUM_NETTNC)) {
if (strcmp(p_audio_config->achan[i].mycall, "NOCALL") == 0 || strcmp(p_audio_config->achan[i].mycall, "N0CALL") == 0) {
text_color_set(DW_COLOR_ERROR);
@ -5332,9 +5487,9 @@ void config_init (char *fname, struct audio_s *p_audio_config,
if (strlen(p_igate_config->t2_login) > 0) {
for (j=0; j<MAX_CHANS; j++) {
if (p_audio_config->achan[j].medium == MEDIUM_RADIO || p_audio_config->achan[j].medium == MEDIUM_NETTNC) {
if (p_audio_config->chan_medium[j] == MEDIUM_RADIO || p_audio_config->chan_medium[j] == MEDIUM_NETTNC) {
if (p_digi_config->filter_str[MAX_CHANS][j] == NULL) {
p_digi_config->filter_str[MAX_CHANS][j] = strdup("i/60");
p_digi_config->filter_str[MAX_CHANS][j] = strdup("i/180");
}
}
}
@ -5354,6 +5509,10 @@ void config_init (char *fname, struct audio_s *p_audio_config,
* Returns 1 for success, 0 for serious error.
*/
// FIXME: provide error messages when non applicable option is used for particular beacon type.
// e.g. IBEACON DELAY=1 EVERY=1 SENDTO=IG OVERLAY=R SYMBOL="igate" LAT=37^44.46N LONG=122^27.19W COMMENT="N1KOL-1 IGATE"
// Just ignores overlay, symbol, lat, long, and comment.
static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_s *p_audio_config)
{
char *t;
@ -5388,7 +5547,7 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
while ((t = split(NULL,0)) != NULL) {
char keyword[20];
char value[200];
char value[1000];
char *e;
char *p;
@ -5403,6 +5562,44 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
strlcpy (keyword, t, sizeof(keyword));
strlcpy (value, e+1, sizeof(value));
// QUICK TEMP EXPERIMENT, maybe permanent new feature.
// Recognize \xnn as hexadecimal value. Handy for UTF-8 in comment.
// Maybe recognize the <0xnn> form that we print.
//
// # Convert between languages here: https://translate.google.com/ then
// # Convert to UTF-8 bytes here: https://codebeautify.org/utf8-converter
//
// pbeacon delay=0:05 every=0:30 sendto=R0 lat=12.5N long=69.97W comment="\xe3\x82\xa2\xe3\x83\x9e\xe3\x83\x81\xe3\x83\xa5\xe3\x82\xa2\xe7\x84\xa1\xe7\xb7\x9a \xce\xa1\xce\xb1\xce\xb4\xce\xb9\xce\xbf\xce\xb5\xcf\x81\xce\xb1\xcf\x83\xce\xb9\xcf\x84\xce\xb5\xcf\x87\xce\xbd\xce\xb9\xcf\x83\xce\xbc\xcf\x8c\xcf\x82"
char temp[256];
int tlen = 0;
for (char *p = value; *p != '\0'; ) {
if (p[0] == '\\' && p[1] == 'x' && strlen(p) >= 4 && isxdigit(p[2]) && isxdigit(p[3])) {
int n = 0;
for (int i = 2; i < 4; i++) {
n = n * 16;
if (islower(p[i])) {
n += p[i] - 'a' + 10;
}
else if (isupper(p[i])) {
n += p[i] - 'A' + 10;
}
else { // must be digit due to isxdigit test above.
n += p[i] - '0';
}
}
temp[tlen++] = n;
p += 4;
}
else {
temp[tlen++] = *p++;
}
}
temp[tlen] = '\0';
strlcpy (value, temp, sizeof(value));
// end
if (strcasecmp(keyword, "DELAY") == 0) {
b->delay = parse_interval(value,line);
}
@ -5425,7 +5622,8 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
}
else if (value[0] == 'r' || value[0] == 'R') {
int n = atoi(value+1);
if ( n < 0 || n >= MAX_CHANS || p_audio_config->achan[n].medium == MEDIUM_NONE) {
if (( n < 0 || n >= MAX_CHANS || p_audio_config->chan_medium[n] == MEDIUM_NONE)
&& p_audio_config->chan_medium[n] != MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Simulated receive on channel %d is not valid.\n", line, n);
continue;
@ -5435,7 +5633,8 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
}
else if (value[0] == 't' || value[0] == 'T' || value[0] == 'x' || value[0] == 'X') {
int n = atoi(value+1);
if ( n < 0 || n >= MAX_CHANS || p_audio_config->achan[n].medium == MEDIUM_NONE) {
if (( n < 0 || n >= MAX_CHANS || p_audio_config->chan_medium[n] == MEDIUM_NONE)
&& p_audio_config->chan_medium[n] != MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Send to channel %d is not valid.\n", line, n);
continue;
@ -5446,7 +5645,8 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
}
else {
int n = atoi(value);
if ( n < 0 || n >= MAX_CHANS || p_audio_config->achan[n].medium == MEDIUM_NONE) {
if (( n < 0 || n >= MAX_CHANS || p_audio_config->chan_medium[n] == MEDIUM_NONE)
&& p_audio_config->chan_medium[n] != MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Send to channel %d is not valid.\n", line, n);
continue;
@ -5526,7 +5726,29 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
}
}
else if (strcasecmp(keyword, "ALT") == 0 || strcasecmp(keyword, "ALTITUDE") == 0) {
b->alt_m = atof(value);
char *unit = strpbrk(value, "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
if (unit != NULL) {
float meters = 0;
for (int j=0; j<NUM_UNITS && meters == 0; j++) {
if (strcasecmp(units[j].name, unit) == 0) {
meters = units[j].meters;
}
}
if (meters == 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Unrecognized unit '%s' for altitude. Using meter.\n", line, unit);
dw_printf ("Try using singular form. e.g. ft or foot rather than feet.\n");
b->alt_m = atof(value);
}
else {
// valid unit
b->alt_m = atof(value) * meters;
}
} else {
// no unit specified
b->alt_m = atof(value);
}
}
else if (strcasecmp(keyword, "ZONE") == 0) {
strlcpy(zone, value, sizeof(zone));
@ -5553,8 +5775,9 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
else if (strcasecmp(keyword, "POWER") == 0) {
b->power = atoi(value);
}
else if (strcasecmp(keyword, "HEIGHT") == 0) {
else if (strcasecmp(keyword, "HEIGHT") == 0) { // This is in feet.
b->height = atoi(value);
// TODO: ability to add units suffix, e.g. 10m
}
else if (strcasecmp(keyword, "GAIN") == 0) {
b->gain = atoi(value);
@ -5602,7 +5825,7 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
}
/*
* Convert UTM coordintes to lat / long.
* Convert UTM coordinates to lat / long.
*/
if (strlen(zone) > 0 || easting != G_UNKNOWN || northing != G_UNKNOWN) {
@ -5637,6 +5860,10 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
/*
* Process symbol now that we have any later overlay.
*
* FIXME: Someone who used this was surprised to end up with Solar Powser (S-).
* overlay=S symbol="/-"
* We should complain if overlay used with symtab other than \.
*/
if (strlen(temp_symbol) > 0) {
@ -5669,19 +5896,32 @@ static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_
if (b->sendto_type == SENDTO_XMIT) {
if ( b->sendto_chan < 0 || b->sendto_chan >= MAX_CHANS || p_audio_config->achan[b->sendto_chan].medium == MEDIUM_NONE) {
if (( b->sendto_chan < 0 || b->sendto_chan >= MAX_CHANS || p_audio_config->chan_medium[b->sendto_chan] == MEDIUM_NONE)
&& p_audio_config->chan_medium[b->sendto_chan] != MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Send to channel %d is not valid.\n", line, b->sendto_chan);
return (0);
}
if ( strcmp(p_audio_config->achan[b->sendto_chan].mycall, "") == 0 ||
strcmp(p_audio_config->achan[b->sendto_chan].mycall, "NOCALL") == 0 ||
strcmp(p_audio_config->achan[b->sendto_chan].mycall, "N0CALL") == 0 ) {
if (p_audio_config->chan_medium[b->sendto_chan] == MEDIUM_IGATE) { // Prevent subscript out of bounds.
// Will be using call from chan 0 later.
if ( strcmp(p_audio_config->achan[0].mycall, "") == 0 ||
strcmp(p_audio_config->achan[0].mycall, "NOCALL") == 0 ||
strcmp(p_audio_config->achan[0].mycall, "N0CALL") == 0 ) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: MYCALL must be set for channel %d before beaconing is allowed.\n", b->sendto_chan);
return (0);
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: MYCALL must be set for channel %d before beaconing is allowed.\n", 0);
return (0);
}
} else {
if ( strcmp(p_audio_config->achan[b->sendto_chan].mycall, "") == 0 ||
strcmp(p_audio_config->achan[b->sendto_chan].mycall, "NOCALL") == 0 ||
strcmp(p_audio_config->achan[b->sendto_chan].mycall, "N0CALL") == 0 ) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: MYCALL must be set for channel %d before beaconing is allowed.\n", b->sendto_chan);
return (0);
}
}
}

View File

@ -76,7 +76,8 @@ struct misc_config_s {
char gpsnmea_port[20]; /* Serial port name for reading NMEA sentences from GPS. */
/* e.g. COM22, /dev/ttyACM0 */
/* Currently no option for setting non-standard speed. */
int gpsnmea_speed; /* Speed for above, baud, default 4800. */
char gpsd_host[20]; /* Host for gpsd server. */
/* e.g. localhost, 192.168.1.2 */
@ -97,11 +98,11 @@ struct misc_config_s {
int waypoint_formats; /* Which sentence formats should be generated? */
#define WPT_FORMAT_NMEA_GENERIC 0x01 /* N $GPWPT */
#define WPT_FORMAT_GARMIN 0x02 /* G $PGRMW */
#define WPT_FORMAT_MAGELLAN 0x04 /* M $PMGNWPL */
#define WPT_FORMAT_KENWOOD 0x08 /* K $PKWDWPL */
#define WPT_FORMAT_AIS 0x10 /* A !AIVDM */
#define WPL_FORMAT_NMEA_GENERIC 0x01 /* N $GPWPL */
#define WPL_FORMAT_GARMIN 0x02 /* G $PGRMW */
#define WPL_FORMAT_MAGELLAN 0x04 /* M $PMGNWPL */
#define WPL_FORMAT_KENWOOD 0x08 /* K $PKWDWPL */
#define WPL_FORMAT_AIS 0x10 /* A !AIVDM */
int log_daily_names; /* True to generate new log file each day. */
@ -213,7 +214,7 @@ struct misc_config_s {
char symbol; /* Symbol code. */
float power; /* For PHG. */
float height;
float height; /* HAAT in feet */
float gain; /* Original protocol spec was unclear. */
/* Addendum 1.1 clarifies it is dBi not dBd. */

File diff suppressed because it is too large Load Diff

View File

@ -24,11 +24,12 @@ typedef struct decode_aprs_s {
int g_quiet; /* Suppress error messages when decoding. */
char g_src[AX25_MAX_ADDR_LEN];
char g_src[AX25_MAX_ADDR_LEN]; // In the case of a packet encapsulated by a 3rd party
// header, this is the encapsulated source.
char g_msg_type[60]; /* APRS data type. Telemetry descriptions get pretty long. */
/* Putting msg in the name was a poor choice because */
/* "message" has a specific meaning. Rename it someday. */
char g_dest[AX25_MAX_ADDR_LEN];
char g_data_type_desc[100]; /* APRS data type description. Telemetry descriptions get pretty long. */
char g_symbol_table; /* The Symbol Table Identifier character selects one */
/* of the two Symbol Tables, or it may be used as */
@ -66,10 +67,30 @@ typedef struct decode_aprs_s {
/* Also for Directed Station Query which is a */
/* special case of message. */
// This is so pfilter.c:filt_t does not need to duplicate the same work.
int g_has_thirdparty_header;
enum packet_type_e {
packet_type_none=0,
packet_type_position,
packet_type_weather,
packet_type_object,
packet_type_item,
packet_type_message,
packet_type_query,
packet_type_capabilities,
packet_type_status,
packet_type_telemetry,
packet_type_userdefined,
packet_type_nws
} g_packet_type;
enum message_subtype_e { message_subtype_invalid = 0,
message_subtype_message,
message_subtype_ack,
message_subtype_rej,
message_subtype_bulletin,
message_subtype_nws,
message_subtype_telem_parm,
message_subtype_telem_unit,
message_subtype_telem_eqns,
@ -77,7 +98,9 @@ typedef struct decode_aprs_s {
message_subtype_directed_query
} g_message_subtype; /* Various cases of the overloaded "message." */
char g_message_number[8]; /* Message number. Should be 1 - 5 characters if used. */
char g_message_number[12]; /* Message number. Should be 1 - 5 alphanumeric characters if used. */
/* Addendum 1.1 has new format {mm} or {mm}aa with only two */
/* characters for message number and an ack riding piggyback. */
float g_speed_mph; /* Speed in MPH. */
/* The APRS transmission uses knots so watch out for */
@ -88,8 +111,9 @@ typedef struct decode_aprs_s {
int g_power; /* Transmitter power in watts. */
int g_height; /* Antenna height above average terrain, feet. */
// TODO: rename to g_height_ft
int g_gain; /* Antenna gain in dB. */
int g_gain; /* Antenna gain in dBi. */
char g_directivity[12]; /* Direction of max signal strength */
@ -97,7 +121,7 @@ typedef struct decode_aprs_s {
float g_altitude_ft; /* Feet above median sea level. */
/* I used feet here because the APRS specification */
/* has units of feet for alititude. Meters would be */
/* has units of feet for altitude. Meters would be */
/* more natural to the other 96% of the world. */
char g_mfr[80]; /* Manufacturer or application. */
@ -140,9 +164,9 @@ typedef struct decode_aprs_s {
extern void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet);
extern void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet, char *third_party_src);
extern void decode_aprs_print (decode_aprs_t *A);
#endif
#endif

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2019 John Langner, WB2OSZ
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2019, 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -60,10 +60,6 @@
static struct audio_s *save_audio_config_p;
// TODO: temp experiment.
static int zerostuff = 1; // temp experiment.
// Current state of all the decoders.
@ -106,7 +102,7 @@ int demod_init (struct audio_s *pa)
for (chan = 0; chan < MAX_CHANS; chan++) {
if (save_audio_config_p->achan[chan].medium == MEDIUM_RADIO) {
if (save_audio_config_p->chan_medium[chan] == MEDIUM_RADIO) {
char *p;
char just_letters[16];
@ -503,7 +499,7 @@ int demod_init (struct audio_s *pa)
// In versions 1.4 and 1.5, V.26 "Alternative A" was used.
// years later, I discover that the MFJ-2400 used "Alternative B."
// It looks like the other two manufacturers use the same but we
// can't be sure until we find one for compatbility testing.
// can't be sure until we find one for compatibility testing.
// In version 1.6 we add a choice for the user.
// If neither one was explicitly specified, print a message and take
@ -514,8 +510,8 @@ int demod_init (struct audio_s *pa)
text_color_set(DW_COLOR_ERROR);
dw_printf ("Two incompatible versions of 2400 bps QPSK are now available.\n");
dw_printf ("For compatbility with direwolf <= 1.5, use 'V26A' modem option in config file.\n");
dw_printf ("For compatbility MFJ-2400 use 'V26B' modem option in config file.\n");
dw_printf ("For compatibility with direwolf <= 1.5, use 'V26A' modem option in config file.\n");
dw_printf ("For compatibility MFJ-2400 use 'V26B' modem option in config file.\n");
dw_printf ("Command line options -j and -J can be used for channel 0.\n");
dw_printf ("For more information, read the Dire Wolf User Guide and\n");
dw_printf ("2400-4800-PSK-for-APRS-Packet-Radio.pdf.\n");
@ -676,12 +672,6 @@ int demod_init (struct audio_s *pa)
strlcpy (save_audio_config_p->achan[chan].profiles, "+", sizeof(save_audio_config_p->achan[chan].profiles));
}
#ifdef TUNE_ZEROSTUFF
zerostuff = TUNE_ZEROSTUFF;
#endif
/*
* We need a minimum number of audio samples per bit time for good performance.
* Easier to check here because demod_9600_init might have an adjusted sample rate.
@ -696,26 +686,32 @@ int demod_init (struct audio_s *pa)
if (save_audio_config_p->achan[chan].upsample == 0) {
if (ratio < 5) {
if (ratio < 4) {
// example: 44100 / 9600 is 4.59
// Big improvement with x2.
// x4 seems to work the best.
// The other parameters are not as touchy.
// Might reduce on ARM if it takes too much CPU power.
// This is extreme.
// No one should be using a sample rate this low but
// amazingly a recording with 22050 rate can be decoded.
// 3 and 4 are the same. Need more tests.
save_audio_config_p->achan[chan].upsample = 4;
}
else if (ratio < 5) {
// example: 44100 / 9600 is 4.59
// 3 is slightly better than 2 or 4.
save_audio_config_p->achan[chan].upsample = 3;
}
else if (ratio < 10) {
// 48000 / 9600 is 5.00
// Need more reasearch. Treat like above for now.
// example: 48000 / 9600 = 5
// 3 is slightly better than 2 or 4.
save_audio_config_p->achan[chan].upsample = 4;
save_audio_config_p->achan[chan].upsample = 3;
}
else if (ratio < 15) {
// ...
// ... guessing
save_audio_config_p->achan[chan].upsample = 2;
}
@ -786,7 +782,8 @@ int demod_init (struct audio_s *pa)
}
demod_9600_init (save_audio_config_p->achan[chan].modem_type,
save_audio_config_p->achan[chan].upsample * save_audio_config_p->adev[ACHAN2ADEV(chan)].samples_per_sec,
save_audio_config_p->adev[ACHAN2ADEV(chan)].samples_per_sec,
save_audio_config_p->achan[chan].upsample,
save_audio_config_p->achan[chan].baud, D);
if (strchr(save_audio_config_p->achan[chan].profiles, '+') != NULL) {
@ -807,10 +804,23 @@ int demod_init (struct audio_s *pa)
} /* switch on modulation type. */
} /* if channel number is valid */
} /* if channel medium is radio */
// FIXME dw_printf ("-------- end of loop for chn %d \n", chan);
} /* for chan ... */
// Now the virtual channels. FIXME: could be single loop.
for (chan = MAX_CHANS; chan < MAX_TOTAL_CHANS; chan++) {
// FIXME dw_printf ("-------- virtual channel loop %d \n", chan);
if (chan == save_audio_config_p->igate_vchannel) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("Channel %d: IGate virtual channel.\n", chan);
}
}
return (0);
@ -822,7 +832,7 @@ int demod_init (struct audio_s *pa)
*
* Name: demod_get_sample
*
* Purpose: Get one audio sample fromt the specified sound input source.
* Purpose: Get one audio sample from the specified sound input source.
*
* Inputs: a - Index for audio device. 0 = first.
*
@ -832,7 +842,7 @@ int demod_init (struct audio_s *pa)
* Global In: save_audio_config_p->adev[ACHAN2ADEV(chan)].bits_per_sample - So we know whether to
* read 1 or 2 bytes from audio stream.
*
* Description: Grab 1 or two btyes depending on data source.
* Description: Grab 1 or two bytes depending on data source.
*
* When processing stereo, the caller will call this
* at twice the normal rate to obtain alternating left
@ -842,17 +852,15 @@ int demod_init (struct audio_s *pa)
#define FSK_READ_ERR (256*256)
__attribute__((hot))
int demod_get_sample (int a)
{
int x1, x2;
signed short sam; /* short to force sign extention. */
signed short sam; /* short to force sign extension. */
assert (save_audio_config_p->adev[a].bits_per_sample == 8 || save_audio_config_p->adev[a].bits_per_sample == 16);
if (save_audio_config_p->adev[a].bits_per_sample == 8) {
x1 = audio_get(a);
@ -919,12 +927,27 @@ int demod_get_sample (int a)
*
*--------------------------------------------------------------------*/
static volatile int mute_input[MAX_CHANS];
// New in 1.7.
// A few people have a really bad audio cross talk situation where they receive their own transmissions.
// It usually doesn't cause a problem but it is confusing to look at.
// "half duplex" setting applied only to the transmit logic. i.e. wait for clear channel before sending.
// Receiving was still active.
// I think the simplest solution is to mute/unmute the audio input at this point if not full duplex.
// This is called from ptt_set for half duplex.
void demod_mute_input (int chan, int mute_during_xmit)
{
assert (chan >= 0 && chan < MAX_CHANS);
mute_input[chan] = mute_during_xmit;
}
__attribute__((hot))
void demod_process_sample (int chan, int subchan, int sam)
{
float fsam;
int k;
//int k;
struct demodulator_state_s *D;
@ -932,6 +955,10 @@ void demod_process_sample (int chan, int subchan, int sam)
assert (chan >= 0 && chan < MAX_CHANS);
assert (subchan >= 0 && subchan < MAX_SUBCHANS);
if (mute_input[chan]) {
sam = 0;
};
D = &demodulator_state[chan][subchan];
@ -1016,47 +1043,7 @@ void demod_process_sample (int chan, int subchan, int sam)
case MODEM_AIS:
default:
if (zerostuff) {
/* Literature says this is better if followed */
/* by appropriate low pass filter. */
/* So far, both are same in tests with different */
/* optimal low pass filter parameters. */
for (k=1; k<save_audio_config_p->achan[chan].upsample; k++) {
demod_9600_process_sample (chan, 0, D);
}
demod_9600_process_sample (chan, sam * save_audio_config_p->achan[chan].upsample, D);
}
else {
/* Linear interpolation. */
static int prev_sam;
switch (save_audio_config_p->achan[chan].upsample) {
case 1:
demod_9600_process_sample (chan, sam, D);
break;
case 2:
demod_9600_process_sample (chan, (prev_sam + sam) / 2, D);
demod_9600_process_sample (chan, sam, D);
break;
case 3:
demod_9600_process_sample (chan, (2 * prev_sam + sam) / 3, D);
demod_9600_process_sample (chan, (prev_sam + 2 * sam) / 3, D);
demod_9600_process_sample (chan, sam, D);
break;
case 4:
demod_9600_process_sample (chan, (3 * prev_sam + sam) / 4, D);
demod_9600_process_sample (chan, (prev_sam + sam) / 2, D);
demod_9600_process_sample (chan, (prev_sam + 3 * sam) / 4, D);
demod_9600_process_sample (chan, sam, D);
break;
default:
assert (0);
break;
}
prev_sam = sam;
}
demod_9600_process_sample (chan, sam, save_audio_config_p->achan[chan].upsample, D);
break;
} /* switch modem_type */

View File

@ -8,10 +8,13 @@
int demod_init (struct audio_s *pa);
void demod_mute_input (int chan, int mute);
int demod_get_sample (int a);
void demod_process_sample (int chan, int subchan, int sam);
void demod_print_agc (int chan, int subchan);
alevel_t demod_get_audio_level (int chan, int subchan);
alevel_t demod_get_audio_level (int chan, int subchan);

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2012, 2013, 2015, 2019 John Langner, WB2OSZ
// Copyright (C) 2011, 2012, 2013, 2015, 2019, 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -25,7 +25,8 @@
*
* Module: demod_9600.c
*
* Purpose: Demodulator for scrambled baseband encoding.
* Purpose: Demodulator for baseband signal.
* This is used for AX.25 (with scrambling) and IL2P without.
*
* Input: Audio samples from either a file or the "sound card."
*
@ -45,12 +46,14 @@
#include <ctype.h>
// Fine tuning for different demodulator types.
// Don't remove this section. It is here for a reason.
#define DCD_THRESH_ON 32 // Hysteresis: Can miss 0 out of 32 for detecting lock.
// This is best for actual on-the-air signals.
// Still too many brief false matches.
#define DCD_THRESH_OFF 8 // Might want a little more fine tuning.
#define DCD_GOOD_WIDTH 1024 // No more than 1024!!!
#define DCD_THRESH_ON 32 // Hysteresis: Can miss 0 out of 32 for detecting lock.
// This is best for actual on-the-air signals.
// Still too many brief false matches.
#define DCD_THRESH_OFF 8 // Might want a little more fine tuning.
#define DCD_GOOD_WIDTH 1024 // No more than 1024!!!
#include "fsk_demod_state.h" // Values above override defaults.
#include "tune.h"
@ -125,9 +128,12 @@ static inline float agc (float in, float fast_attack, float slow_decay, float *p
*
* Inputs: modem_type - Determines whether scrambling is used.
*
* samples_per_sec - Number of samples per second.
* Might be upsampled in hopes of
* reducing the PLL jitter.
* samples_per_sec - Number of samples per second for audio.
*
* upsample - Factor to upsample the incoming stream.
* After a lot of experimentation, I discovered that
* it works better if the data is upsampled.
* This reduces the jitter for PLL synchronization.
*
* baud - Data rate in bits per second.
*
@ -137,10 +143,13 @@ static inline float agc (float in, float fast_attack, float slow_decay, float *p
*
*----------------------------------------------------------------*/
void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, struct demodulator_state_s *D)
void demod_9600_init (enum modem_t modem_type, int original_sample_rate, int upsample, int baud, struct demodulator_state_s *D)
{
float fc;
int j;
if (upsample < 1) upsample = 1;
if (upsample > 4) upsample = 4;
memset (D, 0, sizeof(struct demodulator_state_s));
D->modem_type = modem_type;
@ -155,12 +164,13 @@ void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, st
// case 'L': // upsample x4 with filtering.
D->lp_filter_len_bits = 1.0;
D->lp_filter_len_bits = 1.0; // -U4 = 61 4.59 samples/symbol
// Works best with odd number in some tests. Even is better in others.
//D->lp_filter_size = ((int) (0.5f * ( D->lp_filter_len_bits * (float)samples_per_sec / (float)baud ))) * 2 + 1;
//D->lp_filter_size = ((int) (0.5f * ( D->lp_filter_len_bits * (float)original_sample_rate / (float)baud ))) * 2 + 1;
D->lp_filter_size = (int) (( D->lp_filter_len_bits * (float)samples_per_sec / baud) + 0.5f);
// Just round to nearest integer.
D->lp_filter_size = (int) (( D->lp_filter_len_bits * (float)original_sample_rate / baud) + 0.5f);
D->lp_window = BP_WINDOW_COSINE;
@ -185,8 +195,11 @@ void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, st
dw_printf ("samples per bit = %.1f\n", (double)samples_per_sec / baud);
#endif
// PLL needs to use the upsampled rate.
D->pll_step_per_sample =
(int) round(TICKS_PER_PLL_CYCLE * (double) baud / (double)samples_per_sec);
(int) round(TICKS_PER_PLL_CYCLE * (double) baud / (double)(original_sample_rate * upsample));
#ifdef TUNE_LP_WINDOW
@ -217,13 +230,87 @@ void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, st
D->pll_searching_inertia = TUNE_PLL_SEARCHING;
#endif
fc = (float)baud * D->lpf_baud / (float)samples_per_sec;
// Initial filter (before scattering) is based on upsampled rate.
fc = (float)baud * D->lpf_baud / (float)(original_sample_rate * upsample);
//dw_printf ("demod_9600_init: call gen_lowpass(fc=%.2f, , size=%d, )\n", fc, D->lp_filter_size);
gen_lowpass (fc, D->lp_filter, D->lp_filter_size, D->lp_window);
gen_lowpass (fc, D->u.bb.lp_filter, D->lp_filter_size * upsample, D->lp_window);
// New in 1.7 -
// Use a polyphase filter to reduce the CPU load.
// Originally I used zero stuffing to upsample.
// Here is the general idea.
//
// Suppose the input samples are 1 2 3 4 5 6 7 8 9 ...
// Filter coefficients are a b c d e f g h i ...
//
// With original sampling rate, the filtering would involve multiplying and adding:
//
// 1a 2b 3c 4d 5e 6f ...
//
// When upsampling by 3, each of these would need to be evaluated
// for each audio sample:
//
// 1a 0b 0c 2d 0e 0f 3g 0h 0i ...
// 0a 1b 0c 0d 2e 0f 0g 3h 0i ...
// 0a 0b 1c 0d 0e 2f 0g 0h 3i ...
//
// 2/3 of the multiplies are always by a stuffed zero.
// We can do this more efficiently by removing them.
//
// 1a 2d 3g ...
// 1b 2e 3h ...
// 1c 2f 3i ...
//
// We scatter the original filter across multiple shorter filters.
// Each input sample cycles around them to produce the upsampled rate.
//
// a d g ...
// b e h ...
// c f i ...
//
// There are countless sources of information DSP but this one is unique
// in that it is a college course that mentions APRS.
// https://www2.eecs.berkeley.edu/Courses/EE123
//
// Was the effort worthwhile? Times on an RPi 3.
//
// command: atest -B9600 ~/walkabout9600[abc]-compressed*.wav
//
// These are 3 recordings of a portable system being carried out of
// range and back in again. It is a real world test for weak signals.
//
// options num decoded seconds x realtime
// 1.6 1.7 1.6 1.7 1.6 1.7
// --- --- --- --- --- ---
// -P- 171 172 23.928 17.967 14.9 19.9
// -P+ 180 180 54.688 48.772 6.5 7.3
// -P- -F1 177 178 32.686 26.517 10.9 13.5
//
// So, it turns out that -P+ doesn't have a dramatic improvement, only
// around 4%, for drastically increased CPU requirements.
// Maybe we should turn that off by default, especially for ARM.
//
int k = 0;
for (int i = 0; i < D->lp_filter_size; i++) {
D->u.bb.lp_polyphase_1[i] = D->u.bb.lp_filter[k++];
if (upsample >= 2) {
D->u.bb.lp_polyphase_2[i] = D->u.bb.lp_filter[k++];
if (upsample >= 3) {
D->u.bb.lp_polyphase_3[i] = D->u.bb.lp_filter[k++];
if (upsample >= 4) {
D->u.bb.lp_polyphase_4[i] = D->u.bb.lp_filter[k++];
}
}
}
}
/* Version 1.2: Experiment with different slicing levels. */
// Really didn't help that much because we should have a symmetrical signal.
for (j = 0; j < MAX_SUBCHANS; j++) {
slice_point[j] = 0.02f * (j - 0.5f * (MAX_SUBCHANS-1));
@ -259,7 +346,7 @@ void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, st
* been distorted by going thru voice transceivers not
* intended to pass this sort of "audio" signal.
*
* Data is "scrambled" to reduce the amount of DC bias.
* For G3RUH mode, data is "scrambled" to reduce the amount of DC bias.
* The data stream must be unscrambled at the receiving end.
*
* We also have a digital phase locked loop (PLL)
@ -276,6 +363,9 @@ void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, st
* of the function to be called for each bit recovered
* from the demodulator. For now, it's simply hard-coded.
*
* After experimentation, I found that this works better if
* the original signal is upsampled by 2x or even 4x.
*
* References: 9600 Baud Packet Radio Modem Design
* http://www.amsat.org/amsat/articles/g3ruh/109.html
*
@ -290,63 +380,57 @@ void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, st
inline static void nudge_pll (int chan, int subchan, int slice, float demod_out, struct demodulator_state_s *D);
__attribute__((hot))
void demod_9600_process_sample (int chan, int sam, struct demodulator_state_s *D)
{
static void process_filtered_sample (int chan, float fsam, struct demodulator_state_s *D);
__attribute__((hot))
void demod_9600_process_sample (int chan, int sam, int upsample, struct demodulator_state_s *D)
{
float fsam;
float amp;
float demod_out;
#if DEBUG4
static FILE *demod_log_fp = NULL;
static int log_file_seq = 0; /* Part of log file name */
#endif
int subchan = 0;
int demod_data; /* Still scrambled. */
assert (chan >= 0 && chan < MAX_CHANS);
assert (subchan >= 0 && subchan < MAX_SUBCHANS);
/*
* Filters use last 'filter_size' samples.
*
* First push the older samples down.
*
* Finally, put the most recent at the beginning.
*
* Future project? Rather than shifting the samples,
* it might be faster to add another variable to keep
* track of the most recent sample and change the
* indexing in the later loops that multipy and add.
*/
/* Scale to nice number for convenience. */
/* Consistent with the AFSK demodulator, we'd like to use */
/* only half of the dynamic range to have some headroom. */
/* i.e. input range +-16k becomes +-1 here and is */
/* displayed in the heard line as audio level 100. */
fsam = sam / 16384.0;
fsam = (float)sam / 16384.0f;
#if defined(TUNE_ZEROSTUFF) && TUNE_ZEROSTUFF == 0
// experiment - no filtering.
// Low pass filter
push_sample (fsam, D->u.bb.audio_in, D->lp_filter_size);
amp = fsam;
fsam = convolve (D->u.bb.audio_in, D->u.bb.lp_polyphase_1, D->lp_filter_size);
process_filtered_sample (chan, fsam, D);
if (upsample >= 2) {
fsam = convolve (D->u.bb.audio_in, D->u.bb.lp_polyphase_2, D->lp_filter_size);
process_filtered_sample (chan, fsam, D);
if (upsample >= 3) {
fsam = convolve (D->u.bb.audio_in, D->u.bb.lp_polyphase_3, D->lp_filter_size);
process_filtered_sample (chan, fsam, D);
if (upsample >= 4) {
fsam = convolve (D->u.bb.audio_in, D->u.bb.lp_polyphase_4, D->lp_filter_size);
process_filtered_sample (chan, fsam, D);
}
}
}
}
#else
push_sample (fsam, D->raw_cb, D->lp_filter_size);
/*
* Low pass filter to reduce noise yet pass the data.
*/
__attribute__((hot))
static void process_filtered_sample (int chan, float fsam, struct demodulator_state_s *D)
{
amp = convolve (D->raw_cb, D->lp_filter, D->lp_filter_size);
#endif
int subchan = 0;
/*
* Version 1.2: Capture the post-filtering amplitude for display.
@ -359,18 +443,18 @@ void demod_9600_process_sample (int chan, int sam, struct demodulator_state_s *D
// TODO: probably no need for this. Just use D->m_peak, D->m_valley
if (amp >= D->alevel_mark_peak) {
D->alevel_mark_peak = amp * D->quick_attack + D->alevel_mark_peak * (1.0f - D->quick_attack);
if (fsam >= D->alevel_mark_peak) {
D->alevel_mark_peak = fsam * D->quick_attack + D->alevel_mark_peak * (1.0f - D->quick_attack);
}
else {
D->alevel_mark_peak = amp * D->sluggish_decay + D->alevel_mark_peak * (1.0f - D->sluggish_decay);
D->alevel_mark_peak = fsam * D->sluggish_decay + D->alevel_mark_peak * (1.0f - D->sluggish_decay);
}
if (amp <= D->alevel_space_peak) {
D->alevel_space_peak = amp * D->quick_attack + D->alevel_space_peak * (1.0f - D->quick_attack);
if (fsam <= D->alevel_space_peak) {
D->alevel_space_peak = fsam * D->quick_attack + D->alevel_space_peak * (1.0f - D->quick_attack);
}
else {
D->alevel_space_peak = amp * D->sluggish_decay + D->alevel_space_peak * (1.0f - D->sluggish_decay);
D->alevel_space_peak = fsam * D->sluggish_decay + D->alevel_space_peak * (1.0f - D->sluggish_decay);
}
/*
@ -381,12 +465,14 @@ void demod_9600_process_sample (int chan, int sam, struct demodulator_state_s *D
* This works by looking at the minimum and maximum signal peaks
* and scaling the results to be roughly in the -1.0 to +1.0 range.
*/
float demod_out;
int demod_data; /* Still scrambled. */
demod_out = agc (amp, D->agc_fast_attack, D->agc_slow_decay, &(D->m_peak), &(D->m_valley));
demod_out = agc (fsam, D->agc_fast_attack, D->agc_slow_decay, &(D->m_peak), &(D->m_valley));
// TODO: There is potential for multiple decoders with one filter.
//dw_printf ("peak=%.2f valley=%.2f amp=%.2f norm=%.2f\n", D->m_peak, D->m_valley, amp, norm);
//dw_printf ("peak=%.2f valley=%.2f fsam=%.2f norm=%.2f\n", D->m_peak, D->m_valley, fsam, norm);
if (D->num_slicers <= 1) {
@ -435,7 +521,7 @@ void demod_9600_process_sample (int chan, int sam, struct demodulator_state_s *D
fprintf (demod_log_fp, "%.3f, %.3f, %.3f, %.3f, %.3f, %d, %.2f\n",
fsam + 6,
amp + 4,
fsam + 4,
D->m_peak + 4,
D->m_valley + 4,
demod_out + 2,
@ -478,7 +564,7 @@ void demod_9600_process_sample (int chan, int sam, struct demodulator_state_s *D
*
* Returns: None
*
* Descripton: A PLL is used to sample near the centers of the data bits.
* Description: A PLL is used to sample near the centers of the data bits.
*
* D->data_clock_pll is a SIGNED 32 bit variable.
* When it overflows from a large positive value to a negative value, we

View File

@ -6,9 +6,9 @@
#include "fsk_demod_state.h"
void demod_9600_init (enum modem_t modem_type, int samples_per_sec, int baud, struct demodulator_state_s *D);
void demod_9600_init (enum modem_t modem_type, int original_sample_rate, int upsample, int baud, struct demodulator_state_s *D);
void demod_9600_process_sample (int chan, int sam, struct demodulator_state_s *D);
void demod_9600_process_sample (int chan, int sam, int upsample, struct demodulator_state_s *D);

View File

@ -25,6 +25,8 @@
// #define DEBUG4 1 /* capture AFSK demodulator output to log files */
/* Can be used to make nice plots. */
// #define DEBUG5 1 // Write just demodulated bit stream to file. */
/*------------------------------------------------------------------
*
@ -307,10 +309,6 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
D->lp_window = BP_WINDOW_TRUNCATED;
}
D->agc_fast_attack = 0.820;
D->agc_slow_decay = 0.000214;
D->agc_fast_attack = 0.45;
D->agc_slow_decay = 0.000195;
D->agc_fast_attack = 0.70;
D->agc_slow_decay = 0.000090;
@ -370,10 +368,16 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
// For scaling phase shift into normallized -1 to +1 range for mark and space.
D->u.afsk.normalize_rpsam = 1.0 / (0.5 * abs(mark_freq - space_freq) * 2 * M_PI / samples_per_sec);
// New "B" demodulator does not use AGC but demod.c needs this to derive "quick" and
// "sluggish" values for overall signal amplitude. That probably should be independent
// of these values.
D->agc_fast_attack = 0.70;
D->agc_slow_decay = 0.000090;
D->pll_locked_inertia = 0.74;
D->pll_searching_inertia = 0.50;
D->alevel_mark_peak = -1; // FIXME: disable display
D->alevel_mark_peak = -1; // Disable received signal (m/s) display.
D->alevel_space_peak = -1;
break;
@ -405,7 +409,7 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
* Calculate constants used for timing.
* The audio sample rate must be at least a few times the data rate.
*
* Baud is an integer so we hack in a fine ajustment for EAS.
* Baud is an integer so we hack in a fine adjustment for EAS.
* Probably makes no difference because the DPLL keeps it in sync.
*
* A fraction if a Hz would make no difference for the filters.
@ -429,11 +433,17 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
TUNE("TUNE_PRE_FILTER_TAPS", D->pre_filter_taps, "pre_filter_taps", "%d")
// TODO: Size comes out to 417 for 1200 bps with 48000 sample rate.
// The message is upsetting. Can we handle this better?
if (D->pre_filter_taps > MAX_FILTER_SIZE) {
text_color_set (DW_COLOR_ERROR);
dw_printf ("Calculated pre filter size of %d is too large.\n", D->pre_filter_taps);
dw_printf ("Decrease the audio sample rate or increase the decimation factor or\n");
dw_printf ("recompile the application with MAX_FILTER_SIZE larger than %d.\n", MAX_FILTER_SIZE);
dw_printf ("Warning: Calculated pre filter size of %d is too large.\n", D->pre_filter_taps);
dw_printf ("Decrease the audio sample rate or increase the decimation factor.\n");
dw_printf ("You can use -D2 or -D3, on the command line, to down-sample the audio rate\n");
dw_printf ("before demodulating. This greatly decreases the CPU requirements with little\n");
dw_printf ("impact on the decoding performance. This is useful for a slow ARM processor,\n");
dw_printf ("such as with a Raspberry Pi model 1.\n");
D->pre_filter_taps = (MAX_FILTER_SIZE - 1) | 1;
}
@ -580,7 +590,7 @@ void demod_afsk_init (int samples_per_sec, int baud, int mark_freq,
*
* First, let's take a look at Track 1 of the TNC test CD. Here the receiver
* has a flat response. We find the mark/space strength ratios very from 0.53 to 1.38
* with a median of 0.81. This in in line with expections because most
* with a median of 0.81. This is in line with expectations because most
* transmitters add pre-emphasis to boost the higher audio frequencies.
* Track 2 should more closely resemble what comes out of the speaker on a typical
* transceiver. Here we see a ratio from 1.73 to 3.81 with a median of 2.48.
@ -698,7 +708,7 @@ void demod_afsk_process_sample (int chan, int subchan, int sam, struct demodulat
// Rather than trying to find the best threshold location, use multiple
// slicer thresholds in parallel.
// The best slicing point will vary from packet to packet but should
// remain abount the same or a given packet.
// remain about the same for a given packet.
// We are not performing the AGC step here but still want the envelope
// for caluculating the confidence level (or quality) of the sample.
@ -847,7 +857,7 @@ void demod_afsk_process_sample (int chan, int subchan, int sam, struct demodulat
* If we adjust it too quickly, the clock will have too much jitter.
* If we adjust it too slowly, it will take too long to lock on to a new signal.
*
* Be a little more agressive about adjusting the PLL
* Be a little more aggressive about adjusting the PLL
* phase when searching for a signal. Don't change it as much when
* locked on to a signal.
*
@ -860,6 +870,7 @@ static void nudge_pll (int chan, int subchan, int slice, float demod_out, struct
{
D->slicer[slice].prev_d_c_pll = D->slicer[slice].data_clock_pll;
// Perform the add as unsigned to avoid signed overflow error.
D->slicer[slice].data_clock_pll = (signed)((unsigned)(D->slicer[slice].data_clock_pll) + (unsigned)(D->pll_step_per_sample));
@ -875,7 +886,33 @@ static void nudge_pll (int chan, int subchan, int slice, float demod_out, struct
int quality = fabsf(demod_out) * 100.0f / amplitude;
if (quality > 100) quality = 100;
#if DEBUG5
// Write bit stream to a file.
static FILE *bsfp = NULL;
static int bcount = 0;
if (chan == 0 && subchan == 0 && slice == 0) {
if (bsfp == NULL) {
bsfp = fopen ("bitstream.txt", "w");
}
fprintf (bsfp, "%d", demod_out > 0);
bcount++;
if (bcount % 64 == 0) {
fprintf (bsfp, "\n");
}
}
#endif
#if 1
hdlc_rec_bit (chan, subchan, slice, demod_out > 0, 0, quality);
#else // TODO: new feature to measure data speed error.
// Maybe hdlc_rec_bit could provide indication when frame starts.
hdlc_rec_bit_new (chan, subchan, slice, demod_out > 0, 0, quality,
&(D->slicer[slice].pll_nudge_total), &(D->slicer[slice].pll_symbol_count));
D->slicer[slice].pll_symbol_count++;
#endif
pll_dcd_each_symbol2 (D, chan, subchan, slice);
}
@ -886,12 +923,14 @@ static void nudge_pll (int chan, int subchan, int slice, float demod_out, struct
pll_dcd_signal_transition2 (D, slice, D->slicer[slice].data_clock_pll);
// TODO: signed int before = (signed int)(D->slicer[slice].data_clock_pll); // Treat as signed.
if (D->slicer[slice].data_detect) {
D->slicer[slice].data_clock_pll = (int)(D->slicer[slice].data_clock_pll * D->pll_locked_inertia);
}
else {
D->slicer[slice].data_clock_pll = (int)(D->slicer[slice].data_clock_pll * D->pll_searching_inertia);
}
// TODO: D->slicer[slice].pll_nudge_total += (int64_t)((signed int)(D->slicer[slice].data_clock_pll)) - (int64_t)before;
}
/*

View File

@ -60,7 +60,7 @@
* "bis" and "ter" are from Latin for second and third.
* I used the "ter" version which has phase shifts of 0, 90, 180, and 270 degrees.
*
* There are ealier references to an alternative B which uses other phase shifts offset
* There are earlier references to an alternative B which uses other phase shifts offset
* by another 45 degrees.
*
* After getting QPSK working, it was not much more effort to add V.27 with 8 phases.
@ -781,7 +781,7 @@ static void nudge_pll (int chan, int subchan, int slice, int demod_bits, struct
* If we adjust it too quickly, the clock will have too much jitter.
* If we adjust it too slowly, it will take too long to lock on to a new signal.
*
* Be a little more agressive about adjusting the PLL
* Be a little more aggressive about adjusting the PLL
* phase when searching for a signal.
* Don't change it as much when locked on to a signal.
*/

View File

@ -49,7 +49,8 @@
* Preemptive Digipeating (new in version 0.8)
*
* http://www.aprs.org/aprs12/preemptive-digipeating.txt
*
* I ignored the part about the RR bits.
*
*------------------------------------------------------------------*/
#define DIGIPEATER_C
@ -73,7 +74,7 @@
static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, char *mycall_xmit,
regex_t *uidigi, regex_t *uitrace, int to_chan, enum preempt_e preempt, char *type_filter);
regex_t *uidigi, regex_t *uitrace, int to_chan, enum preempt_e preempt, char *atgp, char *type_filter);
/*
@ -154,8 +155,8 @@ void digipeater (int from_chan, packet_t pp)
// Network TNC is OK for UI frames where we don't care about timing.
if ( from_chan < 0 || from_chan >= MAX_CHANS ||
(save_audio_config_p->achan[from_chan].medium != MEDIUM_RADIO &&
save_audio_config_p->achan[from_chan].medium != MEDIUM_NETTNC)) {
(save_audio_config_p->chan_medium[from_chan] != MEDIUM_RADIO &&
save_audio_config_p->chan_medium[from_chan] != MEDIUM_NETTNC)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("APRS digipeater: Did not expect to receive on invalid channel %d.\n", from_chan);
}
@ -164,7 +165,34 @@ void digipeater (int from_chan, packet_t pp)
/*
* First pass: Look at packets being digipeated to same channel.
*
* We want these to get out quickly.
* We want these to get out quickly, bypassing the usual random wait time.
*
* Some may disagree but I followed what WB4APR had to say about it.
*
* http://www.aprs.org/balloons.html
*
* APRS NETWORK FRATRICIDE: Generally, all APRS digipeaters are supposed to transmit
* immediately and all at the same time. They should NOT wait long enough for each
* one to QRM the channel with the same copy of each packet. NO, APRS digipeaters
* are all supposed to STEP ON EACH OTHER with every packet. This makes sure that
* everyone in range of a digi will hear one and only one copy of each packet.
* and that the packet will digipeat OUTWARD and not backward. The goal is that a
* digipeated packet is cleared out of the local area in ONE packet time and not
* N packet times for every N digipeaters that heard the packet. This means no
* PERSIST times, no DWAIT times and no UIDWAIT times. Notice, this is contrary
* to other packet systems that might want to guarantee delivery (but at the
* expense of throughput). APRS wants to clear the channel quickly to maximize throughput.
*
* http://www.aprs.org/kpc3/kpc3+WIDEn.txt
*
* THIRD: Eliminate the settings that are detrimental to the network.
*
* * UIDWAIT should be OFF. (the default). With it on, your digi is not doing the
* fundamental APRS fratricide that is the primary mechanism for minimizing channel
* loading. All digis that hear the same packet are supposed to DIGI it at the SAME
* time so that all those copies only take up one additional time slot. (but outward
* located digs will hear it without collision (and continue outward propagation)
*
*/
for (to_chan=0; to_chan<MAX_CHANS; to_chan++) {
@ -176,10 +204,11 @@ void digipeater (int from_chan, packet_t pp)
save_audio_config_p->achan[to_chan].mycall,
&save_digi_config_p->alias[from_chan][to_chan], &save_digi_config_p->wide[from_chan][to_chan],
to_chan, save_digi_config_p->preempt[from_chan][to_chan],
save_digi_config_p->atgp[from_chan][to_chan],
save_digi_config_p->filter_str[from_chan][to_chan]);
if (result != NULL) {
dedupe_remember (pp, to_chan);
tq_append (to_chan, TQ_PRIO_0_HI, result);
tq_append (to_chan, TQ_PRIO_0_HI, result); // High priority queue.
digi_count[from_chan][to_chan]++;
}
}
@ -202,10 +231,11 @@ void digipeater (int from_chan, packet_t pp)
save_audio_config_p->achan[to_chan].mycall,
&save_digi_config_p->alias[from_chan][to_chan], &save_digi_config_p->wide[from_chan][to_chan],
to_chan, save_digi_config_p->preempt[from_chan][to_chan],
save_digi_config_p->atgp[from_chan][to_chan],
save_digi_config_p->filter_str[from_chan][to_chan]);
if (result != NULL) {
dedupe_remember (pp, to_chan);
tq_append (to_chan, TQ_PRIO_1_LO, result);
tq_append (to_chan, TQ_PRIO_1_LO, result); // Low priority queue.
digi_count[from_chan][to_chan]++;
}
}
@ -244,6 +274,9 @@ void digipeater (int from_chan, packet_t pp)
*
* preempt - Option for "preemptive" digipeating.
*
* atgp - No tracing if this matches alias prefix.
* Hack added for special needs of ATGP.
*
* filter_str - Filter expression string or NULL.
*
* Returns: Packet object for transmission or NULL.
@ -260,32 +293,9 @@ void digipeater (int from_chan, packet_t pp)
*
*------------------------------------------------------------------------------*/
#define OBSOLETE14 1
#ifndef OBSOLETE14
static char *dest_ssid_path[16] = {
"", /* Use VIA path */
"WIDE1-1",
"WIDE2-2",
"WIDE3-3",
"WIDE4-4",
"WIDE5-5",
"WIDE6-6",
"WIDE7-7",
"WIDE1-1", /* North */
"WIDE1-1", /* South */
"WIDE1-1", /* East */
"WIDE1-1", /* West */
"WIDE2-2", /* North */
"WIDE2-2", /* South */
"WIDE2-2", /* East */
"WIDE2-2" }; /* West */
#endif
static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, char *mycall_xmit,
regex_t *alias, regex_t *wide, int to_chan, enum preempt_e preempt, char *filter_str)
regex_t *alias, regex_t *wide, int to_chan, enum preempt_e preempt, char *atgp, char *filter_str)
{
char source[AX25_MAX_ADDR_LEN];
int ssid;
@ -323,15 +333,6 @@ static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, ch
* Otherwise we don't want to modify the input because this could be called multiple times.
*/
#ifndef OBSOLETE14 // Took it out in 1.4
if (ax25_get_num_repeaters(pp) == 0 && (ssid = ax25_get_ssid(pp, AX25_DESTINATION)) > 0) {
ax25_set_addr(pp, AX25_REPEATER_1, dest_ssid_path[ssid]);
ax25_set_ssid(pp, AX25_DESTINATION, 0);
/* Continue with general case, below. */
}
#endif
/*
* Find the first repeater station which doesn't have "has been repeated" set.
@ -440,6 +441,10 @@ static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, ch
/*
* If preemptive digipeating is enabled, try matching my call
* and aliases against all remaining unused digipeaters.
*
* Bob says: "GENERIC XXXXn-N DIGIPEATING should not do preemptive digipeating."
*
* But consider this case: https://github.com/wb2osz/direwolf/issues/488
*/
if (preempt != PREEMPT_OFF) {
@ -465,13 +470,22 @@ static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, ch
switch (preempt) {
case PREEMPT_DROP: /* remove all prior */
// TODO: deprecate this option. Result is misleading.
text_color_set (DW_COLOR_ERROR);
dw_printf ("The digipeat DROP option will be removed in a future release. Use PREEMPT for preemptive digipeating.\n");
while (r2 > AX25_REPEATER_1) {
ax25_remove_addr (result, r2-1);
r2--;
}
break;
case PREEMPT_MARK:
case PREEMPT_MARK: // TODO: deprecate this option. Result is misleading.
text_color_set (DW_COLOR_ERROR);
dw_printf ("The digipeat MARK option will be removed in a future release. Use PREEMPT for preemptive digipeating.\n");
r2--;
while (r2 >= AX25_REPEATER_1 && ax25_get_h(result,r2) == 0) {
ax25_set_h (result, r2);
@ -479,7 +493,12 @@ static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, ch
}
break;
case PREEMPT_TRACE: /* remove prior unused */
case PREEMPT_TRACE: /* My enhancement - remove prior unused digis. */
/* this provides an accurate path of where packet traveled. */
// Uh oh. It looks like sample config files went out
// with this option. Should it be renamed as
// PREEMPT which is more descriptive?
default:
while (r2 > AX25_REPEATER_1 && ax25_get_h(result,r2-1) == 0) {
ax25_remove_addr (result, r2-1);
@ -510,6 +529,40 @@ static packet_t digipeat_match (int from_chan, packet_t pp, char *mycall_rec, ch
err = regexec(wide,repeater,0,NULL,0);
if (err == 0) {
// Special hack added for ATGP to behave like some combination of options in some old TNC
// so the via path does not continue to grow and exceed the 8 available positions.
// The strange thing about this is that the used up digipeater is left there but
// removed by the next digipeater.
if (strlen(atgp) > 0 && strncasecmp(repeater, atgp, strlen(atgp)) == 0) {
if (ssid >= 1 && ssid <= 7) {
packet_t result;
result = ax25_dup (pp);
assert (result != NULL);
// First, remove any already used digipeaters.
while (ax25_get_num_addr(result) >= 3 && ax25_get_h(result,AX25_REPEATER_1) == 1) {
ax25_remove_addr (result, AX25_REPEATER_1);
r--;
}
ssid = ssid - 1;
ax25_set_ssid(result, r, ssid); // could be zero.
if (ssid == 0) {
ax25_set_h (result, r);
}
// Insert own call at beginning and mark it used.
ax25_insert_addr (result, AX25_REPEATER_1, mycall_xmit);
ax25_set_h (result, AX25_REPEATER_1);
return (result);
}
}
/*
* If ssid == 1, we simply replace the repeater with my call and
* mark it as being used.
@ -608,7 +661,7 @@ void digi_regen (int from_chan, packet_t pp)
*
* Name: main
*
* Purpose: Standalone test case for this funtionality.
* Purpose: Standalone test case for this functionality.
*
* Usage: make -f Makefile.<platform> dtest
* ./dtest
@ -617,7 +670,7 @@ void digi_regen (int from_chan, packet_t pp)
#if DIGITEST
static char mycall[] = "WB2OSZ-9";
static char mycall[12];
static regex_t alias_re;
@ -627,6 +680,7 @@ static int failed;
static enum preempt_e preempt = PREEMPT_OFF;
static char config_atgp[AX25_MAX_ADDR_LEN] = "HOP";
static void test (char *in, char *out)
@ -640,6 +694,7 @@ static void test (char *in, char *out)
int frame_len;
alevel_t alevel;
dw_printf ("\n");
/*
@ -689,9 +744,9 @@ static void test (char *in, char *out)
text_color_set(DW_COLOR_REC);
dw_printf ("Rec\t%s\n", rec);
//TODO: Add filtering to test.
// V
result = digipeat_match (0, pp, mycall, mycall, &alias_re, &wide_re, 0, preempt, NULL);
//TODO: Add filtering to test.
// V
result = digipeat_match (0, pp, mycall, mycall, &alias_re, &wide_re, 0, preempt, config_atgp, NULL);
if (result != NULL) {
@ -726,6 +781,7 @@ int main (int argc, char *argv[])
int e;
failed = 0;
char message[256];
strlcpy(mycall, "WB2OSZ-9", sizeof(mycall));
dedupe_init (4);
@ -740,7 +796,7 @@ int main (int argc, char *argv[])
exit (1);
}
e = regcomp (&wide_re, "^WIDE[1-7]-[1-7]$|^TRACE[1-7]-[1-7]$|^MA[1-7]-[1-7]$", REG_EXTENDED|REG_NOSUB);
e = regcomp (&wide_re, "^WIDE[1-7]-[1-7]$|^TRACE[1-7]-[1-7]$|^MA[1-7]-[1-7]$|^HOP[1-7]-[1-7]$", REG_EXTENDED|REG_NOSUB);
if (e != 0) {
regerror (e, &wide_re, message, sizeof(message));
text_color_set(DW_COLOR_ERROR);
@ -830,11 +886,8 @@ int main (int argc, char *argv[])
*/
test ( "W1ABC>TEST-3:",
#ifndef OBSOLETE14
"W1ABC>TEST,WB2OSZ-9*,WIDE3-2:");
#else
"");
#endif
test ( "W1DEF>TEST-3,WIDE2-2:",
"W1DEF>TEST-3,WB2OSZ-9*,WIDE2-1:");
@ -844,17 +897,17 @@ int main (int argc, char *argv[])
* The 4th case might be controversial.
*/
test ( "W1XYZ>TEST,R1*,WIDE3-2:info1",
"W1XYZ>TEST,R1,WB2OSZ-9*,WIDE3-1:info1");
test ( "W1XYZ>TESTD,R1*,WIDE3-2:info1",
"W1XYZ>TESTD,R1,WB2OSZ-9*,WIDE3-1:info1");
test ( "W1XYZ>TEST,R2*,WIDE3-2:info1",
test ( "W1XYZ>TESTD,R2*,WIDE3-2:info1",
"");
test ( "W1XYZ>TEST,R3*,WIDE3-2:info1",
test ( "W1XYZ>TESTD,R3*,WIDE3-2:info1",
"");
test ( "W1XYZ>TEST,R1*,WB2OSZ-9:has explicit routing",
"W1XYZ>TEST,R1,WB2OSZ-9*:has explicit routing");
test ( "W1XYZ>TESTD,R1*,WB2OSZ-9:has explicit routing",
"W1XYZ>TESTD,R1,WB2OSZ-9*:has explicit routing");
/*
@ -931,6 +984,54 @@ int main (int argc, char *argv[])
test ( "WB2OSZ-15>TEST14,WIDE1-1,WIDE1-1:stuff",
"WB2OSZ-15>TEST14,WB2OSZ-9*,WIDE1-1:stuff");
// New in 1.7 - ATGP Hack
preempt = PREEMPT_OFF; // Shouldn't make a difference here.
test ( "W1ABC>TEST51,HOP7-7,HOP7-7:stuff1",
"W1ABC>TEST51,WB2OSZ-9*,HOP7-6,HOP7-7:stuff1");
test ( "W1ABC>TEST52,ABCD*,HOP7-1,HOP7-7:stuff2",
"W1ABC>TEST52,WB2OSZ-9,HOP7*,HOP7-7:stuff2"); // Used up address remains.
test ( "W1ABC>TEST53,HOP7*,HOP7-7:stuff3",
"W1ABC>TEST53,WB2OSZ-9*,HOP7-6:stuff3"); // But it gets removed here.
test ( "W1ABC>TEST54,HOP7*,HOP7-1:stuff4",
"W1ABC>TEST54,WB2OSZ-9,HOP7*:stuff4"); // Remains again here.
test ( "W1ABC>TEST55,HOP7,HOP7*:stuff5",
"");
// Examples given for desired result.
strlcpy (mycall, "CLNGMN-1", sizeof(mycall));
test ( "W1ABC>TEST60,HOP7-7,HOP7-7:",
"W1ABC>TEST60,CLNGMN-1*,HOP7-6,HOP7-7:");
test ( "W1ABC>TEST61,ROAN-3*,HOP7-6,HOP7-7:",
"W1ABC>TEST61,CLNGMN-1*,HOP7-5,HOP7-7:");
strlcpy (mycall, "GDHILL-8", sizeof(mycall));
test ( "W1ABC>TEST62,MDMTNS-7*,HOP7-1,HOP7-7:",
"W1ABC>TEST62,GDHILL-8,HOP7*,HOP7-7:");
test ( "W1ABC>TEST63,CAMLBK-9*,HOP7-1,HOP7-7:",
"W1ABC>TEST63,GDHILL-8,HOP7*,HOP7-7:");
strlcpy (mycall, "MDMTNS-7", sizeof(mycall));
test ( "W1ABC>TEST64,GDHILL-8*,HOP7*,HOP7-7:",
"W1ABC>TEST64,MDMTNS-7*,HOP7-6:");
strlcpy (mycall, "CAMLBK-9", sizeof(mycall));
test ( "W1ABC>TEST65,GDHILL-8,HOP7*,HOP7-7:",
"W1ABC>TEST65,CAMLBK-9*,HOP7-6:");
strlcpy (mycall, "KATHDN-15", sizeof(mycall));
test ( "W1ABC>TEST66,MTWASH-14*,HOP7-1:",
"W1ABC>TEST66,KATHDN-15,HOP7*:");
strlcpy (mycall, "SPRNGR-1", sizeof(mycall));
test ( "W1ABC>TEST67,CLNGMN-1*,HOP7-1:",
"W1ABC>TEST67,SPRNGR-1,HOP7*:");
if (failed == 0) {

View File

@ -1,5 +1,4 @@
#ifndef DIGIPEATER_H
#define DIGIPEATER_H 1
@ -38,6 +37,11 @@ struct digi_config_s {
enum preempt_e { PREEMPT_OFF, PREEMPT_DROP, PREEMPT_MARK, PREEMPT_TRACE } preempt[MAX_CHANS][MAX_CHANS];
// ATGP is an ugly hack for the specific need of ATGP which needs more that 8 digipeaters.
// DO NOT put this in the User Guide. On a need to know basis.
char atgp[MAX_CHANS][MAX_CHANS][AX25_MAX_ADDR_LEN];
char *filter_str[MAX_CHANS+1][MAX_CHANS+1];
// NULL or optional Packet Filter strings such as "t/m".
// Notice the size of arrays is one larger than normal.

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020, 2021 John Langner, WB2OSZ
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020, 2021, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -33,7 +33,9 @@
* Internet Gateway (IGate)
* Ham Radio of Things - IoT with Ham Radio
* FX.25 Forward Error Correction.
*
* IL2P Forward Error Correction.
* Emergency Alert System (EAS) Specific Area Message Encoding (SAME) receiver.
* AIS receiver for tracking ships.
*
*---------------------------------------------------------------*/
@ -67,9 +69,8 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#ifdef __OpenBSD__
#include <soundcard.h>
#elif __APPLE__
#if USE_SNDIO || __APPLE__
// no need to include <soundcard.h>
#else
#include <sys/soundcard.h>
#endif
@ -124,8 +125,10 @@
#include "ax25_link.h"
#include "dtime_now.h"
#include "fx25.h"
#include "il2p.h"
#include "dwsock.h"
#include "dns_sd_dw.h"
#include "dlq.h" // for fec_type_t definition.
//static int idx_decoded = 0;
@ -136,7 +139,7 @@ static BOOL cleanup_win (int);
static void cleanup_linux (int);
#endif
static void usage (char **argv);
static void usage ();
#if defined(__SSE__) && !defined(__APPLE__)
@ -223,14 +226,19 @@ int main (int argc, char *argv[])
int d_h_opt = 0; /* "-d h" option for hamlib debugging. Repeat for more detail */
#endif
int d_x_opt = 1; /* "-d x" option for FX.25. Default minimal. Repeat for more detail. -qx to silence. */
int d_2_opt = 0; /* "-d 2" option for IL2P. Default minimal. Repeat for more detail. */
int aprstt_debug = 0; /* "-d d" option for APRStt (think Dtmf) debug. */
int E_tx_opt = 0; /* "-E n" Error rate % for clobbering trasmit frames. */
int E_tx_opt = 0; /* "-E n" Error rate % for clobbering transmit frames. */
int E_rx_opt = 0; /* "-E Rn" Error rate % for clobbering receive frames. */
float e_recv_ber = 0.0; /* Receive Bit Error Rate (BER). */
int X_fx25_xmit_enable = 0; /* FX.25 transmit enable. */
int I_opt = -1; /* IL2P transmit, normal polarity, arg is max_fec. */
int i_opt = -1; /* IL2P transmit, inverted polarity, arg is max_fec. */
char x_opt_mode = ' '; /* "-x N" option for transmitting calibration tones. */
int x_opt_chan = 0; /* Split into 2 parts. Mode e.g. m, a, and optional channel. */
@ -276,6 +284,8 @@ int main (int argc, char *argv[])
/* 1 = normal, 0 = no text colors. */
/* 2, 3, ... alternate escape sequences for different terminals. */
// FIXME: consider case of no space between t and number.
for (j=1; j<argc-1; j++) {
if (strcmp(argv[j], "-t") == 0) {
t_opt = atoi (argv[j+1]);
@ -291,9 +301,9 @@ int main (int argc, char *argv[])
text_color_init(t_opt);
text_color_set(DW_COLOR_INFO);
//dw_printf ("Dire Wolf version %d.%d (%s) Beta Test 4\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "A", __DATE__);
//dw_printf ("Dire Wolf version %d.%d\n", MAJOR_VERSION, MINOR_VERSION);
//dw_printf ("Dire Wolf version %d.%d (%s) BETA TEST 7\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
//dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "G", __DATE__);
dw_printf ("Dire Wolf version %d.%d\n", MAJOR_VERSION, MINOR_VERSION);
#if defined(ENABLE_GPSD) || defined(USE_HAMLIB) || defined(USE_CM108) || USE_AVAHI_CLIENT || USE_MACOS_DNSSD
@ -315,6 +325,7 @@ int main (int argc, char *argv[])
#if __WIN32__
//setlinebuf (stdout); setvbuf???
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)cleanup_win, TRUE);
#else
setlinebuf (stdout);
@ -364,7 +375,23 @@ int main (int argc, char *argv[])
text_color_set(DW_COLOR_INFO);
#endif
// I've seen many references to people running this as root.
// There is no reason to do that.
// Ordinary users can access audio, gpio, etc. if they are in the correct groups.
// Giving an applications permission to do things it does not need to do
// is a huge security risk.
#ifndef __WIN32__
if (getuid() == 0 || geteuid() == 0) {
text_color_set(DW_COLOR_ERROR);
for (int n=0; n<15; n++) {
dw_printf ("\n");
dw_printf ("Dire Wolf requires only privileges available to ordinary users.\n");
dw_printf ("Running this as root is an unnecessary security risk.\n");
//SLEEP_SEC(1);
}
}
#endif
/*
* Default location of configuration file is current directory.
@ -394,7 +421,7 @@ int main (int argc, char *argv[])
/* ':' following option character means arg is required. */
c = getopt_long(argc, argv, "hP:B:gjJD:U:c:px:r:b:n:d:q:t:ul:L:Sa:E:T:e:X:A",
c = getopt_long(argc, argv, "hP:B:gjJD:U:c:px:r:b:n:d:q:t:ul:L:Sa:E:T:e:X:AI:i:",
long_options, &option_index);
if (c == -1)
break;
@ -572,7 +599,7 @@ int main (int argc, char *argv[])
case '?':
/* For '?' unknown option message was already printed. */
usage (argv);
usage ();
break;
case 'd': /* Set debug option. */
@ -607,6 +634,7 @@ int main (int argc, char *argv[])
case 'h': d_h_opt++; break; // Hamlib verbose level.
#endif
case 'x': d_x_opt++; break; // FX.25
case '2': d_2_opt++; break; // IL2P
case 'd': aprstt_debug++; break; // APRStt (mnemonic Dtmf)
default: break;
}
@ -695,6 +723,16 @@ int main (int argc, char *argv[])
X_fx25_xmit_enable = atoi(optarg);
break;
case 'I': // IL2P, normal polarity
I_opt = atoi(optarg);
break;
case 'i': // IL2P, inverted polarity
i_opt = atoi(optarg);
break;
case 'A': // -A convert AIS to APRS object
A_opt_ais_to_obj = 1;
@ -705,7 +743,7 @@ int main (int argc, char *argv[])
/* Should not be here. */
text_color_set(DW_COLOR_DEBUG);
dw_printf("?? getopt returned character code 0%o ??\n", c);
usage (argv);
usage ();
}
} /* end while(1) for options */
@ -745,7 +783,7 @@ int main (int argc, char *argv[])
if (n_opt != 0) {
audio_config.adev[0].num_channels = n_opt;
if (n_opt == 2) {
audio_config.achan[1].medium = MEDIUM_RADIO;
audio_config.chan_medium[1] = MEDIUM_RADIO;
}
}
@ -895,7 +933,45 @@ int main (int argc, char *argv[])
audio_config.recv_ber = e_recv_ber;
audio_config.fx25_xmit_enable = X_fx25_xmit_enable;
if (X_fx25_xmit_enable > 0) {
if (I_opt != -1 || i_opt != -1) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Can't mix -X with -I or -i.\n");
exit (EXIT_FAILURE);
}
audio_config.achan[0].fx25_strength = X_fx25_xmit_enable;
audio_config.achan[0].layer2_xmit = LAYER2_FX25;
}
if (I_opt != -1 && i_opt != -1) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Can't use both -I and -i at the same time.\n");
exit (EXIT_FAILURE);
}
if (I_opt >= 0) {
audio_config.achan[0].layer2_xmit = LAYER2_IL2P;
audio_config.achan[0].il2p_max_fec = (I_opt > 0);
if (audio_config.achan[0].il2p_max_fec == 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("It is highly recommended that 1, rather than 0, is used with -I for best results.\n");
}
audio_config.achan[0].il2p_invert_polarity = 0; // normal
}
if (i_opt >= 0) {
audio_config.achan[0].layer2_xmit = LAYER2_IL2P;
audio_config.achan[0].il2p_max_fec = (i_opt > 0);
if (audio_config.achan[0].il2p_max_fec == 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("It is highly recommended that 1, rather than 0, is used with -i for best results.\n");
}
audio_config.achan[0].il2p_invert_polarity = 1; // invert for transmit
if (audio_config.achan[0].baud == 1200) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Using -i with 1200 bps is a bad idea. Use -I instead.\n");
}
}
/*
@ -912,14 +988,16 @@ int main (int argc, char *argv[])
text_color_set(DW_COLOR_ERROR);
dw_printf ("Pointless to continue without audio device.\n");
SLEEP_SEC(5);
usage ();
exit (1);
}
/*
* Initialize the demodulator(s) and HDLC decoder.
* Initialize the demodulator(s) and layer 2 decoder (HDLC, IL2P).
*/
multi_modem_init (&audio_config);
fx25_init (d_x_opt);
il2p_init (d_2_opt);
/*
* Initialize the touch tone decoder & APRStt gateway.
@ -957,7 +1035,7 @@ int main (int argc, char *argv[])
*/
if (x_opt_mode != ' ') {
if (audio_config.achan[x_opt_chan].medium == MEDIUM_RADIO) {
if (audio_config.chan_medium[x_opt_chan] == MEDIUM_RADIO) {
if (audio_config.achan[x_opt_chan].mark_freq
&& audio_config.achan[x_opt_chan].space_freq) {
int max_duration = 60;
@ -982,7 +1060,7 @@ int main (int argc, char *argv[])
audio_config.achan[x_opt_chan].mark_freq,
x_opt_chan);
while (n-- > 0) {
tone_gen_put_bit(x_opt_chan, 0);
tone_gen_put_bit(x_opt_chan, 1);
}
break;
case 's': // "Space" tone: -x s
@ -990,7 +1068,7 @@ int main (int argc, char *argv[])
audio_config.achan[x_opt_chan].space_freq,
x_opt_chan);
while (n-- > 0) {
tone_gen_put_bit(x_opt_chan, 1);
tone_gen_put_bit(x_opt_chan, 0);
}
break;
case 'p': // Silence - set PTT only: -x p
@ -1102,7 +1180,7 @@ int main (int argc, char *argv[])
// TODO: Use only one printf per line so output doesn't get jumbled up with stuff from other threads.
void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, int is_fx25, retry_t retries, char *spectrum)
void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, fec_type_t fec_type, retry_t retries, char *spectrum)
{
char stemp[500];
@ -1111,21 +1189,31 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
char heard[AX25_MAX_ADDR_LEN];
//int j;
int h;
char display_retries[32];
char display_retries[32]; // Extra stuff before slice indicators.
// Can indicate FX.25/IL2P or fix_bits.
assert (chan >= 0 && chan < MAX_CHANS);
assert (subchan >= -1 && subchan < MAX_SUBCHANS);
assert (chan >= 0 && chan < MAX_TOTAL_CHANS); // TOTAL for virtual channels
assert (subchan >= -2 && subchan < MAX_SUBCHANS);
assert (slice >= 0 && slice < MAX_SLICERS);
assert (pp != NULL); // 1.1J+
strlcpy (display_retries, "", sizeof(display_retries));
if (is_fx25) {
;
}
else if (audio_config.achan[chan].fix_bits != RETRY_NONE || audio_config.achan[chan].passall) {
assert (retries >= RETRY_NONE && retries <= RETRY_MAX);
snprintf (display_retries, sizeof(display_retries), " [%s] ", retry_text[(int)retries]);
switch (fec_type) {
case fec_type_fx25:
strlcpy (display_retries, " FX.25 ", sizeof(display_retries));
break;
case fec_type_il2p:
strlcpy (display_retries, " IL2P ", sizeof(display_retries));
break;
case fec_type_none:
default:
// Possible fix_bits indication.
if (audio_config.achan[chan].fix_bits != RETRY_NONE || audio_config.achan[chan].passall) {
assert (retries >= RETRY_NONE && retries <= RETRY_MAX);
snprintf (display_retries, sizeof(display_retries), " [%s] ", retry_text[(int)retries]);
}
break;
}
ax25_format_addrs (pp, stemp);
@ -1150,8 +1238,11 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
text_color_set(DW_COLOR_DEBUG);
dw_printf ("\n");
if (( ! q_h_opt ) && alevel.rec >= 0) { /* suppress if "-q h" option */
// The HEARD line.
if (( ! q_h_opt ) && alevel.rec >= 0) { /* suppress if "-q h" option */
// FIXME: rather than checking for ichannel, how about checking medium==radio
if (chan != audio_config.igate_vchannel) { // suppress if from ICHANNEL
if (h != -1 && h != AX25_SOURCE) {
dw_printf ("Digipeater ");
}
@ -1194,6 +1285,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
dw_printf ("%s audio level = %s %s %s\n", heard, alevel_text, display_retries, spectrum);
}
}
}
/* Version 1.2: Cranking the input level way up produces 199. */
@ -1207,7 +1299,8 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
text_color_set(DW_COLOR_ERROR);
dw_printf ("Audio input level is too high. Reduce so most stations are around 50.\n");
}
else if (alevel.rec < 5) {
// FIXME: rather than checking for ichannel, how about checking medium==radio
else if (alevel.rec < 5 && chan != audio_config.igate_vchannel) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Audio input level is too low. Increase so most stations are around 50.\n");
@ -1236,6 +1329,10 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
text_color_set(DW_COLOR_REC);
dw_printf ("[%d.dtmf%s] ", chan, ts);
}
else if (subchan == -2) {
text_color_set(DW_COLOR_REC);
dw_printf ("[%d.is%s] ", chan, ts);
}
else {
if (ax25_is_aprs(pp)) {
text_color_set(DW_COLOR_REC);
@ -1346,7 +1443,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
// we still want to decode it for logging and other processing.
// Just be quiet about errors if "-qd" is set.
decode_aprs (&A, pp, q_d_opt);
decode_aprs (&A, pp, q_d_opt, NULL);
if ( ! q_d_opt ) {
@ -1443,6 +1540,16 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
}
}
/*
* If it is from the ICHANNEL, we are done.
* Don't digipeat. Don't IGate.
* Don't do anything with it after printing and sending to client apps.
*/
if (chan == audio_config.igate_vchannel) {
return;
}
/*
* If it came from DTMF decoder (subchan == -1), send it to APRStt gateway.
* Otherwise, it is a candidate for IGate and digipeater.
@ -1464,10 +1571,14 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
}
else {
/* Send to Internet server if option is enabled. */
/* Consider only those with correct CRC. */
if (ax25_is_aprs(pp) && retries == RETRY_NONE) {
/*
* Send to the IGate processing.
* Use only those with correct CRC; We don't want to spread corrupted data!
* Our earlier "fix bits" hack could allow corrupted information to get thru.
* However, if it used FEC mode (FX.25. IL2P), we have much higher level of
* confidence that it is correct.
*/
if (ax25_is_aprs(pp) && ( retries == RETRY_NONE || fec_type == fec_type_fx25 || fec_type == fec_type_il2p) ) {
igate_send_rec_packet (chan, pp);
}
@ -1482,24 +1593,23 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
/*
* APRS digipeater.
* Send to APRS digipeater.
* Use only those with correct CRC; We don't want to spread corrupted data!
* Our earlier "fix bits" hack could allow corrupted information to get thru.
* However, if it used FEC mode (FX.25. IL2P), we have much higher level of
* confidence that it is correct.
*/
// TODO: Should also use anything received with FX.25 because it is known to be good.
// Our earlier "fix bits" hack could allow corrupted information to get thru.
if (ax25_is_aprs(pp) && retries == RETRY_NONE) {
if (ax25_is_aprs(pp) && ( retries == RETRY_NONE || fec_type == fec_type_fx25 || fec_type == fec_type_il2p) ) {
digipeater (chan, pp);
}
/*
* Connected mode digipeater.
* Use only those with correct CRC.
* Use only those with correct CRC (or using FEC.)
*/
if (retries == RETRY_NONE) {
if (retries == RETRY_NONE || fec_type == fec_type_fx25 || fec_type == fec_type_il2p) {
cdigipeater (chan, pp);
}
@ -1574,7 +1684,9 @@ static void usage (char **argv)
dw_printf (" -P xxx Modem Profiles.\n");
dw_printf (" -A Convert AIS positions to APRS Object Reports.\n");
dw_printf (" -D n Divide audio sample rate by n for channel 0.\n");
dw_printf (" -X n 1 to enable FX.25 transmit.\n");
dw_printf (" -X n 1 to enable FX.25 transmit. 16, 32, 64 for specific number of check bytes.\n");
dw_printf (" -I n Enable IL2P transmit. n=1 is recommended. 0 uses weaker FEC.\n");
dw_printf (" -i n Enable IL2P transmit, inverted polarity. n=1 is recommended. 0 uses weaker FEC.\n");
dw_printf (" -d Debug options:\n");
dw_printf (" a a = AGWPE network protocol client.\n");
dw_printf (" k k = KISS serial port or pseudo terminal client.\n");
@ -1592,6 +1704,7 @@ static void usage (char **argv)
dw_printf (" h h = hamlib increase verbose level.\n");
#endif
dw_printf (" x x = FX.25 increase verbose level.\n");
dw_printf (" 2 2 = IL2P.\n");
dw_printf (" d d = APRStt (DTMF to APRS object translation).\n");
dw_printf (" -q Quiet (suppress output) options:\n");
dw_printf (" h h = Heard line with the audio level.\n");
@ -1617,20 +1730,20 @@ static void usage (char **argv)
dw_printf ("\n");
dw_printf ("After any options, there can be a single command line argument for the source of\n");
dw_printf ("received audio. This can overrides the audio input specified in the configuration file.\n");
dw_printf ("received audio. This can override the audio input specified in the configuration file.\n");
dw_printf ("\n");
#if __WIN32__
dw_printf ("Complete documentation can be found in the 'doc' folder\n");
dw_printf ("Documentation can be found in the 'doc' folder\n");
#else
// TODO: Could vary by platform and build options.
dw_printf ("Complete documentation can be found in /usr/local/share/doc/direwolf\n");
dw_printf ("Documentation can be found in /usr/local/share/doc/direwolf\n");
#endif
dw_printf ("or online at https://github.com/wb2osz/direwolf/tree/master/doc\n");
dw_printf ("additional topics: https://github.com/wb2osz/direwolf-doc\n");
text_color_set(DW_COLOR_INFO);
exit (EXIT_FAILURE);
}
/* end direwolf.c */

View File

@ -38,9 +38,7 @@
#endif
/*
* Previously, we could handle only a single audio device.
* This meant we could have only two radio channels.
* In version 1.2, we relax this restriction and allow more audio devices.
* Maximum number of audio devices.
* Three is probably adequate for standard version.
* Larger reasonable numbers should also be fine.
*
@ -64,7 +62,15 @@
* and make sure they handle undefined channels correctly.
*/
#define MAX_CHANS ((MAX_ADEVS) * 2)
#define MAX_RADIO_CHANS ((MAX_ADEVS) * 2)
#define MAX_CHANS MAX_RADIO_CHANS // TODO: Replace all former with latter to avoid confusion with following.
#define MAX_TOTAL_CHANS 16 // v1.7 allows additional virtual channels which are connected
// to something other than radio modems.
// Total maximum channels is based on the 4 bit KISS field.
// Someone with very unusual requirements could increase this and
// use only the AGW network protocol.
/*
* Maximum number of rigs.
@ -96,7 +102,7 @@
* Each one of these can have multiple slicers, at
* different levels, to compensate for different
* amplitudes of the AFSK tones.
* Intially used same number as subchannels but
* Initially used same number as subchannels but
* we could probably trim this down a little
* without impacting performance.
*/
@ -272,6 +278,8 @@ typedef pthread_mutex_t dw_mutex_t;
/* Platform differences for string functions. */
// Windows is missing a few which are available on Unix/Linux platforms.
// We provide our own copies when building on Windows.
#if __WIN32__
char *strsep(char **stringp, const char *delim);
@ -279,13 +287,49 @@ char *strtok_r(char *str, const char *delim, char **saveptr);
#endif
// Don't recall why I added this for everyone rather than only for Windows.
// Potential problem if some C library declares it a little differently.
char *strcasestr(const char *S, const char *FIND);
// cmake determines whether strlcpy and strlcat are available
// or if we need to supply our own.
// cmake tries to determine whether strlcpy and strlcat are provided by the C runtime library.
//
// ../CMakeLists.txt:check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
//
// It sets HAVE_STRLCPY and HAVE_STRLCAT if the corresponding functions are declared.
// Unfortunately this does not work right for glibc 2.38 which declares the functions
// like this:
//
// extern __typeof (strlcpy) __strlcpy;
// libc_hidden_proto (__strlcpy)
// extern __typeof (strlcat) __strlcat;
// libc_hidden_proto (__strlcat)
//
// Rather than the normal way found in earlier versions:
//
// extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
//
// Perhaps a later version of cmake will recognize this form but the version I'm
// using does not.
// So, our work around is to assume these functions are available for glibc >= 2.38.
//
// In theory, cmake should be able to find the version of the C runtime library,
// but I could not get it to work. So we have the test here. We will still build
// own library with the strl... functions but this does not cause a problem
// because they have special debug names which will not cause a conflict.
#ifdef __GLIBC__
#if (__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 38))
// These functions first added in 2.38.
//#warning "DEBUG - glibc >= 2.38"
#define HAVE_STRLCPY 1
#define HAVE_STRLCAT 1
#else
//#warning "DEBUG - glibc < 2.38"
#endif
#endif
#define DEBUG_STRL 1 // Extra Debug version when using our own strlcpy, strlcat.
// Should be ignored if not supplying our own.
#ifndef HAVE_STRLCPY // Need to supply our own.
#if DEBUG_STRL

View File

@ -130,12 +130,18 @@ void dlq_init (void)
#else
int err;
err = pthread_mutex_init (&wake_up_mutex, NULL);
if (err != 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("dlq_init: pthread_mutex_init err=%d", err);
perror ("");
exit (EXIT_FAILURE);
}
err = pthread_mutex_init (&dlq_mutex, NULL);
if (err != 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("dlq_init: pthread_mutex_init err=%d", err);
perror ("");
exit (1);
exit (EXIT_FAILURE);
}
#endif
@ -209,10 +215,10 @@ void dlq_init (void)
* display of audio level line.
* Use -2 to indicate DTMF message.)
*
* is_fx25 - Was it from FX.25? Need to know because
* fec_type - Was it from FX.25 or IL2P? Need to know because
* meaning of retries is different.
*
* retries - Level of bit correction used.
* retries - Level of correction used.
*
* spectrum - Display of how well multiple decoders did.
*
@ -222,7 +228,7 @@ void dlq_init (void)
*
*--------------------------------------------------------------------*/
void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, int is_fx25, retry_t retries, char *spectrum)
void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, fec_type_t fec_type, retry_t retries, char *spectrum)
{
struct dlq_item_s *pnew;
@ -233,7 +239,7 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
dw_printf ("dlq_rec_frame (chan=%d, pp=%p, ...)\n", chan, pp);
#endif
assert (chan >= 0 && chan < MAX_CHANS);
assert (chan >= 0 && chan < MAX_TOTAL_CHANS); // TOTAL to include virtual channels.
if (pp == NULL) {
text_color_set(DW_COLOR_ERROR);
@ -253,6 +259,11 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
if (s_new_count > s_delete_count + 50) {
@ -267,7 +278,7 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
pnew->subchan = subchan;
pnew->pp = pp;
pnew->alevel = alevel;
pnew->is_fx25 = is_fx25;
pnew->fec_type = fec_type;
pnew->retries = retries;
if (spectrum == NULL)
strlcpy(pnew->spectrum, "", sizeof(pnew->spectrum));
@ -492,6 +503,11 @@ void dlq_connect_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int num
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_CONNECT_REQUEST;
@ -545,6 +561,11 @@ void dlq_disconnect_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_DISCONNECT_REQUEST;
@ -603,6 +624,11 @@ void dlq_outstanding_frames_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LE
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_OUTSTANDING_FRAMES_REQUEST;
@ -670,6 +696,11 @@ void dlq_xmit_data_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int n
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_XMIT_DATA_REQUEST;
@ -697,8 +728,7 @@ void dlq_xmit_data_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int n
*
* Purpose: Register callsigns that we will recognize for incoming connection requests.
*
* Inputs: addrs - Source (owncall), destination (peercall),
* and possibly digipeaters.
* Inputs: addr - Callsign to [un]register.
*
* chan - Channel, 0 is first.
*
@ -718,7 +748,7 @@ void dlq_xmit_data_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int n
*--------------------------------------------------------------------*/
void dlq_register_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client)
void dlq_register_callsign (char *addr, int chan, int client)
{
struct dlq_item_s *pnew;
@ -733,11 +763,16 @@ void dlq_register_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client)
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_REGISTER_CALLSIGN;
pnew->chan = chan;
strlcpy (pnew->addrs[0], addr, AX25_MAX_ADDR_LEN);
strlcpy (pnew->addrs[0], addr, sizeof(pnew->addrs[0]));
pnew->num_addr = 1;
pnew->client = client;
@ -748,7 +783,7 @@ void dlq_register_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client)
} /* end dlq_register_callsign */
void dlq_unregister_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client)
void dlq_unregister_callsign (char *addr, int chan, int client)
{
struct dlq_item_s *pnew;
@ -763,11 +798,16 @@ void dlq_unregister_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_UNREGISTER_CALLSIGN;
pnew->chan = chan;
strlcpy (pnew->addrs[0], addr, AX25_MAX_ADDR_LEN);
strlcpy (pnew->addrs[0], addr, sizeof(pnew->addrs[0]));
pnew->num_addr = 1;
pnew->client = client;
@ -817,6 +857,11 @@ void dlq_channel_busy (int chan, int activity, int status)
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_CHANNEL_BUSY;
@ -840,7 +885,7 @@ void dlq_channel_busy (int chan, int activity, int status)
* Name: dlq_seize_confirm
*
* Purpose: Inform data link state machine that the transmitter is on.
* This is in reponse to lm_seize_request.
* This is in response to lm_seize_request.
*
* Inputs: chan - Radio channel number.
*
@ -865,6 +910,11 @@ void dlq_seize_confirm (int chan)
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
pnew->type = DLQ_SEIZE_CONFIRM;
@ -910,6 +960,11 @@ void dlq_client_cleanup (int client)
/* Allocate a new queue item. */
pnew = (struct dlq_item_s *) calloc (sizeof(struct dlq_item_s), 1);
if (pnew == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
s_new_count++;
// All we care about is the client number.
@ -1192,6 +1247,11 @@ cdata_t *cdata_new (int pid, char *data, int len)
size = ( len + 127 ) & ~0x7f;
cdata = malloc ( sizeof(cdata_t) + size );
if (cdata == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
cdata->magic = TXDATA_MAGIC;
cdata->next = NULL;

View File

@ -33,10 +33,13 @@ typedef struct cdata_s {
/* Types of things that can be in queue. */
typedef enum dlq_type_e {DLQ_REC_FRAME, DLQ_CONNECT_REQUEST, DLQ_DISCONNECT_REQUEST, DLQ_XMIT_DATA_REQUEST, DLQ_REGISTER_CALLSIGN, DLQ_UNREGISTER_CALLSIGN, DLQ_OUTSTANDING_FRAMES_REQUEST, DLQ_CHANNEL_BUSY, DLQ_SEIZE_CONFIRM, DLQ_CLIENT_CLEANUP} dlq_type_t;
typedef enum fec_type_e {fec_type_none=0, fec_type_fx25=1, fec_type_il2p=2} fec_type_t;
/* A queue item. */
@ -68,7 +71,7 @@ typedef struct dlq_item_s {
alevel_t alevel; /* Audio level. */
int is_fx25; /* Was it from FX.25? */
fec_type_t fec_type; // Type of FEC for received signal: none, FX.25, or IL2P.
retry_t retries; /* Effort expended to get a valid CRC. */
/* Bits changed for regular AX.25. */
@ -106,7 +109,7 @@ void dlq_init (void);
void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, int is_fx25, retry_t retries, char *spectrum);
void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, fec_type_t fec_type, retry_t retries, char *spectrum);
void dlq_connect_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int num_addr, int chan, int client, int pid);
@ -116,9 +119,9 @@ void dlq_outstanding_frames_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LE
void dlq_xmit_data_request (char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN], int num_addr, int chan, int client, int pid, char *xdata_ptr, int xdata_len);
void dlq_register_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client);
void dlq_register_callsign (char *addr, int chan, int client);
void dlq_unregister_callsign (char addr[AX25_MAX_ADDR_LEN], int chan, int client);
void dlq_unregister_callsign (char *addr, int chan, int client);
void dlq_channel_busy (int chan, int activity, int status);

View File

@ -241,7 +241,7 @@ void dns_sd_announce (struct misc_config_s *mc)
/* Allocate a new client */
client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error);
/* Check wether creating the client object succeeded */
/* Check whether creating the client object succeeded */
if (!client) {
text_color_set(DW_COLOR_ERROR);
dw_printf(PRINT_PREFIX "Failed to create Avahi client: %s\n", avahi_strerror(error));

View File

@ -25,9 +25,9 @@
/*------------------------------------------------------------------
*
* Name: dtime_now
* Name: dtime_realtime
*
* Purpose: Return current time as double precision.
* Purpose: Return current wall clock time as double precision.
*
* Input: none
*
@ -40,11 +40,24 @@
* part of a second, and having extra calculations everywhere,
* simply use double precision floating point to make usage
* easier.
*
*
* NOTE: This is not a good way to calculate elapsed time because
* it can jump forward or backware via NTP or other manual setting.
*
* Use the monotonic version for measuring elapsed time.
*
* History: Originally I called this dtime_now. We ran into issues where
* we really cared about elapsed time, rather than wall clock time.
* The wall clock time could be wrong at start up time if there
* is no realtime clock or Internet access. It can then jump
* when GPS time or Internet access becomes available.
* All instances of dtime_now should be replaced by dtime_realtime
* if we want wall clock time, or dtime_monotonic if it is to be
* used for measuring elapsed time, such as between becons.
*
*---------------------------------------------------------------*/
double dtime_now (void)
double dtime_realtime (void)
{
double result;
@ -55,7 +68,7 @@ double dtime_now (void)
GetSystemTimeAsFileTime (&ft);
result = ((( (double)ft.dwHighDateTime * (256. * 256. * 256. * 256.) +
result = ((( (double)ft.dwHighDateTime * (256. * 256. * 256. * 256.) +
(double)ft.dwLowDateTime ) / 10000000.) - 11644473600.);
#else
/* tv_sec is seconds from Jan 1, 1970. */
@ -63,6 +76,10 @@ double dtime_now (void)
struct timespec ts;
#ifdef __APPLE__
// Why didn't I use clock_gettime?
// Not available before Max OSX 10.12? https://github.com/gambit/gambit/issues/293
struct timeval tp;
gettimeofday(&tp, NULL);
ts.tv_nsec = tp.tv_usec * 1000;
@ -75,6 +92,83 @@ double dtime_now (void)
#endif
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("dtime_realtime() returns %.3f\n", result );
#endif
return (result);
}
/*------------------------------------------------------------------
*
* Name: dtime_monotonic
*
* Purpose: Return montonically increasing time, which is not influenced
* by the wall clock changing. e.g. leap seconds, NTP adjustments.
*
* Input: none
*
* Returns: Time as double precision, so we can get resolution
* finer than one second.
*
* Description: Use this when calculating elapsed time.
*
*---------------------------------------------------------------*/
double dtime_monotonic (void)
{
double result;
#if __WIN32__
// FIXME:
// This is still returning wall clock time.
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64
// GetTickCount64 would be ideal but it requires Vista or Server 2008.
// As far as I know, the current version of direwolf still works on XP.
//
// As a work-around, GetTickCount could be used if we add extra code to deal
// with the wrap around after about 49.7 days.
// Resolution is only about 10 or 16 milliseconds. Is that good enough?
/* 64 bit integer is number of 100 nanosecond intervals from Jan 1, 1601. */
FILETIME ft;
GetSystemTimeAsFileTime (&ft);
result = ((( (double)ft.dwHighDateTime * (256. * 256. * 256. * 256.) +
(double)ft.dwLowDateTime ) / 10000000.) - 11644473600.);
#else
/* tv_sec is seconds from Jan 1, 1970. */
struct timespec ts;
#ifdef __APPLE__
// FIXME: Does MacOS have a monotonically increasing time?
// https://stackoverflow.com/questions/41509505/clock-gettime-on-macos
struct timeval tp;
gettimeofday(&tp, NULL);
ts.tv_nsec = tp.tv_usec * 1000;
ts.tv_sec = tp.tv_sec;
#else
// This is the only case handled properly.
// Probably the only one that matters.
// It is common to have a Raspberry Pi, without Internet,
// starting up direwolf before GPS/NTP adjusts the time.
clock_gettime (CLOCK_MONOTONIC, &ts);
#endif
result = ((double)(ts.tv_sec) + (double)(ts.tv_nsec) * 0.000000001);
#endif
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("dtime_now() returns %.3f\n", result );
@ -84,6 +178,7 @@ double dtime_now (void)
}
/*------------------------------------------------------------------
*
* Name: timestamp_now
@ -104,7 +199,7 @@ double dtime_now (void)
void timestamp_now (char *result, int result_size, int show_ms)
{
double now = dtime_now();
double now = dtime_realtime();
time_t t = (int)now;
struct tm tm;
@ -150,7 +245,7 @@ void timestamp_now (char *result, int result_size, int show_ms)
void timestamp_user_format (char *result, int result_size, char *user_format)
{
double now = dtime_now();
double now = dtime_realtime();
time_t t = (int)now;
struct tm tm;
@ -191,7 +286,7 @@ void timestamp_user_format (char *result, int result_size, char *user_format)
void timestamp_filename (char *result, int result_size)
{
double now = dtime_now();
double now = dtime_realtime();
time_t t = (int)now;
struct tm tm;

View File

@ -1,9 +1,18 @@
extern double dtime_now (void);
extern double dtime_realtime (void);
extern double dtime_monotonic (void);
void timestamp_now (char *result, int result_size, int show_ms);
void timestamp_user_format (char *result, int result_size, char *user_format);
void timestamp_filename (char *result, int result_size);
void timestamp_filename (char *result, int result_size);
// FIXME: remove temp workaround.
// Needs many scattered updates.
#define dtime_now dtime_realtime

View File

@ -245,7 +245,7 @@ char dtmf_sample (int c, float input)
* others in the same group multiplied by some factor.
*
* For perfect synthetic signals this needs to be in
* the range of about 1.33 (very senstive) to 2.15 (very fussy).
* the range of about 1.33 (very sensitive) to 2.15 (very fussy).
*
* Too low will cause false triggers on random noise.
* Too high will won't decode less than perfect signals.
@ -529,7 +529,7 @@ int main ()
memset (&my_audio_config, 0, sizeof(my_audio_config));
my_audio_config.adev[ACHAN2ADEV(c)].defined = 1;
my_audio_config.adev[ACHAN2ADEV(c)].samples_per_sec = 44100;
my_audio_config.achan[c].medium = MEDIUM_RADIO;
my_audio_config.chan_medium[c] = MEDIUM_RADIO;
my_audio_config.achan[c].dtmf_decode = DTMF_DECODE_ON;
dtmf_init(&my_audio_config, 50);

View File

@ -90,7 +90,7 @@ static dw_mutex_t s_gps_mutex;
*
* Name: dwgps_init
*
* Purpose: Intialize the GPS interface.
* Purpose: Initialize the GPS interface.
*
* Inputs: pconfig Configuration settings. This might include
* serial port name for direct connect and host

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2013, 2014, 2015, 2020 John Langner, WB2OSZ
// Copyright (C) 2013, 2014, 2015, 2020, 2022 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
/*------------------------------------------------------------------
*
* Module: dwgps.c
* Module: dwgpsd.c
*
* Purpose: Interface to location data, i.e. GPS receiver.
*
@ -57,13 +57,36 @@
// An incompatibility was introduced with version 7
// and again with 9 and again with 10.
// An API incompatibility was introduced with API version 7.
// and again with 9.
// and again with 10.
// We deal with it by using a bunch of conditional code such as:
// #if GPSD_API_MAJOR_VERSION >= 9
#if GPSD_API_MAJOR_VERSION < 5 || GPSD_API_MAJOR_VERSION > 11
#error libgps API version might be incompatible.
// release lib version API Raspberry Pi OS Testing status
// 3.22 28 11 bullseye OK.
// 3.23 29 12 OK.
// 3.25 30 14 OK, Jan. 2023
// Previously the compilation would fail if the API version was later
// than the last one tested. Now it is just a warning because it changes so
// often but more recent versions have not broken backward compatibility.
#define MAX_TESTED_VERSION 14
#if (GPSD_API_MAJOR_VERSION < 5) || (GPSD_API_MAJOR_VERSION > MAX_TESTED_VERSION)
#pragma message "Your version of gpsd might be incompatible with this application."
#pragma message "The libgps application program interface (API) often"
#pragma message "changes to be incompatible with earlier versions."
// I could not figure out how to do value substitution here.
#pragma message "You have libgpsd API version GPSD_API_MAJOR_VERSION."
#pragma message "The last that has been tested is MAX_TESTED_VERSION."
#pragma message "Even if this builds successfully, it might not run properly."
#endif
/*
* Information for interface to gpsd daemon.
*/
@ -94,7 +117,7 @@ static void * read_gpsd_thread (void *arg);
*
* Name: dwgpsd_init
*
* Purpose: Intialize the GPS interface.
* Purpose: Initialize the GPS interface.
*
* Inputs: pconfig Configuration settings. This includes
* host name or address for network connection.
@ -163,6 +186,22 @@ static void * read_gpsd_thread (void *arg);
* can't find it there. Solution is to define environment variable:
*
* export LD_LIBRARY_PATH=/use/local/lib
*
* January 2023: Now using 64 bit Raspberry Pi OS, bullseye.
* See https://gitlab.com/gpsd/gpsd/-/blob/master/build.adoc
* Try to install in proper library place so we don't have to mess with LD_LIBRARY_PATH.
*
* (Remove any existing gpsd first so we are not mixing mismatched pieces.)
*
* sudo apt-get install libncurses5-dev
* sudo apt-get install gtk+-3.0
*
* git clone https://gitlab.com/gpsd/gpsd.git gpsd-gitlab
* cd gpsd-gitlab
* scons prefix=/usr libdir=lib/aarch64-linux-gnu
* [ scons check ]
* sudo scons udev-install
*
*/
@ -191,7 +230,7 @@ int dwgpsd_init (struct misc_config_s *pconfig, int debug)
if (strlen(pconfig->gpsd_host) == 0) {
/* Nothing to do. Leave initial fix value of errror. */
/* Nothing to do. Leave initial fix value of error. */
return (0);
}
@ -364,6 +403,10 @@ static void * read_gpsd_thread (void *arg)
default:
case MODE_NOT_SEEN:
case MODE_NO_FIX:
if (info.fix <= DWFIX_NOT_SEEN) {
text_color_set(DW_COLOR_INFO);
dw_printf ("GPSD: No location fix.\n");
}
if (info.fix >= DWFIX_2D) {
text_color_set(DW_COLOR_INFO);
dw_printf ("GPSD: Lost location fix.\n");
@ -393,13 +436,15 @@ static void * read_gpsd_thread (void *arg)
if (/*gpsdata.stupid_status >= STATUS_FIX &&*/ gpsdata.fix.mode >= MODE_2D) {
info.dlat = isfinite(gpsdata.fix.latitude) ? gpsdata.fix.latitude : G_UNKNOWN;
info.dlon = isfinite(gpsdata.fix.longitude) ? gpsdata.fix.longitude : G_UNKNOWN;
#define GOOD(x) (isfinite(x) && ! isnan(x))
info.dlat = GOOD(gpsdata.fix.latitude) ? gpsdata.fix.latitude : G_UNKNOWN;
info.dlon = GOOD(gpsdata.fix.longitude) ? gpsdata.fix.longitude : G_UNKNOWN;
// When stationary, track is NaN which is not finite.
info.track = isfinite(gpsdata.fix.track) ? gpsdata.fix.track : G_UNKNOWN;
info.speed_knots = isfinite(gpsdata.fix.speed) ? (MPS_TO_KNOTS * gpsdata.fix.speed) : G_UNKNOWN;
info.track = GOOD(gpsdata.fix.track) ? gpsdata.fix.track : G_UNKNOWN;
info.speed_knots = GOOD(gpsdata.fix.speed) ? (MPS_TO_KNOTS * gpsdata.fix.speed) : G_UNKNOWN;
if (gpsdata.fix.mode >= MODE_3D) {
info.altitude = isfinite(gpsdata.fix.stupid_altitude) ? gpsdata.fix.stupid_altitude : G_UNKNOWN;
info.altitude = GOOD(gpsdata.fix.stupid_altitude) ? gpsdata.fix.stupid_altitude : G_UNKNOWN;
}
// Otherwise keep last known altitude when we downgrade from 3D to 2D fix.
// Caller knows altitude is outdated if info.fix == DWFIX_2D.

View File

@ -144,11 +144,9 @@ int dwgpsnmea_init (struct misc_config_s *pconfig, int debug)
/*
* Open serial port connection.
* 4800 baud is standard for GPS.
* Should add an option to allow changing someday.
*/
s_gpsnmea_port_fd = serial_port_open (pconfig->gpsnmea_port, 4800);
s_gpsnmea_port_fd = serial_port_open (pconfig->gpsnmea_port, pconfig->gpsnmea_speed);
if (s_gpsnmea_port_fd != MYFDERROR) {
#if __WIN32__
@ -182,12 +180,10 @@ int dwgpsnmea_init (struct misc_config_s *pconfig, int debug)
/* Return fd to share if waypoint wants same device. */
/* Currently both are fixed speed at 4800. */
/* If that ever becomes configurable, that needs to be compared too. */
MYFDTYPE dwgpsnmea_get_fd(char *wp_port_name, int speed)
{
if (strcmp(s_save_configp->gpsnmea_port, wp_port_name) == 0 && speed == 4800) {
if (strcmp(s_save_configp->gpsnmea_port, wp_port_name) == 0 && speed == s_save_configp->gpsnmea_speed) {
return (s_gpsnmea_port_fd);
}
return (MYFDERROR);
@ -266,9 +262,12 @@ static void * read_gpsnmea_thread (void *arg)
}
dwgps_set_data (&info);
// TODO: doesn't exist yet - serial_port_close(fd);
serial_port_close(s_gpsnmea_port_fd);
s_gpsnmea_port_fd = MYFDERROR;
// TODO: If the open() was in this thread, we could wait a while and
// try to open again. That would allow recovery if the USB GPS device
// is unplugged and plugged in again.
break; /* terminate thread. */
}
@ -289,74 +288,53 @@ static void * read_gpsnmea_thread (void *arg)
}
/* Process sentence. */
// FIXME: Ignore the second letter rather than recognizing only GP... and GN...
// TODO: More general: Ignore the second letter rather than recognizing only GP... and GN...
if (strncmp(gps_msg, "$GPRMC", 6) == 0 ||
strncmp(gps_msg, "$GNRMC", 6) == 0) {
f = dwgpsnmea_gprmc (gps_msg, 0, &info.dlat, &info.dlon, &info.speed_knots, &info.track);
// Here we just tuck away the course and speed.
// Fix and location will be updated by GxGGA.
double ignore_dlat;
double ignore_dlon;
f = dwgpsnmea_gprmc (gps_msg, 0, &ignore_dlat, &ignore_dlon, &info.speed_knots, &info.track);
if (f == DWFIX_ERROR) {
/* Parse error. Shouldn't happen. Better luck next time. */
text_color_set(DW_COLOR_INFO);
/* Parse error. Shouldn't happen. Better luck next time. */
text_color_set(DW_COLOR_ERROR);
dw_printf ("GPSNMEA: Error parsing $GPRMC sentence.\n");
dw_printf ("%s\n", gps_msg);
}
else if (f == DWFIX_2D) {
if (info.fix != DWFIX_2D && info.fix != DWFIX_3D) {
text_color_set(DW_COLOR_INFO);
dw_printf ("GPSNMEA: Location fix is now available.\n");
info.fix = DWFIX_2D; // Don't know if 2D or 3D. Take minimum.
}
info.timestamp = time(NULL);
if (s_debug >= 2) {
text_color_set(DW_COLOR_DEBUG);
dwgps_print ("GPSNMEA: ", &info);
}
dwgps_set_data (&info);
}
else {
if (info.fix == DWFIX_2D || info.fix == DWFIX_3D) {
text_color_set(DW_COLOR_INFO);
dw_printf ("GPSNMEA: Lost location fix.\n");
}
info.fix = f; /* lost it. */
info.timestamp = time(NULL);
if (s_debug >= 2) {
text_color_set(DW_COLOR_DEBUG);
dwgps_print ("GPSNMEA: ", &info);
}
dwgps_set_data (&info);
}
}
else if (strncmp(gps_msg, "$GPGGA", 6) == 0 ||
strncmp(gps_msg, "$GNGGA", 6) == 0) {
int nsat;
f = dwgpsnmea_gpgga (gps_msg, 0, &info.dlat, &info.dlon, &info.altitude, &nsat);
/* Only switch between 2D & 3D. */
/* Let GPRMC handle other changes in fix state and data transfer. */
if (f == DWFIX_ERROR) {
/* Parse error. Shouldn't happen. Better luck next time. */
text_color_set(DW_COLOR_INFO);
text_color_set(DW_COLOR_ERROR);
dw_printf ("GPSNMEA: Error parsing $GPGGA sentence.\n");
dw_printf ("%s\n", gps_msg);
}
else if ((f == DWFIX_3D && info.fix == DWFIX_2D) ||
(f == DWFIX_2D && info.fix == DWFIX_3D)) {
text_color_set(DW_COLOR_INFO);
dw_printf ("GPSNMEA: Location fix is now %dD.\n", (int)f);
info.fix = f;
else {
if (f != info.fix) { // Print change in location fix.
text_color_set(DW_COLOR_INFO);
if (f == DWFIX_NO_FIX) dw_printf ("GPSNMEA: Location fix has been lost.\n");
if (f == DWFIX_2D) dw_printf ("GPSNMEA: Location fix is now 2D.\n");
if (f == DWFIX_3D) dw_printf ("GPSNMEA: Location fix is now 3D.\n");
info.fix = f;
}
info.timestamp = time(NULL);
if (s_debug >= 2) {
text_color_set(DW_COLOR_DEBUG);
dwgps_print ("GPSNMEA: ", &info);
}
dwgps_set_data (&info);
}
}
}
@ -437,7 +415,7 @@ static int remove_checksum (char *sent, int quiet)
*
* Name: dwgpsnmea_gprmc
*
* Purpose: Parse $GPRMC sentence and extract interesing parts.
* Purpose: Parse $GPRMC sentence and extract interesting parts.
*
* Inputs: sentence NMEA sentence.
*
@ -447,9 +425,11 @@ static int remove_checksum (char *sent, int quiet)
* odlon longitude
* oknots speed
* ocourse direction of travel.
*
*
* Left undefined if not valid.
*
* Note: RMC does not contain altitude.
*
* Returns: DWFIX_ERROR Parse error.
* DWFIX_NO_FIX GPS is there but Position unknown. Could be temporary.
* DWFIX_2D Valid position. We don't know if it is really 2D or 3D.
@ -586,7 +566,7 @@ dwfix_t dwgpsnmea_gprmc (char *sentence, int quiet, double *odlat, double *odlon
*
* Name: dwgpsnmea_gpgga
*
* Purpose: Parse $GPGGA sentence and extract interesing parts.
* Purpose: Parse $GPGGA sentence and extract interesting parts.
*
* Inputs: sentence NMEA sentence.
*
@ -599,10 +579,13 @@ dwfix_t dwgpsnmea_gprmc (char *sentence, int quiet, double *odlat, double *odlon
*
* Left undefined if not valid.
*
* Note: GGA has altitude but not course and speed so we need to use both.
*
* Returns: DWFIX_ERROR Parse error.
* DWFIX_NO_FIX GPS is there but Position unknown. Could be temporary.
* DWFIX_2D Valid position. We don't know if it is really 2D or 3D.
* Take more cautious value so we don't try using altitude.
* DWFIX_3D Valid 3D position.
*
* Examples: $GPGGA,001429.00,,,,,0,00,99.99,,,,,,*68
* $GPGGA,212407.000,4237.1505,N,07120.8602,W,0,00,,,M,,M,,*58
@ -611,9 +594,6 @@ dwfix_t dwgpsnmea_gprmc (char *sentence, int quiet, double *odlat, double *odlon
*
*--------------------------------------------------------------------*/
// TODO: in progress...
dwfix_t dwgpsnmea_gpgga (char *sentence, int quiet, double *odlat, double *odlon, float *oalt, int *onsat)
{
char stemp[NMEA_MAX_LEN]; /* Make copy because parsing is destructive. */
@ -710,8 +690,7 @@ dwfix_t dwgpsnmea_gpgga (char *sentence, int quiet, double *odlat, double *odlon
return (DWFIX_ERROR);
}
// TODO: num sat...
// TODO: num sat... Why would we care?
/*
* We can distinguish between 2D & 3D fix by presence

View File

@ -11,7 +11,7 @@
int dwsock_init (void);
int dwsock_connect (char *hostname, char *port, char *description, int allow_ipv6, int debug, char *ipaddr_str);
int dwsock_connect (char *hostname, char *port, char *description, int allow_ipv6, int debug, char ipaddr_str[DWSOCK_IPADDR_LEN]);
/* ipaddr_str needs to be at least SOCK_IPADDR_LEN bytes */
char *dwsock_ia_to_text (int Family, void * pAddr, char * pStringBuf, size_t StringBufSize);

View File

@ -125,7 +125,7 @@ static int set_norm_position (char symtab, char symbol, double dlat, double dlon
* height - Feet.
* gain - dBi.
*
* course - Degress, 0 - 360 (360 equiv. to 0).
* course - Degrees, 0 - 360 (360 equiv. to 0).
* Use G_UNKNOWN for none or unknown.
* speed - knots.
*
@ -343,7 +343,7 @@ static int phg_data_extension (int power, int height, int gain, char *dir, char
*
* Purpose: Fill in parts of the course & speed data extension.
*
* Inputs: course - Degress, 0 - 360 (360 equiv. to 0).
* Inputs: course - Degrees, 0 - 360 (360 equiv. to 0).
* Use G_UNKNOWN for none or unknown.
*
* speed - knots.
@ -494,7 +494,7 @@ static int frequency_spec (float freq, float tone, float offset, char *presult)
* gain - dB. Not clear if it is dBi or dBd.
* dir - Directivity: N, NE, etc., omni.
*
* course - Degress, 0 - 360 (360 equiv. to 0).
* course - Degrees, 0 - 360 (360 equiv. to 0).
* Use G_UNKNOWN for none or unknown.
* speed - knots. // TODO: should distinguish unknown(not revevant) vs. known zero.
*
@ -504,7 +504,7 @@ static int frequency_spec (float freq, float tone, float offset, char *presult)
*
* comment - Additional comment text.
*
* result_size - Ammount of space for result, provideed by
* result_size - Amount of space for result, provided by
* caller, to avoid buffer overflow.
*
* Outputs: presult - Stored here. Should be at least ??? bytes.
@ -519,7 +519,7 @@ static int frequency_spec (float freq, float tone, float offset, char *presult)
* Power/height/gain/directivity or
* Course/speed.
*
* Afer that,
* After that,
*
*----------------------------------------------------------------*/
@ -551,6 +551,15 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
int result_len = 0;
if (compressed) {
// Thought:
// https://groups.io/g/direwolf/topic/92718535#6886
// When speed is zero, we could put the altitude in the compressed
// position rather than having /A=999999.
// However, the resolution would be decreased and that could be important
// when hiking in hilly terrain. It would also be confusing to
// flip back and forth between two different representations.
aprs_compressed_pos_t *p = (aprs_compressed_pos_t *)presult;
p->dti = messaging ? '=' : '!';
@ -636,7 +645,7 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
* gain - dB. Not clear if it is dBi or dBd.
* dir - Direction: N, NE, etc., omni.
*
* course - Degress, 0 - 360 (360 equiv. to 0).
* course - Degrees, 0 - 360 (360 equiv. to 0).
* Use G_UNKNOWN for none or unknown.
* speed - knots.
*
@ -646,7 +655,7 @@ int encode_position (int messaging, int compressed, double lat, double lon, int
*
* comment - Additional comment text.
*
* result_size - Ammount of space for result, provideed by
* result_size - Amount of space for result, provided by
* caller, to avoid buffer overflow.
*
* Outputs: presult - Stored here. Should be at least ??? bytes.
@ -776,7 +785,7 @@ int encode_object (char *name, int compressed, time_t thyme, double lat, double
* Inputs: addressee - Addressed to, up to 9 characters.
* text - Text part of the message.
* id - Identifier, 0 to 5 characters.
* result_size - Ammount of space for result, provided by
* result_size - Amount of space for result, provided by
* caller, to avoid buffer overflow.
*
* Outputs: presult - Stored here.
@ -860,7 +869,7 @@ int main (int argc, char *argv[])
dw_printf ("%s\n", result);
if (strcmp(result, "!4234.61ND07126.47W&PHG7368") != 0) { dw_printf ("ERROR! line %d\n", __LINE__); errors++; }
/* with freq & tone. minus offset, no offset, explict simplex. */
/* with freq & tone. minus offset, no offset, explicit simplex. */
encode_position (0, 0, 42+34.61/60, -(71+26.47/60), 0, G_UNKNOWN, 'D', '&',
0, 0, 0, NULL, G_UNKNOWN, 0, 146.955, 74.4, -0.6, NULL, result, sizeof(result));

View File

@ -2,6 +2,8 @@
#ifndef FSK_DEMOD_STATE_H
#include <stdint.h> // int64_t
#include "rpack.h"
#include "audio.h" // for enum modem_t
@ -43,8 +45,9 @@ typedef struct cic_s {
} cic_t;
#define MAX_FILTER_SIZE 404 /* 401 is needed for profile A, 300 baud & 44100. Revisit someday. */
#define MAX_FILTER_SIZE 480 /* 401 is needed for profile A, 300 baud & 44100. Revisit someday. */
// Size comes out to 417 for 1200 bps with 48000 sample rate
// v1.7 - Was 404. Bump up to 480.
struct demodulator_state_s
{
@ -216,6 +219,12 @@ struct demodulator_state_s
signed int prev_d_c_pll; // Previous value of above, before
// incrementing, to detect overflows.
int pll_symbol_count; // Number symbols during time nudge_total is accumulated.
int64_t pll_nudge_total; // Sum of DPLL nudge amounts.
// Both of these are cleared at start of frame.
// At end of frame, we can see if incoming
// baud rate is a little off.
int prev_demod_data; // Previous data bit detected.
// Used to look for transitions.
float prev_demod_out_f;
@ -301,6 +310,8 @@ struct demodulator_state_s
// //
//////////////////////////////////////////////////////////////////////////////////
// TODO: Continue experiments with root raised cosine filter.
// Either switch to that or take out all the related stuff.
struct bb_only_s {
@ -314,8 +325,15 @@ struct demodulator_state_s
float audio_in[MAX_FILTER_SIZE] __attribute__((aligned(16))); // Audio samples in.
// FIXME: use lp_filter
float rrc_filter[MAX_FILTER_SIZE] __attribute__((aligned(16))); // RRC Low pass filter.
float lp_filter[MAX_FILTER_SIZE] __attribute__((aligned(16))); // Low pass filter.
// New in 1.7 - Polyphase filter to reduce CPU requirements.
float lp_polyphase_1[MAX_FILTER_SIZE] __attribute__((aligned(16)));
float lp_polyphase_2[MAX_FILTER_SIZE] __attribute__((aligned(16)));
float lp_polyphase_3[MAX_FILTER_SIZE] __attribute__((aligned(16)));
float lp_polyphase_4[MAX_FILTER_SIZE] __attribute__((aligned(16)));
float lp_1_iir_param; // very low pass filters to get DC offset.
float lp_1_out;
@ -349,7 +367,7 @@ struct demodulator_state_s
// Add a sample to the total when putting it in our array of recent samples.
// Subtract it from the total when it gets pushed off the end.
// We can also eliminate the need to shift them all down by using a circular buffer.
// This only works with integers because float would have cummulated round off errors.
// This only works with integers because float would have cumulated round off errors.
cic_t cic_center1;
cic_t cic_above;

View File

@ -371,6 +371,7 @@ int fx25_pick_mode (int fx_mode, int dlen)
// The PRUG FX.25 TNC has additional modes that will handle larger frames
// by using multiple RS blocks. This is a future possibility but needs
// to be coordinated with other FX.25 developers so we maintain compatibility.
// See https://web.tapr.org/meetings/DCC_2020/JE1WAZ/DCC-2020-PRUG-FINAL.pptx
static const int prefer[6] = { 0x04, 0x03, 0x06, 0x09, 0x05, 0x01 };
for (int k = 0; k < 6; k++) {
@ -410,19 +411,25 @@ struct rs *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigne
return NULL; /* Can't have more roots than symbol values! */
rs = (struct rs *)calloc(1,sizeof(struct rs));
if (rs == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
rs->mm = symsize;
rs->nn = (1<<symsize)-1;
rs->alpha_to = (DTYPE *)malloc(sizeof(DTYPE)*(rs->nn+1));
rs->alpha_to = (DTYPE *)calloc((rs->nn+1),sizeof(DTYPE));
if(rs->alpha_to == NULL){
free(rs);
return NULL;
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
rs->index_of = (DTYPE *)malloc(sizeof(DTYPE)*(rs->nn+1));
rs->index_of = (DTYPE *)calloc((rs->nn+1),sizeof(DTYPE));
if(rs->index_of == NULL){
free(rs->alpha_to);
free(rs);
return NULL;
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
/* Generate Galois field lookup tables */
@ -446,14 +453,13 @@ struct rs *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigne
}
/* Form RS code generator polynomial from its roots */
rs->genpoly = (DTYPE *)malloc(sizeof(DTYPE)*(nroots+1));
rs->genpoly = (DTYPE *)calloc((nroots+1),sizeof(DTYPE));
if(rs->genpoly == NULL){
free(rs->alpha_to);
free(rs->index_of);
free(rs);
return NULL;
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
rs->fcr = fcr;
rs->fcr = fcr;
rs->prim = prim;
rs->nroots = nroots;
@ -482,7 +488,7 @@ struct rs *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigne
}
// diagnostic prints
/*
#if 0
printf("Alpha To:\n\r");
for (i=0; i < sizeof(DTYPE)*(rs->nn+1); i++)
printf("0x%2x,", rs->alpha_to[i]);
@ -497,7 +503,7 @@ struct rs *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned fcr,unsigne
for (i = 0; i <= nroots; i++)
printf("0x%2x,", rs->genpoly[i]);
printf("\n\r");
*/
#endif
return rs;
}

View File

@ -258,7 +258,7 @@ int fx25_rec_busy (int chan)
{
assert (chan >= 0 && chan < MAX_CHANS);
// This could be a litle faster if we knew number of
// This could be a little faster if we knew number of
// subchannels and slicers but it is probably insignificant.
for (int i = 0; i < MAX_SUBCHANS; i++) {

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2013, 2014, 2015, 2016, 2019 John Langner, WB2OSZ
// Copyright (C) 2011, 2013, 2014, 2015, 2016, 2019, 2021, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -56,7 +56,15 @@
* gen_packets -n 100 -o z2.wav
* atest z2.wav
*
*
* Variable speed. e.g. 95% to 105% of normal speed.
* Required parameter is max % below and above normal.
* Optionally specify step other than 0.1%.
* Used to test how tolerant TNCs are to senders not
* not using exactly the right baud rate.
*
* gen_packets -v 5
* gen_packets -v 5,0.5
*
*------------------------------------------------------------------*/
@ -67,6 +75,7 @@
#include <getopt.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include "audio.h"
#include "ax25_pad.h"
@ -76,6 +85,7 @@
#include "morse.h"
#include "dtmf.h"
#include "fx25.h"
#include "il2p.h"
/* Own random number generator so we can get */
@ -99,6 +109,7 @@ static float g_noise_level = 0;
static int g_morse_wpm = 0; /* Send morse code at this speed. */
static struct audio_s modem;
@ -107,13 +118,48 @@ static void send_packet (char *str)
packet_t pp;
unsigned char fbuf[AX25_MAX_PACKET_LEN+2];
int flen;
int c;
int c = 0; // channel number.
if (g_morse_wpm > 0) {
// TODO: Why not use the destination field instead of command line option?
// Why not use the destination field instead of command line option?
// For one thing, this is not in TNC-2 monitor format.
morse_send (0, str, g_morse_wpm, 100, 100);
morse_send (c, str, g_morse_wpm, 100, 100);
}
else if (modem.achan[0].modem_type == MODEM_EAS) {
// Generate EAS SAME signal FOR RESEARCH AND TESTING ONLY!!!
// There could be legal consequences for sending unauhorized SAME
// over the radio so don't do it!
// I'm expecting to see TNC 2 monitor format.
// The source and destination are ignored.
// The optional destination SSID is the number of times to repeat.
// The user defined data type indicator can optionally be used
// for compatibility with how it is received and presented to client apps.
// Examples:
// X>X-3:{DEZCZC-WXR-RWT-033019-033017-033015-033013-033011-025011-025017-033007-033005-033003-033001-025009-025027-033009+0015-1691525-KGYX/NWS-
// X>X:NNNN
pp = ax25_from_text (str, 1);
if (pp == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("\"%s\" is not valid TNC2 monitoring format.\n", str);
return;
}
unsigned char *pinfo;
int info_len = ax25_get_info (pp, &pinfo);
if (info_len >= 3 && strncmp((char*)pinfo, "{DE", 3) == 0) {
pinfo += 3;
info_len -= 3;
}
int repeat = ax25_get_ssid (pp, AX25_DESTINATION);
if (repeat == 0) repeat = 1;
eas_send (c, pinfo, repeat, 500, 500);
ax25_delete (pp);
}
else {
pp = ax25_from_text (str, 1);
@ -123,6 +169,10 @@ static void send_packet (char *str)
return;
}
flen = ax25_pack (pp, fbuf);
(void)flen;
// If stereo, put same thing in each channel.
for (c=0; c<modem.adev[0].num_channels; c++)
{
@ -151,12 +201,10 @@ static void send_packet (char *str)
gen_tone_put_sample (c, 0, 0);
}
#endif
hdlc_send_flags (c, 8, 0);
hdlc_send_flags (c, 8, 0);
hdlc_send_flags (c, 8, 0);
hdlc_send_flags (c, 8, 0);
hdlc_send_frame (c, fbuf, flen, 0, modem.fx25_xmit_enable);
hdlc_send_flags (c, 2, 1);
layer2_preamble_postamble (c, 32, 0, &modem);
layer2_send_frame (c, pp, 0, &modem);
layer2_preamble_postamble (c, 2, 1, &modem);
}
ax25_delete (pp);
}
@ -176,6 +224,12 @@ int main(int argc, char **argv)
int g_opt = 0;
int j_opt = 0;
int J_opt = 0;
int X_opt = 0; // send FX.25
int I_opt = -1; // send IL2P rather than AX.25, normal polarity
int i_opt = -1; // send IL2P rather than AX.25, inverted polarity
double variable_speed_max_error = 0; // both in percent
double variable_speed_increment = 0.1;
/*
* Set up default values for the modem.
@ -195,7 +249,7 @@ int main(int argc, char **argv)
modem.achan[chan].baud = DEFAULT_BAUD; /* -b option */
}
modem.achan[0].medium = MEDIUM_RADIO;
modem.chan_medium[0] = MEDIUM_RADIO;
/*
@ -227,7 +281,7 @@ int main(int argc, char **argv)
/* ':' following option character means arg is required. */
c = getopt_long(argc, argv, "gjJm:s:a:b:B:r:n:N:o:z:82M:X:",
c = getopt_long(argc, argv, "gjJm:s:a:b:B:r:n:N:o:z:82M:X:I:i:v:",
long_options, &option_index);
if (c == -1)
break;
@ -266,23 +320,31 @@ int main(int argc, char **argv)
// FIXME: options should not be order dependent.
modem.achan[0].baud = atoi(optarg);
if (strcasecmp(optarg, "EAS") == 0) {
modem.achan[0].baud = 0xEA5EA5; // See special case below.
}
else {
modem.achan[0].baud = atoi(optarg);
}
text_color_set(DW_COLOR_INFO);
dw_printf ("Data rate set to %d bits / second.\n", modem.achan[0].baud);
if (modem.achan[0].baud != 100 && (modem.achan[0].baud < MIN_BAUD || modem.achan[0].baud > MAX_BAUD)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
exit (EXIT_FAILURE);
}
/* We have similar logic in direwolf.c, config.c, gen_packets.c, and atest.c, */
/* that need to be kept in sync. Maybe it could be a common function someday. */
if (modem.achan[0].baud == 100) {
if (modem.achan[0].baud == 100) { // What was this for?
modem.achan[0].modem_type = MODEM_AFSK;
modem.achan[0].mark_freq = 1615;
modem.achan[0].space_freq = 1785;
}
else if (modem.achan[0].baud == 0xEA5EA5) {
modem.achan[0].baud = 521; // Fine tuned later. 520.83333
// Proper fix is to make this float.
modem.achan[0].modem_type = MODEM_EAS;
modem.achan[0].mark_freq = 2083.3333; // Ideally these should be floating point.
modem.achan[0].space_freq = 1562.5000 ;
}
else if (modem.achan[0].baud < 600) {
modem.achan[0].modem_type = MODEM_AFSK;
modem.achan[0].mark_freq = 1600; // Typical for HF SSB
@ -318,6 +380,11 @@ int main(int argc, char **argv)
text_color_set(DW_COLOR_INFO);
dw_printf ("Using scrambled baseband signal rather than AFSK.\n");
}
if (modem.achan[0].baud != 100 && (modem.achan[0].baud < MIN_BAUD || modem.achan[0].baud > MAX_BAUD)) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Use a more reasonable bit rate in range of %d - %d.\n", MIN_BAUD, MAX_BAUD);
exit (EXIT_FAILURE);
}
break;
case 'g': /* -g for g3ruh scrambling */
@ -424,7 +491,7 @@ int main(int argc, char **argv)
case '2': /* -2 for 2 channels of sound */
modem.adev[0].num_channels = 2;
modem.achan[1].medium = MEDIUM_RADIO;
modem.chan_medium[1] = MEDIUM_RADIO;
text_color_set(DW_COLOR_INFO);
dw_printf("2 channels of sound rather than 1.\n");
break;
@ -453,9 +520,29 @@ int main(int argc, char **argv)
case 'X':
modem.fx25_xmit_enable = atoi(optarg);
X_opt = atoi(optarg);
break;
case 'I': // IL2P, normal polarity
I_opt = atoi(optarg);
break;
case 'i': // IL2P, inverted polarity
i_opt = atoi(optarg);
break;
case 'v': // Variable speed data + an - this percentage
// optional comma and increment.
variable_speed_max_error = fabs(atof(optarg));
char *q = strchr(optarg, ',');
if (q != NULL) {
variable_speed_increment = fabs(atof(q+1));
}
break;
case '?':
/* Unknown option message was already printed. */
@ -466,7 +553,7 @@ int main(int argc, char **argv)
/* Should not be here. */
text_color_set(DW_COLOR_ERROR);
dw_printf("?? getopt returned character code 0%o ??\n", c);
dw_printf("?? getopt returned character code 0%o ??\n", (unsigned)c);
usage (argv);
}
}
@ -507,6 +594,43 @@ int main(int argc, char **argv)
exit (1);
}
if (X_opt > 0) {
if (I_opt != -1 || i_opt != -1) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Can't mix -X with -I or -i.\n");
exit (EXIT_FAILURE);
}
modem.achan[0].fx25_strength = X_opt;
modem.achan[0].layer2_xmit = LAYER2_FX25;
}
if (I_opt != -1 && i_opt != -1) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Can't use both -I and -i at the same time.\n");
exit (EXIT_FAILURE);
}
if (I_opt >= 0) {
text_color_set(DW_COLOR_INFO);
dw_printf ("Using IL2P normal polarity.\n");
modem.achan[0].layer2_xmit = LAYER2_IL2P;
modem.achan[0].il2p_max_fec = (I_opt > 0);
modem.achan[0].il2p_invert_polarity = 0; // normal
}
if (i_opt >= 0) {
text_color_set(DW_COLOR_INFO);
dw_printf ("Using IL2P inverted polarity.\n");
modem.achan[0].layer2_xmit = LAYER2_IL2P;
modem.achan[0].il2p_max_fec = (i_opt > 0);
modem.achan[0].il2p_invert_polarity = 1; // invert for transmit
if (modem.achan[0].baud == 1200) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Using -i with 1200 bps is a bad idea. Use -I instead.\n");
}
}
/*
* Open the output file.
*/
@ -536,6 +660,7 @@ int main(int argc, char **argv)
// Just use the default of minimal information.
fx25_init (1);
il2p_init (0); // There are no "-d" options so far but it could be handy here.
assert (modem.adev[0].bits_per_sample == 8 || modem.adev[0].bits_per_sample == 16);
assert (modem.adev[0].num_channels == 1 || modem.adev[0].num_channels == 2);
@ -596,9 +721,35 @@ int main(int argc, char **argv)
*/
text_color_set(DW_COLOR_INFO);
dw_printf ("built in message...\n");
if (packet_count > 0) {
//
// Generate packets with variable speed.
// This overrides any other number of packets or adding noise.
//
if (variable_speed_max_error != 0) {
int normal_speed = modem.achan[0].baud;
text_color_set(DW_COLOR_INFO);
dw_printf ("Variable speed.\n");
for (double speed_error = - variable_speed_max_error;
speed_error <= variable_speed_max_error + 0.001;
speed_error += variable_speed_increment) {
// Baud is int so we get some roundoff. Make it real?
modem.achan[0].baud = (int)round(normal_speed * (1. + speed_error / 100.));
gen_tone_init (&modem, amplitude/2, 1);
char stemp[256];
snprintf (stemp, sizeof(stemp), "WB2OSZ-15>TEST:, speed %+0.1f%% The quick brown fox jumps over the lazy dog!", speed_error);
send_packet (stemp);
}
}
else if (packet_count > 0) {
/*
* Generate packets with increasing noise level.
@ -640,14 +791,23 @@ int main(int argc, char **argv)
}
else {
// This should send a total of 6.
// Note that sticking in the user defined type {DE is optional.
if (modem.achan[0].modem_type == MODEM_EAS) {
send_packet ("X>X-3:{DEZCZC-WXR-RWT-033019-033017-033015-033013-033011-025011-025017-033007-033005-033003-033001-025009-025027-033009+0015-1691525-KGYX/NWS-");
send_packet ("X>X-2:{DENNNN");
send_packet ("X>X:NNNN");
}
else {
/*
* Builtin default 4 packets.
*/
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 1 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 2 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 3 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 4 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 1 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 2 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 3 of 4");
send_packet ("WB2OSZ-15>TEST:,The quick brown fox jumps over the lazy dog! 4 of 4");
}
}
audio_file_close();
@ -665,11 +825,13 @@ static void usage (char **argv)
dw_printf ("Options:\n");
dw_printf (" -a <number> Signal amplitude in range of 0 - 200%%. Default 50.\n");
dw_printf (" -b <number> Bits / second for data. Default is %d.\n", DEFAULT_BAUD);
dw_printf (" -B <number> Bits / second for data. Proper modem selected for 300, 1200, 2400, 4800, 9600.\n");
dw_printf (" -B <number> Bits / second for data. Proper modem selected for 300, 1200, 2400, 4800, 9600, EAS.\n");
dw_printf (" -g Scrambled baseband rather than AFSK.\n");
dw_printf (" -j 2400 bps QPSK compatible with direwolf <= 1.5.\n");
dw_printf (" -J 2400 bps QPSK compatible with MFJ-2400.\n");
dw_printf (" -X n Generate FX.25 frames. Specify number of check bytes: 16, 32, or 64.\n");
dw_printf (" -X n 1 to enable FX.25 transmit. 16, 32, 64 for specific number of check bytes.\n");
dw_printf (" -I n Enable IL2P transmit. n=1 is recommended. 0 uses weaker FEC.\n");
dw_printf (" -i n Enable IL2P transmit, inverted polarity. n=1 is recommended. 0 uses weaker FEC.\n");
dw_printf (" -m <number> Mark frequency. Default is %d.\n", DEFAULT_MARK_FREQ);
dw_printf (" -s <number> Space frequency. Default is %d.\n", DEFAULT_SPACE_FREQ);
dw_printf (" -r <number> Audio sample Rate. Default is %d.\n", DEFAULT_SAMPLES_PER_SEC);
@ -677,6 +839,7 @@ static void usage (char **argv)
dw_printf (" -o <file> Send output to .wav file.\n");
dw_printf (" -8 8 bit audio rather than 16.\n");
dw_printf (" -2 2 channels (stereo) audio rather than one channel.\n");
dw_printf (" -v max[,incr] Variable speed with specified maximum error and increment.\n");
// dw_printf (" -z <number> Number of leading zero bits before frame.\n");
// dw_printf (" Default is 12 which is .01 seconds at 1200 bits/sec.\n");
@ -685,6 +848,7 @@ static void usage (char **argv)
dw_printf ("the default built-in message. The format should correspond to\n");
dw_printf ("the standard packet monitoring representation such as,\n\n");
dw_printf (" WB2OSZ-1>APDW12,WIDE2-2:!4237.14NS07120.83W#\n");
dw_printf ("User defined content can't be used with -n option.\n");
dw_printf ("\n");
dw_printf ("Example: gen_packets -o x.wav \n");
dw_printf ("\n");

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2014, 2015, 2016, 2019 John Langner, WB2OSZ
// Copyright (C) 2011, 2014, 2015, 2016, 2019, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -70,6 +70,7 @@ static int ticks_per_sample[MAX_CHANS]; /* Same for both channels of same soundc
static int ticks_per_bit[MAX_CHANS];
static int f1_change_per_sample[MAX_CHANS];
static int f2_change_per_sample[MAX_CHANS];
static float samples_per_symbol[MAX_CHANS];
static short sine_table[256];
@ -164,7 +165,7 @@ int gen_tone_init (struct audio_s *audio_config_p, int amp, int gen_packets)
for (chan = 0; chan < MAX_CHANS; chan++) {
if (audio_config_p->achan[chan].medium == MEDIUM_RADIO) {
if (audio_config_p->chan_medium[chan] == MEDIUM_RADIO) {
int a = ACHAN2ADEV(chan);
@ -198,8 +199,11 @@ int gen_tone_init (struct audio_s *audio_config_p, int amp, int gen_packets)
ticks_per_bit[chan] = (int) ((TICKS_PER_CYCLE / ((double)audio_config_p->achan[chan].baud * 0.5)) + 0.5);
f1_change_per_sample[chan] = (int) (((double)audio_config_p->achan[chan].mark_freq * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
f2_change_per_sample[chan] = f1_change_per_sample[chan]; // Not used.
samples_per_symbol[chan] = 2. * (float)audio_config_p->adev[a].samples_per_sec / (float)audio_config_p->achan[chan].baud;
tone_phase[chan] = PHASE_SHIFT_45; // Just to mimic first attempt.
// ??? Why? We are only concerned with the difference
// from one symbol to the next.
break;
case MODEM_8PSK:
@ -211,6 +215,7 @@ int gen_tone_init (struct audio_s *audio_config_p, int amp, int gen_packets)
ticks_per_bit[chan] = (int) ((TICKS_PER_CYCLE / ((double)audio_config_p->achan[chan].baud / 3.)) + 0.5);
f1_change_per_sample[chan] = (int) (((double)audio_config_p->achan[chan].mark_freq * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
f2_change_per_sample[chan] = f1_change_per_sample[chan]; // Not used.
samples_per_symbol[chan] = 3. * (float)audio_config_p->adev[a].samples_per_sec / (float)audio_config_p->achan[chan].baud;
break;
case MODEM_BASEBAND:
@ -220,11 +225,23 @@ int gen_tone_init (struct audio_s *audio_config_p, int amp, int gen_packets)
// Tone is half baud.
ticks_per_bit[chan] = (int) ((TICKS_PER_CYCLE / (double)audio_config_p->achan[chan].baud ) + 0.5);
f1_change_per_sample[chan] = (int) (((double)audio_config_p->achan[chan].baud * 0.5 * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
samples_per_symbol[chan] = (float)audio_config_p->adev[a].samples_per_sec / (float)audio_config_p->achan[chan].baud;
break;
case MODEM_EAS: // EAS.
// TODO: Proper fix would be to use float for baud, mark, space.
ticks_per_bit[chan] = (int) ((TICKS_PER_CYCLE / 520.833333333333 ) + 0.5);
samples_per_symbol[chan] = (int)((audio_config_p->adev[a].samples_per_sec / 520.83333) + 0.5);
f1_change_per_sample[chan] = (int) ((2083.33333333333 * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
f2_change_per_sample[chan] = (int) ((1562.5000000 * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
break;
default: // AFSK
ticks_per_bit[chan] = (int) ((TICKS_PER_CYCLE / (double)audio_config_p->achan[chan].baud ) + 0.5);
samples_per_symbol[chan] = (float)audio_config_p->adev[a].samples_per_sec / (float)audio_config_p->achan[chan].baud;
f1_change_per_sample[chan] = (int) (((double)audio_config_p->achan[chan].mark_freq * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
f2_change_per_sample[chan] = (int) (((double)audio_config_p->achan[chan].space_freq * TICKS_PER_CYCLE / (double)audio_config_p->adev[a].samples_per_sec ) + 0.5);
break;
@ -285,9 +302,64 @@ int gen_tone_init (struct audio_s *audio_config_p, int amp, int gen_packets)
*
*--------------------------------------------------------------------*/
// Interpolate between two values.
// My original approximation simply jumped between phases, producing a discontinuity,
// and increasing bandwidth.
// According to multiple sources, we should transition more gently.
// Below see see a rough approximation of:
// * A step function, immediately going to new value.
// * Linear interpoation.
// * Raised cosine. Square root of cosine is also mentioned.
//
// new - / --
// | / /
// | / |
// | / /
// old ------- / --
// step linear raised cosine
//
// Inputs are the old (previous value), new value, and a blending control
// 0 -> take old value
// 1 -> take new value.
// inbetween some sort of weighted average.
static inline float interpol8 (float oldv, float newv, float bc)
{
// Step function.
//return (newv); // 78 on 11/7
assert (bc >= 0);
assert (bc <= 1.1);
if (bc < 0) return (oldv);
if (bc > 1) return (newv);
// Linear interpolation, just for comparison.
//return (bc * newv + (1.0f - bc) * oldv); // 39 on 11/7
float rc = 0.5f * (cosf(bc * M_PI - M_PI) + 1.0f);
float rrc = bc >= 0.5f
? 0.5f * (sqrtf(fabsf(cosf(bc * M_PI - M_PI))) + 1.0f)
: 0.5f * (-sqrtf(fabsf(cosf(bc * M_PI - M_PI))) + 1.0f);
(void)rrc;
return (rc * newv + (1.0f - bc) * oldv); // 49 on 11/7
//return (rrc * newv + (1.0f - bc) * oldv); // 55 on 11/7
}
static const int gray2phase_v26[4] = {0, 1, 3, 2};
static const int gray2phase_v27[8] = {1, 0, 2, 3, 6, 7, 5, 4};
// #define PSKIQ 1 // not ready for prime time yet.
#if PSKIQ
static int xmit_octant[MAX_CHANS]; // absolute phase in 45 degree units.
static int xmit_prev_octant[MAX_CHANS]; // from previous symbol.
// For PSK, we generate the final signal by combining fixed frequency cosine and
// sine by the following weights.
static const float ci[8] = { 1, .7071, 0, -.7071, -1, -.7071, 0, .7071 };
static const float sq[8] = { 0, .7071, 1, .7071, 0, -.7071, -1, -.7071 };
#endif
void tone_gen_put_bit (int chan, int dat)
{
@ -295,7 +367,7 @@ void tone_gen_put_bit (int chan, int dat)
assert (save_audio_config_p != NULL);
if (save_audio_config_p->achan[chan].medium != MEDIUM_RADIO) {
if (save_audio_config_p->chan_medium[chan] != MEDIUM_RADIO) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Invalid channel %d for tone generation.\n", chan);
return;
@ -324,14 +396,28 @@ void tone_gen_put_bit (int chan, int dat)
// All zero bits should give us steady 1800 Hz.
// All one bits should flip phase by 180 degrees each time.
// For V.26B, add another 45 degrees.
// This seems to work a little better.
dibit = (save_bit[chan] << 1) | dat;
symbol = gray2phase_v26[dibit];
symbol = gray2phase_v26[dibit]; // 0 .. 3 for QPSK.
#if PSKIQ
// One phase shift unit is 45 degrees.
// Remember what it was last time and calculate new.
// values 0 .. 7.
xmit_prev_octant[chan] = xmit_octant[chan];
xmit_octant[chan] += symbol * 2;
if (save_audio_config_p->achan[chan].v26_alternative == V26_B) {
xmit_octant[chan] += 1;
}
xmit_octant[chan] &= 0x7;
#else
tone_phase[chan] += symbol * PHASE_SHIFT_90;
if (save_audio_config_p->achan[chan].v26_alternative == V26_B) {
tone_phase[chan] += PHASE_SHIFT_45;
}
#endif
bit_count[chan]++;
}
@ -360,14 +446,19 @@ void tone_gen_put_bit (int chan, int dat)
bit_count[chan] = 0;
}
if (save_audio_config_p->achan[chan].modem_type == MODEM_SCRAMBLE) {
// Would be logical to have MODEM_BASEBAND for IL2P rather than checking here. But...
// That would mean putting in at least 3 places and testing all rather than just one.
if (save_audio_config_p->achan[chan].modem_type == MODEM_SCRAMBLE &&
save_audio_config_p->achan[chan].layer2_xmit != LAYER2_IL2P) {
int x;
x = (dat ^ (lfsr[chan] >> 16) ^ (lfsr[chan] >> 11)) & 1;
lfsr[chan] = (lfsr[chan] << 1) | (x & 1);
dat = x;
}
#if PSKIQ
int blend = 1;
#endif
do { /* until enough audio samples for this symbol. */
int sam;
@ -380,14 +471,70 @@ void tone_gen_put_bit (int chan, int dat)
text_color_set(DW_COLOR_DEBUG);
dw_printf ("tone_gen_put_bit %d AFSK\n", __LINE__);
#endif
tone_phase[chan] += dat ? f2_change_per_sample[chan] : f1_change_per_sample[chan];
// v1.7 reversed.
// Previously a data '1' selected the second (usually higher) tone.
// It never really mattered before because we were using NRZI.
// With the addition of IL2P, we need to be more careful.
// A data '1' should be the mark tone.
tone_phase[chan] += dat ? f1_change_per_sample[chan] : f2_change_per_sample[chan];
sam = sine_table[(tone_phase[chan] >> 24) & 0xff];
gen_tone_put_sample (chan, a, sam);
break;
case MODEM_EAS:
tone_phase[chan] += dat ? f1_change_per_sample[chan] : f2_change_per_sample[chan];
sam = sine_table[(tone_phase[chan] >> 24) & 0xff];
gen_tone_put_sample (chan, a, sam);
break;
case MODEM_QPSK:
case MODEM_8PSK:
#if DEBUG2
text_color_set(DW_COLOR_DEBUG);
dw_printf ("tone_gen_put_bit %d PSK\n", __LINE__);
#endif
tone_phase[chan] += f1_change_per_sample[chan];
#if PSKIQ
#if 1 // blend JWL
// remove loop invariant
float old_i = ci[xmit_prev_octant[chan]];
float old_q = sq[xmit_prev_octant[chan]];
float new_i = ci[xmit_octant[chan]];
float new_q = sq[xmit_octant[chan]];
float b = blend / samples_per_symbol[chan]; // roughly 0 to 1
blend++;
// b = (b - 0.5) * 20 + 0.5;
// if (b < 0) b = 0;
// if (b > 1) b = 1;
// b = b > 0.5;
//b = 1; // 78 decoded with this.
// only 39 without.
//float blended_i = new_i * b + old_i * (1.0f - b);
//float blended_q = new_q * b + old_q * (1.0f - b);
float blended_i = interpol8 (old_i, new_i, b);
float blended_q = interpol8 (old_q, new_q, b);
sam = blended_i * sine_table[((tone_phase[chan] - PHASE_SHIFT_90) >> 24) & 0xff] +
blended_q * sine_table[(tone_phase[chan] >> 24) & 0xff];
#else // jump
sam = ci[xmit_octant[chan]] * sine_table[((tone_phase[chan] - PHASE_SHIFT_90) >> 24) & 0xff] +
sq[xmit_octant[chan]] * sine_table[(tone_phase[chan] >> 24) & 0xff];
#endif
#else
sam = sine_table[(tone_phase[chan] >> 24) & 0xff];
#endif
gen_tone_put_sample (chan, a, sam);
break;
case MODEM_8PSK:
#if DEBUG2
text_color_set(DW_COLOR_DEBUG);
dw_printf ("tone_gen_put_bit %d PSK\n", __LINE__);
@ -511,6 +658,20 @@ void gen_tone_put_sample (int chan, int a, int sam) {
}
}
void gen_tone_put_quiet_ms (int chan, int time_ms) {
int a = ACHAN2ADEV(chan); /* device for channel. */
int sam = 0;
int nsamples = (int) ((time_ms * (float)save_audio_config_p->adev[a].samples_per_sec / 1000.) + 0.5);
for (int j=0; j<nsamples; j++) {
gen_tone_put_sample (chan, a, sam);
};
// Avoid abrupt change when it starts up again.
tone_phase[chan] = 0;
}
/*-------------------------------------------------------------------

View File

@ -14,4 +14,6 @@ int gen_tone_init (struct audio_s *pp, int amp, int gen_packets);
void tone_gen_put_bit (int chan, int dat);
void gen_tone_put_sample (int chan, int a, int sam);
void gen_tone_put_sample (int chan, int a, int sam);
void gen_tone_put_quiet_ms (int chan, int time_ms);

View File

@ -433,9 +433,9 @@ static const symbol_type_t grm_alternate_symtab[SYMTAB_SIZE] = {
sym_park, // ; 27 Park/Picnic area
sym_default, // < 28 ADVISORY (one WX flag)
sym_rbcn, // = 29 APRStt Touchtone (DTMF users)
sym_car, // > 30 OVERLAYED CAR
sym_car, // > 30 OVERLAID CAR
sym_default, // ? 31 INFO Kiosk (Blue box with ?)
sym_default, // @ 32 HURICANE/Trop-Storm
sym_default, // @ 32 HURRICANE/Trop-Storm
sym_default, // A 33 overlayBOX DTMF & RFID & XO
sym_default, // B 34 Blwng Snow (& future codes)
sym_coast_guard, // C 35 Coast Guard
@ -445,7 +445,7 @@ static const symbol_type_t grm_alternate_symtab[SYMTAB_SIZE] = {
sym_default, // G 39 Snow Shwr (& future ovrlys)
sym_default, // H 40 Haze (& Overlay Hazards)
sym_default, // I 41 Rain Shower
sym_default, // J 42 Lightening (& future ovrlys)
sym_default, // J 42 Lightning (& future ovrlys)
sym_rbcn, // K 43 Kenwood HT (W)
sym_light, // L 44 Lighthouse
sym_default, // M 45 MARS (A=Army,N=Navy,F=AF)
@ -488,12 +488,12 @@ static const symbol_type_t grm_alternate_symtab[SYMTAB_SIZE] = {
sym_restrooms, // r 82 Restrooms
sym_default, // s 83 OVERLAY SHIP/boat (top view)
sym_default, // t 84 Tornado
sym_car, // u 85 OVERLAYED TRUCK
sym_car, // v 86 OVERLAYED Van
sym_car, // u 85 OVERLAID TRUCK
sym_car, // v 86 OVERLAID Van
sym_default, // w 87 Flooding
sym_wreck, // x 88 Wreck or Obstruction ->X<-
sym_default, // y 89 Skywarn
sym_default, // z 90 OVERLAYED Shelter
sym_default, // z 90 OVERLAID Shelter
sym_default, // { 91 Fog (& future ovrly codes)
sym_default, // | 92 TNC Stream Switch
sym_default, // } 93

View File

@ -46,6 +46,7 @@
#include "demod_9600.h" /* for descramble() */
#include "ptt.h"
#include "fx25.h"
#include "il2p.h"
//#define TEST 1 /* Define for unit testing. */
@ -151,7 +152,7 @@ void hdlc_rec_init (struct audio_s *pa)
for (ch = 0; ch < MAX_CHANS; ch++)
{
if (pa->achan[ch].medium == MEDIUM_RADIO) {
if (pa->chan_medium[ch] == MEDIUM_RADIO) {
num_subchan[ch] = pa->achan[ch].num_subchan;
@ -496,6 +497,7 @@ void hdlc_rec_bit (int chan, int subchan, int slice, int raw, int is_scrambled,
if (g_audio_p->achan[chan].modem_type != MODEM_AIS) {
fx25_rec_bit (chan, subchan, slice, dbit);
il2p_rec_bit (chan, subchan, slice, raw); // Note: skip NRZI.
}
/*
@ -759,7 +761,7 @@ void dcd_change (int chan, int subchan, int slice, int state)
*
* Name: hdlc_rec_data_detect_any
*
* Purpose: Determine if the radio channel is curently busy
* Purpose: Determine if the radio channel is currently busy
* with packet data.
* This version doesn't care about voice or other sounds.
* This is used by the transmit logic to transmit only
@ -774,7 +776,7 @@ void dcd_change (int chan, int subchan, int slice, int state)
* Description: We have two different versions here.
*
* hdlc_rec_data_detect_any sees if ANY of the decoders
* for this channel are receving a signal. This is
* for this channel are receiving a signal. This is
* used to determine whether the channel is clear and
* we can transmit. This would apply to the 300 baud
* HF SSB case where we have multiple decoders running

View File

@ -273,7 +273,7 @@ void hdlc_rec2_block (rrbb_t block)
}
/*
* Not successful with frame in orginal form.
* Not successful with frame in original form.
* See if we can "fix" it.
*/
if (try_to_fix_quick_now (block, chan, subchan, slice, alevel)) {

View File

@ -6,6 +6,7 @@
#include "ax25_pad.h" /* for packet_t, alevel_t */
#include "rrbb.h"
#include "audio.h" /* for struct audio_s */
#include "dlq.h" // for fec_type_t definition.
@ -62,6 +63,6 @@ int hdlc_rec2_try_to_fix_later (rrbb_t block, int chan, int subchan, int slice,
/* Provided by the top level application to process a complete frame. */
void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alevel_t level, int is_fx25, retry_t retries, char *spectrum);
void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alevel_t level, fec_type_t fec_type, retry_t retries, char *spectrum);
#endif

View File

@ -2,7 +2,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2013, 2014, 2019 John Langner, WB2OSZ
// Copyright (C) 2011, 2013, 2014, 2019, 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -27,37 +27,37 @@
#include "gen_tone.h"
#include "textcolor.h"
#include "fcs_calc.h"
#include "ax25_pad.h"
#include "fx25.h"
#include "il2p.h"
static void send_control (int, int);
static void send_data (int, int);
static void send_bit (int, int);
static void send_byte_msb_first (int chan, int x, int polarity);
static void send_control_nrzi (int, int);
static void send_data_nrzi (int, int);
static void send_bit_nrzi (int, int);
static int number_of_bits_sent[MAX_CHANS]; // Count number of bits sent by "hdlc_send_frame" or "hdlc_send_flags"
static int number_of_bits_sent[MAX_CHANS]; // Count number of bits sent by "hdlc_send_frame" or "hdlc_send_flags"
/*-------------------------------------------------------------
*
* Name: hdlc_send
* Name: layer2_send_frame
*
* Purpose: Convert HDLC frames to a stream of bits.
* Purpose: Convert frames to a stream of bits.
* Originally this was for AX.25 only, hence the file name.
* Over time, FX.25 and IL2P were shoehorned in.
*
* Inputs: chan - Audio channel number, 0 = first.
*
* fbuf - Frame buffer address.
*
* flen - Frame length, not including the FCS.
* pp - Packet object.
*
* bad_fcs - Append an invalid FCS for testing purposes.
* Applies only to regular AX.25.
*
* fx25_xmit_enable - Just like the name says.
*
* Outputs: Bits are shipped out by calling tone_gen_put_bit().
*
* Returns: Number of bits sent including "flags" and the
@ -65,12 +65,12 @@ static int number_of_bits_sent[MAX_CHANS]; // Count number of bits sent by "hdl
* The required time can be calculated by dividing this
* number by the transmit rate of bits/sec.
*
* Description: Convert to stream of bits including:
* Description: For AX.25, send:
* start flag
* bit stuffed data
* calculated FCS
* end flag
* NRZI encoding
* NRZI encoding for all but the "flags."
*
*
* Assumptions: It is assumed that the tone_gen module has been
@ -81,23 +81,40 @@ static int number_of_bits_sent[MAX_CHANS]; // Count number of bits sent by "hdl
static int ax25_only_hdlc_send_frame (int chan, unsigned char *fbuf, int flen, int bad_fcs);
// New in 1.6: Option to encapsulate in FX.25.
int hdlc_send_frame (int chan, unsigned char *fbuf, int flen, int bad_fcs, int fx25_xmit_enable)
int layer2_send_frame (int chan, packet_t pp, int bad_fcs, struct audio_s *audio_config_p)
{
if (fx25_xmit_enable) {
int n = fx25_send_frame (chan, fbuf, flen, fx25_xmit_enable);
if (audio_config_p->achan[chan].layer2_xmit == LAYER2_IL2P) {
int n = il2p_send_frame (chan, pp, audio_config_p->achan[chan].il2p_max_fec,
audio_config_p->achan[chan].il2p_invert_polarity);
if (n > 0) {
return (n);
}
text_color_set(DW_COLOR_ERROR);
dw_printf ("Unable to send IL2p frame. Falling back to regular AX.25.\n");
// Not sure if we should fall back to AX.25 or not here.
}
else if (audio_config_p->achan[chan].layer2_xmit == LAYER2_FX25) {
unsigned char fbuf[AX25_MAX_PACKET_LEN+2];
int flen = ax25_pack (pp, fbuf);
int n = fx25_send_frame (chan, fbuf, flen, audio_config_p->achan[chan].fx25_strength);
if (n > 0) {
return (n);
}
text_color_set(DW_COLOR_ERROR);
dw_printf ("Unable to send FX.25. Falling back to regular AX.25.\n");
// Definitely need to fall back to AX.25 here because
// the FX.25 frame length is so limited.
}
unsigned char fbuf[AX25_MAX_PACKET_LEN+2];
int flen = ax25_pack (pp, fbuf);
return (ax25_only_hdlc_send_frame (chan, fbuf, flen, bad_fcs));
}
static int ax25_only_hdlc_send_frame (int chan, unsigned char *fbuf, int flen, int bad_fcs)
{
int j, fcs;
@ -105,33 +122,31 @@ static int ax25_only_hdlc_send_frame (int chan, unsigned char *fbuf, int flen, i
number_of_bits_sent[chan] = 0;
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("hdlc_send_frame ( chan = %d, fbuf = %p, flen = %d, bad_fcs = %d)\n", chan, fbuf, flen, bad_fcs);
fflush (stdout);
#endif
send_control (chan, 0x7e); /* Start frame */
send_control_nrzi (chan, 0x7e); /* Start frame */
for (j=0; j<flen; j++) {
send_data (chan, fbuf[j]);
send_data_nrzi (chan, fbuf[j]);
}
fcs = fcs_calc (fbuf, flen);
if (bad_fcs) {
/* For testing only - Simulate a frame getting corrupted along the way. */
send_data (chan, (~fcs) & 0xff);
send_data (chan, ((~fcs) >> 8) & 0xff);
send_data_nrzi (chan, (~fcs) & 0xff);
send_data_nrzi (chan, ((~fcs) >> 8) & 0xff);
}
else {
send_data (chan, fcs & 0xff);
send_data (chan, (fcs >> 8) & 0xff);
send_data_nrzi (chan, fcs & 0xff);
send_data_nrzi (chan, (fcs >> 8) & 0xff);
}
send_control (chan, 0x7e); /* End frame */
send_control_nrzi (chan, 0x7e); /* End frame */
return (number_of_bits_sent[chan]);
}
@ -139,22 +154,25 @@ static int ax25_only_hdlc_send_frame (int chan, unsigned char *fbuf, int flen, i
/*-------------------------------------------------------------
*
* Name: hdlc_send_flags
* Name: layer2_preamble_postamble
*
* Purpose: Send HDLC flags before and after the frame.
* Purpose: Send filler pattern before and after the frame.
* For HDLC it is 01111110, for IL2P 01010101.
*
* Inputs: chan - Audio channel number, 0 = first.
*
* nflags - Number of flag patterns to send.
* nbytes - Number of bytes to send.
*
* finish - True for end of transmission.
* This causes the last audio buffer to be flushed.
*
* audio_config_p - Configuration for audio and modems.
*
* Outputs: Bits are shipped out by calling tone_gen_put_bit().
*
* Returns: Number of bits sent.
* There is no bit-stuffing so we would expect this to
* be 8 * nflags.
* be 8 * nbytes.
* The required time can be calculated by dividing this
* number by the transmit rate of bits/sec.
*
@ -164,25 +182,30 @@ static int ax25_only_hdlc_send_frame (int chan, unsigned char *fbuf, int flen, i
*
*--------------------------------------------------------------*/
int hdlc_send_flags (int chan, int nflags, int finish)
int layer2_preamble_postamble (int chan, int nbytes, int finish, struct audio_s *audio_config_p)
{
int j;
number_of_bits_sent[chan] = 0;
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("hdlc_send_flags ( chan = %d, nflags = %d, finish = %d )\n", chan, nflags, finish);
fflush (stdout);
#endif
/* The AX.25 spec states that when the transmitter is on but not sending data */
/* it should send a continuous stream of "flags." */
// When the transmitter is on but not sending data, it should be sending
// a stream of a filler pattern.
// For AX.25, it is the 01111110 "flag" pattern with NRZI and no bit stuffing.
// For IL2P, it is 01010101 without NRZI.
for (j=0; j<nflags; j++) {
send_control (chan, 0x7e);
for (j=0; j<nbytes; j++) {
if (audio_config_p->achan[chan].layer2_xmit == LAYER2_IL2P) {
send_byte_msb_first (chan, IL2P_PREAMBLE, audio_config_p->achan[chan].il2p_invert_polarity);
}
else {
send_control_nrzi (chan, 0x7e);
}
}
/* Push out the final partial buffer! */
@ -196,33 +219,54 @@ int hdlc_send_flags (int chan, int nflags, int finish)
// The next one is only for IL2P. No NRZI.
// MSB first, opposite of AX.25.
static void send_byte_msb_first (int chan, int x, int polarity)
{
int i;
for (i=0; i<8; i++) {
int dbit = (x & 0x80) != 0;
tone_gen_put_bit (chan, (dbit ^ polarity) & 1);
x <<= 1;
number_of_bits_sent[chan]++;
}
}
// The following are only for HDLC.
// All bits are sent NRZI.
// Data (non flags) use bit stuffing.
static int stuff[MAX_CHANS]; // Count number of "1" bits to keep track of when we
// need to break up a long run by "bit stuffing."
// Needs to be array because we could be transmitting
// on multiple channels at the same time.
static void send_control (int chan, int x)
static void send_control_nrzi (int chan, int x)
{
int i;
for (i=0; i<8; i++) {
send_bit (chan, x & 1);
send_bit_nrzi (chan, x & 1);
x >>= 1;
}
stuff[chan] = 0;
}
static void send_data (int chan, int x)
static void send_data_nrzi (int chan, int x)
{
int i;
for (i=0; i<8; i++) {
send_bit (chan, x & 1);
send_bit_nrzi (chan, x & 1);
if (x & 1) {
stuff[chan]++;
if (stuff[chan] == 5) {
send_bit (chan, 0);
send_bit_nrzi (chan, 0);
stuff[chan] = 0;
}
} else {
@ -238,7 +282,7 @@ static void send_data (int chan, int x)
* data 0 bit -> invert signal.
*/
static void send_bit (int chan, int b)
static void send_bit_nrzi (int chan, int b)
{
static int output[MAX_CHANS];
@ -251,4 +295,82 @@ static void send_bit (int chan, int b)
number_of_bits_sent[chan]++;
}
/* end hdlc_send.c */
// The rest of this is for EAS SAME.
// This is sort of a logical place because it serializes a frame, but not in HDLC.
// We have a parallel where SAME deserialization is in hdlc_rec.
// Maybe both should be pulled out and moved to a same.c.
/*-------------------------------------------------------------------
*
* Name: eas_send
*
* Purpose: Serialize EAS SAME for transmission.
*
* Inputs: chan - Radio channel number.
* str - Character string to send.
* repeat - Number of times to repeat with 1 sec quiet between.
* txdelay - Delay (ms) from PTT to first preamble bit.
* txtail - Delay (ms) from last data bit to PTT off.
*
*
* Returns: Total number of milliseconds to activate PTT.
* This includes delays before the first character
* and after the last to avoid chopping off part of it.
*
* Description: xmit_thread calls this instead of the usual hdlc_send
* when we have a special packet that means send EAS SAME
* code.
*
*--------------------------------------------------------------------*/
static inline void eas_put_byte (int chan, unsigned char b)
{
for (int n=0; n<8; n++) {
tone_gen_put_bit (chan, (b & 1));
b >>= 1;
}
}
int eas_send (int chan, unsigned char *str, int repeat, int txdelay, int txtail)
{
int bytes_sent = 0;
const int gap = 1000;
int gaps_sent = 0;
gen_tone_put_quiet_ms (chan, txdelay);
for (int r=0; r<repeat; r++ ) {
for (int j=0; j<16; j++) {
eas_put_byte (chan, 0xAB);
bytes_sent++;
}
for (unsigned char *p = str; *p != '\0'; p++) {
eas_put_byte (chan, *p);
bytes_sent++;
}
if (r < repeat-1) {
gen_tone_put_quiet_ms (chan, gap);
gaps_sent++;
}
}
gen_tone_put_quiet_ms (chan, txtail);
audio_flush(ACHAN2ADEV(chan));
int elapsed = txdelay + (int) (bytes_sent * 8 * 1.92) + (gaps_sent * gap) + txtail;
// dw_printf ("DEBUG: EAS total time = %d ms\n", elapsed);
return (elapsed);
} /* end eas_send */
/* end hdlc_send.c */

View File

@ -1,9 +1,21 @@
/* hdlc_send.h */
int hdlc_send_frame (int chan, unsigned char *fbuf, int flen, int bad_fcs, int fx25_xmit_enable);
// In version 1.7 an extra layer of abstraction was added here.
// Rather than calling hdlc_send_frame, we now use another function
// which sends AX.25, FX.25, or IL2P depending on mode.
int hdlc_send_flags (int chan, int flags, int finish);
// eas_send fits here logically because it also serializes a packet.
#include "ax25_pad.h"
#include "audio.h"
int layer2_send_frame (int chan, packet_t pp, int bad_fcs, struct audio_s *audio_config_p);
int layer2_preamble_postamble (int chan, int flags, int finish, struct audio_s *audio_config_p);
int eas_send (int chan, unsigned char *str, int repeat, int txdelay, int txtail);
/* end hdlc_send.h */

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2013, 2014, 2015, 2016 John Langner, WB2OSZ
// Copyright (C) 2013, 2014, 2015, 2016, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -100,6 +100,7 @@
#include "version.h"
#include "digipeater.h"
#include "tq.h"
#include "dlq.h"
#include "igate.h"
#include "latlong.h"
#include "pfilter.h"
@ -107,6 +108,7 @@
#include "mheard.h"
#if __WIN32__
static unsigned __stdcall connnect_thread (void *arg);
static unsigned __stdcall igate_recv_thread (void *arg);
@ -201,6 +203,8 @@ static char * ia_to_text (int Family, void * pAddr, char * pStringBuf, size_t S
#if ITEST
// TODO: Add to automated tests.
/* For unit testing. */
int main (int argc, char *argv[])
@ -324,7 +328,7 @@ static int stats_uplink_packets; /* Number of packets passed along to the IGate
/* server after filtering. */
static int stats_uplink_bytes; /* Total number of bytes sent to IGate server */
/* including login, packets, and hearbeats. */
/* including login, packets, and heartbeats. */
static int stats_downlink_bytes; /* Total number of bytes from IGate server including */
/* packets, heartbeats, other messages. */
@ -851,6 +855,9 @@ static void * connnect_thread (void *arg)
* Purpose: Send a packet to the IGate server
*
* Inputs: chan - Radio channel it was received on.
* This is required for the RF>IS filtering.
* Beaconing (sendto=ig, chan=-1) and a client app sending
* to ICHANNEL should bypass the filtering.
*
* recv_pp - Pointer to packet object.
* *** CALLER IS RESPONSIBLE FOR DELETING IT! **
@ -898,7 +905,12 @@ void igate_send_rec_packet (int chan, packet_t recv_pp)
* In that case, the payload will have TCPIP in the path and it will be dropped.
*/
if (save_digi_config_p->filter_str[chan][MAX_CHANS] != NULL) {
// Apply RF>IS filtering only if it same from a radio channel.
// Beacon will be channel -1.
// Client app to ICHANNEL is outside of radio channel range.
if (chan >= 0 && chan < MAX_CHANS && // in radio channel range
save_digi_config_p->filter_str[chan][MAX_CHANS] != NULL) {
if (pfilter(chan, MAX_CHANS, save_digi_config_p->filter_str[chan][MAX_CHANS], recv_pp, 1) != 1) {
@ -1217,7 +1229,7 @@ static void send_packet_to_server (packet_t pp, int chan)
* Name: send_msg_to_server
*
* Purpose: Send something to the IGate server.
* This one function should be used for login, hearbeats,
* This one function should be used for login, heartbeats,
* and packets.
*
* Inputs: imsg - Message. We will add CR/LF here.
@ -1469,7 +1481,7 @@ static void * igate_recv_thread (void *arg)
*
* Future: might have ability to configure multiple transmit
* channels, each with own client side filtering and via path.
* Loop here over all configured channels.
* If so, loop here over all configured channels.
*/
text_color_set(DW_COLOR_REC);
dw_printf ("\n[ig>tx] "); // formerly just [ig]
@ -1504,6 +1516,64 @@ static void * igate_recv_thread (void *arg)
if (to_chan >= 0) {
maybe_xmit_packet_from_igate ((char*)message, to_chan);
}
/*
* New in 1.7: If ICHANNEL was specified, send packet to client app as specified channel.
*/
if (save_audio_config_p->igate_vchannel >= 0) {
int ichan = save_audio_config_p->igate_vchannel;
// My original poorly thoughtout idea was to parse it into a packet object,
// using the non-strict option, and send to the client app.
//
// A lot of things can go wrong with that approach.
// (1) Up to 8 digipeaters are allowed in radio format.
// There is a potential of finding a larger number here.
//
// (2) The via path can have names that are not valid in the radio format.
// e.g. qAC, T2HAKATA, N5JXS-F1.
// Non-strict parsing would force uppercase, truncate names too long,
// and drop unacceptable SSIDs.
//
// (3) The source address could be invalid for the RF address format.
// e.g. WHO-IS>APJIW4,TCPIP*,qAC,AE5PL-JF::ZL1JSH-9 :Charles Beadfield/New Zealand{583
// That is essential information that we absolutely need to preserve.
//
// I think the only correct solution is to apply a third party header
// wrapper so the original contents are preserved. This will be a little
// more work for the application developer. Search for ":}" and use only
// the part after that. At this point, I don't see any value in encoding
// information in the source/destination so I will just use "X>X:}" as a prefix
char stemp[AX25_MAX_INFO_LEN];
strlcpy (stemp, "X>X:}", sizeof(stemp));
strlcat (stemp, (char*)message, sizeof(stemp));
packet_t pp3 = ax25_from_text(stemp, 0); // 0 means not strict
if (pp3 != NULL) {
alevel_t alevel;
memset (&alevel, 0, sizeof(alevel));
alevel.mark = -2; // FIXME: Do we want some other special case?
alevel.space = -2;
int subchan = -2; // FIXME: -1 is special case for APRStt.
// See what happens with -2 and follow up on this.
// Do we need something else here?
int slice = 0;
fec_type_t fec_type = fec_type_none;
char spectrum[] = "APRS-IS";
dlq_rec_frame (ichan, subchan, slice, pp3, alevel, fec_type, RETRY_NONE, spectrum);
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("ICHANNEL %d: Could not parse message from APRS-IS server.\n", ichan);
dw_printf ("%s\n", message);
}
} // end ICHANNEL option
}
} /* while (1) */
@ -1538,9 +1608,14 @@ static void * igate_recv_thread (void *arg)
* Duplicate removal will drop the original if there is no
* corresponding digipeated version.
*
*
* This was an idea that came up in one of the discussion forums.
* I rushed in without thinking about it very much.
*
* In retrospect, I don't think this was such a good idea.
* It would be of value only if there is no other IGate nearby
* that would report on the original transmission.
* I wonder if anyone would notice if this silently disappeared.
*
*--------------------------------------------------------------------*/
@ -1652,7 +1727,14 @@ static void * satgate_delay_thread (void *arg)
* K1RI-2>APWW10,WIDE1-1,WIDE2-1,qAS,K1RI:/221700h/9AmA<Ct3_ sT010/002g005t045r000p023P020h97b10148
* KC1BOS-2>T3PQ3S,WIDE1-1,WIDE2-1,qAR,W1TG-1:`c)@qh\>/"50}TinyTrak4 Mobile
*
* Notice how the final address in the header might not
* This is interesting because the source is not a valid AX.25 address.
* Non-RF stations can have 2 alphanumeric characters for SSID.
* In this example, the WHO-IS server is responding to a message.
*
* WHO-IS>APJIW4,TCPIP*,qAC,AE5PL-JF::ZL1JSH-9 :Charles Beadfield/New Zealand{583
*
*
* Notice how the final digipeater address, in the header, might not
* be a valid AX.25 address. We see a 9 character address
* (with no ssid) and an ssid of two letters.
* We don't care because we end up discarding them before
@ -1667,29 +1749,61 @@ static void * satgate_delay_thread (void *arg)
*
*--------------------------------------------------------------------*/
// It is unforunate that the : data type indicator (DTI) was overloaded with
// so many different meanings. Simply looking at the DTI is not adequate for
// determining whether a packet is a message.
// We need to exclude the other special cases of telemetry metadata,
// bulletins, and weather bulletins.
static int is_message_message (char *infop)
{
if (*infop != ':') return (0);
if (strlen(infop) < 11) return (0); // too short for : addressee :
if (strlen(infop) >= 16) {
if (strncmp(infop+10, ":PARM.", 6) == 0) return (0);
if (strncmp(infop+10, ":UNIT.", 6) == 0) return (0);
if (strncmp(infop+10, ":EQNS.", 6) == 0) return (0);
if (strncmp(infop+10, ":BITS.", 6) == 0) return (0);
}
if (strlen(infop) >= 4) {
if (strncmp(infop+1, "BLN", 3) == 0) return (0);
if (strncmp(infop+1, "NWS", 3) == 0) return (0);
if (strncmp(infop+1, "SKY", 3) == 0) return (0);
if (strncmp(infop+1, "CWA", 3) == 0) return (0);
if (strncmp(infop+1, "BOM", 3) == 0) return (0);
}
return (1); // message, including ack, rej
}
static void maybe_xmit_packet_from_igate (char *message, int to_chan)
{
packet_t pp3;
char payload[AX25_MAX_PACKET_LEN]; /* what is max len? */
char src[AX25_MAX_ADDR_LEN]; /* Source address. */
char *pinfo = NULL;
int info_len;
int n;
assert (to_chan >= 0 && to_chan < MAX_CHANS);
/*
* Try to parse it into a packet object.
* This will contain "q constructs" and we might see an address
* with two alphnumeric characters in the SSID so we must use
* the non-strict parsing.
* Try to parse it into a packet object; we need this for the packet filtering.
*
* Bug: Up to 8 digipeaters are allowed in radio format.
* There is a potential of finding a larger number here.
* We use the non-strict option because there the via path can have:
* - station names longer than 6.
* - alphanumeric SSID.
* - lower case for "q constructs.
* We don't care about any of those because the via path will be discarded anyhow.
*
* The other issue, that I did not think of originally, is that the "source"
* address might not conform to AX.25 restrictions when it originally came
* from a non-RF source. For example an APRS "message" might be sent to the
* "WHO-IS" server, and the reply message would have that for the source address.
*
* Originally, I used the source address from the packet object but that was
* missing the alphanumeric SSID. This needs to be done differently.
*
* Potential Bug: Up to 8 digipeaters are allowed in radio format.
* Is there a possibility of finding a larger number here?
*/
pp3 = ax25_from_text(message, 0);
packet_t pp3 = ax25_from_text(message, 0);
if (pp3 == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Tx IGate: Could not parse message from server.\n");
@ -1697,7 +1811,18 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
return;
}
ax25_get_addr_with_ssid (pp3, AX25_SOURCE, src);
// Issue 408: The source address might not be valid AX.25 because it
// came from a non-RF station. e.g. some server responding to a message.
// We need to take source address from original rather than extracting it
// from the packet object.
char src[AX25_MAX_ADDR_LEN]; /* Source address. */
memset (src, 0, sizeof(src));
memcpy (src, message, sizeof(src)-1);
char *gt = strchr(src, '>');
if (gt != NULL) {
*gt = '\0';
}
/*
* Drop if path contains:
@ -1709,8 +1834,8 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
ax25_get_addr_with_ssid (pp3, n + AX25_REPEATER_1, via);
if (strcmp(via, "qAX") == 0 ||
strcmp(via, "TCPXX") == 0 ||
if (strcmp(via, "qAX") == 0 || // qAX deprecated. http://www.aprs-is.net/q.aspx
strcmp(via, "TCPXX") == 0 || // TCPXX deprecated.
strcmp(via, "RFONLY") == 0 ||
strcmp(via, "NOGATE") == 0) {
@ -1739,14 +1864,26 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
* If we recently transmitted a 'message' from some station,
* send the position of the message sender when it comes along later.
*
* Some refer to this as a "courtesy posit report" but I don't
* think that is an official term.
*
* If we have a position report, look up the sender and see if we should
* bypass the normal filtering.
*
* Reference: https://www.aprs-is.net/IGating.aspx
*
* "Passing all message packets also includes passing the sending station's position
* along with the message. When APRS-IS was small, we did this using historical position
* packets. This has become problematic as it introduces historical data on to RF.
* The IGate should note the station(s) it has gated messages to RF for and pass
* the next position packet seen for that station(s) to RF."
*/
// TODO: Not quite this simple. Should have a function to check for position.
// $ raw gps could be a position. @ could be weather data depending on symbol.
info_len = ax25_get_info (pp3, (unsigned char **)(&pinfo));
char *pinfo = NULL;
int info_len = ax25_get_info (pp3, (unsigned char **)(&pinfo));
int msp_special_case = 0;
@ -1776,12 +1913,6 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
// Previously there was a debug message here about the packet being dropped by filtering.
// This is now handled better by the "-df" command line option for filtering details.
// TODO: clean up - remove these lines.
//if (s_debug >= 1) {
// text_color_set(DW_COLOR_INFO);
// dw_printf ("Packet from IGate to channel %d was rejected by filter: %s\n", to_chan, save_digi_config_p->filter_str[MAX_CHANS][to_chan]);
//}
ax25_delete (pp3);
return;
}
@ -1790,13 +1921,15 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
/*
* Remove the VIA path.
* We want to discard the via path, as received from the APRS-IS, then
* replace it with TCPIP and our own call, marked as used.
*
*
* For example, we might get something like this from the server.
* K1USN-1>APWW10,TCPIP*,qAC,N5JXS-F1:T#479,100,048,002,500,000,10000000<0x0d><0x0a>
* K1USN-1>APWW10,TCPIP*,qAC,N5JXS-F1:T#479,100,048,002,500,000,10000000
*
* We want to reduce it to this before wrapping it as third party traffic.
* K1USN-1>APWW10:T#479,100,048,002,500,000,10000000<0x0d><0x0a>
* We want to transform it to this before wrapping it as third party traffic.
* K1USN-1>APWW10,TCPIP,mycall*:T#479,100,048,002,500,000,10000000
*/
/*
@ -1824,36 +1957,23 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
*
* What is the ",I" construct?
* Do we care here?
* Is is something new and improved that we should be using in the other direction?
* Is it something new and improved that we should be using in the other direction?
*/
while (ax25_get_num_repeaters(pp3) > 0) {
ax25_remove_addr (pp3, AX25_REPEATER_1);
}
char payload[AX25_MAX_PACKET_LEN];
char dest[AX25_MAX_ADDR_LEN]; /* Destination field. */
ax25_get_addr_with_ssid (pp3, AX25_DESTINATION, dest);
snprintf (payload, sizeof(payload), "%s>%s,TCPIP,%s*:%s",
src, dest, save_audio_config_p->achan[to_chan].mycall, pinfo);
/*
* Replace the VIA path with TCPIP and my call.
* Mark my call as having been used.
*/
ax25_set_addr (pp3, AX25_REPEATER_1, "TCPIP");
ax25_set_h (pp3, AX25_REPEATER_1);
ax25_set_addr (pp3, AX25_REPEATER_2, save_audio_config_p->achan[to_chan].mycall);
ax25_set_h (pp3, AX25_REPEATER_2);
/*
* Convert to text representation.
*/
memset (payload, 0, sizeof(payload));
ax25_format_addrs (pp3, payload);
info_len = ax25_get_info (pp3, (unsigned char **)(&pinfo));
(void)(info_len);
strlcat (payload, pinfo, sizeof(payload));
#if DEBUGx
text_color_set(DW_COLOR_DEBUG);
dw_printf ("Tx IGate: payload=%s\n", payload);
dw_printf ("Tx IGate: DEBUG payload=%s\n", payload);
#endif
/*
* Encapsulate for sending over radio if no reason to drop it.
@ -1870,19 +1990,13 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
*/
if (ig_to_tx_allow (pp3, to_chan)) {
char radio [2400];
packet_t pradio;
snprintf (radio, sizeof(radio), "%s>%s%d%d%s:}%s",
save_audio_config_p->achan[to_chan].mycall,
APP_TOCALL, MAJOR_VERSION, MINOR_VERSION,
save_igate_config_p->tx_via,
payload);
pradio = ax25_from_text (radio, 1);
/* Oops. Didn't have a check for NULL here. */
/* Could this be the cause of rare and elusive crashes in 1.2? */
packet_t pradio = ax25_from_text (radio, 1);
if (pradio != NULL) {
#if ITEST
@ -1895,10 +2009,7 @@ static void maybe_xmit_packet_from_igate (char *message, int to_chan)
#endif
stats_rf_xmit_packets++; // Any type of packet.
// TEMP TEST: metadata temporarily allowed during testing.
if (*pinfo == ':' && ! is_telem_metadata(pinfo)) {
// temp test // if (*pinfo == ':') {
if (is_message_message(pinfo)) {
// We transmitted a "message." Telemetry metadata is excluded.
// Remember to pass along address of the sender later.
@ -2211,7 +2322,7 @@ static int rx_to_ig_allow (packet_t pp)
*
* Future:
* Should the digipeater function avoid transmitting something if it
* was recently transmitted by the IGate funtion?
* was recently transmitted by the IGate function?
* This code is pretty much the same as dedupe.c. Maybe it could all
* be combined into one. Need to ponder this some more.
*
@ -2356,6 +2467,8 @@ void ig_to_tx_remember (packet_t pp, int chan, int bydigi)
}
}
static int ig_to_tx_allow (packet_t pp, int chan)
{
unsigned short crc = ax25_dedupe_crc(pp);
@ -2388,7 +2501,7 @@ static int ig_to_tx_allow (packet_t pp, int chan)
/* We have a duplicate within some time period. */
if (*pinfo == ':' && ! is_telem_metadata((char*)pinfo)) {
if (is_message_message((char*)pinfo)) {
/* I think I want to avoid the duplicate suppression for "messages." */
/* Suppose we transmit a message from station X and it doesn't get an ack back. */
@ -2437,7 +2550,7 @@ static int ig_to_tx_allow (packet_t pp, int chan)
/* the normal limit for them. */
increase_limit = 1;
if (*pinfo == ':' && ! is_telem_metadata((char*)pinfo)) {
if (is_message_message((char*)pinfo)) {
increase_limit = 3;
}

145
src/il2p.h Normal file
View File

@ -0,0 +1,145 @@
#ifndef IL2P_H
#define IL2P_H 1
#define IL2P_PREAMBLE 0x55
#define IL2P_SYNC_WORD 0xF15E48
#define IL2P_SYNC_WORD_SIZE 3
#define IL2P_HEADER_SIZE 13 // Does not include 2 parity.
#define IL2P_HEADER_PARITY 2
#define IL2P_MAX_PAYLOAD_SIZE 1023
#define IL2P_MAX_PAYLOAD_BLOCKS 5
#define IL2P_MAX_PARITY_SYMBOLS 16 // For payload only.
#define IL2P_MAX_ENCODED_PAYLOAD_SIZE (IL2P_MAX_PAYLOAD_SIZE + IL2P_MAX_PAYLOAD_BLOCKS * IL2P_MAX_PARITY_SYMBOLS)
#define IL2P_MAX_PACKET_SIZE (IL2P_SYNC_WORD_SIZE + IL2P_HEADER_SIZE + IL2P_HEADER_PARITY + IL2P_MAX_ENCODED_PAYLOAD_SIZE)
///////////////////////////////////////////////////////////////////////////////
//
// il2p_init.c
//
///////////////////////////////////////////////////////////////////////////////
// Init must be called at start of application.
extern void il2p_init (int debug);
#include "fx25.h" // For Reed Solomon stuff. e.g. struct rs
// Maybe rearrange someday because RS now used another place.
extern struct rs *il2p_find_rs(int nparity); // Internal later?
extern void il2p_encode_rs (unsigned char *tx_data, int data_size, int num_parity, unsigned char *parity_out);
extern int il2p_decode_rs (unsigned char *rec_block, int data_size, int num_parity, unsigned char *out);
extern int il2p_get_debug(void);
extern void il2p_set_debug(int debug);
///////////////////////////////////////////////////////////////////////////////
//
// il2p_rec.c
//
///////////////////////////////////////////////////////////////////////////////
// Receives a bit stream from demodulator.
extern void il2p_rec_bit (int chan, int subchan, int slice, int dbit);
///////////////////////////////////////////////////////////////////////////////
//
// il2p_send.c
//
///////////////////////////////////////////////////////////////////////////////
#include "ax25_pad.h" // For packet object.
// Send bit stream to modulator.
int il2p_send_frame (int chan, packet_t pp, int max_fec, int polarity);
///////////////////////////////////////////////////////////////////////////////
//
// il2p_codec.c
//
///////////////////////////////////////////////////////////////////////////////
#include "ax25_pad.h"
extern int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout);
packet_t il2p_decode_frame (unsigned char *irec);
packet_t il2p_decode_header_payload (unsigned char* uhdr, unsigned char *epayload, int *symbols_corrected);
///////////////////////////////////////////////////////////////////////////////
//
// il2p_header.c
//
///////////////////////////////////////////////////////////////////////////////
extern int il2p_type_1_header (packet_t pp, int max_fec, unsigned char *hdr);
extern packet_t il2p_decode_header_type_1 (unsigned char *hdr, int num_sym_changed);
extern int il2p_type_0_header (packet_t pp, int max_fec, unsigned char *hdr);
extern int il2p_clarify_header(unsigned char *rec_hdr, unsigned char *corrected_descrambled_hdr);
///////////////////////////////////////////////////////////////////////////////
//
// il2p_scramble.c
//
///////////////////////////////////////////////////////////////////////////////
extern void il2p_scramble_block (unsigned char *in, unsigned char *out, int len);
extern void il2p_descramble_block (unsigned char *in, unsigned char *out, int len);
///////////////////////////////////////////////////////////////////////////////
//
// il2p_payload.c
//
///////////////////////////////////////////////////////////////////////////////
typedef struct {
int payload_byte_count; // Total size, 0 thru 1023
int payload_block_count;
int small_block_size;
int large_block_size;
int large_block_count;
int small_block_count;
int parity_symbols_per_block; // 2, 4, 6, 8, 16
} il2p_payload_properties_t;
extern int il2p_payload_compute (il2p_payload_properties_t *p, int payload_size, int max_fec);
extern int il2p_encode_payload (unsigned char *payload, int payload_size, int max_fec, unsigned char *enc);
extern int il2p_decode_payload (unsigned char *received, int payload_size, int max_fec, unsigned char *payload_out, int *symbols_corrected);
extern int il2p_get_header_attributes (unsigned char *hdr, int *hdr_type, int *max_fec);
#endif

263
src/il2p_codec.c Normal file
View File

@ -0,0 +1,263 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "direwolf.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "il2p.h"
#include "textcolor.h"
#include "demod.h"
/*-------------------------------------------------------------
*
* File: il2p_codec.c
*
* Purpose: Convert IL2P encoded format from and to direwolf internal packet format.
*
*--------------------------------------------------------------*/
/*-------------------------------------------------------------
*
* Name: il2p_encode_frame
*
* Purpose: Convert AX.25 frame to IL2P encoding.
*
* Inputs: chan - Audio channel number, 0 = first.
*
* pp - Packet object pointer.
*
* max_fec - 1 to send maximum FEC size rather than automatic.
*
* Outputs: iout - Encoded result, excluding the 3 byte sync word.
* Caller should provide IL2P_MAX_PACKET_SIZE bytes.
*
* Returns: Number of bytes for transmission.
* -1 is returned for failure.
*
* Description: Encode into IL2P format.
*
* Errors: If something goes wrong, return -1.
*
* Most likely reason is that the frame is too large.
* IL2P has a max payload size of 1023 bytes.
* For a type 1 header, this is the maximum AX.25 Information part size.
* For a type 0 header, this is the entire AX.25 frame.
*
*--------------------------------------------------------------*/
int il2p_encode_frame (packet_t pp, int max_fec, unsigned char *iout)
{
// Can a type 1 header be used?
unsigned char hdr[IL2P_HEADER_SIZE + IL2P_HEADER_PARITY];
int e;
int out_len = 0;
e = il2p_type_1_header (pp, max_fec, hdr);
if (e >= 0) {
il2p_scramble_block (hdr, iout, IL2P_HEADER_SIZE);
il2p_encode_rs (iout, IL2P_HEADER_SIZE, IL2P_HEADER_PARITY, iout+IL2P_HEADER_SIZE);
out_len = IL2P_HEADER_SIZE + IL2P_HEADER_PARITY;
if (e == 0) {
// Success. No info part.
return (out_len);
}
// Payload is AX.25 info part.
unsigned char *pinfo;
int info_len;
info_len = ax25_get_info (pp, &pinfo);
int k = il2p_encode_payload (pinfo, info_len, max_fec, iout+out_len);
if (k > 0) {
out_len += k;
// Success. Info part was <= 1023 bytes.
return (out_len);
}
// Something went wrong with the payload encoding.
return (-1);
}
else if (e == -1) {
// Could not use type 1 header for some reason.
// e.g. More than 2 addresses, extended (mod 128) sequence numbers, etc.
e = il2p_type_0_header (pp, max_fec, hdr);
if (e > 0) {
il2p_scramble_block (hdr, iout, IL2P_HEADER_SIZE);
il2p_encode_rs (iout, IL2P_HEADER_SIZE, IL2P_HEADER_PARITY, iout+IL2P_HEADER_SIZE);
out_len = IL2P_HEADER_SIZE + IL2P_HEADER_PARITY;
// Payload is entire AX.25 frame.
unsigned char *frame_data_ptr = ax25_get_frame_data_ptr (pp);
int frame_len = ax25_get_frame_len (pp);
int k = il2p_encode_payload (frame_data_ptr, frame_len, max_fec, iout+out_len);
if (k > 0) {
out_len += k;
// Success. Entire AX.25 frame <= 1023 bytes.
return (out_len);
}
// Something went wrong with the payload encoding.
return (-1);
}
else if (e == 0) {
// Impossible condition. Type 0 header must have payload.
return (-1);
}
else {
// AX.25 frame is too large.
return (-1);
}
}
// AX.25 Information part is too large.
return (-1);
}
/*-------------------------------------------------------------
*
* Name: il2p_decode_frame
*
* Purpose: Convert IL2P encoding to AX.25 frame.
* This is only used during testing, with a whole encoded frame.
* During reception, the header would have FEC and descrambling
* applied first so we would know how much to collect for the payload.
*
* Inputs: irec - Received IL2P frame excluding the 3 byte sync word.
*
* Future Out: Number of symbols corrected.
*
* Returns: Packet pointer or NULL for error.
*
*--------------------------------------------------------------*/
packet_t il2p_decode_frame (unsigned char *irec)
{
unsigned char uhdr[IL2P_HEADER_SIZE]; // After FEC and descrambling.
int e = il2p_clarify_header (irec, uhdr);
// TODO?: for symmetry we might want to clarify the payload before combining.
return (il2p_decode_header_payload(uhdr, irec + IL2P_HEADER_SIZE + IL2P_HEADER_PARITY, &e));
}
/*-------------------------------------------------------------
*
* Name: il2p_decode_header_payload
*
* Purpose: Convert IL2P encoding to AX.25 frame
*
* Inputs: uhdr - Received header after FEC and descrambling.
* epayload - Encoded payload.
*
* In/Out: symbols_corrected - Symbols (bytes) corrected in the header.
* Should be 0 or 1 because it has 2 parity symbols.
* Here we add number of corrections for the payload.
*
* Returns: Packet pointer or NULL for error.
*
*--------------------------------------------------------------*/
packet_t il2p_decode_header_payload (unsigned char* uhdr, unsigned char *epayload, int *symbols_corrected)
{
int hdr_type;
int max_fec;
int payload_len = il2p_get_header_attributes (uhdr, &hdr_type, &max_fec);
packet_t pp = NULL;
if (hdr_type == 1) {
// Header type 1. Any payload is the AX.25 Information part.
pp = il2p_decode_header_type_1 (uhdr, *symbols_corrected);
if (pp == NULL) {
// Failed for some reason.
return (NULL);
}
if (payload_len > 0) {
// This is the AX.25 Information part.
unsigned char extracted[IL2P_MAX_PAYLOAD_SIZE];
int e = il2p_decode_payload (epayload, payload_len, max_fec, extracted, symbols_corrected);
// It would be possible to have a good header but too many errors in the payload.
if (e <= 0) {
ax25_delete (pp);
pp = NULL;
return (pp);
}
if (e != payload_len) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P Internal Error: %s(): hdr_type=%d, max_fec=%d, payload_len=%d, e=%d.\n", __func__, hdr_type, max_fec, payload_len, e);
}
ax25_set_info (pp, extracted, payload_len);
}
return (pp);
}
else {
// Header type 0. The payload is the entire AX.25 frame.
unsigned char extracted[IL2P_MAX_PAYLOAD_SIZE];
int e = il2p_decode_payload (epayload, payload_len, max_fec, extracted, symbols_corrected);
if (e <= 0) { // Payload was not received correctly.
return (NULL);
}
if (e != payload_len) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P Internal Error: %s(): hdr_type=%d, e=%d, payload_len=%d\n", __func__, hdr_type, e, payload_len);
return (NULL);
}
alevel_t alevel;
memset (&alevel, 0, sizeof(alevel));
//alevel = demod_get_audio_level (chan, subchan); // What TODO? We don't know channel here.
// I think alevel gets filled in somewhere later making
// this redundant.
pp = ax25_from_frame (extracted, payload_len, alevel);
return (pp);
}
} // end il2p_decode_header_payload
// end il2p_codec.c

679
src/il2p_header.c Normal file
View File

@ -0,0 +1,679 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "direwolf.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "textcolor.h"
#include "ax25_pad.h"
#include "ax25_pad2.h"
#include "il2p.h"
/*--------------------------------------------------------------------------------
*
* File: il2p_header.c
*
* Purpose: Functions to deal with the IL2P header.
*
* Reference: http://tarpn.net/t/il2p/il2p-specification0-4.pdf
*
*--------------------------------------------------------------------------------*/
// Convert ASCII to/from DEC SIXBIT as defined here:
// https://en.wikipedia.org/wiki/Six-bit_character_code#DEC_six-bit_code
static inline int ascii_to_sixbit (int a)
{
if (a >= ' ' && a <= '_') return (a - ' ');
return (31); // '?' for any invalid.
}
static inline int sixbit_to_ascii (int s)
{
return (s + ' ');
}
// Functions for setting the various header fields.
// It is assumed that it was zeroed first so only the '1' bits are set.
static void set_field (unsigned char *hdr, int bit_num, int lsb_index, int width, int value)
{
while (width > 0 && value != 0) {
assert (lsb_index >= 0 && lsb_index <= 11);
if (value & 1) {
hdr[lsb_index] |= 1 << bit_num;
}
value >>= 1;
lsb_index--;
width--;
}
assert (value == 0);
}
#define SET_UI(hdr,val) set_field(hdr, 6, 0, 1, val)
#define SET_PID(hdr,val) set_field(hdr, 6, 4, 4, val)
#define SET_CONTROL(hdr,val) set_field(hdr, 6, 11, 7, val)
#define SET_FEC_LEVEL(hdr,val) set_field(hdr, 7, 0, 1, val)
#define SET_HDR_TYPE(hdr,val) set_field(hdr, 7, 1, 1, val)
#define SET_PAYLOAD_BYTE_COUNT(hdr,val) set_field(hdr, 7, 11, 10, val)
// Extracting the fields.
static int get_field (unsigned char *hdr, int bit_num, int lsb_index, int width)
{
int result = 0;
lsb_index -= width - 1;
while (width > 0) {
result <<= 1;
assert (lsb_index >= 0 && lsb_index <= 11);
if (hdr[lsb_index] & (1 << bit_num)) {
result |= 1;
}
lsb_index++;
width--;
}
return (result);
}
#define GET_UI(hdr) get_field(hdr, 6, 0, 1)
#define GET_PID(hdr) get_field(hdr, 6, 4, 4)
#define GET_CONTROL(hdr) get_field(hdr, 6, 11, 7)
#define GET_FEC_LEVEL(hdr) get_field(hdr, 7, 0, 1)
#define GET_HDR_TYPE(hdr) get_field(hdr, 7, 1, 1)
#define GET_PAYLOAD_BYTE_COUNT(hdr) get_field(hdr, 7, 11, 10)
// AX.25 'I' and 'UI' frames have a protocol ID which determines how the
// information part should be interpreted.
// Here we squeeze the most common cases down to 4 bits.
// Return -1 if translation is not possible. Fall back to type 0 header in this case.
static int encode_pid (packet_t pp)
{
int pid = ax25_get_pid(pp);
if ((pid & 0x30) == 0x20) return (0x2); // AX.25 Layer 3
if ((pid & 0x30) == 0x10) return (0x2); // AX.25 Layer 3
if (pid == 0x01) return (0x3); // ISO 8208 / CCIT X.25 PLP
if (pid == 0x06) return (0x4); // Compressed TCP/IP
if (pid == 0x07) return (0x5); // Uncompressed TCP/IP
if (pid == 0x08) return (0x6); // Segmentation fragmen
if (pid == 0xcc) return (0xb); // ARPA Internet Protocol
if (pid == 0xcd) return (0xc); // ARPA Address Resolution
if (pid == 0xce) return (0xd); // FlexNet
if (pid == 0xcf) return (0xe); // TheNET
if (pid == 0xf0) return (0xf); // No L3
return (-1);
}
// Convert IL2P 4 bit PID to AX.25 8 bit PID.
static int decode_pid (int pid)
{
static const unsigned char axpid[16] = {
0xf0, // Should not happen. 0 is for 'S' frames.
0xf0, // Should not happen. 1 is for 'U' frames (but not UI).
0x20, // AX.25 Layer 3
0x01, // ISO 8208 / CCIT X.25 PLP
0x06, // Compressed TCP/IP
0x07, // Uncompressed TCP/IP
0x08, // Segmentation fragment
0xf0, // Future
0xf0, // Future
0xf0, // Future
0xf0, // Future
0xcc, // ARPA Internet Protocol
0xcd, // ARPA Address Resolution
0xce, // FlexNet
0xcf, // TheNET
0xf0 }; // No L3
assert (pid >= 0 && pid <= 15);
return (axpid[pid]);
}
/*--------------------------------------------------------------------------------
*
* Function: il2p_type_1_header
*
* Purpose: Attempt to create type 1 header from packet object.
*
* Inputs: pp - Packet object.
*
* max_fec - 1 to use maximum FEC symbols , 0 for automatic.
*
* Outputs: hdr - IL2P header with no scrambling or parity symbols.
* Must be large enough to hold IL2P_HEADER_SIZE unsigned bytes.
*
* Returns: Number of bytes for information part or -1 for failure.
* In case of failure, fall back to type 0 transparent encapsulation.
*
* Description: Type 1 Headers do not support AX.25 repeater callsign addressing,
* Modulo-128 extended mode window sequence numbers, nor any callsign
* characters that cannot translate to DEC SIXBIT.
* If these cases are encountered during IL2P packet encoding,
* the encoder switches to Type 0 Transparent Encapsulation.
* SABME can't be handled by type 1.
*
*--------------------------------------------------------------------------------*/
int il2p_type_1_header (packet_t pp, int max_fec, unsigned char *hdr)
{
memset (hdr, 0, IL2P_HEADER_SIZE);
if (ax25_get_num_addr(pp) != 2) {
// Only two addresses are allowed for type 1 header.
return (-1);
}
// Check does not apply for 'U' frames but put in one place rather than two.
if (ax25_get_modulo(pp) == 128) return(-1);
// Destination and source addresses go into low bits 0-5 for bytes 0-11.
char dst_addr[AX25_MAX_ADDR_LEN];
char src_addr[AX25_MAX_ADDR_LEN];
ax25_get_addr_no_ssid (pp, AX25_DESTINATION, dst_addr);
int dst_ssid = ax25_get_ssid (pp, AX25_DESTINATION);
ax25_get_addr_no_ssid (pp, AX25_SOURCE, src_addr);
int src_ssid = ax25_get_ssid (pp, AX25_SOURCE);
unsigned char *a = (unsigned char *)dst_addr;
for (int i = 0; *a != '\0'; i++, a++) {
if (*a < ' ' || *a > '_') {
// Shouldn't happen but follow the rule.
return (-1);
}
hdr[i] = ascii_to_sixbit(*a);
}
a = (unsigned char *)src_addr;
for (int i = 6; *a != '\0'; i++, a++) {
if (*a < ' ' || *a > '_') {
// Shouldn't happen but follow the rule.
return (-1);
}
hdr[i] = ascii_to_sixbit(*a);
}
// Byte 12 has DEST SSID in upper nybble and SRC SSID in lower nybble and
hdr[12] = (dst_ssid << 4) | src_ssid;
ax25_frame_type_t frame_type;
cmdres_t cr; // command or response.
char description[64];
int pf; // Poll/Final.
int nr, ns; // Sequence numbers.
frame_type = ax25_frame_type (pp, &cr, description, &pf, &nr, &ns);
//dw_printf ("%s(): %s-%d>%s-%d: %s\n", __func__, src_addr, src_ssid, dst_addr, dst_ssid, description);
switch (frame_type) {
case frame_type_S_RR: // Receive Ready - System Ready To Receive
case frame_type_S_RNR: // Receive Not Ready - TNC Buffer Full
case frame_type_S_REJ: // Reject Frame - Out of Sequence or Duplicate
case frame_type_S_SREJ: // Selective Reject - Request single frame repeat
// S frames (RR, RNR, REJ, SREJ), mod 8, have control N(R) P/F S S 0 1
// These are mapped into P/F N(R) C S S
// Bit 6 is not mentioned in documentation but it is used for P/F for the other frame types.
// C is copied from the C bit in the destination addr.
// C from source is not used here. Reception assumes it is the opposite.
// PID is set to 0, meaning none, for S frames.
SET_UI(hdr, 0);
SET_PID(hdr, 0);
SET_CONTROL(hdr, (pf<<6) | (nr<<3) | (((cr == cr_cmd) | (cr == cr_11))<<2));
// This gets OR'ed into the above.
switch (frame_type) {
case frame_type_S_RR: SET_CONTROL(hdr, 0); break;
case frame_type_S_RNR: SET_CONTROL(hdr, 1); break;
case frame_type_S_REJ: SET_CONTROL(hdr, 2); break;
case frame_type_S_SREJ: SET_CONTROL(hdr, 3); break;
default: break;
}
break;
case frame_type_U_SABM: // Set Async Balanced Mode
case frame_type_U_DISC: // Disconnect
case frame_type_U_DM: // Disconnect Mode
case frame_type_U_UA: // Unnumbered Acknowledge
case frame_type_U_FRMR: // Frame Reject
case frame_type_U_UI: // Unnumbered Information
case frame_type_U_XID: // Exchange Identification
case frame_type_U_TEST: // Test
// The encoding allows only 3 bits for frame type and SABME got left out.
// Control format: P/F opcode[3] C n/a n/a
// The grayed out n/a bits are observed as 00 in the example.
// The header UI field must also be set for UI frames.
// PID is set to 1 for all U frames other than UI.
if (frame_type == frame_type_U_UI) {
SET_UI(hdr, 1); // I guess this is how we distinguish 'I' and 'UI'
// on the receiving end.
int pid = encode_pid(pp);
if (pid < 0) return (-1);
SET_PID(hdr, pid);
}
else {
SET_PID(hdr, 1); // 1 for 'U' other than 'UI'.
}
// Each of the destination and source addresses has a "C" bit.
// They should normally have the opposite setting.
// IL2P has only a single bit to represent 4 possbilities.
//
// dst src il2p meaning
// --- --- ---- -------
// 0 0 0 Not valid (earlier protocol version)
// 1 0 1 Command (v2)
// 0 1 0 Response (v2)
// 1 1 1 Not valid (earlier protocol version)
//
// APRS does not mention how to set these bits and all 4 combinations
// are seen in the wild. Apparently these are ignored on receive and no
// one cares. Here we copy from the C bit in the destination address.
// It should be noted that the case of both C bits being the same can't
// be represented so the il2p encode/decode bit not produce exactly the
// same bits. We see this in the second example in the protocol spec.
// The original UI frame has both C bits of 0 so it is received as a response.
SET_CONTROL(hdr, (pf<<6) | (((cr == cr_cmd) | (cr == cr_11))<<2));
// This gets OR'ed into the above.
switch (frame_type) {
case frame_type_U_SABM: SET_CONTROL(hdr, 0<<3); break;
case frame_type_U_DISC: SET_CONTROL(hdr, 1<<3); break;
case frame_type_U_DM: SET_CONTROL(hdr, 2<<3); break;
case frame_type_U_UA: SET_CONTROL(hdr, 3<<3); break;
case frame_type_U_FRMR: SET_CONTROL(hdr, 4<<3); break;
case frame_type_U_UI: SET_CONTROL(hdr, 5<<3); break;
case frame_type_U_XID: SET_CONTROL(hdr, 6<<3); break;
case frame_type_U_TEST: SET_CONTROL(hdr, 7<<3); break;
default: break;
}
break;
case frame_type_I: // Information
// I frames (mod 8 only)
// encoded control: P/F N(R) N(S)
SET_UI(hdr, 0);
int pid2 = encode_pid(pp);
if (pid2 < 0) return (-1);
SET_PID(hdr, pid2);
SET_CONTROL(hdr, (pf<<6) | (nr<<3) | ns);
break;
case frame_type_U_SABME: // Set Async Balanced Mode, Extended
case frame_type_U: // other Unnumbered, not used by AX.25.
case frame_not_AX25: // Could not get control byte from frame.
default:
// Fall back to the header type 0 for these.
return (-1);
}
// Common for all header type 1.
// Bit 7 has [FEC Level:1], [HDR Type:1], [Payload byte Count:10]
SET_FEC_LEVEL(hdr, max_fec);
SET_HDR_TYPE(hdr, 1);
unsigned char *pinfo;
int info_len;
info_len = ax25_get_info (pp, &pinfo);
if (info_len < 0 || info_len > IL2P_MAX_PAYLOAD_SIZE) {
return (-2);
}
SET_PAYLOAD_BYTE_COUNT(hdr, info_len);
return (info_len);
}
// This should create a packet from the IL2P header.
// The information part will not be filled in.
static void trim (char *stuff)
{
char *p = stuff + strlen(stuff) - 1;
while (strlen(stuff) > 0 && (*p == ' ')) {
*p = '\0';
p--;
}
}
/*--------------------------------------------------------------------------------
*
* Function: il2p_decode_header_type_1
*
* Purpose: Attempt to convert type 1 header to a packet object.
*
* Inputs: hdr - IL2P header with no scrambling or parity symbols.
*
* num_sym_changed - Number of symbols changed by FEC in the header.
* Should be 0 or 1.
*
* Returns: Packet Object or NULL for failure.
*
* Description: A later step will process the payload for the information part.
*
*--------------------------------------------------------------------------------*/
packet_t il2p_decode_header_type_1 (unsigned char *hdr, int num_sym_changed)
{
if (GET_HDR_TYPE(hdr) != 1 ) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P Internal error. Should not be here: %s, when header type is 0.\n", __func__);
return (NULL);
}
// First get the addresses including SSID.
char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN];
int num_addr = 2;
memset (addrs, 0, 2*AX25_MAX_ADDR_LEN);
// The IL2P header uses 2 parity symbols which means a single corrupted symbol (byte)
// can always be corrected.
// However, I have seen cases, where the error rate is very high, where the RS decoder
// thinks it found a valid code block by changing one symbol but it was the wrong one.
// The result is trash. This shows up as address fields like 'R&G4"A' and 'TEW\ !'.
// I added a sanity check here to catch characters other than upper case letters and digits.
// The frame should be rejected in this case. The question is whether to discard it
// silently or print a message so the user can see that something strange is happening?
// My current thinking is that it should be silently ignored if the header has been
// modified (correctee or more likely, made worse in this cases).
// If no changes were made, something weird is happening. We should mention it for
// troubleshooting rather than sweeping it under the rug.
// The same thing has been observed with the payload, under very high error conditions,
// and max_fec==0. Here I don't see a good solution. AX.25 information can contain
// "binary" data so I'm not sure what sort of sanity check could be added.
// This was not observed with max_fec==1. If we make that the default, same as Nino TNC,
// it would be extremely extremely unlikely unless someone explicitly selects weaker FEC.
// TODO: We could do something similar for header type 0.
// The address fields should be all binary zero values.
// Someone overly ambitious might check the addresses found in the first payload block.
for (int i = 0; i <= 5; i++) {
addrs[AX25_DESTINATION][i] = sixbit_to_ascii(hdr[i] & 0x3f);
}
trim (addrs[AX25_DESTINATION]);
for (int i = 0; i < strlen(addrs[AX25_DESTINATION]); i++) {
if (! isupper(addrs[AX25_DESTINATION][i]) && ! isdigit(addrs[AX25_DESTINATION][i])) {
if (num_sym_changed == 0) {
// This can pop up sporadically when receiving random noise.
// Would be better to show only when debug is enabled but variable not available here.
// TODO: For now we will just suppress it.
//text_color_set(DW_COLOR_ERROR);
//dw_printf ("IL2P: Invalid character '%c' in destination address '%s'\n", addrs[AX25_DESTINATION][i], addrs[AX25_DESTINATION]);
}
return (NULL);
}
}
snprintf (addrs[AX25_DESTINATION]+strlen(addrs[AX25_DESTINATION]), 4, "-%d", (hdr[12] >> 4) &0xf);
for (int i = 0; i <= 5; i++) {
addrs[AX25_SOURCE][i] = sixbit_to_ascii(hdr[i+6] & 0x3f);
}
trim (addrs[AX25_SOURCE]);
for (int i = 0; i < strlen(addrs[AX25_SOURCE]); i++) {
if (! isupper(addrs[AX25_SOURCE][i]) && ! isdigit(addrs[AX25_SOURCE][i])) {
if (num_sym_changed == 0) {
// This can pop up sporadically when receiving random noise.
// Would be better to show only when debug is enabled but variable not available here.
// TODO: For now we will just suppress it.
//text_color_set(DW_COLOR_ERROR);
//dw_printf ("IL2P: Invalid character '%c' in source address '%s'\n", addrs[AX25_SOURCE][i], addrs[AX25_SOURCE]);
}
return (NULL);
}
}
snprintf (addrs[AX25_SOURCE]+strlen(addrs[AX25_SOURCE]), 4, "-%d", hdr[12] &0xf);
// The PID field gives us the general type.
// 0 = 'S' frame.
// 1 = 'U' frame other than UI.
// others are either 'UI' or 'I' depending on the UI field.
int pid = GET_PID(hdr);
int ui = GET_UI(hdr);
if (pid == 0) {
// 'S' frame.
// The control field contains: P/F N(R) C S S
int control = GET_CONTROL(hdr);
cmdres_t cr = (control & 0x04) ? cr_cmd : cr_res;
ax25_frame_type_t ftype;
switch (control & 0x03) {
case 0: ftype = frame_type_S_RR; break;
case 1: ftype = frame_type_S_RNR; break;
case 2: ftype = frame_type_S_REJ; break;
default: ftype = frame_type_S_SREJ; break;
}
int modulo = 8;
int nr = (control >> 3) & 0x07;
int pf = (control >> 6) & 0x01;
unsigned char *pinfo = NULL; // Any info for SREJ will be added later.
int info_len = 0;
return (ax25_s_frame (addrs, num_addr, cr, ftype, modulo, nr, pf, pinfo, info_len));
}
else if (pid == 1) {
// 'U' frame other than 'UI'.
// The control field contains: P/F OPCODE{3) C x x
int control = GET_CONTROL(hdr);
cmdres_t cr = (control & 0x04) ? cr_cmd : cr_res;
int axpid = 0; // unused for U other than UI.
ax25_frame_type_t ftype;
switch ((control >> 3) & 0x7) {
case 0: ftype = frame_type_U_SABM; break;
case 1: ftype = frame_type_U_DISC; break;
case 2: ftype = frame_type_U_DM; break;
case 3: ftype = frame_type_U_UA; break;
case 4: ftype = frame_type_U_FRMR; break;
case 5: ftype = frame_type_U_UI; axpid = 0xf0; break; // Should not happen with IL2P pid == 1.
case 6: ftype = frame_type_U_XID; break;
default: ftype = frame_type_U_TEST; break;
}
int pf = (control >> 6) & 0x01;
unsigned char *pinfo = NULL; // Any info for UI, XID, TEST will be added later.
int info_len = 0;
return (ax25_u_frame (addrs, num_addr, cr, ftype, pf, axpid, pinfo, info_len));
}
else if (ui) {
// 'UI' frame.
// The control field contains: P/F OPCODE{3) C x x
int control = GET_CONTROL(hdr);
cmdres_t cr = (control & 0x04) ? cr_cmd : cr_res;
ax25_frame_type_t ftype = frame_type_U_UI;
int pf = (control >> 6) & 0x01;
int axpid = decode_pid(GET_PID(hdr));
unsigned char *pinfo = NULL; // Any info for UI, XID, TEST will be added later.
int info_len = 0;
return (ax25_u_frame (addrs, num_addr, cr, ftype, pf, axpid, pinfo, info_len));
}
else {
// 'I' frame.
// The control field contains: P/F N(R) N(S)
int control = GET_CONTROL(hdr);
cmdres_t cr = cr_cmd; // Always command.
int pf = (control >> 6) & 0x01;
int nr = (control >> 3) & 0x7;
int ns = control & 0x7;
int modulo = 8;
int axpid = decode_pid(GET_PID(hdr));
unsigned char *pinfo = NULL; // Any info for UI, XID, TEST will be added later.
int info_len = 0;
return (ax25_i_frame (addrs, num_addr, cr, modulo, nr, ns, pf, axpid, pinfo, info_len));
}
return (NULL); // unreachable but avoid warning.
} // end
/*--------------------------------------------------------------------------------
*
* Function: il2p_type_0_header
*
* Purpose: Attempt to create type 0 header from packet object.
*
* Inputs: pp - Packet object.
*
* max_fec - 1 to use maximum FEC symbols, 0 for automatic.
*
* Outputs: hdr - IL2P header with no scrambling or parity symbols.
* Must be large enough to hold IL2P_HEADER_SIZE unsigned bytes.
*
* Returns: Number of bytes for information part or -1 for failure.
* In case of failure, fall back to type 0 transparent encapsulation.
*
* Description: The type 0 header is used when it is not one of the restricted cases
* covered by the type 1 header.
* The AX.25 frame is put in the payload.
* This will cover: more than one address, mod 128 sequences, etc.
*
*--------------------------------------------------------------------------------*/
int il2p_type_0_header (packet_t pp, int max_fec, unsigned char *hdr)
{
memset (hdr, 0, IL2P_HEADER_SIZE);
// Bit 7 has [FEC Level:1], [HDR Type:1], [Payload byte Count:10]
SET_FEC_LEVEL(hdr, max_fec);
SET_HDR_TYPE(hdr, 0);
int frame_len = ax25_get_frame_len (pp);
if (frame_len < 14 || frame_len > IL2P_MAX_PAYLOAD_SIZE) {
return (-2);
}
SET_PAYLOAD_BYTE_COUNT(hdr, frame_len);
return (frame_len);
}
/***********************************************************************************
*
* Name: il2p_get_header_attributes
*
* Purpose: Extract a few attributes from an IL2p header.
*
* Inputs: hdr - IL2P header structure.
*
* Outputs: hdr_type - 0 or 1.
*
* max_fec - 0 for automatic or 1 for fixed maximum size.
*
* Returns: Payload byte count. (actual payload size, not the larger encoded format)
*
***********************************************************************************/
int il2p_get_header_attributes (unsigned char *hdr, int *hdr_type, int *max_fec)
{
*hdr_type = GET_HDR_TYPE(hdr);
*max_fec = GET_FEC_LEVEL(hdr);
return(GET_PAYLOAD_BYTE_COUNT(hdr));
}
/***********************************************************************************
*
* Name: il2p_clarify_header
*
* Purpose: Convert received header to usable form.
* This involves RS FEC then descrambling.
*
* Inputs: rec_hdr - Header as received over the radio.
*
* Outputs: corrected_descrambled_hdr - After RS FEC and unscrambling.
*
* Returns: Number of symbols that were corrected:
* 0 = No errors
* 1 = Single symbol corrected.
* <0 = Unable to obtain good header.
*
***********************************************************************************/
int il2p_clarify_header(unsigned char *rec_hdr, unsigned char *corrected_descrambled_hdr)
{
unsigned char corrected[IL2P_HEADER_SIZE+IL2P_HEADER_PARITY];
int e = il2p_decode_rs (rec_hdr, IL2P_HEADER_SIZE, IL2P_HEADER_PARITY, corrected);
il2p_descramble_block (corrected, corrected_descrambled_hdr, IL2P_HEADER_SIZE);
return (e);
}
// end il2p_header.c

226
src/il2p_init.c Normal file
View File

@ -0,0 +1,226 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "direwolf.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "textcolor.h"
#include "fx25.h" // For Reed Solomon stuff.
#include "il2p.h"
// Interesting related stuff:
// https://www.kernel.org/doc/html/v4.15/core-api/librs.html
// https://berthub.eu/articles/posts/reed-solomon-for-programmers/
#define MAX_NROOTS 16
#define NTAB 5
static struct {
int symsize; // Symbol size, bits (1-8). Always 8 for this application.
int genpoly; // Field generator polynomial coefficients.
int fcs; // First root of RS code generator polynomial, index form.
// FX.25 uses 1 but IL2P uses 0.
int prim; // Primitive element to generate polynomial roots.
int nroots; // RS code generator polynomial degree (number of roots).
// Same as number of check bytes added.
struct rs *rs; // Pointer to RS codec control block. Filled in at init time.
} Tab[NTAB] = {
{8, 0x11d, 0, 1, 2, NULL }, // 2 parity
{8, 0x11d, 0, 1, 4, NULL }, // 4 parity
{8, 0x11d, 0, 1, 6, NULL }, // 6 parity
{8, 0x11d, 0, 1, 8, NULL }, // 8 parity
{8, 0x11d, 0, 1, 16, NULL }, // 16 parity
};
static int g_il2p_debug = 0;
/*-------------------------------------------------------------
*
* Name: il2p_init
*
* Purpose: This must be called at application start up time.
* It sets up tables for the Reed-Solomon functions.
*
* Inputs: debug - Enable debug output.
*
*--------------------------------------------------------------*/
void il2p_init (int il2p_debug)
{
g_il2p_debug = il2p_debug;
for (int i = 0 ; i < NTAB ; i++) {
assert (Tab[i].nroots <= MAX_NROOTS);
Tab[i].rs = INIT_RS(Tab[i].symsize, Tab[i].genpoly, Tab[i].fcs, Tab[i].prim, Tab[i].nroots);
if (Tab[i].rs == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf("IL2P internal error: init_rs_char failed!\n");
exit(EXIT_FAILURE);
}
}
} // end il2p_init
int il2p_get_debug(void)
{
return (g_il2p_debug);
}
void il2p_set_debug(int debug)
{
g_il2p_debug = debug;
}
// Find RS codec control block for specified number of parity symbols.
struct rs *il2p_find_rs(int nparity)
{
for (int n = 0; n < NTAB; n++) {
if (Tab[n].nroots == nparity) {
return (Tab[n].rs);
}
}
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P INTERNAL ERROR: il2p_find_rs: control block not found for nparity = %d.\n", nparity);
return (Tab[0].rs);
}
/*-------------------------------------------------------------
*
* Name: void il2p_encode_rs
*
* Purpose: Add parity symbols to a block of data.
*
* Inputs: tx_data Header or other data to transmit.
* data_size Number of data bytes in above.
* num_parity Number of parity symbols to add.
* Maximum of IL2P_MAX_PARITY_SYMBOLS.
*
* Outputs: parity_out Specified number of parity symbols
*
* Restriction: data_size + num_parity <= 255 which is the RS block size.
* The caller must ensure this.
*
*--------------------------------------------------------------*/
void il2p_encode_rs (unsigned char *tx_data, int data_size, int num_parity, unsigned char *parity_out)
{
assert (data_size >= 1);
assert (num_parity == 2 || num_parity == 4 || num_parity == 6 || num_parity == 8 || num_parity == 16);
assert (data_size + num_parity <= 255);
unsigned char rs_block[FX25_BLOCK_SIZE];
memset (rs_block, 0, sizeof(rs_block));
memcpy (rs_block + sizeof(rs_block) - data_size - num_parity, tx_data, data_size);
ENCODE_RS (il2p_find_rs(num_parity), rs_block, parity_out);
}
/*-------------------------------------------------------------
*
* Name: void il2p_decode_rs
*
* Purpose: Check and attempt to fix block with FEC.
*
* Inputs: rec_block Received block composed of data and parity.
* Total size is sum of following two parameters.
* data_size Number of data bytes in above.
* num_parity Number of parity symbols (bytes) in above.
*
* Outputs: out Original with possible corrections applied.
* data_size bytes.
*
* Returns: -1 for unrecoverable.
* >= 0 for success. Number of symbols corrected.
*
*--------------------------------------------------------------*/
int il2p_decode_rs (unsigned char *rec_block, int data_size, int num_parity, unsigned char *out)
{
// Use zero padding in front if data size is too small.
int n = data_size + num_parity; // total size in.
unsigned char rs_block[FX25_BLOCK_SIZE];
// We could probably do this more efficiently by skipping the
// processing of the bytes known to be zero. Good enough for now.
memset (rs_block, 0, sizeof(rs_block) - n);
memcpy (rs_block + sizeof(rs_block) - n, rec_block, n);
if (il2p_get_debug() >= 3) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("============================== il2p_decode_rs ==============================\n");
dw_printf ("%d filler zeros, %d data, %d parity\n", (int)(sizeof(rs_block) - n), data_size, num_parity);
fx_hex_dump (rs_block, sizeof (rs_block));
}
int derrlocs[FX25_MAX_CHECK]; // Half would probably be OK.
int derrors = DECODE_RS(il2p_find_rs(num_parity), rs_block, derrlocs, 0);
memcpy (out, rs_block + sizeof(rs_block) - n, data_size);
if (il2p_get_debug() >= 3) {
if (derrors == 0) {
dw_printf ("No errors reported for RS block.\n");
}
else if (derrors > 0) {
dw_printf ("%d errors fixed in positions:\n", derrors);
for (int j = 0; j < derrors; j++) {
dw_printf (" %3d (0x%02x)\n", derrlocs[j] , derrlocs[j]);
}
fx_hex_dump (rs_block, sizeof (rs_block));
}
}
// It is possible to have a situation where too many errors are
// present but the algorithm could get a good code block by "fixing"
// one of the padding bytes that should be 0.
for (int i = 0; i < derrors; i++) {
if (derrlocs[i] < sizeof(rs_block) - n) {
if (il2p_get_debug() >= 3) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("RS DECODE ERROR! Padding position %d should be 0 but it was set to %02x.\n", derrlocs[i], rs_block[derrlocs[i]]);
}
derrors = -1;
break;
}
}
if (il2p_get_debug() >= 3) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("============================== il2p_decode_rs returns %d ==============================\n", derrors);
}
return (derrors);
}
// end il2p_init.c

298
src/il2p_payload.c Normal file
View File

@ -0,0 +1,298 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "direwolf.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "textcolor.h"
#include "il2p.h"
/*--------------------------------------------------------------------------------
*
* File: il2p_payload.c
*
* Purpose: Functions dealing with the payload.
*
*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------
*
* Function: il2p_payload_compute
*
* Purpose: Compute number and sizes of data blocks based on total size.
*
* Inputs: payload_size 0 to 1023. (IL2P_MAX_PAYLOAD_SIZE)
* max_fec true for 16 parity symbols, false for automatic.
*
* Outputs: *p Payload block sizes and counts.
* Number of parity symbols per block.
*
* Returns: Number of bytes in the encoded format.
* Could be 0 for no payload blocks.
* -1 for error (i.e. invalid unencoded size: <0 or >1023)
*
*--------------------------------------------------------------------------------*/
int il2p_payload_compute (il2p_payload_properties_t *p, int payload_size, int max_fec)
{
memset (p, 0, sizeof(il2p_payload_properties_t));
if (payload_size < 0 || payload_size > IL2P_MAX_PAYLOAD_SIZE) {
return (-1);
}
if (payload_size == 0) {
return (0);
}
if (max_fec) {
p->payload_byte_count = payload_size;
p->payload_block_count = (p->payload_byte_count + 238) / 239;
p->small_block_size = p->payload_byte_count / p->payload_block_count;
p->large_block_size = p->small_block_size + 1;
p->large_block_count = p->payload_byte_count - (p->payload_block_count * p->small_block_size);
p->small_block_count = p->payload_block_count - p->large_block_count;
p->parity_symbols_per_block = 16;
}
else {
p->payload_byte_count = payload_size;
p->payload_block_count = (p->payload_byte_count + 246) / 247;
p->small_block_size = p->payload_byte_count / p->payload_block_count;
p->large_block_size = p->small_block_size + 1;
p->large_block_count = p->payload_byte_count - (p->payload_block_count * p->small_block_size);
p->small_block_count = p->payload_block_count - p->large_block_count;
//p->parity_symbols_per_block = (p->small_block_size / 32) + 2; // Looks like error in documentation
// It would work if the number of parity symbols was based on large block size.
if (p->small_block_size <= 61) p->parity_symbols_per_block = 2;
else if (p->small_block_size <= 123) p->parity_symbols_per_block = 4;
else if (p->small_block_size <= 185) p->parity_symbols_per_block = 6;
else if (p->small_block_size <= 247) p->parity_symbols_per_block = 8;
else {
// Should not happen. But just in case...
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P parity symbol per payload block error. small_block_size = %d\n", p->small_block_size);
return (-1);
}
}
// Return the total size for the encoded format.
return (p->small_block_count * (p->small_block_size + p->parity_symbols_per_block) +
p->large_block_count * (p->large_block_size + p->parity_symbols_per_block));
} // end il2p_payload_compute
/*--------------------------------------------------------------------------------
*
* Function: il2p_encode_payload
*
* Purpose: Split payload into multiple blocks such that each set
* of data and parity symbols fit into a 255 byte RS block.
*
* Inputs: *payload Array of bytes.
* payload_size 0 to 1023. (IL2P_MAX_PAYLOAD_SIZE)
* max_fec true for 16 parity symbols, false for automatic.
*
* Outputs: *enc Encoded payload for transmission.
* Up to IL2P_MAX_ENCODED_SIZE bytes.
*
* Returns: -1 for error (i.e. invalid size)
* 0 for no blocks. (i.e. size zero)
* Number of bytes generated. Maximum IL2P_MAX_ENCODED_SIZE.
*
* Note: I interpreted the protocol spec as saying the LFSR state is retained
* between data blocks. During interoperability testing, I found that
* was not the case. It is reset for each data block.
*
*--------------------------------------------------------------------------------*/
int il2p_encode_payload (unsigned char *payload, int payload_size, int max_fec, unsigned char *enc)
{
if (payload_size > IL2P_MAX_PAYLOAD_SIZE) return (-1);
if (payload_size == 0) return (0);
// Determine number of blocks and sizes.
il2p_payload_properties_t ipp;
int e;
e = il2p_payload_compute (&ipp, payload_size, max_fec);
if (e <= 0) {
return (e);
}
unsigned char *pin = payload;
unsigned char *pout = enc;
int encoded_length = 0;
unsigned char scram[256];
unsigned char parity[IL2P_MAX_PARITY_SYMBOLS];
// First the large blocks.
for (int b = 0; b < ipp.large_block_count; b++) {
il2p_scramble_block (pin, scram, ipp.large_block_size);
memcpy (pout, scram, ipp.large_block_size);
pin += ipp.large_block_size;
pout += ipp.large_block_size;
encoded_length += ipp.large_block_size;
il2p_encode_rs (scram, ipp.large_block_size, ipp.parity_symbols_per_block, parity);
memcpy (pout, parity, ipp.parity_symbols_per_block);
pout += ipp.parity_symbols_per_block;
encoded_length += ipp.parity_symbols_per_block;
}
// Then the small blocks.
for (int b = 0; b < ipp.small_block_count; b++) {
il2p_scramble_block (pin, scram, ipp.small_block_size);
memcpy (pout, scram, ipp.small_block_size);
pin += ipp.small_block_size;
pout += ipp.small_block_size;
encoded_length += ipp.small_block_size;
il2p_encode_rs (scram, ipp.small_block_size, ipp.parity_symbols_per_block, parity);
memcpy (pout, parity, ipp.parity_symbols_per_block);
pout += ipp.parity_symbols_per_block;
encoded_length += ipp.parity_symbols_per_block;
}
return (encoded_length);
} // end il2p_encode_payload
/*--------------------------------------------------------------------------------
*
* Function: il2p_decode_payload
*
* Purpose: Extract original data from encoded payload.
*
* Inputs: received Array of bytes. Size is unknown but in practice it
* must not exceed IL2P_MAX_ENCODED_SIZE.
* payload_size 0 to 1023. (IL2P_MAX_PAYLOAD_SIZE)
* Expected result size based on header.
* max_fec true for 16 parity symbols, false for automatic.
*
* Outputs: payload_out Recovered payload.
*
* In/Out: symbols_corrected Number of symbols corrected.
*
*
* Returns: Number of bytes extracted. Should be same as payload_size going in.
* -3 for unexpected internal inconsistency.
* -2 for unable to recover from signal corruption.
* -1 for invalid size.
* 0 for no blocks. (i.e. size zero)
*
* Description: Each block is scrambled separately but the LSFR state is carried
* from the first payload block to the next.
*
*--------------------------------------------------------------------------------*/
int il2p_decode_payload (unsigned char *received, int payload_size, int max_fec, unsigned char *payload_out, int *symbols_corrected)
{
// Determine number of blocks and sizes.
il2p_payload_properties_t ipp;
int e;
e = il2p_payload_compute (&ipp, payload_size, max_fec);
if (e <= 0) {
return (e);
}
unsigned char *pin = received;
unsigned char *pout = payload_out;
int decoded_length = 0;
int failed = 0;
// First the large blocks.
for (int b = 0; b < ipp.large_block_count; b++) {
unsigned char corrected_block[255];
int e = il2p_decode_rs (pin, ipp.large_block_size, ipp.parity_symbols_per_block, corrected_block);
// dw_printf ("%s:%d: large block decode_rs returned status = %d\n", __FILE__, __LINE__, e);
if (e < 0) failed = 1;
*symbols_corrected += e;
il2p_descramble_block (corrected_block, pout, ipp.large_block_size);
if (il2p_get_debug() >= 2) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("Descrambled large payload block, %d bytes:\n", ipp.large_block_size);
fx_hex_dump(pout, ipp.large_block_size);
}
pin += ipp.large_block_size + ipp.parity_symbols_per_block;
pout += ipp.large_block_size;
decoded_length += ipp.large_block_size;
}
// Then the small blocks.
for (int b = 0; b < ipp.small_block_count; b++) {
unsigned char corrected_block[255];
int e = il2p_decode_rs (pin, ipp.small_block_size, ipp.parity_symbols_per_block, corrected_block);
// dw_printf ("%s:%d: small block decode_rs returned status = %d\n", __FILE__, __LINE__, e);
if (e < 0) failed = 1;
*symbols_corrected += e;
il2p_descramble_block (corrected_block, pout, ipp.small_block_size);
if (il2p_get_debug() >= 2) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("Descrambled small payload block, %d bytes:\n", ipp.small_block_size);
fx_hex_dump(pout, ipp.small_block_size);
}
pin += ipp.small_block_size + ipp.parity_symbols_per_block;
pout += ipp.small_block_size;
decoded_length += ipp.small_block_size;
}
if (failed) {
//dw_printf ("%s:%d: failed = %0x\n", __FILE__, __LINE__, failed);
return (-2);
}
if (decoded_length != payload_size) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P Internal error: decoded_length = %d, payload_size = %d\n", decoded_length, payload_size);
return (-3);
}
return (decoded_length);
} // end il2p_decode_payload
// end il2p_payload.c

276
src/il2p_rec.c Normal file
View File

@ -0,0 +1,276 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
/********************************************************************************
*
* File: il2p_rec.c
*
* Purpose: Extract IL2P frames from a stream of bits and process them.
*
* References: http://tarpn.net/t/il2p/il2p-specification0-4.pdf
*
*******************************************************************************/
#include "direwolf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "textcolor.h"
#include "il2p.h"
#include "multi_modem.h"
#include "demod.h"
struct il2p_context_s {
enum { IL2P_SEARCHING=0, IL2P_HEADER, IL2P_PAYLOAD, IL2P_DECODE } state;
unsigned int acc; // Accumulate most recent 24 bits for sync word matching.
// Lower 8 bits are also used for accumulating bytes for
// the header and payload.
int bc; // Bit counter so we know when a complete byte has been accumulated.
int polarity; // 1 if opposite of expected polarity.
unsigned char shdr[IL2P_HEADER_SIZE+IL2P_HEADER_PARITY];
// Scrambled header as received over the radio. Includes parity.
int hc; // Number if bytes placed in above.
unsigned char uhdr[IL2P_HEADER_SIZE]; // Header after FEC and unscrambling.
int eplen; // Encoded payload length. This is not the nuumber from
// from the header but rather the number of encoded bytes to gather.
unsigned char spayload[IL2P_MAX_ENCODED_PAYLOAD_SIZE];
// Scrambled and encoded payload as received over the radio.
int pc; // Number of bytes placed in above.
int corrected; // Number of symbols corrected by RS FEC.
};
static struct il2p_context_s *il2p_context[MAX_CHANS][MAX_SUBCHANS][MAX_SLICERS];
/***********************************************************************************
*
* Name: il2p_rec_bit
*
* Purpose: Extract FX.25 packets from a stream of bits.
*
* Inputs: chan - Channel number.
*
* subchan - This allows multiple demodulators per channel.
*
* slice - Allows multiple slicers per demodulator (subchannel).
*
* dbit - One bit from the received data stream.
*
* Description: This is called once for each received bit.
* For each valid packet, process_rec_frame() is called for further processing.
* It can gather multiple candidates from different parallel demodulators
* ("subchannels") and slicers, then decide which one is the best.
*
***********************************************************************************/
void il2p_rec_bit (int chan, int subchan, int slice, int dbit)
{
// Allocate context blocks only as needed.
struct il2p_context_s *F = il2p_context[chan][subchan][slice];
if (F == NULL) {
assert (chan >= 0 && chan < MAX_CHANS);
assert (subchan >= 0 && subchan < MAX_SUBCHANS);
assert (slice >= 0 && slice < MAX_SLICERS);
F = il2p_context[chan][subchan][slice] = (struct il2p_context_s *)malloc(sizeof (struct il2p_context_s));
assert (F != NULL);
memset (F, 0, sizeof(struct il2p_context_s));
}
// Accumulate most recent 24 bits received. Most recent is LSB.
F->acc = ((F->acc << 1) | (dbit & 1)) & 0x00ffffff;
// State machine to look for sync word then gather appropriate number of header and payload bytes.
switch (F->state) {
case IL2P_SEARCHING: // Searching for the sync word.
if (__builtin_popcount (F->acc ^ IL2P_SYNC_WORD) <= 1) { // allow single bit mismatch
//text_color_set (DW_COLOR_INFO);
//dw_printf ("IL2P header has normal polarity\n");
F->polarity = 0;
F->state = IL2P_HEADER;
F->bc = 0;
F->hc = 0;
}
else if (__builtin_popcount ((~F->acc & 0x00ffffff) ^ IL2P_SYNC_WORD) <= 1) {
text_color_set (DW_COLOR_INFO);
// FIXME - this pops up occasionally with random noise. Find better way to convey information.
// This also happens for each slicer - to noisy.
//dw_printf ("IL2P header has reverse polarity\n");
F->polarity = 1;
F->state = IL2P_HEADER;
F->bc = 0;
F->hc = 0;
}
break;
case IL2P_HEADER: // Gathering the header.
F->bc++;
if (F->bc == 8) { // full byte has been collected.
F->bc = 0;
if ( ! F->polarity) {
F->shdr[F->hc++] = F->acc & 0xff;
}
else {
F->shdr[F->hc++] = (~ F->acc) & 0xff;
}
if (F->hc == IL2P_HEADER_SIZE+IL2P_HEADER_PARITY) { // Have all of header
if (il2p_get_debug() >= 1) {
text_color_set (DW_COLOR_DEBUG);
dw_printf ("IL2P header as received [%d.%d.%d]:\n", chan, subchan, slice);
fx_hex_dump (F->shdr, IL2P_HEADER_SIZE+IL2P_HEADER_PARITY);
}
// Fix any errors and descramble.
F->corrected = il2p_clarify_header(F->shdr, F->uhdr);
if (F->corrected >= 0) { // Good header.
// How much payload is expected?
il2p_payload_properties_t plprop;
int hdr_type, max_fec;
int len = il2p_get_header_attributes (F->uhdr, &hdr_type, &max_fec);
F->eplen = il2p_payload_compute (&plprop, len, max_fec);
if (il2p_get_debug() >= 1) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("IL2P header after correcting %d symbols and unscrambling [%d.%d.%d]:\n", F->corrected, chan, subchan, slice);
fx_hex_dump (F->uhdr, IL2P_HEADER_SIZE);
dw_printf ("Header type %d, max fec = %d\n", hdr_type, max_fec);
dw_printf ("Need to collect %d encoded bytes for %d byte payload.\n", F->eplen, len);
dw_printf ("%d small blocks of %d and %d large blocks of %d. %d parity symbols per block\n",
plprop.small_block_count, plprop.small_block_size,
plprop.large_block_count, plprop.large_block_size, plprop.parity_symbols_per_block);
}
if (F->eplen >= 1) { // Need to gather payload.
F->pc = 0;
F->state = IL2P_PAYLOAD;
}
else if (F->eplen == 0) { // No payload.
F->pc = 0;
F->state = IL2P_DECODE;
}
else { // Error.
if (il2p_get_debug() >= 1) {
text_color_set (DW_COLOR_ERROR);
dw_printf ("IL2P header INVALID.\n");
}
F->state = IL2P_SEARCHING;
}
} // good header after FEC.
else {
F->state = IL2P_SEARCHING; // Header failed FEC check.
}
} // entire header has been collected.
} // full byte collected.
break;
case IL2P_PAYLOAD: // Gathering the payload, if any.
F->bc++;
if (F->bc == 8) { // full byte has been collected.
F->bc = 0;
if ( ! F->polarity) {
F->spayload[F->pc++] = F->acc & 0xff;
}
else {
F->spayload[F->pc++] = (~ F->acc) & 0xff;
}
if (F->pc == F->eplen) {
// TODO?: for symmetry it seems like we should clarify the payload before combining.
F->state = IL2P_DECODE;
}
}
break;
case IL2P_DECODE:
// We get here after a good header and any payload has been collected.
// Processing is delayed by one bit but I think it makes the logic cleaner.
// During unit testing be sure to send an extra bit to flush it out at the end.
// in uhdr[IL2P_HEADER_SIZE]; // Header after FEC and descrambling.
// TODO?: for symmetry, we might decode the payload here and later build the frame.
{
packet_t pp = il2p_decode_header_payload (F->uhdr, F->spayload, &(F->corrected));
if (il2p_get_debug() >= 1) {
if (pp != NULL) {
ax25_hex_dump (pp);
}
else {
// Most likely too many FEC errors.
text_color_set(DW_COLOR_ERROR);
dw_printf ("FAILED to construct frame in %s.\n", __func__);
}
}
if (pp != NULL) {
alevel_t alevel = demod_get_audio_level (chan, subchan);
retry_t retries = F->corrected;
int is_fx25 = 1; // FIXME: distinguish fx.25 and IL2P.
// Currently this just means that a FEC mode was used.
// TODO: Could we put last 3 arguments in packet object rather than passing around separately?
multi_modem_process_rec_packet (chan, subchan, slice, pp, alevel, retries, is_fx25);
}
} // end block for local variables.
if (il2p_get_debug() >= 1) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("-----\n");
}
F->state = IL2P_SEARCHING;
break;
} // end of switch
} // end il2p_rec_bit
// end il2p_rec.c

157
src/il2p_scramble.c Normal file
View File

@ -0,0 +1,157 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
/*--------------------------------------------------------------------------------
*
* File: il2p_scramble.c
*
* Purpose: Scramble / descramble data as specified in the IL2P protocol specification.
*
*--------------------------------------------------------------------------------*/
#include "direwolf.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "il2p.h"
// Scramble bits for il2p transmit.
// Note that there is a delay of 5 until the first bit comes out.
// So we need to need to ignore the first 5 out and stick in
// an extra 5 filler bits to flush at the end.
#define INIT_TX_LSFR 0x00f
static inline int scramble_bit (int in, int *state)
{
int out = ((*state >> 4) ^ *state) & 1;
*state = ( (((in ^ *state) & 1) << 9) | (*state ^ ((*state & 1) << 4)) ) >> 1;
return (out);
}
// Undo data scrambling for il2p receive.
#define INIT_RX_LSFR 0x1f0
static inline int descramble_bit (int in, int *state)
{
int out = (in ^ *state) & 1;
*state = ((*state >> 1) | ((in & 1) << 8)) ^ ((in & 1) << 3);
return (out);
}
/*--------------------------------------------------------------------------------
*
* Function: il2p_scramble_block
*
* Purpose: Scramble a block before adding RS parity.
*
* Inputs: in Array of bytes.
* len Number of bytes both in and out.
*
* Outputs: out Array of bytes.
*
*--------------------------------------------------------------------------------*/
void il2p_scramble_block (unsigned char *in, unsigned char *out, int len)
{
int tx_lfsr_state = INIT_TX_LSFR;
memset (out, 0, len);
int skipping = 1; // Discard the first 5 out.
int ob = 0; // Index to output byte.
int om = 0x80; // Output bit mask;
for (int ib = 0; ib < len; ib++) {
for (int im = 0x80; im != 0; im >>= 1) {
int s = scramble_bit((in[ib] & im) != 0, &tx_lfsr_state);
if (ib == 0 && im == 0x04) skipping = 0;
if ( ! skipping) {
if (s) {
out[ob] |= om;
}
om >>= 1;
if (om == 0) {
om = 0x80;
ob++;
}
}
}
}
// Flush it.
// This is a relic from when I thought the state would need to
// be passed along for the next block.
// Preserve the LSFR state from before flushing.
// This might be needed as the initial state for later payload blocks.
int x = tx_lfsr_state;
for (int n = 0; n < 5; n++) {
int s = scramble_bit(0, &x);
if (s) {
out[ob] |= om;
}
om >>=1;
if (om == 0) {
om = 0x80;
ob++;
}
}
} // end il2p_scramble_block
/*--------------------------------------------------------------------------------
*
* Function: il2p_descramble_block
*
* Purpose: Descramble a block after removing RS parity.
*
* Inputs: in Array of bytes.
* len Number of bytes both in and out.
*
* Outputs: out Array of bytes.
*
*--------------------------------------------------------------------------------*/
void il2p_descramble_block (unsigned char *in, unsigned char *out, int len)
{
int rx_lfsr_state = INIT_RX_LSFR;
memset (out, 0, len);
for (int b = 0; b < len; b++) {
for (int m = 0x80; m != 0; m >>= 1) {
int d = descramble_bit((in[b] & m) != 0, &rx_lfsr_state);
if (d) {
out[b] |= m;
}
}
}
}
// end il2p_scramble.c

147
src/il2p_send.c Normal file
View File

@ -0,0 +1,147 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "direwolf.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "il2p.h"
#include "textcolor.h"
#include "audio.h"
#include "gen_tone.h"
static int number_of_bits_sent[MAX_CHANS]; // Count number of bits sent by "il2p_send_frame"
static void send_bytes (int chan, unsigned char *b, int count, int polarity);
static void send_bit (int chan, int b, int polarity);
/*-------------------------------------------------------------
*
* Name: il2p_send_frame
*
* Purpose: Convert frames to a stream of bits in IL2P format.
*
* Inputs: chan - Audio channel number, 0 = first.
*
* pp - Pointer to packet object.
*
* max_fec - 1 to force 16 parity symbols for each payload block.
* 0 for automatic depending on block size.
*
* polarity - 0 for normal. 1 to invert signal.
* 2 special case for testing - introduce some errors to test FEC.
*
* Outputs: Bits are shipped out by calling tone_gen_put_bit().
*
* Returns: Number of bits sent including
* - Preamble (01010101...)
* - 3 byte Sync Word.
* - 15 bytes for Header.
* - Optional payload.
* The required time can be calculated by dividing this
* number by the transmit rate of bits/sec.
* -1 is returned for failure.
*
* Description: Generate an IL2P encoded frame.
*
* Assumptions: It is assumed that the tone_gen module has been
* properly initialized so that bits sent with
* tone_gen_put_bit() are processed correctly.
*
* Errors: Return -1 for error. Probably frame too large.
*
* Note: Inconsistency here. ax25 version has just a byte array
* and length going in. Here we need the full packet object.
*
*--------------------------------------------------------------*/
int il2p_send_frame (int chan, packet_t pp, int max_fec, int polarity)
{
unsigned char encoded[IL2P_MAX_PACKET_SIZE];
encoded[0] = ( IL2P_SYNC_WORD >> 16 ) & 0xff;
encoded[1] = ( IL2P_SYNC_WORD >> 8 ) & 0xff;
encoded[2] = ( IL2P_SYNC_WORD ) & 0xff;
int elen = il2p_encode_frame (pp, max_fec, encoded + IL2P_SYNC_WORD_SIZE);
if (elen <= 0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("IL2P: Unable to encode frame into IL2P.\n");
return (-1);
}
elen += IL2P_SYNC_WORD_SIZE;
number_of_bits_sent[chan] = 0;
if (il2p_get_debug() >= 1) {
text_color_set(DW_COLOR_DEBUG);
dw_printf ("IL2P frame, max_fec = %d, %d encoded bytes total\n", max_fec, elen);
fx_hex_dump (encoded, elen);
}
// Clobber some bytes for testing.
if (polarity >= 2) {
for (int j = 10; j < elen; j+=100) {
encoded[j] = ~ encoded[j];
}
}
// Send bits to modulator.
static unsigned char preamble = IL2P_PREAMBLE;
send_bytes (chan, &preamble, 1, polarity);
send_bytes (chan, encoded, elen, polarity);
return (number_of_bits_sent[chan]);
}
static void send_bytes (int chan, unsigned char *b, int count, int polarity)
{
for (int j = 0; j < count; j++) {
unsigned int x = b[j];
for (int k = 0; k < 8; k++) {
send_bit (chan, (x & 0x80) != 0, polarity);
x <<= 1;
}
}
}
// NRZI would be applied for AX.25 but IL2P does not use it.
// However we do have an option to invert the signal.
// The direwolf receive implementation will automatically compensate
// for either polarity but other implementations might not.
static void send_bit (int chan, int b, int polarity)
{
tone_gen_put_bit (chan, (b ^ polarity) & 1);
number_of_bits_sent[chan]++;
}
// end il2p_send.c

977
src/il2p_test.c Normal file
View File

@ -0,0 +1,977 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2021 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "direwolf.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "textcolor.h"
#include "il2p.h"
#include "ax25_pad.h"
#include "ax25_pad2.h"
#include "multi_modem.h"
static void test_scramble(void);
static void test_rs(void);
static void test_payload(void);
static void test_example_headers(void);
static void all_frame_types(void);
static void test_serdes(void);
static void decode_bitstream(void);
/*-------------------------------------------------------------
*
* Name: il2p_test.c
*
* Purpose: Unit tests for IL2P protocol functions.
*
* Errors: Die if anything goes wrong.
*
*--------------------------------------------------------------*/
int main ()
{
int enable_color = 1;
text_color_init (enable_color);
int enable_debug_out = 0;
il2p_init(enable_debug_out);
text_color_set(DW_COLOR_INFO);
dw_printf ("Begin IL2P unit tests.\n");
// These start simple and later complex cases build upon earlier successes.
// Test scramble and descramble.
test_scramble();
// Test Reed Solomon error correction.
test_rs();
// Test payload functions.
test_payload();
// Try encoding the example headers in the protocol spec.
test_example_headers();
// Convert all of the AX.25 frame types to IL2P and back again.
all_frame_types();
// Use same serialize / deserialize functions used on the air.
test_serdes ();
// Decode bitstream from demodulator if data file is available.
// TODO: Very large info parts. Appropriate error if too long.
// TODO: More than 2 addresses.
decode_bitstream();
text_color_set(DW_COLOR_REC);
dw_printf ("\n----------\n\n");
dw_printf ("\nSUCCESS!\n");
return (EXIT_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test scrambling and descrambling.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static void test_scramble(void)
{
text_color_set(DW_COLOR_INFO);
dw_printf ("Test scrambling...\n");
// First an example from the protocol specification to make sure I'm compatible.
static unsigned char scramin1[] = { 0x63, 0xf1, 0x40, 0x40, 0x40, 0x00, 0x6b, 0x2b, 0x54, 0x28, 0x25, 0x2a, 0x0f };
static unsigned char scramout1[] = { 0x6a, 0xea, 0x9c, 0xc2, 0x01, 0x11, 0xfc, 0x14, 0x1f, 0xda, 0x6e, 0xf2, 0x53 };
unsigned char scramout[sizeof(scramin1)];
il2p_scramble_block (scramin1, scramout, sizeof(scramin1));
assert (memcmp(scramout, scramout, sizeof(scramout1)) == 0);
} // end test_scramble.
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test Reed Solomon encode/decode examples found in the protocol spec.
// The data part is scrambled but that does not matter here because.
// We are only concerned abound adding the parity and verifying.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static void test_rs()
{
text_color_set(DW_COLOR_INFO);
dw_printf ("Test Reed Solomon functions...\n");
static unsigned char example_s[] = { 0x26, 0x57, 0x4d, 0x57, 0xf1, 0x96, 0xcc, 0x85, 0x42, 0xe7, 0x24, 0xf7, 0x2e,
0x8a, 0x97 };
unsigned char parity_out[2];
il2p_encode_rs (example_s, 13, 2, parity_out);
//dw_printf ("DEBUG RS encode %02x %02x\n", parity_out[0], parity_out[1]);
assert (memcmp(parity_out, example_s + 13, 2) == 0);
static unsigned char example_u[] = { 0x6a, 0xea, 0x9c, 0xc2, 0x01, 0x11, 0xfc, 0x14, 0x1f, 0xda, 0x6e, 0xf2, 0x53,
0x91, 0xbd };
il2p_encode_rs (example_u, 13, 2, parity_out);
//dw_printf ("DEBUG RS encode %02x %02x\n", parity_out[0], parity_out[1]);
assert (memcmp(parity_out, example_u + 13, 2) == 0);
// See if we can go the other way.
unsigned char received[15];
unsigned char corrected[15];
int e;
e = il2p_decode_rs (example_s, 13, 2, corrected);
assert (e == 0);
assert (memcmp(example_s, corrected, 13) == 0);
memcpy (received, example_s, 15);
received[0] = '?';
e = il2p_decode_rs (received, 13, 2, corrected);
assert (e == 1);
assert (memcmp(example_s, corrected, 13) == 0);
e = il2p_decode_rs (example_u, 13, 2, corrected);
assert (e == 0);
assert (memcmp(example_u, corrected, 13) == 0);
memcpy (received, example_u, 15);
received[12] = '?';
e = il2p_decode_rs (received, 13, 2, corrected);
assert (e == 1);
assert (memcmp(example_u, corrected, 13) == 0);
received[1] = '?';
received[2] = '?';
e = il2p_decode_rs (received, 13, 2, corrected);
assert (e == -1);
}
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test payload functions.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static void test_payload(void)
{
text_color_set(DW_COLOR_INFO);
dw_printf ("Test payload functions...\n");
il2p_payload_properties_t ipp;
int e;
// Examples in specification.
e = il2p_payload_compute (&ipp, 100, 0);
assert (ipp.small_block_size == 100);
assert (ipp.large_block_size == 101);
assert (ipp.large_block_count == 0);
assert (ipp.small_block_count == 1);
assert (ipp.parity_symbols_per_block == 4);
e = il2p_payload_compute (&ipp, 236, 0);
assert (ipp.small_block_size == 236);
assert (ipp.large_block_size == 237);
assert (ipp.large_block_count == 0);
assert (ipp.small_block_count == 1);
assert (ipp.parity_symbols_per_block == 8);
e = il2p_payload_compute (&ipp, 512, 0);
assert (ipp.small_block_size == 170);
assert (ipp.large_block_size == 171);
assert (ipp.large_block_count == 2);
assert (ipp.small_block_count == 1);
assert (ipp.parity_symbols_per_block == 6);
e = il2p_payload_compute (&ipp, 1023, 0);
assert (ipp.small_block_size == 204);
assert (ipp.large_block_size == 205);
assert (ipp.large_block_count == 3);
assert (ipp.small_block_count == 2);
assert (ipp.parity_symbols_per_block == 8);
// Now try all possible sizes for Baseline FEC Parity.
for (int n = 1; n <= IL2P_MAX_PAYLOAD_SIZE; n++) {
e = il2p_payload_compute (&ipp, n, 0);
//dw_printf ("bytecount=%d, smallsize=%d, largesize=%d, largecount=%d, smallcount=%d\n", n,
// ipp.small_block_size, ipp.large_block_size,
// ipp.large_block_count, ipp.small_block_count);
//fflush (stdout);
assert (ipp.payload_block_count >= 1 && ipp.payload_block_count <= IL2P_MAX_PAYLOAD_BLOCKS);
assert (ipp.payload_block_count == ipp.small_block_count + ipp.large_block_count);
assert (ipp.small_block_count * ipp.small_block_size +
ipp.large_block_count * ipp.large_block_size == n);
assert (ipp.parity_symbols_per_block == 2 ||
ipp.parity_symbols_per_block == 4 ||
ipp.parity_symbols_per_block == 6 ||
ipp.parity_symbols_per_block == 8);
// Data and parity must fit in RS block size of 255.
// Size test does not apply if block count is 0.
assert (ipp.small_block_count == 0 || ipp.small_block_size + ipp.parity_symbols_per_block <= 255);
assert (ipp.large_block_count == 0 || ipp.large_block_size + ipp.parity_symbols_per_block <= 255);
}
// All sizes for MAX FEC.
for (int n = 1; n <= IL2P_MAX_PAYLOAD_SIZE; n++) {
e = il2p_payload_compute (&ipp, n, 1); // 1 for max fec.
//dw_printf ("bytecount=%d, smallsize=%d, largesize=%d, largecount=%d, smallcount=%d\n", n,
// ipp.small_block_size, ipp.large_block_size,
// ipp.large_block_count, ipp.small_block_count);
//fflush (stdout);
assert (ipp.payload_block_count >= 1 && ipp.payload_block_count <= IL2P_MAX_PAYLOAD_BLOCKS);
assert (ipp.payload_block_count == ipp.small_block_count + ipp.large_block_count);
assert (ipp.small_block_count * ipp.small_block_size +
ipp.large_block_count * ipp.large_block_size == n);
assert (ipp.parity_symbols_per_block == 16);
// Data and parity must fit in RS block size of 255.
// Size test does not apply if block count is 0.
assert (ipp.small_block_count == 0 || ipp.small_block_size + ipp.parity_symbols_per_block <= 255);
assert (ipp.large_block_count == 0 || ipp.large_block_size + ipp.parity_symbols_per_block <= 255);
}
// Now let's try encoding payloads and extracting original again.
// This will also provide exercise for scrambling and Reed Solomon under more conditions.
unsigned char original_payload[IL2P_MAX_PAYLOAD_SIZE];
for (int n = 0; n < IL2P_MAX_PAYLOAD_SIZE; n++) {
original_payload[n] = n & 0xff;
}
for (int max_fec = 0; max_fec <= 1; max_fec++) {
for (int payload_length = 1; payload_length <= IL2P_MAX_PAYLOAD_SIZE; payload_length++) {
//dw_printf ("\n--------- max_fec = %d, payload_length = %d\n", max_fec, payload_length);
unsigned char encoded[IL2P_MAX_ENCODED_PAYLOAD_SIZE];
int k = il2p_encode_payload (original_payload, payload_length, max_fec, encoded);
//dw_printf ("payload length %d %s -> %d\n", payload_length, max_fec ? "M" : "", k);
assert (k > payload_length && k <= IL2P_MAX_ENCODED_PAYLOAD_SIZE);
// Now extract.
unsigned char extracted[IL2P_MAX_PAYLOAD_SIZE];
int symbols_corrected = 0;
int e = il2p_decode_payload (encoded, payload_length, max_fec, extracted, &symbols_corrected);
//dw_printf ("e = %d, payload_length = %d\n", e, payload_length);
assert (e == payload_length);
// if (memcmp (original_payload, extracted, payload_length) != 0) {
// dw_printf ("********** Received message not as expected. **********\n");
// fx_hex_dump(extracted, payload_length);
// }
assert (memcmp (original_payload, extracted, payload_length) == 0);
}
}
(void)e;
} // end test_payload
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test header examples found in protocol specification.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static void test_example_headers()
{
//----------- Example 1: AX.25 S-Frame --------------
// This frame sample only includes a 15 byte header, without PID field.
// Destination Callsign: ?KA2DEW-2
// Source Callsign: ?KK4HEJ-7
// N(R): 5
// P/F: 1
// C: 1
// Control Opcode: 00 (Receive Ready)
//
// AX.25 data:
// 96 82 64 88 8a ae e4 96 96 68 90 8a 94 6f b1
//
// IL2P Data Prior to Scrambling and RS Encoding:
// 2b a1 12 24 25 77 6b 2b 54 68 25 2a 27
//
// IL2P Data After Scrambling and RS Encoding:
// 26 57 4d 57 f1 96 cc 85 42 e7 24 f7 2e 8a 97
text_color_set(DW_COLOR_INFO);
dw_printf ("Example 1: AX.25 S-Frame...\n");
static unsigned char example1[] = {0x96, 0x82, 0x64, 0x88, 0x8a, 0xae, 0xe4, 0x96, 0x96, 0x68, 0x90, 0x8a, 0x94, 0x6f, 0xb1};
static unsigned char header1[] = {0x2b, 0xa1, 0x12, 0x24, 0x25, 0x77, 0x6b, 0x2b, 0x54, 0x68, 0x25, 0x2a, 0x27 };
unsigned char header[IL2P_HEADER_SIZE];
unsigned char sresult[32];
memset (header, 0, sizeof(header));
memset (sresult, 0, sizeof(sresult));
unsigned char check[2];
alevel_t alevel;
memset(&alevel, 0, sizeof(alevel));
packet_t pp = ax25_from_frame (example1, sizeof(example1), alevel);
assert (pp != NULL);
int e;
e = il2p_type_1_header (pp, 0, header);
assert (e == 0);
ax25_delete(pp);
//dw_printf ("Example 1 header:\n");
//for (int i = 0 ; i < sizeof(header); i++) {
// dw_printf (" %02x", header[i]);
//}
///dw_printf ("\n");
assert (memcmp(header, header1, sizeof(header)) == 0);
il2p_scramble_block (header, sresult, 13);
//dw_printf ("Expect scrambled 26 57 4d 57 f1 96 cc 85 42 e7 24 f7 2e\n");
//for (int i = 0 ; i < sizeof(sresult); i++) {
// dw_printf (" %02x", sresult[i]);
//}
//dw_printf ("\n");
il2p_encode_rs (sresult, 13, 2, check);
//dw_printf ("expect checksum = 8a 97\n");
//dw_printf ("check = ");
//for (int i = 0 ; i < sizeof(check); i++) {
// dw_printf (" %02x", check[i]);
//}
//dw_printf ("\n");
assert (check[0] == 0x8a);
assert (check[1] == 0x97);
// Can we go from IL2P back to AX.25?
pp = il2p_decode_header_type_1 (header, 0);
assert (pp != NULL);
char dst_addr[AX25_MAX_ADDR_LEN];
char src_addr[AX25_MAX_ADDR_LEN];
ax25_get_addr_with_ssid (pp, AX25_DESTINATION, dst_addr);
ax25_get_addr_with_ssid (pp, AX25_SOURCE, src_addr);
ax25_frame_type_t frame_type;
cmdres_t cr; // command or response.
char description[64];
int pf; // Poll/Final.
int nr, ns; // Sequence numbers.
frame_type = ax25_frame_type (pp, &cr, description, &pf, &nr, &ns);
(void)frame_type;
#if 1
dw_printf ("%s(): %s>%s: %s\n", __func__, src_addr, dst_addr, description);
#endif
// TODO: compare binary.
ax25_delete (pp);
dw_printf ("Example 1 header OK\n");
// -------------- Example 2 - UI frame, no info part ------------------
// This is an AX.25 Unnumbered Information frame, such as APRS.
// Destination Callsign: ?CQ -0
// Source Callsign: ?KK4HEJ-15
// P/F: 0
// C: 0
// Control Opcode: 3 Unnumbered Information
// PID: 0xF0 No L3
//
// AX.25 Data:
// 86 a2 40 40 40 40 60 96 96 68 90 8a 94 7f 03 f0
//
// IL2P Data Prior to Scrambling and RS Encoding:
// 63 f1 40 40 40 00 6b 2b 54 28 25 2a 0f
//
// IL2P Data After Scrambling and RS Encoding:
// 6a ea 9c c2 01 11 fc 14 1f da 6e f2 53 91 bd
//dw_printf ("---------- example 2 ------------\n");
static unsigned char example2[] = { 0x86, 0xa2, 0x40, 0x40, 0x40, 0x40, 0x60, 0x96, 0x96, 0x68, 0x90, 0x8a, 0x94, 0x7f, 0x03, 0xf0 };
static unsigned char header2[] = { 0x63, 0xf1, 0x40, 0x40, 0x40, 0x00, 0x6b, 0x2b, 0x54, 0x28, 0x25, 0x2a, 0x0f };
memset (header, 0, sizeof(header));
memset (sresult, 0, sizeof(sresult));
memset(&alevel, 0, sizeof(alevel));
pp = ax25_from_frame (example2, sizeof(example2), alevel);
assert (pp != NULL);
e = il2p_type_1_header (pp, 0, header);
assert (e == 0);
ax25_delete(pp);
//dw_printf ("Example 2 header:\n");
//for (int i = 0 ; i < sizeof(header); i++) {
// dw_printf (" %02x", header[i]);
//}
//dw_printf ("\n");
assert (memcmp(header, header2, sizeof(header2)) == 0);
il2p_scramble_block (header, sresult, 13);
//dw_printf ("Expect scrambled 6a ea 9c c2 01 11 fc 14 1f da 6e f2 53\n");
//for (int i = 0 ; i < sizeof(sresult); i++) {
// dw_printf (" %02x", sresult[i]);
//}
//dw_printf ("\n");
il2p_encode_rs (sresult, 13, 2, check);
//dw_printf ("expect checksum = 91 bd\n");
//dw_printf ("check = ");
//for (int i = 0 ; i < sizeof(check); i++) {
// dw_printf (" %02x", check[i]);
//}
//dw_printf ("\n");
assert (check[0] == 0x91);
assert (check[1] == 0xbd);
// Can we go from IL2P back to AX.25?
pp = il2p_decode_header_type_1 (header, 0);
assert (pp != NULL);
ax25_get_addr_with_ssid (pp, AX25_DESTINATION, dst_addr);
ax25_get_addr_with_ssid (pp, AX25_SOURCE, src_addr);
frame_type = ax25_frame_type (pp, &cr, description, &pf, &nr, &ns);
(void)frame_type;
#if 1
dw_printf ("%s(): %s>%s: %s\n", __func__, src_addr, dst_addr, description);
#endif
// TODO: compare binary.
ax25_delete (pp);
// TODO: more examples
dw_printf ("Example 2 header OK\n");
// -------------- Example 3 - I Frame ------------------
// This is an AX.25 I-Frame with 9 bytes of information after the 16 byte header.
//
// Destination Callsign: ?KA2DEW-2
// Source Callsign: ?KK4HEJ-2
// P/F: 1
// C: 1
// N(R): 5
// N(S): 4
// AX.25 PID: 0xCF TheNET
// IL2P Payload Byte Count: 9
//
// AX.25 Data:
// 96 82 64 88 8a ae e4 96 96 68 90 8a 94 65 b8 cf 30 31 32 33 34 35 36 37 38
//
// IL2P Scrambled and Encoded Data:
// 26 13 6d 02 8c fe fb e8 aa 94 2d 6a 34 43 35 3c 69 9f 0c 75 5a 38 a1 7f f3 fc
//dw_printf ("---------- example 3 ------------\n");
static unsigned char example3[] = { 0x96, 0x82, 0x64, 0x88, 0x8a, 0xae, 0xe4, 0x96, 0x96, 0x68, 0x90, 0x8a, 0x94, 0x65, 0xb8, 0xcf, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 };
static unsigned char header3[] = { 0x2b, 0xe1, 0x52, 0x64, 0x25, 0x77, 0x6b, 0x2b, 0xd4, 0x68, 0x25, 0xaa, 0x22 };
static unsigned char complete3[] = { 0x26, 0x13, 0x6d, 0x02, 0x8c, 0xfe, 0xfb, 0xe8, 0xaa, 0x94, 0x2d, 0x6a, 0x34, 0x43, 0x35, 0x3c, 0x69, 0x9f, 0x0c, 0x75, 0x5a, 0x38, 0xa1, 0x7f, 0xf3, 0xfc };
memset (header, 0, sizeof(header));
memset (sresult, 0, sizeof(sresult));
memset(&alevel, 0, sizeof(alevel));
pp = ax25_from_frame (example3, sizeof(example3), alevel);
assert (pp != NULL);
e = il2p_type_1_header (pp, 0, header);
assert (e == 9);
ax25_delete(pp);
//dw_printf ("Example 3 header:\n");
//for (int i = 0 ; i < sizeof(header); i++) {
// dw_printf (" %02x", header[i]);
//}
//dw_printf ("\n");
assert (memcmp(header, header3, sizeof(header)) == 0);
il2p_scramble_block (header, sresult, 13);
//dw_printf ("Expect scrambled 26 13 6d 02 8c fe fb e8 aa 94 2d 6a 34\n");
//for (int i = 0 ; i < sizeof(sresult); i++) {
// dw_printf (" %02x", sresult[i]);
//}
//dw_printf ("\n");
il2p_encode_rs (sresult, 13, 2, check);
//dw_printf ("expect checksum = 43 35\n");
//dw_printf ("check = ");
//for (int i = 0 ; i < sizeof(check); i++) {
// dw_printf (" %02x", check[i]);
//}
//dw_printf ("\n");
assert (check[0] == 0x43);
assert (check[1] == 0x35);
// That was only the header. We will get to the info part in a later test.
// Can we go from IL2P back to AX.25?
pp = il2p_decode_header_type_1 (header, 0);
assert (pp != NULL);
ax25_get_addr_with_ssid (pp, AX25_DESTINATION, dst_addr);
ax25_get_addr_with_ssid (pp, AX25_SOURCE, src_addr);
frame_type = ax25_frame_type (pp, &cr, description, &pf, &nr, &ns);
(void)frame_type;
#if 1
dw_printf ("%s(): %s>%s: %s\n", __func__, src_addr, dst_addr, description);
#endif
// TODO: compare binary.
ax25_delete (pp);
dw_printf ("Example 3 header OK\n");
// Example 3 again, this time the Information part is included.
pp = ax25_from_frame (example3, sizeof(example3), alevel);
assert (pp != NULL);
int max_fec = 0;
unsigned char iout[IL2P_MAX_PACKET_SIZE];
e = il2p_encode_frame (pp, max_fec, iout);
//dw_printf ("expected for example 3:\n");
//fx_hex_dump(complete3, sizeof(complete3));
//dw_printf ("actual result for example 3:\n");
//fx_hex_dump(iout, e);
// Does it match the example in the protocol spec?
assert (e == sizeof(complete3));
assert (memcmp(iout, complete3, sizeof(complete3)) == 0);
ax25_delete (pp);
dw_printf ("Example 3 with info OK\n");
} // end test_example_headers
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test all of the frame types.
//
// Encode to IL2P format, decode, and verify that the result is the same as the original.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static void enc_dec_compare (packet_t pp1)
{
for (int max_fec = 0; max_fec <= 1; max_fec++) {
unsigned char encoded[IL2P_MAX_PACKET_SIZE];
int enc_len;
enc_len = il2p_encode_frame (pp1, max_fec, encoded);
assert (enc_len >= 0);
packet_t pp2;
pp2 = il2p_decode_frame (encoded);
assert (pp2 != NULL);
// Is it the same after encoding to IL2P and then decoding?
int len1 = ax25_get_frame_len (pp1);
unsigned char *data1 = ax25_get_frame_data_ptr (pp1);
int len2 = ax25_get_frame_len (pp2);
unsigned char *data2 = ax25_get_frame_data_ptr (pp2);
if (len1 != len2 || memcmp(data1, data2, len1) != 0) {
dw_printf ("\nEncode/Decode Error. Original:\n");
ax25_hex_dump (pp1);
dw_printf ("IL2P encoded as:\n");
fx_hex_dump(encoded, enc_len);
dw_printf ("Got turned into this:\n");
ax25_hex_dump (pp2);
}
assert (len1 == len2 && memcmp(data1, data2, len1) == 0);
ax25_delete (pp2);
}
}
static void all_frame_types(void)
{
char addrs[AX25_MAX_ADDRS][AX25_MAX_ADDR_LEN];
int num_addr = 2;
cmdres_t cr;
ax25_frame_type_t ftype;
int pf = 0;
int pid = 0xf0;
int modulo;
int nr, ns;
unsigned char *pinfo = NULL;
int info_len = 0;
packet_t pp;
strcpy (addrs[0], "W2UB");
strcpy (addrs[1], "WB2OSZ-12");
num_addr = 2;
text_color_set(DW_COLOR_INFO);
dw_printf ("Testing all frame types.\n");
/* U frame */
dw_printf ("\nU frames...\n");
for (ftype = frame_type_U_SABME; ftype <= frame_type_U_TEST; ftype++) {
for (pf = 0; pf <= 1; pf++) {
int cmin = 0, cmax = 1;
switch (ftype) {
// 0 = response, 1 = command
case frame_type_U_SABME: cmin = 1; cmax = 1; break;
case frame_type_U_SABM: cmin = 1; cmax = 1; break;
case frame_type_U_DISC: cmin = 1; cmax = 1; break;
case frame_type_U_DM: cmin = 0; cmax = 0; break;
case frame_type_U_UA: cmin = 0; cmax = 0; break;
case frame_type_U_FRMR: cmin = 0; cmax = 0; break;
case frame_type_U_UI: cmin = 0; cmax = 1; break;
case frame_type_U_XID: cmin = 0; cmax = 1; break;
case frame_type_U_TEST: cmin = 0; cmax = 1; break;
default: break; // avoid compiler warning.
}
for (cr = cmin; cr <= cmax; cr++) {
text_color_set(DW_COLOR_INFO);
dw_printf ("\nConstruct U frame, cr=%d, ftype=%d, pid=0x%02x\n", cr, ftype, pid);
pp = ax25_u_frame (addrs, num_addr, cr, ftype, pf, pid, pinfo, info_len);
ax25_hex_dump (pp);
enc_dec_compare (pp);
ax25_delete (pp);
}
}
}
/* S frame */
//strcpy (addrs[2], "DIGI1-1");
//num_addr = 3;
dw_printf ("\nS frames...\n");
for (ftype = frame_type_S_RR; ftype <= frame_type_S_SREJ; ftype++) {
for (pf = 0; pf <= 1; pf++) {
modulo = 8;
nr = modulo / 2 + 1;
// SREJ can only be response.
for (cr = 0; cr <= (int)(ftype!=frame_type_S_SREJ); cr++) {
text_color_set(DW_COLOR_INFO);
dw_printf ("\nConstruct S frame, cmd=%d, ftype=%d, pid=0x%02x\n", cr, ftype, pid);
pp = ax25_s_frame (addrs, num_addr, cr, ftype, modulo, nr, pf, NULL, 0);
ax25_hex_dump (pp);
enc_dec_compare (pp);
ax25_delete (pp);
}
modulo = 128;
nr = modulo / 2 + 1;
for (cr = 0; cr <= (int)(ftype!=frame_type_S_SREJ); cr++) {
text_color_set(DW_COLOR_INFO);
dw_printf ("\nConstruct S frame, cmd=%d, ftype=%d, pid=0x%02x\n", cr, ftype, pid);
pp = ax25_s_frame (addrs, num_addr, cr, ftype, modulo, nr, pf, NULL, 0);
ax25_hex_dump (pp);
enc_dec_compare (pp);
ax25_delete (pp);
}
}
}
/* SREJ is only S frame which can have information part. */
static unsigned char srej_info[] = { 1<<1, 2<<1, 3<<1, 4<<1 };
ftype = frame_type_S_SREJ;
for (pf = 0; pf <= 1; pf++) {
modulo = 128;
nr = 127;
cr = cr_res;
text_color_set(DW_COLOR_INFO);
dw_printf ("\nConstruct Multi-SREJ S frame, cmd=%d, ftype=%d, pid=0x%02x\n", cr, ftype, pid);
pp = ax25_s_frame (addrs, num_addr, cr, ftype, modulo, nr, pf, srej_info, (int)(sizeof(srej_info)));
ax25_hex_dump (pp);
enc_dec_compare (pp);
ax25_delete (pp);
}
/* I frame */
dw_printf ("\nI frames...\n");
pinfo = (unsigned char*)"The rain in Spain stays mainly on the plain.";
info_len = strlen((char*)pinfo);
for (pf = 0; pf <= 1; pf++) {
modulo = 8;
nr = 0x55 & (modulo - 1);
ns = 0xaa & (modulo - 1);
for (cr = 1; cr <= 1; cr++) { // can only be command
text_color_set(DW_COLOR_INFO);
dw_printf ("\nConstruct I frame, cmd=%d, ftype=%d, pid=0x%02x\n", cr, ftype, pid);
pp = ax25_i_frame (addrs, num_addr, cr, modulo, nr, ns, pf, pid, pinfo, info_len);
ax25_hex_dump (pp);
enc_dec_compare (pp);
ax25_delete (pp);
}
modulo = 128;
nr = 0x55 & (modulo - 1);
ns = 0xaa & (modulo - 1);
for (cr = 1; cr <= 1; cr++) {
text_color_set(DW_COLOR_INFO);
dw_printf ("\nConstruct I frame, cmd=%d, ftype=%d, pid=0x%02x\n", cr, ftype, pid);
pp = ax25_i_frame (addrs, num_addr, cr, modulo, nr, ns, pf, pid, pinfo, info_len);
ax25_hex_dump (pp);
enc_dec_compare (pp);
ax25_delete (pp);
}
}
} // end all_frame_types
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test bitstream tapped off from demodulator.
//
// 5 frames were sent to Nino TNC and a recording was made.
// This was demodulated and the resulting bit stream saved to a file.
//
// No automatic test here - must be done manually with audio recording.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static int decoding_bitstream = 0;
static void decode_bitstream(void)
{
dw_printf("-----\nReading il2p-bitstream.txt if available...\n");
FILE *fp = fopen ("il2p-bitstream.txt", "r");
if (fp == NULL) {
dw_printf ("Bitstream test file not available.\n");
return;
}
decoding_bitstream = 1;
int save_previous = il2p_get_debug();
il2p_set_debug (1);
int ch;
while ( (ch = fgetc(fp)) != EOF) {
if (ch == '0' || ch == '1') {
il2p_rec_bit (0, 0, 0, ch - '0');
}
}
fclose(fp);
il2p_set_debug (save_previous);
decoding_bitstream = 0;
} // end decode_bitstream
/////////////////////////////////////////////////////////////////////////////////////////////
//
// Test serialize / deserialize.
//
// This uses same functions used on the air.
//
/////////////////////////////////////////////////////////////////////////////////////////////
static char addrs2[] = "AA1AAA-1>ZZ9ZZZ-9";
static char addrs3[] = "AA1AAA-1>ZZ9ZZZ-9,DIGI*";
static char text[] =
"'... As I was saying, that seems to be done right - though I haven't time to look it over thoroughly just now - and that shows that there are three hundred and sixty-four days when you might get un-birthday presents -'"
"\n"
"'Certainly,' said Alice."
"\n"
"'And only one for birthday presents, you know. There's glory for you!'"
"\n"
"'I don't know what you mean by \"glory\",' Alice said."
"\n"
"Humpty Dumpty smiled contemptuously. 'Of course you don't - till I tell you. I meant \"there's a nice knock-down argument for you!\"'"
"\n"
"'But \"glory\" doesn't mean \"a nice knock-down argument\",' Alice objected."
"\n"
"'When I use a word,' Humpty Dumpty said, in rather a scornful tone, 'it means just what I choose it to mean - neither more nor less.'"
"\n"
"'The question is,' said Alice, 'whether you can make words mean so many different things.'"
"\n"
"'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'"
"\n" ;
static int rec_count = -1; // disable deserialized packet test.
static int polarity = 0;
static void test_serdes (void)
{
text_color_set(DW_COLOR_INFO);
dw_printf ("\nTest serialize / deserialize...\n");
rec_count = 0;
int max_fec = 1;
// try combinations of header type, max_fec, polarity, errors.
for (int hdr_type = 0; hdr_type <= 1; hdr_type++) {
char packet[1024];
snprintf (packet, sizeof(packet), "%s:%s", hdr_type ? addrs2 : addrs3, text);
packet_t pp = ax25_from_text (packet, 1);
assert (pp != NULL);
int chan = 0;
for (max_fec = 0; max_fec <= 1; max_fec++) {
for (polarity = 0; polarity <= 2; polarity++) { // 2 means throw in some errors.
int num_bits_sent = il2p_send_frame (chan, pp, max_fec, polarity);
dw_printf ("%d bits sent.\n", num_bits_sent);
// Need extra bit at end to flush out state machine.
il2p_rec_bit (0, 0, 0, 0);
}
}
ax25_delete(pp);
}
dw_printf ("Serdes receive count = %d\n", rec_count);
assert (rec_count == 12);
rec_count = -1; // disable deserialized packet test.
}
// Serializing calls this which then simulates the demodulator output.
void tone_gen_put_bit (int chan, int data)
{
il2p_rec_bit (chan, 0, 0, data);
}
// This is called when a complete frame has been deserialized.
void multi_modem_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alevel_t alevel, retry_t retries, fec_type_t fec_type)
{
if (rec_count < 0) return; // Skip check before serdes test.
rec_count++;
// Does it have the the expected content?
unsigned char *pinfo;
int len = ax25_get_info(pp, &pinfo);
assert (len == strlen(text));
assert (strcmp(text, (char*)pinfo) == 0);
dw_printf ("Number of symbols corrected: %d\n", retries);
if (polarity == 2) { // expecting errors corrected.
assert (retries == 10);
}
else { // should be no errors.
assert (retries == 0);
}
ax25_delete (pp);
}
alevel_t demod_get_audio_level (int chan, int subchan)
{
alevel_t alevel;
memset (&alevel, 0, sizeof(alevel));
return (alevel);
}
// end il2p_test.c

View File

@ -465,11 +465,11 @@ void kisspt_send_rec_packet (int chan, int kiss_cmd, unsigned char *fbuf, int f
*
* Returns: one byte (value 0 - 255) or terminate thread on error.
*
* Description: There is room for improvment here. Reading one byte
* Description: There is room for improvement here. Reading one byte
* at a time is inefficient. We could read a large block
* into a local buffer and return a byte from that most of the time.
* Is it worth the effort? I don't know. With GHz processors and
* the low data rate here it might not make a noticable difference.
* the low data rate here it might not make a noticeable difference.
*
*--------------------------------------------------------------------*/

View File

@ -1,7 +1,7 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2013, 2014, 2017 John Langner, WB2OSZ
// Copyright (C) 2013, 2014, 2017, 2023 John Langner, WB2OSZ
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -40,7 +40,8 @@
*
* The first byte of the frame contains:
*
* * port number (radio channel) in upper nybble.
* * radio channel in upper nybble.
* (KISS doc uses "port" but I don't like that because it has too many meanings.)
* * command in lower nybble.
*
*
@ -64,7 +65,7 @@
* _6 SetHardware TNC specific.
*
* _C XKISS extension - not supported.
* _E XKISS extention - not supported.
* _E XKISS extension - not supported.
*
* FF Return Exit KISS mode. Ignored.
*
@ -107,6 +108,7 @@ void hex_dump (unsigned char *p, int len)
offset = 0;
while (len > 0) {
n = len < 16 ? len : 16;
// FIXME: Is there some reason not to use dw_printf here?
printf (" %03x: ", offset);
for (i=0; i<n; i++) {
printf (" %02x", p[i]);
@ -610,7 +612,8 @@ void kiss_process_msg (unsigned char *kiss_msg, int kiss_len, int debug, struct
/* Verify that the radio channel number is valid. */
/* Any sort of medium should be OK here. */
if (chan < 0 || chan >= MAX_CHANS || save_audio_config_p->achan[chan].medium == MEDIUM_NONE) {
if ((chan < 0 || chan >= MAX_CHANS || save_audio_config_p->chan_medium[chan] == MEDIUM_NONE)
&& save_audio_config_p->chan_medium[chan] != MEDIUM_IGATE) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Invalid transmit channel %d from KISS client app.\n", chan);
dw_printf ("\n");
@ -952,7 +955,7 @@ void kiss_debug_print (fromto_t fromto, char *special, unsigned char *pmsg, int
p = pmsg;
if (*p == FEND) p++;
dw_printf ("%s %s %s KISS client application, port %d, total length = %d\n",
dw_printf ("%s %s %s KISS client application, channel %d, total length = %d\n",
prefix[(int)fromto], function[p[0] & 0xf], direction[(int)fromto],
(p[0] >> 4) & 0xf, msg_len);
}

View File

@ -45,7 +45,7 @@ enum kiss_state_e {
#define MAX_KISS_LEN 2048 /* Spec calls for at least 1024. */
/* Might want to make it longer to accomodate */
/* Might want to make it longer to accommodate */
/* maximum packet length. */
#define MAX_NOISE_LEN 100
@ -66,7 +66,7 @@ typedef struct kiss_frame_s {
// This is used only for TCPKISS but it put in kissnet.h,
// there would be a circular dependecy between the two header files.
// there would be a circular dependency between the two header files.
// Each KISS TCP port has its own status block.
struct kissport_status_s {
@ -84,6 +84,8 @@ struct kissport_status_s {
// The default is a limit of 3 client applications at the same time.
// You can increase the limit by changing the line below.
// A larger number consumes more resources so don't go crazy by making it larger than needed.
// TODO: Should this be moved to direwolf.h so max number of audio devices
// client apps are in the same place?
#define MAX_NET_CLIENTS 3

View File

@ -263,6 +263,11 @@ void kissnet_init (struct misc_config_s *mc)
for (int i = 0; i < MAX_KISS_TCP_PORTS; i++) {
if (mc->kiss_port[i] != 0) {
struct kissport_status_s *kps = calloc(sizeof(struct kissport_status_s), 1);
if (kps == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("FATAL ERROR: Out of memory.\n");
exit (EXIT_FAILURE);
}
kps->tcp_port = mc->kiss_port[i];
kps->chan = mc->kiss_chan[i];
@ -530,7 +535,7 @@ static THREAD_F connect_listen_thread (void *arg)
#else /* End of Windows case, now Linux / Unix / Mac OSX. */
struct sockaddr_in sockaddr; /* Internet socket address stuct */
struct sockaddr_in sockaddr; /* Internet socket address struct */
socklen_t sockaddr_size = sizeof(struct sockaddr_in);
int listen_sock;
int bcopt = 1;

Some files were not shown because too many files have changed in this diff Show More