subrascasse

Sub Rascasse: an iPhone dive log for Subsurface cloud storage, with a pure-Swift git client (GPL-2.0)
git clone https://git.schurger.org/subrascasse.git
Log | Files | Refs | README | LICENSE

README.md (11615B)


      1 # Sub Rascasse
      2 
      3 An iPhone app for [Subsurface](https://subsurface-divelog.org) dive logs: it reads and edits the logbook kept in
      4 Subsurface cloud storage, in the same format, without going through the official app.
      5 
      6 Sub Rascasse is an independent application. It is not affiliated with, or endorsed by, the Subsurface team.
      7 
      8 The app is available in English and French.
      9 
     10 ## Features
     11 
     12 - Sign in to Subsurface cloud storage (email and password, kept in the keychain); the logbook is copied to the
     13   iPhone.
     14 - Dive list by trip or by month, search, and a dive page with its profile (depth, temperature, pressure, deco
     15   stops, events, scrubbing with a finger), with several dive computers per dive.
     16 - Offline editing: site, buddy, guide, suit, tags, rating, visibility, notes; adding a dive by hand, creating a
     17   site, deleting a dive. Changes are sent at the next sync.
     18 - Map and list of dive sites, statistics, metric or imperial units.
     19 - UDDF 3.2 import and export (`SubsurfaceLog/UDDF.swift`): the exchange format most dive log programs read and
     20   write. Import: date, profile (depth, temperature, cylinder pressure, gas switches, stops), site and position,
     21   buddies, notes. Export: the whole logbook or one dive, with sites, buddies, gases, cylinders and profiles.
     22 - Import of a Shearwater Cloud export (`.zip` or `dive_data.db`) or of the Dive Shearwater app database
     23   (`watermelon.db`, found in `~/Library/Containers/com.shearwater.dive/Data/Documents` when the iOS app runs on a
     24   Mac): full profiles, gases, deco stops, pressure, sites created as needed, duplicates skipped.
     25 - Download from a dive computer over Bluetooth LE, with libdivecomputer: the app lists the computers nearby that
     26   libdivecomputer recognises by name, downloads the dives (only the new ones after the first time) and previews
     27   them like a file import. Checked on a real Shearwater Petrel 3 (2026-11-14); Heinrichs-Weikamp computers
     28   need a flow-control step that is not written yet.
     29 - Dives from Open Rémora (a dive computer for Apple Watch) and Open Mérou (an iPhone underwater housing): at
     30   launch, when coming back to the foreground and when `subrascasse://open-remora` is opened, the app reads
     31   `OpenRemora/Plongees/*.json` and `OpenMerou/Dives/*.json` in the `group.org.schurger.dive` app group, adds the
     32   dives to the logbook and removes the files (the contract is `docs/SHARING.md` in the open-remora repository).
     33   Nothing is read until a logbook is open.
     34 - One dive, several dive computers: a dive that comes in (from a file, a dive computer, Open Rémora or Open
     35   Mérou) while the logbook already has a dive at that time joins it as one more dive computer, the way Subsurface
     36   stores it (`Divecomputer-001`, `Divecomputer-002`…). "At that time" means that the two [start, end] ranges
     37   overlap: each device notices the submersion at its own moment. The dive keeps its date, number, site and notes,
     38   and the incoming one fills what it lacks. Open Rémora is the primary computer (the first one, shown by default),
     39   then the other dive computers, then Open Mérou (`DiveMerge.rank`), and the duration shown is the first computer's. The same dive from the same computer is not
     40   imported twice. "Merge dives…" in the + menu does the same for dives picked by hand (clocks that disagree,
     41   successive immersions: the same computer's profiles are then joined on one timeline).
     42 - Photos: a dive page shows the photos and videos of the photo library taken during the dive (from 20 minutes
     43   before to 30 minutes after), placed on the profile at their time, hence at their depth; a site page shows those
     44   of all its dives. Logbook times are local to the site: the time zone comes from the site's position (Apple
     45   reverse geocoding, then remembered). Read-only; nothing is sent anywhere.
     46 - Editing a dive: site, buddy, guide, suit, tags, rating, visibility, notes, and its equipment: cylinders (name,
     47   volume, working pressure, gas, start and end pressures) and weights.
     48 - Merging dives: from the list (+, Merge dives) or from a dive page; the numbering closes up.
     49 - Certification cards (Settings, Certification cards): agency, certification, number, date, a photo of each
     50   side, shown full screen. They are not part of the Subsurface logbook: they are kept on the iPhone and copied
     51   automatically to the app's iCloud Drive folder (`iCloud.org.schurger.subrascasse`, `Documents/Cards`), merged
     52   both ways at launch, so they come back on a new iPhone.
     53 - The Subsurface cloud account is optional: the logbook can live on the iPhone alone (same storage, a local git
     54   repository in the Subsurface format, without a remote). An account can be connected later (an account without
     55   dives receives the logbook; otherwise the user picks which one stays), and signing out can keep the logbook.
     56 - iCloud backup: after each change, the logbook goes to the app's iCloud Drive folder as `Logbook/logbook.zip`
     57   (the files of the Subsurface git format), with `logbook.json` (what it holds), `settings.plist` and one archive
     58   per day for a week in `history`. The sign-in screen offers to restore it. Photos are not copied.
     59 - Planning (its own tab), on top of the `DivePlanner` library:
     60   - no-stop: how long at a depth on a gas with a cylinder (no-stop time, gas time, table of no-stop times);
     61   - decompression: levels, cylinders with nitrox, trimix and decompression gases, Bühlmann with gradient
     62     factors or VPM-B, open circuit or rebreather (CCR, pSCR, bailout), stops, run time, gas per cylinder,
     63     minimum gas, CNS and OTU, warnings, profile, plan variations; plans are saved by name in a library of
     64     their own (kept in the settings, hence in the iCloud backup), printed or shared as a PDF sheet, and can
     65     also be saved as a logbook dive, which then carries a "Plan" tag and stays out of the statistics;
     66   - gas: maximum operating depth, equivalent narcotic and air depths, density, best mix, consumption.
     67 - Creation of a Subsurface cloud account (email, password, code received by email).
     68 - Demo logbook (a button on the sign-in screen, or the `-demo` launch option).
     69 
     70 Not there yet: Subsurface XML import, dive planner.
     71 
     72 ## Architecture
     73 
     74 - `Packages/DiveKit/Sources/GitLite`: a git client in pure Swift (objects, packfiles, the smart HTTP protocol,
     75   shallow and incremental fetch, push). No binary dependency.
     76 - `Packages/DiveKit/Sources/SubsurfaceLog`: the Subsurface git storage format.
     77   - `Loader` reads the format.
     78   - `Changes` applies line-level edits: only the lines touched in a file are rewritten, the rest of the file is
     79     kept byte-identical.
     80   - `Repository` handles sync: an offline change queue, replayed on top of the server state.
     81   - Importers for the Shearwater and Open Rémora formats.
     82   - `Merge` holds the rules for dives recorded by several computers and merges them as text, so that the files
     83     of the other computers stay byte-identical.
     84 - `Packages/DiveKit/Sources/DivePlanner`: gas formulas and a decompression planner, with no dependency.
     85   `Core.swift` is a port of Subsurface's `core/deco.cpp`, `core/planner.cpp`, `core/gas.cpp` and
     86   `core/gas-model.cpp` that keeps their units and rounding (millimetres, whole seconds, millibars, two-second
     87   ascent steps): Bühlmann ZHL-16C with gradient factors, VPM-B, open circuit, closed and semi-closed
     88   rebreathers, bailout, oxygen breaks. `SubsurfaceVectorsTests` runs the plans of Subsurface's
     89   `tests/testplan.cpp` (one Bühlmann, seven VPM-B, one closed circuit with bailout) and expects its known run
     90   times to the second, in metres and in feet. Also ported, without a reference figure in Subsurface's tests:
     91   its recreational mode, the tissues left by earlier dives (`init_decompression`), setpoint switches on the
     92   loop, semi-closed circuits, oxygen breaks.
     93 - `Packages/DiveKit/Sources/CLibDiveComputer`: libdivecomputer, vendored unchanged (see its `README.md` for the
     94   exact revision), built as a package target.
     95 - `Packages/DiveKit/Sources/DiveComputerKit`: Swift on top of it. `Catalog` lists the models and matches one from
     96   a Bluetooth name, `Parser` turns a raw dive into the importer's `ImportedDive`, `Download` runs a download over
     97   a `DiveComputerTransport` that the app provides (`App/Model/DiveComputerLink.swift`, CoreBluetooth).
     98 - `Packages/DiveKit/Sources/divelog-cli`: a macOS command-line tool running the same code as the app (list a cloud
     99   logbook, inspect or import a file).
    100 - `App`: the SwiftUI interface. The display name and the bundle identifier live only in `project.yml` and
    101   `App/Brand.swift`.
    102 
    103 ## Acknowledgements and sources
    104 
    105 - The storage format was written from the Subsurface sources (`core/save-git.cpp`, `core/load-git.cpp`,
    106   GPL-2.0): https://github.com/subsurface/subsurface
    107 - Dive computers are read with libdivecomputer (LGPL-2.1), in the branch that Subsurface maintains:
    108   https://github.com/subsurface/libdc (upstream: https://github.com/libdivecomputer/libdivecomputer). Our own
    109   decoder of Shearwater export files follows its `shearwater_predator_parser.c`, and the tests check one against
    110   the other.
    111 - The choice of the Bluetooth service and characteristics follows Subsurface's `core/qt-ble.cpp` (GPL-2.0).
    112 - The format reader was validated on two public sample logbooks: https://github.com/Egbertdepauw/anchorline (real
    113   exports) and https://github.com/Ventrilok/divelens
    114 
    115 ## Building and testing
    116 
    117     make test-kit                      # package tests (checked against the real command-line git)
    118     make build                         # app for the simulator
    119     make shot SHOT=list                # screenshot with the demo logbook (build/shots/)
    120     make shot SHOT=dive ARGS="-showDive 11"
    121 
    122 `make test-kit FILTER=TestName` runs a single test.
    123 
    124 Launch options: `-demo`, `-tab sites|stats|settings`, `-showDive N`, `-scroll notes|bottom`, `-edit`, `-newDive`,
    125 `-demoChanges`, `-importFile path`, `-importAll`, `-createAccount`, `-remoraFolder path`, `-merouFolder path`,
    126 `-selectDives 12,13` (the selection that precedes a merge; with `-merge`, its confirmation), `-tab plan -planner simple|technical|gas`, `-starterPlan`, `-startLocal`, `-restoreBackup`, `-backupFolder path` (a plain folder stands in for iCloud Drive), `-connectCloud`, `-cards`, `-demoCards`, `-showCard`, `-editCard`, `-selectDives 12,13`, `-mergeNow`, `-diveComputer`
    127 (opens the download sheet; with `-fakeComputers` it lists made-up computers, the simulator having no Bluetooth).
    128 
    129 ### Validating on a real logbook
    130 
    131 These tests are skipped unless their environment variables are set (run them from `Packages/DiveKit`):
    132 
    133 - `SUBSURFACE_TREE=/path/to/tree swift test --filter testExternalTree`: a folder laid out like the git tree
    134   (`00-Subsurface`, `01-Divesites/`, `yyyy/mm/…`).
    135 - `SHEARWATER_EXPORT=/path/to/export swift test --filter testRealShearwaterExport`: a Shearwater Cloud export
    136   (the `.zip` or `dive_data.db`).
    137 - `CLOUD_EMAIL=… CLOUD_PASSWORD=… swift test --filter testRealCloudReadOnly`: a real Subsurface cloud account,
    138   read-only; nothing is pushed.
    139 
    140 ### Development setup
    141 
    142 The Makefile assumes the author's setup: the sources are edited on a Linux host and synced with `rsync` to a Mac
    143 reachable over SSH as `chunga`, which runs Swift and Xcode. Set `CHUNGA` (the SSH host) and `REMOTE` (the
    144 directory on the Mac) to adapt it:
    145 
    146     make build CHUNGA=my-mac REMOTE=src/subrascasse
    147 
    148 Or work directly on a Mac: run `xcodegen` at the root of the repository and open the generated Xcode project
    149 (`project.yml` is the source of truth; the `.xcodeproj` is not versioned), and run `swift test` in
    150 `Packages/DiveKit`.
    151 
    152 ## License
    153 
    154 GPL-2.0-only. See [LICENSE](LICENSE).