diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ca79ca5..8c0f5d3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,32 @@ version: 2 + +multi-ecosystem-groups: + deps: + schedule: + interval: weekly + updates: - package-ecosystem: github-actions directory: / - schedule: - interval: weekly + patterns: ["*"] + multi-ecosystem-group: deps + cooldown: + default-days: 7 + - package-ecosystem: docker + directory: /packaging/appimage + patterns: ["*"] + multi-ecosystem-group: deps + cooldown: + default-days: 7 + - package-ecosystem: docker + directory: /packaging/windows + patterns: ["*"] + multi-ecosystem-group: deps + cooldown: + default-days: 7 + - package-ecosystem: docker + directory: /packaging/macos + patterns: ["*"] + multi-ecosystem-group: deps + cooldown: + default-days: 7 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 288ec1a..96dad49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,9 +8,26 @@ on: permissions: {} +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: + decoder-revisions: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - run: ./tools/check-decoder-revisions.sh + test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 30 permissions: contents: read packages: read @@ -21,6 +38,32 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - name: Run unit tests run: octave --no-gui --eval "run('tests/run_tests.m')" + + flatpak: + runs-on: ubuntu-24.04 + timeout-minutes: 60 + permissions: + contents: read + container: + image: ghcr.io/flathub-infra/flatpak-github-actions:kde-6.10 + options: --privileged + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - name: Add Flathub remote for the Octave base app + run: | + flatpak remote-add --if-not-exists --user flathub \ + https://dl.flathub.org/repo/flathub.flatpakrepo + + - uses: flatpak/flatpak-github-actions/flatpak-builder@79327416609af08178ad73b352877e51450790b3 # v6.8 + with: + bundle: PIDscope.flatpak + manifest-path: packaging/flatpak/com.pidscope.PIDscope.yml + cache-key: flatpak-builder-${{ github.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0858099..ff0f870 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,15 @@ env: permissions: {} +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + jobs: # Stage 0: Run tests before building anything test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 30 permissions: contents: read packages: read @@ -25,6 +30,8 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - name: Run unit tests run: octave --no-gui --eval "run('tests/run_tests.m')" @@ -32,12 +39,15 @@ jobs: # Stage 1: Build Docker builder images (3 parallel) build-appimage-builder: needs: test - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 60 permissions: contents: read packages: write steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: @@ -52,12 +62,15 @@ jobs: build-windows-builder: needs: test - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 60 permissions: contents: read packages: write steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: @@ -80,13 +93,17 @@ jobs: - runner: macos-15-intel arch_name: x86_64 runs-on: ${{ matrix.runner }} + timeout-minutes: 20 permissions: contents: read steps: - name: Build blackbox_decode + env: + BF_BLACKBOX_REV: f832acf9cd9dbe5ad8220de1a5f4eb4021523d72 run: | - git clone --depth 1 https://github.com/betaflight/blackbox-tools.git + git clone https://github.com/betaflight/blackbox-tools.git cd blackbox-tools + git checkout --detach "${BF_BLACKBOX_REV}" make DEBUG= obj/blackbox_decode cp obj/blackbox_decode ../blackbox_decode.${{ matrix.arch_name }} codesign --force --sign - ../blackbox_decode.${{ matrix.arch_name }} @@ -99,12 +116,15 @@ jobs: # Stage 2: Build packages (each depends only on its own builder) build-appimage: needs: build-appimage-builder - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 45 permissions: contents: read packages: read steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: @@ -126,14 +146,46 @@ jobs: name: appimage path: dist/PIDscope-*-x86_64.AppImage + build-flatpak: + runs-on: ubuntu-24.04 + timeout-minutes: 60 + permissions: + contents: read + container: + image: ghcr.io/flathub-infra/flatpak-github-actions:kde-6.10 + options: --privileged + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - name: Add Flathub remote for the Octave base app + run: | + flatpak remote-add --if-not-exists --user flathub \ + https://dl.flathub.org/repo/flathub.flatpakrepo + + - uses: flatpak/flatpak-github-actions/flatpak-builder@79327416609af08178ad73b352877e51450790b3 # v6.8 + with: + bundle: PIDscope.flatpak + manifest-path: packaging/flatpak/com.pidscope.PIDscope.yml + cache-key: flatpak-builder-${{ github.sha }} + + - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 + with: + name: flatpak + path: PIDscope.flatpak + build-windows: needs: build-windows-builder - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 45 permissions: contents: read packages: read steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 with: @@ -158,12 +210,15 @@ jobs: build-macos: needs: build-macos-blackbox runs-on: macos-15 + timeout-minutes: 45 permissions: contents: read env: INAV_BB_VERSION: "9.0.0" steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: @@ -191,6 +246,7 @@ jobs: cp blackbox_decode.arm64 blackbox_decode.x86_64 "$STAGING/" cp blackbox_decode_INAV.arm64 blackbox_decode_INAV.x86_64 "$STAGING/" chmod +x "$STAGING"/blackbox_decode* + cp LICENSE THIRD-PARTY-LICENSES.md "$STAGING/" if [ -f packaging/com.pidscope.PIDscope.png ]; then cp packaging/com.pidscope.PIDscope.png "$STAGING/PIDscope.png"; fi cat > "$STAGING/README-macOS.txt" <<'HEREDOC' PIDscope - Blackbox Flight Log Analyzer @@ -216,7 +272,8 @@ jobs: release: if: startsWith(github.ref, 'refs/tags/') needs: [build-appimage, build-windows, build-macos] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 15 permissions: contents: write steps: diff --git a/PIDscope.m b/PIDscope.m index 2da22e4..74a5277 100644 --- a/PIDscope.m +++ b/PIDscope.m @@ -23,9 +23,7 @@ if isOctave % Load required Octave packages (suppress warnings if already loaded) try pkg load signal; end - try pkg load statistics; end try pkg load control; end - try pkg load image; end end executableDir = fileparts(mfilename('fullpath')); diff --git a/README.md b/README.md index 64f0cb8..c9e77ef 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,18 @@ Arch Linux users can install from the AUR thanks to [FPVogel](https://github.com --- +## Credits + +The chirp analysis in PIDscope builds on work by **Michael Peter ([pichim](https://github.com/pichim))**, whose [bf_controller_tuning](https://github.com/pichim/bf_controller_tuning) (GPL-3.0) established the frequency-response identification used here. Three files are adapted from it and say so in their headers: + +- `src/core/PSestimateFreqResponse.m` - from `estimate_frequency_response.m` +- `src/core/PSstepFromFRD.m` - from `calculate_step_response_from_frd.m` +- `src/core/PSrotFiltFilt.m` - from `apply_rotfiltfilt.m` + +Arch Linux packaging is maintained by [FPVogel](https://github.com/FPVogel). + +--- + ## License PIDscope is licensed under the [GNU General Public License v3.0](LICENSE). diff --git a/THIRD-PARTY-LICENSES.md b/THIRD-PARTY-LICENSES.md new file mode 100644 index 0000000..f7dfced --- /dev/null +++ b/THIRD-PARTY-LICENSES.md @@ -0,0 +1,95 @@ +# Third-party components shipped with PIDscope + +PIDscope is distributed under the GNU General Public License v3.0; see `LICENSE`. + +The packages below also contain programs written by other authors. Those +programs are covered by their own licences, and the corresponding source for +each is identified here so that anyone who receives a PIDscope package can +obtain it. This satisfies the "clear directions" requirement of GPL-3.0 +section 6(d). + +## blackbox_decode (Betaflight) + +| | | +| --- | --- | +| Upstream | https://github.com/betaflight/blackbox-tools | +| Revision built | `f832acf9cd9dbe5ad8220de1a5f4eb4021523d72` | +| Licence | GPL-3.0 | +| Copyright | the Betaflight / Cleanflight blackbox-tools contributors | + +Shipped as `blackbox_decode` (`blackbox_decode.exe` on Windows). Built from +unmodified upstream source. The build scripts that produce it are part of the +corresponding source and live in this repository: + +- `packaging/windows/Dockerfile` (Windows, cross-compiled with mingw-w64) +- `packaging/appimage/Dockerfile` (AppImage) +- `packaging/flatpak/com.pidscope.PIDscope.yml` (Flatpak) +- `.github/workflows/release.yml` (macOS, native runners) + +## blackbox_decode_INAV (iNav) + +| | | +| --- | --- | +| Upstream | https://github.com/iNavFlight/blackbox-tools | +| Revision built | tag `v9.0.0` | +| Licence | GPL-3.0 | +| Copyright | the iNavFlight blackbox-tools contributors | + +Shipped as `blackbox_decode_INAV` (`blackbox_decode_INAV.exe` on Windows). +Built from unmodified upstream source on Windows and Linux. The macOS packages +instead ship the official upstream release binaries from +https://github.com/iNavFlight/blackbox-tools/releases/tag/v9.0.0 + +## GNU Octave (Windows packages only) + +| | | +| --- | --- | +| Upstream | https://ftpmirror.gnu.org/gnu/octave/ | +| Version | 11.3.0 | +| Licence | GPL-3.0 | +| Copyright | John W. Eaton and others | + +The Windows ZIP bundles the official prebuilt Octave distribution +(`octave-11.3.0-w64.7z`), unmodified apart from the removal of components not +needed at runtime. Source: `octave-11.3.0.tar.lz` from the same location. + +Octave itself bundles further third-party libraries; their licence and +copyright notices are kept in place inside the bundled `octave/` directory. + +The AppImage links against the system Octave of its build container. The +Flatpak uses the `org.octave.Octave` base from Flathub and does not bundle +Octave itself. + +## Octave Forge packages + +The AppImage and Flatpak install the packages below from the upstream release +tarballs listed. Each package keeps its own licence and copyright notices inside +its installed directory, under `packinfo/COPYING` and, where a package carries +additional terms, beside it. + +| Package | Version | Upstream tarball | Licence | +| --- | --- | --- | --- | +| control | 4.2.1 | https://github.com/gnu-octave/pkg-control/releases/download/control-4.2.1/control-4.2.1.tar.gz | GPL-3.0-or-later; the bundled SLICOT routines are BSD-3-Clause | +| signal | 1.4.7 | https://github.com/gnu-octave/octave-signal/releases/download/1.4.7/signal-1.4.7.tar.gz | GPL-3.0-or-later; some files are public domain | + +The SLICOT copyright notice and its BSD-3-Clause terms travel with the package +as `control-4.2.1/doc/SLICOT/LICENSE`. + +The Windows ZIP installs none of these itself; it carries the package set of the +official Octave distribution (control 4.2.1, image 2.20.0, io 2.7.1, +signal 1.4.7, statistics 1.8.3) with their notices retained in place. The macOS +package ships no Octave packages at all - `pidscope.command` installs control +and signal from Octave Forge on first launch. + +## MATLAB File Exchange helpers + +`src/` contains a small number of helper functions originating from the +MathWorks File Exchange. Their original headers, author names and licence +terms are retained in the respective files. + +## Obtaining the source + +All of the above is public at the URLs and revisions listed. If any of those +locations becomes unavailable, or you would prefer to receive the corresponding +source directly, open an issue at https://github.com/dzikus/PIDscope/issues +and it will be provided. diff --git a/packaging/appimage/Dockerfile b/packaging/appimage/Dockerfile index 744467d..592027d 100644 --- a/packaging/appimage/Dockerfile +++ b/packaging/appimage/Dockerfile @@ -11,31 +11,30 @@ RUN apt-get update && apt-get install -y software-properties-common && \ apt-get update RUN apt-get install -y \ - octave liboctave-dev \ + octave octave-dev \ build-essential git \ wget file desktop-file-utils appstream \ libfftw3-3 libopenblas0 libsuitesparse-dev \ libgl1-mesa-glx libfontconfig1 libfreetype6 \ && rm -rf /var/lib/apt/lists/* -RUN wget --tries=5 --timeout=30 -q \ - "https://sourceforge.net/projects/octave/files/Octave%20Forge%20Packages/Individual%20Package%20Releases/image-2.18.1.tar.gz/download" \ - -O /tmp/image-2.18.1.tar.gz && \ - octave --eval "\ +RUN octave --eval "\ pkg install 'https://github.com/gnu-octave/pkg-control/releases/download/control-4.2.1/control-4.2.1.tar.gz'; \ - pkg install 'https://github.com/gnu-octave/octave-signal/releases/download/1.4.7/signal-1.4.7.tar.gz'; \ - pkg install 'https://github.com/pr0m1th3as/datatypes/releases/download/release-1.1.8/datatypes-1.1.8.tar.gz'; \ - pkg install 'https://github.com/gnu-octave/statistics/releases/download/release-1.8.1/statistics-1.8.1.tar.gz'; \ - pkg install '/tmp/image-2.18.1.tar.gz';" + pkg install 'https://github.com/gnu-octave/octave-signal/releases/download/1.4.7/signal-1.4.7.tar.gz';" # Compile blackbox_decode from source (not in git) +ARG BF_BLACKBOX_REV=f832acf9cd9dbe5ad8220de1a5f4eb4021523d72 +ARG INAV_BLACKBOX_REV=v9.0.0 + RUN mkdir -p /cache && \ - git clone --depth=1 https://github.com/betaflight/blackbox-tools.git /tmp/bb-bf && \ - cd /tmp/bb-bf && make -j$(nproc) obj/blackbox_decode && \ + git clone https://github.com/betaflight/blackbox-tools.git /tmp/bb-bf && \ + cd /tmp/bb-bf && git checkout --detach ${BF_BLACKBOX_REV} && \ + make -j$(nproc) obj/blackbox_decode && \ gcc -o /cache/blackbox_decode obj/*.o -lm && \ cd / && rm -rf /tmp/bb-bf && \ - git clone --depth=1 https://github.com/iNavFlight/blackbox-tools.git /tmp/bb-inav && \ - cd /tmp/bb-inav && make -j$(nproc) obj/blackbox_decode && \ + git clone https://github.com/iNavFlight/blackbox-tools.git /tmp/bb-inav && \ + cd /tmp/bb-inav && git checkout --detach ${INAV_BLACKBOX_REV} && \ + make -j$(nproc) obj/blackbox_decode && \ cp obj/blackbox_decode /cache/blackbox_decode_INAV && \ cd / && rm -rf /tmp/bb-inav diff --git a/packaging/appimage/build-appimage.sh b/packaging/appimage/build-appimage.sh index a4d87b2..caa416b 100755 --- a/packaging/appimage/build-appimage.sh +++ b/packaging/appimage/build-appimage.sh @@ -29,16 +29,17 @@ cp "${SRC_DIR}"/VERSION "${APPDIR}/usr/share/pidscope/" cp -r "${SRC_DIR}/src" "${APPDIR}/usr/share/pidscope/" for decoder in blackbox_decode blackbox_decode_INAV; do - if [ -f "${SRC_DIR}/${decoder}" ]; then - cp "${SRC_DIR}/${decoder}" "${APPDIR}/usr/share/pidscope/" - elif [ -f "/cache/${decoder}" ]; then - cp "/cache/${decoder}" "${APPDIR}/usr/share/pidscope/" - else - echo "WARNING: ${decoder} not found in ${SRC_DIR} or /cache" + if [ ! -f "/cache/${decoder}" ]; then + echo "ERROR: /cache/${decoder} missing - rebuild the builder image" >&2 + exit 1 fi - [ -f "${APPDIR}/usr/share/pidscope/${decoder}" ] && chmod +x "${APPDIR}/usr/share/pidscope/${decoder}" + cp "/cache/${decoder}" "${APPDIR}/usr/share/pidscope/" + chmod +x "${APPDIR}/usr/share/pidscope/${decoder}" done +cp "${SRC_DIR}/LICENSE" "${APPDIR}/usr/share/pidscope/" +cp "${SRC_DIR}/THIRD-PARTY-LICENSES.md" "${APPDIR}/usr/share/pidscope/" + # Desktop integration cp "${SRC_DIR}/packaging/pidscope.desktop" "${APPDIR}/usr/share/applications/" cp "${SRC_DIR}/packaging/pidscope.desktop" "${APPDIR}/pidscope.desktop" diff --git a/packaging/flatpak/com.pidscope.PIDscope.yml b/packaging/flatpak/com.pidscope.PIDscope.yml index fa757be..c5e0877 100644 --- a/packaging/flatpak/com.pidscope.PIDscope.yml +++ b/packaging/flatpak/com.pidscope.PIDscope.yml @@ -7,7 +7,7 @@ base: org.octave.Octave base-version: stable # Octave uses Sdk (not Platform) as runtime - needs compilers for Forge packages runtime: org.kde.Sdk -runtime-version: '5.15-24.08' +runtime-version: '6.10' sdk: org.kde.Sdk command: pidscope @@ -48,27 +48,41 @@ modules: - type: file url: https://github.com/gnu-octave/octave-signal/releases/download/1.4.7/signal-1.4.7.tar.gz sha256: 6a8b4b8cf0b3019d984fde75af947ae73e9a1c509890552cd5e113f7ba89038c - - type: file - url: https://github.com/pr0m1th3as/datatypes/releases/download/release-1.1.8/datatypes-1.1.8.tar.gz - sha256: 83258f0a587f014f2fb7ddb477cdb4fcc25cb92bf6ebdf8c046f64178a0ed4d4 - - type: file - url: https://github.com/gnu-octave/statistics/releases/download/release-1.8.1/statistics-1.8.1.tar.gz - sha256: 5174f80ddf182674ca06d871d9fbed439f3eaed3e3970892a0716ed480f5545d - - type: file - url: https://downloads.sourceforge.net/project/octave/Octave%20Forge%20Packages/Individual%20Package%20Releases/image-2.18.1.tar.gz - sha256: d4eed0579782c2efaa0818de2f20f13b276eb3d4b4b3d63347c7317d84e29531 build-commands: # Install all packages globally into /app in dependency order - | + mkdir -p /tmp/shim + printf '#!/bin/sh\nexec %s "$@" --no-same-owner\n' "$(command -v tar)" > /tmp/shim/tar + chmod +x /tmp/shim/tar + export PATH=/tmp/shim:$PATH octave --eval " pkg install -global control-4.2.1.tar.gz; pkg install -global signal-1.4.7.tar.gz; - pkg install -global datatypes-1.1.8.tar.gz; - pkg install -global statistics-1.8.1.tar.gz; - pkg install -global image-2.18.1.tar.gz; pkg list; " + # --- blackbox_decode (GPL-3.0, built from pinned upstream sources) --- + - name: blackbox-decode-bf + buildsystem: simple + sources: + - type: git + url: https://github.com/betaflight/blackbox-tools.git + commit: f832acf9cd9dbe5ad8220de1a5f4eb4021523d72 + build-commands: + - make obj/blackbox_decode + - install -Dm755 obj/blackbox_decode /app/share/pidscope/blackbox_decode + + - name: blackbox-decode-inav + buildsystem: simple + sources: + - type: git + url: https://github.com/iNavFlight/blackbox-tools.git + tag: v9.0.0 + commit: 1918a752851d99beb092bb2f3a2e7ba16ccb86db + build-commands: + - make obj/blackbox_decode + - install -Dm755 obj/blackbox_decode /app/share/pidscope/blackbox_decode_INAV + # --- PIDscope application --- - name: pidscope buildsystem: simple @@ -77,9 +91,7 @@ modules: - install -d /app/share/pidscope - install -m644 PIDscope.m VERSION /app/share/pidscope/ - cp -r src /app/share/pidscope/ - # Install blackbox_decode binaries - - install -m755 blackbox_decode /app/share/pidscope/ - - install -m755 blackbox_decode_INAV /app/share/pidscope/ + - install -m644 LICENSE THIRD-PARTY-LICENSES.md /app/share/pidscope/ # Install launcher - install -Dm755 packaging/flatpak/pidscope-launcher.sh /app/bin/pidscope # Install desktop integration diff --git a/packaging/macos/build-macos.sh b/packaging/macos/build-macos.sh index 3a3abfc..ec52709 100644 --- a/packaging/macos/build-macos.sh +++ b/packaging/macos/build-macos.sh @@ -30,16 +30,25 @@ cp -r "${SRC_DIR}/src" "${STAGING}/" # 2. Copy blackbox_decode binaries # BF: from GH Actions artifacts (mounted) or /cache; INAV: from /cache (Dockerfile) echo "Copying blackbox_decode binaries..." -for bin in blackbox_decode.arm64 blackbox_decode.x86_64 blackbox_decode_INAV.arm64 blackbox_decode_INAV.x86_64; do - if [ -f "/cache/${bin}" ]; then - cp "/cache/${bin}" "${STAGING}/" - elif [ -f "${SRC_DIR}/${bin}" ]; then +for bin in blackbox_decode_INAV.arm64 blackbox_decode_INAV.x86_64; do + if [ ! -f "/cache/${bin}" ]; then + echo "ERROR: /cache/${bin} missing - rebuild the builder image" >&2 + exit 1 + fi + cp "/cache/${bin}" "${STAGING}/" +done +for bin in blackbox_decode.arm64 blackbox_decode.x86_64; do + if [ -f "${SRC_DIR}/${bin}" ]; then cp "${SRC_DIR}/${bin}" "${STAGING}/" else - echo "WARNING: ${bin} not found, skipping (BF binaries come from GH Actions)" + echo "WARNING: ${bin} not found (BF binaries come from GH Actions runners)" fi done +# 2a. Licence text and third-party notices +cp "${SRC_DIR}/LICENSE" "${STAGING}/" +cp "${SRC_DIR}/THIRD-PARTY-LICENSES.md" "${STAGING}/" + # 3. Copy launcher cp "${SRC_DIR}/packaging/macos/pidscope.command" "${STAGING}/" chmod +x "${STAGING}/pidscope.command" diff --git a/packaging/macos/pidscope.command b/packaging/macos/pidscope.command index a5e3bcd..0238b8e 100644 --- a/packaging/macos/pidscope.command +++ b/packaging/macos/pidscope.command @@ -25,17 +25,17 @@ elif [ -x "/usr/local/bin/octave" ]; then elif [ -d "/Applications/Octave-9.2.app" ]; then OCTAVE="/Applications/Octave-9.2.app/Contents/Resources/usr/bin/octave" else - osascript -e 'display dialog "GNU Octave not found.\n\nInstall with:\n brew install octave\n\nThen install packages:\n octave --eval \"pkg install -forge datatypes signal statistics control image\"" with title "PIDscope" buttons {"OK"} default button "OK" with icon stop' + osascript -e 'display dialog "GNU Octave not found.\n\nInstall with:\n brew install octave\n\nThen install packages:\n octave --eval \"pkg install -forge signal control\"" with title "PIDscope" buttons {"OK"} default button "OK" with icon stop' exit 1 fi # Check and auto-install required Octave Forge packages -PKGMISSING=$("$OCTAVE" --no-gui --eval "for p={'signal','control','image','statistics'}; if isempty(pkg('list',p{1})), fprintf('MISSING\n'); break; end; end" 2>/dev/null) +PKGMISSING=$("$OCTAVE" --no-gui --eval "for p={'signal','control'}; if isempty(pkg('list',p{1})), fprintf('MISSING\n'); break; end; end" 2>/dev/null) if echo "$PKGMISSING" | grep -q MISSING; then osascript -e 'display notification "Installing required Octave packages (first launch only)..." with title "PIDscope"' - "$OCTAVE" --no-gui --eval "pkg install -forge datatypes signal statistics control image" 2>&1 | tee /tmp/pidscope-pkg-install.log + "$OCTAVE" --no-gui --eval "pkg install -forge signal control" 2>&1 | tee /tmp/pidscope-pkg-install.log if [ $? -ne 0 ]; then - osascript -e 'display dialog "Package installation failed.\n\nCheck /tmp/pidscope-pkg-install.log for details.\n\nOr install manually:\n octave --eval \"pkg install -forge datatypes signal statistics control image\"" with title "PIDscope" buttons {"OK"} default button "OK" with icon stop' + osascript -e 'display dialog "Package installation failed.\n\nCheck /tmp/pidscope-pkg-install.log for details.\n\nOr install manually:\n octave --eval \"pkg install -forge signal control\"" with title "PIDscope" buttons {"OK"} default button "OK" with icon stop' exit 1 fi fi diff --git a/packaging/windows/Dockerfile b/packaging/windows/Dockerfile index 61658e7..1e27b9e 100644 --- a/packaging/windows/Dockerfile +++ b/packaging/windows/Dockerfile @@ -19,14 +19,19 @@ RUN mkdir -p /cache && \ # Cross-compile blackbox_decode.exe from betaflight and iNav # BIN_DIR = obj/, so output is obj/blackbox_decode -RUN git clone --depth=1 https://github.com/betaflight/blackbox-tools.git /tmp/blackbox-tools-bf && \ +ARG BF_BLACKBOX_REV=f832acf9cd9dbe5ad8220de1a5f4eb4021523d72 +ARG INAV_BLACKBOX_REV=v9.0.0 + +RUN git clone https://github.com/betaflight/blackbox-tools.git /tmp/blackbox-tools-bf && \ cd /tmp/blackbox-tools-bf && \ + git checkout --detach ${BF_BLACKBOX_REV} && \ CC=x86_64-w64-mingw32-gcc make -j$(nproc) obj/blackbox_decode && \ x86_64-w64-mingw32-gcc -o /cache/blackbox_decode.exe obj/*.o -lm -lws2_32 && \ rm -rf /tmp/blackbox-tools-bf -RUN git clone --depth=1 https://github.com/iNavFlight/blackbox-tools.git /tmp/blackbox-tools-inav && \ +RUN git clone https://github.com/iNavFlight/blackbox-tools.git /tmp/blackbox-tools-inav && \ cd /tmp/blackbox-tools-inav && \ + git checkout --detach ${INAV_BLACKBOX_REV} && \ CC=x86_64-w64-mingw32-gcc make -j$(nproc) obj/blackbox_decode && \ x86_64-w64-mingw32-gcc -o /cache/blackbox_decode_INAV.exe obj/*.o -lm -lws2_32 && \ rm -rf /tmp/blackbox-tools-inav diff --git a/packaging/windows/build-windows.sh b/packaging/windows/build-windows.sh index aa60f83..451e3ca 100644 --- a/packaging/windows/build-windows.sh +++ b/packaging/windows/build-windows.sh @@ -39,7 +39,10 @@ rm -rf "${STAGING}/octave/mingw64/include" # Remove bulky doc files but keep .qhc/.qch (prevents Qt Help startup errors) find "${STAGING}/octave/mingw64/share/octave/${OCTAVE_VERSION}/doc" -name '*.html' -delete 2>/dev/null || true find "${STAGING}/octave/mingw64/share/octave/${OCTAVE_VERSION}/doc" -name '*.pdf' -delete 2>/dev/null || true -rm -rf "${STAGING}/octave/mingw64/share/doc" +find "${STAGING}/octave/mingw64/share/doc" -type f \ + ! -iname 'COPYING*' ! -iname 'LICENSE*' ! -iname 'COPYRIGHT*' \ + ! -iname 'NOTICE*' ! -iname 'AUTHORS*' -delete 2>/dev/null || true +find "${STAGING}/octave/mingw64/share/doc" -type d -empty -delete 2>/dev/null || true rm -rf "${STAGING}/octave/mingw64/share/info" rm -rf "${STAGING}/octave/mingw64/share/man" # Remove .a static libraries (not needed at runtime) @@ -79,6 +82,10 @@ cp -r "${SRC_DIR}/src" "${STAGING}/app/" cp /cache/blackbox_decode.exe "${STAGING}/app/" cp /cache/blackbox_decode_INAV.exe "${STAGING}/app/" +# 4a. Licence text and third-party notices +cp "${SRC_DIR}/LICENSE" "${STAGING}/" +cp "${SRC_DIR}/THIRD-PARTY-LICENSES.md" "${STAGING}/" + # 5. Suppress Windows Terminal false-positive warning (only affects CLI, not GUI) OCTAVERC="${STAGING}/octave/mingw64/share/octave/site/m/startup/octaverc" if [ -f "${OCTAVERC}" ]; then diff --git a/src/compat/fspecial.m b/src/compat/fspecial.m new file mode 100644 index 0000000..c823747 --- /dev/null +++ b/src/compat/fspecial.m @@ -0,0 +1,41 @@ +function h = fspecial(type, hsize, sigma) +% +% Gaussian filter kernel, drop-in replacement for the image package +% version so PIDscope does not depend on it. +% +% h = fspecial('gaussian', [rows cols], sigma) +% h = fspecial('gaussian', n, sigma) + + if nargin < 1 || ~ischar(type) || ~strcmpi(type, 'gaussian') + error('fspecial: only the ''gaussian'' type is implemented'); + end + if nargin < 2 || isempty(hsize) + hsize = [3 3]; + end + if nargin < 3 || isempty(sigma) + sigma = 0.5; + end + + if isscalar(hsize) + hsize = [hsize hsize]; + end + if numel(hsize) ~= 2 + error('fspecial: hsize must be a scalar or a two-element vector'); + end + if ~isscalar(sigma) || sigma <= 0 + error('fspecial: sigma must be a positive scalar'); + end + + nr = hsize(1); + nc = hsize(2); + [x, y] = meshgrid(-(nc - 1) / 2 : (nc - 1) / 2, ... + -(nr - 1) / 2 : (nr - 1) / 2); + + h = exp(-(x .^ 2 + y .^ 2) / (2 * sigma ^ 2)); + h(h < eps * max(h(:))) = 0; + + s = sum(h(:)); + if s ~= 0 + h = h / s; + end +end diff --git a/src/compat/kstest2.m b/src/compat/kstest2.m new file mode 100644 index 0000000..729302f --- /dev/null +++ b/src/compat/kstest2.m @@ -0,0 +1,49 @@ +function [H, pValue, ks2stat] = kstest2(x1, x2, varargin) +% +% Two-sample Kolmogorov-Smirnov test, drop-in replacement for the +% statistics package version so PIDscope does not depend on it. +% +% [h, p] = kstest2(x1, x2) +% [h, p] = kstest2(x1, x2, alpha) +% [h, p] = kstest2(x1, x2, 'alpha', alpha) +% +% Two-sided test only. Asymptotic p-value after Numerical Recipes 14.3. + + alpha = 0.05; + if numel(varargin) == 1 && isnumeric(varargin{1}) + alpha = varargin{1}; + elseif numel(varargin) == 2 && strcmpi(varargin{1}, 'alpha') + alpha = varargin{2}; + elseif ~isempty(varargin) + error('kstest2: unsupported arguments'); + end + + if ~isscalar(alpha) || ~isnumeric(alpha) || alpha <= 0 || alpha >= 1 + error('kstest2: alpha must be a scalar in (0,1)'); + end + + x1 = x1(:); + x2 = x2(:); + x1 = x1(~isnan(x1)); + x2 = x2(~isnan(x2)); + + n1 = numel(x1); + n2 = numel(x2); + if n1 < 1 || n2 < 1 + error('kstest2: both samples must be non-empty'); + end + + edges = [-Inf; sort([x1; x2]); Inf]; + cdf1 = cumsum(histc(x1, edges)) / n1; + cdf2 = cumsum(histc(x2, edges)) / n2; + ks2stat = max(abs(cdf1(1:end-1) - cdf2(1:end-1))); + + n = n1 * n2 / (n1 + n2); + lambda = max((sqrt(n) + 0.12 + 0.11 / sqrt(n)) * ks2stat, 0); + + v = 1:101; + pValue = 2 * sum((-1) .^ (v - 1) .* exp(-2 * lambda * lambda * v .^ 2)); + pValue = min(max(pValue, 0), 1); + + H = (alpha >= pValue); +end diff --git a/tests/run_tests.m b/tests/run_tests.m index 0254a07..2539fcb 100644 --- a/tests/run_tests.m +++ b/tests/run_tests.m @@ -12,7 +12,6 @@ % Load required packages if exist('OCTAVE_VERSION', 'builtin') pkg load signal; - pkg load statistics; end % Collect test files diff --git a/tests/test_compat.m b/tests/test_compat.m index c91730c..f20a7c3 100644 --- a/tests/test_compat.m +++ b/tests/test_compat.m @@ -58,3 +58,48 @@ %!test %! % contains() - case insensitive %! assert(contains('Hello', 'hello', 'IgnoreCase', true)); + +%!test +%! % kstest2() - samples from clearly different distributions +%! a = [0.1 0.5 0.3 0.9 0.2 0.7 0.44 0.61 0.15 0.83]; +%! b = [1.1 1.5 0.95 2.0 1.2 1.7 1.44 1.61 1.05 1.83]; +%! [h, p] = kstest2(a, b); +%! assert(h, true); +%! assert(p, 1.88797936571626e-05, 1e-15); + +%!test +%! % kstest2() - samples that track each other closely +%! c = [1 2 3 4 5 6 7 8]; +%! d = [1.2 2.1 3.3 3.9 5.2 5.8 7.1 8.3]; +%! [h, p] = kstest2(c, d); +%! assert(h, false); +%! assert(p, 0.999999479887226, 1e-12); + +%!test +%! % kstest2() - alpha controls the reject decision +%! a = [0.1 0.5 0.3 0.9 0.2 0.7 0.44 0.61 0.15 0.83]; +%! b = [1.1 1.5 0.95 2.0 1.2 1.7 1.44 1.61 1.05 1.83]; +%! assert(kstest2(a, b, 0.01), true); +%! assert(kstest2([1 2 3 4], [1.1 2.1 3.1 4.1], 0.01), false); + +%!test +%! % fspecial() - gaussian column kernel, values from the image package +%! f = fspecial('gaussian', [5 1], 4); +%! assert(size(f), [5 1]); +%! assert(sum(f(:)), 1, 1e-14); +%! assert(f(1), 0.18762716195139, 1e-14); +%! assert(f(3), 0.212609428318537, 1e-14); +%! assert(f(1), f(5), 1e-14); + +%!test +%! % fspecial() - non-square gaussian normalises to unit sum +%! f = fspecial('gaussian', [10 2], 4); +%! assert(size(f), [10 2]); +%! assert(sum(f(:)), 1, 1e-14); +%! assert(f(1), 0.0335293399098535, 1e-14); + +%!test +%! % fspecial() - scalar size gives a square kernel +%! f = fspecial('gaussian', 5, 4); +%! assert(size(f), [5 5]); +%! assert(sum(f(:)), 1, 1e-14); diff --git a/tools/check-decoder-revisions.sh b/tools/check-decoder-revisions.sh new file mode 100755 index 0000000..525f904 --- /dev/null +++ b/tools/check-decoder-revisions.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Fail if the pinned blackbox-tools revisions drift apart between packaging +# paths and THIRD-PARTY-LICENSES.md. +set -uo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +cd "${ROOT}" + +fail=0 + +check() { + local label="$1"; shift + local found + found=$(printf '%s\n' "$@" | sort -u) + if [ "$(printf '%s\n' "${found}" | wc -l)" -ne 1 ]; then + echo "MISMATCH: ${label} is pinned to more than one revision:" + printf ' %s\n' ${found} + fail=1 + else + echo "OK: ${label} = ${found}" + fi +} + +bf_win=$(grep -oP 'ARG BF_BLACKBOX_REV=\K\S+' packaging/windows/Dockerfile) +bf_app=$(grep -oP 'ARG BF_BLACKBOX_REV=\K\S+' packaging/appimage/Dockerfile) +bf_rel=$(grep -oP 'BF_BLACKBOX_REV: \K\S+' .github/workflows/release.yml) +bf_fpk=$(grep -A5 'name: blackbox-decode-bf' packaging/flatpak/com.pidscope.PIDscope.yml | grep -oP 'commit: \K\S+') +bf_dev=$(grep -oP 'BF_REV="\$\{BF_BLACKBOX_REV:-\K[^}]+' tools/fetch-decoders.sh) +bf_doc=$(grep -oP '^\| Revision built \| `\K[0-9a-f]{40}' THIRD-PARTY-LICENSES.md) + +check "betaflight/blackbox-tools" "$bf_win" "$bf_app" "$bf_rel" "$bf_fpk" "$bf_dev" "$bf_doc" + +inav_win=$(grep -oP 'ARG INAV_BLACKBOX_REV=\K\S+' packaging/windows/Dockerfile) +inav_app=$(grep -oP 'ARG INAV_BLACKBOX_REV=\K\S+' packaging/appimage/Dockerfile) +inav_fpk=$(grep -A5 'name: blackbox-decode-inav' packaging/flatpak/com.pidscope.PIDscope.yml | grep -oP 'tag: \K\S+') +inav_dev=$(grep -oP 'INAV_REV="\$\{INAV_BLACKBOX_REV:-\K[^}]+' tools/fetch-decoders.sh) +inav_mac=$(grep -oP 'ARG INAV_BB_VERSION=\K\S+' packaging/macos/Dockerfile | sed 's/^/v/') +inav_rel=$(grep -oP 'INAV_BB_VERSION: "\K[^"]+' .github/workflows/release.yml | sed 's/^/v/') + +check "iNavFlight/blackbox-tools" "$inav_win" "$inav_app" "$inav_fpk" "$inav_dev" "$inav_mac" "$inav_rel" + +exit "${fail}" diff --git a/tools/fetch-decoders.sh b/tools/fetch-decoders.sh new file mode 100755 index 0000000..e206990 --- /dev/null +++ b/tools/fetch-decoders.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Build the blackbox_decode binaries into the repo root for local development. +set -euo pipefail + +BF_REV="${BF_BLACKBOX_REV:-f832acf9cd9dbe5ad8220de1a5f4eb4021523d72}" +INAV_REV="${INAV_BLACKBOX_REV:-v9.0.0}" + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +WORK="$(mktemp -d)" +trap 'rm -rf "${WORK}"' EXIT + +build() { + local url="$1" rev="$2" out="$3" + echo "Building ${out} from ${url} @ ${rev}" + git clone -q "${url}" "${WORK}/src" + git -C "${WORK}/src" checkout -q --detach "${rev}" + make -C "${WORK}/src" -j"$(nproc)" obj/blackbox_decode >/dev/null + cp "${WORK}/src/obj/blackbox_decode" "${ROOT}/${out}" + chmod +x "${ROOT}/${out}" + rm -rf "${WORK}/src" +} + +build https://github.com/betaflight/blackbox-tools.git "${BF_REV}" blackbox_decode +build https://github.com/iNavFlight/blackbox-tools.git "${INAV_REV}" blackbox_decode_INAV + +echo "Done:" +ls -l "${ROOT}/blackbox_decode" "${ROOT}/blackbox_decode_INAV"