@@ -455,9 +455,8 @@ private void handleIncomingIntent(Intent intent) {
455455 boolean isShareableApp = cursor .getColumnIndex (DocumentsContract .Document
456456 .COLUMN_DOCUMENT_ID ) != -1 ;
457457
458- fullPathOfFile = new File (Environment .getExternalStoragePublicDirectory (Environment
459- .DIRECTORY_DOWNLOADS ), selectedFileName ).getAbsolutePath ();
460-
458+ fullPathOfFile = new File (Environment .getExternalStoragePublicDirectory (Environment
459+ .DIRECTORY_DOWNLOADS ), selectedFileName ).getAbsolutePath ();
461460 if (isShareableApp ) {
462461 try {
463462 IOUtils .copy (getContentResolver ().openInputStream (uri ), new FileOutputStream (fullPathOfFile ));
@@ -513,7 +512,7 @@ private void handleIncomingIntent(Intent intent) {
513512
514513 private Project getLatestProjectFromFolder (long lengthOfSearchingFile ) {
515514 File downloadDirectory = Environment .getExternalStoragePublicDirectory (Environment
516- .DIRECTORY_DOWNLOADS );
515+ .DIRECTORY_DOWNLOADS );
517516
518517 FilenameFilter hexFilenameFilter = new FilenameFilter () {
519518 @ Override
@@ -1132,7 +1131,8 @@ int charToInt(char in) {
11321131 @ RequiresApi (api = Build .VERSION_CODES .O )
11331132 protected void startFlashing (int flashingType ) {
11341133
1135- logi (">>>>>>>>>>>>>>>>>>> startFlashing called >>>>>>>>>>>>>>>>>>> " );
1134+ logi (">>>>>>>>>>>>>>>>>>> startFlashing called >>>>>>>>>>>>>>>>>>> " );
1135+ Log .v (TAG , "startFlashing: " + flashingType );
11361136 //Reset all stats value
11371137 m_BinSizeStats = "0" ;
11381138 m_MicroBitFirmware = "0.0" ;
@@ -1310,6 +1310,8 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
13101310 ByteArrayOutputStream outputHex ;
13111311 outputHex = new ByteArrayOutputStream ();
13121312
1313+ ByteArrayOutputStream test = new ByteArrayOutputStream ();
1314+
13131315 FileOutputStream outputStream ;
13141316
13151317 int application_size = 0 ;
@@ -1328,6 +1330,7 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
13281330 i = fis .read (bs );
13291331
13301332 for (int b_x = 0 ; b_x < bs .length - 1 ; /* empty */ ) {
1333+
13311334 // Get record from following bytes
13321335 char b_type = (char ) bs [b_x + 8 ];
13331336
@@ -1358,12 +1361,16 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
13581361 ByteArrayOutputStream currentELA = new ByteArrayOutputStream ();
13591362 currentELA .write (bs , b_x , next );
13601363
1364+ uses_ESA = false ;
1365+
13611366 // If ELA has changed write
1362- if (!Arrays . equals ( currentELA .toByteArray (), lastELA .toByteArray ())) {
1367+ if (!currentELA .toString (). equals ( lastELA .toString ())) {
13631368 lastELA .reset ();
13641369 lastELA .write (bs , b_x , next );
1370+ Log .v (TAG , "TEST ELA " + lastELA .toString ());
13651371 outputHex .write (bs , b_x , next );
13661372 }
1373+
13671374 break ;
13681375 case '2' :
13691376 uses_ESA = true ;
@@ -1400,13 +1407,18 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
14001407 first_cr ++;
14011408 }
14021409
1410+ // Skip 1 word records
1411+ // TODO: Pad this record for uPY FS scratch
1412+ if (bs [b_x + 2 ] == '1' ) break ;
1413+
14031414 // Recalculate checksum
14041415 int checksum = (charToInt ((char ) bs [b_x + first_cr - 2 ]) * 16 ) + charToInt ((char ) bs [b_x + first_cr - 1 ]) + 0xD ;
14051416 String checksum_hex = Integer .toHexString (checksum );
14061417 checksum_hex = "00" + checksum_hex .toUpperCase (); // Pad to ensure we have 2 characters
14071418 checksum_hex = checksum_hex .substring (checksum_hex .length () - 2 );
14081419 bs [b_x + first_cr - 2 ] = (byte ) checksum_hex .charAt (0 );
14091420 bs [b_x + first_cr - 1 ] = (byte ) checksum_hex .charAt (1 );
1421+ case '3' :
14101422 case '5' :
14111423 case '0' :
14121424 // Copy record to hex
@@ -1427,7 +1439,6 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
14271439 int b_raddr = (charToInt ((char ) bs [b_x + 3 ]) << 12 ) | (charToInt ((char ) bs [b_x + 4 ]) << 8 ) | (charToInt ((char ) bs [b_x + 5 ]) << 4 ) | (charToInt ((char ) bs [b_x + 6 ]));
14281440 int b_addr = b_a | b_raddr ;
14291441
1430-
14311442 int lower_bound = 0 ; int upper_bound = 0 ;
14321443 if (hardwareType == MICROBIT_V1 ) { lower_bound = 0x18000 ; upper_bound = 0x38000 ; }
14331444 if (hardwareType == MICROBIT_V2 ) { lower_bound = 0x1C000 ; upper_bound = 0x77000 ; }
@@ -1438,9 +1449,13 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
14381449 }
14391450
14401451 if ((records_wanted || !is_fat ) && b_addr >= lower_bound && b_addr < upper_bound ) {
1452+
14411453 outputHex .write (bs , b_x , next );
14421454 // Add to app size
14431455 application_size = application_size + charToInt ((char ) bs [b_x + 1 ]) * 16 + charToInt ((char ) bs [b_x + 2 ]);
1456+ } else {
1457+ // Log.v(TAG, "TEST " + Integer.toHexString(b_addr) + " BA " + b_a + " LELA " + lastELA.toString() + " " + uses_ESA);
1458+ // test.write(bs, b_x, next);
14441459 }
14451460
14461461 break ;
@@ -1458,9 +1473,12 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
14581473 } else {
14591474 b_x = b_x + next ;
14601475 }
1476+
14611477 }
14621478
14631479 byte [] output = outputHex .toByteArray ();
1480+ byte [] testBytes = test .toByteArray ();
1481+
14641482 Log .v (TAG , "Finished parsing HEX. Writing application HEX for flashing" );
14651483
14661484 try {
0 commit comments