@@ -7,11 +7,11 @@ use crate::{
77 command_impl:: reshuffle_apps:: PAGE_SIZE ,
88 connection:: { Connection , SerialConnection } ,
99 errors:: { InternalError , TockloaderError } ,
10- IOCommands ,
10+ IOCommands , IO ,
1111} ;
1212
1313#[ async_trait]
14- impl IOCommands for SerialConnection {
14+ impl IO for SerialConnection {
1515 async fn read ( & mut self , address : u64 , size : usize ) -> Result < Vec < u8 > , TockloaderError > {
1616 let mut pkt = ( address as u32 ) . to_le_bytes ( ) . to_vec ( ) ;
1717 let length = ( size as u16 ) . to_le_bytes ( ) . to_vec ( ) ;
@@ -30,34 +30,35 @@ impl IOCommands for SerialConnection {
3030 )
3131 . await ?;
3232
33- // this might be very specific, but when I was testing, i got 8191 bytes instead of 8192
34- // this is because of the consecutive ESCAPE_CHAR rule inside issue_command function
35-
3633 if appdata. len ( ) < size {
37- panic ! ( "Appdata was not read correctly?? We should not reach here" ) ;
34+ // Sanity check that we wrote everything. This was previously failing
35+ // due to not reading enough when encountering double ESCAPE_CHAR.
36+ panic ! ( "Internal Error: When reading from a Serial connection, we read less bytes than requested despite previous checks." ) ;
3837 }
3938 Ok ( appdata)
4039 }
4140
4241 async fn write ( & mut self , address : u64 , pkt : Vec < u8 > ) -> Result < ( ) , TockloaderError > {
4342 let stream = self . stream . as_mut ( ) . expect ( "Board must be open" ) ;
4443 let mut binary = pkt. clone ( ) ;
45- while !binary. len ( ) . is_multiple_of ( PAGE_SIZE as usize ) {
46- binary. push ( 0u8 ) ;
44+
45+ if !binary. len ( ) . is_multiple_of ( PAGE_SIZE as usize ) {
46+ binary. extend ( vec ! [
47+ 0u8 ;
48+ PAGE_SIZE as usize - ( binary. len( ) % PAGE_SIZE as usize )
49+ ] ) ;
4750 }
4851
49- let mut page_number = 0 ;
50- while ( page_number + 1 ) * PAGE_SIZE <= binary. len ( ) as u32 {
51- let mut pkt = ( address as u32 + page_number * PAGE_SIZE )
52+ for page_number in 0 ..( binary. len ( ) / PAGE_SIZE as usize ) {
53+ let mut pkt = ( address as u32 + page_number as u32 * PAGE_SIZE )
5254 . to_le_bytes ( )
5355 . to_vec ( ) ;
5456 pkt. append (
5557 & mut binary
56- [ ( page_number * PAGE_SIZE ) as usize ..( ( page_number + 1 ) * PAGE_SIZE ) as usize ]
58+ [ ( page_number * PAGE_SIZE as usize ) ..( ( page_number + 1 ) * PAGE_SIZE as usize ) ]
5759 . to_vec ( ) ,
5860 ) ;
5961 let _ = issue_command ( stream, Command :: WritePage , pkt, true , 0 , Response :: OK ) . await ?;
60- page_number += 1 ;
6162 }
6263
6364 let pkt = ( address as u32 + binary. len ( ) as u32 )
@@ -67,8 +68,11 @@ impl IOCommands for SerialConnection {
6768 let _ = issue_command ( stream, Command :: ErasePage , pkt, true , 0 , Response :: OK ) . await ?;
6869 Ok ( ( ) )
6970 }
71+ }
7072
71- async fn list_apps (
73+ #[ async_trait]
74+ impl IOCommands for SerialConnection {
75+ async fn read_installed_apps (
7276 & mut self ,
7377 settings : & BoardSettings ,
7478 ) -> Result < Vec < AppAttributes > , TockloaderError > {
0 commit comments