1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-09 15:11:34 +02:00

Garmin: Improve transaction logging

This commit is contained in:
José Rebelo 2024-05-19 18:04:25 +01:00 committed by Daniele Gobbetti
parent d741b6ff66
commit 39bbd2e579
4 changed files with 32 additions and 32 deletions

View File

@ -221,11 +221,11 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
evaluateGBDeviceEvent(event); evaluateGBDeviceEvent(event);
} }
communicator.sendMessage(parsedMessage.getAckBytestream()); //send status message communicator.sendMessage("send status", parsedMessage.getAckBytestream()); //send status message
sendOutgoingMessage(parsedMessage); //send reply if any sendOutgoingMessage("send reply", parsedMessage); //send reply if any
sendOutgoingMessage(followup); //send followup message if any sendOutgoingMessage("send followup", followup); //send followup message if any
if (parsedMessage instanceof ConfigurationMessage) { //the last forced message exchange if (parsedMessage instanceof ConfigurationMessage) { //the last forced message exchange
completeInitialization(); completeInitialization();
@ -239,7 +239,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
@Override @Override
public void onSetCallState(CallSpec callSpec) { public void onSetCallState(CallSpec callSpec) {
LOG.info("INCOMING CALLSPEC: {}", callSpec.command); LOG.info("INCOMING CALLSPEC: {}", callSpec.command);
sendOutgoingMessage(notificationsHandler.onSetCallState(callSpec)); sendOutgoingMessage("send call", notificationsHandler.onSetCallState(callSpec));
} }
@Override @Override
@ -262,7 +262,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
LOG.info("NOTIFICATIONS ARE NOW enabled={}, status={}", enable, finalStatus); LOG.info("NOTIFICATIONS ARE NOW enabled={}, status={}", enable, finalStatus);
sendOutgoingMessage(new NotificationSubscriptionStatusMessage( sendOutgoingMessage("toggle notification subscription", new NotificationSubscriptionStatusMessage(
GFDIMessage.Status.ACK, GFDIMessage.Status.ACK,
finalStatus, finalStatus,
enable, enable,
@ -281,7 +281,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
} }
if (!getKeepActivityDataOnDevice()) { // delete file from watch upon successful download if (!getKeepActivityDataOnDevice()) { // delete file from watch upon successful download
sendOutgoingMessage(new SetFileFlagsMessage(entry.getFileIndex(), SetFileFlagsMessage.FileFlags.ARCHIVE)); sendOutgoingMessage("archive file " + entry.getFileIndex(), new SetFileFlagsMessage(entry.getFileIndex(), SetFileFlagsMessage.FileFlags.ARCHIVE));
} }
} }
@ -301,17 +301,17 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
// FIXME respect dataTypes? // FIXME respect dataTypes?
sendOutgoingMessage(fileTransferHandler.initiateDownload()); sendOutgoingMessage("fetch recorded data", fileTransferHandler.initiateDownload());
} }
@Override @Override
public void onNotification(final NotificationSpec notificationSpec) { public void onNotification(final NotificationSpec notificationSpec) {
sendOutgoingMessage(notificationsHandler.onNotification(notificationSpec)); sendOutgoingMessage("send notification " + notificationSpec.getId(), notificationsHandler.onNotification(notificationSpec));
} }
@Override @Override
public void onDeleteNotification(int id) { public void onDeleteNotification(int id) {
sendOutgoingMessage(notificationsHandler.onDeleteNotification(id)); sendOutgoingMessage("delete notification " + id, notificationsHandler.onDeleteNotification(id));
} }
@ -320,10 +320,10 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
sendWeatherConditions(weatherSpecs.get(0)); sendWeatherConditions(weatherSpecs.get(0));
} }
private void sendOutgoingMessage(GFDIMessage message) { private void sendOutgoingMessage(final String taskName, final GFDIMessage message) {
if (message == null) if (message == null)
return; return;
communicator.sendMessage(message.getOutgoingMessage()); communicator.sendMessage(taskName, message.getOutgoingMessage());
} }
private boolean supports(final GarminCapability capability) { private boolean supports(final GarminCapability capability) {
@ -348,7 +348,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
weatherDefinitions.add(recordDefinitionHourly); weatherDefinitions.add(recordDefinitionHourly);
weatherDefinitions.add(recordDefinitionDaily); weatherDefinitions.add(recordDefinitionDaily);
sendOutgoingMessage(new nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.FitDefinitionMessage(weatherDefinitions)); sendOutgoingMessage("send weather definitions", new nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.FitDefinitionMessage(weatherDefinitions));
try { try {
RecordData today = new RecordData(recordDefinitionToday, recordDefinitionToday.getRecordHeader()); RecordData today = new RecordData(recordDefinitionToday, recordDefinitionToday.getRecordHeader());
@ -426,7 +426,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
} }
} }
sendOutgoingMessage(new nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.FitDataMessage(weatherData)); sendOutgoingMessage("send weather data", new nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.FitDataMessage(weatherData));
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage()); LOG.error(e.getMessage());
} }
@ -438,16 +438,16 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
enableWeather(); enableWeather();
//following is needed for vivomove style //following is needed for vivomove style
sendOutgoingMessage(new SystemEventMessage(SystemEventMessage.GarminSystemEventType.SYNC_READY, 0)); sendOutgoingMessage("set sync ready", new SystemEventMessage(SystemEventMessage.GarminSystemEventType.SYNC_READY, 0));
enableBatteryLevelUpdate(); enableBatteryLevelUpdate();
gbDevice.setState(GBDevice.State.INITIALIZED); gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext()); gbDevice.sendDeviceUpdateIntent(getContext());
sendOutgoingMessage(new SupportedFileTypesMessage()); sendOutgoingMessage("request supported file types", new SupportedFileTypesMessage());
sendOutgoingMessage(toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true))); sendOutgoingMessage("toggle default reply suffix", toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true)));
} }
private ProtobufMessage toggleDefaultReplySuffix(boolean value) { private ProtobufMessage toggleDefaultReplySuffix(boolean value) {
@ -467,7 +467,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
public void onSendConfiguration(String config) { public void onSendConfiguration(String config) {
switch (config) { switch (config) {
case PREF_GARMIN_DEFAULT_REPLY_SUFFIX: case PREF_GARMIN_DEFAULT_REPLY_SUFFIX:
sendOutgoingMessage(toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true))); sendOutgoingMessage("toggle default reply suffix", toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true)));
break; break;
case PREF_SEND_APP_NOTIFICATIONS: case PREF_SEND_APP_NOTIFICATIONS:
NotificationSubscriptionDeviceEvent notificationSubscriptionDeviceEvent = new NotificationSubscriptionDeviceEvent(); NotificationSubscriptionDeviceEvent notificationSubscriptionDeviceEvent = new NotificationSubscriptionDeviceEvent();
@ -493,14 +493,14 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
if (alreadyDownloaded(directoryEntry)) { if (alreadyDownloaded(directoryEntry)) {
LOG.debug("File: {} already downloaded, not downloading again.", directoryEntry.getFileName()); LOG.debug("File: {} already downloaded, not downloading again.", directoryEntry.getFileName());
if (!getKeepActivityDataOnDevice()) { // delete file from watch if already downloaded if (!getKeepActivityDataOnDevice()) { // delete file from watch if already downloaded
sendOutgoingMessage(new SetFileFlagsMessage(directoryEntry.getFileIndex(), SetFileFlagsMessage.FileFlags.ARCHIVE)); sendOutgoingMessage("archive file " + directoryEntry.getFileIndex(), new SetFileFlagsMessage(directoryEntry.getFileIndex(), SetFileFlagsMessage.FileFlags.ARCHIVE));
} }
continue; continue;
} }
final DownloadRequestMessage downloadRequestMessage = fileTransferHandler.downloadDirectoryEntry(directoryEntry); final DownloadRequestMessage downloadRequestMessage = fileTransferHandler.downloadDirectoryEntry(directoryEntry);
LOG.debug("Will download file: {}", directoryEntry.getFileName()); LOG.debug("Will download file: {}", directoryEntry.getFileName());
sendOutgoingMessage(downloadRequestMessage); sendOutgoingMessage("download file " + directoryEntry.getFileIndex(), downloadRequestMessage);
return; return;
} }
} }
@ -559,7 +559,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
) )
) )
.build()); .build());
sendOutgoingMessage(batteryLevelProtobufRequest); sendOutgoingMessage("enable battery updates", batteryLevelProtobufRequest);
} }
private void enableWeather() { private void enableWeather() {
@ -567,12 +567,12 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
settings.put(SetDeviceSettingsMessage.GarminDeviceSetting.AUTO_UPLOAD_ENABLED, false); settings.put(SetDeviceSettingsMessage.GarminDeviceSetting.AUTO_UPLOAD_ENABLED, false);
settings.put(SetDeviceSettingsMessage.GarminDeviceSetting.WEATHER_CONDITIONS_ENABLED, true); settings.put(SetDeviceSettingsMessage.GarminDeviceSetting.WEATHER_CONDITIONS_ENABLED, true);
settings.put(SetDeviceSettingsMessage.GarminDeviceSetting.WEATHER_ALERTS_ENABLED, false); settings.put(SetDeviceSettingsMessage.GarminDeviceSetting.WEATHER_ALERTS_ENABLED, false);
sendOutgoingMessage(new SetDeviceSettingsMessage(settings)); sendOutgoingMessage("enable weather", new SetDeviceSettingsMessage(settings));
} }
@Override @Override
public void onSetTime() { public void onSetTime() {
sendOutgoingMessage(new SystemEventMessage(SystemEventMessage.GarminSystemEventType.TIME_UPDATED, 0)); sendOutgoingMessage("set time", new SystemEventMessage(SystemEventMessage.GarminSystemEventType.TIME_UPDATED, 0));
} }
@Override @Override
@ -592,12 +592,12 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
GdiSmartProto.Smart.newBuilder() GdiSmartProto.Smart.newBuilder()
.setFindMyWatchService(a).build()); .setFindMyWatchService(a).build());
sendOutgoingMessage(findMyWatch); sendOutgoingMessage("find device", findMyWatch);
} }
@Override @Override
public void onSetCannedMessages(CannedMessagesSpec cannedMessagesSpec) { public void onSetCannedMessages(CannedMessagesSpec cannedMessagesSpec) {
sendOutgoingMessage(protocolBufferHandler.setCannedMessages(cannedMessagesSpec)); sendOutgoingMessage("set canned messages", protocolBufferHandler.setCannedMessages(cannedMessagesSpec));
} }
@Override @Override
@ -610,7 +610,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
attributes.put(MusicControlEntityUpdateMessage.TRACK.TITLE, musicSpec.track); attributes.put(MusicControlEntityUpdateMessage.TRACK.TITLE, musicSpec.track);
attributes.put(MusicControlEntityUpdateMessage.TRACK.DURATION, String.valueOf(musicSpec.duration)); attributes.put(MusicControlEntityUpdateMessage.TRACK.DURATION, String.valueOf(musicSpec.duration));
sendOutgoingMessage(new MusicControlEntityUpdateMessage(attributes)); sendOutgoingMessage("set music info", new MusicControlEntityUpdateMessage(attributes));
} }
@Override @Override
@ -634,7 +634,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
Map<MusicControlEntityUpdateMessage.MusicEntity, String> attributes = new HashMap<>(); Map<MusicControlEntityUpdateMessage.MusicEntity, String> attributes = new HashMap<>();
attributes.put(MusicControlEntityUpdateMessage.PLAYER.PLAYBACK_INFO, StringUtils.join(",", playing, playRate, position).toString()); attributes.put(MusicControlEntityUpdateMessage.PLAYER.PLAYBACK_INFO, StringUtils.join(",", playing, playRate, position).toString());
sendOutgoingMessage(new MusicControlEntityUpdateMessage(attributes)); sendOutgoingMessage("music state timer", new MusicControlEntityUpdateMessage(attributes));
} }
}, 0, updatePeriod); }, 0, updatePeriod);
@ -645,7 +645,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
Map<MusicControlEntityUpdateMessage.MusicEntity, String> attributes = new HashMap<>(); Map<MusicControlEntityUpdateMessage.MusicEntity, String> attributes = new HashMap<>();
attributes.put(MusicControlEntityUpdateMessage.PLAYER.PLAYBACK_INFO, StringUtils.join(",", playing, playRate, position).toString()); attributes.put(MusicControlEntityUpdateMessage.PLAYER.PLAYBACK_INFO, StringUtils.join(",", playing, playRate, position).toString());
sendOutgoingMessage(new MusicControlEntityUpdateMessage(attributes)); sendOutgoingMessage("music stopped", new MusicControlEntityUpdateMessage(attributes));
} }
} }
@ -700,7 +700,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
GdiCore.CoreService.newBuilder().setLocationUpdatedNotification(locationUpdatedNotification) GdiCore.CoreService.newBuilder().setLocationUpdatedNotification(locationUpdatedNotification)
).build() ).build()
); );
sendOutgoingMessage(locationUpdatedNotificationRequest); sendOutgoingMessage("set gps location", locationUpdatedNotificationRequest);
} }
@Nullable @Nullable

View File

@ -6,7 +6,7 @@ import android.bluetooth.BluetoothGattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
public interface ICommunicator { public interface ICommunicator {
void sendMessage(byte[] message); void sendMessage(String taskName, byte[] message);
void onMtuChanged(final int mtu); void onMtuChanged(final int mtu);

View File

@ -29,7 +29,7 @@ public class CommunicatorV1 implements ICommunicator {
} }
@Override @Override
public void sendMessage(final byte[] message) { public void sendMessage(final String taskName, final byte[] message) {
} }

View File

@ -48,7 +48,7 @@ public class CommunicatorV2 implements ICommunicator {
} }
@Override @Override
public void sendMessage(final byte[] message) { public void sendMessage(final String taskName, final byte[] message) {
if (null == message) if (null == message)
return; return;
if (0 == gfdiHandle) { if (0 == gfdiHandle) {
@ -57,7 +57,7 @@ public class CommunicatorV2 implements ICommunicator {
} }
final byte[] payload = cobsCoDec.encode(message); final byte[] payload = cobsCoDec.encode(message);
// LOG.debug("SENDING MESSAGE: {} - COBS ENCODED: {}", GB.hexdump(message), GB.hexdump(payload)); // LOG.debug("SENDING MESSAGE: {} - COBS ENCODED: {}", GB.hexdump(message), GB.hexdump(payload));
final TransactionBuilder builder = new TransactionBuilder("sendMessage()"); final TransactionBuilder builder = new TransactionBuilder(taskName);
int remainingBytes = payload.length; int remainingBytes = payload.length;
if (remainingBytes > maxWriteSize - 1) { if (remainingBytes > maxWriteSize - 1) {
int position = 0; int position = 0;