@@ -39,6 +39,14 @@ impl Packet for PacketV2 {
3939 } )
4040 }
4141
42+ fn reboot_packet ( id : u8 ) -> Box < dyn InstructionPacket < Self > > {
43+ Box :: new ( InstructionPacketV2 {
44+ id,
45+ instruction : InstructionKindV2 :: Reboot ,
46+ params : vec ! [ ] ,
47+ } )
48+ }
49+
4250 fn read_packet ( id : u8 , addr : u8 , length : u8 ) -> Box < dyn InstructionPacket < Self > > {
4351 Box :: new ( InstructionPacketV2 {
4452 id,
@@ -214,6 +222,7 @@ pub(crate) enum InstructionKindV2 {
214222 Ping ,
215223 Read ,
216224 Write ,
225+ Reboot ,
217226 SyncRead ,
218227 SyncWrite ,
219228}
@@ -224,6 +233,7 @@ impl InstructionKindV2 {
224233 InstructionKindV2 :: Ping => 0x01 ,
225234 InstructionKindV2 :: Read => 0x02 ,
226235 InstructionKindV2 :: Write => 0x03 ,
236+ InstructionKindV2 :: Reboot => 0x08 ,
227237 InstructionKindV2 :: SyncRead => 0x82 ,
228238 InstructionKindV2 :: SyncWrite => 0x83 ,
229239 }
@@ -310,6 +320,7 @@ mod tests {
310320
311321 assert_eq ! ( crc. to_le_bytes( ) , [ 0x16 , 0xd2 ] ) ;
312322 }
323+
313324 #[ test]
314325 fn create_ping_packet ( ) {
315326 let p = PacketV2 :: ping_packet ( 2 ) ;
@@ -320,6 +331,16 @@ mod tests {
320331 ) ;
321332 }
322333
334+ #[ test]
335+ fn create_reboot_packet ( ) {
336+ let p = PacketV2 :: reboot_packet ( 2 ) ;
337+ let bytes = p. to_bytes ( ) ;
338+ assert_eq ! (
339+ bytes,
340+ [ 0xff , 0xff , 0xfd , 0x0 , 0x2 , 0x3 , 0x0 , 0x8 , 0x2f , 0x72 ]
341+ ) ;
342+ }
343+
323344 #[ test]
324345 fn create_read_packet ( ) {
325346 let p = PacketV2 :: read_packet ( 1 , 0x2B , 2 ) ;
0 commit comments