Skip to content

Commit

Permalink
more configurable debug log, disabled by default (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
kai-morich committed Sep 26, 2021
1 parent d319879 commit 76f9198
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.util.Log;

import com.hoho.android.usbserial.driver.CdcAcmSerialDriver;
import com.hoho.android.usbserial.driver.CommonUsbSerialPort;
import com.hoho.android.usbserial.driver.UsbSerialDriver;
import com.hoho.android.usbserial.driver.UsbSerialPort;

Expand Down Expand Up @@ -53,6 +54,7 @@ public UsbWrapper(Context context, UsbSerialDriver serialDriver, int devicePort)
this.serialDriver = serialDriver;
this.devicePort = devicePort;
serialPort = serialDriver.getPorts().get(devicePort);
CommonUsbSerialPort.DEBUG = true;
}

public void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public abstract class CommonUsbSerialPort implements UsbSerialPort {

private static final String TAG = CommonUsbSerialPort.class.getSimpleName();
public static boolean DEBUG = false;
private static final int DEFAULT_WRITE_BUFFER_SIZE = 16 * 1024;
private static final int MAX_READ_SIZE = 16 * 1024; // = old bulkTransfer limit

Expand Down Expand Up @@ -238,7 +239,9 @@ public void write(final byte[] src, final int timeout) throws IOException {
actualLength = mConnection.bulkTransfer(mWriteEndpoint, writeBuffer, requestLength, requestTimeout);
}
}
Log.d(TAG, "Wrote " + actualLength + "/" + requestLength + " offset " + offset + "/" + src.length + " timeout " + requestTimeout);
if (DEBUG) {
Log.d(TAG, "Wrote " + actualLength + "/" + requestLength + " offset " + offset + "/" + src.length + " timeout " + requestTimeout);
}
if (actualLength <= 0) {
if (timeout != 0 && MonotonicClock.millis() >= endTime) {
SerialTimeoutException ex = new SerialTimeoutException("Error writing " + requestLength + " bytes at offset " + offset + " of total " + src.length + ", rc=" + actualLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ private void step() throws IOException {
}
int len = mSerialPort.read(buffer, mReadTimeout);
if (len > 0) {
if (DEBUG) Log.d(TAG, "Read data len=" + len);
if (DEBUG) {
Log.d(TAG, "Read data len=" + len);
}
final Listener listener = getListener();
if (listener != null) {
final byte[] data = new byte[len];
Expand Down

0 comments on commit 76f9198

Please sign in to comment.