@@ -23,7 +23,7 @@ impl Messages {
2323 #[ inline( never) ]
2424 pub fn from_can_message ( id : u32 , payload : & [ u8 ] ) -> Result < Self , CanError > {
2525 use core:: convert:: TryFrom ;
26-
26+
2727 let res = match id {
2828 256 => Messages :: Foo ( Foo :: try_from ( payload) ?) ,
2929 512 => Messages :: Bar ( Bar :: try_from ( payload) ?) ,
@@ -46,15 +46,15 @@ pub struct Foo {
4646
4747impl Foo {
4848 pub const MESSAGE_ID : u32 = 256 ;
49-
49+
5050 /// Construct new Foo from values
5151 pub fn new ( voltage : f64 , current : f64 ) -> Result < Self , CanError > {
5252 let mut res = Self { raw : [ 0u8 ; 4 ] } ;
5353 res. set_voltage ( voltage) ?;
5454 res. set_current ( current) ?;
5555 Ok ( res)
5656 }
57-
57+
5858 /// Voltage
5959 ///
6060 /// - Min: 0
@@ -65,7 +65,7 @@ impl Foo {
6565 pub fn voltage ( & self ) -> f64 {
6666 self . voltage_raw ( )
6767 }
68-
68+
6969 /// Get raw value of Voltage
7070 ///
7171 /// - Start bit: 16
@@ -77,25 +77,25 @@ impl Foo {
7777 #[ inline( always) ]
7878 pub fn voltage_raw ( & self ) -> f64 {
7979 let signal = u16:: unpack_le_bits ( & self . raw , 16 , 16 ) ;
80-
80+
8181 let factor = 0.000976562_f64 ;
8282 let offset = 0_f64 ;
8383 ( signal as f64 ) * factor + offset
8484 }
85-
85+
8686 /// Set value of Voltage
8787 #[ inline( always) ]
8888 pub fn set_voltage ( & mut self , value : f64 ) -> Result < ( ) , CanError > {
8989 let factor = 0.000976562_f64 ;
9090 let offset = 0_f64 ;
9191 let value = ( ( value - offset) / factor) as u16 ;
92-
92+
9393 let start_bit = 16 ;
9494 let bits = 16 ;
9595 value. pack_le_bits ( & mut self . raw , start_bit, bits) ;
9696 Ok ( ( ) )
9797 }
98-
98+
9999 /// Current
100100 ///
101101 /// - Min: -2048
@@ -106,7 +106,7 @@ impl Foo {
106106 pub fn current ( & self ) -> f64 {
107107 self . current_raw ( )
108108 }
109-
109+
110110 /// Get raw value of Current
111111 ///
112112 /// - Start bit: 0
@@ -118,40 +118,40 @@ impl Foo {
118118 #[ inline( always) ]
119119 pub fn current_raw ( & self ) -> f64 {
120120 let signal = i16:: unpack_le_bits ( & self . raw , 0 , 16 ) ;
121-
121+
122122 let factor = 0.0625_f64 ;
123123 let offset = 0_f64 ;
124124 ( signal as f64 ) * factor + offset
125125 }
126-
126+
127127 /// Set value of Current
128128 #[ inline( always) ]
129129 pub fn set_current ( & mut self , value : f64 ) -> Result < ( ) , CanError > {
130130 let factor = 0.0625_f64 ;
131131 let offset = 0_f64 ;
132132 let value = ( ( value - offset) / factor) as i16 ;
133-
133+
134134 let start_bit = 0 ;
135135 let bits = 16 ;
136136 value. pack_le_bits ( & mut self . raw , start_bit, bits) ;
137137 Ok ( ( ) )
138138 }
139-
140139}
141140
142141impl core:: convert:: TryFrom < & [ u8 ] > for Foo {
143142 type Error = CanError ;
144-
143+
145144 #[ inline( always) ]
146145 fn try_from ( payload : & [ u8 ] ) -> Result < Self , Self :: Error > {
147- if payload. len ( ) != 4 { return Err ( CanError :: InvalidPayloadSize ) ; }
146+ if payload. len ( ) != 4 {
147+ return Err ( CanError :: InvalidPayloadSize ) ;
148+ }
148149 let mut raw = [ 0u8 ; 4 ] ;
149150 raw. copy_from_slice ( & payload[ ..4 ] ) ;
150151 Ok ( Self { raw } )
151152 }
152153}
153154
154-
155155/// Bar
156156///
157157/// - ID: 512 (0x200)
@@ -165,7 +165,7 @@ pub struct Bar {
165165
166166impl Bar {
167167 pub const MESSAGE_ID : u32 = 512 ;
168-
168+
169169 /// Construct new Bar from values
170170 pub fn new ( one : u8 , two : f64 , three : u8 , four : u8 ) -> Result < Self , CanError > {
171171 let mut res = Self { raw : [ 0u8 ; 8 ] } ;
@@ -175,7 +175,7 @@ impl Bar {
175175 res. set_four ( four) ?;
176176 Ok ( res)
177177 }
178-
178+
179179 /// One
180180 ///
181181 /// - Min: 0
@@ -186,7 +186,7 @@ impl Bar {
186186 pub fn one ( & self ) -> u8 {
187187 self . one_raw ( )
188188 }
189-
189+
190190 /// Get raw value of One
191191 ///
192192 /// - Start bit: 15
@@ -198,10 +198,10 @@ impl Bar {
198198 #[ inline( always) ]
199199 pub fn one_raw ( & self ) -> u8 {
200200 let signal = u8:: unpack_be_bits ( & self . raw , ( 15 - ( 2 - 1 ) ) , 2 ) ;
201-
201+
202202 signal
203203 }
204-
204+
205205 /// Set value of One
206206 #[ inline( always) ]
207207 pub fn set_one ( & mut self , value : u8 ) -> Result < ( ) , CanError > {
@@ -210,7 +210,7 @@ impl Bar {
210210 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
211211 Ok ( ( ) )
212212 }
213-
213+
214214 /// Two
215215 ///
216216 /// - Min: 0
@@ -221,7 +221,7 @@ impl Bar {
221221 pub fn two ( & self ) -> f64 {
222222 self . two_raw ( )
223223 }
224-
224+
225225 /// Get raw value of Two
226226 ///
227227 /// - Start bit: 7
@@ -233,25 +233,25 @@ impl Bar {
233233 #[ inline( always) ]
234234 pub fn two_raw ( & self ) -> f64 {
235235 let signal = u8:: unpack_be_bits ( & self . raw , ( 7 - ( 8 - 1 ) ) , 8 ) ;
236-
236+
237237 let factor = 0.39_f64 ;
238238 let offset = 0_f64 ;
239239 ( signal as f64 ) * factor + offset
240240 }
241-
241+
242242 /// Set value of Two
243243 #[ inline( always) ]
244244 pub fn set_two ( & mut self , value : f64 ) -> Result < ( ) , CanError > {
245245 let factor = 0.39_f64 ;
246246 let offset = 0_f64 ;
247247 let value = ( ( value - offset) / factor) as u8 ;
248-
248+
249249 let start_bit = 7 ;
250250 let bits = 8 ;
251251 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
252252 Ok ( ( ) )
253253 }
254-
254+
255255 /// Three
256256 ///
257257 /// - Min: 0
@@ -262,7 +262,7 @@ impl Bar {
262262 pub fn three ( & self ) -> u8 {
263263 self . three_raw ( )
264264 }
265-
265+
266266 /// Get raw value of Three
267267 ///
268268 /// - Start bit: 13
@@ -274,10 +274,10 @@ impl Bar {
274274 #[ inline( always) ]
275275 pub fn three_raw ( & self ) -> u8 {
276276 let signal = u8:: unpack_be_bits ( & self . raw , ( 13 - ( 3 - 1 ) ) , 3 ) ;
277-
277+
278278 signal
279279 }
280-
280+
281281 /// Set value of Three
282282 #[ inline( always) ]
283283 pub fn set_three ( & mut self , value : u8 ) -> Result < ( ) , CanError > {
@@ -286,7 +286,7 @@ impl Bar {
286286 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
287287 Ok ( ( ) )
288288 }
289-
289+
290290 /// Four
291291 ///
292292 /// - Min: 0
@@ -303,7 +303,7 @@ impl Bar {
303303 x => BarFour :: Other ( x) ,
304304 }
305305 }
306-
306+
307307 /// Get raw value of Four
308308 ///
309309 /// - Start bit: 10
@@ -315,10 +315,10 @@ impl Bar {
315315 #[ inline( always) ]
316316 pub fn four_raw ( & self ) -> u8 {
317317 let signal = u8:: unpack_be_bits ( & self . raw , ( 10 - ( 2 - 1 ) ) , 2 ) ;
318-
318+
319319 signal
320320 }
321-
321+
322322 /// Set value of Four
323323 #[ inline( always) ]
324324 pub fn set_four ( & mut self , value : u8 ) -> Result < ( ) , CanError > {
@@ -327,15 +327,16 @@ impl Bar {
327327 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
328328 Ok ( ( ) )
329329 }
330-
331330}
332331
333332impl core:: convert:: TryFrom < & [ u8 ] > for Bar {
334333 type Error = CanError ;
335-
334+
336335 #[ inline( always) ]
337336 fn try_from ( payload : & [ u8 ] ) -> Result < Self , Self :: Error > {
338- if payload. len ( ) != 8 { return Err ( CanError :: InvalidPayloadSize ) ; }
337+ if payload. len ( ) != 8 {
338+ return Err ( CanError :: InvalidPayloadSize ) ;
339+ }
339340 let mut raw = [ 0u8 ; 8 ] ;
340341 raw. copy_from_slice ( & payload[ ..8 ] ) ;
341342 Ok ( Self { raw } )
@@ -353,7 +354,6 @@ pub enum BarFour {
353354 Other ( u8 ) ,
354355}
355356
356-
357357/// This is just to make testing easier
358358fn main ( ) { }
359359
@@ -363,4 +363,3 @@ pub enum CanError {
363363 UnknownMessageId ( u32 ) ,
364364 InvalidPayloadSize ,
365365}
366-
0 commit comments