Skip to main content

viva_u3v/
status.rs

1//! The status codes a USB3 Vision device answers with: GenCP's table, and
2//! USB3 Vision's own codes.
3//!
4//! The codes GigE Vision defines too are [`viva_gencp::StatusCode`], wrapped
5//! as [`U3vStatus::Common`]. `0x800B` is the reason the two transports have
6//! a table each: GenCP calls it `MSG_TIMEOUT`, GigE Vision `NO_MSG`
7//! (ADR-0020).
8//!
9//! GenCP 1.2 Table 6 is free; the USB3 Vision codes (`0xA001`–`0xA101`) are
10//! from aravis's `ArvUvcpStatus` (`arvuvcpprivate.h`), since the USB3 Vision
11//! standard is not freely available.
12
13viva_gencp::transport_status! {
14    /// A USB3 Vision acknowledgement's status.
15    pub enum U3vStatus {
16        /// GenCP: a timeout waiting for an acknowledge. GigE Vision's
17        /// `NO_MSG` is the same number.
18        MsgTimeout = 0x800B, "MSG_TIMEOUT";
19        /// USB3 Vision: the device cannot resend.
20        ResendNotSupported = 0xA001, "RESEND_NOT_SUPPORTED";
21        /// USB3 Vision: the stream endpoint is halted.
22        DsiEndpointHalted = 0xA002, "DSI_ENDPOINT_HALTED";
23        /// USB3 Vision: the payload size is not a multiple of the transfer
24        /// alignment the device requires.
25        SiPayloadSizeNotAligned = 0xA003, "SI_PAYLOAD_SIZE_NOT_ALIGNED";
26        /// USB3 Vision: the streaming interface registers contradict each
27        /// other.
28        SiRegistersInconsistent = 0xA004, "SI_REGISTERS_INCONSISTENT";
29        /// USB3 Vision: data was discarded.
30        DataDiscarded = 0xA100, "DATA_DISCARDED";
31        /// USB3 Vision: the device's buffer overran.
32        DataOverrun = 0xA101, "DATA_OVERRUN";
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39    use viva_gencp::StatusCode;
40
41    /// GenCP 1.2 Table 6 and aravis's `ArvUvcpStatus`, as literals rather
42    /// than from `to_raw` (ADR-0019).
43    const TABLE: &[(u16, &str)] = &[
44        (0x0000, "SUCCESS"),
45        (0x8001, "NOT_IMPLEMENTED"),
46        (0x8002, "INVALID_PARAMETER"),
47        (0x8003, "INVALID_ADDRESS"),
48        (0x8004, "WRITE_PROTECT"),
49        (0x8005, "BAD_ALIGNMENT"),
50        (0x8006, "ACCESS_DENIED"),
51        (0x8007, "BUSY"),
52        (0x800B, "MSG_TIMEOUT"),
53        (0x800E, "INVALID_HEADER"),
54        (0x800F, "WRONG_CONFIG"),
55        (0x8FFF, "ERROR"),
56        (0xA001, "RESEND_NOT_SUPPORTED"),
57        (0xA002, "DSI_ENDPOINT_HALTED"),
58        (0xA003, "SI_PAYLOAD_SIZE_NOT_ALIGNED"),
59        (0xA004, "SI_REGISTERS_INCONSISTENT"),
60        (0xA100, "DATA_DISCARDED"),
61        (0xA101, "DATA_OVERRUN"),
62    ];
63
64    #[test]
65    fn every_code_in_the_table_is_named_and_round_trips() {
66        for &(raw, name) in TABLE {
67            let status = U3vStatus::from_raw(raw);
68            assert_eq!(status.name(), name, "{raw:#06x}");
69            assert_eq!(status.to_raw(), raw, "{name}");
70        }
71    }
72
73    /// GigE Vision's packet-resend family is not GenCP's.
74    #[test]
75    fn gige_codes_are_unknown_here() {
76        assert_eq!(U3vStatus::from_raw(0x800C), U3vStatus::Unknown(0x800C));
77        assert_eq!(
78            U3vStatus::from_raw(0x8004),
79            U3vStatus::Common(StatusCode::WriteProtect)
80        );
81    }
82}