1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 02:25:50 +01:00

Keep data sent to Bangle.js in the log as well

This commit is contained in:
Gordon Williams 2022-06-14 11:23:38 +01:00
parent 3ef39433a6
commit c11af9e95c

View File

@ -152,6 +152,12 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
registerGlobalIntents(); registerGlobalIntents();
} }
private void addReceiveHistory(String s) {
receiveHistory += s;
if (receiveHistory.length() > MAX_RECEIVE_HISTORY_CHARS)
receiveHistory = receiveHistory.substring(receiveHistory.length() - MAX_RECEIVE_HISTORY_CHARS);
}
private void registerLocalIntents() { private void registerLocalIntents() {
IntentFilter commandFilter = new IntentFilter(); IntentFilter commandFilter = new IntentFilter();
commandFilter.addAction(GBDevice.ACTION_DEVICE_CHANGED); commandFilter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
@ -173,7 +179,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} }
case GBDevice.ACTION_DEVICE_CHANGED: { case GBDevice.ACTION_DEVICE_CHANGED: {
LOG.info("ACTION_DEVICE_CHANGED " + gbDevice.getStateString()); LOG.info("ACTION_DEVICE_CHANGED " + gbDevice.getStateString());
receiveHistory += "\n================================================\nACTION_DEVICE_CHANGED "+gbDevice.getStateString()+" "+(new SimpleDateFormat("yyyy-mm-dd hh:mm:ss")).format(Calendar.getInstance().getTime())+"\n================================================\n"; addReceiveHistory("\n================================================\nACTION_DEVICE_CHANGED "+gbDevice.getStateString()+" "+(new SimpleDateFormat("yyyy-mm-dd hh:mm:ss")).format(Calendar.getInstance().getTime())+"\n================================================\n");
} }
} }
} }
@ -260,6 +266,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
private void uartTx(TransactionBuilder builder, String str) { private void uartTx(TransactionBuilder builder, String str) {
byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1); byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1);
LOG.info("UART TX: " + str); LOG.info("UART TX: " + str);
addReceiveHistory("\n================================================\nSENDING "+str+"\n================================================\n");
// FIXME: somehow this is still giving us UTF8 data when we put images in strings. Maybe JSON.stringify is converting to UTF-8? // FIXME: somehow this is still giving us UTF8 data when we put images in strings. Maybe JSON.stringify is converting to UTF-8?
for (int i=0;i<bytes.length;i+=mtuSize) { for (int i=0;i<bytes.length;i+=mtuSize) {
int l = bytes.length-i; int l = bytes.length-i;
@ -598,9 +605,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
String packetStr = new String(chars); String packetStr = new String(chars);
LOG.info("RX: " + packetStr); LOG.info("RX: " + packetStr);
// logging // logging
receiveHistory += packetStr; addReceiveHistory(packetStr);
if (receiveHistory.length() > MAX_RECEIVE_HISTORY_CHARS)
receiveHistory = receiveHistory.substring(receiveHistory.length() - MAX_RECEIVE_HISTORY_CHARS);
// split into input lines // split into input lines
receivedLine += packetStr; receivedLine += packetStr;
while (receivedLine.contains("\n")) { while (receivedLine.contains("\n")) {