Pebble: support fetching debug logs

Those are only displayed in logcat. And really disappointng

Guess I need to build a debug firmware to figure out why this is so.
This commit is contained in:
Andreas Shimokawa
2025-11-03 12:13:06 +01:00
parent fd2627caee
commit da7c7181f1
4 changed files with 50 additions and 7 deletions
@@ -190,6 +190,11 @@ public class PebbleCoordinator extends AbstractBLClassicDeviceCoordinator {
return true;
}
@Override
public boolean supportsDebugLogs(@NonNull GBDevice device) {
return true;
}
@Override
public DeviceSpecificSettings getDeviceSpecificSettings(final GBDevice device) {
final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings();
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -65,6 +66,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec.Action;
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.model.weather.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.weather.WeatherMapper;
@@ -733,6 +735,26 @@ public class PebbleProtocol extends GBDeviceProtocol {
return encodeSimpleMessage(ENDPOINT_DATALOG, DATALOG_REPORTSESSIONS);
}
@Override
public byte[] encodeFetchRecordedData(int dataTypes) {
if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) {
return encodeRequestLogDump(0, 0);
}
return null;
}
byte[] encodeRequestLogDump(int generation, int cookie) {
final short LENGTH_REQUEST_LOGDUMP = 5;
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REQUEST_LOGDUMP);
buf.order(ByteOrder.BIG_ENDIAN);
buf.putShort(LENGTH_REQUEST_LOGDUMP);
buf.putShort(ENDPOINT_LOGDUMP);
buf.put((byte) generation);
buf.putInt(cookie);
return buf.array();
}
private byte[] encodeBlobDBClear(byte database) {
final short LENGTH_BLOBDB_CLEAR = 4;
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_BLOBDB_CLEAR);
@@ -2060,7 +2082,20 @@ public class PebbleProtocol extends GBDeviceProtocol {
int lineNumber = buf.getShort() & 0xffff;
String fileName = getFixedString(buf, 16);
String message = getFixedString(buf, messageLength);
LOG.debug("APP_LOGS ({}) from uuid {} in {}:{} {}", logLevel, uuid, fileName, lineNumber, message);
LOG.debug("APP_LOGS: {} : ({}) from uuid {} in {}:{} {}", DateTimeUtils.formatIso8601(new Date(timestamp * 1000L)), logLevel, uuid, fileName, lineNumber, message);
}
private void decodeLogDump(ByteBuffer buf) {
int logLevel = buf.get() & 0xff;
int cookie = buf.getInt();
int timestamp = buf.getInt();
buf.get();
buf.order(ByteOrder.LITTLE_ENDIAN);
int length = buf.getShort();
short lineNumber = buf.getShort();
String fileName = getFixedString(buf, 15);
String message = getFixedString(buf, length);
LOG.debug("PEBBLE LOG_DUMP: {} : ({}) in {}:{} {}", DateTimeUtils.formatIso8601(new Date(timestamp * 1000L)), logLevel, fileName, lineNumber, message);
}
private GBDeviceEvent decodeSystemMessage(ByteBuffer buf) {
@@ -2561,6 +2596,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
case ENDPOINT_APPLOGS:
decodeAppLogs(buf);
break;
case ENDPOINT_LOGDUMP:
decodeLogDump(buf);
break;
case ENDPOINT_VOICECONTROL:
devEvts = new GBDeviceEvent[]{decodeVoiceControl(buf)};
break;
@@ -214,7 +214,7 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
@Override
public void onFetchRecordedData(int dataTypes) {
byte[] bytes = gbDeviceProtocol.encodeSynchronizeActivityData();
byte[] bytes = gbDeviceProtocol.encodeFetchRecordedData(dataTypes);
sendToDevice(bytes);
}
@@ -117,11 +117,6 @@ public abstract class GBDeviceProtocol {
return null;
}
@Nullable
public byte[] encodeSynchronizeActivityData() {
return null;
}
@Nullable
public byte[] encodeReset(int flags) {
return null;
@@ -217,6 +212,11 @@ public abstract class GBDeviceProtocol {
return null;
}
@Nullable
public byte[] encodeFetchRecordedData(int dataTypes) {
return null;
}
protected DevicePrefs getDevicePrefs() {
return GBApplication.getDevicePrefs(getDevice());
}