1010using System . Net . Security ;
1111using System . Security . Cryptography . X509Certificates ;
1212using System . Threading ;
13+ using System . Threading . Tasks ;
1314using System . Windows . Forms ;
1415
1516namespace BK7231Flasher
@@ -21,6 +22,7 @@ public partial class FormMain : Form, ILogListener
2122 int chosenBaudRate ;
2223 string chosenSourceFile ;
2324 FormCustom formCustom ;
25+ CancellationTokenSource cts ;
2426
2527 public FormMain ( )
2628 {
@@ -198,11 +200,14 @@ private void Form1_Load(object sender, EventArgs e)
198200 comboBoxChipType . Items . Add ( new ChipType ( BKType . RTL8710B , "RTL8710B" ) ) ;
199201 comboBoxChipType . Items . Add ( new ChipType ( BKType . RTL87X0C , "RTL87X0C" ) ) ;
200202 comboBoxChipType . Items . Add ( new ChipType ( BKType . RTL8720D , "RTL8720DN" ) ) ;
203+ //comboBoxChipType.Items.Add(new ChipType(BKType.RTL8721DA, "RTL8721DA"));
204+ //comboBoxChipType.Items.Add(new ChipType(BKType.RTL8720E, "RTL8720E"));
201205 comboBoxChipType . Items . Add ( new ChipType ( BKType . LN882H , "LN882H" ) ) ;
202206 comboBoxChipType . Items . Add ( new ChipType ( BKType . BL602 , "BL602" ) ) ;
203207 comboBoxChipType . Items . Add ( new ChipType ( BKType . ECR6600 , "ECR6600" ) ) ;
204208 comboBoxChipType . Items . Add ( new ChipType ( BKType . W800 , "W800" ) ) ;
205209 comboBoxChipType . Items . Add ( new ChipType ( BKType . W600 , "W600 (write)" ) ) ;
210+ comboBoxChipType . Items . Add ( new ChipType ( BKType . RDA5981 , "RDA5981" ) ) ;
206211 comboBoxChipType . Items . Add ( new ChipType ( BKType . BekenSPI , "Beken SPI CH341" ) ) ;
207212 comboBoxChipType . Items . Add ( new ChipType ( BKType . GenericSPI , "Generic SPI CH341" ) ) ;
208213
@@ -381,7 +386,7 @@ public void addLog(string s, Color col)
381386 // Singleton.buttonRead.Text = s;
382387 // });
383388 //}
384- Thread worker ;
389+ Task worker ;
385390 string getSelectedSerialName ( )
386391 {
387392 if ( comboBoxUART . SelectedIndex != - 1 )
@@ -416,7 +421,8 @@ bool interruptIfRequired()
416421 {
417422 if ( worker != null )
418423 {
419- worker . Abort ( ) ;
424+ cts ? . Cancel ( ) ;
425+ //worker.Abort();
420426 }
421427 worker = null ;
422428 //setButtonReadLabel(label_startRead);
@@ -473,7 +479,9 @@ void clearUp()
473479 {
474480 if ( flasher != null )
475481 {
476- flasher . closePort ( ) ;
482+ cts . Cancel ( ) ;
483+ flasher . Dispose ( ) ;
484+ //flasher.closePort();
477485 flasher = null ;
478486 }
479487 }
@@ -484,32 +492,37 @@ void createFlasher()
484492 {
485493 case BKType . RTL8710B :
486494 case BKType . RTL8720D :
487- flasher = new RTLFlasher ( ) ;
495+ case BKType . RTL8721DA :
496+ case BKType . RTL8720E :
497+ flasher = new RTLFlasher ( cts . Token ) ;
488498 break ;
489499 case BKType . RTL87X0C :
490- flasher = new RTLZ2Flasher ( ) ;
500+ flasher = new RTLZ2Flasher ( cts . Token ) ;
491501 break ;
492502 case BKType . LN882H :
493- flasher = new LN882HFlasher ( ) ;
503+ flasher = new LN882HFlasher ( cts . Token ) ;
494504 break ;
495505 case BKType . BL602 :
496- flasher = new BL602Flasher ( ) ;
506+ flasher = new BL602Flasher ( cts . Token ) ;
497507 break ;
498508 case BKType . BekenSPI :
499- flasher = new SPIFlasher_Beken ( ) ;
509+ flasher = new SPIFlasher_Beken ( cts . Token ) ;
500510 break ;
501511 case BKType . GenericSPI :
502- flasher = new SPIFlasher ( ) ;
512+ flasher = new SPIFlasher ( cts . Token ) ;
503513 break ;
504514 case BKType . ECR6600 :
505- flasher = new ECR6600Flasher ( ) ;
515+ flasher = new ECR6600Flasher ( cts . Token ) ;
506516 break ;
507517 case BKType . W600 :
508518 case BKType . W800 :
509- flasher = new WMFlasher ( ) ;
519+ flasher = new WMFlasher ( cts . Token ) ;
520+ break ;
521+ case BKType . RDA5981 :
522+ flasher = new RDAFlasher ( cts . Token ) ;
510523 break ;
511524 default :
512- flasher = new BK7231Flasher ( ) ;
525+ flasher = new BK7231Flasher ( cts . Token ) ;
513526 break ;
514527 }
515528 flasher . setBasic ( this , serialName , curType , chosenBaudRate ) ;
@@ -894,7 +907,7 @@ public bool checkFirmwareForCurType(string s)
894907 break ;
895908 case BKType . W600 :
896909 case BKType . W800 :
897- if ( s . StartsWith ( $ "Open{ curType } _") && s . EndsWith ( ".fls" ) )
910+ if ( s . StartsWith ( $ "Open{ curType } _") && ( s . EndsWith ( ".fls" ) || s . EndsWith ( ".bin" ) ) )
898911 {
899912 return true ;
900913 }
@@ -1390,16 +1403,20 @@ public void doCustomRead(CustomParms customRead)
13901403 startWorkerThread ( readThread , customRead ) ;
13911404 }
13921405
1393- void startWorkerThread ( ParameterizedThreadStart ts , object customArg )
1406+ void startWorkerThread ( Action < object > ts , object customArg )
13941407 {
1408+ cts ? . Dispose ( ) ;
1409+ cts = new CancellationTokenSource ( ) ;
13951410 setButtonStates ( false ) ;
1396- worker = new Thread ( ts ) ;
1397- worker . Start ( customArg ) ;
1411+ worker = new Task ( ts , customArg , cts . Token ) ;
1412+ worker . Start ( ) ;
13981413 }
1399- void startWorkerThread ( ThreadStart ts )
1414+ void startWorkerThread ( Action ts )
14001415 {
1416+ cts ? . Dispose ( ) ;
1417+ cts = new CancellationTokenSource ( ) ;
14011418 setButtonStates ( false ) ;
1402- worker = new Thread ( ts ) ;
1419+ worker = new Task ( ts , cts . Token ) ;
14031420 worker . Start ( ) ;
14041421 }
14051422 private void buttonStartScan_Click ( object sender , EventArgs e )
0 commit comments