e1608: do not fight a hardware trigger, stop the scan on a failed connect, daemon drop timer in the mock

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino FerrariandClaude Sonnet 4.6 committed 2026-11-01 10:01:38 +01:00
1 parent 3093568d11
commit 6245811699
5 files changed
+24 -4

No files matched your search

+17 -1
View File
@@ -186,6 +186,7 @@ void E1608Source::open(SourceSink& sink) {
void E1608Source::close() {
if (state_ == State::Scanning) dev_.scan_stop();
scan_started_ = false;
link_.close();
connected_.store(false, std::memory_order_relaxed);
}
@@ -212,6 +213,15 @@ void E1608Source::note(const std::string& msg) {
}
void E1608Source::fail(const std::string& msg, bool fatal) {
if (scan_started_) {
// The scan may have started before a later connect step failed: tell the board to stop, so it
// is not left scanning with nobody reading. Best effort; it must never throw out of here.
try {
dev_.scan_stop();
} catch (...) {
}
scan_started_ = false;
}
link_.close();
const bool was_up = connected_.exchange(false, std::memory_order_relaxed);
note(msg);
@@ -283,6 +293,7 @@ void E1608Source::connect_and_start() {
}
link_.connect(host, cfg_.port, cfg_.code, cfg_.timeout_ms);
scan_started_ = false;
cal_ = Calibration{};
if (cfg_.calibrate && !dev_.read_calibration(cal_))
note("calibration memory refused; using nominal values");
@@ -419,13 +430,16 @@ void E1608Source::check_status() {
sink_->on_event(SourceEvent::Error, "scan overrun; restarting");
restart_scan();
pending_lost_ = 1;
} else if (!(st & 2) && cfg_.auto_restart) {
} else if (!(st & 2) && cfg_.auto_restart && cfg_.trigger == Trigger::None) {
// With a hardware trigger the board may report "not running" while it waits for the edge;
// restarting then would reset the wait forever, so only the overrun bit restarts the scan.
restart_scan();
}
}
void E1608Source::restart_scan() {
dev_.scan_stop();
scan_started_ = false;
pending_.clear();
for (auto& r : ready_) r.clear();
start_scan();
@@ -437,6 +451,7 @@ void E1608Source::start_scan() {
throw LinkError(LinkError::Kind::Command, "the aggregate rate exceeds 250 kS/s");
try {
dev_.scan_start(queue_, cfg_.aggregate(), cfg_.ext_clock, cfg_.trigger);
scan_started_ = true;
} catch (...) {
// The board may have accepted the start (0x11) before a later step failed (the filler byte):
// tell it to stop, so it is not left scanning with nobody reading.
@@ -444,6 +459,7 @@ void E1608Source::start_scan() {
dev_.scan_stop();
} catch (...) {
}
scan_started_ = false;
throw;
}
}
+1
View File
@@ -124,6 +124,7 @@ class E1608Source final : public DataSource {
E1608Settings cfg_;
SourceSink* sink_ = nullptr;
State state_ = State::Down;
bool scan_started_ = false; ///< a scan start succeeded and no stop has followed
Link link_;
Device dev_{link_};
Calibration cal_;