From 06e4a4105035b36a6789f0c58192bc051e3bc33a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 23:57:13 +0000 Subject: [PATCH] No line: the modem started on its own, without a SIP account A fifth line, "No line (the modem on its own)": the engine starts as on a peer line (no SIP, no network needed) with nothing behind it. It answers AT commands in the terminal and on the serial bridges; a dial gets NO DIALTONE, as a modem with no phone cable plugged in (the engine's new peer event NO LINE), an answer NO CARRIER. Home offers "Start without a line" beside "Set up SIP" when there's no account: the line set to none and the modem started in one tap. iOS has the same line and button. Tests: c_api_test (NO LINE: NO DIALTONE), DModemKitTests.testNoLine (started without an account, a dial NO DIALTONE, commands still answered), PeerShotsTest.noLine, DashboardShotsTest.firstRun. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs --- README.md | 5 +++++ app/src/main/cpp/dmodem_engine.h | 3 ++- app/src/main/cpp/peer_modem.cpp | 3 +++ .../neodesktop/dmodem/modem/ModemService.kt | 9 +++++++- .../dmodem/settings/ModemSettings.kt | 6 +++++- .../neodesktop/dmodem/ui/DashboardScreen.kt | 17 ++++++++++++++- .../com/neodesktop/dmodem/ui/PeerLineUi.kt | 12 ++++++++++- .../dmodem/ui/DashboardShotsTest.kt | 4 ++++ .../com/neodesktop/dmodem/ui/PeerShotsTest.kt | 12 +++++++++++ ios/DModem/Sources/AppModel.swift | 4 ++-- ios/DModem/Sources/HomeView.swift | 17 +++++++++++++-- ios/DModem/Sources/SettingsView.swift | 15 ++++++++----- .../Sources/DModemKit/ModemSession.swift | 10 +++++++++ .../Sources/DModemKit/ModemSettings.swift | 8 +++++-- .../Tests/DModemKitTests/DModemKitTests.swift | 21 +++++++++++++++++++ native-test/c_api_test.c | 18 ++++++++++++++++ 16 files changed, 148 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2327572..b6f716b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ Fax doesn't get through at all (V.cvm has no fax; V.27ter's training at 2400 bit through AMR 12.2 with about one bit in sixteen wrong), so the app turns fax down on that line. +Or no line at all: the modem starts on its own, no SIP account or +network needed, and answers AT commands in the terminal and on the serial +bridges; a dial gets NO DIALTONE, as a modem with no phone cable. Home +offers it beside setting up SIP ("Start without a line"). + Two phones with the app can also be each other's line, over Wi-Fi or Bluetooth, with no SIP account: the modems connect as over a perfect line. An optional PIN, the same on both phones, keeps other callers out (a diff --git a/app/src/main/cpp/dmodem_engine.h b/app/src/main/cpp/dmodem_engine.h index 3f263bd..5084c95 100644 --- a/app/src/main/cpp/dmodem_engine.h +++ b/app/src/main/cpp/dmodem_engine.h @@ -85,7 +85,8 @@ void dmodem_stop(void); int dmodem_running(void); /* a peer line's event to the modem: RING, CANCEL, ANSWERED, FAILED - , DROPPED */ + , DROPPED; NO LINE (a dial with nothing plugged in: NO + DIALTONE) */ void dmodem_peer_event(const char *line); #ifdef __cplusplus diff --git a/app/src/main/cpp/peer_modem.cpp b/app/src/main/cpp/peer_modem.cpp index 96c3bad..150aa0a 100644 --- a/app/src/main/cpp/peer_modem.cpp +++ b/app/src/main/cpp/peer_modem.cpp @@ -304,6 +304,9 @@ void PeerModem::act(const char *s) m.line_answered(); else if (!strncmp(s, "FAILED ", 7)) m.line_failed(failure(atoi(s + 7))); + else if (!strcmp(s, "NO LINE")) + /* (nothing plugged in: as a modem with no phone cable) */ + m.line_failed(dcore::Result::NoDialtone); else if (!strcmp(s, "DROPPED")) { if (m.started()) m.line_dropped(); diff --git a/app/src/main/java/com/neodesktop/dmodem/modem/ModemService.kt b/app/src/main/java/com/neodesktop/dmodem/modem/ModemService.kt index 7e2b434..f64aa61 100644 --- a/app/src/main/java/com/neodesktop/dmodem/modem/ModemService.kt +++ b/app/src/main/java/com/neodesktop/dmodem/modem/ModemService.kt @@ -236,7 +236,7 @@ class ModemService : Service() { speakerSocket = s ModemState.speaker.start(java.io.FileInputStream(s.fileDescriptor)) } - if (settings.peer) com.neodesktop.dmodem.peer.Peers.start(this, settings, ::log) + if (settings.peer && !settings.noLine) com.neodesktop.dmodem.peer.Peers.start(this, settings, ::log) val start = settings.startCommands() if (start.isNotBlank()) ModemState.dte.write(start + "\r") return true @@ -327,6 +327,12 @@ class ModemService : Service() { } override fun onLine(caller: Boolean, dial: String, line: android.os.ParcelFileDescriptor) { + if (settings.noLine) { + // (nothing plugged in: a dial gets NO DIALTONE, an answer NO CARRIER) + NativeModem.peerEvent(if (caller) "NO LINE" else "FAILED 503") + runCatching { line.close() } + return + } com.neodesktop.dmodem.peer.Peers.lineStarted(caller, dial, line) } @@ -425,6 +431,7 @@ class ModemService : Service() { ModemSettings.LINE_WIFI -> " (line: another phone on Wi-Fi)" ModemSettings.LINE_BLUETOOTH -> " (line: another phone on Bluetooth)" ModemSettings.LINE_CELL -> " (line: mobile calls)" + ModemSettings.LINE_NONE -> " (no line)" else -> "" } } diff --git a/app/src/main/java/com/neodesktop/dmodem/settings/ModemSettings.kt b/app/src/main/java/com/neodesktop/dmodem/settings/ModemSettings.kt index ce0d2f5..e5ea865 100644 --- a/app/src/main/java/com/neodesktop/dmodem/settings/ModemSettings.kt +++ b/app/src/main/java/com/neodesktop/dmodem/settings/ModemSettings.kt @@ -53,9 +53,12 @@ data class ModemSettings( */ val cellSpeed: String = CELL_VCVM, ) { - /** the line is another phone (or this phone's mobile calls), not SIP: the app carries its samples */ + /** the line is another phone (or this phone's mobile calls, or none), not SIP: the app carries its samples */ val peer: Boolean get() = line != LINE_SIP + /** no line at all: the modem on its own (AT commands, the terminal, the bridges); a dial gets NO DIALTONE */ + val noLine: Boolean get() = line == LINE_NONE + /** Enough to start: an account (or the line another phone's). */ val complete: Boolean get() = peer || (user.isNotBlank() && domain.isNotBlank()) @@ -77,6 +80,7 @@ data class ModemSettings( const val LINE_WIFI = "wifi" const val LINE_BLUETOOTH = "bluetooth" const val LINE_CELL = "cell" + const val LINE_NONE = "none" /** the mobile-call line's V.cvm (D-Modem-RE's +MS=V_CVM) */ const val CELL_VCVM = "V_CVM" diff --git a/app/src/main/java/com/neodesktop/dmodem/ui/DashboardScreen.kt b/app/src/main/java/com/neodesktop/dmodem/ui/DashboardScreen.kt index 18d4453..dbe5283 100644 --- a/app/src/main/java/com/neodesktop/dmodem/ui/DashboardScreen.kt +++ b/app/src/main/java/com/neodesktop/dmodem/ui/DashboardScreen.kt @@ -130,6 +130,12 @@ fun DashboardScreen( onHangUp = { scope.launch { Terminal.session.hangUp(status.link == NativeModem.Link.ONLINE) } }, onTerminal = onOpenTerminal, onSetUp = onOpenSettings, + onStartNoLine = { + scope.launch { + SettingsStore(context).save(settings.copy(line = ModemSettings.LINE_NONE)) + ModemService.start(context) + } + }, ) if (appearance != null && !lightsOnTop) ModemLights() @@ -202,6 +208,7 @@ private fun HeroCard( onHangUp: () -> Unit, onTerminal: () -> Unit, onSetUp: () -> Unit, + onStartNoLine: () -> Unit = {}, ) { val online = run == ModemState.Run.RUNNING && status.link == NativeModem.Link.ONLINE val (dot, title, sub) = when { @@ -249,8 +256,11 @@ private fun HeroCard( Spacer(Modifier.height(4.dp)) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { when { - run == ModemState.Run.STOPPED && !configured -> + run == ModemState.Run.STOPPED && !configured -> { Button(onClick = onSetUp) { Text("Set up SIP") } + // (the modem on its own: its AT commands, the terminal, the bridges) + OutlinedButton(onClick = onStartNoLine) { Text("Start without a line") } + } run == ModemState.Run.STOPPED -> Button(onClick = onStart) { Text("Start modem") } online || status.offhook -> @@ -288,6 +298,11 @@ private fun LineCard(s: ModemSettings, run: ModemState.Run, network: String?, on Card(Modifier.fillMaxWidth().clickable(onClick = onSettings)) { Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { Text("Line", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.primary) + if (s.noLine) { + InfoRow("Line", "none: the modem on its own") + Text("AT commands answered; a dial gets NO DIALTONE", style = MaterialTheme.typography.bodySmall) + return@Column + } if (s.peer) { PeerLineRows(s, run, network) return@Column diff --git a/app/src/main/java/com/neodesktop/dmodem/ui/PeerLineUi.kt b/app/src/main/java/com/neodesktop/dmodem/ui/PeerLineUi.kt index cb01e9d..c858077 100644 --- a/app/src/main/java/com/neodesktop/dmodem/ui/PeerLineUi.kt +++ b/app/src/main/java/com/neodesktop/dmodem/ui/PeerLineUi.kt @@ -54,6 +54,7 @@ fun LineChoice(s: ModemSettings, onChange: (ModemSettings) -> Unit) { ModemSettings.LINE_WIFI to "Another phone with D-Modem, on Wi-Fi", ModemSettings.LINE_BLUETOOTH to "Another phone with D-Modem, on Bluetooth", ModemSettings.LINE_CELL to "This phone's mobile calls (slow; root)", + ModemSettings.LINE_NONE to "No line (the modem on its own)", ) var open by remember { mutableStateOf(false) } ExposedDropdownMenuBox(expanded = open, onExpandedChange = { open = it }) { @@ -73,7 +74,7 @@ fun LineChoice(s: ModemSettings, onChange: (ModemSettings) -> Unit) { onClick = { open = false when (line) { - ModemSettings.LINE_SIP, ModemSettings.LINE_CELL -> onChange(s.copy(line = line)) + ModemSettings.LINE_SIP, ModemSettings.LINE_CELL, ModemSettings.LINE_NONE -> onChange(s.copy(line = line)) ModemSettings.LINE_WIFI -> onChange( s.copy(line = line, peerAddress = if (s.line == line) s.peerAddress else "", peerName = ""), ) @@ -98,6 +99,15 @@ fun LineChoice(s: ModemSettings, onChange: (ModemSettings) -> Unit) { */ @Composable fun PeerLineFields(s: ModemSettings, onChange: (ModemSettings) -> Unit) { + if (s.noLine) { + Text( + "The modem starts with nothing on its line: no SIP account, no network needed. It answers AT commands " + + "in the terminal and on the serial bridges (ATI, AT&V, its registers, its settings); a dial gets NO DIALTONE, " + + "as a modem with no phone cable plugged in.", + style = MaterialTheme.typography.bodySmall, + ) + return + } if (s.line == ModemSettings.LINE_CELL) { CellLineFields(s, onChange) return diff --git a/app/src/test/java/com/neodesktop/dmodem/ui/DashboardShotsTest.kt b/app/src/test/java/com/neodesktop/dmodem/ui/DashboardShotsTest.kt index 58ac408..1a70a41 100644 --- a/app/src/test/java/com/neodesktop/dmodem/ui/DashboardShotsTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/ui/DashboardShotsTest.kt @@ -4,6 +4,7 @@ package com.neodesktop.dmodem.ui import android.graphics.Bitmap import androidx.compose.ui.graphics.asAndroidBitmap +import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.captureToImage import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onRoot @@ -51,6 +52,9 @@ class DashboardShotsTest { ModemState.setStatus(ModemState.IDLE) compose.waitForIdle() shot("home-1-first-run") + // no SIP account yet: set one up, or start the modem on its own + compose.onNodeWithText("Set up SIP").assertExists() + compose.onNodeWithText("Start without a line").assertExists() } @Test diff --git a/app/src/test/java/com/neodesktop/dmodem/ui/PeerShotsTest.kt b/app/src/test/java/com/neodesktop/dmodem/ui/PeerShotsTest.kt index 3052830..6d882d8 100644 --- a/app/src/test/java/com/neodesktop/dmodem/ui/PeerShotsTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/ui/PeerShotsTest.kt @@ -64,6 +64,18 @@ class PeerShotsTest { shot("peer-0-line-menu") } + @Test + fun noLine() { + save(ModemSettings(line = ModemSettings.LINE_SIP)) + compose.onNodeWithText("Settings").performClick() + compose.onNodeWithText("A SIP account (calls over the internet)").performScrollTo().performClick() + compose.onNodeWithText("No line (the modem on its own)").performClick() + compose.onNodeWithText("a dial gets NO DIALTONE", substring = true).assertExists() + // (no SIP account asked for) + compose.onNodeWithText("SIP account (saved with the button below)").assertDoesNotExist() + shot("peer-4-no-line") + } + @Test fun homeOnACall() { save(ModemSettings(line = ModemSettings.LINE_WIFI, peerAddress = "192.168.1.20:5070", peerName = "D-Modem on Pixel 8", listen = true)) diff --git a/ios/DModem/Sources/AppModel.swift b/ios/DModem/Sources/AppModel.swift index 54ca6c8..33b9559 100644 --- a/ios/DModem/Sources/AppModel.swift +++ b/ios/DModem/Sources/AppModel.swift @@ -136,13 +136,13 @@ final class AppModel: ObservableObject { // (the background audio first: the call keeps the app running) audio.begin() // (the line to another phone first: the modem's start commands may dial) - if s.peer { peer.start(s, session: session) } else { session.onLine = nil } + if s.peer && !s.noLine { peer.start(s, session: session) } else { session.onLine = nil } if !session.start(s, dns: SystemDNS.servers(), dataFile: dataFile) { peer.stop() audio.end() } } - watchPeer(s.peer) + watchPeer(s.peer && !s.noLine) } func stop() { diff --git a/ios/DModem/Sources/HomeView.swift b/ios/DModem/Sources/HomeView.swift index 30ce58d..dd22c43 100644 --- a/ios/DModem/Sources/HomeView.swift +++ b/ios/DModem/Sources/HomeView.swift @@ -43,7 +43,10 @@ struct HomeView: View { .padding(.vertical, 6) } Section("Line") { - if model.settings.line == .wifi { + if model.settings.noLine { + LabeledContent("Line", value: "none: the modem on its own") + Text("AT commands answered; a dial gets NO DIALTONE").foregroundStyle(.secondary) + } else if model.settings.line == .wifi { LabeledContent("Another phone", value: model.settings.peerAddress.isEmpty ? "none chosen" : model.settings.peerAddress) Text(model.peerState ?? "Starts with the modem").foregroundStyle(.secondary) if let e = model.peerError { @@ -53,7 +56,9 @@ struct HomeView: View { LabeledContent("SIP account", value: model.settings.complete ? "\(model.settings.user)@\(model.settings.domain)" : "not set up") LabeledContent("Fax", value: model.settings.t38 ? "audio or T.38" : "audio") } - LabeledContent("Incoming calls", value: model.settings.listen ? "taken" : "off") + if !model.settings.noLine { + LabeledContent("Incoming calls", value: model.settings.listen ? "taken" : "off") + } } if model.run == .running { Section("AT command") { @@ -86,6 +91,14 @@ struct HomeView: View { Button("Start the modem") { model.start() } .buttonStyle(.borderedProminent) .disabled(!model.settings.complete) + if !model.settings.complete { + // (the modem on its own: its AT commands in the terminal) + Button("Start without a line") { + model.settings.line = .none + model.start() + } + .buttonStyle(.bordered) + } case .running: if model.status.offHook { Button("Hang up") { model.hangUp() }.buttonStyle(.borderedProminent) diff --git a/ios/DModem/Sources/SettingsView.swift b/ios/DModem/Sources/SettingsView.swift index ff0b004..0cac04e 100644 --- a/ios/DModem/Sources/SettingsView.swift +++ b/ios/DModem/Sources/SettingsView.swift @@ -17,19 +17,24 @@ struct SettingsView: View { Picker("Line", selection: $model.settings.line) { Text("SIP account").tag(ModemSettings.Line.sip) Text("Another phone (Wi-Fi)").tag(ModemSettings.Line.wifi) + Text("No line (the modem on its own)").tag(ModemSettings.Line.none) } } footer: { - Text(model.settings.line == .sip - ? "The modem calls through a SIP provider to the phone network." - : "The two phones' modems call each other as on a perfect phone line, no SIP account: each dials (ATD) or answers as usual. The other phone needs D-Modem (Android or iOS) on the same Wi-Fi, taking calls.") + switch model.settings.line { + case .sip: Text("The modem calls through a SIP provider to the phone network.") + case .wifi: Text("The two phones' modems call each other as on a perfect phone line, no SIP account: each dials (ATD) or answers as usual. The other phone needs D-Modem (Android or iOS) on the same Wi-Fi, taking calls.") + case .none: Text("The modem starts with nothing on its line, no SIP account or network: it answers AT commands in the terminal; a dial gets NO DIALTONE, as a modem with no phone cable plugged in.") + } } if model.settings.line == .wifi { PeerSection(model: model) - } else { + } else if model.settings.line == .sip { sipSection } Section("Calls") { - Toggle(model.settings.line == .sip ? "Take incoming calls" : "Take calls from the other phone", isOn: $model.settings.listen) + if !model.settings.noLine { + Toggle(model.settings.line == .sip ? "Take incoming calls" : "Take calls from the other phone", isOn: $model.settings.listen) + } if model.settings.line == .sip { Toggle("Fax over T.38", isOn: $model.settings.t38) Stepper("Local SIP port: \(model.settings.sipPort)", value: $model.settings.sipPort, in: 1024...65535) diff --git a/ios/DModemKit/Sources/DModemKit/ModemSession.swift b/ios/DModemKit/Sources/DModemKit/ModemSession.swift index 5776757..25a30d1 100644 --- a/ios/DModemKit/Sources/DModemKit/ModemSession.swift +++ b/ios/DModemKit/Sources/DModemKit/ModemSession.swift @@ -19,6 +19,8 @@ public final class ModemSession: EngineListener, @unchecked Sendable { private var dte: DTE? /// the job the DTE is lent to (a fax call, a transfer, dial-up): its data goes there, not to [onData] private var claimant: ((Data) -> Void)? + /// the settings' line is none: the engine's dials answered here + private var noLine = false /// the most of the log and the console kept public var logMax = 2000 @@ -63,6 +65,7 @@ public final class ModemSession: EngineListener, @unchecked Sendable { let d = try engine.start(settings.engineConfig(dns: dns, dataFile: dataFile), listener: self) lock.lock() dte = d + noLine = settings.noLine _run = .running _status = ModemStatus() _error = nil @@ -181,6 +184,13 @@ public final class ModemSession: EngineListener, @unchecked Sendable { } public func engineLine(caller: Bool, dial: String, fd: Int32) { + lock.lock(); let none = noLine; lock.unlock() + if none { + // (nothing plugged in: a dial gets NO DIALTONE, an answer NO CARRIER) + engine.peerEvent(caller ? "NO LINE" : "FAILED 503") + close(fd) + return + } if let h = onLine { h(caller, dial, fd) } else { close(fd) } } diff --git a/ios/DModemKit/Sources/DModemKit/ModemSettings.swift b/ios/DModemKit/Sources/DModemKit/ModemSettings.swift index 6cbeef8..dbdc0f7 100644 --- a/ios/DModemKit/Sources/DModemKit/ModemSettings.swift +++ b/ios/DModemKit/Sources/DModemKit/ModemSettings.swift @@ -6,7 +6,8 @@ import Foundation /// a SIP account, or another phone with the app on the same Wi-Fi). public struct ModemSettings: Codable, Equatable, Sendable { public enum Line: String, Codable, Sendable { - case sip, wifi + /// a SIP account; another phone with the app on Wi-Fi; nothing at all (the modem on its own) + case sip, wifi, none } /// the SIP account @@ -54,9 +55,12 @@ public struct ModemSettings: Codable, Equatable, Sendable { ("sip-password", \.password), ("peer-pin", \.peerPin), ("isp-password", \.ispPassword), ] - /// the line another phone's, not SIP + /// the line another phone's (or none), not SIP public var peer: Bool { line != .sip } + /// no line: the modem on its own (AT commands, the terminal); a dial gets NO DIALTONE + public var noLine: Bool { line == .none } + /// enough to start: an account (or the line another phone's) public var complete: Bool { peer || (!user.isEmpty && !domain.isEmpty) } diff --git a/ios/DModemKit/Tests/DModemKitTests/DModemKitTests.swift b/ios/DModemKit/Tests/DModemKitTests/DModemKitTests.swift index dd587c8..95e3fd8 100644 --- a/ios/DModemKit/Tests/DModemKitTests/DModemKitTests.swift +++ b/ios/DModemKit/Tests/DModemKitTests/DModemKitTests.swift @@ -134,6 +134,27 @@ final class DModemKitTests: XCTestCase { session.stop() } + func testNoLine() { + signal(SIGPIPE, SIG_IGN) + let session = ModemSession() + var settings = ModemSettings() + settings.line = .none + settings.initCommands = "ATE0" + // (no SIP account: it starts all the same) + XCTAssertTrue(settings.complete) + XCTAssertTrue(session.start(settings)) + XCTAssertTrue(waitFor { session.console.contains("OK") }, session.console) + // a dial: nothing plugged in + session.command("ATX3D5551234") + XCTAssertTrue(waitFor { session.console.contains("NO DIALTONE") }, session.console) + // still answering commands + session.command("ATI3") + XCTAssertTrue(waitFor { session.console.contains("peer") }, session.console) + session.stop() + // the setting kept + XCTAssertEqual(try JSONDecoder().decode(ModemSettings.self, from: JSONEncoder().encode(settings)).line, .none) + } + func testIncompleteSettingsDontStart() { let session = ModemSession() XCTAssertFalse(session.start(ModemSettings())) diff --git a/native-test/c_api_test.c b/native-test/c_api_test.c index 889baa3..cdf0de8 100644 --- a/native-test/c_api_test.c +++ b/native-test/c_api_test.c @@ -127,6 +127,24 @@ int main(void) if (fd >= 0) close(fd); CHECK(expect(dte, "BUSY", 10), "the program's FAILED 486: BUSY"); + + /* no line at all (the app's "no line"): NO DIALTONE */ + pthread_mutex_lock(&mu); + line_fd = -1; + pthread_mutex_unlock(&mu); + fd = -1; + put(dte, "ATD1\r"); + for (int i = 0; i < 50 && fd < 0; i++) { + usleep(100000); + pthread_mutex_lock(&mu); + fd = line_fd; + pthread_mutex_unlock(&mu); + } + CHECK(fd >= 0, "ATD again: the line to the program"); + dmodem_peer_event("NO LINE"); + if (fd >= 0) + close(fd); + CHECK(expect(dte, "NO DIALTONE", 10), "the program's NO LINE: NO DIALTONE"); CHECK(statuses > 0 && logs > 0, "status (%d) and log (%d) reported", statuses, logs); /* the DTE closed: the modem ends */