scsir/command/
test_unit_ready.rs1#![allow(dead_code)]
2
3use modular_bitfield_msb::prelude::*;
4
5use crate::{result_data::ResultData, Command, DataDirection, Scsi};
6
7#[derive(Clone, Debug)]
8pub struct TestUnitReadyCommand<'a> {
9 interface: &'a Scsi,
10 command_buffer: CommandBuffer,
11}
12
13impl<'a> TestUnitReadyCommand<'a> {
14 fn new(interface: &'a Scsi) -> Self {
15 Self {
16 interface,
17 command_buffer: CommandBuffer::new().with_operation_code(OPERATION_CODE),
18 }
19 }
20
21 pub fn control(&mut self, value: u8) -> &mut Self {
22 self.command_buffer.set_control(value);
23 self
24 }
25
26 pub fn issue(&mut self) -> crate::Result<()> {
27 self.interface.issue(&ThisCommand {
28 command_buffer: self.command_buffer,
29 })
30 }
31}
32
33impl Scsi {
34 pub fn test_unit_ready(&self) -> TestUnitReadyCommand {
35 TestUnitReadyCommand::new(self)
36 }
37}
38
39const OPERATION_CODE: u8 = 0x00;
40
41#[bitfield]
42#[derive(Clone, Copy, Debug)]
43struct CommandBuffer {
44 operation_code: B8,
45 reserved: B32,
46 control: B8,
47}
48
49struct ThisCommand {
50 command_buffer: CommandBuffer,
51}
52
53impl Command for ThisCommand {
54 type CommandBuffer = CommandBuffer;
55
56 type DataBuffer = ();
57
58 type DataBufferWrapper = ();
59
60 type ReturnType = crate::Result<()>;
61
62 fn direction(&self) -> DataDirection {
63 DataDirection::None
64 }
65
66 fn command(&self) -> Self::CommandBuffer {
67 self.command_buffer
68 }
69
70 fn data(&self) -> Self::DataBufferWrapper {}
71
72 fn data_size(&self) -> u32 {
73 0
74 }
75
76 fn process_result(&self, result: ResultData<Self::DataBufferWrapper>) -> Self::ReturnType {
77 result.check_ioctl_error()?;
78 result.check_common_error()?;
79
80 Ok(())
81 }
82}
83
84#[cfg(test)]
85mod tests {
86 use super::*;
87 use std::mem::size_of;
88
89 const COMMAND_LENGTH: usize = 6;
90
91 #[test]
92 fn layout_test() {
93 assert_eq!(
94 size_of::<CommandBuffer>(),
95 COMMAND_LENGTH,
96 concat!("Size of: ", stringify!(CommandBuffer))
97 );
98 }
99}