Rihards Balass / 4DGL-mbed-32PTU
Revision:
15:86bdf382e6f7
Parent:
14:561cb06a2739
Child:
16:cb072eea16e9
--- a/Picaso_4DGL-32PTU_Media.cpp	Thu Sep 15 09:48:59 2016 +0000
+++ b/Picaso_4DGL-32PTU_Media.cpp	Thu Sep 15 11:52:31 2016 +0000
@@ -114,32 +114,34 @@
 
     char command[514] = "";
     bool success = false;
+    int j;
     
     command[0] = (MEDIA_WRITE_SECTOR >> (8*1)) & 0xff;
     command[1] = (MEDIA_WRITE_SECTOR >> (8*0)) & 0xff;
     
+#if DEBUGMODE
+    pc.printf("\n\r     DEBUG: string length = %i\n\r", strlen(block));
+#endif
     if (strlen(block) <= 512) {
-        int j = 513 - strlen(block);
+        j = 513 - strlen(block);
         for (int i = 0; i < strlen(block); i++) {
             command[j++] = block[i];
         }
         success = media_WrData(command, 514);
     }
     else { // data is bigger than one block
-        int j = 513 - (strlen(block) % 512); // set the first block pointer
+        j = 513 - (strlen(block) % 512); // set the first block pointer
         for (int i = 0; i < strlen(block); i++) {
             if (j == 513) {
                 success = media_WrData(command, 514);
                 #if DEBUGMODE
                     pc.printf("\n\r     DEBUG: Block send = %i", success);
+                    //if (success) puts("\n\r Sector send: OK");
+                    //else puts("\n\r Sector send: FAIL");
                 #endif
                 j = 2;
                 command[j++] = block[i];
             }
-            else if (i == (strlen(block) - 1)) {
-                command[j] = block[i];
-                success = media_WrData(command, 514);
-            }
             else command[j++] = block[i];
         }
     }
@@ -155,7 +157,7 @@
     }
     pc.printf("\n\r");
 #endif
-    writeCOMMAND(block, size);
+    writeCOMMAND_2(block, size);
     bool success = writeSectorResponse(3);
     return success;
 }