From 1eb5c503244720e6781456c9cc2b70b835722af2 Mon Sep 17 00:00:00 2001 From: maxieds Date: Sun, 14 Jan 2018 21:55:26 -0500 Subject: [PATCH] Implemented export (DUMP_MFU) and added "RANDOM UID" command to the advanced shell in the tools menu. --- .idea/misc.xml | 2 +- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 1 - .../ChameleonIO.java | 9 ++-- .../ExportTools.java | 42 +++++++++++++++++- .../LiveLoggerActivity.java | 16 +++++-- .../LogEntryMetadataRecord.java | 1 + .../TabFragment.java | 16 ++++++- app/src/main/res/drawable/export24.png | Bin 0 -> 583 bytes app/src/main/res/drawable/exportarrow16.png | Bin 0 -> 487 bytes app/src/main/res/layout/export_tab.xml | 9 ++-- app/src/main/res/values/strings.xml | 1 + 12 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 app/src/main/res/drawable/export24.png create mode 100644 app/src/main/res/drawable/exportarrow16.png diff --git a/.idea/misc.xml b/.idea/misc.xml index 75dac50..3963879 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index a7d4e5e..a02fca9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.maxieds.chameleonminilivedebugger" minSdkVersion 21 targetSdkVersion 25 - versionCode 14 - versionName "0.1.6" + versionCode 15 + versionName "0.1.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7cc92cb..124688b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,6 @@ - diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java index cb63132..17d3b98 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ChameleonIO.java @@ -24,16 +24,17 @@ public class ChameleonIO { private static final String TAG = ChameleonIO.class.getSimpleName(); - public static final int RESP_BUFFER_SIZE = 1024; - public static final int TIMEOUT = 1500; + public static final int TIMEOUT = 2000; public static boolean PAUSED = true; public static boolean WAITING_FOR_RESPONSE = false; public static boolean DOWNLOAD = false; + public static boolean EXPECTING_BINARY_DATA = false; public static final int CMUSB_VENDORID = 0x16d0; public static final int CMUSB_PRODUCTID = 0x04b2; - public static final String DEVICE_RESPONSE_INTENT = "ChameleonIO.device.CMD_QUERY_RESPONSE"; - public static String DEVICE_RESPONSE; public static String DEVICE_RESPONSE_CODE; + public static String DEVICE_RESPONSE; + public static byte[] DEVICE_RESPONSE_BINARY; + public enum SerialRespCode { diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ExportTools.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ExportTools.java index 0ee6061..4579116 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ExportTools.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ExportTools.java @@ -88,7 +88,7 @@ public void run() { outfile.getAbsolutePath(), outfile.length(), true); String statusMsg = "Write internal log data to file " + outfile.getName() + "(+" + fileSize + " / " + outfile.length() + " bytes).\n"; statusMsg += "If you are not seeing the expected output, try running the LOGSTORE command from the tools menu first."; - LiveLoggerActivity.appendNewLog(new LogEntryMetadataRecord(LiveLoggerActivity.defaultInflater, "NEW EVENT", statusMsg)); + LiveLoggerActivity.appendNewLog(new LogEntryMetadataRecord(LiveLoggerActivity.defaultInflater, "EXPORT", statusMsg)); if (throwToLive) { throwDeviceLogDataToLive(outfile); } @@ -292,4 +292,44 @@ public static boolean writeBinaryLogFile(File fd) throws Exception { return true; } + public static boolean saveBinaryDumpMFU(String filePathPrefix) { + LiveLoggerActivity.runningActivity.setStatusIcon(R.id.statusIconUlDl, R.drawable.statusdownload16); + String mimeType = "application/octet-stream"; + String outfilePath = filePathPrefix + Utils.getTimestamp().replace(":", "") + ".bin"; + File downloadsFolder = new File("//sdcard//Download//"); + outfile = new File(downloadsFolder, outfilePath); + boolean docsFolderExists = true; + if (!downloadsFolder.exists()) { + docsFolderExists = downloadsFolder.mkdir(); + } + if (docsFolderExists) { + outfile = new File(downloadsFolder.getAbsolutePath(),outfilePath); + } + else { + LiveLoggerActivity.appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("ERROR", "Unable to save output in Downloads folder.")); + LiveLoggerActivity.runningActivity.setStatusIcon(R.id.statusIconUlDl, R.drawable.statusxferfailed16); + return false; + } + try { + outfile.createNewFile(); + FileOutputStream fout = new FileOutputStream(outfile); + ChameleonIO.EXPECTING_BINARY_DATA = true; + LiveLoggerActivity.getSettingFromDevice(LiveLoggerActivity.serialPort, "DUMP_MFU"); + fout.write(ChameleonIO.DEVICE_RESPONSE_BINARY); + fout.flush(); + fout.close(); + } catch(Exception ioe) { + LiveLoggerActivity.appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("ERROR", ioe.getMessage())); + LiveLoggerActivity.runningActivity.setStatusIcon(R.id.statusIconUlDl, R.drawable.statusxferfailed16); + ioe.printStackTrace(); + return false; + } + DownloadManager downloadManager = (DownloadManager) LiveLoggerActivity.defaultContext.getSystemService(DOWNLOAD_SERVICE); + downloadManager.addCompletedDownload(outfile.getName(), outfile.getName(), true, mimeType, + outfile.getAbsolutePath(), outfile.length(),true); + String statusMsg = "Dumped MFU binary data to " + outfilePath + " (" + String.valueOf(outfile.length()) + " bytes)."; + LiveLoggerActivity.appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("EXPORT", statusMsg)); + return true; + } + } diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java index eef0837..0d498c9 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java @@ -173,7 +173,6 @@ public void onPageScrollStateChanged(int state) {} String[] permissions = { "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", - "android.permission.INTERNET", "com.android.example.USB_PERMISSION" }; if(android.os.Build.VERSION.SDK_INT >= 23) @@ -224,7 +223,6 @@ public static String getSettingFromDevice(UsbSerialDevice cmPort, String query) break; } } - //appendNewLog(new LogEntryMetadataRecord(defaultInflater, "INFO: Device query of " + query + " returned status " + ChameleonIO.DEVICE_RESPONSE_CODE, ChameleonIO.DEVICE_RESPONSE)); return ChameleonIO.DEVICE_RESPONSE; } @@ -307,7 +305,13 @@ else if(ChameleonIO.WAITING_FOR_RESPONSE && ChameleonIO.isCommandResponse(liveLo String strLogData = new String(liveLogData); Log.i(TAG, strLogData); ChameleonIO.DEVICE_RESPONSE_CODE = strLogData.split("[\n\r]+")[0]; - ChameleonIO.DEVICE_RESPONSE = strLogData.replace(ChameleonIO.DEVICE_RESPONSE_CODE, "").replaceAll("[\n\r\t]*", ""); + ChameleonIO.DEVICE_RESPONSE = strLogData.replace(ChameleonIO.DEVICE_RESPONSE_CODE, "").replaceAll("[\n\r]*", ""); + if(ChameleonIO.EXPECTING_BINARY_DATA) { + int binaryBufSize = liveLogData.length - ChameleonIO.DEVICE_RESPONSE_CODE.length() - 2; + ChameleonIO.DEVICE_RESPONSE_BINARY = new byte[binaryBufSize]; + System.arraycopy(liveLogData, liveLogData.length - binaryBufSize, ChameleonIO.DEVICE_RESPONSE_BINARY, 0, binaryBufSize); + ChameleonIO.EXPECTING_BINARY_DATA = false; + } ChameleonIO.WAITING_FOR_RESPONSE = false; return; } @@ -683,7 +687,11 @@ else if (fileType.equals("bin")) { i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(i, "Share the file ... ")); } - appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("STATUS", "Saved log file to \"" + outfilePath + "\".")); + appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("EXPORT", "Saved log file to \"" + outfilePath + "\".")); + } + + public void actionButtonDumpMFU(View view) { + ExportTools.saveBinaryDumpMFU("mfultralight"); } public static void actionSpinnerSetCommand(View view) { diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java index 8953589..50e0e82 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java @@ -70,6 +70,7 @@ public View getLayoutContainer() { prefixIconMap.put("ONCLICK", R.drawable.powaction24); prefixIconMap.put("IDENTIFY", R.drawable.find24); prefixIconMap.put("PRINT", R.drawable.dotdotdotbubble24); + prefixIconMap.put("EXPORT", R.drawable.export24); } public static LogEntryMetadataRecord createDefaultEventRecord(String eventID, String eventMsg) { diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java index 730d038..2d26121 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java @@ -16,6 +16,8 @@ import android.widget.SpinnerAdapter; import android.widget.Switch; +import java.util.Random; + import static android.content.ContentValues.TAG; /** @@ -108,7 +110,7 @@ public void onItemSelected(AdapterView adapterView, View view, int i, long l) if(setCmd.charAt(0) != '-') { String userInputBytes = ((EditText) LiveLoggerActivity.runningActivity.findViewById(R.id.userInputFormattedBytes)).getText().toString(); userInputBytes = userInputBytes.replace(" ", "").replace(":", "").replace("-", ""); // remove pretty printing / spaces formatting - boolean errorFlag = false; + boolean errorFlag = false, resetStatus = false; if(setCmd.equals("UID=") && (!Utils.stringIsHexadecimal(userInputBytes) || userInputBytes.length() != 2 * ChameleonIO.deviceStatus.UIDSIZE)) { errorFlag = true; } @@ -120,10 +122,22 @@ else if((setCmd.equals("THRESHOLD=") || setCmd.equals("TIMEOUT=")) && !Utils.str } else if(setCmd.equals("UID=") || setCmd.equals("SETTING=") || setCmd.equals("THRESHOLD=") || setCmd.equals("TIMEOUT=")) { setCmd += userInputBytes; + resetStatus = true; + } + else if(setCmd.equals("RANDOM UID")) { + int uidNumBytes = ChameleonIO.deviceStatus.UIDSIZE; + Random rnGen = new Random(System.currentTimeMillis()); + byte[] randomBytes = new byte[uidNumBytes]; + for(int b = 0; b < uidNumBytes; b++) + randomBytes[b] = (byte) rnGen.nextInt(0xff); + setCmd = "UID=" + Utils.bytes2Hex(randomBytes).replace(" ", ""); + resetStatus = true; } if(!errorFlag) { String deviceSetting = LiveLoggerActivity.getSettingFromDevice(LiveLoggerActivity.serialPort, setCmd); LiveLoggerActivity.appendNewLog(new LogEntryMetadataRecord(LiveLoggerActivity.defaultInflater, "INFO: Shell command of " + setCmd + " returned status " + ChameleonIO.DEVICE_RESPONSE_CODE, ChameleonIO.DEVICE_RESPONSE)); + if(resetStatus) + ChameleonIO.deviceStatus.updateAllStatusAndPost(false); } else { LiveLoggerActivity.appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("ERROR", "Command formatting error: the input user bytes are invalid or not of the correct length")); diff --git a/app/src/main/res/drawable/export24.png b/app/src/main/res/drawable/export24.png new file mode 100644 index 0000000000000000000000000000000000000000..57c9d905841632db8ce62521e3c13f200c6bd59a GIT binary patch literal 583 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1mUKs7M+SzC{oH>NS%G|oWRD45bDP46hOx7_4S6Fo+k-*%fF5lweBoc6VW5Sk5Uj7}P}D}aLRC7!;n?2j1vndNmWW*n_$U|g~O;XUhs1z;ogXPk>wU4&t<_6Vpuohm|7TL;qXGefU6z4AnFC`By#Zy~m ztlVk5{o}6F#R+Xc&;OTwcCR?$y;E`ROOcZk5}f9%1&hu}ZuvQz+e_=W+lJ`M*Z;k( z-XB@|s!K&NZ^nhRmwHo|z6(3|_WOhtsXR9v+#2LBUf98+kd*CyXLsWgh8iw^^-D?x zXIB<6#IkFAa*5!S`EPQT%Y9B#LIL{$PBu2?g}WB=1c)wayYl@^aklt{Vov^f&F5?m zXio~con-#A!Q6Ar?_0jd9Fv|bUCXucL2I-9yH(7NyX>+RpU*08aGqDbsXnl9+tvf3 znkDx)o_%pSX@Si9`XlB?KW^V5JH>uJFw9g-Tq8mmtT}V`<;yxP!WTttDnm{r-UW|yWP@o literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/exportarrow16.png b/app/src/main/res/drawable/exportarrow16.png new file mode 100644 index 0000000000000000000000000000000000000000..a51bfa111ffb8cc16b141a60793ed6af3aed253e GIT binary patch literal 487 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1O92wCOqsGdgL^t^f+Mmw5WRvOi+vXJ+J_a7zv-&#=|g#W6(VeD4HXKE^hJn%(_?1i&TE;kxOJp!u3KdK#@EkEb>-QQ22%wx7+ z62SA~Nz6GH4u=jApA4CIS2&AgYUC^!l6s7~zAycL$d_@t$jQc!$8R1^OlQ_^(e0Jk zVd!$xp=KQ$B1bz`zfB02EnMU@ zThF_tA=1&kuxtINAL06sLVQFdociwrJ)m0R8c~vxSdwa$T$Bo=7>o=IEp!bGbq!5J z42-P|46O_-wLzr8H11QtFhtUjo1c=IR*74~^ROZdpaw~h4Z-BuF?hQAxvX @@ -174,7 +174,7 @@ android:layout_height="wrap_content" android:layout_margin="4dp" android:background="@color/colorAccentLog" - android:columnCount="13" + android:columnCount="2" android:orientation="horizontal" android:padding="2dp" android:rowCount="1"> @@ -183,13 +183,14 @@ style="@style/GridButtons" android:drawableLeft="@drawable/dumpmfuchip24" android:tag="DUMP_MFU" + android:onClick="actionButtonDumpMFU" android:text="Dump MFU Tag to Bin" />