@@ -190,39 +190,6 @@ class SerialConnection extends EventEmitter {
190
190
_eventHandler ( buffer ) {
191
191
const data = buffer . toString ( )
192
192
this . emit ( 'output' , data )
193
-
194
- // Getting data that should be sent to frontend
195
- // Loading file content, listing files, etc
196
- // if (data.indexOf('<REC>') !== -1) {
197
- // this.recordingData = true
198
- // }
199
- // if (this.recordingData) {
200
- // this.data += data
201
- // }
202
- // if (data.indexOf('<EOF>') !== -1) {
203
- // const iofREC = this.data.indexOf('<REC>')
204
- // const rec = this.data.indexOf('<REC>\r\n')+7
205
- // const eof = this.data.indexOf('<EOF>')
206
- // if (this.loadingFile) {
207
- // this.emit('file-loaded', this.data.slice(rec, eof))
208
- // this.loadingFile = false
209
- // }
210
- // if (this.loadingFileList) {
211
- // this.emit('file-list-loaded', this.data.slice(rec, eof))
212
- // this.loadingFileList = false
213
- // }
214
- // this.recordingData = false
215
- // }
216
-
217
- if ( this . rawRepl && data . indexOf ( '\n>>> ' ) != - 1 ) {
218
- this . emit ( 'execution-finished' )
219
- this . rawRepl = false
220
- }
221
-
222
- if ( ! this . rawRepl && data . indexOf ( 'raw REPL;' ) != - 1 ) {
223
- this . emit ( 'execution-started' )
224
- this . rawRepl = true
225
- }
226
193
}
227
194
/**
228
195
* Put REPL in raw mode
@@ -241,32 +208,21 @@ class SerialConnection extends EventEmitter {
241
208
* @param {String } command Command to be written on connected port
242
209
*/
243
210
_executeRaw ( command ) {
244
- const writePromise = ( buffer ) => {
245
- return new Promise ( ( resolve , reject ) => {
246
- setTimeout ( ( ) => {
247
- this . port . write ( buffer , ( err ) => {
248
- if ( err ) return reject ( )
249
- resolve ( )
250
- } )
251
- } , 1 )
252
- } )
253
- }
254
- const l = 1024
255
- let slices = [ ]
256
- for ( let i = 0 ; i < command . length ; i += l ) {
257
- let slice = command . slice ( i , i + l )
258
- slices . push ( slice )
259
- }
211
+ let p = 0
212
+ const l = 256
260
213
return new Promise ( ( resolve , reject ) => {
261
- slices . reduce ( ( cur , next ) => {
262
- return cur . then ( ( ) => {
263
- return writePromise ( next )
264
- } )
265
- } , Promise . resolve ( ) )
266
- . then ( )
267
- . then ( ( ) => {
214
+ for ( let i = 0 ; i < command . length ; i += l ) {
215
+ let slice = command . slice ( i , i + l )
216
+ setTimeout ( ( ) => {
217
+ this . port . write ( slice )
218
+ } , p * 10 )
219
+ p += 1
220
+ }
221
+ let finished = ( command . length / l ) + 1
222
+ setTimeout ( ( ) => {
223
+ this . port . write ( '\x04' )
268
224
resolve ( )
269
- } )
225
+ } , finished * 10 )
270
226
} )
271
227
}
272
228
}
0 commit comments