@@ -28,6 +28,7 @@ enum Attributes {
28
28
ProductId = 4 ,
29
29
HwVer = 7 ,
30
30
SwVer = 9 ,
31
+ SwVerString = 0xa ,
31
32
SerialNo = 0x0f ,
32
33
}
33
34
@@ -37,64 +38,12 @@ pub struct BasicInfoConfig {
37
38
pub pid : u16 ,
38
39
pub hw_ver : u16 ,
39
40
pub sw_ver : u32 ,
41
+ pub sw_ver_str : String ,
40
42
pub serial_no : String ,
41
43
/// Device name; up to 32 characters
42
44
pub device_name : String ,
43
45
}
44
46
45
- fn attr_dm_rev_new ( ) -> Result < Attribute , Error > {
46
- Attribute :: new (
47
- Attributes :: DMRevision as u16 ,
48
- AttrValue :: Uint8 ( 1 ) ,
49
- Access :: RV ,
50
- Quality :: FIXED ,
51
- )
52
- }
53
-
54
- fn attr_vid_new ( vid : u16 ) -> Result < Attribute , Error > {
55
- Attribute :: new (
56
- Attributes :: VendorId as u16 ,
57
- AttrValue :: Uint16 ( vid) ,
58
- Access :: RV ,
59
- Quality :: FIXED ,
60
- )
61
- }
62
-
63
- fn attr_pid_new ( pid : u16 ) -> Result < Attribute , Error > {
64
- Attribute :: new (
65
- Attributes :: ProductId as u16 ,
66
- AttrValue :: Uint16 ( pid) ,
67
- Access :: RV ,
68
- Quality :: FIXED ,
69
- )
70
- }
71
-
72
- fn attr_hw_ver_new ( hw_ver : u16 ) -> Result < Attribute , Error > {
73
- Attribute :: new (
74
- Attributes :: HwVer as u16 ,
75
- AttrValue :: Uint16 ( hw_ver) ,
76
- Access :: RV ,
77
- Quality :: FIXED ,
78
- )
79
- }
80
-
81
- fn attr_sw_ver_new ( sw_ver : u32 ) -> Result < Attribute , Error > {
82
- Attribute :: new (
83
- Attributes :: SwVer as u16 ,
84
- AttrValue :: Uint32 ( sw_ver) ,
85
- Access :: RV ,
86
- Quality :: FIXED ,
87
- )
88
- }
89
-
90
- fn attr_serial_no_new ( label : String ) -> Result < Attribute , Error > {
91
- Attribute :: new (
92
- Attributes :: SerialNo as u16 ,
93
- AttrValue :: Utf8 ( label) ,
94
- Access :: RV ,
95
- Quality :: FIXED ,
96
- )
97
- }
98
47
pub struct BasicInfoCluster {
99
48
base : Cluster ,
100
49
}
@@ -104,14 +53,53 @@ impl BasicInfoCluster {
104
53
let mut cluster = Box :: new ( BasicInfoCluster {
105
54
base : Cluster :: new ( ID ) ?,
106
55
} ) ;
107
- cluster. base . add_attribute ( attr_dm_rev_new ( ) ?) ?;
108
- cluster. base . add_attribute ( attr_vid_new ( cfg. vid ) ?) ?;
109
- cluster. base . add_attribute ( attr_pid_new ( cfg. pid ) ?) ?;
110
- cluster. base . add_attribute ( attr_hw_ver_new ( cfg. hw_ver ) ?) ?;
111
- cluster. base . add_attribute ( attr_sw_ver_new ( cfg. sw_ver ) ?) ?;
112
- cluster
113
- . base
114
- . add_attribute ( attr_serial_no_new ( cfg. serial_no ) ?) ?;
56
+
57
+ let attrs = [
58
+ Attribute :: new (
59
+ Attributes :: DMRevision as u16 ,
60
+ AttrValue :: Uint8 ( 1 ) ,
61
+ Access :: RV ,
62
+ Quality :: FIXED ,
63
+ ) ?,
64
+ Attribute :: new (
65
+ Attributes :: VendorId as u16 ,
66
+ AttrValue :: Uint16 ( cfg. vid ) ,
67
+ Access :: RV ,
68
+ Quality :: FIXED ,
69
+ ) ?,
70
+ Attribute :: new (
71
+ Attributes :: ProductId as u16 ,
72
+ AttrValue :: Uint16 ( cfg. pid ) ,
73
+ Access :: RV ,
74
+ Quality :: FIXED ,
75
+ ) ?,
76
+ Attribute :: new (
77
+ Attributes :: HwVer as u16 ,
78
+ AttrValue :: Uint16 ( cfg. hw_ver ) ,
79
+ Access :: RV ,
80
+ Quality :: FIXED ,
81
+ ) ?,
82
+ Attribute :: new (
83
+ Attributes :: SwVer as u16 ,
84
+ AttrValue :: Uint32 ( cfg. sw_ver ) ,
85
+ Access :: RV ,
86
+ Quality :: FIXED ,
87
+ ) ?,
88
+ Attribute :: new (
89
+ Attributes :: SwVerString as u16 ,
90
+ AttrValue :: Utf8 ( cfg. sw_ver_str ) ,
91
+ Access :: RV ,
92
+ Quality :: FIXED ,
93
+ ) ?,
94
+ Attribute :: new (
95
+ Attributes :: SerialNo as u16 ,
96
+ AttrValue :: Utf8 ( cfg. serial_no ) ,
97
+ Access :: RV ,
98
+ Quality :: FIXED ,
99
+ ) ?,
100
+ ] ;
101
+ cluster. base . add_attributes ( & attrs[ ..] ) ?;
102
+
115
103
Ok ( cluster)
116
104
}
117
105
}
0 commit comments