@@ -259,6 +259,16 @@ public static TargetBoard getTargetBoard() {
259
259
return getTargetPlatform ().getBoard (boardId );
260
260
}
261
261
262
+ /**
263
+ * Returns a specific TargetPackage
264
+ *
265
+ * @param packageName
266
+ * @return
267
+ */
268
+ static public TargetPackage getTargetPackage (String packageName ) {
269
+ return packages .get (packageName );
270
+ }
271
+
262
272
/**
263
273
* Returns the currently selected TargetPlatform.
264
274
*
@@ -499,6 +509,62 @@ static public void prescanParameters(String args[]) {
499
509
PreferencesData .init (absoluteFile (preferencesFile ));
500
510
}
501
511
512
+ static protected void processBoardArgument (String selectBoard ) {
513
+ // No board selected? Nothing to do
514
+ if (selectBoard == null )
515
+ return ;
516
+
517
+ String [] split = selectBoard .split (":" , 4 );
518
+
519
+ if (split .length < 3 ) {
520
+ showError (null , I18n .format (_ ("{0}: Invalid board name, it should be of the form \" package:arch:board\" or \" package:arch:board:options\" " ), selectBoard ), 3 );
521
+ }
522
+
523
+ TargetPackage targetPackage = getTargetPackage (split [0 ]);
524
+ if (targetPackage == null ) {
525
+ showError (null , I18n .format (_ ("{0}: Unknown package" ), split [0 ]), 3 );
526
+ }
527
+
528
+ TargetPlatform targetPlatform = targetPackage .get (split [1 ]);
529
+ if (targetPlatform == null ) {
530
+ showError (null , I18n .format (_ ("{0}: Unknown architecture" ), split [1 ]), 3 );
531
+ }
532
+
533
+ TargetBoard targetBoard = targetPlatform .getBoard (split [2 ]);
534
+ if (targetBoard == null ) {
535
+ showError (null , I18n .format (_ ("{0}: Unknown board" ), split [2 ]), 3 );
536
+ }
537
+
538
+ selectBoard (targetBoard );
539
+
540
+ if (split .length > 3 ) {
541
+ String [] options = split [3 ].split ("," );
542
+ for (String option : options ) {
543
+ String [] keyValue = option .split ("=" , 2 );
544
+
545
+ if (keyValue .length != 2 )
546
+ showError (null , I18n .format (_ ("{0}: Invalid option, should be of the form \" name=value\" " ), option , targetBoard .getId ()), 3 );
547
+ String key = keyValue [0 ].trim ();
548
+ String value = keyValue [1 ].trim ();
549
+
550
+ if (!targetBoard .hasMenu (key ))
551
+ showError (null , I18n .format (_ ("{0}: Invalid option for board \" {1}\" " ), key , targetBoard .getId ()), 3 );
552
+ if (targetBoard .getMenuLabel (key , value ) == null )
553
+ showError (null , I18n .format (_ ("{0}: Invalid option for \" {1}\" option for board \" {2}\" " ), value , key , targetBoard .getId ()), 3 );
554
+
555
+ Preferences .set ("custom_" + key , targetBoard .getId () + "_" + value );
556
+ }
557
+ }
558
+ }
559
+
560
+ static protected void processPrefArgument (String arg ) {
561
+ String [] split = arg .split ("=" , 2 );
562
+ if (split .length != 2 || split [0 ].isEmpty ())
563
+ showError (null , I18n .format (_ ("{0}: Invalid argument to --pref, should be of the form \" pref=value\" " ), arg ), 3 );
564
+
565
+ PreferencesData .set (split [0 ], split [1 ]);
566
+ }
567
+
502
568
/**
503
569
* Recursively remove all files within a directory,
504
570
* used with removeDir(), or when the contents of a dir
@@ -649,6 +715,27 @@ static public LibraryList scanLibraries(File folder) throws IOException {
649
715
return res ;
650
716
}
651
717
718
+ static protected void selectBoard (TargetBoard targetBoard ) {
719
+ TargetPlatform targetPlatform = targetBoard .getContainerPlatform ();
720
+ TargetPackage targetPackage = targetPlatform .getContainerPackage ();
721
+
722
+ PreferencesData .set ("target_package" , targetPackage .getId ());
723
+ PreferencesData .set ("target_platform" , targetPlatform .getId ());
724
+ PreferencesData .set ("board" , targetBoard .getId ());
725
+
726
+ File platformFolder = targetPlatform .getFolder ();
727
+ PreferencesData .set ("runtime.platform.path" , platformFolder .getAbsolutePath ());
728
+ PreferencesData .set ("runtime.hardware.path" , platformFolder .getParentFile ().getAbsolutePath ());
729
+ }
730
+
731
+ public static void selectSerialPort (String port ) {
732
+ PreferencesData .set ("serial.port" , port );
733
+ if (port .startsWith ("/dev/" ))
734
+ PreferencesData .set ("serial.port.file" , port .substring (5 ));
735
+ else
736
+ PreferencesData .set ("serial.port.file" , port );
737
+ }
738
+
652
739
static public void showError (String title , String message , int exit_code ) {
653
740
showError (title , message , null , exit_code );
654
741
}
0 commit comments