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
use crate::{MemoryTypes, SMBiosStruct, UndefinedStruct};
use std::fmt;
pub struct SMBiosMemoryModuleInformation<'a> {
parts: &'a UndefinedStruct,
}
impl<'a> SMBiosStruct<'a> for SMBiosMemoryModuleInformation<'a> {
const STRUCT_TYPE: u8 = 6u8;
fn new(parts: &'a UndefinedStruct) -> Self {
Self { parts }
}
fn parts(&self) -> &'a UndefinedStruct {
self.parts
}
}
impl<'a> SMBiosMemoryModuleInformation<'a> {
pub fn socket_designation(&self) -> Option<String> {
self.parts.get_field_string(0x04)
}
pub fn bank_connections(&self) -> Option<u8> {
self.parts.get_field_byte(0x05)
}
pub fn current_speed(&self) -> Option<u8> {
self.parts.get_field_byte(0x06)
}
pub fn current_memory_type(&self) -> Option<MemoryTypes> {
self.parts
.get_field_word(0x07)
.map(|raw| MemoryTypes::from(raw))
}
pub fn installed_size(&self) -> Option<u8> {
self.parts.get_field_byte(0x09)
}
pub fn enabled_size(&self) -> Option<u8> {
self.parts.get_field_byte(0x0A)
}
pub fn error_status(&self) -> Option<u8> {
self.parts.get_field_byte(0x0B)
}
}
impl fmt::Debug for SMBiosMemoryModuleInformation<'_> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct(std::any::type_name::<SMBiosMemoryModuleInformation<'_>>())
.field("header", &self.parts.header)
.field("socket_designation", &self.socket_designation())
.field("bank_connections", &self.bank_connections())
.field("current_speed", &self.current_speed())
.field("current_memory_type", &self.current_memory_type())
.field("installed_size", &self.installed_size())
.field("enabled_size", &self.enabled_size())
.field("error_status", &self.error_status())
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn unit_test() {
let struct_type6 = vec![
6,
0x0C,
0x0F, 0x00,
0x01,
0x01,
0b00000010,
0xA4, 0x00,
0x7D,
0x83,
0,
0x41, 0x31, 0x00,
0x00,
];
let parts = UndefinedStruct::new(&struct_type6);
let test_struct = SMBiosMemoryModuleInformation::new(&parts);
assert_eq!(test_struct.socket_designation(), Some("A1".to_string()));
assert_eq!(test_struct.bank_connections(), Some(0x01));
assert_eq!(test_struct.current_speed(), Some(0b00000010));
let memory_types = test_struct.current_memory_type().unwrap();
assert!(memory_types.standard());
assert!(memory_types.simm());
assert_eq!(test_struct.installed_size(), Some(0x7D));
assert_eq!(test_struct.enabled_size(), Some(0x83));
}
}