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

Commit

Permalink
Added new UID changing functionality. Fixed several bugs. Uploading o…
Browse files Browse the repository at this point in the history
…f card by XModem still not working correctly.
  • Loading branch information
maxieds committed Jan 23, 2018
1 parent bed7045 commit 2e22562
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ChameleonIO {
public static boolean DOWNLOAD = false;
public static boolean UPLOAD = false;
public static boolean EXPECTING_BINARY_DATA = false;
public static String LASTCMD = "";

/**
* Static storage for command return values.
Expand Down Expand Up @@ -146,8 +147,11 @@ public static SerialRespCode lookupByResponseCode(int rcode) {
*/
public static boolean isCommandResponse(byte[] liveLogData) {
String respText = new String(liveLogData).split("[\n\r]+")[0];
String[] respText2 = new String(liveLogData).split("=");
if(SerialRespCode.RESP_CODE_TEXT_MAP.get(respText) != null)
return true;
else if(respText2.length >= 2 && SerialRespCode.RESP_CODE_TEXT_MAP.get(LASTCMD.replace(respText2[1].substring(0, LiveLoggerActivity.USB_DATA_BITS), "")) != null)
return false;
return false;
}

Expand Down Expand Up @@ -225,7 +229,7 @@ public void updateAllStatusAndPost(boolean resetTimer) {
return;
boolean haveUpdates = updateAllStatus(resetTimer);
if(!haveUpdates)
return;
return;ChameleonIO.WAITING_FOR_RESPONSE = true;
((TextView) LiveLoggerActivity.runningActivity.findViewById(R.id.deviceConfigText)).setText(CONFIG);
String formattedUID = UID;
if(!UID.equals("NO UID."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class LiveLoggerActivity extends AppCompatActivity {
public static UsbSerialDevice serialPort;
public static final Semaphore serialPortLock = new Semaphore(1, true);
boolean usbReceiversRegistered = false;
public static final int USB_DATA_BITS = 16;

/**
* Appends a new log to the logging interface tab.
Expand Down Expand Up @@ -525,10 +526,11 @@ public void onResume() {
* @ref LiveLoggerActivity.usbReaderCallback
*/
public static String getSettingFromDevice(UsbSerialDevice cmPort, String query) {
ChameleonIO.WAITING_FOR_RESPONSE = true;
ChameleonIO.DEVICE_RESPONSE = "0";
ChameleonIO.LASTCMD = query;
if(cmPort == null)
return ChameleonIO.DEVICE_RESPONSE;
ChameleonIO.WAITING_FOR_RESPONSE = true;
ChameleonIO.SerialRespCode rcode = ChameleonIO.executeChameleonMiniCommand(cmPort, query, ChameleonIO.TIMEOUT);
for(int i = 0; i < ChameleonIO.TIMEOUT / 50; i++) {
if(!ChameleonIO.WAITING_FOR_RESPONSE)
Expand Down Expand Up @@ -582,7 +584,7 @@ public UsbSerialDevice configureSerialPort(UsbSerialDevice serialPort, UsbSerial
//serialPort.setBaudRate(115200);
serialPort.setBaudRate(256000);
//serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
serialPort.setDataBits(16); // slight optimization?
serialPort.setDataBits(USB_DATA_BITS); // slight optimization? ... yes, better
serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
serialPort.setParity(UsbSerialInterface.PARITY_NONE);
serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
Expand Down Expand Up @@ -621,6 +623,9 @@ public boolean closeSerialPort(UsbSerialDevice serialPort) {
ChameleonIO.DOWNLOAD = false;
ChameleonIO.UPLOAD = false;
ChameleonIO.WAITING_FOR_XMODEM = false;
ChameleonIO.WAITING_FOR_RESPONSE = false;
ChameleonIO.EXPECTING_BINARY_DATA = false;
ChameleonIO.LASTCMD = "";
setStatusIcon(R.id.statusIconUSB, R.drawable.usbdisconnected16);
return true;
}
Expand Down Expand Up @@ -1010,22 +1015,29 @@ public void actionButtonModifyUID(View view) {
if(ChameleonIO.deviceStatus.UID == null || ChameleonIO.deviceStatus.UID.equals("DEVICE UID") || ChameleonIO.deviceStatus.UID.equals("NO UID."))
return;
String uidAction = ((Button) view).getTag().toString();
int uid = Integer.parseInt(ChameleonIO.deviceStatus.UID, 16);
int uidSize = ChameleonIO.deviceStatus.UIDSIZE;
byte[] uid = Utils.hexString2Bytes(ChameleonIO.deviceStatus.UID);
int uidSize = uid.length - 1;
if(uidAction.equals("INCREMENT_RIGHT"))
uid += 1;
uid[uidSize] += (byte) 0x01;
else if(uidAction.equals("DECREMENT_RIGHT"))
uid -= 1;
else if(uidAction.equals("SHIFT_RIGHT"))
uid <<= 4;
uid[uidSize] -= (byte) 0x01;
else if(uidAction.equals("SHIFT_RIGHT")) {
byte[] nextUID = new byte[uid.length];
System.arraycopy(uid, 1, nextUID, 0, uid.length - 1);
uid = nextUID;
}
else if(uidAction.equals("INCREMENT_LEFT"))
uid += 0x80 << (8 * uidSize);
uid[0] += (byte) 0x80;
else if(uidAction.equals("DECREMENT_LEFT"))
uid -= 0x80 << (8 * uidSize);
else if(uidAction.equals("SHIFT_LEFT"))
uid >>>= 4;
getSettingFromDevice(serialPort, String.format(Locale.ENGLISH, "UID=%x"));
uid[0] -= (byte) 0x80;
else if(uidAction.equals("SHIFT_LEFT")){
byte[] nextUID = new byte[uid.length];
System.arraycopy(uid, 0, nextUID, 1, uid.length - 1);
uid = nextUID;
}
getSettingFromDevice(serialPort, String.format(Locale.ENGLISH, "UID=%s", Utils.bytes2Hex(uid).replace(" ", "")));
ChameleonIO.deviceStatus.updateAllStatusAndPost(false);
appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("UID", "Next device UID set to " + Utils.bytes2Hex(uid).replace(" ", ":")));
}

/**
Expand Down Expand Up @@ -1261,11 +1273,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public void actionButtonUploadCard(View view) {
if(serialPort == null)
return;
// fixes (should fix) a slight "bug" where the card uploads but fails to get transferred to the
// should potentially fix a slight "bug" where the card uploads but fails to get transferred to the
// running device profile due to differences in the current configuration's memsize setting.
// This might be more of a bug with the Chameleon software, but not entirely sure.
// Solution: Clear out the current setting slot to CONFIG=NONE before performing the upload:
getSettingFromDevice(serialPort, "CONFIG=NONE");
//getSettingFromDevice(serialPort, "CONFIG=NONE");

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/maxieds/chameleonminilivedebugger/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public static byte hexString2Byte(String byteStr) {
return (byte) (lsb | msb << 4);
}

// TODO: javadoc
public static byte[] hexString2Bytes(String byteStr) {
if (byteStr.length() % 2 != 0) { // left-pad the string:
byteStr = "0" + byteStr;
}
byte[] byteRep = new byte[byteStr.length() / 2];
for(int b = 0; b < byteStr.length(); b += 2)
byteRep[b / 2] = hexString2Byte(byteStr.substring(b, b + 2));
return byteRep;
}

/**
* Returns an ascii print character (or '.' representation for non-print characters) of the input byte.
* @param b
Expand Down

0 comments on commit 2e22562

Please sign in to comment.