Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Implemented export (DUMP_MFU) and added "RANDOM UID" command to the a…
Browse files Browse the repository at this point in the history
…dvanced shell in the tools menu.
  • Loading branch information
maxieds committed Jan 15, 2018
1 parent c1f00e8 commit 1eb5c50
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<uses-feature android:name="android.hardware.usb.host" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import android.widget.SpinnerAdapter;
import android.widget.Switch;

import java.util.Random;

import static android.content.ContentValues.TAG;

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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"));
Expand Down
Binary file added app/src/main/res/drawable/export24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/exportarrow16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions app/src/main/res/layout/export_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:drawableLeft="@drawable/todo16"
android:drawableLeft="@drawable/exportarrow16"
android:drawablePadding="5dp"
android:singleLine="true"
android:text="TODO / wishlist features for later:"
android:text="Other Export Features: "
android:textSize="14sp"
android:textAllCaps="true"
android:textStyle="bold|italic" />
Expand All @@ -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">
Expand All @@ -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" />

<Button
style="@style/GridButtons"
android:drawableLeft="@drawable/idcard24"
android:tag="UPLOAD"
android:text="UPLOAD CARD" />
android:text="UPLOAD CARD (TODO)" />

</GridLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<item>TIMEOUT=</item>
<item>TIMEOUT=?</item>
<item>UID=</item>
<item>RANDOM UID</item>
</string-array>


Expand Down

0 comments on commit 1eb5c50

Please sign in to comment.