serial-mcp 0.9.3

MCP server for serial port communication. 25 tools (list/open/read/write/transact/capture_boot/get_status/reconfigure/list_profiles/open_profile/save_profile/delete_profile/configure/rollback_profile/get_log/clear_log/export_log/reconnect/compute_checksum/...), resources, prompts, task cancellation, stdio + streamable-HTTP transports.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
//! Shared stop-decision controller for all RX operations.
//!
//! A single `RxStopController` evaluates stop conditions for `read` (and the
//! `transact` read half / `capture_boot` read pipeline). Same inputs yield
//! the same stop reason regardless of which call path drives it.
//!
//! Silence-timeout support (`no_new_rx_timeout_ms`) lets operations stop
//! after a period of no incoming data.
//!
//! The controller is *stateless* regarding event sourcing — it does not own
//! channels, loops, or notification logic. It only tracks counters and deadlines
//! and answers: "should the operation continue, and if not, why?"
//!
//! ## Normal vs Error stop reasons
//!
//! Normal stops (successful outcomes):
//! - `match_found`      — pattern matched in the byte stream
//! - `timeout`          — total wall-clock budget elapsed
//! - `max_buffered_bytes` — buffer budget reached
//! - `data_complete`    — settle phase completed (read without matcher)
//! - `no_new_rx_timeout` — silence budget elapsed (no data within window)
//!
//! Error stops (something went wrong):
//! - `connection_closed` — underlying serial port closed
//! - `cancelled`        — MCP client cancelled the request

use std::time::Instant;

use crate::match_config::MatchResult;
use crate::rx_metadata::{RxStopMetadata, RxStopReason};

/// Decision returned by [`RxStopController`] after evaluating the current state.
#[derive(Debug)]
pub enum RxStopDecision {
    /// No stop condition has triggered; continue collecting data.
    Continue,
    /// A stop condition was met. Contains the outcome metadata.
    Stop(RxStopOutcome),
}

/// Outcome produced when a stop condition triggers.
///
/// Carries the stop metadata plus optional match information.
#[derive(Debug)]
pub struct RxStopOutcome {
    pub meta: RxStopMetadata,
    pub matched: bool,
    pub match_index: Option<usize>,
}

/// Shared stop-decision controller for all RX operations.
///
/// All RX read paths (`read`, `transact` read half, `capture_boot`) call
/// into the same controller instance for the duration of one operation. The
/// controller tracks:
/// - deadline (from `timeout_ms`)
/// - silence deadline (from `no_new_rx_timeout_ms`)
/// - byte counters (observed and returned)
/// - max buffer limit
/// - match state
pub struct RxStopController {
    deadline: Option<Instant>,
    silence_duration: Option<std::time::Duration>,
    silence_deadline: Option<Instant>,
    max_bytes: usize,
    bytes_observed: usize,
    bytes_returned: usize,
    matched: bool,
    match_index: Option<usize>,
}

impl RxStopController {
    /// Create a new controller.
    ///
    /// `start` is the instant the operation began (for deadline computation).
    /// `timeout_ms` is the optional total wall-clock budget in milliseconds.
    /// `max_bytes` is the buffer budget limit.
    /// `no_new_rx_timeout_ms` is the optional silence timeout in milliseconds.
    ///   When set, the operation stops if no data arrives within this window.
    ///   The timer starts immediately and resets on each non-empty data event.
    pub fn new(
        start: Instant,
        timeout_ms: Option<u64>,
        max_bytes: usize,
        no_new_rx_timeout_ms: Option<u64>,
    ) -> Self {
        let deadline = timeout_ms.map(|ms| start + std::time::Duration::from_millis(ms));
        let silence_duration = no_new_rx_timeout_ms.map(std::time::Duration::from_millis);
        let silence_deadline = silence_duration.map(|d| start + d);
        Self {
            deadline,
            silence_duration,
            silence_deadline,
            max_bytes,
            bytes_observed: 0,
            bytes_returned: 0,
            matched: false,
            match_index: None,
        }
    }

    /// Check whether the total timeout deadline has passed.
    ///
    /// Returns `Stop(RxStopOutcome)` with `RxStopReason::Timeout` if the
    /// deadline has been reached, otherwise `Continue`.
    pub fn check_timeout(&self) -> RxStopDecision {
        if let Some(dl) = self.deadline {
            if Instant::now() >= dl {
                return RxStopDecision::Stop(RxStopOutcome {
                    meta: RxStopMetadata::timeout(self.bytes_observed)
                        .with_bytes(self.bytes_observed, self.bytes_returned),
                    matched: self.matched,
                    match_index: self.match_index,
                });
            }
        }
        RxStopDecision::Continue
    }

    /// Check whether the silence timeout has passed.
    ///
    /// The silence deadline is set at operation start and reset every time
    /// a non-empty data chunk arrives. If the deadline has passed, returns
    /// `Stop` with `RxStopReason::NoNewRxTimeout`.
    pub fn check_silence_timeout(&self) -> RxStopDecision {
        if let Some(dl) = self.silence_deadline {
            if Instant::now() >= dl {
                return RxStopDecision::Stop(RxStopOutcome {
                    meta: RxStopMetadata::no_new_rx_timeout(self.bytes_observed)
                        .with_bytes(self.bytes_observed, self.bytes_returned),
                    matched: self.matched,
                    match_index: self.match_index,
                });
            }
        }
        RxStopDecision::Continue
    }

    /// Record that a non-empty data chunk was received, resetting the silence
    /// timer.
    ///
    /// Call this for every `RxEvent::Data` chunk. This resets the silence
    /// deadline so the silence timer starts counting from "now".
    /// Byte value `0x00` counts as real data.
    pub fn notify_data_received(&mut self) {
        if let Some(dur) = self.silence_duration {
            self.silence_deadline = Some(Instant::now() + dur);
        }
    }

    /// Reset the silence timer without recording new data.
    /// Used when the connection is in a disconnected/reconnecting state
    /// where we don't want the silence timer to fire.
    pub fn reset_silence_timer(&mut self) {
        self.silence_deadline = self.silence_duration.map(|dur| Instant::now() + dur);
    }

    /// Record incoming data and evaluate stop conditions.
    ///
    /// Call this after receiving a data chunk. The caller provides:
    /// - `chunk_len`: how many bytes arrived in this chunk
    /// - `buffered_len`: total bytes currently in the accumulation buffer
    /// - `match_result`: `Some(result)` if a matcher is active, `None` otherwise
    ///
    /// The controller updates its counters and checks:
    /// 1. Whether the matcher found a pattern (→ `MatchFound`)
    /// 2. Whether `max_buffered_bytes` was reached (→ `MaxBufferedBytes`)
    ///
    /// Returns `Continue` if no stop condition triggered.
    pub fn push_data(
        &mut self,
        chunk_len: usize,
        buffered_len: usize,
        match_result: Option<MatchResult>,
    ) -> RxStopDecision {
        self.bytes_observed += chunk_len;
        self.bytes_returned = buffered_len;

        if let Some(MatchResult::Found(idx)) = match_result {
            self.matched = true;
            self.match_index = Some(idx);
            return RxStopDecision::Stop(RxStopOutcome {
                meta: RxStopMetadata::match_found(self.bytes_observed, self.bytes_returned),
                matched: self.matched,
                match_index: self.match_index,
            });
        }

        if self.max_bytes > 0 && buffered_len >= self.max_bytes {
            let meta = RxStopMetadata::max_buffered_bytes(self.bytes_observed, self.bytes_returned);
            return RxStopDecision::Stop(RxStopOutcome {
                meta,
                matched: self.matched,
                match_index: self.match_index,
            });
        }

        RxStopDecision::Continue
    }

    /// Produce the stop outcome for a connection-closed event.
    pub fn connection_closed(&self) -> RxStopOutcome {
        RxStopOutcome {
            meta: RxStopMetadata::connection_closed(self.bytes_observed, self.bytes_returned),
            matched: self.matched,
            match_index: self.match_index,
        }
    }

    /// Produce the stop outcome for a client-initiated cancellation.
    pub fn cancelled(&self) -> RxStopOutcome {
        RxStopOutcome {
            meta: RxStopMetadata::cancelled().with_bytes(self.bytes_observed, self.bytes_returned),
            matched: self.matched,
            match_index: self.match_index,
        }
    }

    /// Produce the stop outcome for a runtime frame decode error
    /// (e.g. SLIP malformed escape sequence).
    pub fn framing_error(&self, _error: crate::framing::FrameDecodeError) -> RxStopOutcome {
        RxStopOutcome {
            meta: RxStopMetadata::framing_error(self.bytes_observed),
            matched: false,
            match_index: None,
        }
    }

    /// Build a `DataComplete` outcome for the settle phase of a non-matcher read.
    ///
    /// This is only called by the read path when no matcher is active and the
    /// settle phase ends naturally.
    pub fn data_complete(&self) -> RxStopOutcome {
        RxStopOutcome {
            meta: RxStopMetadata::data_complete(self.bytes_observed, self.bytes_returned),
            matched: false,
            match_index: None,
        }
    }

    /// Current `bytes_observed` counter.
    pub fn bytes_observed(&self) -> usize {
        self.bytes_observed
    }

    /// Current `bytes_returned` counter.
    pub fn bytes_returned(&self) -> usize {
        self.bytes_returned
    }

    /// Whether a match was found.
    pub fn matched(&self) -> bool {
        self.matched
    }

    /// The match index, if found.
    pub fn match_index(&self) -> Option<usize> {
        self.match_index
    }

    /// The configured deadline, if any.
    pub fn deadline(&self) -> Option<Instant> {
        self.deadline
    }

    /// The configured max_bytes limit.
    pub fn max_bytes(&self) -> usize {
        self.max_bytes
    }
}

/// Classify a stop reason as "normal" (not an error).
///
/// Normal stop reasons are returned as successful results from `read`.
/// Error stop reasons are not normal stops and are surfaced through the
/// result's `stop_reason` / `error` fields instead.
pub fn is_normal_stop(reason: RxStopReason) -> bool {
    matches!(
        reason,
        RxStopReason::DataComplete
            | RxStopReason::Timeout
            | RxStopReason::MaxBufferedBytes
            | RxStopReason::MatchFound
            | RxStopReason::NoNewRxTimeout
    )
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::time::Duration;

    #[test]
    fn timeout_stops_at_deadline() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, Some(0), 1024, None);
        // Deadline already passed (0ms timeout).
        let decision = ctrl.check_timeout();
        assert!(matches!(decision, RxStopDecision::Stop(_)));
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.stop_reason, RxStopReason::Timeout);
            assert!(!outcome.matched);
            assert!(outcome.match_index.is_none());
        }
    }

    #[test]
    fn continue_before_deadline() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, Some(5000), 1024, None);
        assert!(matches!(ctrl.check_timeout(), RxStopDecision::Continue));
    }

    #[test]
    fn no_timeout_without_deadline() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, None, 1024, None);
        assert!(matches!(ctrl.check_timeout(), RxStopDecision::Continue));
    }

    #[test]
    fn match_found_stops_immediately() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        let decision = ctrl.push_data(5, 5, Some(MatchResult::Found(2)));
        assert!(matches!(decision, RxStopDecision::Stop(_)));
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.stop_reason, RxStopReason::MatchFound);
            assert!(outcome.matched);
            assert_eq!(outcome.match_index, Some(2));
            assert_eq!(outcome.meta.bytes_observed, 5);
            assert_eq!(outcome.meta.bytes_returned, 5);
        }
    }

    #[test]
    fn no_match_continues() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        let decision = ctrl.push_data(5, 5, Some(MatchResult::NoMatch));
        assert!(matches!(decision, RxStopDecision::Continue));
        assert_eq!(ctrl.bytes_observed(), 5);
    }

    #[test]
    fn max_buffered_bytes_stops() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 10, None);
        // push_data with buffered_len == max_bytes should stop.
        let decision = ctrl.push_data(10, 10, None);
        assert!(matches!(decision, RxStopDecision::Stop(_)));
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.stop_reason, RxStopReason::MaxBufferedBytes);
        }
    }

    #[test]
    fn match_found_takes_priority_over_max_bytes() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 5, None);
        // Both match and max_bytes — match should win.
        let decision = ctrl.push_data(10, 10, Some(MatchResult::Found(3)));
        assert!(matches!(decision, RxStopDecision::Stop(_)));
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.stop_reason, RxStopReason::MatchFound);
        }
    }

    #[test]
    fn connection_closed_outcome() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        ctrl.push_data(100, 80, None);
        let outcome = ctrl.connection_closed();
        assert_eq!(outcome.meta.stop_reason, RxStopReason::ConnectionClosed);
        assert_eq!(outcome.meta.bytes_observed, 100);
        assert_eq!(outcome.meta.bytes_returned, 80);
    }

    #[test]
    fn cancelled_outcome() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        ctrl.push_data(30, 30, None);
        let outcome = ctrl.cancelled();
        assert_eq!(outcome.meta.stop_reason, RxStopReason::Cancelled);
        assert_eq!(outcome.meta.bytes_observed, 30);
    }

    #[test]
    fn framing_error_outcome_not_normal_stop() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, None, 1024, None);
        let outcome = ctrl.framing_error(crate::framing::FrameDecodeError::SlipInvalidEscape(0x41));
        assert_eq!(outcome.meta.stop_reason, RxStopReason::FramingError);
        assert!(!outcome.matched);
        assert!(!is_normal_stop(RxStopReason::FramingError));
    }

    #[test]
    fn data_complete_outcome() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        ctrl.push_data(42, 42, None);
        let outcome = ctrl.data_complete();
        assert_eq!(outcome.meta.stop_reason, RxStopReason::DataComplete);
        assert!(!outcome.matched);
    }

    #[test]
    fn is_normal_stop_classifies_correctly() {
        assert!(is_normal_stop(RxStopReason::DataComplete));
        assert!(is_normal_stop(RxStopReason::Timeout));
        assert!(is_normal_stop(RxStopReason::MaxBufferedBytes));
        assert!(is_normal_stop(RxStopReason::MatchFound));

        assert!(!is_normal_stop(RxStopReason::ConnectionClosed));
        assert!(!is_normal_stop(RxStopReason::Cancelled));
    }

    #[test]
    fn push_data_without_matcher_accumulates() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        // No matcher: pass None
        let decision = ctrl.push_data(10, 10, None);
        assert!(matches!(decision, RxStopDecision::Continue));
        assert_eq!(ctrl.bytes_observed(), 10);

        let decision = ctrl.push_data(20, 30, None);
        assert!(matches!(decision, RxStopDecision::Continue));
        assert_eq!(ctrl.bytes_observed(), 30);
        assert_eq!(ctrl.bytes_returned(), 30);
    }

    #[test]
    fn timeout_preserves_match_state_from_earlier_data() {
        let start = Instant::now();
        // 0ms timeout means deadline has already passed.
        let mut ctrl = RxStopController::new(start, Some(0), 1024, None);
        // Record some data but don't find match yet (this simulates
        // a scenario where data arrived before timeout was checked).
        ctrl.push_data(5, 5, None);
        // Now check timeout — should include bytes info.
        let decision = ctrl.check_timeout();
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.bytes_observed, 5);
            assert_eq!(outcome.meta.bytes_returned, 5);
            assert_eq!(outcome.meta.stop_reason, RxStopReason::Timeout);
        } else {
            panic!("expected Stop decision for expired deadline");
        }
    }

    #[test]
    fn silence_timeout_stops_when_expired() {
        let start = Instant::now();
        // 0ms silence timeout means it's already expired.
        let ctrl = RxStopController::new(start, None, 1024, Some(0));
        let decision = ctrl.check_silence_timeout();
        assert!(matches!(decision, RxStopDecision::Stop(_)));
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.stop_reason, RxStopReason::NoNewRxTimeout);
            assert!(!outcome.matched);
            assert!(outcome.match_index.is_none());
        }
    }

    #[test]
    fn silence_timeout_continues_with_future_deadline() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, None, 1024, Some(5000));
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Continue
        ));
    }

    #[test]
    fn silence_timeout_disabled_when_none() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, None, 1024, None);
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Continue
        ));
    }

    #[test]
    fn notify_data_received_resets_silence_deadline() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, Some(5000));
        // Before data, silence deadline is start + 5s.
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Continue
        ));
        // After receiving data, deadline resets to now + 5s.
        ctrl.notify_data_received();
        // Still continues since we just reset it.
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Continue
        ));
    }

    #[test]
    fn silence_timeout_is_normal_stop() {
        assert!(is_normal_stop(RxStopReason::NoNewRxTimeout));
    }

    #[test]
    fn silence_timeout_with_data_produces_bytes_in_outcome() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, Some(0));
        ctrl.push_data(100, 80, None);
        let decision = ctrl.check_silence_timeout();
        if let RxStopDecision::Stop(outcome) = decision {
            assert_eq!(outcome.meta.stop_reason, RxStopReason::NoNewRxTimeout);
            assert_eq!(outcome.meta.bytes_observed, 100);
            assert_eq!(outcome.meta.bytes_returned, 80);
        } else {
            panic!("expected Stop decision");
        }
    }

    #[test]
    fn both_timeouts_can_be_set_independently() {
        let start = Instant::now();
        // Total timeout of 10s, silence timeout of 1s.
        let ctrl = RxStopController::new(start, Some(10000), 1024, Some(1000));
        assert!(matches!(ctrl.check_timeout(), RxStopDecision::Continue));
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Continue
        ));
    }

    #[test]
    fn no_new_rx_timeout_metadata_preserves_bytes() {
        let meta = RxStopMetadata::no_new_rx_timeout(42);
        assert_eq!(meta.stop_reason, RxStopReason::NoNewRxTimeout);
        assert_eq!(meta.bytes_observed, 42);
        assert_eq!(meta.bytes_returned, 42);
        assert!(!meta.truncated);
    }

    #[test]
    fn no_new_rx_timeout_with_bytes() {
        let meta = RxStopMetadata::no_new_rx_timeout(100).with_bytes(100, 80);
        assert_eq!(meta.bytes_observed, 100);
        assert_eq!(meta.bytes_returned, 80);
        assert!(meta.truncated);
    }

    #[test]
    fn notify_data_received_resets_expired_silence_deadline() {
        // start 200ms in the past + 50ms silence window → deadline is 150ms ago (expired).
        let past = Instant::now() - Duration::from_millis(200);
        let mut ctrl = RxStopController::new(past, None, 1024, Some(50));
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Stop(_)
        ));
        // notify_data_received resets deadline to now+50ms (future).
        ctrl.notify_data_received();
        assert!(matches!(
            ctrl.check_silence_timeout(),
            RxStopDecision::Continue
        ));
    }

    #[test]
    fn matched_getter_reflects_match_state() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        assert!(!ctrl.matched());
        ctrl.push_data(5, 5, Some(MatchResult::Found(2)));
        assert!(ctrl.matched());
    }

    #[test]
    fn match_index_getter_reflects_found_index() {
        let start = Instant::now();
        let mut ctrl = RxStopController::new(start, None, 1024, None);
        assert_eq!(ctrl.match_index(), None);
        ctrl.push_data(5, 5, Some(MatchResult::Found(3)));
        assert_eq!(ctrl.match_index(), Some(3));
    }

    #[test]
    fn max_bytes_getter_returns_configured_limit() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, None, 512, None);
        assert_eq!(ctrl.max_bytes(), 512);
    }

    #[test]
    fn deadline_getter_returns_configured_deadline() {
        let start = Instant::now();
        let ctrl = RxStopController::new(start, Some(5000), 1024, None);
        assert!(ctrl.deadline().is_some());
        let ctrl_no_deadline = RxStopController::new(start, None, 1024, None);
        assert!(ctrl_no_deadline.deadline().is_none());
    }
}