@@ -61,7 +61,7 @@ const MSP = {
61
61
62
62
JUMBO_FRAME_SIZE_LIMIT : 255 ,
63
63
64
- read : function ( readInfo ) {
64
+ read ( readInfo ) {
65
65
if ( CONFIGURATOR . virtualMode ) {
66
66
return ;
67
67
}
@@ -209,11 +209,11 @@ const MSP = {
209
209
}
210
210
this . last_received_timestamp = Date . now ( ) ;
211
211
} ,
212
- _initialize_read_buffer : function ( ) {
212
+ _initialize_read_buffer ( ) {
213
213
this . message_buffer = new ArrayBuffer ( this . message_length_expected ) ;
214
214
this . message_buffer_uint8_view = new Uint8Array ( this . message_buffer ) ;
215
215
} ,
216
- _dispatch_message : function ( expectedChecksum ) {
216
+ _dispatch_message ( expectedChecksum ) {
217
217
if ( this . message_checksum === expectedChecksum ) {
218
218
// message received, store dataview
219
219
this . dataView = new DataView ( this . message_buffer , 0 , this . message_length_expected ) ;
@@ -229,21 +229,20 @@ const MSP = {
229
229
this . messageIsJumboFrame = false ;
230
230
this . crcError = false ;
231
231
} ,
232
- notify : function ( ) {
233
- const self = this ;
234
- self . listeners . forEach ( function ( listener ) {
235
- listener ( self ) ;
232
+ notify ( ) {
233
+ this . listeners . forEach ( ( listener ) => {
234
+ listener ( this ) ;
236
235
} ) ;
237
236
} ,
238
- listen : function ( listener ) {
237
+ listen ( listener ) {
239
238
if ( this . listeners . indexOf ( listener ) == - 1 ) {
240
239
this . listeners . push ( listener ) ;
241
240
}
242
241
} ,
243
- clearListeners : function ( ) {
242
+ clearListeners ( ) {
244
243
this . listeners = [ ] ;
245
244
} ,
246
- crc8_dvb_s2 : function ( crc , ch ) {
245
+ crc8_dvb_s2 ( crc , ch ) {
247
246
crc ^= ch ;
248
247
for ( let ii = 0 ; ii < 8 ; ii ++ ) {
249
248
if ( crc & 0x80 ) {
@@ -254,14 +253,14 @@ const MSP = {
254
253
}
255
254
return crc ;
256
255
} ,
257
- crc8_dvb_s2_data : function ( data , start , end ) {
256
+ crc8_dvb_s2_data ( data , start , end ) {
258
257
let crc = 0 ;
259
258
for ( let ii = start ; ii < end ; ii ++ ) {
260
259
crc = this . crc8_dvb_s2 ( crc , data [ ii ] ) ;
261
260
}
262
261
return crc ;
263
262
} ,
264
- encode_message_v1 : function ( code , data ) {
263
+ encode_message_v1 ( code , data ) {
265
264
const dataLength = data ? data . length : 0 ;
266
265
// always reserve 6 bytes for protocol overhead !
267
266
const bufferSize = dataLength + 6 ;
@@ -284,7 +283,7 @@ const MSP = {
284
283
bufView [ 5 + dataLength ] = checksum ;
285
284
return bufferOut ;
286
285
} ,
287
- encode_message_v2 : function ( code , data ) {
286
+ encode_message_v2 ( code , data ) {
288
287
const dataLength = data ? data . length : 0 ;
289
288
// 9 bytes for protocol overhead
290
289
const bufferSize = dataLength + 9 ;
@@ -304,7 +303,7 @@ const MSP = {
304
303
bufView [ bufferSize - 1 ] = this . crc8_dvb_s2_data ( bufView , 3 , bufferSize - 1 ) ;
305
304
return bufferOut ;
306
305
} ,
307
- send_message : function ( code , data , callback_sent , callback_msp , doCallbackOnError ) {
306
+ send_message ( code , data , callback_sent , callback_msp , doCallbackOnError ) {
308
307
if ( code === undefined || ! serial . connectionId || CONFIGURATOR . virtualMode ) {
309
308
if ( callback_msp ) {
310
309
callback_msp ( ) ;
@@ -314,7 +313,7 @@ const MSP = {
314
313
315
314
// Check if request already exists in the queue
316
315
let requestExists = false ;
317
- for ( const instance of MSP . callbacks ) {
316
+ for ( const instance of this . callbacks ) {
318
317
if ( instance . code === code ) {
319
318
requestExists = true ;
320
319
@@ -333,25 +332,25 @@ const MSP = {
333
332
} ;
334
333
335
334
if ( ! requestExists ) {
336
- obj . timer = setTimeout ( function ( ) {
337
- console . warn ( `MSP: data request timed-out: ${ code } ID: ${ serial . connectionId } TAB: ${ GUI . active_tab } TIMEOUT: ${ MSP . timeout } QUEUE: ${ MSP . callbacks . length } (${ MSP . callbacks . map ( function ( e ) { return e . code ; } ) } )` ) ;
338
- serial . send ( bufferOut , function ( _sendInfo ) {
335
+ obj . timer = setTimeout ( ( ) => {
336
+ console . warn ( `MSP: data request timed-out: ${ code } ID: ${ serial . connectionId } TAB: ${ GUI . active_tab } TIMEOUT: ${ this . timeout } QUEUE: ${ this . callbacks . length } (${ this . callbacks . map ( ( e ) => e . code ) } )` ) ;
337
+ serial . send ( bufferOut , ( _sendInfo ) => {
339
338
obj . stop = performance . now ( ) ;
340
339
const executionTime = Math . round ( obj . stop - obj . start ) ;
341
- MSP . timeout = Math . max ( MSP . MIN_TIMEOUT , Math . min ( executionTime , MSP . MAX_TIMEOUT ) ) ;
340
+ this . timeout = Math . max ( this . MIN_TIMEOUT , Math . min ( executionTime , this . MAX_TIMEOUT ) ) ;
342
341
} ) ;
343
- } , MSP . timeout ) ;
342
+ } , this . timeout ) ;
344
343
}
345
344
346
- MSP . callbacks . push ( obj ) ;
345
+ this . callbacks . push ( obj ) ;
347
346
348
347
// always send messages with data payload (even when there is a message already in the queue)
349
348
if ( data || ! requestExists ) {
350
- if ( MSP . timeout > MSP . MIN_TIMEOUT ) {
351
- MSP . timeout -- ;
349
+ if ( this . timeout > this . MIN_TIMEOUT ) {
350
+ this . timeout -- ;
352
351
}
353
352
354
- serial . send ( bufferOut , function ( sendInfo ) {
353
+ serial . send ( bufferOut , ( sendInfo ) => {
355
354
if ( sendInfo . bytesSent === bufferOut . byteLength ) {
356
355
if ( callback_sent ) {
357
356
callback_sent ( ) ;
@@ -366,23 +365,21 @@ const MSP = {
366
365
/**
367
366
* resolves: {command: code, data: data, length: message_length}
368
367
*/
369
- promise : async function ( code , data ) {
370
- const self = this ;
371
-
372
- return new Promise ( function ( resolve ) {
373
- self . send_message ( code , data , false , function ( _data ) {
368
+ async promise ( code , data ) {
369
+ return new Promise ( ( resolve ) => {
370
+ this . send_message ( code , data , false , ( _data ) => {
374
371
resolve ( _data ) ;
375
372
} ) ;
376
373
} ) ;
377
374
} ,
378
- callbacks_cleanup : function ( ) {
375
+ callbacks_cleanup ( ) {
379
376
for ( const callback of this . callbacks ) {
380
377
clearInterval ( callback . timer ) ;
381
378
}
382
379
383
380
this . callbacks = [ ] ;
384
381
} ,
385
- disconnect_cleanup : function ( ) {
382
+ disconnect_cleanup ( ) {
386
383
this . state = 0 ; // reset packet state for "clean" initial entry (this is only required if user hot-disconnects)
387
384
this . packet_error = 0 ; // reset CRC packet error counter for next session
388
385
0 commit comments