more configurable debug log, disabled by default (#389)

pull/392/head
kai-morich 2021-09-26 07:52:49 +02:00
rodzic d319879386
commit 76f9198c02
3 zmienionych plików z 9 dodań i 2 usunięć

Wyświetl plik

@ -12,6 +12,7 @@ import android.net.Uri;
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;
@ -53,6 +54,7 @@ public class UsbWrapper implements SerialInputOutputManager.Listener {
this.serialDriver = serialDriver;
this.devicePort = devicePort;
serialPort = serialDriver.getPorts().get(devicePort);
CommonUsbSerialPort.DEBUG = true;
}
public void setUp() throws Exception {

Wyświetl plik

@ -26,6 +26,7 @@ import java.util.EnumSet;
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
@ -238,7 +239,9 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
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);

Wyświetl plik

@ -223,7 +223,9 @@ public class SerialInputOutputManager implements Runnable {
}
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];