Permalink
Browse files

Changed format of platform ID. Updated ioio file format, tools, IOIO …

…manager BT, bootloader accordingly.
  • Loading branch information...
ytai committed Apr 24, 2011
1 parent 4feacb0 commit 8562b04f8b263dd6897f6ac230cfc402526a7b67
@@ -92,7 +92,7 @@ static BOOL IOIOFileBlockDone() {
void IOIOFileInit() {
ioio_file_buf_pos = 0;
- ioio_file_field_remaining = 12;
+ ioio_file_field_remaining = 8;
ioio_file_last_page = BOOTLOADER_INVALID_ADDRESS;
ioio_file_state = IOIO_FILE_STATE_WAIT_HEADER;
}
View
@@ -79,6 +79,25 @@
#error Unsupported target
#endif
+// platform ID:
+// the platform ID is what maintains compatibility between the application
+// firmware image and the board / bootloader.
+// any application firmware image is given a platform ID for which it was built,
+// similarly, the bootloader holds a platform ID uniquely designating its own
+// binary interface and the underlying hardware.
+// the bootloader will only attempt to install a firmware image with a matching
+// platform ID.
+// boards that are completely electrically equivalent and have the same pin
+// numbering scheme and the same bootloader interface, will have identical
+// platform IDs.
+#if IOIO_VER == 10
+ #define PLATFORM_ID "IOIO0000"
+#elif IOIO_VER >= 10 && IOIO_VER <= 12
+ #define PLATFORM_ID "IOIO0001"
+#elif IOIO_VER >= 13 && IOIO_VER <= 15
+ #define PLATFORM_ID "IOIO0002"
+#endif
+
#define FINGERPRINT_SIZE 16
#define MAX_PATH 64
@@ -256,7 +275,7 @@ int main() {
case MAIN_STATE_FIND_PATH_DONE:
fingerprint_size = 0;
strcpy(filepath, manager_path);
- strcat(filepath, "/files/image." BOARD_VARIANT_STRING ".fp");
+ strcat(filepath, "/files/" PLATFORM_ID ".fp");
f = ADBFileRead(filepath, &FileRecvFingerprint);
state = MAIN_STATE_WAIT_RECV_FP;
break;
@@ -278,7 +297,7 @@ int main() {
} else {
IOIOFileInit();
strcpy(filepath, manager_path);
- strcat(filepath, "/files/image." BOARD_VARIANT_STRING ".ioio");
+ strcat(filepath, "/files/" PLATFORM_ID ".ioio");
f = ADBFileRead(filepath, &FileRecvImage);
state = MAIN_STATE_WAIT_RECV_IMAGE;
}
View
@@ -69,23 +69,6 @@
#error Unknown board
#endif
-// board variants:
-// the board variant is what maintains compatibility between the application
-// firmware image and the board. when an application firmware has the same
-// designator as the board, it means that this firmware is intended to run on
-// this board version.
-// boards that are completely electrically equivalent and have the same pin
-// numbering scheme will have identical firmware variant designators.
-#if IOIO_VER == 10
- #define BOARD_VARIANT 0
-#elif IOIO_VER >= 10 && IOIO_VER <= 12
- #define BOARD_VARIANT 1
-#elif IOIO_VER >= 13 && IOIO_VER <= 15
- #define BOARD_VARIANT 2
-#endif
-
-#define BOARD_VARIANT_STRING _TOSTRING(BOARD_VARIANT)
-
#if defined(__PIC24FJ256DA206__) || defined(__PIC24FJ128DA106__) || defined(__PIC24FJ128DA206__)
#define NUM_PWM_MODULES 9
#define NUM_UART_MODULES 4
@@ -1,6 +1,5 @@
package ioio.manager;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -15,17 +14,19 @@
import android.util.Log;
public class BTThread extends Thread {
+ private static final String LOG_TAG = "BTThread";
public static final String ACTION_BT_CONNECTION = "ioio.manager.ACTION_BT_CONNECTION";
public static final String EXTRA_CONNECTED = "connected";
public static final String ACTION_BT_GOT_IMAGE = "ioio.manager.ACTION_BT_GOT_IMAGE";
+ public static final String EXTRA_FILENAME = "filename";
- private static final String FILENAME = "image";
- private static final String IMAGE_SUFFIX = "ioio";
- private static final String FINGERPRINT_SUFFIX = "fp";
+ private static final String IMAGE_SUFFIX = ".ioio";
+ private static final String FINGERPRINT_SUFFIX = ".fp";
public Handler mHandler;
private Context mContext;
private BluetoothServerSocket mServer;
+ private String mBaseFilename;
BTThread(Context context, BluetoothServerSocket server) {
mContext = context;
@@ -37,22 +38,23 @@ public void run() {
Intent intent = new Intent(ACTION_BT_CONNECTION);
intent.putExtra(EXTRA_CONNECTED, true);
mContext.sendStickyBroadcast(intent);
- while (true) {
- try {
- Log.i("BTThread", "Accepting");
+ try {
+ while (true) {
+ Log.i(LOG_TAG, "Accepting");
BluetoothSocket socket = mServer.accept();
- Log.i("BTThread", "Accepted");
+ Log.i(LOG_TAG, "Accepted");
copyToFile(socket);
createFingerprint();
- renameFilesByVariant();
- Log.i("BTThread", "Done");
- mContext.sendBroadcast(new Intent(ACTION_BT_GOT_IMAGE));
- } catch (Exception e) {
- if (e.getMessage().equals("Operation Canceled")) {
- break;
- } else {
- Log.e("BTThread", "Exception caught", e);
- }
+ Log.i(LOG_TAG, "Done");
+ Intent gotImageIntent = new Intent(ACTION_BT_GOT_IMAGE);
+ gotImageIntent.putExtra(EXTRA_FILENAME, mBaseFilename);
+ mContext.sendBroadcast(gotImageIntent);
+ }
+ } catch (Exception e) {
+ if (!e.getMessage().equals("Operation Canceled")) {
+ Log.e(LOG_TAG, "Exception caught", e);
+ mContext.deleteFile(IMAGE_SUFFIX);
+ mContext.deleteFile(FINGERPRINT_SUFFIX);
}
}
intent = new Intent(ACTION_BT_CONNECTION);
@@ -69,7 +71,11 @@ public void cancel() {
private void copyToFile(BluetoothSocket socket) throws IOException {
InputStream input = socket.getInputStream();
- OutputStream output = mContext.openFileOutput(FILENAME + "." + IMAGE_SUFFIX,
+ byte buf[] = new byte[8];
+ fillBufferFromInputStream(buf, input);
+ mBaseFilename = new String(buf);
+ String filename = mBaseFilename + IMAGE_SUFFIX;
+ OutputStream output = mContext.openFileOutput(filename,
Context.MODE_WORLD_READABLE);
byte[] b = new byte[1024];
try {
@@ -78,7 +84,9 @@ private void copyToFile(BluetoothSocket socket) throws IOException {
output.write(b, 0, i);
}
} catch (IOException e) {
- if (!e.getMessage().equals("Software caused connection abort")) {
+ if (e.getMessage().equals("Software caused connection abort")) {
+ Log.i(LOG_TAG, "Wrote image file: " + filename);
+ } else {
throw e;
}
} finally {
@@ -88,8 +96,9 @@ private void copyToFile(BluetoothSocket socket) throws IOException {
private void createFingerprint() throws IOException,
NoSuchAlgorithmException {
- InputStream in = mContext.openFileInput(FILENAME + "." + IMAGE_SUFFIX);
- OutputStream out = mContext.openFileOutput(FILENAME + "." + FINGERPRINT_SUFFIX,
+ InputStream in = mContext.openFileInput(mBaseFilename + IMAGE_SUFFIX);
+ String filename = mBaseFilename + FINGERPRINT_SUFFIX;
+ OutputStream out = mContext.openFileOutput(filename,
Context.MODE_WORLD_READABLE);
try {
MessageDigest digester = MessageDigest.getInstance("MD5");
@@ -100,33 +109,23 @@ private void createFingerprint() throws IOException,
}
byte[] digest = digester.digest();
out.write(digest);
+ Log.i(LOG_TAG, "Wrote fingerprint file: " + filename);
} finally {
in.close();
out.close();
}
}
- private void renameFilesByVariant() throws IOException {
- InputStream in = mContext.openFileInput(FILENAME + "." + IMAGE_SUFFIX);;
- byte[] buf = new byte[12];
- String variantName;
- try {
- if (in.read(buf) != 12) {
- throw new IOException("IOIO file is corrupt");
+ private void fillBufferFromInputStream(byte[] buffer, InputStream is)
+ throws IOException {
+ int pos = 0;
+ while (pos < buffer.length) {
+ int read = is.read(buffer, pos, buffer.length - pos);
+ if (read == -1) {
+ throw new IOException("Expected " + buffer.length
+ + " bytes, but got only " + pos);
}
- int variant = buf[11];
- variant = variant << 8 | buf[10];
- variant = variant << 8 | buf[9];
- variant = variant << 8 | buf[8];
- variantName = Integer.toString(variant);
- } finally {
- in.close();
+ pos += read;
}
- final File newImageFile = mContext.getFileStreamPath(FILENAME + "." + variantName + "." + IMAGE_SUFFIX);
- final File newFingerprintFile = mContext.getFileStreamPath(FILENAME + "." + variantName + "." + FINGERPRINT_SUFFIX);
- Log.i("BTThread", "Renaming files - start");
- new File(mContext.getFilesDir(), FILENAME + "." + IMAGE_SUFFIX).renameTo(newImageFile);
- new File(mContext.getFilesDir(), FILENAME + "." + FINGERPRINT_SUFFIX).renameTo(newFingerprintFile);
- Log.i("BTThread", "Renaming files - done");
}
}
Oops, something went wrong.

0 comments on commit 8562b04

Please sign in to comment.