Skip to main content

viva_gige/
status.rs

1//! GigE Vision's status codes: the table GVCP acknowledgements and GVSP
2//! packets share.
3//!
4//! The codes GenCP defines too are [`viva_gencp::StatusCode`], wrapped as
5//! [`GigeStatus::Common`]; the rest are GigE Vision's own. `0x800B` is the
6//! reason the two are not one table: GigE Vision calls it `NO_MSG`, GenCP
7//! `MSG_TIMEOUT` (ADR-0020).
8//!
9//! Values from aravis's `ArvGvspPacketStatus` (`arvgvspprivate.h`), which
10//! lists the GigE Vision table and marks what was deprecated or added in
11//! which version, cross-checked against Wireshark's `GEV_STATUS_*`
12//! (`packet-gvcp.c`). The GigE Vision standard itself is not freely
13//! available.
14
15viva_gencp::transport_status! {
16    /// A GigE Vision status: a GVCP acknowledgement's, or a GVSP packet's.
17    pub enum GigeStatus {
18        /// A GVSP packet the device sent again, in answer to a resend
19        /// request. Not an error.
20        PacketResend = 0x0100, "PACKET_RESEND";
21        /// An internal problem in the device (deprecated).
22        LocalProblem = 0x8008, "LOCAL_PROBLEM";
23        /// The acknowledgement does not match the command (deprecated).
24        MsgMismatch = 0x8009, "MSG_MISMATCH";
25        /// The command is not of a protocol the device supports
26        /// (deprecated).
27        InvalidProtocol = 0x800A, "INVALID_PROTOCOL";
28        /// No message (deprecated). GenCP's `MSG_TIMEOUT` is the same number.
29        NoMsg = 0x800B, "NO_MSG";
30        /// The packet asked for again is no longer available.
31        PacketUnavailable = 0x800C, "PACKET_UNAVAILABLE";
32        /// The device's internal memory overran: data was lost.
33        DataOverrun = 0x800D, "DATA_OVERRUN";
34        /// The packet asked for again has not been sent yet.
35        PacketNotYetAvailable = 0x8010, "PACKET_NOT_YET_AVAILABLE";
36        /// The packet asked for again, and every packet before it, has been
37        /// removed from the device's memory.
38        PacketAndPreviousRemovedFromMemory = 0x8011, "PACKET_AND_PREV_REMOVED_FROM_MEMORY";
39        /// The packet asked for again has been removed from the device's
40        /// memory.
41        PacketRemovedFromMemory = 0x8012, "PACKET_REMOVED_FROM_MEMORY";
42        /// The device has no time reference for a scheduled action (GigE
43        /// Vision 2.0).
44        NoRefTime = 0x8013, "NO_REF_TIME";
45        /// The packet asked for again cannot be sent just now (GigE Vision
46        /// 2.0).
47        PacketTemporarilyUnavailable = 0x8014, "PACKET_TEMPORARILY_UNAVAILABLE";
48        /// The device's queue overflowed (GigE Vision 2.0).
49        Overflow = 0x8015, "OVERFLOW";
50        /// A scheduled action arrived after its time (GigE Vision 2.0).
51        ActionLate = 0x8016, "ACTION_LATE";
52        /// A leader or trailer did not fit the packet size (GigE Vision 2.1).
53        LeaderTrailerOverflow = 0x8017, "LEADER_TRAILER_OVERFLOW";
54    }
55}
56
57impl GigeStatus {
58    /// Whether a GVSP packet with this status is in error: bit 15 set, as
59    /// the standard marks every error code.
60    pub const fn is_error(self) -> bool {
61        self.to_raw() & 0x8000 != 0
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68    use viva_gencp::StatusCode;
69
70    /// The GigE Vision table, written as literals from aravis's
71    /// `ArvGvspPacketStatus` rather than from `to_raw` (ADR-0019).
72    const TABLE: &[(u16, &str)] = &[
73        (0x0000, "SUCCESS"),
74        (0x0100, "PACKET_RESEND"),
75        (0x8001, "NOT_IMPLEMENTED"),
76        (0x8002, "INVALID_PARAMETER"),
77        (0x8003, "INVALID_ADDRESS"),
78        (0x8004, "WRITE_PROTECT"),
79        (0x8005, "BAD_ALIGNMENT"),
80        (0x8006, "ACCESS_DENIED"),
81        (0x8007, "BUSY"),
82        (0x8008, "LOCAL_PROBLEM"),
83        (0x8009, "MSG_MISMATCH"),
84        (0x800A, "INVALID_PROTOCOL"),
85        (0x800B, "NO_MSG"),
86        (0x800C, "PACKET_UNAVAILABLE"),
87        (0x800D, "DATA_OVERRUN"),
88        (0x800E, "INVALID_HEADER"),
89        (0x800F, "WRONG_CONFIG"),
90        (0x8010, "PACKET_NOT_YET_AVAILABLE"),
91        (0x8011, "PACKET_AND_PREV_REMOVED_FROM_MEMORY"),
92        (0x8012, "PACKET_REMOVED_FROM_MEMORY"),
93        (0x8013, "NO_REF_TIME"),
94        (0x8014, "PACKET_TEMPORARILY_UNAVAILABLE"),
95        (0x8015, "OVERFLOW"),
96        (0x8016, "ACTION_LATE"),
97        (0x8017, "LEADER_TRAILER_OVERFLOW"),
98        (0x8FFF, "ERROR"),
99    ];
100
101    #[test]
102    fn every_code_in_the_table_is_named_and_round_trips() {
103        for &(raw, name) in TABLE {
104            let status = GigeStatus::from_raw(raw);
105            assert_eq!(status.name(), name, "{raw:#06x}");
106            assert_eq!(status.to_raw(), raw, "{name}");
107            assert_eq!(status.to_string(), format!("{name} (0x{raw:04X})"));
108        }
109    }
110
111    #[test]
112    fn the_shared_core_is_genicams() {
113        assert_eq!(
114            GigeStatus::from_raw(0x8006),
115            GigeStatus::Common(StatusCode::AccessDenied)
116        );
117        assert_eq!(GigeStatus::from_raw(0x800B).common(), None);
118        assert_eq!(GigeStatus::from_raw(0x8018), GigeStatus::Unknown(0x8018));
119        assert_eq!(
120            GigeStatus::Unknown(0x8018).to_string(),
121            "unknown status (0x8018)"
122        );
123    }
124
125    #[test]
126    fn an_error_has_bit_15_set() {
127        assert!(GigeStatus::from_raw(0x800C).is_error());
128        assert!(!GigeStatus::PacketResend.is_error());
129        assert!(!GigeStatus::from_raw(0).is_error());
130    }
131}