Moyoung: Improve logging

This commit is contained in:
Arjan Schrijver 2024-08-24 21:01:58 +02:00
parent 52610057eb
commit 8768349aaa
4 changed files with 42 additions and 46 deletions

View File

@ -18,7 +18,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung;
import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -81,7 +80,7 @@ public class FetchDataOperation extends AbstractBTLEOperation<MoyoungDeviceSuppo
UUID charUuid = characteristic.getUuid(); UUID charUuid = characteristic.getUuid();
if (charUuid.equals(MoyoungConstants.UUID_CHARACTERISTIC_STEPS)) { if (charUuid.equals(MoyoungConstants.UUID_CHARACTERISTIC_STEPS)) {
byte[] data = characteristic.getValue(); byte[] data = characteristic.getValue();
Log.i("TODAY STEPS", "data: " + Logging.formatBytes(data)); LOG.info("TODAY STEPS data: " + Logging.formatBytes(data));
decodeSteps(0, data); decodeSteps(0, data);
return true; return true;
} }
@ -120,7 +119,7 @@ public class FetchDataOperation extends AbstractBTLEOperation<MoyoungDeviceSuppo
private boolean handlePacket(byte packetType, byte[] payload) { private boolean handlePacket(byte packetType, byte[] payload) {
if (packetType == MoyoungConstants.CMD_SYNC_SLEEP) { if (packetType == MoyoungConstants.CMD_SYNC_SLEEP) {
Log.i("TODAY SLEEP", "data: " + Logging.formatBytes(payload)); LOG.info("TODAY SLEEP data: " + Logging.formatBytes(payload));
decodeSleep(0, payload); decodeSleep(0, payload);
return true; return true;
} }
@ -135,22 +134,22 @@ public class FetchDataOperation extends AbstractBTLEOperation<MoyoungDeviceSuppo
// in the app itself and all past data is getting messed up because of it) // in the app itself and all past data is getting messed up because of it)
if (dataType == MoyoungConstants.ARG_SYNC_YESTERDAY_STEPS) { if (dataType == MoyoungConstants.ARG_SYNC_YESTERDAY_STEPS) {
Log.i("2 DAYS AGO STEPS", "data: " + Logging.formatBytes(data)); LOG.info("2 DAYS AGO STEPS data: " + Logging.formatBytes(data));
decodeSteps(2, data); decodeSteps(2, data);
return true; return true;
} }
else if (dataType == MoyoungConstants.ARG_SYNC_DAY_BEFORE_YESTERDAY_STEPS) { else if (dataType == MoyoungConstants.ARG_SYNC_DAY_BEFORE_YESTERDAY_STEPS) {
Log.i("YESTERDAY STEPS", "data: " + Logging.formatBytes(data)); LOG.info("YESTERDAY STEPS data: " + Logging.formatBytes(data));
decodeSteps(1, data); decodeSteps(1, data);
return true; return true;
} }
else if (dataType == MoyoungConstants.ARG_SYNC_YESTERDAY_SLEEP) { else if (dataType == MoyoungConstants.ARG_SYNC_YESTERDAY_SLEEP) {
Log.i("2 DAYS AGO SLEEP", "data: " + Logging.formatBytes(data)); LOG.info("2 DAYS AGO SLEEP data: " + Logging.formatBytes(data));
decodeSleep(2, data); decodeSleep(2, data);
return true; return true;
} }
else if (dataType == MoyoungConstants.ARG_SYNC_DAY_BEFORE_YESTERDAY_SLEEP) { else if (dataType == MoyoungConstants.ARG_SYNC_DAY_BEFORE_YESTERDAY_SLEEP) {
Log.i("YESTERDAY SLEEP", "data: " + Logging.formatBytes(data)); LOG.info("YESTERDAY SLEEP data: " + Logging.formatBytes(data));
decodeSleep(1, data); decodeSleep(1, data);
return true; return true;
} }

View File

@ -22,7 +22,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import android.widget.Toast; import android.widget.Toast;
@ -211,7 +210,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
if (charUuid.equals(MoyoungConstants.UUID_CHARACTERISTIC_STEPS)) if (charUuid.equals(MoyoungConstants.UUID_CHARACTERISTIC_STEPS))
{ {
byte[] payload = characteristic.getValue(); byte[] payload = characteristic.getValue();
Log.i("AAAAAAAAAAAAAAAA", "Update step count: " + Logging.formatBytes(characteristic.getValue())); LOG.info("Update step count: " + Logging.formatBytes(characteristic.getValue()));
handleStepsHistory(0, payload, true); handleStepsHistory(0, payload, true);
return true; return true;
} }
@ -224,7 +223,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
byte packetType = packet.first; byte packetType = packet.first;
byte[] payload = packet.second; byte[] payload = packet.second;
Log.i("AAAAAAAAAAAAAAAA", "Response for: " + packetType); LOG.info("Response for: " + packetType);
if (handlePacket(packetType, payload)) if (handlePacket(packetType, payload))
return true; return true;
@ -240,7 +239,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
if (packetType == MoyoungConstants.CMD_TRIGGER_MEASURE_HEARTRATE) if (packetType == MoyoungConstants.CMD_TRIGGER_MEASURE_HEARTRATE)
{ {
int heartRate = payload[0]; int heartRate = payload[0];
Log.i("XXXXXXXX", "Measure heart rate finished: " + heartRate + " BPM"); LOG.info("Measure heart rate finished: " + heartRate + " BPM");
try (DBHandler dbHandler = GBApplication.acquireDB()) { try (DBHandler dbHandler = GBApplication.acquireDB()) {
MoyoungHeartRateSampleProvider sampleProvider = new MoyoungHeartRateSampleProvider(getDevice(), dbHandler.getDaoSession()); MoyoungHeartRateSampleProvider sampleProvider = new MoyoungHeartRateSampleProvider(getDevice(), dbHandler.getDaoSession());
@ -267,7 +266,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
if (packetType == MoyoungConstants.CMD_TRIGGER_MEASURE_BLOOD_OXYGEN) if (packetType == MoyoungConstants.CMD_TRIGGER_MEASURE_BLOOD_OXYGEN)
{ {
int percent = payload[0]; int percent = payload[0];
Log.i("XXXXXXXX", "Measure blood oxygen finished: " + percent + "%"); LOG.info("Measure blood oxygen finished: " + percent + "%");
try (DBHandler dbHandler = GBApplication.acquireDB()) { try (DBHandler dbHandler = GBApplication.acquireDB()) {
MoyoungSpo2SampleProvider sampleProvider = new MoyoungSpo2SampleProvider(getDevice(), dbHandler.getDaoSession()); MoyoungSpo2SampleProvider sampleProvider = new MoyoungSpo2SampleProvider(getDevice(), dbHandler.getDaoSession());
@ -293,7 +292,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
int dataUnknown = payload[0]; int dataUnknown = payload[0];
int data1 = payload[1]; int data1 = payload[1];
int data2 = payload[2]; int data2 = payload[2];
Log.i("XXXXXXXX", "Measure blood pressure finished: " + data1 + "/" + data2 + " (" + dataUnknown + ")"); LOG.info("Measure blood pressure finished: " + data1 + "/" + data2 + " (" + dataUnknown + ")");
try (DBHandler dbHandler = GBApplication.acquireDB()) { try (DBHandler dbHandler = GBApplication.acquireDB()) {
MoyoungBloodPressureSampleProvider sampleProvider = new MoyoungBloodPressureSampleProvider(getDevice(), dbHandler.getDaoSession()); MoyoungBloodPressureSampleProvider sampleProvider = new MoyoungBloodPressureSampleProvider(getDevice(), dbHandler.getDaoSession());
@ -323,7 +322,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
try { try {
new TrainingFinishedDataOperation(this, payload).perform(); new TrainingFinishedDataOperation(this, payload).perform();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("TrainingFinishedDataOperation failed: ", e);
} }
} }
@ -412,7 +411,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
provider.addGBActivitySample(sample); provider.addGBActivitySample(sample);
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); LOG.error("Error saving samples: ", ex);
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
} }
@ -454,7 +453,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_SEND_MESSAGE, payload)); sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_SEND_MESSAGE, payload));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error sending notification: ", e);
} }
} }
@ -494,7 +493,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
setTime(builder); setTime(builder);
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error setting time: ", e);
} }
} }
@ -585,7 +584,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
} }
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error setting alarms: ", e);
} }
} }
@ -596,7 +595,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
try { try {
new FetchDataOperation(this).perform(); new FetchDataOperation(this).perform();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error fetching data: ", e);
} }
} }
} }
@ -657,7 +656,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
LOG.info("Adding an idle sample: " + sample.toString()); LOG.info("Adding an idle sample: " + sample.toString());
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); LOG.error("Error saving samples: ", ex);
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
} }
@ -676,7 +675,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
System.arraycopy(data, 6, bArr2, 0, 3); System.arraycopy(data, 6, bArr2, 0, 3);
int calories = BytesToInt24(bArr2); int calories = BytesToInt24(bArr2);
Log.i("steps[" + daysAgo + "]", "steps=" + steps + ", distance=" + distance + ", calories=" + calories); LOG.info("steps[" + daysAgo + "] steps=" + steps + ", distance=" + distance + ", calories=" + calories);
try (DBHandler dbHandler = GBApplication.acquireDB()) { try (DBHandler dbHandler = GBApplication.acquireDB()) {
User user = DBHelper.getUser(dbHandler.getDaoSession()); User user = DBHelper.getUser(dbHandler.getDaoSession());
@ -753,7 +752,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
LOG.info("Adding a sample: " + sample.toString()); LOG.info("Adding a sample: " + sample.toString());
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); LOG.error("Error saving samples: ", ex);
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
} }
@ -773,7 +772,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
int start_h = data[3*i + 1]; int start_h = data[3*i + 1];
int start_m = data[3*i + 2]; int start_m = data[3*i + 2];
Log.i("sleep[" + daysAgo + "][" + i + "]", "type=" + type + ", start_h=" + start_h + ", start_m=" + start_m); LOG.info("sleep[" + daysAgo + "][" + i + "] type=" + type + ", start_h=" + start_h + ", start_m=" + start_m);
// SleepAnalysis measures sleep fragment type by marking the END of the fragment. // SleepAnalysis measures sleep fragment type by marking the END of the fragment.
// The watch provides data by marking the START of the fragment. // The watch provides data by marking the START of the fragment.
@ -880,7 +879,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
prevActivityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_START; prevActivityType = MoyoungActivitySampleProvider.ACTIVITY_SLEEP_START;
prevSampleTimestamp = thisSampleTimestamp; prevSampleTimestamp = thisSampleTimestamp;
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); LOG.error("Error saving samples: ", ex);
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
} }
@ -907,7 +906,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
int steps = buffer.getInt(); int steps = buffer.getInt();
int distance = buffer.getInt(); int distance = buffer.getInt();
int calories = buffer.getShort(); int calories = buffer.getShort();
Log.i("Training data", "start=" + startTime + " end=" + endTime + " totalTimeWithoutPause=" + validTime + " num=" + num + " type=" + type + " steps=" + steps + " distance=" + distance + " calories=" + calories); LOG.info("Training data: start=" + startTime + " end=" + endTime + " totalTimeWithoutPause=" + validTime + " num=" + num + " type=" + type + " steps=" + steps + " distance=" + distance + " calories=" + calories);
// NOTE: We are ignoring the step/distance/calories data here // NOTE: We are ignoring the step/distance/calories data here
// If we had the phone connected, the realtime data is already stored anyway, and I'm // If we had the phone connected, the realtime data is already stored anyway, and I'm
@ -970,7 +969,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
provider.updateActivityInRange((int)(startTime.getTime() / 1000), (int)(endTime.getTime() / 1000), type); provider.updateActivityInRange((int)(startTime.getTime() / 1000), (int)(endTime.getTime() / 1000), type);
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); LOG.error("Error saving samples: ", ex);
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
} }
@ -1003,7 +1002,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_SHUTDOWN, new byte[] { -1 })); sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_SHUTDOWN, new byte[] { -1 }));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error sending reset command: ", e);
} }
} }
@ -1014,7 +1013,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_TRIGGER_MEASURE_HEARTRATE, new byte[] { start ? (byte)0 : (byte)-1 })); sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_TRIGGER_MEASURE_HEARTRATE, new byte[] { start ? (byte)0 : (byte)-1 }));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error sending heart rate test command: ", e);
} }
} }
@ -1080,7 +1079,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
try { try {
time = new SimpleDateFormat("HH:mm").parse(timePref); time = new SimpleDateFormat("HH:mm").parse(timePref);
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); LOG.error("Error parsing time: ", e);
} }
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(time); cal.setTime(time);
@ -1099,7 +1098,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
sendSetting(builder, setting, newValue); sendSetting(builder, setting, newValue);
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error sending setting: ", e);
} }
} }
@ -1116,13 +1115,13 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
builder.queue(getQueue()); builder.queue(getQueue());
queriedSettings.add(setting); queriedSettings.add(setting);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error querying setting: ", e);
} }
} }
@Override @Override
public void onSendConfiguration(String config) { public void onSendConfiguration(String config) {
Log.i("OOOOOOOOOOOOOOOOsend", config); LOG.info("Send configuration: " + config);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress())); Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
switch (config) { switch (config) {
@ -1255,7 +1254,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onReadConfiguration(String config) { public void onReadConfiguration(String config) {
Log.i("OOOOOOOOOOOOOOOOread", config); LOG.info("Read configuration: " + config);
switch (config) { switch (config) {
/* These use the global Gadgetbridge configuration and are always forced on device upon connection /* These use the global Gadgetbridge configuration and are always forced on device upon connection
@ -1325,7 +1324,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
public void onReadConfigurationDone(MoyoungSetting setting, Object value, byte[] data) public void onReadConfigurationDone(MoyoungSetting setting, Object value, byte[] data)
{ {
Log.i("CONFIG", setting.name + " = " + value); LOG.info("CONFIG " + setting.name + " = " + value);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress())); Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
Map<String, String> changedProperties = new ArrayMap<>(); Map<String, String> changedProperties = new ArrayMap<>();
SharedPreferences.Editor prefsEditor = prefs.getPreferences().edit(); SharedPreferences.Editor prefsEditor = prefs.getPreferences().edit();
@ -1469,7 +1468,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error sending weather: ", e);
} }
} }
} }

View File

@ -18,7 +18,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung;
import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -113,7 +112,7 @@ public class QuerySettingsOperation extends AbstractBTLEOperation<MoyoungDeviceS
if (setting.cmdQuery == packetType) if (setting.cmdQuery == packetType)
{ {
Object value = setting.decode(payload); Object value = setting.decode(payload);
Log.i("SETTING QUERY", setting.name + " = " + value.toString()); LOG.info("SETTING QUERY " + setting.name + " = " + value.toString());
received[i] = true; received[i] = true;
handled = true; handled = true;
} }

View File

@ -18,7 +18,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung;
import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import android.widget.Toast; import android.widget.Toast;
@ -50,7 +49,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class TrainingFinishedDataOperation extends AbstractBTLEOperation<MoyoungDeviceSupport> { public class TrainingFinishedDataOperation extends AbstractBTLEOperation<MoyoungDeviceSupport> {
private static final Logger LOG = LoggerFactory.getLogger(FetchDataOperation.class); private static final Logger LOG = LoggerFactory.getLogger(TrainingFinishedDataOperation.class);
private final byte[] firstPacketData; private final byte[] firstPacketData;
private final long firstPacketTimeInMillis; private final long firstPacketTimeInMillis;
@ -119,7 +118,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
private void handleTrainingHealthRatePacket(byte[] payload, boolean isFirst) { private void handleTrainingHealthRatePacket(byte[] payload, boolean isFirst) {
Log.i("TRAINING DATA", "data: " + Logging.formatBytes(payload)); LOG.info("TRAINING DATA: " + Logging.formatBytes(payload));
byte sequenceType = payload[0]; byte sequenceType = payload[0];
if (isFirst != (sequenceType == MoyoungConstants.ARG_TRANSMISSION_FIRST)) if (isFirst != (sequenceType == MoyoungConstants.ARG_TRANSMISSION_FIRST))
throw new IllegalArgumentException("Expected packet to be " + (isFirst ? "first" : "continued") + " but got packet of type " + sequenceType); throw new IllegalArgumentException("Expected packet to be " + (isFirst ? "first" : "continued") + " but got packet of type " + sequenceType);
@ -140,7 +139,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
getSupport().sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_QUERY_LAST_DYNAMIC_RATE, new byte[0])); getSupport().sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_QUERY_LAST_DYNAMIC_RATE, new byte[0]));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error fetching training data: ", e);
GB.toast(getContext(), "Error fetching training data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error fetching training data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
operationFinished(); operationFinished();
@ -149,7 +148,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
private void processAllData() { private void processAllData() {
byte[] completeData = data.toByteArray(); byte[] completeData = data.toByteArray();
Log.i("HAVE COMPLETE DATA", Logging.formatBytes(completeData)); LOG.info("HAVE COMPLETE DATA: " + Logging.formatBytes(completeData));
ByteBuffer dataBuffer = ByteBuffer.wrap(completeData); ByteBuffer dataBuffer = ByteBuffer.wrap(completeData);
dataBuffer.order(ByteOrder.LITTLE_ENDIAN); dataBuffer.order(ByteOrder.LITTLE_ENDIAN);
@ -165,14 +164,14 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
MoyoungHeartRateSampleProvider provider = new MoyoungHeartRateSampleProvider(getDevice(), dbHandler.getDaoSession()); MoyoungHeartRateSampleProvider provider = new MoyoungHeartRateSampleProvider(getDevice(), dbHandler.getDaoSession());
Log.i("START DATE", dateRecorded.getTime().toString()); LOG.info("START DATE: " + dateRecorded.getTime().toString());
while (dataBuffer.hasRemaining()) while (dataBuffer.hasRemaining())
{ {
int measurement = dataBuffer.get() & 0xFF; int measurement = dataBuffer.get() & 0xFF;
if (!dataBuffer.hasRemaining()) if (!dataBuffer.hasRemaining())
dateRecorded.setTimeInMillis(firstPacketTimeInMillis); // the last sample is captured exactly at the end of measurement dateRecorded.setTimeInMillis(firstPacketTimeInMillis); // the last sample is captured exactly at the end of measurement
Log.i("MEASUREMENT", "at " + dateRecorded.getTime().toString() + " was " + measurement); LOG.info("MEASUREMENT: at " + dateRecorded.getTime().toString() + " was " + measurement);
MoyoungHeartRateSample sample = new MoyoungHeartRateSample(); MoyoungHeartRateSample sample = new MoyoungHeartRateSample();
sample.setDevice(device); sample.setDevice(device);
@ -186,7 +185,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
dateRecorded.add(Calendar.MINUTE, 1); dateRecorded.add(Calendar.MINUTE, 1);
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); LOG.error("Error saving samples: ", ex);
GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
} }
@ -196,7 +195,7 @@ public class TrainingFinishedDataOperation extends AbstractBTLEOperation<Moyoung
getSupport().sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_QUERY_MOVEMENT_HEART_RATE, new byte[] { })); getSupport().sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_QUERY_MOVEMENT_HEART_RATE, new byte[] { }));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.error("Error fetching training data: ", e);
GB.toast(getContext(), "Error fetching training data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error fetching training data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
operationFinished(); operationFinished();