@@ -136,8 +136,8 @@ def getkey_callback(c):
136
136
self .main_task = asyncio .ensure_future (self .main_coro ())
137
137
138
138
async def send_frame (self , frame ):
139
- while retry :
140
- await self .port .write (frame .encode ())
139
+ while True :
140
+ await self .port .write_exactly (frame .encode ())
141
141
reply = await self .port .read (1 )
142
142
if reply == sfl_ack_success :
143
143
return
@@ -186,7 +186,7 @@ async def boot(self):
186
186
187
187
async def answer_magic (self ):
188
188
print ("[FLTERM] Received firmware download request from the device." )
189
- await self .port .write (sfl_magic_ack )
189
+ await self .port .write_exactly (sfl_magic_ack )
190
190
try :
191
191
await self .upload (self .kernel_image , self .kernel_address )
192
192
except FileNotFoundError :
@@ -212,21 +212,20 @@ async def main_coro(self):
212
212
await asyncio .wait ([f ])
213
213
214
214
if fs [0 ] in done :
215
- c = fs [0 ].result ()
216
- if c == b"\r " :
217
- sys .stdout .write (b"\n " )
218
- else :
219
- sys .stdout .buffer .write (c )
215
+ data = fs [0 ].result ()
216
+ sys .stdout .buffer .write (data )
220
217
sys .stdout .flush ()
221
218
219
+ if self .kernel_image is not None :
220
+ for c in data :
221
+ magic_detect_buffer = magic_detect_buffer [1 :] + bytes ([c ])
222
+ if magic_detect_buffer == sfl_magic_req :
223
+ await self .answer_magic ()
224
+ break
225
+
222
226
if fs [1 ] in done :
223
- c = fs [1 ].result ()
224
- await self .port .write (c )
227
+ await self .port .write (fs [1 ].result ())
225
228
226
- if self .kernel_image is not None :
227
- magic_detect_buffer = magic_detect_buffer [1 :] + c
228
- if magic_detect_buffer == sfl_magic_req :
229
- await self .answer_magic ()
230
229
231
230
async def close (self ):
232
231
deinit_getkey ()
0 commit comments